diff options
author | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2024-07-18 17:29:21 +0200 |
---|---|---|
committer | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2024-07-20 03:15:17 +0200 |
commit | c3ccaeeddc4d92bfe34cedaa6b71cb6e830fe280 (patch) | |
tree | 926df7c4c604381f4d7b7b9ebccfa13bacefa3d7 /src/librc | |
parent | 18be0d77dc00d2e9faa7d8718e80a2f137ec0bf7 (diff) |
librc, openrc-pam: instantiate user.<username> service automatically
it's created in /run/openrc/dynamic and linked to the service in /etc at
login.
Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
Diffstat (limited to 'src/librc')
-rw-r--r-- | src/librc/librc-depend.c | 1 | ||||
-rw-r--r-- | src/librc/librc.c | 29 | ||||
-rw-r--r-- | src/librc/rc.h.in | 10 |
3 files changed, 40 insertions, 0 deletions
diff --git a/src/librc/librc-depend.c b/src/librc/librc-depend.c index a03e1a61..9f592cfe 100644 --- a/src/librc/librc-depend.c +++ b/src/librc/librc-depend.c @@ -700,6 +700,7 @@ static const char *const depdirs[] = "options", "exclusive", "scheduled", + "dynamic", "tmp", NULL }; diff --git a/src/librc/librc.c b/src/librc/librc.c index d218c8be..ee728b30 100644 --- a/src/librc/librc.c +++ b/src/librc/librc.c @@ -1317,6 +1317,35 @@ rc_service_delete(const char *runlevel, const char *service) return (r == 0); } +char * +rc_service_base(const char *service) +{ + char *dot = strchr(service, '.'); + if (!dot) + return NULL; + return xstrndup(service, dot - service); +} + +char * +rc_service_dylink(const char *service, const char *target) +{ + char *file = rc_service_resolve(service); + char *target_file = NULL; + if (!exists(file)) + goto out; + + xasprintf(&target_file, "%s/dynamic/%s", rc_service_dir(), target); + if (!exists(target_file) && symlink(file, target_file) == -1) { + free(target_file); + target_file = NULL; + goto out; + } + +out: + free(file); + return target_file; +} + RC_STRINGLIST * rc_services_scheduled_by(const char *service) { diff --git a/src/librc/rc.h.in b/src/librc/rc.h.in index 59fdfda3..794b4353 100644 --- a/src/librc/rc.h.in +++ b/src/librc/rc.h.in @@ -275,6 +275,16 @@ RC_STRINGLIST *rc_service_extra_commands(const char *); * @return pointer to full path of service */ char *rc_service_resolve(const char *); +/*! Gets the base service for a multiplexed service + * @param multiplexed service to check + * @return pointer to base service name or NULL if not multiplexed */ +char *rc_service_base(const char *); + +/*! Dynamically multiplexes a service into the runtime directory. + * @param service to link + * @param target service name */ +char *rc_service_dylink(const char *, const char *); + /*! Schedule a service to be started when another service starts * @param service that starts the scheduled service when started * @param service_to_start service that will be started */ |