Compare commits

...

25 Commits
0.36 ... 0.38

Author SHA1 Message Date
William Hubbs
01c34c28e6 Update ChangeLog 2018-06-28 13:02:42 -05:00
William Hubbs
56ddda54b5 supervise-daemon.c: clean up memory leaks 2018-06-27 17:37:11 -05:00
William Hubbs
3a803b3135 librc-daemon.c: fix memory leaks 2018-06-27 12:06:19 -05:00
William Hubbs
72df51e17b librc-daemon: convert most snprintf calls to xasprintf 2018-06-22 15:41:25 -05:00
William Hubbs
b2f5531194 librc-misc: convert snprintf calls to xasprintf 2018-06-20 17:45:01 -05:00
William Hubbs
19bf49a710 libeinfo: convert remaining snprintf calls to xasprintf 2018-06-20 12:36:51 -05:00
William Hubbs
64354831da openrc: convert snprintf calls to xasprintf 2018-06-20 09:37:20 -05:00
William Hubbs
e14edd765f supervise-daemon: convert snprintf calls to xasprintf 2018-06-19 17:57:10 -05:00
William Hubbs
f9d41243d8 start-stop-daemon: convert snprintf calls to xasprintf 2018-06-19 17:46:12 -05:00
William Hubbs
be7ad06d4a rc-status: convert snprintf calls to xasprintf 2018-06-19 17:06:33 -05:00
William Hubbs
a616516895 rc-status: fix gcc 7 warnings 2018-06-19 16:18:48 -05:00
William Hubbs
04721ece03 start-stop-daemon: fix gcc 7 warnings 2018-06-19 15:32:10 -05:00
William Hubbs
c7e8f1133a checkpath: fix gcc 7 warnings 2018-06-19 14:01:54 -05:00
William Hubbs
47e4bfae57 fix gcc 7 warnings in pipe routines 2018-06-19 13:59:16 -05:00
William Hubbs
8a945194af libeinfo: clean up gcc 7 compiler warnings 2018-06-19 13:52:40 -05:00
William Hubbs
aa4a004c29 version 0.38 2018-06-17 12:45:51 -05:00
William Hubbs
9ec5d36bdd Update ChangeLog 2018-06-15 18:04:43 -05:00
William Hubbs
a097933eda sh/start-stop-daemon.sh: fix processing of the logger arguments 2018-06-15 17:44:39 -05:00
William Hubbs
a6f5b1bb63 Update ChangeLog 2018-06-15 12:59:13 -05:00
William Hubbs
e6d01471fe start-stop-daemon: add ability to log stdout or stderr to processes 2018-06-15 12:23:50 -05:00
William Hubbs
d4501a9f06 fix a typo 2018-06-14 14:55:42 -05:00
Mike Gilbert
ec8abea460 Add helper to spawn process with stdin connected to a pipe 2018-06-13 13:49:42 -05:00
William Hubbs
e4ddfa38e0 user-guide.md: small cleanups 2018-06-05 17:34:09 -05:00
William Hubbs
21d30bc6d9 service-script-guide.md: small cleanups 2018-06-05 17:26:57 -05:00
William Hubbs
2a1ff6e49c version 0.37 2018-06-05 16:11:28 -05:00
19 changed files with 439 additions and 251 deletions

287
ChangeLog
View File

