Compare commits

..

29 Commits

Author SHA1 Message Date
Daniel Robbins
d308a781f2 Copyright update 2015-03-14 17:46:23 -06:00
Daniel Robbins
888bc07f7b Update /etc/conf.d/hostname with better documentation. 2015-03-14 17:43:26 -06:00
Daniel Robbins
8169cd89b1 Revert "FL-227: Change how /etc/hosts is generated"
This change was never discussed in the bug on the bug tracker. It is thus being removed.

This reverts commit 6b78f4c8e0.
2015-03-14 17:38:50 -06:00
Daniel Robbins
e67ab2da48 FL-1906: fix hostname setting so 'hostname' returns short, not full, hostname. 2015-01-03 21:22:27 -07:00
Oleg Vinichenko
8137d15c1a FL-1729: backport tmpfiles changes from upstream 2014-12-02 20:40:58 +00:00
Dantrell B
7447c63e02 Replace space with tab in conf.d/hostname 2014-08-16 02:23:49 -04:00
Dantrell B
6b78f4c8e0 FL-227: Change how /etc/hosts is generated 2014-08-13 18:09:34 -04:00
Dantrell B
e8b4dc22cb FL-227: Add comment to conf.d/hostname about setting aliases 2014-08-13 18:09:06 -04:00
Dantrell B
5fb4b03366 FL-28: Add comment to conf.d/hostname about setting nisdomainname 2014-08-13 12:44:39 -04:00
Dantrell B
76581025ea FL-967: Improve comment in conf.d/hostname about setting hostname 2014-08-13 12:15:51 -04:00
Daniel Robbins
a559af4ff9 remove trailing whitespace in sysctl.Linux.in, which produces a warning during build 2014-08-12 13:35:09 -04:00
Daniel Robbins
35fe25ab06 FL-786: funtoo hostname changes 2014-08-12 13:35:09 -04:00
Daniel Robbins
a2e4cb2f89 FL-786: sysctl.Linux.in: set System V SHM to 25% of RAM 2014-08-12 13:35:09 -04:00
Oleg Vinichenko
0490a83134 FL-786: openrc: remove loopback interface 2014-08-12 13:35:08 -04:00
Steven Chamberlain
0853c110e5 Begin port to GNU/kFreeBSD
This is just a minimal port to get Debian up and running; the rest will
be done later.
2013-10-30 15:00:40 -05:00
William Hubbs
1a43ce11d0 bootmisc: do not run clean_run on VSERVER systems
X-Gentoo-Bug: 489370
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=489370
2013-10-28 15:40:47 -05:00
William Hubbs
46e504b403 loopback: do not run in a prefix or vserver
X-Gentoo-Bug: 489370
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=489370
2013-10-28 15:40:16 -05:00
William Hubbs
fc1f3d14f4 start 0.12.4 2013-10-28 15:39:19 -05:00
Alexander V Vershilov
b8a016aaba Add uml keyword to fsck service.
Fix relevant an issue mentioned by Toralf Förster.

X-Gentoo-Bug: 481096.
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=481096
2013-10-18 15:22:24 -05:00
William Hubbs
63f5256b59 start work on OpenRC-0.12.3 2013-10-18 15:19:52 -05:00
Daniel Robbins
c420f56856 FL-786: localmount: support filesystem mounting on openvz 2013-10-08 12:06:09 -05:00
Natanael Copa
5b0f323da9 librc: fix off-by-one bug
We need allocate space for both the added leading '-' and the trailing
'\0'.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
2013-10-08 12:06:09 -05:00
Natanael Copa
d86853538a librc: fix a read off-by-one bug
We should first check if we are within bounds and then read rather than
the opposite.

This makes valgrind happy.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
2013-10-08 12:06:09 -05:00
William Hubbs
f2c0e700c6 netmount: add -lxc keyword
Netmount should not run on lxc, thanks to Mark van Dijk <funtoo@internecto.net>.
2013-10-08 12:06:09 -05:00
William Hubbs
b1de9d7324 start-stop-daemon: fix do_stop calls
Several calls to do_stop were forcing the test parameter to be true,
which was causing extra output to the terminal, such as:

* Would send signal 0 to pid xxxxx

This should only happen if the --test command line option was used.

Conflicts:
	src/rc/start-stop-daemon.c
2013-10-08 12:06:09 -05:00
William Hubbs
5b4886d23e start-stop-daemon: fix eerorr calls in get_pid
The eerror calls in this function make it too verbose, so change them to
ewarnv() calls instead. This means that they will only print if the
--verbose option is used or EINFO_VERBOSE=yes is set in the environment.
2013-10-08 12:06:09 -05:00
William Hubbs
2a53efbc07 start work on OpenRC-0.12.2 2013-10-08 12:03:47 -05:00
William Hubbs
a530722f65 fix cgroup_cleanup function
The yesno test for rc_cgroup_cleanup belongs at the point where this
function is called from runscript, not in the function itself.

X-Gentoo-Bug: 486210
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=486210
2013-10-02 05:43:51 -05:00
William Hubbs
661e9cf002 start work on OpenRC 0.12.1 2013-10-02 05:40:18 -05:00
26 changed files with 257 additions and 250 deletions

View File

@@ -1,3 +1,3 @@
NAME= openrc
VERSION= 0.12.1
VERSION= 0.12.4
PKG= ${NAME}-${VERSION}

View File

@@ -1,2 +1,18 @@
# Set to the fully-qualified hostname of this machine
# Set to the fully qualified domain name (e.g. "mybox.example.com") of this
# machine, if it has one, otherwise set to the machine name (e.g. "mybox").
# This hostname will be automatically added to /etc/hosts for the 127.0.0.1 and
# ::1 addresses.
hostname="localhost"
# If your local system has other aliases for your local interfaces, you can
# add them here. These will also be added to /etc/hosts for 127.0.0.1 and ::1:
# Add aliases for other hosts to /etc/hosts directly. The networking scripts
# automatically generate the localhost lines only.
#aliases="mybox server1"
# Set to the NIS domain name of this machine, if it has one, otherwise leave
# commented out.
#nisdomainname="localdomain.com"

