From 3ac1d11b59e992c101b48d886e02172b543917f0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 28 Dec 2025 15:57:18 +0000 Subject: [PATCH] Refactor init.c to use constants for user configuration Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com> --- src/init.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/init.c b/src/init.c index b979b45..fb957fb 100644 --- a/src/init.c +++ b/src/init.c @@ -12,6 +12,12 @@ #include #include +// Default user configuration +#define SPARK_UID 1000 +#define SPARK_GID 1000 +#define SPARK_HOME "/home/spark" +#define SPARK_USER "spark" + static void signal_handler(int sig) { if (sig == SIGCHLD) { // Reap zombie processes @@ -28,31 +34,31 @@ static void spawn_shell() { } if (pid == 0) { - // Child process - exec shell as spark user (uid 1000, gid 1000) + // Child process - exec shell as spark user // Set user and group IDs to spark user - if (setgid(1000) != 0) { + if (setgid(SPARK_GID) != 0) { perror("setgid failed"); exit(1); } - if (setuid(1000) != 0) { + if (setuid(SPARK_UID) != 0) { perror("setuid failed"); exit(1); } char *argv[] = {"/bin/sh", "-l", NULL}; char *envp[] = { - "HOME=/home/spark", + "HOME=" SPARK_HOME, "PATH=/bin:/sbin:/usr/bin:/usr/sbin", "TERM=linux", "PS1=SparkOS$ ", - "USER=spark", - "LOGNAME=spark", + "USER=" SPARK_USER, + "LOGNAME=" SPARK_USER, NULL }; // Change to home directory - if (chdir("/home/spark") != 0) { + if (chdir(SPARK_HOME) != 0) { perror("chdir failed"); }