~ubuntu-branches/ubuntu/trusty/gdm/trusty-proposed

« back to all changes in this revision

Viewing changes to daemon/gdm-session-worker.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha, Tim Lunn, Jeremy Bicha, Robert Ancell
  • Date: 2013-05-31 22:36:08 UTC
  • mfrom: (1.4.55)
  • Revision ID: package-import@ubuntu.com-20130531223608-33uo85niksee5460
Tags: 3.8.1.1-0ubuntu1
[ Tim Lunn ]
* New upstream release
* debian/patches/ubuntu_dont_catch_sigsegv.patch:
  - Dropped, obsolete
* debian/rules:
  - Don't rename gdm binary since that's already been
    done in the new version

[ Jeremy Bicha ]
* debian/control.in: Bump minimum glib
* debian/watch: Watch for unstable releases
* debian/patches/00git_logind_check.patch:
  - Dropped, applied in new release
* debian/patches/08_frequent-users_greeter.patch: Refreshed

[ Robert Ancell ]
* New upstream release
* debian/patches/ubuntu_daemon_autologin_tracking.patch:
* debian/patches/ubuntu_ensure_dirs.patch:
* debian/patches/ubuntu_slave-only-set-up-autologin.patch:
  - Applied upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
#include <security/pam_appl.h>
36
36
 
 
37
#ifdef HAVE_LOGINCAP
 
38
#include <login_cap.h>
 
39
#endif
 
40
 
37
41
#include <glib.h>
38
42
#include <glib/gi18n.h>
39
43
#include <glib/gstdio.h>
46
50
#include <systemd/sd-daemon.h>
47
51
#endif
48
52
 
 
53
#ifdef ENABLE_SYSTEMD_JOURNAL
 
54
#include <systemd/sd-journal.h>
 
55
#endif
 
56
 
49
57
#ifdef HAVE_SELINUX
50
58
#include <selinux/selinux.h>
51
59
#endif /* HAVE_SELINUX */
1782
1790
                const char * const * environment;
1783
1791
                char  *kerberos_cache;
1784
1792
                char  *home_dir;
1785
 
                int    fd;
1786
 
 
1787
 
                fd = open ("/dev/null", O_RDWR);
1788
 
                dup2 (fd, STDIN_FILENO);
1789
 
                close (fd);
1790
 
 
1791
 
                if (worker->priv->is_program_session) {
1792
 
                        fd = _open_program_session_log (worker->priv->log_file);
 
1793
                int    stdin_fd = -1, stdout_fd = -1, stderr_fd = -1;
 
1794
                gboolean has_journald = FALSE;
 
1795
 
 
1796
                stdin_fd = open ("/dev/null", O_RDWR);
 
1797
                dup2 (stdin_fd, STDIN_FILENO);
 
1798
                close (stdin_fd);
 
1799
 
 
1800
#ifdef ENABLE_SYSTEMD_JOURNAL
 
1801
                has_journald = sd_booted() > 0;
 
1802
#endif
 
1803
                if (!has_journald && worker->priv->is_program_session) {
 
1804
                        stdout_fd = _open_program_session_log (worker->priv->log_file);
 
1805
                        stderr_fd = dup (stdout_fd);
1793
1806
                }
1794
1807
 
 
1808
#ifdef HAVE_LOGINCAP
 
1809
                if (setusercontext (NULL, passwd_entry, passwd_entry->pw_uid, LOGIN_SETALL) < 0) {
 
1810
                        g_debug ("GdmSessionWorker: setusercontext() failed for user %s: %s",
 
1811
                                 passwd_entry->pw_name, g_strerror (errno));
 
1812
                        _exit (1);
 
1813
                }       
 
1814
#else
1795
1815
                if (setuid (worker->priv->uid) < 0) {
1796
1816
                        g_debug ("GdmSessionWorker: could not reset uid: %s", g_strerror (errno));
1797
1817
                        _exit (1);
1798
1818
                }
 
1819
#endif
1799
1820
 
1800
1821
                if (setsid () < 0) {
1801
1822
                        g_debug ("GdmSessionWorker: could not set pid '%u' as leader of new session and process group: %s",
1834
1855
                        g_chdir ("/");
1835
1856
                }
1836
1857
 
1837
 
                if (!worker->priv->is_program_session) {
 
1858
#ifdef ENABLE_SYSTEMD_JOURNAL
 
1859
                if (has_journald) {
 
1860
                        stdout_fd = sd_journal_stream_fd (worker->priv->arguments[0], LOG_INFO, FALSE);
 
1861
                        stderr_fd = sd_journal_stream_fd (worker->priv->arguments[0], LOG_WARNING, FALSE);
 
1862
 
 
1863
                        /* Unset the CLOEXEC flags, because sd_journal_stream_fd
 
1864
                         * gives it to us by default.
 
1865
                         */
 
1866
                        gdm_clear_close_on_exec_flag (stdout_fd);
 
1867
                        gdm_clear_close_on_exec_flag (stderr_fd);
 
1868
                }
 
1869
#endif
 
1870
                if (!has_journald && !worker->priv->is_program_session) {
1838
1871
                        if (home_dir != NULL && home_dir[0] != '\0') {
1839
1872
                                char *cache_dir;
1840
1873
                                char *log_dir;
1848
1881
                                g_free (cache_dir);
1849
1882
 
1850
1883
                                if (g_mkdir_with_parents (log_dir, S_IRWXU) == 0) {
1851
 
                                        fd = _open_user_session_log (log_dir);
 
1884
                                        stdout_fd = _open_user_session_log (log_dir);
 
1885
                                        stderr_fd = dup (stdout_fd);
1852
1886
                                } else {
1853
 
                                        fd = open ("/dev/null", O_RDWR);
 
1887
                                        stdout_fd = open ("/dev/null", O_RDWR);
 
1888
                                        stderr_fd = dup (stdout_fd);
1854
1889
                                }
1855
1890
                                g_free (log_dir);
1856
1891
                        } else {
1857
 
                                fd = open ("/dev/null", O_RDWR);
 
1892
                                stdout_fd = open ("/dev/null", O_RDWR);
 
1893
                                stderr_fd = dup (stdout_fd);
1858
1894
                        }
1859
1895
                }
1860
1896
                g_free (home_dir);
1861
1897
 
1862
 
                dup2 (fd, STDOUT_FILENO);
1863
 
                dup2 (fd, STDERR_FILENO);
1864
 
                close (fd);
 
1898
                if (stdout_fd != -1) {
 
1899
                        dup2 (stdout_fd, STDOUT_FILENO);
 
1900
                        close (stdout_fd);
 
1901
                }
 
1902
 
 
1903
                if (stderr_fd != -1) {
 
1904
                        dup2 (stderr_fd, STDERR_FILENO);
 
1905
                        close (stderr_fd);
 
1906
                }
1865
1907
 
1866
1908
                gdm_log_shutdown ();
1867
1909