11
etc/rc.conf.GNU-kFreeBSD Normal file
View File

@@ -0,0 +1,11 @@
##############################################################################
# GNU/kFreeBSD SPECIFIC OPTIONS
# This is the subsystem type. Valid options on GNU/kFreeBSD:
# "" - nothing special
# "jail" - FreeBSD jails (not yet implemented)
# If this is commented out, automatic detection will be used.
#
# This should be set to the value representing the environment this file is
# PRESENTLY in, not the virtualization the environment is capable of.
#rc_sys=""

3
init.d/.gitignore vendored
View File

@@ -4,6 +4,8 @@ hostname
local
localmount
moused
net.lo
net.lo0
netmount
network
root
@@ -39,5 +41,4 @@ syslogd
termencoding
ttys
wscons
tmpfiles.dev
tmpfiles.setup

View File

@@ -117,6 +117,7 @@ migrate_to_run()
clean_run()
{
[ "$RC_SYS" = VSERVER ] && return 0
local dir
dir=$(mktemp -d)
mount --bind / $dir

View File

@@ -9,7 +9,7 @@ _IFS="
depend()
{
use dev clock modules
keyword -jail -openvz -prefix -timeout -vserver -lxc
keyword -jail -openvz -prefix -timeout -vserver -lxc -uml
}
_abort() {

View File

@@ -1,5 +1,5 @@
#!@PREFIX@/sbin/runscript
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
# Copyright (c) 2009-2015 Funtoo Technologies
# Released under the 2-clause BSD license.
description="Sets the hostname of the machine."
@@ -38,6 +38,6 @@ END
eend $?
[ "$RC_SYS" = "LXC" ] && return 0
ebegin "Setting hostname to $hostname"
hostname "$hostname"
hostname "$short"
eend $? "Failed to set the hostname"
}

View File

@@ -14,8 +14,7 @@ depend()
start()
{
ebegin "setting up tmpfiles.d entries for /dev"
@LIBEXECDIR@/sh/tmpfiles.sh --prefix=/dev --create --remove \
${tmpfiles_opts}
@LIBEXECDIR@/sh/tmpfiles.sh --prefix=/dev --create ${tmpfiles_opts}
eend $?
return 0
}

View File

@@ -12,7 +12,7 @@ depend()
start()
{
ebegin "setting up tmpfiles.d entries"
@LIBEXECDIR@/sh/tmpfiles.sh --exclude-prefix=/dev --create --remove \
@LIBEXECDIR@/sh/tmpfiles.sh --exclude-prefix=/dev --create --remove --boot \
${tmpfiles_opts}
eend $?
return 0

View File

@@ -105,8 +105,7 @@ and
respectively, but only work when
.Va EINFO_VERBOSE
is true. You can also make the
.Fn einfo ,
.Fn ewarn ,
.Fn einfo
and
.Fn ebegin
functions silent by setting
@@ -185,12 +184,6 @@ when set to true makes the
and
.Fn einfon
family of functions quiet, so nothing is printed.
.Va EERROR_QUIET
when set to true makes the
.Fn eerror
and
.Fn eerrorn
family of functions quiet, so nothing is printed.
.Pp
.Va EINFO_VERBOSE
when set to true makes the

View File

@@ -60,12 +60,12 @@ First we ensure that any services that depend on us are stopped. If any
services that need us fail to stop then we exit with a suitable error,
otherwise call the supplied stop function if it exists.
.It Ar restart
Stops and starts the service, including dependencies. This cannot be
Stop and start the service, including dependencies. This cannot be
overridden. See the description of the RC_CMD variable below for the
method to make your service behave differently when restart is being
executed.
.It Ar status
Shows the status of the service. The return code matches the status, with the
Show the status of the service. The return code matches the status, with the
exception of "started" returning 0 to match standard command behaviour.
.It Ar zap
Resets the service state to stopped and removes all saved data about the
@@ -88,8 +88,8 @@ Output from any non OpenRC commands is not affected.
.It Fl v , -verbose
Turns on any extra informational output the service generates.
.It Fl Z , -dry-run
Shows which services would be stopped and/or started without actually stopping
or starting them.
Shows what services would be stopped and/or started without actually starting
or stopping them.
.El
.Pp
The following variables affect the service script:
@@ -471,7 +471,7 @@ start_pre()
# stop_post.
fi
# Ensure that our dirs are correct
checkpath --directory --owner foo:foo --mode 0775 \\
checkpath --dir --owner foo:foo --mode 0664 \\
/var/run/foo /var/cache/foo
}

9
mk/os-GNU-kFreeBSD.mk Normal file
View File

@@ -0,0 +1,9 @@
# Copyright (c) 2008 Roy Marples <roy@marples.name>
# Released under the 2-clause BSD license.
# Generic definitions
CPPFLAGS+= -D_BSD_SOURCE -D_XOPEN_SOURCE=700
LIBDL= -Wl,-Bdynamic -ldl
LIBKVM?=
include ${MK}/os-BSD.mk

View File

@@ -3,7 +3,7 @@
# Generic definitions
_OS_SH= uname -s
_OS_SH= uname -s | tr '/' '-'
_OS:= $(shell ${_OS_SH})
OS?= ${_OS}
include ${MK}/os-${OS}.mk

View File

@@ -3,10 +3,11 @@
# Control creation, deletion, and cleaning of volatile and temporary files
#
# Copyright (c) 2012 Gentoo Foundation
# Released under the 2-clause BSD license.
#
# This instance based on the Arch Linux version:
# This instance is a pure-POSIX sh version, written by Robin H Johnson
# <robbat2@gentoo.org>, based on the Arch Linux version as of 2012/01/01:
# http://projects.archlinux.org/initscripts.git/tree/arch-tmpfiles
# As of 2012/01/01
#
# See the tmpfiles.d manpage as well:
# http://0pointer.de/public/systemd-man/tmpfiles.d.html
@@ -14,6 +15,7 @@
#
DRYRUN=0
CHECKPATH="@LIBEXECDIR@/bin/checkpath"
checkprefix() {
n=$1
@@ -43,19 +45,27 @@ relabel() {
for path in ${paths}; do
if [ -e "$path" ]; then
[ -x /sbin/restorecon ] && dryrun_or_real restorecon $CHOPTS "$path"
[ $uid != '-' ] && dryrun_or_real chown $CHOPTS "$uid" "$path"
[ $gid != '-' ] && dryrun_or_real chgrp $CHOPTS "$gid" "$path"
[ $mode != '-' ] && dryrun_or_real chmod $CHOPTS "$mode" "$path"
[ -x /sbin/restorecon ] && dryrun_or_real restorecon $CHOPTS "$path"
fi
done
}
_restorecon() {
local path=$1
if [ -x /sbin/restorecon ]; then
dryrun_or_real restorecon -F "$path"
fi
}
_b() {
# Create a block device node if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
if [ ! -e "$path" ]; then
dryrun_or_real mknod -m $mode $path b ${arg%:*} ${arg#*:}
_restorecon "$path"
dryrun_or_real chown $uid:$gid $path
fi
}
@@ -65,10 +75,22 @@ _c() {
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
if [ ! -e "$path" ]; then
dryrun_or_real mknod -m $mode $path c ${arg%:*} ${arg#*:}
_restorecon "$path"
dryrun_or_real chown $uid:$gid $path
fi
}
_C() {
# recursively copy a file or directory
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
if [ ! -e "$path" ]; then
dryrun_or_real cp -r "$arg" "$path"
_restorecon "$path"
[ $uid != '-' ] && dryrun_or_real chown "$uid" "$path"
[ $gid != '-' ] && dryrun_or_real chgrp "$gid" "$path"
[ $mode != '-' ] && dryrun_or_real chmod "$mode" "$path"
fi
}
_f() {
# Create a file if it doesn't exist yet
@@ -77,7 +99,7 @@ _f() {
[ $CREATE -gt 0 ] || return 0
if [ ! -e "$path" ]; then
dryrun_or_real install -m"$mode" -o"$uid" -g"$gid" /dev/null "$path"
dryrun_or_real $CHECKPATH -fq -m "$mode" -o "$uid:$gid" "$path"
[ -z "$arg" ] || _w "$@"
fi
}
@@ -88,7 +110,7 @@ _F() {
[ $CREATE -gt 0 ] || return 0
dryrun_or_real install -m"$mode" -o"$uid" -g"$gid" /dev/null "$path"
dryrun_or_real $CHECKPATH -Fq -m "$mode" -o "$uid:$gid" "$path"
[ -z "$arg" ] || _w "$@"
}
@@ -99,7 +121,8 @@ _d() {
[ $CREATE -gt 0 ] || return 0
if [ ! -d "$path" ]; then
dryrun_or_real install -d -m"$mode" -o"$uid" -g"$gid" "$path"
dryrun_or_real mkdir -p "$path" 2>/dev/null
dryrun_or_real $CHECKPATH -dq -m "$mode" -o "$uid:$gid" "$path"
fi
}
@@ -109,10 +132,12 @@ _D() {
if [ -d "$path" ] && [ $REMOVE -gt 0 ]; then
dryrun_or_real find "$path" -mindepth 1 -maxdepth 1 -xdev -exec rm -rf {} +
_restorecon "$path"
fi
if [ $CREATE -gt 0 ]; then
dryrun_or_real install -d -m"$mode" -o"$uid" -g"$gid" "$path"
dryrun_or_real mkdir -p "$path" 2>/dev/null
dryrun_or_real $CHECKPATH -Dq -m "$mode" -o "$uid:$gid" "$path"
fi
}
@@ -120,6 +145,7 @@ _L() {
# Create a symlink if it doesn't exist yet
local path=$1 mode=$2 uid=$3 gid=$4 age=$5 arg=$6
[ ! -e "$path" ] && dryrun_or_real ln -s "$arg" "$path"
_restorecon "$path"
}
_p() {
@@ -129,8 +155,7 @@ _p() {
[ $CREATE -gt 0 ] || return 0
if [ ! -p "$path" ]; then
dryrun_or_real mkfifo -m$mode "$path"
dryrun_or_real chown "$uid:$gid" "$path"
dryrun_or_real $CHECKPATH -pq -m $mode -o "$uid:$gid" "$path"
fi
}
@@ -214,7 +239,7 @@ _Z() {
CHOPTS=-R relabel "$@"
}
CREATE=0 REMOVE=0 CLEAN=0 VERBOSE=0 DRYRUN=0 error=0 LINENO=0
BOOT=0 CREATE=0 REMOVE=0 CLEAN=0 VERBOSE=0 DRYRUN=0 error=0 LINENO=0
EXCLUDE=
PREFIX=
FILE=
@@ -230,11 +255,13 @@ tmpfiles_d=''
# `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf'
for d in ${tmpfiles_dirs} ; do
[ -d $d ] && for f in ${d}/*.conf ; do
[ "$f" = "$d/systemd.conf" ] && continue
case "${f##*/}" in
systemd.conf|systemd-*.conf) continue;;
esac
[ -f $f ] && tmpfiles_basenames="${tmpfiles_basenames}\n${f##*/}"
done # for f in ${d}
done # for d in ${tmpfiles_dirs}
tmpfiles_basenames="`printf "${tmpfiles_basenames}\n" | sort | uniq`"
tmpfiles_basenames="$(printf "${tmpfiles_basenames}\n" | sort -u )"
for b in $tmpfiles_basenames ; do
real_f=''
@@ -247,6 +274,7 @@ done
while [ $# -gt 0 ]; do
case $1 in
--boot) BOOT=1 ;;
--create) CREATE=1 ;;
--remove) REMOVE=1 ;;
--clean) CLEAN=1 ;; # TODO: Not implemented
@@ -264,7 +292,7 @@ if [ $(( CLEAN )) -eq 1 ] ; then
fi
if [ "$CREATE$REMOVE" = '00' ]; then
printf 'usage: %s [--exclude-prefix=path] [--prefix=path] [--create] [--remove] [--clean] [--verbose] [--dry-run]\n' "${0##*/}"
printf 'usage: %s [--exclude-prefix=path] [--prefix=path] [--boot] [--create] [--remove] [--clean] [--verbose] [--dry-run]\n' "${0##*/}"
exit 1
fi
@@ -281,21 +309,34 @@ for FILE in $tmpfiles_d ; do
# Cmd Path Mode UID GID Age Argument
# d /run/user 0755 root root 10d -
# Mode, UID, GID, Age, Argument may be omitted!
# If Cmd ends with !, the line is only processed if --boot is passed
# XXX: Upstream says whitespace is NOT permitted in the Path argument.
# But IS allowed when globs are expanded for the x/r/R/z/Z types.
while read cmd path mode uid gid age arg; do
LINENUM=$(( LINENUM+1 ))
FORCE=0
# Unless we have both command and path, skip this line.
if [ -z "$cmd" -o -z "$path" ]; then
continue
fi
case $cmd in
\#*) continue ;;
esac
while [ ${#cmd} -gt 1 ]; do
case $cmd in
*!) cmd=${cmd%!}; [ "$BOOT" -eq "1" ] || continue 2 ;;
*+) cmd=${cmd%+}; FORCE=1; ;;
*) warninvalid ; continue 2 ;;
esac
done
# whine about invalid entries
case $cmd in
f|F|w|d|D|p|L|c|b|x|X|r|R|z|Z) ;;
\#) continue ;;
f|F|w|d|D|p|L|c|C|b|x|X|r|R|z|Z) ;;
*) warninvalid ; continue ;;
esac
@@ -304,7 +345,7 @@ for FILE in $tmpfiles_d ; do
case "$cmd" in
p|f|F) mode=0644 ;;
d|D) mode=0755 ;;
z|Z|x|r|R|L) ;;
C|z|Z|x|r|R|L) ;;
esac
fi
@@ -316,6 +357,13 @@ for FILE in $tmpfiles_d ; do
[ -n "$EXCLUDE" ] && checkprefix $path $EXCLUDE && continue
[ -n "$PREFIX" ] && ! checkprefix $path $PREFIX && continue
if [ $FORCE -gt 0 ]; then
case $cmd in
p|L|c|b) [ -f "$path" ] && dryrun_or_real rm -f "$path"
esac
fi
[ "$VERBOSE" -eq "1" ] && echo _$cmd "$@"
_$cmd "$@"
rc=$?

