initctl.c revision 514f4ef52f91edb3741cad88d34572d162459346
d1fab3fe88ae873b26b50359758776ad9e31968eZbigniew Jędrzejewski-Szmek/*-*- Mode: C; c-basic-offset: 8 -*-*/
d1fab3fe88ae873b26b50359758776ad9e31968eZbigniew Jędrzejewski-Szmek This file is part of systemd.
along with systemd; If not, see <http://www.gnu.org/licenses/>.
#include <assert.h>
#include <time.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
#include "util.h"
#include "log.h"
#include "list.h"
#include "initreq.h"
#include "special.h"
#include "sd-daemon.h"
typedef struct Server {
int epoll_fd;
unsigned n_fifos;
} Server;
struct Fifo {
int fd;
const int runlevel;
const char *special;
} table[] = {
return NULL;
const char *target;
assert(s);
goto finish;
if (!(m = dbus_message_new_method_call("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartUnit"))) {
goto finish;
if (!dbus_message_append_args(m,
goto finish;
goto finish;
if (reply)
assert(s);
case INIT_CMD_RUNLVL:
case INIT_CMD_POWERFAIL:
case INIT_CMD_POWERFAILNOW:
case INIT_CMD_POWEROK:
log_warning("Received UPS/power initctl request. This is not implemented in systemd. Upgrade your UPS daemon!");
case INIT_CMD_CHANGECONS:
case INIT_CMD_SETENV:
case INIT_CMD_UNSETENV:
ssize_t l;
assert(f);
if ((l = read(f->fd, ((uint8_t*) &f->buffer) + f->bytes_read, sizeof(f->buffer) - f->bytes_read)) <= 0) {
f->bytes_read += l;
f->bytes_read = 0;
assert(f);
if (f->server) {
if (f->fd >= 0) {
if (f->server)
free(f);
assert(s);
while (s->fifos)
if (s->epoll_fd >= 0)
if (s->bus) {
assert(s);
zero(*s);
r = -errno;
goto fail;
for (i = 0; i < n_sockets; i++) {
Fifo *f;
int fd;
goto fail;
r = -EINVAL;
goto fail;
r = -ENOMEM;
goto fail;
r = -errno;
fifo_free(f);
goto fail;
f->server = s;
s->n_fifos ++;
goto fail;
fail:
server_done(s);
Fifo *f;
assert(s);
return -EIO;
if ((r = fifo_process(f)) < 0) {
fifo_free(f);
if ((n = sd_listen_fds(true)) < 0) {
if (n <= 0 || n > SERVER_FD_MAX) {
sd_notify(false,
TIMEOUT)) < 0) {
goto fail;
goto fail;
fail:
sd_notify(false,