aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/Makemodule.am4
-rw-r--r--cmd/killall5.c4
-rw-r--r--cmd/runsvc/runsvc.c43
-rw-r--r--cmd/runsvc/runsvc.h4
-rw-r--r--cmd/service/servicecmd.c1
-rw-r--r--cmd/service/servicecmd.h5
-rw-r--r--cmd/shutdown.c4
7 files changed, 53 insertions, 12 deletions
diff --git a/cmd/Makemodule.am b/cmd/Makemodule.am
index d6ed4fc..0af619f 100644
--- a/cmd/Makemodule.am
+++ b/cmd/Makemodule.am
@@ -7,7 +7,7 @@ runsvc_SOURCES = cmd/runsvc/runsvc.c cmd/runsvc/env.c cmd/runsvc/runsvc.h
runsvc_CPPFLAGS = $(AM_CPPFLAGS)
runsvc_CFLAGS = $(AM_CFLAGS)
runsvc_LDFLAGS = $(AM_LDFLAGS)
-runsvc_LDADD = libinit.a libcfg.a libutil.a
+runsvc_LDADD = libinit.a libcfg.a
killall5_SOURCES = cmd/killall5.c
killall5_CPPFLAGS = $(AM_CPPFLAGS)
@@ -30,7 +30,7 @@ service_SOURCES += $(SRVHEADERS)
service_CPPFLAGS = $(AM_CPPFLAGS)
service_CFLAGS = $(AM_CFLAGS)
service_LDFLAGS = $(AM_LDFLAGS)
-service_LDADD = libinit.a libcfg.a libutil.a
+service_LDADD = libinit.a libcfg.a
dist_man8_MANS += cmd/shutdown.8 cmd/service/service.8
diff --git a/cmd/killall5.c b/cmd/killall5.c
index ccab429..733c0eb 100644
--- a/cmd/killall5.c
+++ b/cmd/killall5.c
@@ -9,9 +9,7 @@
#include <ctype.h>
#include <errno.h>
-#include "util.h"
-
-static NORETURN void usage_and_exit(void)
+static __attribute__((noreturn)) void usage_and_exit(void)
{
fputs("Usage: killall5 SIGNAL\n", stderr);
exit(EXIT_FAILURE);
diff --git a/cmd/runsvc/runsvc.c b/cmd/runsvc/runsvc.c
index 794aa29..75fdc46 100644
--- a/cmd/runsvc/runsvc.c
+++ b/cmd/runsvc/runsvc.c
@@ -1,6 +1,49 @@
/* SPDX-License-Identifier: ISC */
#include "runsvc.h"
+static int setup_tty(const char *tty, bool truncate)
+{
+ int fd;
+
+ if (tty == NULL)
+ return 0;
+
+ fd = open(tty, O_RDWR);
+ if (fd < 0) {
+ perror(tty);
+ return -1;
+ }
+
+ if (truncate)
+ ftruncate(fd, 0);
+
+ close(STDIN_FILENO);
+ close(STDOUT_FILENO);
+ close(STDERR_FILENO);
+
+ setsid();
+
+ dup2(fd, STDIN_FILENO);
+ dup2(fd, STDOUT_FILENO);
+ dup2(fd, STDERR_FILENO);
+ close(fd);
+ return 0;
+}
+
+static __attribute__((noreturn)) void argv_exec(exec_t *e)
+{
+ char **argv = alloca(sizeof(char *) * (e->argc + 1)), *ptr;
+ int i;
+
+ for (ptr = e->args, i = 0; i < e->argc; ++i, ptr += strlen(ptr) + 1)
+ argv[i] = ptr;
+
+ argv[i] = NULL;
+ execvp(argv[0], argv);
+ perror(argv[0]);
+ exit(EXIT_FAILURE);
+}
+
static int run_sequentially(exec_t *list)
{
pid_t ret, pid;
diff --git a/cmd/runsvc/runsvc.h b/cmd/runsvc/runsvc.h
index 9f1a946..2a6ae49 100644
--- a/cmd/runsvc/runsvc.h
+++ b/cmd/runsvc/runsvc.h
@@ -4,6 +4,8 @@
#include <sys/types.h>
#include <sys/wait.h>
+#include <stdbool.h>
+#include <stddef.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
@@ -12,7 +14,7 @@
#include "service.h"
#include "libcfg.h"
-#include "util.h"
+#include "config.h"
#define ENVFILE ETCPATH "/initd.env"
diff --git a/cmd/service/servicecmd.c b/cmd/service/servicecmd.c
index 799a6f1..55afaf5 100644
--- a/cmd/service/servicecmd.c
+++ b/cmd/service/servicecmd.c
@@ -5,7 +5,6 @@
#include "servicecmd.h"
#include "service.h"
#include "config.h"
-#include "util.h"
command_t *commands;
diff --git a/cmd/service/servicecmd.h b/cmd/service/servicecmd.h
index e7cc998..d65c4b5 100644
--- a/cmd/service/servicecmd.h
+++ b/cmd/service/servicecmd.h
@@ -2,13 +2,14 @@
#ifndef SERVICECMD_H
#define SERVICECMD_H
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include "service.h"
-#include "util.h"
+#include "config.h"
/*
Describes a command that can be launched by passing its name as
@@ -45,7 +46,7 @@ service_t *loadsvc(const char *directory, const char *filename, int flags);
Implemented in servicecmd.c. Prints program usage message and
terminates with the given exit status.
*/
-void usage(int status) NORETURN;
+void usage(int status) __attribute__((noreturn));
/*
Write a message to stderr that advises the user how to consult the
diff --git a/cmd/shutdown.c b/cmd/shutdown.c
index 546b076..afceec2 100644
--- a/cmd/shutdown.c
+++ b/cmd/shutdown.c
@@ -10,8 +10,6 @@
#include <sys/reboot.h>
#include <linux/reboot.h>
-#include "util.h"
-
#define FL_FORCE 0x01
#define FL_NOSYNC 0x02
@@ -29,7 +27,7 @@ static const char *shortopt = "hprfn";
static const char *defact_str = "power-off";
static int defact = RB_POWER_OFF;
-static NORETURN void usage(const char *progname, int status)
+static __attribute__((noreturn)) void usage(const char *progname, int status)
{
fprintf(status == EXIT_SUCCESS ? stdout : stderr,
"%s [OPTIONS...]\n\n"