]> pd.if.org Git - startuptools/commitdiff
startup program improvements
authorNathan Wagner <nw@hydaspes.if.org>
Thu, 3 Jul 2014 20:12:28 +0000 (15:12 -0500)
committerNathan Wagner <nw@hydaspes.if.org>
Thu, 3 Jul 2014 20:12:28 +0000 (15:12 -0500)
Makefile
chids.c
exec.c

index acf459c2b079c06364735dbce67e3984d88ab25e..664dc271149bfb1efeefcf2bffe799189953875d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -8,6 +8,9 @@ all:    $(PRG)
 clean:
        rm -f *.o $(PRG)
 
+daemon.o: daemon.c exec.c
+chids.o: chids.c exec.c
+
 install: install-scripts
 
 install-scripts:
diff --git a/chids.c b/chids.c
index 61e72262f2c5aac56013c6abf43fa098beb98f31..fbe742f97fd0eab638ee3e219dcfa5987a5333a7 100644 (file)
--- a/chids.c
+++ b/chids.c
@@ -1,5 +1,5 @@
 /*
- * daemonize and exec
+ * set id
  */
 
 #include <stdlib.h>
@@ -8,16 +8,21 @@
 #include <pwd.h>
 
 #include "exec.c"
+#include "die.c"
 
 int main(int ac, char *av[]) {
        struct passwd *pw;
 
        pw = getpwnam(av[1]);
        if (!pw) {
+               errordie("getpwnam");
                exit(EXIT_FAILURE);
        }
        
-       seteuid(pw->pw_uid);
+       if (seteuid(pw->pw_uid) == -1) {
+               errordie("seteuid");
+               exit(EXIT_FAILURE);
+       };
 
        do_exec(2, ac, av);
 
diff --git a/exec.c b/exec.c
index b8378cec0430ecf36cfa394f010a2609195a0410..bd07905b57dfad9eea220d09565a4ed0fcde053f 100644 (file)
--- a/exec.c
+++ b/exec.c
 static void do_exec(int skip, int ac, char *av[]) {
        int i;
 
+       if (skip >= ac) {
+               fprintf(stderr, "nothing to exec\n");
+               exit(EXIT_FAILURE);
+       }
+
        for (i=0;i<ac-skip;i++) {
                av[i] = av[i+skip];
        }