Check waitpid() return value, stupid!

This commit is contained in:
Yevgen Muntyan 2007-06-20 21:34:09 -06:00
parent 96dc46bc19
commit 119505185d

View File

@ -259,7 +259,7 @@ fork_argv (MooTermPt *pt_gen,
MooTermPtUnix *pt; MooTermPtUnix *pt;
int env_len = 0; int env_len = 0;
char **new_env; char **new_env;
int status; int status, ret;
int i; int i;
int master; int master;
@ -316,18 +316,28 @@ fork_argv (MooTermPt *pt_gen,
return FALSE; return FALSE;
} }
else
ret = waitpid (pt->child_pid, &status, WNOHANG);
if (ret == -1 || ret > 0)
{ {
#if 1 if (ret < 0)
_moo_message ("%s: forked child pid %d on fd %d", g_critical ("%s: error in waitpid", G_STRLOC);
G_STRLOC, pt->child_pid, master); else
#endif _moo_message ("%s: child died already", G_STRLOC);
pt_gen->child_alive = TRUE;
pt_gen->alive = TRUE; pt->child_pid = -1;
kill_child (pt_gen);
return FALSE;
} }
if (waitpid (pt->child_pid, &status, WNOHANG) == -1) if (1)
g_critical ("%s: error in waitpid", G_STRLOC); _moo_message ("%s: forked child pid %d on fd %d",
G_STRLOC, pt->child_pid, master);
pt_gen->child_alive = TRUE;
pt_gen->alive = TRUE;
#ifdef WATCH_CHILD #ifdef WATCH_CHILD
pt->child_watch_id = g_child_watch_add_full (pt_gen->priority, pt->child_watch_id = g_child_watch_add_full (pt_gen->priority,
@ -465,6 +475,10 @@ read_child_out (G_GNUC_UNUSED GIOChannel *source,
{ {
int bytes; int bytes;
if (0)
_moo_message ("reading %" G_GSIZE_FORMAT " bytes\n", to_read);
errno = 0;
bytes = read (pt->master, buf, to_read); bytes = read (pt->master, buf, to_read);
switch (bytes) switch (bytes)