From e61f51240c37ebad3fc1b62599a18ffdc1e8d9c6 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Fri, 13 Jul 2012 17:45:06 +1200 Subject: Only add utmp entry after child has forked (and have a valid PID) --- src/session-child.c | 98 +++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 51 deletions(-) diff --git a/src/session-child.c b/src/session-child.c index 77cca0ef..07525302 100644 --- a/src/session-child.c +++ b/src/session-child.c @@ -459,32 +459,6 @@ session_child_run (int argc, char **argv) g_free (value); } - /* Log to utmp */ - if (g_strcmp0 (class, XDG_SESSION_CLASS_GREETER) != 0) - { - struct utmpx ut; - struct timeval tv; - - memset (&ut, 0, sizeof (ut)); - ut.ut_type = USER_PROCESS; - ut.ut_pid = child_pid; - strncpy (ut.ut_line, tty + strlen ("/dev/"), sizeof (ut.ut_line)); - strncpy (ut.ut_id, xdisplay, sizeof (ut.ut_id)); - strncpy (ut.ut_user, username, sizeof (ut.ut_user)); - if (remote_host_name) - strncpy (ut.ut_host, remote_host_name, sizeof (ut.ut_host)); - else - memset (ut.ut_host, 0, sizeof (ut.ut_host)); - gettimeofday (&tv, NULL); - ut.ut_tv.tv_sec = tv.tv_sec; - ut.ut_tv.tv_usec = tv.tv_usec; - - setutxent (); - if (!pututxline (&ut)) - g_printerr ("Failed to write utmpx: %s\n", strerror (errno)); - endutxent (); - } - /* Put our tools directory in the path as a hack so we can use the legacy gdmflexiserver interface */ path = pam_getenv (pam_handle, "PATH"); if (path) @@ -554,34 +528,56 @@ session_child_run (int argc, char **argv) /* Wait for the command to complete (blocks) */ if (child_pid > 0) { + /* Log to utmp */ + if (g_strcmp0 (class, XDG_SESSION_CLASS_GREETER) != 0) + { + struct utmpx ut; + struct timeval tv; + + memset (&ut, 0, sizeof (ut)); + ut.ut_type = USER_PROCESS; + ut.ut_pid = child_pid; + strncpy (ut.ut_line, tty + strlen ("/dev/"), sizeof (ut.ut_line)); + strncpy (ut.ut_id, xdisplay, sizeof (ut.ut_id)); + strncpy (ut.ut_user, username, sizeof (ut.ut_user)); + if (remote_host_name) + strncpy (ut.ut_host, remote_host_name, sizeof (ut.ut_host)); + gettimeofday (&tv, NULL); + ut.ut_tv.tv_sec = tv.tv_sec; + ut.ut_tv.tv_usec = tv.tv_usec; + + setutxent (); + if (!pututxline (&ut)) + g_printerr ("Failed to write utmpx: %s\n", strerror (errno)); + endutxent (); + } + waitpid (child_pid, &return_code, 0); child_pid = 0; - } - /* Log to utmp */ - if (g_strcmp0 (class, XDG_SESSION_CLASS_GREETER) != 0) - { - struct utmpx ut; - struct timeval tv; - - memset (&ut, 0, sizeof (ut)); - ut.ut_type = DEAD_PROCESS; - ut.ut_pid = child_pid; - strncpy (ut.ut_line, tty + strlen ("/dev/"), sizeof (ut.ut_line)); - strncpy (ut.ut_id, xdisplay, sizeof (ut.ut_id)); - strncpy (ut.ut_user, username, sizeof (ut.ut_user)); - if (remote_host_name) - strncpy (ut.ut_host, remote_host_name, sizeof (ut.ut_host)); - else - memset (ut.ut_host, 0, sizeof (ut.ut_host)); - gettimeofday (&tv, NULL); - ut.ut_tv.tv_sec = tv.tv_sec; - ut.ut_tv.tv_usec = tv.tv_usec; - - setutxent (); - if (!pututxline (&ut)) - g_printerr ("Failed to write utmpx: %s\n", strerror (errno)); - endutxent (); + /* Log to utmp */ + if (g_strcmp0 (class, XDG_SESSION_CLASS_GREETER) != 0) + { + struct utmpx ut; + struct timeval tv; + + memset (&ut, 0, sizeof (ut)); + ut.ut_type = DEAD_PROCESS; + ut.ut_pid = child_pid; + strncpy (ut.ut_line, tty + strlen ("/dev/"), sizeof (ut.ut_line)); + strncpy (ut.ut_id, xdisplay, sizeof (ut.ut_id)); + strncpy (ut.ut_user, username, sizeof (ut.ut_user)); + if (remote_host_name) + strncpy (ut.ut_host, remote_host_name, sizeof (ut.ut_host)); + gettimeofday (&tv, NULL); + ut.ut_tv.tv_sec = tv.tv_sec; + ut.ut_tv.tv_usec = tv.tv_usec; + + setutxent (); + if (!pututxline (&ut)) + g_printerr ("Failed to write utmpx: %s\n", strerror (errno)); + endutxent (); + } } /* Remove X authority */ -- cgit v1.2.1