inetd: fix bug 1562 "inetd does not set argv[0] properly" (fix by IlyaPanfilov)
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>
Tue, 30 Oct 2007 19:54:39 +0000 (19:54 +0000)
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>
Tue, 30 Oct 2007 19:54:39 +0000 (19:54 +0000)
inetd: code shrink while at it

function                                             old     new   delta
static.SOCK_xxx                                        -       6      +6
getconfigent                                        1222    1123     -99
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 6/-99)             Total: -93 bytes
   text    data     bss     dec     hex filename
 776099     974    9420  786493   c003d busybox_old
 776020     974    9420  786414   bffee busybox_unstripped

git-svn-id: svn://busybox.net/trunk/busybox@20333 69ca8d6d-28ef-0310-b511-8ec308f3f277

networking/inetd.c

index 8dca8fc..94d3df6 100644 (file)
@@ -708,18 +708,17 @@ static servtab_t *getconfigent(void)
        sep->se_service = xxstrdup(arg);
        arg = skip(&cp);
 
-       if (strcmp(arg, "stream") == 0)
-               sep->se_socktype = SOCK_STREAM;
-       else if (strcmp(arg, "dgram") == 0)
-               sep->se_socktype = SOCK_DGRAM;
-       else if (strcmp(arg, "rdm") == 0)
-               sep->se_socktype = SOCK_RDM;
-       else if (strcmp(arg, "seqpacket") == 0)
-               sep->se_socktype = SOCK_SEQPACKET;
-       else if (strcmp(arg, "raw") == 0)
-               sep->se_socktype = SOCK_RAW;
-       else
-               sep->se_socktype = -1;
+       {
+               static int8_t SOCK_xxx[] ALIGN1 = {
+                       -1,
+                       SOCK_STREAM, SOCK_DGRAM, SOCK_RDM,
+                       SOCK_SEQPACKET, SOCK_RAW
+               };
+               sep->se_socktype = SOCK_xxx[1 + index_in_strings(
+                       "stream""\0" "dgram""\0" "rdm""\0"
+                       "seqpacket""\0" "raw""\0"
+                       , arg)];
+       }
 
        sep->se_proto = xxstrdup(skip(&cp));
 
@@ -787,10 +786,9 @@ static servtab_t *getconfigent(void)
                *arg++ = '\0';
                sep->se_group = xstrdup(arg);
        }
-       /* if ((arg = skip(&cp, 1)) == NULL) */
-       /* goto more; */
 
-       sep->se_server = xxstrdup(skip(&cp));
+       arg = skip(&cp);
+       sep->se_server = xxstrdup(arg);
        if (strcmp(sep->se_server, "internal") == 0) {
 #ifdef INETD_FEATURE_ENABLED
                const struct builtin *bi;
@@ -815,7 +813,7 @@ static servtab_t *getconfigent(void)
                sep->se_bi = NULL;
 #endif
        argc = 0;
-       for (arg = skip(&cp); cp; arg = skip(&cp)) {
+       for (; cp; arg = skip(&cp)) {
                if (argc < MAXARGV)
                        sep->se_argv[argc++] = xxstrdup(arg);
        }