pidgin: f388ae7c: Kill off sound playing child processes i...

nosnilmot at pidgin.im nosnilmot at pidgin.im
Wed May 7 15:10:39 EDT 2008


-----------------------------------------------------------------
Revision: f388ae7c8eb8f7f38f0b5c8fa5e43547bd781925
Ancestor: 4955af47f51251e1bc160a9fbbd177cca708d81c
Author: nosnilmot at pidgin.im
Date: 2008-05-07T19:06:28
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/f388ae7c8eb8f7f38f0b5c8fa5e43547bd781925

Modified files:
        pidgin/gtksound.c

ChangeLog: 

Kill off sound playing child processes if they are still around after 15
seconds, as they will be if we are piling up children due to blocking on
the audio device. This prevents a barrage of sounds when the device becomes
available.

-------------- next part --------------
============================================================
--- pidgin/gtksound.c	7bed20643adecfafefe031b0f510f82389aa17e6
+++ pidgin/gtksound.c	157c658a8c11b9ee9b26b32a6b988f9981d1891b
@@ -384,6 +384,26 @@ bus_call (GstBus     *bus,
 }
 #endif
 
+#ifndef _WIN32
+static gboolean
+expire_old_child(gpointer data)
+{
+	pid_t pid = GPOINTER_TO_INT(data);
+
+	if (waitpid(pid, NULL, WNOHANG | WUNTRACED) < 0) {
+		if (errno == ECHILD)
+			return FALSE;
+		else
+			purple_debug_warning("gtksound", "Child is ill, pid: %d (%s)\n", pid, strerror(errno));
+	}
+
+	if (kill(pid, SIGKILL) < 0)
+		purple_debug_error("gtksound", "Killing process %d failed (%s)\n", pid, strerror(errno));
+
+	return FALSE;
+}
+#endif
+
 static void
 pidgin_sound_play_file(const char *filename)
 {
@@ -418,7 +438,9 @@ pidgin_sound_play_file(const char *filen
 		const char *sound_cmd;
 		char *command;
 		char *esc_filename;
+		char **argv = NULL;
 		GError *error = NULL;
+		GPid pid;
 
 		sound_cmd = purple_prefs_get_path(PIDGIN_PREFS_ROOT "/sound/command");
 
@@ -436,11 +458,25 @@ pidgin_sound_play_file(const char *filen
 		else
 			command = g_strdup_printf("%s %s", sound_cmd, esc_filename);
 
-		if(!g_spawn_command_line_async(command, &error)) {
-			purple_debug_error("gtksound", "sound command could not be launched: %s\n", error->message);
+		if (!g_shell_parse_argv(command, NULL, &argv, &error)) {
+			purple_debug_error("gtksound", "error parsing command %s (%s)\n",
+							   command, error->message);
 			g_error_free(error);
+			g_free(esc_filename);
+			g_free(command);
+			return;
 		}
 
+		if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
+						  NULL, NULL, &pid, &error)) {
+			purple_debug_error("gtksound", "sound command could not be launched: %s\n",
+							   error->message);
+			g_error_free(error);
+		} else {
+			purple_timeout_add_seconds(15, expire_old_child, GINT_TO_POINTER(pid));
+		}
+
+		g_strfreev(argv);
 		g_free(esc_filename);
 		g_free(command);
 		return;


More information about the Commits mailing list