inetd: revert bogus fix for bug 1562; shrink inetd a bit

function                                             old     new   delta
dupconfig                                            159     146     -13
getconfigent                                        1123    1073     -50
This commit is contained in:
Denis Vlasenko 2007-11-12 21:21:35 +00:00
parent 059c91711f
commit 6df9e3c9a3

View File

@ -570,9 +570,8 @@ static void setup(servtab_t *sep)
static char *nextline(void) static char *nextline(void)
{ {
char *cp; char *cp;
FILE *fd = fconfig;
if (fgets(line, LINE_SIZE, fd) == NULL) if (fgets(line, LINE_SIZE, fconfig) == NULL)
return NULL; return NULL;
cp = strchr(line, '\n'); cp = strchr(line, '\n');
if (cp) if (cp)
@ -586,7 +585,7 @@ static char *skip(char **cpp) /* int report; */
char *start; char *start;
/* erp: */ /* erp: */
if (*cpp == NULL) { if (cp == NULL) {
/* if (report) */ /* if (report) */
/* bb_error_msg("syntax error in inetd config file"); */ /* bb_error_msg("syntax error in inetd config file"); */
return NULL; return NULL;
@ -596,9 +595,7 @@ static char *skip(char **cpp) /* int report; */
while (*cp == ' ' || *cp == '\t') while (*cp == ' ' || *cp == '\t')
cp++; cp++;
if (*cp == '\0') { if (*cp == '\0') {
int c; int c = getc(fconfig);
c = getc(fconfig);
ungetc(c, fconfig); ungetc(c, fconfig);
if (c == ' ' || c == '\t') { if (c == ' ' || c == '\t') {
cp = nextline(); cp = nextline();
@ -606,7 +603,6 @@ static char *skip(char **cpp) /* int report; */
goto again; goto again;
} }
*cpp = NULL; *cpp = NULL;
/* goto erp; */
return NULL; return NULL;
} }
start = cp; start = cp;
@ -614,8 +610,6 @@ static char *skip(char **cpp) /* int report; */
cp++; cp++;
if (*cp != '\0') if (*cp != '\0')
*cp++ = '\0'; *cp++ = '\0';
/* if ((*cpp = cp) == NULL) */
/* goto erp; */
*cpp = cp; *cpp = cp;
return start; return start;
@ -623,7 +617,7 @@ static char *skip(char **cpp) /* int report; */
static servtab_t *new_servtab(void) static servtab_t *new_servtab(void)
{ {
return xmalloc(sizeof(servtab_t)); return xzalloc(sizeof(servtab_t));
} }
static servtab_t *dupconfig(servtab_t *sep) static servtab_t *dupconfig(servtab_t *sep)
@ -632,7 +626,6 @@ static servtab_t *dupconfig(servtab_t *sep)
int argc; int argc;
newtab = new_servtab(); newtab = new_servtab();
memset(newtab, 0, sizeof(servtab_t));
newtab->se_service = xstrdup(sep->se_service); newtab->se_service = xstrdup(sep->se_service);
newtab->se_socktype = sep->se_socktype; newtab->se_socktype = sep->se_socktype;
newtab->se_family = sep->se_family; newtab->se_family = sep->se_family;
@ -668,17 +661,14 @@ static servtab_t *getconfigent(void)
sep = new_servtab(); sep = new_servtab();
/* memset(sep, 0, sizeof *sep); */
more: more:
/* freeconfig(sep); */ while ((cp = nextline()) && *cp == '#')
continue; /* skip comment lines */
while ((cp = nextline()) && *cp == '#') /* skip comment line */;
if (cp == NULL) { if (cp == NULL) {
/* free(sep); */ free(sep);
return NULL; return NULL;
} }
memset((char *) sep, 0, sizeof *sep);
arg = skip(&cp); arg = skip(&cp);
if (arg == NULL) { if (arg == NULL) {
/* A blank line. */ /* A blank line. */
@ -776,9 +766,7 @@ static servtab_t *getconfigent(void)
} else } else
sep->se_max = toomany; sep->se_max = toomany;
} }
sep->se_wait = strcmp(arg, "wait") == 0; sep->se_wait = (strcmp(arg, "wait") == 0);
/* if ((arg = skip(&cp, 1)) == NULL) */
/* goto more; */
sep->se_user = xxstrdup(skip(&cp)); sep->se_user = xxstrdup(skip(&cp));
arg = strchr(sep->se_user, '.'); arg = strchr(sep->se_user, '.');
if (arg == NULL) if (arg == NULL)
@ -788,10 +776,10 @@ static servtab_t *getconfigent(void)
sep->se_group = xstrdup(arg); sep->se_group = xstrdup(arg);
} }
arg = skip(&cp); sep->se_server = xxstrdup(skip(&cp));
sep->se_server = xxstrdup(arg);
if (strcmp(sep->se_server, "internal") == 0) {
#ifdef INETD_FEATURE_ENABLED #ifdef INETD_FEATURE_ENABLED
/* sep->se_bi = NULL; - done by new_servtab() */
if (strcmp(sep->se_server, "internal") == 0) {
const struct builtin *bi; const struct builtin *bi;
for (bi = builtins; bi->bi_service; bi++) for (bi = builtins; bi->bi_service; bi++)
@ -804,22 +792,14 @@ static servtab_t *getconfigent(void)
} }
sep->se_bi = bi; sep->se_bi = bi;
sep->se_wait = 0; /* = bi->bi_wait; - always 0 */ sep->se_wait = 0; /* = bi->bi_wait; - always 0 */
#else
bb_perror_msg("internal service %s unknown", sep->se_service);
goto more;
#endif
} }
#ifdef INETD_FEATURE_ENABLED
else
sep->se_bi = NULL;
#endif #endif
argc = 0; argc = 0;
for (; cp; arg = skip(&cp)) { while ((arg = skip(&cp)) != NULL && argc < MAXARGV) {
if (argc < MAXARGV)
sep->se_argv[argc++] = xxstrdup(arg); sep->se_argv[argc++] = xxstrdup(arg);
} }
while (argc <= MAXARGV) /* while (argc <= MAXARGV) */
sep->se_argv[argc++] = NULL; /* sep->se_argv[argc++] = NULL; - done by new_servtab() */
/* /*
* Now that we've processed the entire line, check if the hostname * Now that we've processed the entire line, check if the hostname