aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2024-07-12 00:51:12 +0200
committerAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2024-07-19 20:40:28 +0200
commitfd961d2ea0eea2cc60f4af1aca6b6e7711d43995 (patch)
treefc53ad7bf4d46a3b72e151b79e8433ff4d565514 /src
parentc34fcd63f05044f9034b26c52f19c91e04668da7 (diff)
openrc-user: init script for users
adds a new multiplexed script for starting user sessions. it also sets up XDG_RUNTIME_DIR. Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
Diffstat (limited to 'src')
-rw-r--r--src/meson.build1
-rw-r--r--src/user_init/meson.build5
-rw-r--r--src/user_init/user_init.c23
3 files changed, 29 insertions, 0 deletions
diff --git a/src/meson.build b/src/meson.build
index 76f6d8a1..cee6cb6c 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -34,3 +34,4 @@ subdir('start-stop-daemon')
subdir('supervise-daemon')
subdir('swclock')
subdir('value')
+subdir('user_init')
diff --git a/src/user_init/meson.build b/src/user_init/meson.build
new file mode 100644
index 00000000..838805fb
--- /dev/null
+++ b/src/user_init/meson.build
@@ -0,0 +1,5 @@
+executable('user_init', ['user_init.c'],
+ include_directories: [incdir, einfo_incdir, rc_incdir],
+ link_with: [libeinfo, librc],
+ install: true,
+ install_dir: rc_bindir)
diff --git a/src/user_init/user_init.c b/src/user_init/user_init.c
new file mode 100644
index 00000000..1f79ec90
--- /dev/null
+++ b/src/user_init/user_init.c
@@ -0,0 +1,23 @@
+#include <sys/types.h>
+#include <pwd.h>
+#include <grp.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "rc.h"
+
+#define USERINIT RC_LIBEXECDIR "/sh/user-init.sh"
+
+int main(int argc, char **argv) {
+ struct passwd *user;
+ if (argc < 3)
+ return 1;
+
+ user = getpwnam(argv[1]);
+ if (!user || initgroups(user->pw_name, user->pw_gid) == -1
+ || setgid(user->pw_gid) == -1
+ || setuid(user->pw_uid) == -1)
+ return 1;
+
+ execl(user->pw_shell, "-", "-c", USERINIT, argv[2], NULL);
+}