View File

@@ -273,12 +273,6 @@ is_quiet(void)
return yesno(getenv("EINFO_QUIET"));
}
static bool
is_really_quiet(void)
{
return yesno(getenv("EERROR_QUIET"));
}
static bool
is_verbose(void)
{
@@ -680,8 +674,6 @@ eerrorn(const char *EINFO_RESTRICT fmt, ...)
int retval;
va_list ap;
if (!fmt || is_really_quiet())
return 0;
va_start(ap, fmt);
retval = _eerrorvn(fmt, ap);
va_end(ap);
@@ -713,7 +705,7 @@ ewarn(const char *EINFO_RESTRICT fmt, ...)
int retval;
va_list ap;
if (!fmt || is_quiet())
if (!fmt)
return 0;
va_start(ap, fmt);
elogv(LOG_WARNING, fmt, ap);
@@ -748,7 +740,7 @@ eerror(const char *EINFO_RESTRICT fmt, ...)
int retval;
va_list ap;
if (!fmt || is_really_quiet())
if (!fmt)
return 0;
va_start(ap, fmt);
elogv(LOG_ERR, fmt, ap);
@@ -765,7 +757,7 @@ eerrorx(const char *EINFO_RESTRICT fmt, ...)
{
va_list ap;
if (fmt && !is_really_quiet()) {
if (fmt) {
va_start(ap, fmt);
elogv(LOG_ERR, fmt, ap);
_eerrorvn(fmt, ap);

View File

@@ -30,7 +30,7 @@
#include "librc.h"
#if defined(__linux__)
#if defined(__linux__) || defined (__GLIBC__)
static bool
pid_is_exec(pid_t pid, const char *exec)
{

View File

@@ -323,42 +323,6 @@ rc_parse_service_state(RC_SERVICE state)
return NULL;
}
/* Returns a list of all the chained runlevels used by the
* specified runlevel in dependency order, including the
* specified runlevel. */
static void
get_runlevel_chain(const char *runlevel, RC_STRINGLIST *level_list)
{
char path[PATH_MAX];
RC_STRINGLIST *dirs;
RC_STRING *d, *dn;
/*
* If we haven't been passed a runlevel or a level list, or
* if the passed runlevel doesn't exist then we're done already!
*/
if (!runlevel || !level_list || !rc_runlevel_exists(runlevel))
return;
/*
* We want to add this runlevel to the list but if
* it is already in the list it needs to go at the
* end again.
*/
if (rc_stringlist_find(level_list, runlevel))
rc_stringlist_delete(level_list, runlevel);
rc_stringlist_add(level_list, runlevel);
/*
* We can now do exactly the above procedure for our chained
* runlevels.
*/
snprintf(path, sizeof(path), "%s/%s", RC_RUNLEVELDIR, runlevel);
dirs = ls_dir(path, LS_DIR);
TAILQ_FOREACH_SAFE(d, dirs, entries, dn)
get_runlevel_chain(d->value, level_list);
}
bool
rc_runlevel_starting(void)
{
@@ -460,10 +424,22 @@ librc_hidden_def(rc_runlevel_unstack)
RC_STRINGLIST *
rc_runlevel_stacks(const char *runlevel)
{
RC_STRINGLIST *stack;
stack = rc_stringlist_new();
get_runlevel_chain(runlevel, stack);
return stack;
char path[PATH_MAX];
RC_STRINGLIST *dirs;
RC_STRING *d, *dn;
if (!runlevel)
return false;
snprintf(path, sizeof(path), "%s/%s", RC_RUNLEVELDIR, runlevel);
dirs = ls_dir(path, LS_DIR);
TAILQ_FOREACH_SAFE(d, dirs, entries, dn) {
if (!rc_runlevel_exists(d->value)) {
TAILQ_REMOVE(dirs, d, entries);
free(d->value);
free(d);
}
}
return dirs;
}
librc_hidden_def(rc_runlevel_stacks)
@@ -927,13 +903,17 @@ rc_services_in_runlevel_stacked(const char *runlevel)
stacks = rc_runlevel_stacks(runlevel);
TAILQ_FOREACH(stack, stacks, entries) {
sl = rc_services_in_runlevel(stack->value);
TAILQ_CONCAT(list, sl, entries);
free(sl);
if (list != NULL) {
TAILQ_CONCAT(list, sl, entries);
free(sl);
} else
list = sl;
}
return list;
}
librc_hidden_def(rc_services_in_runlevel_stacked)
RC_STRINGLIST *
rc_services_in_state(RC_SERVICE state)
{

1
src/rc/.gitignore vendored
View File

@@ -3,7 +3,6 @@ rc-status
rc-service
rc-update
runscript
service
start-stop-daemon
einfon
einfo

View File

@@ -35,21 +35,6 @@
# define _noreturn
#endif
static void set_quiet_options(void)
{
static int qcount = 0;
qcount ++;
switch (qcount) {
case 1:
setenv ("EINFO_QUIET", "YES", 1);
break;
case 2:
setenv ("EERROR_QUIET", "YES", 1);
break;
}
}
_noreturn static void
show_version(void)
{

View File

@@ -38,13 +38,13 @@
"Disable color output", \
"Display software version", \
"Run verbosely", \
"Run quietly (repeat to suppress errors)"
"Run quietly (Does not affect errors)"
#define case_RC_COMMON_getopt_case_C setenv ("EINFO_COLOR", "NO", 1);
#define case_RC_COMMON_getopt_case_h usage (EXIT_SUCCESS);
#define case_RC_COMMON_getopt_case_V if (argc == 2) show_version();
#define case_RC_COMMON_getopt_case_v setenv ("EINFO_VERBOSE", "YES", 1);
#define case_RC_COMMON_getopt_case_q set_quiet_options();
#define case_RC_COMMON_getopt_case_q setenv ("EINFO_QUIET", "YES", 1);
#define case_RC_COMMON_getopt_default usage (EXIT_FAILURE);
#define case_RC_COMMON_GETOPT \

View File

@@ -39,7 +39,7 @@
# include <sys/statvfs.h>
# define statfs statvfs
# define F_FLAGS f_flag
#elif defined (__linux__)
#elif defined (__linux__) || defined (__GLIBC__)
# include <mntent.h>
#endif
@@ -265,7 +265,7 @@ find_mounts(struct args *args)
return list;
}
#elif defined (__linux__)
#elif defined (__linux__) || defined (__GLIBC__)
static struct mntent *
getmntfile(const char *file)
{

View File

@@ -44,7 +44,7 @@
#include <time.h>
#include <unistd.h>
#ifdef __linux__
#if defined(__linux__) || defined(__GLIBC__)
# include <pty.h>
#elif defined(__NetBSD__) || defined(__OpenBSD__)
# include <util.h>

View File

@@ -171,26 +171,6 @@ print_services(const char *runlevel, RC_STRINGLIST *svcs)
rc_stringlist_free(l);
}
static void
print_stacked_services(const char *runlevel)
{
RC_STRINGLIST *stackedlevels, *servicelist;
RC_STRING *stackedlevel;
stackedlevels = rc_runlevel_stacks(runlevel);
TAILQ_FOREACH(stackedlevel, stackedlevels, entries) {
if (rc_stringlist_find(levels, stackedlevel->value) != NULL)
continue;
print_level("Stacked", stackedlevel->value);
servicelist = rc_services_in_runlevel(stackedlevel->value);
print_services(stackedlevel->value, servicelist);
rc_stringlist_free(servicelist);
print_stacked_services(stackedlevel->value);
}
rc_stringlist_free(stackedlevels);
stackedlevels = NULL;
}
#include "_usage.h"
#define usagestring "" \
"Usage: rc-status [options] <runlevel>...\n" \
@@ -219,8 +199,7 @@ static const char * const longopts_help[] = {
int
rc_status(int argc, char **argv)
{
RC_STRING *s, *l, *t, *level;
RC_STRING *s, *l, *t;
char *p, *runlevel = NULL;
int opt, aflag = 0, retval = 0;
@@ -301,7 +280,16 @@ rc_status(int argc, char **argv)
print_level(NULL, l->value);
services = rc_services_in_runlevel(l->value);
print_services(l->value, services);
print_stacked_services(l->value);
nservices = rc_runlevel_stacks(l->value);
TAILQ_FOREACH(s, nservices, entries) {
if (rc_stringlist_find(levels, s->value) != NULL)
continue;
print_level("Stacked", s->value);
sservices = rc_services_in_runlevel(s->value);
print_services(s->value, sservices);
rc_stringlist_free(sservices);
}
sservices = NULL;
rc_stringlist_free(nservices);
nservices = NULL;
rc_stringlist_free(services);
@@ -329,14 +317,16 @@ rc_status(int argc, char **argv)
services = rc_services_in_runlevel(NULL);
sservices = rc_stringlist_new();
TAILQ_FOREACH(l, levels, entries) {
nservices = rc_services_in_runlevel_stacked(l->value);
nservices = rc_services_in_runlevel(l->value);
TAILQ_CONCAT(sservices, nservices, entries);
free(nservices);
}
TAILQ_FOREACH_SAFE(s, services, entries, t) {
if ((rc_stringlist_find(sservices, s->value) ||
(rc_service_state(s->value) & ( RC_SERVICE_STOPPED | RC_SERVICE_HOTPLUGGED)))) {
TAILQ_REMOVE(services, s, entries);
if (rc_stringlist_find(sservices, s->value) ||
rc_service_state(s->value) &
(RC_SERVICE_STOPPED | RC_SERVICE_HOTPLUGGED))
{
TAILQ_REMOVE(services, s, entries);
free(s->value);
free(s);
}
@@ -347,23 +337,22 @@ rc_status(int argc, char **argv)
alist = rc_stringlist_new();
l = rc_stringlist_add(alist, "");
p = l->value;
TAILQ_FOREACH(level, levels, entries) {
TAILQ_FOREACH_SAFE(s, services, entries, t) {
l->value = s->value;
setenv("RC_SVCNAME", l->value, 1);
tmp = rc_deptree_depends(deptree, needsme, alist, level->value, RC_DEP_TRACE);
if (TAILQ_FIRST(tmp)) {
TAILQ_REMOVE(services, s, entries);
TAILQ_INSERT_TAIL(nservices, s, entries);
}
rc_stringlist_free(tmp);
if (!runlevel)
runlevel = rc_runlevel_get();
TAILQ_FOREACH_SAFE(s, services, entries, t) {
l->value = s->value;
unsetenv("RC_SVCNAME");
setenv("RC_SVCNAME", l->value, 1);
tmp = rc_deptree_depends(deptree, needsme, alist, runlevel, RC_DEP_TRACE);
if (TAILQ_FIRST(tmp)) {
TAILQ_REMOVE(services, s, entries);
TAILQ_INSERT_TAIL(nservices, s, entries);
}
rc_stringlist_free(tmp);
}
l->value = p;
/*
* we are unsetting RC_SVCNAME because last loaded service will not
* be added to the list
*/
/* we are unsetting RC_SVCNAME because last loaded service
wount be added to list */
unsetenv("RC_SVCNAME");
print_level("Dynamic", "needed");
print_services(NULL, nservices);

View File

@@ -79,6 +79,12 @@ const char rc_copyright[] = "Copyright (c) 2007-2008 Roy Marples";
const char *applet = NULL;
static char *runlevel;
static RC_STRINGLIST *hotplugged_services;
static RC_STRINGLIST *stop_services;
static RC_STRINGLIST *start_services;
static RC_STRINGLIST *types_n;
static RC_STRINGLIST *types_nua;
static RC_DEPTREE *deptree;
static RC_HOOK hook_out;
struct termios *termios_orig = NULL;
@@ -518,9 +524,7 @@ runlevel_config(const char *service, const char *level)
}
static void
do_stop_services(const RC_STRINGLIST *types_n, const RC_STRINGLIST *start_services,
const RC_STRINGLIST *stop_services, const RC_DEPTREE *deptree,
const char *newlevel, bool parallel, bool going_down)
do_stop_services(const char *newlevel, bool parallel, bool going_down)
{
pid_t pid;
RC_STRING *service, *svc1, *svc2;
@@ -623,7 +627,7 @@ stop:
}
static void
do_start_services(const RC_STRINGLIST *start_services, bool parallel)
do_start_services(bool parallel)
{
RC_STRING *service;
pid_t pid;
@@ -750,12 +754,6 @@ main(int argc, char **argv)
{
const char *bootlevel = NULL;
char *newlevel = NULL;
static RC_STRINGLIST *hotplugged_services;
static RC_STRINGLIST *stop_services;
static RC_STRINGLIST *start_services;
static RC_STRINGLIST *types_n;
static RC_STRINGLIST *types_nua;
static RC_DEPTREE *deptree;
RC_STRINGLIST *deporder = NULL;
RC_STRINGLIST *tmplist;
RC_STRING *service;
@@ -870,11 +868,7 @@ main(int argc, char **argv)
snprintf(pidstr, sizeof(pidstr), "%d", getpid());
setenv("RC_PID", pidstr, 1);
/* Create a list of all services which should be started for the new or
* current runlevel including those in boot, sysinit and hotplugged
* runlevels. Clearly, some of these will already be started so we
* won't actually be starting them all.
*/
/* Load current runlevel */
bootlevel = getenv("RC_BOOTLEVEL");
runlevel = rc_runlevel_get();
@@ -978,13 +972,8 @@ main(int argc, char **argv)
applet, RC_STOPPING, strerror(errno));
}
/* Create a list of all services which we could stop (assuming
* they won't be active in the new or current runlevel) including
* all those services which have been started, are inactive or
* are currently starting. Clearly, some of these will be listed
* in the new or current runlevel so we won't actually be stopping
* them all.
*/
/* Build a list of all services to stop and then work out the
* correct order for stopping them */
stop_services = rc_services_in_state(RC_SERVICE_STARTED);
tmplist = rc_services_in_state(RC_SERVICE_INACTIVE);
TAILQ_CONCAT(stop_services, tmplist, entries);
@@ -1007,11 +996,7 @@ main(int argc, char **argv)
stop_services = tmplist;
}
/* Create a list of all services which should be started for the new or
* current runlevel including those in boot, sysinit and hotplugged
* runlevels. Clearly, some of these will already be started so we
* won't actually be starting them all.
*/
/* Load our list of start services */
hotplugged_services = rc_services_in_state(RC_SERVICE_HOTPLUGGED);
start_services = rc_services_in_runlevel_stacked(newlevel ?
newlevel : runlevel);
@@ -1021,11 +1006,9 @@ main(int argc, char **argv)
tmplist = rc_services_in_runlevel(RC_LEVEL_SYSINIT);
TAILQ_CONCAT(start_services, tmplist, entries);
free(tmplist);
/* If we are NOT headed for the single-user runlevel... */
if (strcmp(newlevel ? newlevel : runlevel,
RC_LEVEL_SINGLE) != 0)
{
/* If we are NOT headed for the boot runlevel... */
if (strcmp(newlevel ? newlevel : runlevel,
bootlevel) != 0)
{
@@ -1046,7 +1029,7 @@ main(int argc, char **argv)
/* Now stop the services that shouldn't be running */
if (stop_services && !nostop)
do_stop_services(types_n, start_services, stop_services, deptree, newlevel, parallel, going_down);
do_stop_services(newlevel, parallel, going_down);
/* Wait for our services to finish */
wait_for_services();
@@ -1082,10 +1065,18 @@ main(int argc, char **argv)
TAILQ_FOREACH(service, hotplugged_services, entries)
rc_service_mark(service->value, RC_SERVICE_HOTPLUGGED);
/* Order the services to start */
if (start_services) {
rc_stringlist_sort(&start_services);
deporder = rc_deptree_depends(deptree, types_nua,
start_services, runlevel,
depoptions | RC_DEP_START);
rc_stringlist_free(start_services);
start_services = deporder;
}
#ifdef __linux__
/* If the "noinit" parameter was passed on the kernel command line then
* mark the specified services as started so they will not be started
* by us. */
/* mark any services skipped as started */
proc = p = rc_proc_getent("noinit");
if (proc) {
while ((token = strsep(&p, ",")))
@@ -1094,38 +1085,19 @@ main(int argc, char **argv)
}
#endif
/* If we have a list of services to start then... */
if (start_services) {
/* Get a list of the chained runlevels which compose the target runlevel */
RC_STRINGLIST *runlevel_chain = rc_runlevel_stacks(runlevel);
do_start_services(parallel);
/* FIXME: If we skip the boot runlevel and go straight
* to default from sysinit, we should now re-evaluate our
* start services + hotplugged services and call
* do_start_services a second time. */
/* Loop through them in reverse order. */
RC_STRING *rlevel;
TAILQ_FOREACH_REVERSE(rlevel, runlevel_chain, rc_stringlist, entries)
{
/* Get a list of all the services in that runlevel */
RC_STRINGLIST *run_services = rc_services_in_runlevel(rlevel->value);
/* Start those services. */
rc_stringlist_sort(&run_services);
deporder = rc_deptree_depends(deptree, types_nua, run_services, rlevel->value, depoptions | RC_DEP_START);
rc_stringlist_free(run_services);
run_services = deporder;
do_start_services(run_services, parallel);
/* Wait for our services to finish */
wait_for_services();
/* Free the list of services, we're done with it. */
rc_stringlist_free(run_services);
}
rc_stringlist_free(runlevel_chain);
/* Wait for our services to finish */
wait_for_services();
}
#ifdef __linux__
/* If the "noinit" parameter was passed on the kernel command line then
* mark the specified services as stopped so that our records reflect
* reality. */
/* mark any services skipped as stopped */
proc = p = rc_proc_getent("noinit");
if (proc) {
while ((token = strsep(&p, ",")))

View File

@@ -52,7 +52,7 @@
#include <time.h>
#include <unistd.h>
#ifdef __linux__
#if defined(__linux__) || defined(__GLIBC__)
# include <pty.h>
#elif defined(__NetBSD__) || defined(__OpenBSD__)
# include <util.h>

View File

@@ -307,7 +307,7 @@ parse_schedule(const char *string, int timeout)
}
static pid_t
get_pid(const char *pidfile)
get_pid(const char *pidfile, bool quiet)
{
FILE *fp;
pid_t pid;
@@ -334,7 +334,8 @@ get_pid(const char *pidfile)
/* return number of processed killed, -1 on error */
static int
do_stop(const char *exec, const char *const *argv,
pid_t pid, uid_t uid,int sig, bool test)
pid_t pid, uid_t uid,int sig,
bool quiet, bool verbose, bool test)
{
RC_PIDLIST *pids;
RC_PID *pi;
@@ -352,16 +353,20 @@ do_stop(const char *exec, const char *const *argv,
LIST_FOREACH_SAFE(pi, pids, entries, np) {
if (test) {
einfo("Would send signal %d to PID %d", sig, pi->pid);
if (!quiet)
einfo("Would send signal %d to PID %d", sig, pi->pid);
nkilled++;
} else {
ebeginv("Sending signal %d to PID %d", sig, pi->pid);
if (verbose)
ebegin("Sending signal %d to PID %d",
sig, pi->pid);
errno = 0;
killed = (kill(pi->pid, sig) == 0 ||
errno == ESRCH ? true : false);
eendv(killed ? 0 : 1,
"%s: failed to send signal %d to PID %d: %s",
applet, sig, pi->pid, strerror(errno));
if (verbose)
eend(killed ? 0 : 1,
"%s: failed to send signal %d to PID %d: %s",
applet, sig, pi->pid, strerror(errno));
if (!killed) {
nkilled = -1;
} else {
@@ -379,7 +384,7 @@ do_stop(const char *exec, const char *const *argv,
static int
run_stop_schedule(const char *exec, const char *const *argv,
const char *pidfile, uid_t uid,
bool test, bool progress)
bool quiet, bool verbose, bool test, bool progress)
{
SCHEDULEITEM *item = TAILQ_FIRST(&schedule);
int nkilled = 0;
@@ -391,15 +396,15 @@ run_stop_schedule(const char *exec, const char *const *argv,
const char *const *p;
bool progressed = false;
if (exec)
einfov("Will stop %s", exec);
if (pidfile)
einfov("Will stop PID in pidfile `%s'", pidfile);
if (uid)
einfov("Will stop processes owned by UID %d", uid);
if (argv && *argv) {
einfovn("Will stop processes of `");
if (rc_yesno(getenv("EINFO_VERBOSE"))) {
if (verbose) {
if (exec)
einfo ("Will stop %s", exec);
if (pidfile)
einfo("Will stop PID in pidfile `%s'", pidfile);
if (uid)
einfo("Will stop processes owned by UID %d", uid);
if (argv && *argv) {
einfon("Will stop processes of `");
for (p = argv; p && *p; p++) {
if (p != argv)
printf(" ");
@@ -410,7 +415,7 @@ run_stop_schedule(const char *exec, const char *const *argv,
}
if (pidfile) {
pid = get_pid(pidfile);
pid = get_pid(pidfile, false);
if (pid == -1)
return 0;
}
@@ -423,7 +428,8 @@ run_stop_schedule(const char *exec, const char *const *argv,
case SC_SIGNAL:
nrunning = 0;
nkilled = do_stop(exec, argv, pid, uid, item->value, test);
nkilled = do_stop(exec, argv, pid, uid, item->value,
quiet, verbose, test);
if (nkilled == 0) {
if (tkilled == 0) {
if (progressed)
@@ -452,7 +458,8 @@ run_stop_schedule(const char *exec, const char *const *argv,
nloops++)
{
if ((nrunning = do_stop(exec, argv,
pid, uid, 0, test)) == 0)
pid, uid, 0, true, false,
test)) == 0)
return 0;
@@ -669,6 +676,8 @@ start_stop_daemon(int argc, char **argv)
bool stop = false;
bool oknodo = false;
bool test = false;
bool quiet;
bool verbose = false;
char *exec = NULL;
char *startas = NULL;
char *name = NULL;
@@ -905,6 +914,8 @@ start_stop_daemon(int argc, char **argv)
endpwent();
argc -= optind;
argv += optind;
quiet = rc_yesno(getenv("EINFO_QUIET"));
verbose = rc_yesno(getenv("EINFO_VERBOSE"));
/* Allow start-stop-daemon --signal HUP --exec /usr/sbin/dnsmasq
* instead of forcing --stop --oknodo as well */
@@ -1048,7 +1059,7 @@ start_stop_daemon(int argc, char **argv)
else
parse_schedule(NULL, sig);
i = run_stop_schedule(exec, (const char *const *)margv,
pidfile, uid, test, progress);
pidfile, uid, quiet, verbose, test, progress);
if (i < 0)
/* We failed to stop something */
@@ -1070,16 +1081,16 @@ start_stop_daemon(int argc, char **argv)
}
if (pidfile)
pid = get_pid(pidfile);
pid = get_pid(pidfile, true);
else
pid = 0;
if (do_stop(exec, (const char * const *)margv, pid, uid,
0, test) > 0)
0, true, false, test) > 0)
eerrorx("%s: %s is already running", applet, exec);
if (test) {
if (rc_yesno(getenv("EINFO_QUIET")))
if (quiet)
exit (EXIT_SUCCESS);
einfon("Would start");
@@ -1103,8 +1114,10 @@ start_stop_daemon(int argc, char **argv)
exit(EXIT_SUCCESS);
}
ebeginv("Detaching to start `%s'", exec);
eindentv();
if (verbose) {
ebegin("Detaching to start `%s'", exec);
eindent();
}
/* Remove existing pidfile */
if (pidfile)
@@ -1272,9 +1285,9 @@ start_stop_daemon(int argc, char **argv)
}
/* We don't redirect stdin as some daemons may need it */
if (background || redirect_stdout || rc_yesno(getenv("EINFO_QUIET")))
if (background || quiet || redirect_stdout)
dup2(stdout_fd, STDOUT_FILENO);
if (background || redirect_stderr || rc_yesno(getenv("EINFO_QUIET")))
if (background || redirect_stderr)
dup2(stderr_fd, STDERR_FILENO);
for (i = getdtablesize() - 1; i >= 3; --i)
@@ -1305,10 +1318,9 @@ start_stop_daemon(int argc, char **argv)
return -1;
}
} while (!WIFEXITED(i) && !WIFSIGNALED(i));
if (!WIFEXITED(i) || WEXITSTATUS(i) != 0) {
eerror("%s: failed to start `%s'", applet, exec);
exit(EXIT_FAILURE);
}
if (!WIFEXITED(i) || WEXITSTATUS(i) != 0)
eerrorx("%s: failed to start `%s'", applet, exec);
pid = spid;
}
@@ -1342,7 +1354,7 @@ start_stop_daemon(int argc, char **argv)
alive = true;
} else {
if (pidfile) {
pid = get_pid(pidfile);
pid = get_pid(pidfile, false);
if (pid == -1) {
eerrorx("%s: did not "
"create a valid"
@@ -1352,7 +1364,7 @@ start_stop_daemon(int argc, char **argv)
} else
pid = 0;
if (do_stop(exec, (const char *const *)margv,
pid, uid, 0, test) > 0)
pid, uid, 0, true, false, test) > 0)
alive = true;
}