Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Services #573

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c34fcd6
openrc: dynamic paths for user services
navi-desu Mar 20, 2024
fd961d2
openrc-user: init script for users
navi-desu Jul 11, 2024
ad169aa
openrc-pam: auto-launch user services via pam
navi-desu Jul 12, 2024
f03a640
openrc-run: allow multiplexed symlinks to live outside init.d
navi-desu Jul 14, 2024
18be0d7
librc/librc-depend.c: small refactor
navi-desu Jul 18, 2024
c3ccaee
librc, openrc-pam: instantiate user.<username> service automatically
navi-desu Jul 18, 2024
f4d7946
librc-misc.c, rc.c, rc-status.c: fix memory leaks
navi-desu Jul 19, 2024
a8dd10c
libeinfo.c: add foot
navi-desu Jul 14, 2024
5caae0d
openrc/rc-logger.c: set log path for user dynamically
navi-desu Jul 19, 2024
a9a26fe
openrc-pam: use 'shared_module' for pam_openrc
navi-desu Jul 20, 2024
3586a89
openrc-shutdown: simplify broadcast function
floppym May 23, 2024
1485cfb
Generate pkg-config files directly
Kangie Jul 16, 2024
15de84d
shared/plugin.c: fix incompatible function warning.
navi-desu Jul 20, 2024
e46a163
start-stop-daemon: open syslog
dwfreed Jun 25, 2024
26314e9
openrc-run.c: allow --user on shebangs
navi-desu Jul 20, 2024
9432319
support: add user.d examples
navi-desu Jul 20, 2024
df50d89
user-guide.md add user-services documentation
navi-desu Jul 20, 2024
e849ef3
librc.c: use rc_runlevel_dir for rc_service_add
navi-desu Jul 20, 2024
9cde77f
openrc-pam: fix session count logic
navi-desu Jul 20, 2024
d5ebe7c
openrc-pam: do not start a login shell
navi-desu Jul 20, 2024
e29e284
openrc-pam: add logging
navi-desu Jul 20, 2024
0fb6b73
openrc-pam: use full path to mark the service
navi-desu Jul 20, 2024
6b0d03e
librc.c: return "none" from rc_runlevel_get when in user mode.
navi-desu Jul 20, 2024
7de84f2
version 0.60-beta
navi-desu Jul 20, 2024
99a5507
meson.build: restore pkg-config filename to openrc.pc
navi-desu Jul 21, 2024
980bfe6
openrc-run: fix check for argument count
navi-desu Jul 21, 2024
255138d
version 0.60-beta2
navi-desu Jul 21, 2024
0dcc569
user_init.c: use a single argument for -c
navi-desu Jul 21, 2024
12b194b
user_init.c: set HOME
navi-desu Jul 21, 2024
8e25129
user_init.c: set SHELL
navi-desu Jul 21, 2024
dce704d
user-init.sh: print message on error
navi-desu Jul 21, 2024
232c398
rc.c: remove superuser error message
navi-desu Jul 21, 2024
fdb1d0d
version 0.60-beta3
navi-desu Jul 21, 2024
53de57e
openrc-run: chdir into HOME for user services.
navi-desu Jul 21, 2024
6221248
rc-logger.c: fix log path for user-mode
navi-desu Jul 21, 2024
056f6df
update readme
navi-desu Jul 21, 2024
114bf66
user-init.c: redirect stdin to /dev/null and start a login shell
navi-desu Jul 22, 2024
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
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
OpenRC README
openrc-navi
=============

OpenRC is a dependency-based init system that works with the
system-provided init program, normally `/sbin/init`.

This fork provides extra functionality like user services.

## building and installing

