Compare commits
22 Commits
openrc-0.2
...
openrc-0.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30fe99dead | ||
|
|
2d75eb7976 | ||
|
|
3663cf1e2a | ||
|
|
766ec96e3d | ||
|
|
a854fe6d61 | ||
|
|
619b0b4f37 | ||
|
|
c8248d05a0 | ||
|
|
5ae702339e | ||
|
|
d384502e57 | ||
|
|
bdaca0baf5 | ||
|
|
5188fd2592 | ||
|
|
5b800030f1 | ||
|
|
208443fa0e | ||
|
|
a818eebf7b | ||
|
|
10910876d1 | ||
|
|
35b4978152 | ||
|
|
cedd81801a | ||
|
|
e273b4e08e | ||
|
|
50cff8ebc8 | ||
|
|
aec83494d6 | ||
|
|
5ba6f0a628 | ||
|
|
5a59542629 |
2
Makefile
2
Makefile
@@ -3,7 +3,7 @@
|
||||
# All rights reserved. Released under the 2-clause BSD license.
|
||||
|
||||
NAME= openrc
|
||||
VERSION= 0.2.3
|
||||
VERSION= 0.2.4
|
||||
PKG= ${NAME}-${VERSION}
|
||||
|
||||
SUBDIR= conf.d doc etc init.d man net sh src
|
||||
|
||||
@@ -87,6 +87,10 @@
|
||||
# is how long we wait for carrier. The current default is 3 seconds
|
||||
#carrier_timeout_eth0=-1
|
||||
|
||||
# You may wish to disable the interface being brought down when stopping.
|
||||
# This is only of use for WakeOnLan.
|
||||
#ifdown_eth0="NO"
|
||||
|
||||
##############################################################################
|
||||
# OPTIONAL MODULES
|
||||
|
||||
|
||||
@@ -120,6 +120,10 @@
|
||||
# tables you may have to set a global metric as the due to a simple read of
|
||||
# the routing table taking over a minute at a time.
|
||||
|
||||
# You may wish to disable the interface being brought down when stopping.
|
||||
# This is only of use for WakeOnLan.
|
||||
#ifdown_eth0="NO"
|
||||
|
||||
##############################################################################
|
||||
# OPTIONAL MODULES
|
||||
|
||||
|
||||
12
init.d/.gitignore
vendored
12
init.d/.gitignore
vendored
@@ -26,3 +26,15 @@ mixer
|
||||
nscd
|
||||
powerd
|
||||
syscons
|
||||
net.lo
|
||||
ttys
|
||||
swap-blk
|
||||
wscons
|
||||
consolefont
|
||||
hwclock
|
||||
keymaps
|
||||
modules
|
||||
mtab
|
||||
numlock
|
||||
procfs
|
||||
termencoding
|
||||
|
||||
@@ -3,7 +3,14 @@ SRCS= bootmisc.in fsck.in halt.sh.in hostname.in local.in localmount.in \
|
||||
netmount.in root.in swap.in sysctl.in urandom.in
|
||||
BIN= ${OBJS}
|
||||
|
||||
INSTALLAFTER= _installafter
|
||||
CLEANFILES+= net.lo
|
||||
TARGETS+= net.lo
|
||||
|
||||
MK= ../mk
|
||||
include ${MK}/os.mk
|
||||
include Makefile.${OS}
|
||||
include ${MK}/scripts.mk
|
||||
|
||||
_installafter: realinstall
|
||||
${INSTALL} -m ${BINMODE} net.lo ${DESTDIR}/${INITDIR}/${NET_LO}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
NET_LO= net.lo0
|
||||
|
||||
# Generic BSD scripts
|
||||
SRCS+= hostid.in moused.in newsyslog.in pf.in rarpd.in rc-enabled.in \
|
||||
rpcbind.in savecore.in syslogd.in
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
NET_LO= net.lo
|
||||
|
||||
SRCS+= hwclock.in consolefont.in keymaps.in modules.in mtab.in numlock.in \
|
||||
procfs.in termencoding.in
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
NET_LO= net.lo0
|
||||
|
||||
# Generic BSD scripts
|
||||
SRCS+= hostid.in moused.in newsyslog.in pf.in rarpd.in rc-enabled.in \
|
||||
rpcbind.in savecore.in syslogd.in
|
||||
|
||||
@@ -28,13 +28,8 @@ cleanup_tmp_dir()
|
||||
cd "${dir}"
|
||||
if yesno ${wipe_tmp:-${WIPE_TMP:-yes}}; then
|
||||
ebegin "Wiping ${dir} directory"
|
||||
local startopts="-x . -depth" delete="-exec rm -rf -- {} ;"
|
||||
|
||||
if [ "${RC_UNAME}" = "Linux" ]; then
|
||||
startopts=". -xdev -depth"
|
||||
# busybox find / rm cannot handle --
|
||||
delete="-delete"
|
||||
fi
|
||||
local startopts="-x . -depth"
|
||||
[ "${RC_UNAME}" = "Linux" ] && startopts=". -xdev -depth"
|
||||
|
||||
# Faster than find
|
||||
rm -rf -- [b-ikm-pr-zA-Z0-9\.]*
|
||||
@@ -54,8 +49,7 @@ cleanup_tmp_dir()
|
||||
! -path "./journal/*" \
|
||||
! -path "./.private" \
|
||||
! -path "./.private/*" \
|
||||
${delete} \
|
||||
-type d -prune
|
||||
-exec rm -rf {} \;
|
||||
eend 0
|
||||
else
|
||||
ebegin "Cleaning ${dir} directory"
|
||||
|
||||
@@ -663,9 +663,14 @@ stop()
|
||||
fi
|
||||
done
|
||||
|
||||
! yesno ${IN_BACKGROUND} && \
|
||||
[ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ] && \
|
||||
_down 2>/dev/null
|
||||
# If not in background, and not loopback then bring the interface down
|
||||
# unless overridden.
|
||||
if ! yesno ${IN_BACKGROUND} && \
|
||||
[ "${IFACE}" != "lo" -a "${IFACE}" != "lo0" ]; then
|
||||
eval module=\$ifdown_${IFVAR}
|
||||
module=${module:-YES}
|
||||
yesno ${module} && _down 2>/dev/null
|
||||
fi
|
||||
|
||||
type resolvconf >/dev/null 2>&1 && resolvconf -d "${IFACE}" 2>/dev/null
|
||||
|
||||
@@ -33,7 +33,8 @@ depend()
|
||||
|
||||
config /etc/fstab
|
||||
need net ${pmap}
|
||||
use afc-client amd autofs dns nfs nfsmount portmap rpcbind rpc.statd
|
||||
use afc-client amd autofs openvpn
|
||||
use dns nfs nfsmount portmap rpcbind rpc.statd
|
||||
keyword nojail noopenvz noprefix novserver
|
||||
}
|
||||
|
||||
|
||||
@@ -49,10 +49,10 @@ start() {
|
||||
|
||||
local v= f=
|
||||
for v in font8x16 font8x14 font8x8; do
|
||||
f=$(eval \$"${v}")
|
||||
eval f=\$${v}
|
||||
if [ -n "${f}" ]; then
|
||||
ebegin "Setting font ${f}"
|
||||
vidcontrol -f ${v##FONT} ${f}
|
||||
vidcontrol -f ${v##font} ${f}
|
||||
eend $?
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -22,9 +22,9 @@ SED_REPLACE= -e 's:@SHELL@:${SH}:g' -e 's:@LIB@:${LIBNAME}:g' -e 's:@SYSCONFDIR
|
||||
.in:
|
||||
${SED} ${SED_REPLACE} ${SED_EXTRA} $< > $@
|
||||
|
||||
all: ${OBJS}
|
||||
all: ${OBJS} ${TARGETS}
|
||||
|
||||
realinstall: ${BIN} ${CONF} ${CONF_APPEND}
|
||||
realinstall: ${BIN} ${CONF} ${INC}
|
||||
@if test -n "${DIR}"; then \
|
||||
${ECHO} ${INSTALL} -d ${DESTDIR}/${DIR}; \
|
||||
${INSTALL} -d ${DESTDIR}/${DIR} || exit $$?; \
|
||||
|
||||
@@ -10,12 +10,12 @@ iproute2_depend()
|
||||
|
||||
_up()
|
||||
{
|
||||
ip link set up dev "${IFACE}"
|
||||
ip link set "${IFACE}" up
|
||||
}
|
||||
|
||||
_down()
|
||||
{
|
||||
ip link set down dev "${IFACE}"
|
||||
ip link set "${IFACE}" down
|
||||
}
|
||||
|
||||
_exists()
|
||||
@@ -78,7 +78,7 @@ _get_mac_address()
|
||||
|
||||
_set_mac_address()
|
||||
{
|
||||
ip link set address "$1" dev "${IFACE}"
|
||||
ip link set "${IFACE}" address "$1"
|
||||
}
|
||||
|
||||
_get_inet_addresses()
|
||||
@@ -126,7 +126,7 @@ _add_address()
|
||||
;;
|
||||
esac
|
||||
|
||||
ip addr add dev "${IFACE}" "$@"
|
||||
ip addr add "$@" dev "${IFACE}"
|
||||
}
|
||||
|
||||
_add_route()
|
||||
@@ -184,12 +184,12 @@ iproute2_pre_start()
|
||||
# MTU support
|
||||
local mtu=
|
||||
eval mtu=\$mtu_${IFVAR}
|
||||
[ -n "${mtu}" ] && ip link set mtu "${mtu}" dev "${IFACE}"
|
||||
[ -n "${mtu}" ] && ip link set "${IFACE}" mtu "${mtu}"
|
||||
|
||||
# TX Queue Length support
|
||||
local len=
|
||||
eval len=\$txqueuelen_${IFVAR}
|
||||
[ -n "${len}" ] && ip link set qlen "${len}" dev "${IFACE}"
|
||||
[ -n "${len}" ] && ip link set "${IFACE}" txqueuelen "${len}"
|
||||
|
||||
local tunnel=
|
||||
eval tunnel=\$iptunnel_${IFVAR}
|
||||
@@ -198,7 +198,7 @@ iproute2_pre_start()
|
||||
metric=1000
|
||||
|
||||
ebegin "Creating tunnel ${IFVAR}"
|
||||
ip tunnel add ${tunnel} name "${IFACE}"
|
||||
ip tunnel add ${tunnel} name dev "${IFACE}"
|
||||
eend $? || return 1
|
||||
_up
|
||||
fi
|
||||
@@ -234,7 +234,7 @@ iproute2_post_stop()
|
||||
if [ "${IFACE}" != "sit0" ]; then
|
||||
if [ -n "$(ip tunnel show "${IFACE}" 2>/dev/null)" ]; then
|
||||
ebegin "Destroying tunnel ${IFACE}"
|
||||
ip tunnel del "${IFACE}"
|
||||
ip tunnel del dev "${IFACE}"
|
||||
eend $?
|
||||
fi
|
||||
fi
|
||||
|
||||
2
sh/.gitignore
vendored
2
sh/.gitignore
vendored
@@ -4,3 +4,5 @@ net.sh
|
||||
rc-functions.sh
|
||||
runscript.sh
|
||||
init.sh
|
||||
ifwatchd-carrier.sh
|
||||
ifwatchd-nocarrier.sh
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
DIR= ${PREFIX}/${RC_LIB}/sh
|
||||
SRCS= functions.sh.in gendepends.sh.in net.sh.in \
|
||||
SRCS= functions.sh.in gendepends.sh.in \
|
||||
rc-functions.sh.in runscript.sh.in
|
||||
INC= init-common-post.sh rc-mount.sh functions.sh rc-functions.sh
|
||||
BIN= gendepends.sh init.sh net.sh runscript.sh
|
||||
BIN= gendepends.sh init.sh runscript.sh
|
||||
|
||||
INSTALLAFTER= _installafter
|
||||
|
||||
@@ -13,8 +13,6 @@ include ${MK}/scripts.mk
|
||||
|
||||
_installafter:
|
||||
${INSTALL} -d ${DESTDIR}/${INITDIR}
|
||||
@# Provide an init script for the loopback interface
|
||||
ln -snf ${PREFIX}/${RC_LIB}/sh/net.sh ${DESTDIR}/${INITDIR}/${NET_LO} || exit $$?
|
||||
@# Put functions.sh into the init.d dir so 3rd party apps don't have to
|
||||
@# be multilib aware
|
||||
ln -snf ${PREFIX}/${RC_LIB}/sh/functions.sh ${DESTDIR}/${INITDIR} || exit $$?
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
SRCS+= init.sh.in
|
||||
|
||||
NET_LO= net.lo0
|
||||
|
||||
.SUFFIXES: .sh.BSD.in
|
||||
.sh.BSD.in.sh:
|
||||
${SED} ${SED_REPLACE} ${SED_EXTRA} $< > $@
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
NET_LO= net.lo
|
||||
SRCS+= init.sh.in init-early.sh.in
|
||||
BIN+= init-early.sh
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
SRCS+= init.sh.in
|
||||
|
||||
NET_LO= net.lo0
|
||||
SRCS+= ifwatchd-carrier.sh.in ifwatchd-nocarrier.sh.in
|
||||
BIN+= ifwatchd-carrier.sh ifwatchd-nocarrier.sh
|
||||
|
||||
|
||||
@@ -51,9 +51,11 @@ do
|
||||
[ -x "${RC_SERVICE}" -a -f "${RC_SERVICE}" ] || continue
|
||||
|
||||
# Only generate dependencies for runscripts
|
||||
read one two < "${RC_SERVICE}"
|
||||
[ "${one}" = "#!@PREFIX@/sbin/runscript" ] || continue
|
||||
unset one two
|
||||
read one two three < "${RC_SERVICE}"
|
||||
[ "${one}" = "#!@PREFIX@/sbin/runscript" ] || \
|
||||
[ "${one}" = "#!" -a "${two}" = "@PREFIX@/sbin/runscript" ] || \
|
||||
continue
|
||||
unset one two three
|
||||
|
||||
export RC_SVCNAME=${RC_SERVICE##*/}
|
||||
|
||||
|
||||
@@ -56,76 +56,53 @@ static size_t strlcpy(char *dst, const char *src, size_t size)
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
|
||||
static bool pid_is_cmd(pid_t pid, const char *cmd)
|
||||
{
|
||||
char buffer[32];
|
||||
FILE *fp;
|
||||
int c;
|
||||
bool retval = false;
|
||||
|
||||
snprintf(buffer, sizeof(buffer), "/proc/%d/stat", pid);
|
||||
if ((fp = fopen(buffer, "r")) == NULL)
|
||||
return false;
|
||||
|
||||
while ((c = getc(fp)) != EOF && c != '(')
|
||||
;
|
||||
|
||||
if (c != '(') {
|
||||
if ((fp = fopen(buffer, "r"))) {
|
||||
while ((c = getc(fp)) != EOF && c != '(')
|
||||
;
|
||||
if (c == '(') {
|
||||
while ((c = getc(fp)) != EOF && c == *cmd)
|
||||
cmd++;
|
||||
if (c == ')' && *cmd == '\0')
|
||||
retval = true;
|
||||
}
|
||||
fclose(fp);
|
||||
return false;
|
||||
}
|
||||
|
||||
while ((c = getc(fp)) != EOF && c == *cmd)
|
||||
cmd++;
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return (c == ')' && *cmd == '\0') ? true : false;
|
||||
return retval;
|
||||
}
|
||||
|
||||
static bool pid_is_exec(pid_t pid, const char *const *argv)
|
||||
{
|
||||
char cmdline[32];
|
||||
int fd;
|
||||
char buffer[PATH_MAX];
|
||||
char *p;
|
||||
int fd = -1;
|
||||
int r;
|
||||
|
||||
/* Check it's the right binary */
|
||||
snprintf (cmdline, sizeof (cmdline), "/proc/%u/exe", pid);
|
||||
memset (buffer, 0, sizeof (buffer));
|
||||
if (readlink(cmdline, buffer, sizeof(buffer)) != -1) {
|
||||
if (strcmp(*argv, buffer) == 0)
|
||||
return true;
|
||||
|
||||
/* We should cater for deleted binaries too */
|
||||
if (strlen(buffer) > 10) {
|
||||
p = buffer + (strlen(buffer) - 10);
|
||||
if (strcmp(p, " (deleted)") == 0) {
|
||||
*p = 0;
|
||||
if (strcmp(buffer, *argv) == 0)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
ssize_t bytes;
|
||||
|
||||
snprintf(cmdline, sizeof(cmdline), "/proc/%u/cmdline", pid);
|
||||
if ((fd = open(cmdline, O_RDONLY)) < 0)
|
||||
return false;
|
||||
|
||||
r = read(fd, buffer, sizeof(buffer));
|
||||
bytes = read(fd, buffer, sizeof(buffer));
|
||||
close(fd);
|
||||
if (bytes == -1)
|
||||
return false;
|
||||
|
||||
if (r == -1)
|
||||
return 0;
|
||||
|
||||
buffer[r] = 0;
|
||||
buffer[bytes] = '\0';
|
||||
p = buffer;
|
||||
while (*argv) {
|
||||
if (strcmp(*argv, p) != 0)
|
||||
return false;
|
||||
argv++;
|
||||
p += strlen(p) + 1;
|
||||
if ((unsigned) (p - buffer) > sizeof (buffer))
|
||||
if ((unsigned)(p - buffer) > sizeof(buffer))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -120,18 +120,15 @@ void rc_plugin_load(void)
|
||||
|
||||
int rc_waitpid(pid_t pid)
|
||||
{
|
||||
int status = 0;
|
||||
pid_t savedpid = pid;
|
||||
int retval = EXIT_FAILURE;
|
||||
int status;
|
||||
|
||||
do {
|
||||
pid = waitpid(savedpid, &status, 0);
|
||||
if (pid == -1 && errno != EINTR)
|
||||
return EXIT_FAILURE;
|
||||
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
|
||||
if (pid == savedpid)
|
||||
retval = WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE;
|
||||
return retval;
|
||||
while (waitpid(pid, &status, 0) == -1) {
|
||||
if (errno != EINTR) {
|
||||
status = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
void rc_plugin_run(RC_HOOK hook, const char *value)
|
||||
|
||||
30
src/rc/rc.c
30
src/rc/rc.c
@@ -146,7 +146,7 @@ static void cleanup(void)
|
||||
rc_plugin_unload();
|
||||
|
||||
if (! rc_in_plugin && termios_orig) {
|
||||
tcsetattr(fileno(stdin), TCSANOW, termios_orig);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, termios_orig);
|
||||
free(termios_orig);
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ static char read_key(bool block)
|
||||
{
|
||||
struct termios termios;
|
||||
char c = 0;
|
||||
int fd = fileno(stdin);
|
||||
int fd = STDIN_FILENO;
|
||||
|
||||
if (! isatty(fd))
|
||||
return false;
|
||||
@@ -308,7 +308,7 @@ static void run_program(const char *prog)
|
||||
sigprocmask(SIG_SETMASK, &old, NULL);
|
||||
|
||||
if (termios_orig)
|
||||
tcsetattr(fileno(stdin), TCSANOW, termios_orig);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, termios_orig);
|
||||
|
||||
execl(prog, prog, (char *) NULL);
|
||||
eerror("%s: unable to exec `%s': %s", applet, prog,
|
||||
@@ -338,12 +338,13 @@ static void sulogin(bool cont)
|
||||
if (! cont) {
|
||||
rc_logger_close();
|
||||
#ifdef __linux__
|
||||
execl("/sbin/sulogin", "/sbin/sulogin", (char *) NULL);
|
||||
eerrorx("%s: unable to exec `/sbin/sulogin': %s",
|
||||
applet, strerror(errno));
|
||||
#else
|
||||
exit(EXIT_SUCCESS);
|
||||
if (RUNLEVEL && strcmp(RUNLEVEL, "S") == 0) {
|
||||
execl("/sbin/sulogin", "/sbin/sulogin", (char *) NULL);
|
||||
eerrorx("%s: unable to exec `/sbin/sulogin': %s",
|
||||
applet, strerror(errno));
|
||||
}
|
||||
#endif
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
@@ -614,7 +615,7 @@ static void do_coldplug(void)
|
||||
if (coldplugged_services)
|
||||
TAILQ_FOREACH(s, coldplugged_services, entries)
|
||||
printf(" %s", s->value);
|
||||
printf ("%s\n", ecolor(ECOLOR_NORMAL));
|
||||
printf("%s\n", ecolor(ECOLOR_NORMAL));
|
||||
}
|
||||
|
||||
static void do_newlevel(const char *newlevel)
|
||||
@@ -733,17 +734,18 @@ static void do_newlevel(const char *newlevel)
|
||||
static bool runlevel_config(const char *service, const char *level)
|
||||
{
|
||||
char *init = rc_service_resolve(service);
|
||||
char *conf;
|
||||
char *conf, *dir;
|
||||
size_t l;
|
||||
bool retval;
|
||||
|
||||
init = dirname(init);
|
||||
init = dirname(init);
|
||||
l = strlen(init) + strlen(level) + strlen(service) + 10;
|
||||
dir = dirname(init);
|
||||
dir = dirname(init);
|
||||
l = strlen(dir) + strlen(level) + strlen(service) + 10;
|
||||
conf = xmalloc(sizeof(char) * l);
|
||||
snprintf(conf, l, "%s/conf.d/%s.%s", init, service, level);
|
||||
snprintf(conf, l, "%s/conf.d/%s.%s", dir, service, level);
|
||||
retval = exists(conf);
|
||||
free(conf);
|
||||
free(init);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
@@ -707,7 +708,8 @@ static void svc_start(bool deps)
|
||||
hook_out = RC_HOOK_SERVICE_START_OUT;
|
||||
rc_plugin_run(RC_HOOK_SERVICE_START_IN, applet);
|
||||
|
||||
if (rc_conf_yesno("rc_depend_strict"))
|
||||
errno = 0;
|
||||
if (rc_conf_yesno("rc_depend_strict") || errno == ENOENT)
|
||||
depoptions |= RC_DEP_STRICT;
|
||||
|
||||
if (deps) {
|
||||
@@ -933,8 +935,8 @@ static void svc_stop(bool deps)
|
||||
ewarn ("WARNING: you are stopping a boot service");
|
||||
|
||||
if (deps && ! (state & RC_SERVICE_WASINACTIVE)) {
|
||||
|
||||
if (rc_conf_yesno("rc_depend_strict"))
|
||||
errno = 0;
|
||||
if (rc_conf_yesno("rc_depend_strict") || errno == ENOENT)
|
||||
depoptions |= RC_DEP_STRICT;
|
||||
|
||||
if (! deptree && ((deptree = _rc_deptree_load(NULL)) == NULL))
|
||||
@@ -1102,39 +1104,73 @@ int runscript(int argc, char **argv)
|
||||
int retval;
|
||||
int opt;
|
||||
RC_STRING *svc;
|
||||
char dir[PATH_MAX];
|
||||
char path[PATH_MAX];
|
||||
char lnk[PATH_MAX];
|
||||
size_t l = 0;
|
||||
size_t ll;
|
||||
char *save;
|
||||
char *dir, *save = NULL;
|
||||
const char *file;
|
||||
int depoptions = RC_DEP_TRACE;
|
||||
struct stat stbuf;
|
||||
|
||||
/* Show help if insufficient args */
|
||||
if (argc < 2 || ! exists(argv[1])) {
|
||||
fprintf(stderr, "runscript is not meant to be to run directly\n");
|
||||
fprintf(stderr, "runscript should not be run directly\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
applet = basename_c(argv[1]);
|
||||
if (argc < 3)
|
||||
usage(EXIT_FAILURE);
|
||||
|
||||
if (*argv[1] == '/')
|
||||
service = xstrdup(argv[1]);
|
||||
else {
|
||||
getcwd(dir, sizeof(dir));
|
||||
l = strlen(dir) + strlen(argv[1]) + 2;
|
||||
service = xmalloc(sizeof (char) * l);
|
||||
snprintf(service, l, "%s/%s", dir, argv[1]);
|
||||
if (stat(argv[1], &stbuf) != 0) {
|
||||
fprintf(stderr, "runscript `%s': %s\n",
|
||||
argv[1], strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
atexit(cleanup);
|
||||
|
||||
/* We need to work out the real full path to our service.
|
||||
* This works fine, provided that we ONLY allow mulitplexed services
|
||||
* to exist in the same directory as the master link.
|
||||
* Also, the master link as to be a real file in the init dir. */
|
||||
if (!realpath(argv[1], path)) {
|
||||
fprintf(stderr, "realpath: %s\n", strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
memset(lnk, 0, sizeof(lnk));
|
||||
if (readlink(argv[1], lnk, sizeof(lnk)-1)) {
|
||||
dir = dirname(path);
|
||||
if (strchr(lnk, '/')) {
|
||||
save = xstrdup(dir);
|
||||
dir = dirname(lnk);
|
||||
if (strcmp(dir, save) == 0)
|
||||
file = basename_c(argv[1]);
|
||||
else
|
||||
file = basename_c(lnk);
|
||||
dir = save;
|
||||
} else
|
||||
file = basename_c(argv[1]);
|
||||
ll = strlen(dir) + strlen(file) + 2;
|
||||
service = xmalloc(ll);
|
||||
snprintf(service, ll, "%s/%s", dir, file);
|
||||
if (stat(service, &stbuf) != 0) {
|
||||
free(service);
|
||||
service = xstrdup(lnk);
|
||||
}
|
||||
free(save);
|
||||
}
|
||||
if (!service)
|
||||
service = xstrdup(path);
|
||||
applet = basename_c(service);
|
||||
|
||||
if (argc < 3)
|
||||
usage(EXIT_FAILURE);
|
||||
|
||||
/* Change dir to / to ensure all init scripts don't use stuff in pwd */
|
||||
chdir("/");
|
||||
|
||||
#ifdef __linux__
|
||||
/* coldplug events can trigger init scripts, but we don't want to run them
|
||||
until after rc sysinit has completed so we punt them to the boot runlevel */
|
||||
/* coldplug events can trigger init scripts, but we don't want to run
|
||||
* them until after rc sysinit has completed so we punt them to the
|
||||
* boot runlevel */
|
||||
if (exists("/dev/.rcsysinit")) {
|
||||
eerror("%s: cannot run until sysvinit completes", applet);
|
||||
if (mkdir("/dev/.rcboot", 0755) != 0 && errno != EEXIST)
|
||||
@@ -1164,11 +1200,15 @@ int runscript(int argc, char **argv)
|
||||
if (rc_conf_yesno("rc_parallel")) {
|
||||
/* Get the longest service name */
|
||||
services = rc_services_in_runlevel(NULL);
|
||||
TAILQ_FOREACH(svc, services, entries) {
|
||||
ll = strlen(svc->value);
|
||||
if (ll > l)
|
||||
l = ll;
|
||||
}
|
||||
if (services) {
|
||||
TAILQ_FOREACH(svc, services, entries) {
|
||||
ll = strlen(svc->value);
|
||||
if (ll > l)
|
||||
l = ll;
|
||||
}
|
||||
rc_stringlist_free(services);
|
||||
services = NULL;
|
||||
} else l = strlen(applet);
|
||||
|
||||
/* Make our prefix string */
|
||||
prefix = xmalloc(sizeof(char) * l + 1);
|
||||
@@ -1256,6 +1296,7 @@ int runscript(int argc, char **argv)
|
||||
prefix = NULL;
|
||||
svc_exec(optarg, NULL);
|
||||
eprefix(save);
|
||||
prefix = save;
|
||||
} else if (strcmp(optarg, "ineed") == 0 ||
|
||||
strcmp(optarg, "iuse") == 0 ||
|
||||
strcmp(optarg, "needsme") == 0 ||
|
||||
@@ -1264,7 +1305,8 @@ int runscript(int argc, char **argv)
|
||||
strcmp(optarg, "ibefore") == 0 ||
|
||||
strcmp(optarg, "iprovide") == 0)
|
||||
{
|
||||
if (rc_conf_yesno("rc_depend_strict"))
|
||||
errno = 0;
|
||||
if (rc_conf_yesno("rc_depend_strict") || errno == ENOENT)
|
||||
depoptions |= RC_DEP_STRICT;
|
||||
|
||||
if (! deptree && ((deptree = _rc_deptree_load(NULL)) == NULL))
|
||||
|
||||
Reference in New Issue
Block a user