Changeset View
Changeset View
Standalone View
Standalone View
head/libexec/getty/subr.c
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | |||||
gettable(const char *name, char *buf) | gettable(const char *name, char *buf) | ||||
{ | { | ||||
struct gettystrs *sp; | struct gettystrs *sp; | ||||
struct gettynums *np; | struct gettynums *np; | ||||
struct gettyflags *fp; | struct gettyflags *fp; | ||||
long n; | long n; | ||||
int l; | int l; | ||||
char *p; | char *p; | ||||
char *msg = NULL; | static char path_gettytab[PATH_MAX]; | ||||
const char *dba[2]; | char *dba[2]; | ||||
static int firsttime = 1; | static int firsttime = 1; | ||||
dba[0] = _PATH_GETTYTAB; | strlcpy(path_gettytab, _PATH_GETTYTAB, sizeof(path_gettytab)); | ||||
dba[0] = path_gettytab; | |||||
dba[1] = NULL; | dba[1] = NULL; | ||||
if (firsttime) { | if (firsttime) { | ||||
/* | /* | ||||
* we need to strdup() anything in the strings array | * we need to strdup() anything in the strings array | ||||
* initially in order to simplify things later | * initially in order to simplify things later | ||||
*/ | */ | ||||
for (sp = gettystrs; sp->field; sp++) | for (sp = gettystrs; sp->field; sp++) | ||||
Show All 11 Lines | for (sp = gettystrs; sp->field; sp++) | ||||
* replace, even if NULL, else we'll | * replace, even if NULL, else we'll | ||||
* have problems with free()ing static mem | * have problems with free()ing static mem | ||||
*/ | */ | ||||
sp->value = p; | sp->value = p; | ||||
} | } | ||||
firsttime = 0; | firsttime = 0; | ||||
} | } | ||||
switch (cgetent(&buf, (char **)dba, name)) { | switch (cgetent(&buf, dba, name)) { | ||||
case 1: | case 1: | ||||
msg = "%s: couldn't resolve 'tc=' in gettytab '%s'"; | syslog(LOG_ERR, "getty: couldn't resolve 'tc=' in gettytab '%s'", name); | ||||
return; | |||||
case 0: | case 0: | ||||
break; | break; | ||||
case -1: | case -1: | ||||
msg = "%s: unknown gettytab entry '%s'"; | syslog(LOG_ERR, "getty: unknown gettytab entry '%s'", name); | ||||
break; | return; | ||||
case -2: | case -2: | ||||
msg = "%s: retrieving gettytab entry '%s': %m"; | syslog(LOG_ERR, "getty: retrieving gettytab entry '%s': %m", name); | ||||
break; | return; | ||||
case -3: | case -3: | ||||
msg = "%s: recursive 'tc=' reference gettytab entry '%s'"; | syslog(LOG_ERR, "getty: recursive 'tc=' reference gettytab entry '%s'", name); | ||||
break; | return; | ||||
default: | default: | ||||
msg = "%s: unexpected cgetent() error for entry '%s'"; | syslog(LOG_ERR, "getty: unexpected cgetent() error for entry '%s'", name); | ||||
break; | |||||
} | |||||
if (msg != NULL) { | |||||
syslog(LOG_ERR, msg, "getty", name); | |||||
return; | return; | ||||
} | } | ||||
for (sp = gettystrs; sp->field; sp++) { | for (sp = gettystrs; sp->field; sp++) { | ||||
if ((l = cgetstr(buf, sp->field, &p)) >= 0) { | if ((l = cgetstr(buf, sp->field, &p)) >= 0) { | ||||
if (sp->value) { | if (sp->value) { | ||||
/* prefer existing value */ | /* prefer existing value */ | ||||
if (strcmp(p, sp->value) != 0) | if (strcmp(p, sp->value) != 0) | ||||
▲ Show 20 Lines • Show All 553 Lines • Show Last 20 Lines |