Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci-alpine-linux.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: ci_alpine_linux

on: [push, pull_request]
on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:

Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/ci-ubuntu.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: ci_ubuntu

on: [push, pull_request]
on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:

Expand Down
16 changes: 9 additions & 7 deletions sh/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ sh_config = [
]

scripts_config = [
'gendepends.sh.in',
'openrc-run.sh.in',
'openrc-user.sh.in',
'gendepends.sh.in',
's6-svscanboot.sh.in'
]

Expand All @@ -49,8 +49,12 @@ else
]
endif

install_data(sh,
install_dir : rc_shdir)
fs = import('fs')
script_deps = []
foreach file : sh
script_deps += fs.copyfile(file, install: true, install_dir: rc_shdir)
endforeach

foreach file : sh_config
configure_file(input : file,
output : '@BASENAME@',
Expand All @@ -60,10 +64,8 @@ endforeach

foreach file : scripts_config
configure_file(input : file,
output : '@BASENAME@',
configuration : sh_conf_data,
install_dir : rc_shdir,
install_mode : 'rwxr-xr-x')
output : '@BASENAME@', configuration : sh_conf_data,
install_dir : rc_shdir, install_mode : 'rwxr-xr-x')
endforeach

foreach file : scripts_config_os
Expand Down
30 changes: 11 additions & 19 deletions sh/openrc-run.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ apply_ulimits()
done
}

sourcex "@LIBEXECDIR@/sh/functions.sh"
sourcex "@LIBEXECDIR@/sh/rc-functions.sh"
sourcex "$RC_LIBEXECDIR/sh/functions.sh"
sourcex "$RC_LIBEXECDIR/sh/rc-functions.sh"
case $RC_SYS in
PREFIX|SYSTEMD-NSPAWN) ;;
*) yesno "$RC_USER_SERVICES" || sourcex -e "@LIBEXECDIR@/sh/rc-cgroup.sh";;
*) yesno "$RC_USER_SERVICES" || sourcex -e "$RC_LIBEXECDIR/sh/rc-cgroup.sh";;
esac

# Support LiveCD foo
Expand Down Expand Up @@ -259,10 +259,10 @@ done
unset _c _f _conf_d

# load service supervisor functions
sourcex "@LIBEXECDIR@/sh/runit.sh"
sourcex "@LIBEXECDIR@/sh/s6.sh"
sourcex "@LIBEXECDIR@/sh/start-stop-daemon.sh"
sourcex "@LIBEXECDIR@/sh/supervise-daemon.sh"
sourcex "$RC_LIBEXECDIR/sh/runit.sh"
sourcex "$RC_LIBEXECDIR/sh/s6.sh"
sourcex "$RC_LIBEXECDIR/sh/start-stop-daemon.sh"
sourcex "$RC_LIBEXECDIR/sh/supervise-daemon.sh"

# Load our script
sourcex "$RC_SERVICE"
Expand All @@ -280,19 +280,11 @@ status|describe) ;;
[ -n "${rc_ulimit:-$RC_ULIMIT}" ] && apply_ulimits ${rc_ulimit:-$RC_ULIMIT}

# Apply cgroups settings if defined
if [ "$(command -v cgroup_add_service)" = "cgroup_add_service" ]; then
if grep -qs /sys/fs/cgroup /proc/1/mountinfo
then
if [ -d /sys/fs/cgroup -a ! -w /sys/fs/cgroup ]; then
eerror "No permission to apply cgroup settings"
break
fi
fi
cgroup_add_service
if grep -qs /sys/fs/cgroup /proc/1/mountinfo && [ -d /sys/fs/cgroup ] && [ -w /sys/fs/cgroup ]; then
{ cgroup_add_service && cgroup_set_limits && cgroup2_set_limits; } 2>/dev/null
else
eerror "No permission to apply cgroup settings"
fi