@@ -1,3 +1,153 @@
commit 56ddda54b5aa01474bf563d5a662075c35152858
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon.c: clean up memory leaks
commit 3a803b3135837665d51ef4dd7a8b913c78e71ff6
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
librc-daemon.c: fix memory leaks
commit 72df51e17ba0e1a0f94451b4bbfb338288c4625c
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
librc-daemon: convert most snprintf calls to xasprintf
commit b2f5531194e33c229462e9f52fa1d9388463f7b7
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
librc-misc: convert snprintf calls to xasprintf
commit 19bf49a710f27d4774ed4c6372d87d6ba15f189e
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
libeinfo: convert remaining snprintf calls to xasprintf
commit 64354831da2adeba5cb2f91a81fa0f56e1ce4ed9
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
openrc: convert snprintf calls to xasprintf
commit e14edd765fdc4ed43356d2eef35fa99228e5d461
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
supervise-daemon: convert snprintf calls to xasprintf
commit f9d41243d8499c5d7027177d5aa716d5b5859cd6
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
start-stop-daemon: convert snprintf calls to xasprintf
commit be7ad06d4a0efce2a1144b2cf6f0cc361f2a81e4
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
rc-status: convert snprintf calls to xasprintf
commit a6165168953b9c7a62c089ce946476b23b73fb12
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
rc-status: fix gcc 7 warnings
commit 04721ece03b15503aa220f60e7c6159d01ee75e1
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
start-stop-daemon: fix gcc 7 warnings
commit c7e8f1133a42152cc293e6b637985f81bcf8b310
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
checkpath: fix gcc 7 warnings
commit 47e4bfae57402eedd017d6098b432c2c411cd374
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
fix gcc 7 warnings in pipe routines
commit 8a945194afb106428bc700e751078ef9944ee617
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
libeinfo: clean up gcc 7 compiler warnings
commit aa4a004c297ec7a1fb794ad2e53ef3ac8b3f4fd1
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
version 0.38
commit 9ec5d36bdddf5bb0e96b0c561bc5d013a8a2da2a
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
Update ChangeLog
commit a097933edab9d7221df1831e098415d604437c98
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
sh/start-stop-daemon.sh: fix processing of the logger arguments
commit a6f5b1bb63070c24145df72040fa7b465948003c
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
Update ChangeLog
commit e6d01471fe2a8eb8a15bb906d7c91c11805d1bef
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
start-stop-daemon: add ability to log stdout or stderr to processes
commit d4501a9f06c807f87be04f128e535a74b370fdb4
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
fix a typo
commit ec8abea4605395a2a59b26906ce4677a578e3c60
Author: Mike Gilbert <floppym@gentoo.org>
Commit: William Hubbs <w.d.hubbs@gmail.com>
Add helper to spawn process with stdin connected to a pipe
commit e4ddfa38e0e0318abf442b7aa07e0d8206191dd7
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
user-guide.md: small cleanups
commit 21d30bc6d9caca31d007631717a480a552b89701
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
service-script-guide.md: small cleanups
commit 2a1ff6e49c6603bb81eec3cafe2c587fa734289f
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
version 0.37
commit 6762cb875c9c039b79dcc447b9d0eb65356a7708
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
Update ChangeLog
commit 6edf516a1fe0ad4f4e8738f9fdd1bf0bc7718361
Author: Austin English <austinenglish@gmail.com>
Commit: Doug Freed <dwfreed@mtu.edu>
@@ -1589,140 +1739,3 @@ Commit: William Hubbs <w.d.hubbs@gmail.com>
man: fix missing .Pp warnings
This fixes #151.
commit f87a9eec3d23ea01578500972f1df993d5d24fba
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
init.d/sysfs: mount efivars read only
This fixes #134.
commit 1e837d596e483ceb5cec177a6c7faff24a42384b
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
fix argument parsing for the sysvinit shutdown wrapper
This fixes #140.
commit dcc686e42b406d63d52ef75de9a326f67d0a06c9
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
scripts/shutdown: fix arguments to be sysvinit shutdown compatible
This fixes #140.
commit 2f81c100afdf45ebf787dfc5d3261aa6055640e4
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
Fix link to shutdown for MKSYSVINIT=yes
commit a511a48d77b1dcb8a3fb0dd1abddb750a152869b
Author: Nuno Silva <nuno.m.ribeiro.silva@tecnico.ulisboa.pt>
Commit: William Hubbs <w.d.hubbs@gmail.com>
init.d/hostname: fix default parameter syntax
The syntax for expanding a variable with a default value is
${parameter:-word}
not
${parameter-word}
although the latter still works for a reason I could not explain.
This fixes #143.
commit 1e5322e5c55ec744a2cdcc3342ef6547eab7c46f
Author: Nuno Silva <nuno.m.ribeiro.silva@tecnico.ulisboa.pt>
Commit: William Hubbs <w.d.hubbs@gmail.com>
init.d/hostname: fix indentation
This is for #143.
commit 199a210d2fbc524c9c400a06f832dabffd7ed1b3
Author: udeved <artoo@manjaro.org>
Commit: William Hubbs <w.d.hubbs@gmail.com>
scripts/Makefile: make symlinks absolute instead of relative
This closes #142.
commit 5b7667af32effddf867a5d021c66d43f0645d374
Author: udeved <artoo@manjaro.org>
Commit: William Hubbs <w.d.hubbs@gmail.com>
scripts/Makefile: respect SBINDIR with MKSYSVINIT
This is for #142.
commit 11243f85b67e5f450ddf50346ffd4a1b2c6faeb5
Author: Jory A. Pratt <anarchy@gentoo.org>
Commit: William Hubbs <w.d.hubbs@gmail.com>
kill_all: include limits.h for PATH_MAX
commit 3c40826d3466cdda1a46abcd5c86b661b8185f46
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
version 0.28
commit 560d874d2fee63bf7ca11f17cf9933021b639a1d
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
fix compile issue for musl
commit e84366fd232a41c3ba79ed351e93c74cef8d7c8d
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
Update ChangeLog
commit caacedc0a82285fb2d25c6d3473f154044c7ad66
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
man: update openrc-shutdown man page
Add the new wtmp options and fix some cross references.
commit 84d140a1f6abf95a4170d13527152d3ab14e6613
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
scripts/shutdown: pass --single to openrc-shutdown
Sysvinit shutdown has a default of single user mode, but openrc-shutdown
makes you choose a default action. Because of this, the shutdown wrapper
needs to pass --single to openrc-shutdown.
commit ee886c44824b1dd892eaff2c6da666286e61bc73
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
openrc-shutdown: add --single option and clean up option processing
commit 1801561c2d36c330df7fd02c7508f503a61ff5ba
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
init.d/bootmisc: use openrc-shutdown instead of halt to write halt record
This fixes #139 and fixes #128.
and fixes #124.
commit 7689106aa10f7852b707b4c21ec080ccb2767280
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
add support for writing reboot and shutdown records to wtmp
commit 1564e155b726308200ecd5df315c002bd8b16952
Author: William Hubbs <w.d.hubbs@gmail.com>
Commit: William Hubbs <w.d.hubbs@gmail.com>
openrc-init: add optional sysvinit compatibility

View File

@@ -1,3 +1,3 @@
NAME= openrc
VERSION= 0.36
VERSION= 0.38
PKG= ${NAME}-${VERSION}

View File

@@ -4,6 +4,15 @@ OpenRC NEWS
This file will contain a list of notable changes for each release. Note
the information in this file is in reverse order.
## OpenRC 0.37
start-stop-daemon now supports logging stdout and stderr of daemons to
processes instead of files. These processes are defined by the
output_logger and error_logger variables in standard service scripts, or
by the -3/--output-logger or -4/--error-logger switches if you use
start-stop-daemon directly. For more information on this, see the
start-stop-daemon man page.
## OpenRC 0.36
In this release, the modules-load service has been combined into the

