Missing dependency spotted by Robert P Day.
[oweals/busybox.git] / networking / fakeidentd.c
index 560f6bab0120b3420affd48702045cd76bc39c82..5442c22c28a8b118ede378f3eeb6681b3354b958 100644 (file)
 #define MAXIDLETIME 45
 
 static const char ident_substr[] = " : USERID : UNIX : ";
-static const int ident_substr_len = sizeof(ident_substr) - 1;
+enum { ident_substr_len = sizeof(ident_substr) - 1 };
 #define PIDFILE "/var/run/identd.pid"
 
 /*
- * We have to track the 'first connection socket' so that we 
+ * We have to track the 'first connection socket' so that we
  * don't go around closing file descriptors for non-clients.
  *
  * descriptor setup normally
@@ -74,14 +74,14 @@ static const int ident_substr_len = sizeof(ident_substr) - 1;
  * FD of the connection is always the index of the connection structure
  * in `conns' array + FCS
  */
-struct {
+static struct {
        char buf[20];
        int len;
        time_t lasttime;
 } conns[MAXCONNS];
 
 /* When using global variables, bind those at least to a structure. */
-struct {
+static struct {
        const char *identuser;
        fd_set readfds;
        int conncnt;
@@ -136,24 +136,15 @@ static void inetbind(void)
        movefd(s, 0);
 }
 
-static void delpidfile(void)
+static void handlexitsigs(int signum)
 {
-       /*
-        * Usually nobody has no write/delete access to directory /var/run/
-        * therefore if file cannot be deleted, it is truncated
-        */
        if (unlink(PIDFILE) < 0)
                close(open(PIDFILE, O_WRONLY|O_CREAT|O_TRUNC, 0644));
-}
-
-static void handlexitsigs(int signum)
-{
-       delpidfile();
        exit(0);
 }
 
 /* May succeed. If not, won't care. */
-static void writepid(uid_t nobody, uid_t nogrp)
+static inline void writepid(uid_t nobody, uid_t nogrp)
 {
        char buf[24];
        int fd = open(PIDFILE, O_WRONLY|O_CREAT|O_TRUNC, 0664);
@@ -193,9 +184,7 @@ static int godaemon(void)
                close(0);
                inetbind();
                if (setgid(nogrp))   bb_error_msg_and_die("Could not setgid()");
-               if (setegid(nogrp))  bb_error_msg_and_die("Could not setegid()");
                if (setuid(nobody))  bb_error_msg_and_die("Could not setuid()");
-               if (seteuid(nobody)) bb_error_msg_and_die("Could not seteuid()");
                close(1);
                close(2);
 
@@ -266,23 +255,13 @@ static int checkInput(char *buf, int len, int l)
 
 int fakeidentd_main(int argc, char **argv)
 {
-       int flag;
-
        memset(conns, 0, sizeof(conns));
        memset(&G, 0, sizeof(G));
        FD_ZERO(&G.readfds);
        FD_SET(0, &G.readfds);
 
        /* handle -b <ip> parameter */
-       while ((flag = getopt(argc, argv, "b:")) != EOF) {
-               switch (flag) {
-               case 'b':
-                       bind_ip_address = optarg;
-                       break;
-               default:
-                       bb_show_usage();
-               }
-       }
+       bb_getopt_ulflags(argc, argv, "b:", &bind_ip_address);
        /* handle optional REPLY STRING */
        if (optind < argc)
                G.identuser = argv[optind];
@@ -293,6 +272,7 @@ int fakeidentd_main(int argc, char **argv)
        if (godaemon() == 0)
                return 0;
 
+       /* main loop where we process all events and never exit */
        while (1) {
        fd_set rfds = G.readfds;
        struct timeval tv = { 15, 0 };