~ubuntu-branches/debian/jessie/systemd/jessie

« back to all changes in this revision

Viewing changes to src/shutdown.c

  • Committer: Package Import Robot
  • Author(s): Tollef Fog Heen, Tollef Fog Heen, Michael Biebl
  • Date: 2012-04-03 19:59:17 UTC
  • mfrom: (1.1.10) (6.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20120403195917-l532urrbg4pkreas
Tags: 44-1
[ Tollef Fog Heen ]
* New upstream version.
  - Backport 3492207: journal: PAGE_SIZE is not known on ppc and other
    archs
  - Backport 5a2a2a1: journal: react with immediate rotation to a couple
    of more errors
  - Backport 693ce21: util: never follow symlinks in rm_rf_children()
    Fixes CVE-2012-1174, closes: #664364
* Drop output message from init-functions hook, it's pointless.
* Only rmdir /lib/init/rw if it exists.
* Explicitly order debian-fixup before sysinit.target to prevent a
  possible race condition with the creation of sockets.  Thanks to
  Michael Biebl for debugging this.
* Always restart the initctl socket on upgrades, to mask sysvinit
  removing it.

[ Michael Biebl ]
* Remove workaround for non-interactive sessions from pam config again.
* Create compat /dev/initctl symlink in case we are upgrading from a system
  running a newer version of sysvinit (using /run/initctl) and sysvinit is
  replaced with systemd-sysv during the upgrade. Closes: #663219
* Install new man pages.
* Build-Depend on valac (>= 0.12) instead of valac-0.12. Closes: #663323

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
#define FINALIZE_ATTEMPTS 50
48
48
 
49
49
static bool ignore_proc(pid_t pid) {
50
 
        if (pid == 1)
51
 
                return true;
52
 
 
53
 
        /* TODO: add more ignore rules here: device-mapper, etc */
54
 
 
55
 
        return false;
56
 
}
57
 
 
58
 
static bool is_kernel_thread(pid_t pid)
59
 
{
60
50
        char buf[PATH_MAX];
61
51
        FILE *f;
62
52
        char c;
63
53
        size_t count;
64
 
 
65
 
        snprintf(buf, sizeof(buf), "/proc/%lu/cmdline", (unsigned long)pid);
 
54
        uid_t uid;
 
55
        int r;
 
56
 
 
57
        /* We are PID 1, let's not commit suicide */
 
58
        if (pid == 1)
 
59
                return true;
 
60
 
 
61
        r = get_process_uid(pid, &uid);
 
62
        if (r < 0)
 
63
                return true; /* not really, but better safe than sorry */
 
64
 
 
65
        /* Non-root processes otherwise are always subject to be killed */
 
66
        if (uid != 0)
 
67
                return false;
 
68
 
 
69
        snprintf(buf, sizeof(buf), "/proc/%lu/cmdline", (unsigned long) pid);
 
70
        char_array_0(buf);
 
71
 
66
72
        f = fopen(buf, "re");
67
73
        if (!f)
68
74
                return true; /* not really, but has the desired effect */
69
75
 
70
76
        count = fread(&c, 1, 1, f);
71
77
        fclose(f);
72
 
        return count != 1;
 
78
 
 
79
        /* Kernel threads have an empty cmdline */
 
80
        if (count <= 0)
 
81
                return true;
 
82
 
 
83
        /* Processes with argv[0][0] = '@' we ignore from the killing
 
84
         * spree.
 
85
         *
 
86
         * http://www.freedesktop.org/wiki/Software/systemd/RootStorageDaemons */
 
87
        if (count == 1 && c == '@')
 
88
                return true;
 
89
 
 
90
        return false;
73
91
}
74
92
 
75
93
static int killall(int sign) {
77
95
        struct dirent *d;
78
96
        unsigned int n_processes = 0;
79
97
 
80
 
        if ((dir = opendir("/proc")) == NULL)
 
98
        dir = opendir("/proc");
 
99
        if (!dir)
81
100
                return -errno;
82
101
 
83
102
        while ((d = readdir(dir))) {
86
105
                if (parse_pid(d->d_name, &pid) < 0)
87
106
                        continue;
88
107
 
89
 
                if (is_kernel_thread(pid))
90
 
                        continue;
91
 
 
92
108
                if (ignore_proc(pid))
93
109
                        continue;
94
110