summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2012-11-21 14:48:05 +1300
committerRobert Ancell <robert.ancell@canonical.com>2012-11-21 14:48:05 +1300
commit52b6681ec69f208dac6740ad776e4bfb438c14b1 (patch)
treeb8940d8c8e9a158031b714d3579100072bc6d5c7
parentf855954f5ece2093fb532c31f9e36f073f9dac54 (diff)
downloadlightdm-git-1.2.3.tar.gz
Write utmp records for sessions1.2.3
-rw-r--r--NEWS1
-rw-r--r--src/session-child.c49
2 files changed, 50 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index b2ff5c43..e60a1ffc 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ Overview of changes in lightdm 1.2.3
* Move from QString::fromLocal8Bit to QString::fromUtf8 when converting from
gchar
* Support multiple simultaneous PAM prompts
+ * Write utmp records for sessions
Overview of changes in lightdm 1.2.2
diff --git a/src/session-child.c b/src/session-child.c
index b04ae2d9..dfb1d2a1 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"
@@ -522,8 +523,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));
+ 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 */