From 0b3f8750e7d307987eef9e63e327488a81c29a71 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 9 Apr 2022 22:54:03 -0500 Subject: openrc-shutdown: remove rc- prefix from file names --- src/openrc-shutdown/meson.build | 2 +- src/openrc-shutdown/openrc-shutdown.c | 2 +- src/openrc-shutdown/rc-sysvinit.c | 102 ---------------------------------- src/openrc-shutdown/rc-sysvinit.h | 72 ------------------------ src/openrc-shutdown/sysvinit.c | 102 ++++++++++++++++++++++++++++++++++ src/openrc-shutdown/sysvinit.h | 72 ++++++++++++++++++++++++ 6 files changed, 176 insertions(+), 176 deletions(-) delete mode 100644 src/openrc-shutdown/rc-sysvinit.c delete mode 100644 src/openrc-shutdown/rc-sysvinit.h create mode 100644 src/openrc-shutdown/sysvinit.c create mode 100644 src/openrc-shutdown/sysvinit.h (limited to 'src/openrc-shutdown') diff --git a/src/openrc-shutdown/meson.build b/src/openrc-shutdown/meson.build index bdd58338..e380b5e3 100644 --- a/src/openrc-shutdown/meson.build +++ b/src/openrc-shutdown/meson.build @@ -1,6 +1,6 @@ if os == 'Linux' executable('openrc-shutdown', - ['openrc-shutdown.c', 'broadcast.c', 'rc-sysvinit.c', misc_c, + ['openrc-shutdown.c', 'broadcast.c', 'sysvinit.c', misc_c, usage_c, wtmp_c, version_h], c_args : cc_branding_flags, include_directories: [incdir, einfo_incdir, rc_incdir], diff --git a/src/openrc-shutdown/openrc-shutdown.c b/src/openrc-shutdown/openrc-shutdown.c index 1234dcfc..6255a485 100644 --- a/src/openrc-shutdown/openrc-shutdown.c +++ b/src/openrc-shutdown/openrc-shutdown.c @@ -35,7 +35,7 @@ #include "rc.h" #include "helpers.h" #include "misc.h" -#include "rc-sysvinit.h" +#include "sysvinit.h" #include "wtmp.h" #include "_usage.h" diff --git a/src/openrc-shutdown/rc-sysvinit.c b/src/openrc-shutdown/rc-sysvinit.c deleted file mode 100644 index 8d258b63..00000000 --- a/src/openrc-shutdown/rc-sysvinit.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * rc-sysvinit.c - * Helper to send a runlevel change to sysvinit - */ - -/* - * Copyright (c) 2019 The OpenRC Authors. - * See the Authors file at the top-level directory of this distribution and - * https://github.com/OpenRC/openrc/blob/HEAD/AUTHORS - * - * This file is part of OpenRC. It is subject to the license terms in - * the LICENSE file found in the top-level directory of this - * distribution and at https://github.com/OpenRC/openrc/blob/HEAD/LICENSE - * This file may not be copied, modified, propagated, or distributed - * except according to the terms contained in the LICENSE file. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "einfo.h" -#include "rc-sysvinit.h" - -static void sysvinit_send_cmd(struct init_request *request) -{ - int fd; - char *p; - size_t bytes; - ssize_t r; - - fd = open("/run/initctl", O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY); - if (fd < 0) { - if (errno != ENOENT) - eerror("Failed to open initctl fifo: %s", strerror(errno)); - return; - } - p = (char *) request; - bytes = sizeof(*request); - do { - r = write(fd, p, bytes); - if (r < 0) { - if ((errno == EAGAIN) || (errno == EINTR)) - continue; - eerror("Failed to write to /run/initctl: %s", strerror(errno)); - return; - } - p += r; - bytes -= r; - } while (bytes > 0); -} - -void sysvinit_runlevel(char rl) -{ - struct init_request request; - - if (!rl) - return; - - request = (struct init_request) { - .magic = INIT_MAGIC, - .sleeptime = 0, - .cmd = INIT_CMD_RUNLVL, - .runlevel = rl, - }; - sysvinit_send_cmd(&request); - return; -} - -/* - * Set environment variables in the init process. - */ -void sysvinit_setenv(const char *name, const char *value) -{ - struct init_request request; - size_t nl; - size_t vl; - - memset(&request, 0, sizeof(request)); - request.magic = INIT_MAGIC; - request.cmd = INIT_CMD_SETENV; - nl = strlen(name); - if (value) - vl = strlen(value); -else - vl = 0; - - if (nl + vl + 3 >= (int)sizeof(request.i.data)) - return; - - memcpy(request.i.data, name, nl); - if (value) { - request.i.data[nl] = '='; - memcpy(request.i.data + nl + 1, value, vl); - } - sysvinit_send_cmd(&request); - return; -} diff --git a/src/openrc-shutdown/rc-sysvinit.h b/src/openrc-shutdown/rc-sysvinit.h deleted file mode 100644 index 6142cdd6..00000000 --- a/src/openrc-shutdown/rc-sysvinit.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * rc-sysvinit.h - Interface to communicate with sysvinit via /run/initctl. - */ - -/* - * Copyright (c) 2019 The OpenRC Authors. - * See the Authors file at the top-level directory of this distribution and - * https://github.com/OpenRC/openrc/blob/HEAD/AUTHORS - * - * This file is part of OpenRC. It is subject to the license terms in - * the LICENSE file found in the top-level directory of this - * distribution and at https://github.com/OpenRC/openrc/blob/HEAD/LICENSE - * This file may not be copied, modified, propagated, or distributed - * except according to the terms contained in the LICENSE file. - */ - -#ifndef _RC_SYSVINIT_H -#define _RC_SYSVINIT_H - -/* - * The #defines and structures below are taken from initreq.h in - * sysvinit and must be used by any program wishing to communicate with - * it. - */ - -#define INIT_MAGIC 0x03091969 -#define INIT_CMD_START 0 -#define INIT_CMD_RUNLVL 1 -#define INIT_CMD_POWERFAIL 2 -#define INIT_CMD_POWERFAILNOW 3 -#define INIT_CMD_POWEROK 4 -#define INIT_CMD_BSD 5 -#define INIT_CMD_SETENV 6 -#define INIT_CMD_UNSETENV 7 - -/* - * This is what BSD 4.4 uses when talking to init. - * Linux doesn't use this right now. - */ -struct init_request_bsd { - char gen_id[8]; /* Beats me.. telnetd uses "fe" */ - char tty_id[16]; /* Tty name minus /dev/tty */ - char host[64]; /* Hostname */ - char term_type[16]; /* Terminal type */ - int signal; /* Signal to send */ - int pid; /* Process to send to */ - char exec_name[128]; /* Program to execute */ - char reserved[128]; /* For future expansion. */ -}; - -/* - * Because of legacy interfaces, "runlevel" and "sleeptime" - * aren't in a seperate struct in the union. - * - * The weird sizes are because init expects the whole - * struct to be 384 bytes. - */ -struct init_request { - int magic; /* Magic number */ - int cmd; /* What kind of request */ - int runlevel; /* Runlevel to change to */ - int sleeptime; /* Time between TERM and KILL */ - union { - struct init_request_bsd bsd; - char data[368]; - } i; -}; - -void sysvinit_runlevel(char rl); -void sysvinit_setenv(const char *name, const char *value); - -#endif diff --git a/src/openrc-shutdown/sysvinit.c b/src/openrc-shutdown/sysvinit.c new file mode 100644 index 00000000..84fc9ec2 --- /dev/null +++ b/src/openrc-shutdown/sysvinit.c @@ -0,0 +1,102 @@ +/* + * sysvinit.c + * Helper to send a runlevel change to sysvinit + */ + +/* + * Copyright (c) 2019 The OpenRC Authors. + * See the Authors file at the top-level directory of this distribution and + * https://github.com/OpenRC/openrc/blob/HEAD/AUTHORS + * + * This file is part of OpenRC. It is subject to the license terms in + * the LICENSE file found in the top-level directory of this + * distribution and at https://github.com/OpenRC/openrc/blob/HEAD/LICENSE + * This file may not be copied, modified, propagated, or distributed + * except according to the terms contained in the LICENSE file. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "einfo.h" +#include "sysvinit.h" + +static void sysvinit_send_cmd(struct init_request *request) +{ + int fd; + char *p; + size_t bytes; + ssize_t r; + + fd = open("/run/initctl", O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY); + if (fd < 0) { + if (errno != ENOENT) + eerror("Failed to open initctl fifo: %s", strerror(errno)); + return; + } + p = (char *) request; + bytes = sizeof(*request); + do { + r = write(fd, p, bytes); + if (r < 0) { + if ((errno == EAGAIN) || (errno == EINTR)) + continue; + eerror("Failed to write to /run/initctl: %s", strerror(errno)); + return; + } + p += r; + bytes -= r; + } while (bytes > 0); +} + +void sysvinit_runlevel(char rl) +{ + struct init_request request; + + if (!rl) + return; + + request = (struct init_request) { + .magic = INIT_MAGIC, + .sleeptime = 0, + .cmd = INIT_CMD_RUNLVL, + .runlevel = rl, + }; + sysvinit_send_cmd(&request); + return; +} + +/* + * Set environment variables in the init process. + */ +void sysvinit_setenv(const char *name, const char *value) +{ + struct init_request request; + size_t nl; + size_t vl; + + memset(&request, 0, sizeof(request)); + request.magic = INIT_MAGIC; + request.cmd = INIT_CMD_SETENV; + nl = strlen(name); + if (value) + vl = strlen(value); +else + vl = 0; + + if (nl + vl + 3 >= (int)sizeof(request.i.data)) + return; + + memcpy(request.i.data, name, nl); + if (value) { + request.i.data[nl] = '='; + memcpy(request.i.data + nl + 1, value, vl); + } + sysvinit_send_cmd(&request); + return; +} diff --git a/src/openrc-shutdown/sysvinit.h b/src/openrc-shutdown/sysvinit.h new file mode 100644 index 00000000..5e3077cf --- /dev/null +++ b/src/openrc-shutdown/sysvinit.h @@ -0,0 +1,72 @@ +/* + * sysvinit.h - Interface to communicate with sysvinit via /run/initctl. + */ + +/* + * Copyright (c) 2019 The OpenRC Authors. + * See the Authors file at the top-level directory of this distribution and + * https://github.com/OpenRC/openrc/blob/HEAD/AUTHORS + * + * This file is part of OpenRC. It is subject to the license terms in + * the LICENSE file found in the top-level directory of this + * distribution and at https://github.com/OpenRC/openrc/blob/HEAD/LICENSE + * This file may not be copied, modified, propagated, or distributed + * except according to the terms contained in the LICENSE file. + */ + +#ifndef _RC_SYSVINIT_H +#define _RC_SYSVINIT_H + +/* + * The #defines and structures below are taken from initreq.h in + * sysvinit and must be used by any program wishing to communicate with + * it. + */ + +#define INIT_MAGIC 0x03091969 +#define INIT_CMD_START 0 +#define INIT_CMD_RUNLVL 1 +#define INIT_CMD_POWERFAIL 2 +#define INIT_CMD_POWERFAILNOW 3 +#define INIT_CMD_POWEROK 4 +#define INIT_CMD_BSD 5 +#define INIT_CMD_SETENV 6 +#define INIT_CMD_UNSETENV 7 + +/* + * This is what BSD 4.4 uses when talking to init. + * Linux doesn't use this right now. + */ +struct init_request_bsd { + char gen_id[8]; /* Beats me.. telnetd uses "fe" */ + char tty_id[16]; /* Tty name minus /dev/tty */ + char host[64]; /* Hostname */ + char term_type[16]; /* Terminal type */ + int signal; /* Signal to send */ + int pid; /* Process to send to */ + char exec_name[128]; /* Program to execute */ + char reserved[128]; /* For future expansion. */ +}; + +/* + * Because of legacy interfaces, "runlevel" and "sleeptime" + * aren't in a seperate struct in the union. + * + * The weird sizes are because init expects the whole + * struct to be 384 bytes. + */ +struct init_request { + int magic; /* Magic number */ + int cmd; /* What kind of request */ + int runlevel; /* Runlevel to change to */ + int sleeptime; /* Time between TERM and KILL */ + union { + struct init_request_bsd bsd; + char data[368]; + } i; +}; + +void sysvinit_runlevel(char rl); +void sysvinit_setenv(const char *name, const char *value); + +#endif -- cgit v1.2.3