OpenRC uses the [meson](http://mesonbuild.com) build system, so use the
Expand Down Expand Up @@ -34,19 +36,18 @@ remove them and then install so that the OS hooks into OpenRC.

## Discussions

We are testing [discussions](https://github.com/OpenRC/openrc/discussions), so
We are testing [discussions](https://github.com/navi-desu/openrc/discussions), so
feel free to open topics there.

## Reporting Bugs

Please report bugs on our [bug tracker](http://github.com/OpenRC/openrc/issues).
Please report bugs on our [bug tracker](http://github.com/navi-desu/openrc/issues).

If you can contribute code , please feel free to do so by opening
[pull requests](https://github.com/OpenRC/openrc/pulls).

## IRC Channel

We have an official irc channel, #openrc on the libera network.
Please connect your irc client to irc.libera.chat and join #openrc on
We have an official irc channel, #navi on the libera network.
Please connect your irc client to irc.libera.chat and join #navi on
that network.

6 changes: 4 additions & 2 deletions init.d/bootmisc.in
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ start()
# Satisfy Linux FHS
extra=/var/lib/misc
if [ ! -d /run ]; then
extra="/var/run $extra"
extra="/var/run /var/run/user $extra"
elif [ ! -d /run/user ]; then
extra="/run/user $extra"
fi
else
extra=/var/run
extra="/var/run /var/run/user"
fi
for x in /var/log /tmp $extra; do
if ! [ -d $x ]; then
Expand Down
5 changes: 3 additions & 2 deletions init.d/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ init_common = [
'netmount.in',
'osclock.in',
'root.in',
'runsvdir.in',
's6-svscan.in',
'savecache.in',
'swap.in',
'swclock.in',
'sysctl.in',
'runsvdir.in',
's6-svscan.in',
'user.in',
]

if get_option('newnet')
Expand Down
48 changes: 48 additions & 0 deletions init.d/user.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!@SBINDIR@/openrc-run
# Copyright (c) 2017 The OpenRC Authors.
# See the Authors file at the top-level directory of this distribution and
# https://github.com/OpenRC/openrc/blob/HEAD/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/HEAD/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.

description="starts an openrc session for an user"
user="${RC_SVCNAME#*.}"

extra_started_commands="runtime_directory"

runtime_directory() {
service_get_value xdg_runtime_dir
}

start_pre() {
if [ "$user" = "$RC_SVCNAME" ]; then
eerror "${RC_SVCNAME} cannot be started directly. You must create"
eerror "symbolic links to it for the users you want to start"
return 1
fi

if [ -z "$XDG_RUNTIME_DIR" ]; then
export XDG_RUNTIME_DIR="/run/user/$(id -u $user)"
checkpath -d -o "$user:$user" "$XDG_RUNTIME_DIR" || return 1
fi

service_set_value xdg_runtime_dir "$XDG_RUNTIME_DIR"
}

start() {
ebegin "Starting user session for $user"
user_init $user start
eend $?
return 0
}

stop() {
ebegin "Stopping user session for $user"
user_init $user stop
eend $?
return 0
}
30 changes: 27 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
project('OpenRC', 'c',
version : '0.54',
version : '0.60-beta3',
license: 'BSD-2',
default_options : [
'c_std=c99',
'prefix=/usr',
'warning_level=3',
],
meson_version : '>=0.53.2')
meson_version : '>=0.56.0' # pkgconfig dict support
)

cc = meson.get_compiler('c')
fs = import('fs')
Expand Down Expand Up @@ -207,14 +208,37 @@ subdir('etc')
subdir('init.d')
subdir('local.d')
subdir('man')
subdir('pkgconfig')
subdir('sh')
subdir('src')
subdir('support')
subdir('sysctl.d')
subdir('test')
subdir('zsh-completion')

if get_option('pkgconfig')
pkg = import('pkgconfig')

einfo_pkgconf = pkg.generate(
name : 'einfo',
description : 'Pretty console informational display',
version : meson.project_version(),
libraries : libeinfo,
subdirs : ['einfo'],
)

openrc_pkgconf = pkg.generate(
name : 'OpenRC',
filebase : 'openrc',
description : 'Universal init system',
version : meson.project_version(),
libraries : librc,
subdirs : ['openrc'],
variables: {
'rc_path': rc_libexecdir,
}
)
endif

meson.add_install_script('tools/meson_runlevels.sh',
os,
get_option('newnet') ? 'yes' : 'no',
Expand Down
9 changes: 0 additions & 9 deletions pkgconfig/einfo.pc.in

This file was deleted.

24 changes: 0 additions & 24 deletions pkgconfig/meson.build

This file was deleted.

10 changes: 0 additions & 10 deletions pkgconfig/openrc.pc.in

This file was deleted.

19 changes: 15 additions & 4 deletions sh/gendepends.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,21 @@ depend() {
:
}

_dirs="
@SYSCONFDIR@/init.d
@PKG_PREFIX@/etc/init.d
@LOCAL_PREFIX@/etc/init.d
"

if yesno "$RC_USER_SERVICES"; then
_dirs="
@SYSCONFDIR@/user.d/init.d
${XDG_CONFIG_HOME:-${HOME}/.config}/openrc/init.d
"
fi

_done_dirs=
for _dir in \
@SYSCONFDIR@/init.d \
@PKG_PREFIX@/etc/init.d \
@LOCAL_PREFIX@/etc/init.d
for _dir in ${_dirs}
do
[ -d "$_dir" ] || continue

Expand Down Expand Up @@ -127,3 +137,4 @@ do
)
done
done
unset _dirs
1 change: 1 addition & 0 deletions sh/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ sh_config = [
scripts_config = [
'gendepends.sh.in',
'openrc-run.sh.in',
'user-init.sh.in',
]

if os == 'Linux'
Expand Down
4 changes: 2 additions & 2 deletions sh/openrc-run.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sourcex "@LIBEXECDIR@/sh/functions.sh"
sourcex "@LIBEXECDIR@/sh/rc-functions.sh"
case $RC_SYS in
PREFIX|SYSTEMD-NSPAWN) ;;
*) sourcex -e "@LIBEXECDIR@/sh/rc-cgroup.sh";;
*) yesno "$RC_USER_SERVICES" || sourcex -e "@LIBEXECDIR@/sh/rc-cgroup.sh";;
esac

# Support LiveCD foo
Expand Down Expand Up @@ -220,7 +220,7 @@ if [ -d "@SYSCONFDIR@/rc.conf.d" ]; then
done
fi

_conf_d=${RC_SERVICE%/*}/../conf.d
_conf_d="${RC_SYSCONF_DIR}/conf.d"
# If we're net.eth0 or openvpn.work then load net or openvpn config
_c=${RC_SVCNAME%%.*}
if [ -n "$_c" -a "$_c" != "$RC_SVCNAME" ]; then
Expand Down
30 changes: 30 additions & 0 deletions sh/user-init.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!@SHELL@

. @LIBEXECDIR@/sh/functions.sh

sourcex()
{
if [ "$1" = "-e" ]; then
shift
[ -e "$1" ] || return 1
fi
if ! . "$1"; then
eerror "$RC_SVCNAME: error loading $1"
exit 1
fi
}

_sysconf="${XDG_CONFIG_HOME:-${HOME}/.config}/openrc"

sourcex -e "@SYSCONFDIR@/rc.conf"
sourcex -e "$_sysconf/rc.conf"

case $1 in
start) _runlevel="${rc_user_runlevel:-default}";;
stop) _runlevel="${rc_user_shutdown_runlevel:-none}";;
*) eerror "no argument given to $0"r exit 1
esac

mkdir -p "$_sysconf/runlevels/$_runlevel"

openrc --user "$_runlevel"
1 change: 1 addition & 0 deletions src/libeinfo/libeinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ static const char *const color_terms[] = {
"xterm",
"xterm-debian",
"xterm-kitty",
"foot",
NULL
};

Expand Down
10 changes: 4 additions & 6 deletions src/librc/librc-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,8 @@ rc_service_daemon_set(const char *service, const char *exec,
return false;
}

xasprintf(&dirpath, RC_SVCDIR "/daemons/%s", basename_c(service));

/* Regardless, erase any existing daemon info */
xasprintf(&dirpath, "%s/daemons/%s", rc_service_dir(), basename_c(service));
if ((dp = opendir(dirpath))) {
match = _match_list(exec, argv, pidfile);
renamelist = rc_stringlist_new();
Expand Down Expand Up @@ -491,7 +490,7 @@ rc_service_started_daemon(const char *service,
if (!service || !exec)
return false;

xasprintf(&dirpath, RC_SVCDIR "/daemons/%s", basename_c(service));
xasprintf(&dirpath, "%s/daemons/%s", rc_service_dir(), basename_c(service));
match = _match_list(exec, argv, NULL);

if (indx > 0) {
Expand Down Expand Up @@ -543,9 +542,8 @@ rc_service_daemons_crashed(const char *service)
char *ch_root;
char *spidfile;

path += snprintf(dirpath, sizeof(dirpath), RC_SVCDIR "/daemons/%s",
basename_c(service));

path += snprintf(dirpath, sizeof(dirpath),
"%s/daemons/%s", rc_service_dir(), basename_c(service));
if (!(dp = opendir(dirpath)))
return false;

Expand Down
Loading