View File

@@ -173,6 +173,23 @@ variable is set.
The same thing as
.Pa output_log
but for the standard error output.
.It Ar output_logger
This is a process which will be used to log the standard output from the
service. If you are starting this service with
.Xr start-stop-daemon 8 ,
, you must set
.Pa command_background
to true. Keep in mind that this command must be executable as a shell
command inside the chroot if the
.Pa chroot
variable is set. Keep in mind also that this command works by accepting
the stdout of the service on stdin.
An example of a command that can be run this way is logger if you want
your service output to go to syslog.
.It Ar error_logger
The same thing as
.Pa output_logger
but for the standard error output.
.It Ar directory
.Xr start-stop-daemon 8
and

View File

@@ -131,9 +131,34 @@ Modifies the scheduling priority of the daemon.
.It Fl 1 , -stdout Ar logfile
Redirect the standard output of the process to logfile when started with
.Fl background .
Must be an absolute pathname, but relative to the path optionally given with
The logfile Must be an absolute pathname, but relative to the path
optionally given with
.Fl r , -chroot .
The logfile can also be a named pipe.
.It Fl 2 , -stderr Ar logfile
Redirect the standard error of the process to logfile when started with
.Fl background .
The logfile must be an absolute pathname, but relative to the path
optionally given with
.Fl r , -chroot .
The logfile can also be a named pipe.
.It Fl 3 , -stdout-logger Ar cmd
Run cmd as a child process redirecting the standard output to the
standard input of cmd when started with
.Fl background .
Cmd must be an absolute pathname, but relative to the path optionally given with
.Fl r , -chroot .
This process must be prepared to accept input on stdin and be able to
log it or send it to another location.
.It Fl 4 , -stderr-logger Ar cmd
Run cmd as a child process and
Redirect the standard error of the process to the standard input of cmd
when started with
.Fl background .
Cmd must be an absolute pathname, but relative to the path optionally given with
.Fl r , -chroot .
This process must be prepared to accept input on stdin and be able to
log it or send it to another location.
.It Fl w , -wait Ar milliseconds
Wait
.Ar milliseconds

View File

