]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blobdiff - src/session-child.c
Re-enable SIGPIPE for children so they have default behaviour
[sojka/lightdm.git] / src / session-child.c
index c5b5c211edf9fbe67a08d5a62dc1a07b3d30b524..fb12d9b812d02f0ee9ebf3a35a53a74249cd5f0b 100644 (file)
@@ -26,6 +26,7 @@
 #include "session.h"
 #include "console-kit.h"
 #include "login1.h"
+#include "log-file.h"
 #include "privileges.h"
 #include "x-authority.h"
 #include "configuration.h"
@@ -257,7 +258,8 @@ session_child_run (int argc, char **argv)
     int i, version, fd, result;
     gboolean auth_complete = TRUE;
     User *user = NULL;
-    gchar *log_filename, *log_backup_filename = NULL;
+    gchar *log_filename;
+    LogMode log_mode = LOG_MODE_BACKUP_AND_TRUNCATE;
     gsize env_length;
     gsize command_argc;
     gchar **command_argv;
@@ -278,6 +280,12 @@ session_child_run (int argc, char **argv)
     const gchar *locale_value;
     gchar *locale_var;
     static const gchar * const locale_var_names[] = {
+        "LC_PAPER",
+        "LC_NAME",
+        "LC_ADDRESS",
+        "LC_TELEPHONE",
+        "LC_MEASUREMENT",
+        "LC_IDENTIFICATION",
         "LC_COLLATE",
         "LC_CTYPE",
         "LC_MONETARY",
@@ -400,11 +408,8 @@ session_child_run (int argc, char **argv)
             ut.ut_type = USER_PROCESS;
             ut.ut_pid = getpid ();
             if (xdisplay)
-            {
-                strncpy (ut.ut_line, xdisplay, sizeof (ut.ut_line));
                 strncpy (ut.ut_id, xdisplay, sizeof (ut.ut_id));
-            }
-            else if (tty)
+            if (tty && g_str_has_prefix (tty, "/dev/"))
                 strncpy (ut.ut_line, tty + strlen ("/dev/"), sizeof (ut.ut_line));
             strncpy (ut.ut_user, username, sizeof (ut.ut_user));
             if (xdisplay)
@@ -488,6 +493,8 @@ session_child_run (int argc, char **argv)
 
     /* Get the command to run (blocks) */
     log_filename = read_string ();
+    if (version >= 3)
+        read_data (&log_mode, sizeof (log_mode));
     if (version >= 1)
     {
         g_free (tty);
@@ -522,11 +529,9 @@ session_child_run (int argc, char **argv)
     /* Redirect stderr to a log file */
     if (log_filename)
     {
-        log_backup_filename = g_strdup_printf ("%s.old", log_filename);
         if (g_path_is_absolute (log_filename))
         {
-            rename (log_filename, log_backup_filename);
-            fd = open (log_filename, O_WRONLY | O_APPEND | O_CREAT, 0600);
+            fd = log_file_open (log_filename, log_mode);
             dup2 (fd, STDERR_FILENO);
             close (fd);
             g_free (log_filename);
@@ -613,9 +618,20 @@ session_child_run (int argc, char **argv)
         if (console_kit_cookie)
         {
             gchar *value;
+            gchar *runtime_dir;
             value = g_strdup_printf ("XDG_SESSION_COOKIE=%s", console_kit_cookie);
             pam_putenv (pam_handle, value);
             g_free (value);
+
+            runtime_dir = ck_get_xdg_runtime_dir (console_kit_cookie);
+            if (runtime_dir)
+            {
+                gchar *value;
+                value = g_strdup_printf ("XDG_RUNTIME_DIR=%s", runtime_dir);
+                pam_putenv (pam_handle, value);
+                g_free (value);
+                g_free (runtime_dir);
+            }
         }
     }
 
@@ -680,8 +696,7 @@ session_child_run (int argc, char **argv)
 
         if (log_filename)
         {
-            rename (log_filename, log_backup_filename);
-            fd = open (log_filename, O_WRONLY | O_APPEND | O_CREAT, 0600);
+            fd = log_file_open (log_filename, log_mode);
             if (fd >= 0)
             {
                 dup2 (fd, STDERR_FILENO);
@@ -689,6 +704,9 @@ session_child_run (int argc, char **argv)
             }
         }
 
+        /* Reset SIGPIPE handler so the child has default behaviour (we disabled it at LightDM start) */
+        signal (SIGPIPE, SIG_DFL);
+
         /* Run the command */
         execve (command_argv[0], command_argv, pam_getenvlist (pam_handle));
         _exit (EXIT_FAILURE);
@@ -714,11 +732,8 @@ session_child_run (int argc, char **argv)
             ut.ut_type = USER_PROCESS;
             ut.ut_pid = child_pid;
             if (xdisplay)
-            {
-                strncpy (ut.ut_line, xdisplay, sizeof (ut.ut_line));
                 strncpy (ut.ut_id, xdisplay, sizeof (ut.ut_id));
-            }
-            else if (tty)
+            if (tty && g_str_has_prefix (tty, "/dev/"))
                 strncpy (ut.ut_line, tty + strlen ("/dev/"), sizeof (ut.ut_line));
             strncpy (ut.ut_user, username, sizeof (ut.ut_user));
             if (xdisplay)
@@ -754,11 +769,8 @@ session_child_run (int argc, char **argv)
             ut.ut_type = DEAD_PROCESS;
             ut.ut_pid = child_pid;
             if (xdisplay)
-            {
-                strncpy (ut.ut_line, xdisplay, sizeof (ut.ut_line));
                 strncpy (ut.ut_id, xdisplay, sizeof (ut.ut_id));
-            }
-            else if (tty)
+            if (tty && g_str_has_prefix (tty, "/dev/"))
                 strncpy (ut.ut_line, tty + strlen ("/dev/"), sizeof (ut.ut_line));
             strncpy (ut.ut_user, username, sizeof (ut.ut_user));
             if (xdisplay)