2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2010-10-07 22:38:40 +02:00
|
|
|
|
|
|
|
#include <errno.h>
|
2015-10-24 22:58:24 +02:00
|
|
|
#include <unistd.h>
|
2010-10-07 22:38:40 +02:00
|
|
|
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "fileio.h"
|
2015-12-04 21:33:42 +01:00
|
|
|
#include "fileio-label.h"
|
2018-02-16 06:58:33 +01:00
|
|
|
#include "fs-util.h"
|
2010-10-07 22:38:40 +02:00
|
|
|
#include "log.h"
|
2015-12-04 21:33:42 +01:00
|
|
|
#include "selinux-util.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "string-util.h"
|
2010-10-07 22:38:40 +02:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
int main(int argc, char*argv[]) {
|
2018-02-16 06:58:33 +01:00
|
|
|
int r, k;
|
2010-10-07 22:38:40 +02:00
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
log_error("This program requires one argument.");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-01-12 05:09:06 +01:00
|
|
|
log_set_target(LOG_TARGET_AUTO);
|
2010-10-07 22:38:40 +02:00
|
|
|
log_parse_environment();
|
|
|
|
log_open();
|
|
|
|
|
2011-08-01 20:52:18 +02:00
|
|
|
umask(0022);
|
|
|
|
|
2016-03-02 02:35:55 +01:00
|
|
|
mac_selinux_init();
|
2015-12-04 21:33:42 +01:00
|
|
|
|
2010-10-07 22:38:40 +02:00
|
|
|
if (streq(argv[1], "start")) {
|
2018-02-16 06:58:33 +01:00
|
|
|
r = unlink_or_warn("/run/nologin");
|
|
|
|
k = unlink_or_warn("/etc/nologin");
|
2018-02-21 23:42:58 +01:00
|
|
|
if (k < 0 && r >= 0)
|
|
|
|
r = k;
|
2010-10-07 23:16:48 +02:00
|
|
|
|
2018-02-22 14:21:30 +01:00
|
|
|
} else if (streq(argv[1], "stop"))
|
|
|
|
r = create_shutdown_run_nologin_or_warn();
|
|
|
|
else {
|
2018-02-21 23:42:58 +01:00
|
|
|
log_error("Unknown verb '%s'.", argv[1]);
|
|
|
|
r = -EINVAL;
|
2010-10-07 22:38:40 +02:00
|
|
|
}
|
|
|
|
|
2015-12-04 21:33:42 +01:00
|
|
|
mac_selinux_finish();
|
2018-02-21 23:42:58 +01:00
|
|
|
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
|
2010-10-07 22:38:40 +02:00
|
|
|
}
|