diff options
author | Robert Ancell <robert.ancell@canonical.com> | 2012-06-12 14:30:17 +1200 |
---|---|---|
committer | Robert Ancell <robert.ancell@canonical.com> | 2012-06-12 14:30:17 +1200 |
commit | ac57a609fea062b732aafc4427111d07626ecd21 (patch) | |
tree | 3b30736a036b7c35443fc5399b41c06ca0cc779e /src | |
parent | e70298dffa1e062c48469762152da2bb30e66f9d (diff) | |
parent | 5fe7bf1298edd20f9b9af27c32dd6330a7b82a98 (diff) | |
download | lightdm-ac57a609fea062b732aafc4427111d07626ecd21.tar.gz |
Write utmp records for sessions
Diffstat (limited to 'src')
-rw-r--r-- | src/session-child.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/session-child.c b/src/session-child.c index f871069f..77cca0ef 100644 --- a/src/session-child.c +++ b/src/session-child.c @@ -11,6 +11,7 @@ #include <grp.h> #include <glib.h> #include <security/pam_appl.h> +#include <utmpx.h> #include "session-child.h" #include "session.h" @@ -458,6 +459,32 @@ 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) @@ -531,6 +558,32 @@ session_child_run (int argc, char **argv) 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 (); + } + /* Remove X authority */ if (xauthority) { |