[ "$(command -v cgroup_set_limits)" = "cgroup_set_limits" ] && cgroup_set_limits
[ "$(command -v cgroup2_set_limits)" = "cgroup2_set_limits" ] && cgroup2_set_limits
;;
esac

Expand Down
9 changes: 8 additions & 1 deletion src/librc/librc-depend.c
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,18 @@ rc_deptree_update(void)
size_t i, l;
bool retval = true;
const char *sys = rc_sys();
char *gendep;
int serrno;

/* Phase 1 - source all init scripts and print dependencies */
setup_environment();
if (!(fp = popen(GENDEP, "r")))
xasprintf(&gendep, "%s/gendepends.sh", rc_svcdir());
if (access(gendep, F_OK) == 0)
fp = popen(gendep, "r");
else
fp = popen(GENDEP, "r");

if (!fp)
return false;

config = rc_stringlist_new();
Expand Down
2 changes: 1 addition & 1 deletion src/openrc-run/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
executable('openrc-run', 'openrc-run.c',
openrc_run = executable('openrc-run', 'openrc-run.c',
dependencies: [rc, einfo, shared, audit_dep, dl_dep, pam_dep, pam_misc_dep, selinux_dep, util_dep, crypt_dep],
include_directories: incdir,
install: true,
Expand Down
2 changes: 1 addition & 1 deletion src/rc-service/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
executable('rc-service', 'rc-service.c',
rc_service = executable('rc-service', 'rc-service.c',
include_directories: incdir,
dependencies: [rc, einfo, shared],
install: true,
Expand Down
5 changes: 4 additions & 1 deletion src/shared/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ static const char *const env_allowlist[] = {
"EERROR_QUIET", "EINFO_QUIET",
"IN_BACKGROUND", "IN_DRYRUN", "IN_HOTPLUG",
"RC_DEBUG", "RC_NODEPS", "RC_USER_SERVICES",
"RC_SVCDIR", "RC_PATH", "RC_LIBEXECDIR",
"LANG", "LC_MESSAGES", "TERM",
"EINFO_COLOR", "EINFO_VERBOSE",
NULL
Expand Down Expand Up @@ -217,11 +218,13 @@ env_config(void)
free(cachedir);
}

e = getenv("RC_LIBEXECDIR");
setenv("RC_LIBEXECDIR", e ? e : RC_LIBEXECDIR, 1);

xasprintf(&tmpdir, "%s/tmp", svcdir);
e = rc_runlevel_get();

setenv("RC_VERSION", VERSION, 1);
setenv("RC_LIBEXECDIR", RC_LIBEXECDIR, 1);
setenv("RC_SVCDIR", svcdir, 1);
setenv("RC_TMPDIR", tmpdir, 1);
setenv("RC_BOOTLEVEL", RC_LEVEL_BOOT, 1);
Expand Down
12 changes: 7 additions & 5 deletions test/units/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
is_older_than = find_program('check-is-older-than.sh')
sh_yesno = find_program('check-sh-yesno.sh')

test('is_older_than', is_older_than, env : test_env)
test('sh_yesno', sh_yesno, env : test_env)
test('is_older_than', find_program('check-is-older-than.sh'), env: test_env)
test('sh_yesno', find_program('check-sh-yesno.sh'), env: test_env)
test('rc-service', find_program('rc-service.sh'),
env: [test_env, 'SUBDIR=' + meson.current_source_dir()],
workdir: meson.project_source_root(),
args: [ rc_service, openrc_run ],
depends: script_deps)
72 changes: 72 additions & 0 deletions test/units/rc-service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/sh

set -e

. "$SUBDIR/setup-root.sh"
rc_service=${1?}
openrc_run=${2?}
cp "$RC_LIBEXECDIR/sh/openrc-run.sh" "$root/run/openrc/openrc-run.sh"
cp "$RC_LIBEXECDIR/sh/gendepends.sh" "$root/run/openrc/gendepends.sh"
chmod +x "$root/run/openrc/openrc-run.sh"
chmod +x "$root/run/openrc/gendepends.sh"

rc_service() {
$rc_service "$@" 2>&1
}

in_state() {
state=${1?}
shift
for svc; do
test "$(readlink "$RC_SVCDIR/$state/$svc")" = "$root/etc/init.d/$svc"
done
}

mkservice() {
service="$root/etc/init.d/$1"
cat > "$service" <<-EOF
#!$SOURCE_ROOT/${openrc_run}
depend() {
${2-:;}
}
start() {
${3-sleep 0.1}
}
EOF
chmod +x "$service"
}

mkservice nya
mkservice foo "need nya"
mkservice mew "want foo"

addrunlevel() {
ln -s "$root/etc/init.d/${1?}" "$root/etc/runlevel/${2?}/$1"
}

rc_service nya start
in_state started nya

rc_service nya stop
( ! in_state started nya )

rc_service foo start
in_state started foo nya

rc_service foo stop
in_state started nya
( ! in_state started foo )

rc_service foo start
in_state started foo nya

rc_service nya stop
( ! in_state started foo nya )

rc_service mew start
in_state started foo nya mew

rc_service nya stop
rc_service mew stop

( ! in_state started foo nya mew )
77 changes: 77 additions & 0 deletions test/units/rc-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/sh

set -ex

. ${1?}
rc_update=${2?}

rc_update() {
"$rc_update" --root "$root" "$@" 2>&1
}

in_runlevel() {
test "$(readlink "$root/etc/runlevels/${1?}/${2?}")" = "$root/etc/init.d/$2"
}

stacked() {
test -d "$root/etc/runlevels/${1?}/${2?}"
}

# non-existent
( ! rc_update add nya )
( ! rc_update -s add nya )
( ! rc_update del nya )
( ! rc_update -s del nya )

cat > "$root/etc/init.d/nya" <<-EOF
#!/sbin/openrc-run
start() {
:;
}
EOF

# non-executable
( ! rc_update add nya )
( ! rc_update -s add nya )

chmod +x "$root/etc/init.d/nya"

# implicit runlevel
rc_update add nya
in_runlevel default nya

rc_update del nya
( ! in_runlevel default nya)
# not in the runlevel
( ! rc_update del nya )

# explicit runlevel
rc_update add nya default
in_runlevel default nya
# not in the specified runlevel
( ! rc_update del nya boop )

# stacking
rc_update -s add boop
stacked default boop

rc_update -s del boop
( ! stacked boop nya )

rc_update -s add boop default
stacked default boop

rc_update -s del boop
( ! stacked boop default )
( ! rc_update -s del boop )

# show
rc_update add nya
rc_update | grep -qE "^\s*nya"
rc_update show | grep -qE "^\s*nya"
rc_update show default | grep -qE "^\s*nya"
rc_update del nya
( ! rc_update show | grep -qE "^\s*nya" )
( ! rc_update show default | grep -qE "^\s*nya" )

exit 0
28 changes: 28 additions & 0 deletions test/units/setup-root.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
root=$(mktemp -d --tmpdir rc.XXXXXX)
#trap "rm -r $root" EXIT

sysdir="$root/etc"
export RC_LIBEXECDIR="$BUILD_ROOT"
export RC_PATH="$sysdir"
export RC_SVCDIR="$root/run/openrc"
mkdir -p "$RC_SVCDIR"
echo "default" > "$RC_SVCDIR/softlevel"

for dir in init.d conf.d runlevels; do
mkdir -p "$sysdir/$dir"
done
for dir in sysinit boot default boop shutdown; do
mkdir -p "$sysdir/runlevels/$dir"
done

for dir in daemons exclusive failed hotplugged inactive init.d \
options scheduled started starting stopping tmp wasinactive; do
mkdir -p "$root/run/openrc/$dir"
done

setup_path() {
local IFS=:
export PATH="$PATH:$*"
}

setup_path "$BUILD_ROOT"/src/*
Loading