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>
|
2019-03-27 11:32:41 +01:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.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"
|
2018-11-20 16:40:49 +01:00
|
|
|
#include "main-func.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
|
|
|
|
2018-12-04 09:29:54 +01:00
|
|
|
static int run(int argc, char *argv[]) {
|
2018-02-16 06:58:33 +01:00
|
|
|
int r, k;
|
2010-10-07 22:38:40 +02:00
|
|
|
|
2018-11-20 23:40:44 +01:00
|
|
|
if (argc != 2)
|
|
|
|
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
|
|
|
"This program requires one argument.");
|
2010-10-07 22:38:40 +02:00
|
|
|
|
2018-11-20 11:18:22 +01:00
|
|
|
log_setup_service();
|
2010-10-07 22:38:40 +02:00
|
|
|
|
2011-08-01 20:52:18 +02:00
|
|
|
umask(0022);
|
|
|
|
|
2020-06-19 19:29:24 +02:00
|
|
|
r = mac_selinux_init();
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
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-11-20 16:40:49 +01:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
return k;
|
2010-10-07 23:16:48 +02:00
|
|
|
|
2018-02-22 14:21:30 +01:00
|
|
|
} else if (streq(argv[1], "stop"))
|
2018-11-20 16:40:49 +01:00
|
|
|
return create_shutdown_run_nologin_or_warn();
|
2010-10-07 22:38:40 +02:00
|
|
|
|
2018-11-20 23:40:44 +01:00
|
|
|
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown verb '%s'.", argv[1]);
|
2010-10-07 22:38:40 +02:00
|
|
|
}
|
2018-11-20 16:40:49 +01:00
|
|
|
|
|
|
|
DEFINE_MAIN_FUNCTION(run);
|