-/***
- This file is part of systemd.
-
- Copyright 2010 Lennart Poettering
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
+/* SPDX-License-Identifier: LGPL-2.1+ */
#include <ctype.h>
#include <errno.h>
#include "bus-util.h"
#include "def.h"
#include "fd-util.h"
-#include "formats-util.h"
+#include "format-util.h"
#include "initreq.h"
#include "list.h"
#include "log.h"
#include "special.h"
#include "util.h"
+#include "process-util.h"
#define SERVER_FD_MAX 16
#define TIMEOUT_MSEC ((int) (DEFAULT_EXIT_USEC/USEC_PER_MSEC))
return NULL;
}
-static void change_runlevel(Server *s, int runlevel) {
+static int change_runlevel(Server *s, int runlevel) {
const char *target;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
const char *mode;
target = translate_runlevel(runlevel, &isolate);
if (!target) {
log_warning("Got request for unknown runlevel %c, ignoring.", runlevel);
- return;
+ return 0;
}
if (isolate)
&error,
NULL,
"ss", target, mode);
- if (r < 0) {
- log_error("Failed to change runlevel: %s", bus_error_message(&error, -r));
- return;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to change runlevel: %s", bus_error_message(&error, -r));
+
+ return 0;
}
static void request_process(Server *s, const struct init_request *req) {
break;
default:
- change_runlevel(s, req->runlevel);
+ (void) change_runlevel(s, req->runlevel);
}
return;
while (s->fifos)
fifo_free(s->fifos);
- safe_close(s->epoll_fd);
-
- if (s->bus) {
- sd_bus_flush(s->bus);
- sd_bus_unref(s->bus);
- }
+ s->epoll_fd = safe_close(s->epoll_fd);
+ s->bus = sd_bus_flush_close_unref(s->bus);
}
static int server_init(Server *s, unsigned n_sockets) {
f->fd = fd;
LIST_PREPEND(fifo, s->fifos, f);
f->server = s;
- s->n_fifos ++;
+ s->n_fifos++;
}
r = bus_connect_system_systemd(&s->bus);
assert(s);
- if (!(ev->events & EPOLLIN)) {
- log_info("Got invalid event from epoll. (3)");
- return -EIO;
- }
+ if (!(ev->events & EPOLLIN))
+ return log_info_errno(SYNTHETIC_ERRNO(EIO),
+ "Got invalid event from epoll. (3)");
f = (Fifo*) ev->data.ptr;
r = fifo_process(f);
return EXIT_FAILURE;
}
- log_set_target(LOG_TARGET_AUTO);
- log_parse_environment();
- log_open();
+ log_setup_service();
umask(0022);
if (server_init(&server, (unsigned) n) < 0)
return EXIT_FAILURE;
- log_debug("systemd-initctl running as pid "PID_FMT, getpid());
+ log_debug("systemd-initctl running as pid "PID_FMT, getpid_cached());
sd_notify(false,
"READY=1\n"
r = EXIT_SUCCESS;
- log_debug("systemd-initctl stopped as pid "PID_FMT, getpid());
+ log_debug("systemd-initctl stopped as pid "PID_FMT, getpid_cached());
fail:
sd_notify(false,