aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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);
+}