aboutsummaryrefslogtreecommitdiff
path: root/src/user_init/user_init.c
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/user_init/user_init.c
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/user_init/user_init.c')
-rw-r--r--src/user_init/user_init.c23
1 files changed, 23 insertions, 0 deletions
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);
+}