]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/user-sessions/user-sessions.c
Merge pull request #653 from dvdhrm/bus-gold
[thirdparty/systemd.git] / src / user-sessions / user-sessions.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2010 Lennart Poettering
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include <errno.h>
21 #include <unistd.h>
22
23 #include "fileio.h"
24 #include "fileio-label.h"
25 #include "log.h"
26 #include "selinux-util.h"
27 #include "string-util.h"
28 #include "util.h"
29
30 int main(int argc, char*argv[]) {
31
32 if (argc != 2) {
33 log_error("This program requires one argument.");
34 return EXIT_FAILURE;
35 }
36
37 log_set_target(LOG_TARGET_AUTO);
38 log_parse_environment();
39 log_open();
40
41 umask(0022);
42
43 mac_selinux_init();
44
45 if (streq(argv[1], "start")) {
46 int r = 0;
47
48 if (unlink("/run/nologin") < 0 && errno != ENOENT)
49 r = log_error_errno(errno,
50 "Failed to remove /run/nologin file: %m");
51
52 if (unlink("/etc/nologin") < 0 && errno != ENOENT) {
53 /* If the file doesn't exist and /etc simply
54 * was read-only (in which case unlink()
55 * returns EROFS even if the file doesn't
56 * exist), don't complain */
57
58 if (errno != EROFS || access("/etc/nologin", F_OK) >= 0) {
59 log_error_errno(errno, "Failed to remove /etc/nologin file: %m");
60 return EXIT_FAILURE;
61 }
62 }
63
64 if (r < 0)
65 return EXIT_FAILURE;
66
67 } else if (streq(argv[1], "stop")) {
68 int r;
69
70 r = write_string_file_atomic_label("/run/nologin", "System is going down.");
71 if (r < 0) {
72 log_error_errno(r, "Failed to create /run/nologin: %m");
73 return EXIT_FAILURE;
74 }
75
76 } else {
77 log_error("Unknown verb %s.", argv[1]);
78 return EXIT_FAILURE;
79 }
80
81 mac_selinux_finish();
82
83 return EXIT_SUCCESS;
84 }