4 Copyright (C) 1999-2000 Timo Sirainen
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 static GHashTable *child_pids;
28 static int signal_pidwait;
30 static void sig_child(GPid pid, gint status, gpointer data)
32 signal_emit_id(signal_pidwait, 2, GINT_TO_POINTER(pid),
33 GINT_TO_POINTER(status));
34 g_hash_table_remove(child_pids, GINT_TO_POINTER(pid));
35 pids = g_slist_remove(pids, GINT_TO_POINTER(pid));
38 /* add a pid to wait list */
39 void pidwait_add(int pid)
41 if (g_hash_table_lookup(child_pids, GINT_TO_POINTER(pid)) == NULL) {
42 int id = g_child_watch_add_full(10, pid, sig_child, NULL, NULL);
43 g_hash_table_insert(child_pids, GINT_TO_POINTER(pid), GINT_TO_POINTER(id));
44 pids = g_slist_append(pids, GINT_TO_POINTER(pid));
48 /* remove pid from wait list */
49 void pidwait_remove(int pid)
51 gpointer id = g_hash_table_lookup(child_pids, GINT_TO_POINTER(pid));
53 g_source_remove(GPOINTER_TO_INT(id));
54 g_hash_table_remove(child_pids, GINT_TO_POINTER(pid));
55 pids = g_slist_remove(pids, GINT_TO_POINTER(pid));
59 /* return list of pids that are being waited.
60 don't free the return value. */
61 GSList *pidwait_get_pids(void)
66 void pidwait_init(void)
68 child_pids = g_hash_table_new(g_direct_hash, g_direct_equal);
71 signal_pidwait = signal_get_uniq_id("pidwait");
74 void pidwait_deinit(void)
76 g_hash_table_destroy(child_pids);