chiark / gitweb /
cgroup: honour sticky bit when trimming cgroup trees
[elogind.git] / src / user-sessions.c
index d3faad0cd60d3ce46daad9a90e6e4b59262ba12e..df46b76c872842597597e1661da4b7e29ec1a329 100644 (file)
@@ -39,17 +39,27 @@ int main(int argc, char*argv[]) {
         log_parse_environment();
         log_open();
 
+        umask(0022);
+
         if (streq(argv[1], "start")) {
                 int q = 0, r = 0;
 
-                if (unlink("/var/run/nologin") < 0 && errno != ENOENT) {
-                        log_error("Failed to remove /var/run/nologin file: %m");
+                if (unlink("/run/nologin") < 0 && errno != ENOENT) {
+                        log_error("Failed to remove /run/nologin file: %m");
                         r = -errno;
                 }
 
                 if (unlink("/etc/nologin") < 0 && errno != ENOENT) {
-                        log_error("Failed to remove /etc/nologin file: %m");
-                        q = -errno;
+
+                        /* If the file doesn't exist and /etc simply
+                         * was read-only (in which case unlink()
+                         * returns EROFS even if the file doesn't
+                         * exist), don't complain */
+
+                        if (errno != EROFS || access("/etc/nologin", F_OK) >= 0) {
+                                log_error("Failed to remove /etc/nologin file: %m");
+                                q = -errno;
+                        }
                 }
 
                 if (r < 0 || q < 0)
@@ -59,8 +69,8 @@ int main(int argc, char*argv[]) {
                 int r, q;
                 char *cgroup_user_tree = NULL;
 
-                if ((r = write_one_line_file("/var/run/nologin", "System is going down.")) < 0)
-                        log_error("Failed to create /var/run/nologin: %s", strerror(-r));
+                if ((r = write_one_line_file_atomic("/run/nologin", "System is going down.")) < 0)
+                        log_error("Failed to create /run/nologin: %s", strerror(-r));
 
                 if ((q = cg_get_user_path(&cgroup_user_tree)) < 0) {
                         log_error("Failed to determine use path: %s", strerror(-q));