@@ -29,7 +29,9 @@ Not using this interpreter will break the use of dependencies and is not
supported. (iow: if you insist on using `#!/bin/sh` you're on your own)
A `depend` function declares the dependencies of this service script.
All scripts must have start/stop/status functions, but defaults are provided and should be used unless you have a very strong reason not to use them.
All scripts must have start/stop/status functions, but defaults are
provided and should be used unless you have a very strong reason not to
use them.
Extra functions can be added easily:

View File

@@ -38,6 +38,10 @@ ssd_start()
service_inactive && _inactive=true
mark_service_inactive
fi
[ -n "$output_logger" ] &&
output_logger_arg="--stdout-logger \"$output_logger\""
[ -n "$error_logger" ] &&
error_logger_arg="--stderr-logger \"$error_logger\""
#the eval call is necessary for cases like:
# command_args="this \"is a\" test"
# to work properly.
@@ -47,6 +51,8 @@ ssd_start()
${directory:+--chdir} $directory \
${output_log+--stdout} $output_log \
${error_log+--stderr} $error_log \
${output_logger_arg} \
${error_logger_arg} \
${procname:+--name} $procname \
${pidfile:+--pidfile} $pidfile \
${command_user+--user} $command_user \

View File

@@ -883,7 +883,7 @@ eindent(void)
{
char *env = getenv("EINFO_INDENT");
int amount = 0;
char num[10];
char *num;
if (env) {
errno = 0;
@@ -894,8 +894,9 @@ eindent(void)
amount += INDENT_WIDTH;
if (amount > INDENT_MAX)
amount = INDENT_MAX;
snprintf(num, 10, "%08d", amount);
xasprintf(&num, "%08d", amount);
setenv("EINFO_INDENT", num, 1);
free(num);
}
hidden_def(eindent)
@@ -903,7 +904,7 @@ void eoutdent(void)
{
char *env = getenv("EINFO_INDENT");
int amount = 0;
char num[10];
char *num = NULL;
int serrno = errno;
if (!env)
@@ -917,8 +918,9 @@ void eoutdent(void)
if (amount <= 0)
unsetenv("EINFO_INDENT");
else {
snprintf(num, 10, "%08d", amount);
xasprintf(&num, "%08d", amount);
setenv("EINFO_INDENT", num, 1);
free(num);
}
errno = serrno;
}

View File

@@ -23,13 +23,13 @@
static bool
pid_is_exec(pid_t pid, const char *exec)
{
char buffer[32];
char *buffer = NULL;
FILE *fp;
int c;
bool retval = false;
exec = basename_c(exec);
snprintf(buffer, sizeof(buffer), "/proc/%d/stat", pid);
xasprintf(&buffer, "/proc/%d/stat", pid);
if ((fp = fopen(buffer, "r"))) {
while ((c = getc(fp)) != EOF && c != '(')
;
@@ -41,23 +41,27 @@ pid_is_exec(pid_t pid, const char *exec)
}
fclose(fp);
}
free(buffer);
return retval;
}
static bool
pid_is_argv(pid_t pid, const char *const *argv)
{
char cmdline[32];
char *cmdline = NULL;
int fd;
char buffer[PATH_MAX];
char *p;
ssize_t bytes;
snprintf(cmdline, sizeof(cmdline), "/proc/%u/cmdline", pid);
if ((fd = open(cmdline, O_RDONLY)) < 0)
xasprintf(&cmdline, "/proc/%u/cmdline", pid);
if ((fd = open(cmdline, O_RDONLY)) < 0) {
free(cmdline);
return false;
}
bytes = read(fd, buffer, sizeof(buffer));
close(fd);
free(cmdline);
if (bytes == -1)
return false;
@@ -88,7 +92,7 @@ rc_find_pids(const char *exec, const char *const *argv, uid_t uid, pid_t pid)
char proc_ns[30];
size_t len = 0;
pid_t p;
char buffer[PATH_MAX];
char *buffer = NULL;
struct stat sb;
pid_t openrc_pid = 0;
char *pp;
@@ -149,18 +153,22 @@ rc_find_pids(const char *exec, const char *const *argv, uid_t uid, pid_t pid)
continue;
if (pid != 0 && pid != p)
continue;
snprintf(buffer, sizeof(buffer), "/proc/%d/ns/pid", p);
xasprintf(&buffer, "/proc/%d/ns/pid", p);
if (exists(buffer)) {
rc = readlink(buffer, proc_ns, sizeof(proc_ns));
if (rc <= 0)
proc_ns[0] = '\0';
}
free(buffer);
if (strlen(my_ns) && strlen (proc_ns) && strcmp(my_ns, proc_ns))
continue;
if (uid) {
snprintf(buffer, sizeof(buffer), "/proc/%d", p);
if (stat(buffer, &sb) != 0 || sb.st_uid != uid)
xasprintf(&buffer, "/proc/%d", p);
if (stat(buffer, &sb) != 0 || sb.st_uid != uid) {
free(buffer);
continue;
}
free(buffer);
}
if (exec && !pid_is_exec(p, exec))
continue;
@@ -169,9 +177,10 @@ rc_find_pids(const char *exec, const char *const *argv, uid_t uid, pid_t pid)
continue;
/* If this is an OpenVZ host, filter out container processes */
if (openvz_host) {
snprintf(buffer, sizeof(buffer), "/proc/%d/status", p);
xasprintf(&buffer, "/proc/%d/status", p);
if (exists(buffer)) {
fp = fopen(buffer, "r");
free(buffer);
if (! fp)
continue;
while (! feof(fp)) {
@@ -315,12 +324,13 @@ _match_daemon(const char *path, const char *file, RC_STRINGLIST *match)
{
char *line = NULL;
size_t len = 0;
char ffile[PATH_MAX];
char *ffile = NULL;
FILE *fp;
RC_STRING *m;
snprintf(ffile, sizeof(ffile), "%s/%s", path, file);
xasprintf(&ffile, "%s/%s", path, file);
fp = fopen(ffile, "r");
free(ffile);
if (!fp)
return false;
@@ -346,29 +356,22 @@ _match_list(const char *exec, const char *const *argv, const char *pidfile)
{
RC_STRINGLIST *match = rc_stringlist_new();
int i = 0;
size_t l;
char *m;
if (exec) {
l = strlen(exec) + 6;
m = xmalloc(sizeof(char) * l);
snprintf(m, l, "exec=%s", exec);
xasprintf(&m, "exec=%s", exec);
rc_stringlist_add(match, m);
free(m);
}
while (argv && argv[i]) {
l = strlen(*argv) + strlen("argv_=") + 16;
m = xmalloc(sizeof(char) * l);
snprintf(m, l, "argv_0=%s", argv[i++]);
xasprintf(&m, "argv_0=%s", argv[i++]);
rc_stringlist_add(match, m);
free(m);
}
if (pidfile) {
l = strlen(pidfile) + 9;
m = xmalloc(sizeof(char) * l);
snprintf(m, l, "pidfile=%s", pidfile);
xasprintf(&m, "pidfile=%s", pidfile);
rc_stringlist_add(match, m);
free(m);
}
@@ -381,8 +384,8 @@ rc_service_daemon_set(const char *service, const char *exec,
const char *const *argv,
const char *pidfile, bool started)
{
char dirpath[PATH_MAX];
char file[PATH_MAX];
char *dirpath = NULL;
char *file = NULL;
int nfiles = 0;
char oldfile[PATH_MAX] = { '\0' };
bool retval = false;
@@ -397,8 +400,7 @@ rc_service_daemon_set(const char *service, const char *exec,
return false;
}
snprintf(dirpath, sizeof(dirpath), RC_SVCDIR "/daemons/%s",
basename_c(service));
xasprintf(&dirpath, RC_SVCDIR "/daemons/%s", basename_c(service));
/* Regardless, erase any existing daemon info */
if ((dp = opendir(dirpath))) {
@@ -407,8 +409,7 @@ rc_service_daemon_set(const char *service, const char *exec,
if (d->d_name[0] == '.')
continue;
snprintf(file, sizeof(file), "%s/%s",
dirpath, d->d_name);
xasprintf(&file, "%s/%s", dirpath, d->d_name);
nfiles++;
if (!*oldfile) {
@@ -421,6 +422,7 @@ rc_service_daemon_set(const char *service, const char *exec,
rename(file, oldfile);
strlcpy(oldfile, file, sizeof(oldfile));
}
free(file);
}
closedir(dp);
rc_stringlist_free(match);
@@ -429,8 +431,7 @@ rc_service_daemon_set(const char *service, const char *exec,
/* Now store our daemon info */
if (started) {
if (mkdir(dirpath, 0755) == 0 || errno == EEXIST) {
snprintf(file, sizeof(file), "%s/%03d",
dirpath, nfiles + 1);
xasprintf(&file, "%s/%03d", dirpath, nfiles + 1);
if ((fp = fopen(file, "w"))) {
fprintf(fp, "exec=");
if (exec)
@@ -446,10 +447,12 @@ rc_service_daemon_set(const char *service, const char *exec,
fclose(fp);
retval = true;
}
free(file);
}
} else
retval = true;
free(dirpath);
return retval;
}
librc_hidden_def(rc_service_daemon_set)
@@ -458,8 +461,8 @@ bool
rc_service_started_daemon(const char *service,
const char *exec, const char *const *argv, int indx)
{
char dirpath[PATH_MAX];
char file[16];
char *dirpath = NULL;
char *file = NULL;
RC_STRINGLIST *match;
bool retval = false;
DIR *dp;
@@ -468,13 +471,13 @@ rc_service_started_daemon(const char *service,
if (!service || !exec)
return false;
snprintf(dirpath, sizeof(dirpath), RC_SVCDIR "/daemons/%s",
basename_c(service));
xasprintf(&dirpath, RC_SVCDIR "/daemons/%s", basename_c(service));
match = _match_list(exec, argv, NULL);
if (indx > 0) {
snprintf(file, sizeof(file), "%03d", indx);
xasprintf(&file, "%03d", indx);
retval = _match_daemon(dirpath, file, match);
free(file);
} else {
if ((dp = opendir(dirpath))) {
while ((d = readdir(dp))) {
@@ -489,6 +492,7 @@ rc_service_started_daemon(const char *service,
}
rc_stringlist_free(match);
free(dirpath);
return retval;
}
librc_hidden_def(rc_service_started_daemon)

View File

@@ -237,13 +237,9 @@ static void rc_config_set_value(RC_STRINGLIST *config, char *value)
if (token[i] == '\n')
token[i] = 0;
i = strlen(entry) + strlen(token) + 2;
newline = xmalloc(sizeof(char) * i);
snprintf(newline, i, "%s=%s", entry, token);
xasprintf(&newline, "%s=%s", entry, token);
} else {
i = strlen(entry) + 2;
newline = xmalloc(sizeof(char) * i);
snprintf(newline, i, "%s=", entry);
xasprintf(&newline, "%s=", entry);
}
replaced = false;
@@ -300,8 +296,7 @@ static RC_STRINGLIST *rc_config_kcl(RC_STRINGLIST *config)
if (value != NULL) {
len = varlen + strlen(value) + 2;
tmp = xmalloc(sizeof(char) * len);
snprintf(tmp, len, "%s=%s", override->value, value);
xasprintf(&tmp, "%s=%s", override->value, value);
}
/*

View File

@@ -5,8 +5,8 @@ include ${MK}/os.mk
SRCS= checkpath.c do_e.c do_mark_service.c do_service.c \
do_value.c fstabinfo.c is_newer_than.c is_older_than.c \
mountinfo.c openrc-run.c rc-abort.c rc.c \
rc-depend.c rc-logger.c rc-misc.c rc-plugin.c \
rc-service.c rc-status.c rc-update.c \
rc-depend.c rc-logger.c rc-misc.c rc-pipes.c \
rc-plugin.c rc-service.c rc-status.c rc-update.c \
shell_var.c start-stop-daemon.c supervise-daemon.c swclock.c _usage.c
ifeq (${MKSELINUX},yes)
@@ -158,7 +158,7 @@ rc-service: rc-service.o _usage.o rc-misc.o
rc-update: rc-update.o _usage.o rc-misc.o
${CC} ${LOCAL_CFLAGS} ${LOCAL_LDFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ $^ ${LDADD}
start-stop-daemon: start-stop-daemon.o _usage.o rc-misc.o rc-schedules.o
start-stop-daemon: start-stop-daemon.o _usage.o rc-misc.o rc-pipes.o rc-schedules.o
${CC} ${LOCAL_CFLAGS} ${LOCAL_LDFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ $^ ${LDADD}
supervise-daemon: supervise-daemon.o _usage.o rc-misc.o rc-schedules.o

View File

@@ -269,11 +269,13 @@ int main(int argc, char **argv)
switch (opt) {
case 'D':
trunc = true;
/* falls through */
case 'd':
type = inode_dir;
break;
case 'F':
trunc = true;
/* falls through */
case 'f':
type = inode_file;
break;

56
src/rc/rc-pipes.c Normal file
View File

@@ -0,0 +1,56 @@
/*
* rc-pipes.c
* Helper to handle spawning processes and connecting them to pipes.
*/
/*
* Copyright (c) 2018 The OpenRC Authors.
* See the Authors file at the top-level directory of this distribution and
* https://github.com/OpenRC/openrc/blob/master/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/master/LICENSE
* This file may not be copied, modified, propagated, or distributed
* except according to the terms contained in the LICENSE file.
*/
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include "rc-pipes.h"
static const int pipe_read_end = 0;
static const int pipe_write_end = 1;
/*
* Starts a command with stdin redirected from a pipe
* Returns the write end of the pipe or -1
*/
int rc_pipe_command(char *cmd)
{
int pfd[2];
pid_t pid;
if (pipe(pfd) < 0)
return -1;
pid = fork();
if (pid > 0) {
/* parent */
close(pfd[pipe_read_end]);
return pfd[pipe_write_end];
} else if (pid == 0) {
/* child */
close(pfd[pipe_write_end]);
if (pfd[pipe_read_end] != STDIN_FILENO) {
if (dup2(pfd[pipe_read_end], STDIN_FILENO) < 0)
exit(1);
close(pfd[pipe_read_end]);
}
execl("/bin/sh", "sh", "-c", cmd, NULL);
exit(1);
}
return -1;
}

18
src/rc/rc-pipes.h Normal file
View File

@@ -0,0 +1,18 @@
/*
* Copyright (c) 2018 The OpenRC Authors.
* See the Authors file at the top-level directory of this distribution and
* https://github.com/OpenRC/openrc/blob/master/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/master/LICENSE
* This file may not be copied, modified, propagated, or distributed
* except according to the terms contained in the LICENSE file.
*/
#ifndef RC_PIPES_H
#define RC_PIPES_H
int rc_pipe_command(char *cmd);
#endif

View File

@@ -75,7 +75,7 @@ print_level(const char *prefix, const char *level)
printf("%s\n", level);
}
static void get_uptime(const char *service, char *uptime, int uptime_size)
static char *get_uptime(const char *service)
{
RC_SERVICE state = rc_service_state(service);
char *start_count;
@@ -87,8 +87,8 @@ static void get_uptime(const char *service, char *uptime, int uptime_size)
time_t diff_hours = (time_t) 0;
time_t diff_mins = (time_t) 0;
time_t diff_secs = (time_t) 0;
char *uptime;
uptime[0] = '\0';
if (state & RC_SERVICE_STARTED) {
start_count = rc_service_value_get(service, "start_count");
start_time_string = rc_service_value_get(service, "start_time");
@@ -110,23 +110,24 @@ static void get_uptime(const char *service, char *uptime, int uptime_size)
diff_secs %= diff_mins * (time_t) 60;
}
if (diff_days > 0)
snprintf(uptime, uptime_size,
xasprintf(&uptime,
"%ld day(s) %02ld:%02ld:%02ld (%s)",
diff_days, diff_hours, diff_mins, diff_secs,
start_count);
else
snprintf(uptime, uptime_size,
xasprintf(&uptime,
"%02ld:%02ld:%02ld (%s)",
diff_hours, diff_mins, diff_secs, start_count);
}
}
return uptime;
}
static void
print_service(const char *service)
{
char status[60];
char uptime [40];
char *status = NULL;
char *uptime = NULL;
char *child_pid = NULL;
char *start_time = NULL;
int cols = printf(" %s", service);
@@ -135,12 +136,12 @@ print_service(const char *service)
ECOLOR color = ECOLOR_BAD;
if (state & RC_SERVICE_STOPPING)
snprintf(status, sizeof(status), "stopping ");
xasprintf(&status, "stopping ");
else if (state & RC_SERVICE_STARTING) {
snprintf(status, sizeof(status), "starting ");
xasprintf(&status, "starting ");
color = ECOLOR_WARN;
} else if (state & RC_SERVICE_INACTIVE) {
snprintf(status, sizeof(status), "inactive ");
xasprintf(&status, "inactive ");
color = ECOLOR_WARN;
} else if (state & RC_SERVICE_STARTED) {
errno = 0;
@@ -149,26 +150,31 @@ print_service(const char *service)
child_pid = rc_service_value_get(service, "child_pid");
start_time = rc_service_value_get(service, "start_time");
if (start_time && child_pid)
snprintf(status, sizeof(status), " unsupervised ");
xasprintf(&status, " unsupervised ");
else
snprintf(status, sizeof(status), " crashed ");
xasprintf(&status, " crashed ");
free(child_pid);
free(start_time);
} else {
get_uptime(service, uptime, 40);
snprintf(status, sizeof(status), " started %s", uptime);
uptime = get_uptime(service);
if (uptime) {
xasprintf(&status, " started %s", uptime);
free(uptime);
} else
xasprintf(&status, " started ");
color = ECOLOR_GOOD;
}
} else if (state & RC_SERVICE_SCHEDULED) {
snprintf(status, sizeof(status), "scheduled");
xasprintf(&status, "scheduled");
color = ECOLOR_WARN;
} else
snprintf(status, sizeof(status), " stopped ");
xasprintf(&status, " stopped ");
errno = 0;
if (c && *c && isatty(fileno(stdout)))
printf("\n");
ebracket(cols, color, status);
free(status);
}
static void

View File

@@ -101,7 +101,6 @@ clean_failed(void)
{
DIR *dp;
struct dirent *d;
size_t l;
char *path;
/* Clean the failed services state dir now */
@@ -112,16 +111,11 @@ clean_failed(void)
(d->d_name[1] == '.' && d->d_name[2] == '\0')))
continue;
l = strlen(RC_SVCDIR "/failed/") +
strlen(d->d_name) + 1;
path = xmalloc(sizeof(char) * l);
snprintf(path, l, RC_SVCDIR "/failed/%s", d->d_name);
if (path) {
if (unlink(path))
eerror("%s: unlink `%s': %s",
applet, path, strerror(errno));
free(path);
}
xasprintf(&path, RC_SVCDIR "/failed/%s", d->d_name);
if (unlink(path))
eerror("%s: unlink `%s': %s",
applet, path, strerror(errno));
free(path);
}
closedir(dp);
}
@@ -391,7 +385,7 @@ static void
handle_signal(int sig)
{
int serrno = errno;
char signame[10] = { '\0' };
char *signame = NULL;
pid_t pid;
RC_PID *pi;
int status = 0;
@@ -422,16 +416,16 @@ handle_signal(int sig)
break;
case SIGINT:
if (!signame[0])
snprintf(signame, sizeof(signame), "SIGINT");
if (!signame)
xasprintf(&signame, "SIGINT");
/* FALLTHROUGH */
case SIGTERM:
if (!signame[0])
snprintf(signame, sizeof(signame), "SIGTERM");
if (!signame)
xasprintf(&signame, "SIGTERM");
/* FALLTHROUGH */
case SIGQUIT:
if (!signame[0])
snprintf(signame, sizeof(signame), "SIGQUIT");
if (!signame)
xasprintf(&signame, "SIGQUIT");
eerrorx("%s: caught %s, aborting", applet, signame);
/* NOTREACHED */
case SIGUSR1:
@@ -512,14 +506,11 @@ runlevel_config(const char *service, const char *level)
{
char *init = rc_service_resolve(service);
char *conf, *dir;
size_t l;
bool retval;
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", dir, service, level);
xasprintf(&conf, "%s/conf.d/%s.%s", dir, service, level);
retval = exists(conf);
free(conf);
free(init);
@@ -744,7 +735,7 @@ int main(int argc, char **argv)
bool going_down = false;
int depoptions = RC_DEP_STRICT | RC_DEP_TRACE;
char *krunlevel = NULL;
char pidstr[10];
char *pidstr = NULL;
int opt;
bool parallel;
int regen = 0;
@@ -844,8 +835,9 @@ int main(int argc, char **argv)
setenv("EINFO_LOG", "openrc", 1);
/* Export our PID */
snprintf(pidstr, sizeof(pidstr), "%d", getpid());
xasprintf(&pidstr, "%d", getpid());
setenv("RC_PID", pidstr, 1);
free(pidstr);
/* Create a list of all services which should be started for the new or
* current runlevel including those in boot, sysinit and hotplugged

View File

@@ -59,13 +59,14 @@ static struct pam_conv conv = { NULL, NULL};
#include "queue.h"
#include "rc.h"
#include "rc-misc.h"
#include "rc-pipes.h"
#include "rc-schedules.h"
#include "_usage.h"
#include "helpers.h"
const char *applet = NULL;
const char *extraopts = NULL;
const char *getoptstring = "I:KN:PR:Sa:bc:d:e:g:ik:mn:op:s:tu:r:w:x:1:2:" \
const char *getoptstring = "I:KN:PR:Sa:bc:d:e:g:ik:mn:op:s:tu:r:w:x:1:2:3:4:" \
getoptstring_COMMON;
const struct option longopts[] = {
{ "ionice", 1, NULL, 'I'},
@@ -93,6 +94,8 @@ const struct option longopts[] = {
{ "exec", 1, NULL, 'x'},
{ "stdout", 1, NULL, '1'},
{ "stderr", 1, NULL, '2'},
{ "stdout-logger",1, NULL, '3'},
{ "stderr-logger",1, NULL, '4'},
{ "progress", 0, NULL, 'P'},
longopts_COMMON
};
@@ -122,6 +125,8 @@ const char * const longopts_help[] = {
"Binary to start/stop",
"Redirect stdout to file",
"Redirect stderr to file",
"Redirect stdout to process",
"Redirect stderr to process",
"Print dots each second while waiting",
longopts_help_COMMON
};
@@ -162,20 +167,20 @@ handle_signal(int sig)
{
int status;
int serrno = errno;
char signame[10] = { '\0' };
char *signame = NULL;
switch (sig) {
case SIGINT:
if (!signame[0])
snprintf(signame, sizeof(signame), "SIGINT");
if (!signame)
xasprintf(&signame, "SIGINT");
/* FALLTHROUGH */
case SIGTERM:
if (!signame[0])
snprintf(signame, sizeof(signame), "SIGTERM");
if (!signame)
xasprintf(&signame, "SIGTERM");
/* FALLTHROUGH */
case SIGQUIT:
if (!signame[0])
snprintf(signame, sizeof(signame), "SIGQUIT");
if (!signame)
xasprintf(&signame, "SIGQUIT");
eerrorx("%s: caught %s, aborting", applet, signame);
/* NOTREACHED */
@@ -194,6 +199,9 @@ handle_signal(int sig)
eerror("%s: caught unknown signal %d", applet, sig);
}
/* free signame */
free(signame);
/* Restore errno */
errno = serrno;
}
@@ -202,7 +210,6 @@ static char *
expand_home(const char *home, const char *path)
{
char *opath, *ppath, *p, *nh;
size_t len;
struct passwd *pw;
if (!path || *path != '~')
@@ -233,9 +240,7 @@ expand_home(const char *home, const char *path)
return xstrdup(home);
}
len = strlen(ppath) + strlen(home) + 1;
nh = xmalloc(len);
snprintf(nh, len, "%s%s", home, ppath);
xasprintf(&nh, "%s%s", home, ppath);
free(opath);
return nh;
}
@@ -276,6 +281,8 @@ int main(int argc, char **argv)
int tid = 0;
char *redirect_stderr = NULL;
char *redirect_stdout = NULL;
char *stderr_process = NULL;
char *stdout_process = NULL;
int stdin_fd;
int stdout_fd;
int stderr_fd;
@@ -379,6 +386,7 @@ int main(int argc, char **argv)
case 'c': /* --chuid <username>|<uid> */
/* DEPRECATED */
ewarn("WARNING: -c/--chuid is deprecated and will be removed in the future, please use -u/--user instead");
/* falls through */
case 'u': /* --user <username>|<uid> */
{
p = optarg;
@@ -500,6 +508,14 @@ int main(int argc, char **argv)
redirect_stderr = optarg;
break;
case '3': /* --stdout-logger "command to run for stdout logging" */
stdout_process = optarg;
break;
case '4': /* --stderr-logger "command to run for stderr logging" */
stderr_process = optarg;
break;
case_RC_COMMON_GETOPT
}
@@ -551,6 +567,9 @@ int main(int argc, char **argv)
if (redirect_stdout || redirect_stderr)
eerrorx("%s: --stdout and --stderr are only relevant"
" with --start", applet);
if (stdout_process || stderr_process)
eerrorx("%s: --stdout-logger and --stderr-logger are only relevant"
" with --start", applet);
if (start_wait)
ewarn("using --wait with --stop has no effect,"
" use --retry instead");
@@ -563,6 +582,15 @@ int main(int argc, char **argv)
if ((redirect_stdout || redirect_stderr) && !background)
eerrorx("%s: --stdout and --stderr are only relevant"
" with --background", applet);
if ((stdout_process || stderr_process) && !background)
eerrorx("%s: --stdout-logger and --stderr-logger are only relevant"
" with --background", applet);
if (redirect_stdout && stdout_process)
eerrorx("%s: do not use --stdout and --stdout-logger together",
applet);
if (redirect_stderr && stderr_process)
eerrorx("%s: do not use --stderr and --stderr-logger together",
applet);
}
/* Expand ~ */
@@ -603,7 +631,6 @@ int main(int argc, char **argv)
*exec_file ? exec_file : exec);
free(exec_file);
exit(EXIT_FAILURE);
}
if (start && retry)
ewarn("using --retry with --start has no effect,"
@@ -886,6 +913,12 @@ int main(int argc, char **argv)
eerrorx("%s: unable to open the logfile"
" for stdout `%s': %s",
applet, redirect_stdout, strerror(errno));
}else if (stdout_process) {
stdout_fd = rc_pipe_command(stdout_process);
if (stdout_fd == -1)
eerrorx("%s: unable to open the logging process"
" for stdout `%s': %s",
applet, stdout_process, strerror(errno));
}
if (redirect_stderr) {
if ((stderr_fd = open(redirect_stderr,
@@ -894,13 +927,21 @@ int main(int argc, char **argv)
eerrorx("%s: unable to open the logfile"
" for stderr `%s': %s",
applet, redirect_stderr, strerror(errno));
}else if (stderr_process) {
stderr_fd = rc_pipe_command(stderr_process);
if (stderr_fd == -1)
eerrorx("%s: unable to open the logging process"
" for stderr `%s': %s",
applet, stderr_process, strerror(errno));
}
if (background)
dup2(stdin_fd, STDIN_FILENO);
if (background || redirect_stdout || rc_yesno(getenv("EINFO_QUIET")))
if (background || redirect_stdout || stdout_process
|| rc_yesno(getenv("EINFO_QUIET")))
dup2(stdout_fd, STDOUT_FILENO);
if (background || redirect_stderr || rc_yesno(getenv("EINFO_QUIET")))
if (background || redirect_stderr || stderr_process
|| rc_yesno(getenv("EINFO_QUIET")))
dup2(stderr_fd, STDERR_FILENO);
for (i = getdtablesize() - 1; i >= 3; --i)

View File

@@ -186,7 +186,6 @@ static void handle_signal(int sig)
static char * expand_home(const char *home, const char *path)
{
char *opath, *ppath, *p, *nh;
size_t len;
struct passwd *pw;
if (!path || *path != '~')
@@ -217,9 +216,7 @@ static char * expand_home(const char *home, const char *path)
return xstrdup(home);
}
len = strlen(ppath) + strlen(home) + 1;
nh = xmalloc(len);
snprintf(nh, len, "%s%s", home, ppath);
xasprintf(&nh, "%s%s", home, ppath);
free(opath);
return nh;
}
@@ -863,10 +860,13 @@ int main(int argc, char **argv)
varbuf = NULL;
xasprintf(&varbuf, "%i", respawn_delay);
rc_service_value_set(svcname, "respawn_delay", varbuf);
free(varbuf);
xasprintf(&varbuf, "%i", respawn_max);
rc_service_value_set(svcname, "respawn_max", varbuf);
free(varbuf);
xasprintf(&varbuf, "%i", respawn_period);
rc_service_value_set(svcname, "respawn_period", varbuf);
free(varbuf);
child_pid = fork();
if (child_pid == -1)
eerrorx("%s: fork: %s", applet, strerror(errno));
@@ -894,6 +894,7 @@ int main(int argc, char **argv)
}
xasprintf(&varbuf, "%d", x);
rc_service_value_set(svcname, "argc", varbuf);
free(varbuf);
rc_service_value_set(svcname, "exec", exec);
supervisor(exec, argv);
} else

View File

@@ -90,8 +90,8 @@ the service script by hand.
FIXME: Document stacked runlevels
The default startup uses the runlevels `boot`, `sysinit` and `default`, in that
order. Shutdown uses the `shutdown` runlevel.
The default startup uses the runlevels `sysinit`, `boot`, and `default`,
in that order. Shutdown uses the `shutdown` runlevel.
# The Magic of `conf.d`
@@ -162,7 +162,6 @@ stopped, by using:
The `rc_cgroup_cleanup` setting can be changed to yes to make this
happen automatically when the service is stopped.
# Caching
For performance reasons OpenRC keeps a cache of pre-parsed service metadata