From 2b885a4564e939888b39f050a058645eb131d140 Mon Sep 17 00:00:00 2001 From: Yiyang Wu Date: Sun, 7 Jan 2024 12:19:22 +0800 Subject: [PATCH] rc.h.in: drop PREFIX macro, and add gentooprefix argument This will place the RC_SVCDIR to ${gentooprefix}/run/openrc. In Gentoo Prefix, user may not have root permission to use /run/openrc, and can only access directories inside ${gentooprefix} RC_PREFIX is now always set to ${gentooprefix} Signed-off-by: Yiyang Wu --- man/openrc-run.8 | 3 +++ meson.build | 1 + meson_options.txt | 2 ++ src/librc/librc.c | 4 ---- src/librc/meson.build | 1 + src/librc/rc.h.in | 8 +++----- src/shared/misc.c | 2 ++ 7 files changed, 12 insertions(+), 9 deletions(-) diff --git a/man/openrc-run.8 b/man/openrc-run.8 index 6b6dc787a..01da633df 100644 --- a/man/openrc-run.8 +++ b/man/openrc-run.8 @@ -563,6 +563,9 @@ Default runlevel chosen. Default is default. .It Va RC_SYS A special variable to describe the system more. Possible values are OPENVZ, XENU, XEN0, UML and VSERVER. +.It Va RC_PREFIX +In a Gentoo Prefix installation, this variable contains the prefix +offset. Otherwise it is an empty string. .It Va RC_UNAME The result of `uname -s`. .It Va RC_CMD diff --git a/meson.build b/meson.build index 9005b1870..b65960a97 100644 --- a/meson.build +++ b/meson.build @@ -6,6 +6,7 @@ project('OpenRC', 'c', 'c_std=c99', 'prefix=/usr', 'sbindir=/sbin', + 'gentooprefix=', 'warning_level=3', ], meson_version : '>=0.62.0' diff --git a/meson_options.txt b/meson_options.txt index 30a7dcfdb..eca424a27 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -18,6 +18,8 @@ option('pkg_prefix', type : 'string', description : 'default location where packages are installed') option('pkgconfig', type : 'boolean', description : 'build PKGConfig files') +option('gentooprefix', type : 'string', + description : 'the Gentoo prefix') option('selinux', type : 'feature', value : 'auto', description : 'enable SELinux support') option('shell', type : 'string', value : '/bin/sh', diff --git a/src/librc/librc.c b/src/librc/librc.c index 41752bfcb..540988e3d 100644 --- a/src/librc/librc.c +++ b/src/librc/librc.c @@ -235,9 +235,6 @@ get_systype(void) static const char * detect_prefix(const char *systype) { -#ifdef PREFIX - return RC_SYS_PREFIX; -#else if (systype) { if (strcmp(systype, RC_SYS_NONE) == 0) return NULL; @@ -246,7 +243,6 @@ detect_prefix(const char *systype) } return NULL; -#endif } static const char * diff --git a/src/librc/meson.build b/src/librc/meson.build index 806b5ae45..a5bf01dcf 100644 --- a/src/librc/meson.build +++ b/src/librc/meson.build @@ -4,6 +4,7 @@ rc_h_conf_data.set('RC_PLUGINDIR', pluginsdir) rc_h_conf_data.set('LOCAL_PREFIX', local_prefix) rc_h_conf_data.set('PKG_PREFIX', pkg_prefix) rc_h_conf_data.set('SYSCONFDIR', get_option('sysconfdir')) +rc_h_conf_data.set('GENTOOPREFIX', get_option('gentooprefix')) librc_version = '1' diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in index 5cc9dc213..b2e7daf6e 100644 --- a/src/librc/rc.h.in +++ b/src/librc/rc.h.in @@ -22,14 +22,12 @@ extern "C" { #endif -#define RC_PREFIX "@PREFIX@" +#define RC_PREFIX "@GENTOOPREFIX@" #define RC_SYSCONFDIR "@SYSCONFDIR@" #define RC_LIBEXECDIR "@RC_LIBEXECDIR@" -#if defined(PREFIX) -#define RC_SVCDIR RC_LIBEXECDIR "/init.d" -#elif defined(__linux__) || (defined(__FreeBSD_kernel__) && \ +#if defined(__linux__) || (defined(__FreeBSD_kernel__) && \ defined(__GLIBC__)) || defined(__GNU__) -#define RC_SVCDIR "/run/openrc" +#define RC_SVCDIR RC_PREFIX "/run/openrc" #else #define RC_SVCDIR RC_LIBEXECDIR "/init.d" #endif diff --git a/src/shared/misc.c b/src/shared/misc.c index 0e7f4e3bf..36d66caa5 100644 --- a/src/shared/misc.c +++ b/src/shared/misc.c @@ -215,6 +215,8 @@ env_config(void) if (sys) setenv("RC_SYS", sys, 1); + setenv("RC_PREFIX", RC_PREFIX, 1); + /* Some scripts may need to take a different code path if Linux/FreeBSD, etc To save on calling uname, we store it in an environment variable */