devfsd: fix formatting (Tito <farmatito@tiscali.it>)

ash: fix SEGV if type has zero parameters
This commit is contained in:
Denis Vlasenko
2007-06-25 22:55:34 +00:00
parent 80b8b39899
commit 1fc6238ffa
2 changed files with 447 additions and 510 deletions

View File

@@ -344,8 +344,7 @@ static void do_ioctl_and_die(int fd, int request, unsigned long event_mask_flag)
static void fork_and_execute(int die, char *arg0, char **arg) static void fork_and_execute(int die, char *arg0, char **arg)
{ {
switch ( fork () ) switch (fork()) {
{
case 0: case 0:
/* Child */ /* Child */
break; break;
@@ -357,16 +356,14 @@ static void fork_and_execute(int die, char *arg0, char **arg )
return; return;
default: default:
/* Parent : ok : return or exit */ /* Parent : ok : return or exit */
if(arg0 != NULL) if (arg0 != NULL) {
{
wait(NULL); wait(NULL);
return; return;
} }
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
/* Child : if arg0 != NULL do execvp */ /* Child : if arg0 != NULL do execvp */
if(arg0 != NULL ) if (arg0 != NULL) {
{
BB_EXECVP(arg0, arg); BB_EXECVP(arg0, arg);
msg_logger_and_die(LOG_ERR, "execvp"); msg_logger_and_die(LOG_ERR, "execvp");
} }
@@ -394,14 +391,15 @@ static unsigned int scan_dev_name_common(const char *d, unsigned int n, int adde
static unsigned int scan_dev_name(const char *d, unsigned int n, char *ptr) static unsigned int scan_dev_name(const char *d, unsigned int n, char *ptr)
{ {
if (d[0] == 's' && d[1] == 'c' && d[2] == 's' && d[3] == 'i' && d[4] == '/') { if (d[0] == 's' && d[1] == 'c' && d[2] == 's' && d[3] == 'i' && d[4] == '/') {
if( d[n - 7]=='g' && d[n - 6]=='e' && d[n - 5]=='n' && if (d[n - 7] == 'g' && d[n - 6] == 'e' && d[n - 5] == 'n'
d[n - 4]=='e' && d[n - 3]=='r' && d[n - 2]=='i' && && d[n - 4] == 'e' && d[n - 3] == 'r' && d[n - 2] == 'i' && d[n - 1] == 'c'
d[n - 1]=='c' ) )
return 1; return 1;
return scan_dev_name_common(d, n, 0, ptr); return scan_dev_name_common(d, n, 0, ptr);
} }
if(d[0]=='i' && d[1]=='d' && d[2]=='e' && d[3]=='/' && if (d[0] == 'i' && d[1] == 'd' && d[2] == 'e' && d[3] == '/'
d[4]=='h' && d[5]=='o' && d[6]=='s' && d[7]=='t') && d[4] == 'h' && d[5] == 'o' && d[6] == 's' && d[7] == 't'
)
return scan_dev_name_common(d, n, 4, ptr); return scan_dev_name_common(d, n, 4, ptr);
if (d[0] == 's' && d[1] == 'b' && d[2] == 'p' && d[3] == '/') if (d[0] == 's' && d[1] == 'b' && d[2] == 'p' && d[3] == '/')
return 10; return 10;
@@ -429,10 +427,8 @@ int devfsd_main (int argc, char **argv)
if (argc < 2) if (argc < 2)
bb_show_usage(); bb_show_usage();
for (count = 2; count < argc; ++count) for (count = 2; count < argc; ++count) {
{ if (argv[count][0] == '-') {
if(argv[count][0] == '-')
{
if (argv[count][1] == 'v' && !argv[count][2]) /* -v */ if (argv[count][1] == 'v' && !argv[count][2]) /* -v */
print_version = TRUE; print_version = TRUE;
else if (ENABLE_DEVFSD_FG_NP && argv[count][1] == 'f' else if (ENABLE_DEVFSD_FG_NP && argv[count][1] == 'f'
@@ -498,8 +494,7 @@ int devfsd_main (int argc, char **argv)
if (ENABLE_DEVFSD_FG_NP && no_polling) if (ENABLE_DEVFSD_FG_NP && no_polling)
exit(0); exit(0);
if (do_daemon) if (do_daemon) {
{
/* Release so that the child can grab it */ /* Release so that the child can grab it */
do_ioctl_and_die(fd, DEVFSDIOC_RELEASE_EVENT_QUEUE, 0); do_ioctl_and_die(fd, DEVFSDIOC_RELEASE_EVENT_QUEUE, 0);
fork_and_execute(DIE, NULL, NULL); fork_and_execute(DIE, NULL, NULL);
@@ -508,8 +503,7 @@ int devfsd_main (int argc, char **argv)
setpgid(0, 0); /* Become process group leader */ setpgid(0, 0); /* Become process group leader */
} }
while (TRUE) while (TRUE) {
{
do_scan = do_servicing(fd, event_mask); do_scan = do_servicing(fd, event_mask);
free_config(); free_config();
@@ -538,13 +532,11 @@ static void read_config_file (char *path, int optional, unsigned long *event_mas
debug_msg_logger(LOG_INFO, "%s: %s", __FUNCTION__, path); debug_msg_logger(LOG_INFO, "%s: %s", __FUNCTION__, path);
if (stat (path, &statbuf) == 0 ) if (stat(path, &statbuf) == 0) {
{
/* Don't read 0 length files: ignored */ /* Don't read 0 length files: ignored */
/*if (statbuf.st_size == 0) /*if (statbuf.st_size == 0)
return;*/ return;*/
if ( S_ISDIR (statbuf.st_mode) ) if (S_ISDIR(statbuf.st_mode)) {
{
/* strip last / from dirname so we don't need to check for it later */ /* strip last / from dirname so we don't need to check for it later */
while (path && path[1] != '\0' && path[strlen(path) - 1] == '/') while (path && path[1] != '\0' && path[strlen(path) - 1] == '/')
path[strlen(path) - 1] = '\0'; path[strlen(path) - 1] = '\0';
@@ -552,10 +544,8 @@ static void read_config_file (char *path, int optional, unsigned long *event_mas
dir_operation(READ_CONFIG, path, 0, event_mask); dir_operation(READ_CONFIG, path, 0, event_mask);
return; return;
} }
if ( ( fp = fopen (path, "r") ) != NULL ) if ((fp = fopen(path, "r")) != NULL) {
{ while (fgets(buf, STRING_LENGTH, fp) != NULL) {
while (fgets (buf, STRING_LENGTH, fp) != NULL)
{
/* Skip whitespace */ /* Skip whitespace */
for (line = buf; isspace(*line); ++line) for (line = buf; isspace(*line); ++line)
/*VOID*/; /*VOID*/;
@@ -608,8 +598,7 @@ static void process_config_line (const char *line, unsigned long *event_mask)
i = index_in_str_array(options, when); i = index_in_str_array(options, when);
/*"CLEAR_CONFIG"*/ /*"CLEAR_CONFIG"*/
if( i == 0) if (i == 0) {
{
free_config(); free_config();
*event_mask = 0; *event_mask = 0;
return; return;
@@ -619,16 +608,14 @@ static void process_config_line (const char *line, unsigned long *event_mask)
goto process_config_line_err; goto process_config_line_err;
/* "INCLUDE" & "OPTIONAL_INCLUDE" */ /* "INCLUDE" & "OPTIONAL_INCLUDE" */
if( i == 1 || i == 2 ) if (i == 1 || i == 2) {
{
st_expr_expand(name, STRING_LENGTH, name, get_variable, NULL); st_expr_expand(name, STRING_LENGTH, name, get_variable, NULL);
msg_logger(LOG_INFO, "%sinclude: %s", (toupper(when[0]) == 'I') ? "": "optional_", name); msg_logger(LOG_INFO, "%sinclude: %s", (toupper(when[0]) == 'I') ? "": "optional_", name);
read_config_file(name, (toupper(when[0]) == 'I') ? FALSE : TRUE, event_mask); read_config_file(name, (toupper(when[0]) == 'I') ? FALSE : TRUE, event_mask);
return; return;
} }
/* "RESTORE" */ /* "RESTORE" */
if( i == 3) if (i == 3) {
{
dir_operation(RESTORE,name, strlen(name),NULL); dir_operation(RESTORE,name, strlen(name),NULL);
return; return;
} }
@@ -638,28 +625,24 @@ static void process_config_line (const char *line, unsigned long *event_mask)
new = xmalloc(sizeof *new); new = xmalloc(sizeof *new);
memset(new, 0, sizeof *new); memset(new, 0, sizeof *new);
for (count = 0; event_types[count].config_name != NULL; ++count) for (count = 0; event_types[count].config_name != NULL; ++count) {
{
if (strcasecmp(when, event_types[count].config_name) != 0) if (strcasecmp(when, event_types[count].config_name) != 0)
continue; continue;
new->action.when = event_types[count].type; new->action.when = event_types[count].type;
break; break;
} }
if (event_types[count].config_name == NULL) if (event_types[count].config_name == NULL) {
{
msg="WHEN in"; msg="WHEN in";
goto process_config_line_err; goto process_config_line_err;
} }
i = index_in_str_array(options, what); i = index_in_str_array(options, what);
switch (i) switch (i) {
{
case 4: /* "PERMISSIONS" */ case 4: /* "PERMISSIONS" */
new->action.what = AC_PERMISSIONS; new->action.what = AC_PERMISSIONS;
/* Get user and group */ /* Get user and group */
if ( ( ptr = strchr (p[0], '.') ) == NULL ) if ((ptr = strchr(p[0], '.')) == NULL) {
{
msg="UID.GID"; msg="UID.GID";
goto process_config_line_err; /*"missing '.' in UID.GID"*/ goto process_config_line_err; /*"missing '.' in UID.GID"*/
} }
@@ -747,8 +730,7 @@ static int do_servicing (int fd, unsigned long event_mask)
/* Tell devfs what events we care about */ /* Tell devfs what events we care about */
tmp_event_mask = event_mask; tmp_event_mask = event_mask;
do_ioctl_and_die(fd, DEVFSDIOC_SET_EVENT_MASK, tmp_event_mask); do_ioctl_and_die(fd, DEVFSDIOC_SET_EVENT_MASK, tmp_event_mask);
while (!caught_signal) while (!caught_signal) {
{
errno = 0; errno = 0;
bytes = read(fd,(char *) &info, sizeof info); bytes = read(fd,(char *) &info, sizeof info);
if (caught_signal) if (caught_signal)
@@ -759,8 +741,7 @@ static int do_servicing (int fd, unsigned long event_mask)
break; break;
service_name(&info); service_name(&info);
} }
if (caught_signal) if (caught_signal) {
{
int c_sighup = caught_sighup; int c_sighup = caught_sighup;
caught_signal = FALSE; caught_signal = FALSE;
@@ -785,26 +766,27 @@ static void service_name (const struct devfsd_notify_struct *info)
debug_msg_logger(LOG_ERR, "lost %u events", info->overrun_count); debug_msg_logger(LOG_ERR, "lost %u events", info->overrun_count);
/* Discard lookups on "/dev/log" and "/dev/initctl" */ /* Discard lookups on "/dev/log" and "/dev/initctl" */
if( info->type == DEVFSD_NOTIFY_LOOKUP && if (info->type == DEVFSD_NOTIFY_LOOKUP
((info->devname[0]=='l' && info->devname[1]=='o' && && ((info->devname[0] == 'l' && info->devname[1] == 'o'
info->devname[2]=='g' && !info->devname[3]) || && info->devname[2] == 'g' && !info->devname[3])
( info->devname[0]=='i' && info->devname[1]=='n' && || (info->devname[0] == 'i' && info->devname[1] == 'n'
info->devname[2]=='i' && info->devname[3]=='t' && && info->devname[2] == 'i' && info->devname[3] == 't'
info->devname[4]=='c' && info->devname[5]=='t' && && info->devname[4] == 'c' && info->devname[5] == 't'
info->devname[6]=='l' && !info->devname[7]))) && info->devname[6] == 'l' && !info->devname[7]))
)
return; return;
for (entry = first_config; entry != NULL; entry = entry->next)
{ for (entry = first_config; entry != NULL; entry = entry->next) {
/* First check if action matches the type, then check if name matches */ /* First check if action matches the type, then check if name matches */
if (info->type != entry->action.when || regexec (&entry->preg, info->devname, MAX_SUBEXPR, mbuf, 0) != 0 ) if (info->type != entry->action.when
|| regexec(&entry->preg, info->devname, MAX_SUBEXPR, mbuf, 0) != 0)
continue; continue;
for (n = 0;(n < MAX_SUBEXPR) && (mbuf[n].rm_so != -1); ++n) for (n = 0;(n < MAX_SUBEXPR) && (mbuf[n].rm_so != -1); ++n)
/* VOID */; /* VOID */;
debug_msg_logger(LOG_INFO, "%s: action.what %d", __FUNCTION__, entry->action.what); debug_msg_logger(LOG_INFO, "%s: action.what %d", __FUNCTION__, entry->action.what);
switch (entry->action.what) switch (entry->action.what) {
{
case AC_PERMISSIONS: case AC_PERMISSIONS:
action_permissions(info, entry); action_permissions(info, entry);
break; break;
@@ -847,8 +829,7 @@ static void action_permissions (const struct devfsd_notify_struct *info,
if (stat(info->devname, &statbuf) != 0 || if (stat(info->devname, &statbuf) != 0 ||
chmod(info->devname,(statbuf.st_mode & S_IFMT) |(entry->u.permissions.mode & ~S_IFMT)) != 0 || chmod(info->devname,(statbuf.st_mode & S_IFMT) |(entry->u.permissions.mode & ~S_IFMT)) != 0 ||
chown (info->devname, entry->u.permissions.uid, entry->u.permissions.gid) != 0) chown(info->devname, entry->u.permissions.uid, entry->u.permissions.gid) != 0) {
{
msg_logger(LOG_ERR, "Can't chmod or chown: %s: %m",info->devname); msg_logger(LOG_ERR, "Can't chmod or chown: %s: %m",info->devname);
} }
} /* End Function action_permissions */ } /* End Function action_permissions */
@@ -897,8 +878,7 @@ static void action_execute (const struct devfsd_notify_struct *info,
gv_info.info = info; gv_info.info = info;
gv_info.devname = info->devname; gv_info.devname = info->devname;
snprintf(gv_info.devpath, sizeof(gv_info.devpath), "%s/%s", mount_point, info->devname); snprintf(gv_info.devpath, sizeof(gv_info.devpath), "%s/%s", mount_point, info->devname);
for (count = 0; entry->u.execute.argv[count] != NULL; ++count) for (count = 0; entry->u.execute.argv[count] != NULL; ++count) {
{
expand_expression(largv[count], STRING_LENGTH, expand_expression(largv[count], STRING_LENGTH,
entry->u.execute.argv[count], entry->u.execute.argv[count],
get_variable, &gv_info, get_variable, &gv_info,
@@ -990,8 +970,7 @@ static void action_compat (const struct devfsd_notify_struct *info, unsigned int
}; };
/* First construct compatibility name */ /* First construct compatibility name */
switch (action) switch (action) {
{
case AC_MKOLDCOMPAT: case AC_MKOLDCOMPAT:
case AC_RMOLDCOMPAT: case AC_RMOLDCOMPAT:
compat_name = get_old_name(info->devname, info->namelen, compat_buf, info->major, info->minor); compat_name = get_old_name(info->devname, info->namelen, compat_buf, info->major, info->minor);
@@ -1022,8 +1001,7 @@ static void action_compat (const struct devfsd_notify_struct *info, unsigned int
sprintf(compat_buf, fmt[i], host, bus, target, lun, atoi(ptr + 4)); sprintf(compat_buf, fmt[i], host, bus, target, lun, atoi(ptr + 4));
/* 5 == scsi/mt */ /* 5 == scsi/mt */
if( i == 5) if (i == 5) {
{
rewind_ = info->devname[info->namelen - 1]; rewind_ = info->devname[info->namelen - 1];
if (rewind_ != 'n') if (rewind_ != 'n')
rewind_ = '\0'; rewind_ = '\0';
@@ -1047,8 +1025,7 @@ static void action_compat (const struct devfsd_notify_struct *info, unsigned int
debug_msg_logger(LOG_INFO, "%s: %s", __FUNCTION__, compat_name); debug_msg_logger(LOG_INFO, "%s: %s", __FUNCTION__, compat_name);
/* Now decide what to do with it */ /* Now decide what to do with it */
switch (action) switch (action) {
{
case AC_MKOLDCOMPAT: case AC_MKOLDCOMPAT:
case AC_MKNEWCOMPAT: case AC_MKNEWCOMPAT:
mksymlink(dest_name, compat_name); mksymlink(dest_name, compat_name);
@@ -1102,18 +1079,16 @@ static int copy_inode (const char *destpath, const struct stat *dest_stat,
debug_msg_logger(LOG_INFO, __FUNCTION__); debug_msg_logger(LOG_INFO, __FUNCTION__);
if ( (source_stat->st_mode & S_IFMT) == (dest_stat->st_mode & S_IFMT) ) if ((source_stat->st_mode & S_IFMT) ==(dest_stat->st_mode & S_IFMT)) {
{
/* Same type */ /* Same type */
if ( S_ISLNK (source_stat->st_mode) ) if (S_ISLNK(source_stat->st_mode)) {
{ if ((source_len = readlink(sourcepath, source_link, STRING_LENGTH - 1)) < 0
if (( source_len = readlink (sourcepath, source_link, STRING_LENGTH - 1) ) < 0 || || (dest_len = readlink(destpath , dest_link , STRING_LENGTH - 1)) < 0
( dest_len = readlink (destpath , dest_link , STRING_LENGTH - 1) ) < 0 ) )
return FALSE; return FALSE;
source_link[source_len] = '\0'; source_link[source_len] = '\0';
dest_link[dest_len] = '\0'; dest_link[dest_len] = '\0';
if ( (source_len != dest_len) || (strcmp (source_link, dest_link) != 0) ) if ((source_len != dest_len) || (strcmp(source_link, dest_link) != 0)) {
{
unlink(destpath); unlink(destpath);
symlink(source_link, destpath); symlink(source_link, destpath);
} }
@@ -1125,8 +1100,7 @@ static int copy_inode (const char *destpath, const struct stat *dest_stat,
} }
/* Different types: unlink and create */ /* Different types: unlink and create */
unlink(destpath); unlink(destpath);
switch (source_stat->st_mode & S_IFMT) switch (source_stat->st_mode & S_IFMT) {
{
case S_IFSOCK: case S_IFSOCK:
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
break; break;
@@ -1178,16 +1152,13 @@ static void free_config (void)
debug_msg_logger(LOG_INFO, __FUNCTION__); debug_msg_logger(LOG_INFO, __FUNCTION__);
for (c_entry = first_config; c_entry != NULL; c_entry = next) for (c_entry = first_config; c_entry != NULL; c_entry = next) {
{
unsigned int count; unsigned int count;
next = c_entry->next; next = c_entry->next;
regfree(&c_entry->preg); regfree(&c_entry->preg);
if (c_entry->action.what == AC_EXECUTE) if (c_entry->action.what == AC_EXECUTE) {
{ for (count = 0; count < MAX_ARGS; ++count) {
for (count = 0; count < MAX_ARGS; ++count)
{
if (c_entry->u.execute.argv[count] == NULL) if (c_entry->u.execute.argv[count] == NULL)
break; break;
free(c_entry->u.execute.argv[count]); free(c_entry->u.execute.argv[count]);
@@ -1252,8 +1223,7 @@ static mode_t get_mode (const char *string)
mode = 0; mode = 0;
i = S_IRUSR; i = S_IRUSR;
while (i>0) while (i > 0) {
{
if (string[0] == 'r' || string[0] == 'w' || string[0] == 'x') if (string[0] == 'r' || string[0] == 'w' || string[0] == 'x')
mode += i; mode += i;
i = i/2; i = i/2;
@@ -1295,8 +1265,7 @@ static const char *get_variable (const char *variable, void *info)
if (i > 6 || i < 0 || (i > 1 && gv_info == NULL)) if (i > 6 || i < 0 || (i > 1 && gv_info == NULL))
return NULL; return NULL;
if( i >= 0 && i <= 3) if (i >= 0 && i <= 3) {
{
debug_msg_logger(LOG_INFO, "%s: i=%d %s", __FUNCTION__, i, field_names[i + 7]); debug_msg_logger(LOG_INFO, "%s: i=%d %s", __FUNCTION__, i, field_names[i + 7]);
return field_names[i + 7]; return field_names[i + 7];
} }
@@ -1349,27 +1318,23 @@ static void dir_operation(int type, const char * dir_name, int var, unsigned lon
debug_msg_logger(LOG_INFO, __FUNCTION__); debug_msg_logger(LOG_INFO, __FUNCTION__);
if((dp = opendir( dir_name))==NULL) if ((dp = opendir(dir_name))==NULL) {
{
debug_msg_logger(LOG_ERR, "opendir: %s: %m", dir_name); debug_msg_logger(LOG_ERR, "opendir: %s: %m", dir_name);
return; return;
} }
while ( (de = readdir (dp) ) != NULL ) while ((de = readdir(dp)) != NULL) {
{
if (de->d_name && DOT_OR_DOTDOT(de->d_name)) if (de->d_name && DOT_OR_DOTDOT(de->d_name))
continue; continue;
snprintf(path, sizeof(path), "%s/%s", dir_name, de->d_name); snprintf(path, sizeof(path), "%s/%s", dir_name, de->d_name);
debug_msg_logger(LOG_ERR, "%s: %s", __FUNCTION__, path); debug_msg_logger(LOG_ERR, "%s: %s", __FUNCTION__, path);
if (lstat (path, &statbuf) != 0) if (lstat(path, &statbuf) != 0) {
{
debug_msg_logger(LOG_ERR, "%s: %s: %m", __FUNCTION__, path); debug_msg_logger(LOG_ERR, "%s: %s: %m", __FUNCTION__, path);
continue; continue;
} }
switch (type) switch (type) {
{
case SERVICE: case SERVICE:
service(statbuf, path); service(statbuf, path);
break; break;
@@ -1414,8 +1379,7 @@ static int make_dir_tree (const char *path)
{ {
debug_msg_logger(LOG_INFO, __FUNCTION__); debug_msg_logger(LOG_INFO, __FUNCTION__);
if (bb_make_directory( dirname((char *)path), -1, FILEUTILS_RECUR )==-1) if (bb_make_directory(dirname((char *)path), -1, FILEUTILS_RECUR) == -1) {
{
debug_msg_logger(LOG_ERR, "%s: %s: %m",__FUNCTION__, path); debug_msg_logger(LOG_ERR, "%s: %s: %m",__FUNCTION__, path);
return FALSE; return FALSE;
} }
@@ -1483,18 +1447,14 @@ static void expand_regexp (char *output, size_t outsize, const char *input,
/* Copy the input string into the output buffer, replacing '\\' with '\' /* Copy the input string into the output buffer, replacing '\\' with '\'
and '\0' .. '\9' with subexpressions 0 .. 9, if they exist. Other \x and '\0' .. '\9' with subexpressions 0 .. 9, if they exist. Other \x
codes are deleted */ codes are deleted */
while ( (c != '\0') && (outsize != 0) ) while ((c != '\0') && (outsize != 0)) {
{
c = *input; c = *input;
++input; ++input;
if (c == '\\') if (c == '\\') {
{
c = *input; c = *input;
++input; ++input;
if (c != '\\') if (c != '\\') {
{ if ((c >= '0') && (c <= last_exp)) {
if ((c >= '0') && (c <= last_exp))
{
const regmatch_t *subexp = ex + (c - '0'); const regmatch_t *subexp = ex + (c - '0');
unsigned int sublen = subexp->rm_eo - subexp->rm_so; unsigned int sublen = subexp->rm_eo - subexp->rm_so;
@@ -1597,12 +1557,10 @@ const char *get_old_name (const char *devname, unsigned int namelen,
debug_msg_logger(LOG_INFO, __FUNCTION__); debug_msg_logger(LOG_INFO, __FUNCTION__);
for (trans = translate_table; trans->match != NULL; ++trans) for (trans = translate_table; trans->match != NULL; ++trans) {
{
len = strlen(trans->match); len = strlen(trans->match);
if (strncmp (devname, trans->match, len) == 0) if (strncmp(devname, trans->match, len) == 0) {
{
if (trans->format == NULL) if (trans->format == NULL)
return devname + len; return devname + len;
sprintf(buffer, trans->format, devname + len); sprintf(buffer, trans->format, devname + len);
@@ -1629,8 +1587,7 @@ const char *get_old_name (const char *devname, unsigned int namelen,
compat_name = write_old_sd_name(buffer, major, minor,((i == 2)?"":(ptr + 4))); compat_name = write_old_sd_name(buffer, major, minor,((i == 2)?"":(ptr + 4)));
/* 5 == scsi/mt */ /* 5 == scsi/mt */
if( i == 5) if (i == 5) {
{
mode = ptr[2]; mode = ptr[2];
if (mode == 'n') if (mode == 'n')
mode = '\0'; mode = '\0';
@@ -1648,15 +1605,13 @@ const char *get_old_name (const char *devname, unsigned int namelen,
sprintf(buffer, fmt[i], ptr + 2, minor & 0x7f); sprintf(buffer, fmt[i], ptr + 2, minor & 0x7f);
/* 11 == vcc/ */ /* 11 == vcc/ */
if( i == 11 ) if (i == 11) {
{
sprintf(buffer, fmt[i], devname + 4); sprintf(buffer, fmt[i], devname + 4);
if (buffer[3] == '0') if (buffer[3] == '0')
buffer[3] = '\0'; buffer[3] = '\0';
} }
/* 12 == pty/ */ /* 12 == pty/ */
if( i == 12 ) if (i == 12) {
{
pty1 = "pqrstuvwxyzabcde"; pty1 = "pqrstuvwxyzabcde";
pty2 = "0123456789abcdef"; pty2 = "0123456789abcdef";
indexx = atoi(devname + 5); indexx = atoi(devname + 5);
@@ -1684,13 +1639,12 @@ static char get_old_ide_name (unsigned int major, unsigned int minor)
/* I hope it works like the previous code as it saves a few bytes. Tito ;P */ /* I hope it works like the previous code as it saves a few bytes. Tito ;P */
do { do {
if( i==IDE0_MAJOR || i==IDE1_MAJOR || i==IDE2_MAJOR || if (i == IDE0_MAJOR || i == IDE1_MAJOR || i == IDE2_MAJOR
i==IDE3_MAJOR || i==IDE4_MAJOR || i==IDE5_MAJOR || || i == IDE3_MAJOR || i == IDE4_MAJOR || i == IDE5_MAJOR
i==IDE6_MAJOR || i==IDE7_MAJOR || i==IDE8_MAJOR || || i == IDE6_MAJOR || i == IDE7_MAJOR || i == IDE8_MAJOR
i==IDE9_MAJOR ) || i == IDE9_MAJOR
{ ) {
if((unsigned int)i==major) if ((unsigned int)i == major) {
{
letter = c; letter = c;
break; break;
} }
@@ -1719,13 +1673,11 @@ static char *write_old_sd_name (char *buffer,
debug_msg_logger(LOG_INFO, __FUNCTION__); debug_msg_logger(LOG_INFO, __FUNCTION__);
if (major == 8) if (major == 8) {
{
sprintf(buffer, "sd%c%s", 'a' + (minor >> 4), part); sprintf(buffer, "sd%c%s", 'a' + (minor >> 4), part);
return buffer; return buffer;
} }
if ( (major > 64) && (major < 72) ) if ((major > 64) && (major < 72)) {
{
disc_index = ((major - 64) << 4) +(minor >> 4); disc_index = ((major - 64) << 4) +(minor >> 4);
if (disc_index < 26) if (disc_index < 26)
sprintf(buffer, "sd%c%s", 'a' + disc_index, part); sprintf(buffer, "sd%c%s", 'a' + disc_index, part);
@@ -1768,10 +1720,8 @@ int st_expr_expand (char *output, unsigned int length, const char *input,
if (length > BUFFER_SIZE) if (length > BUFFER_SIZE)
length = BUFFER_SIZE; length = BUFFER_SIZE;
for (; TRUE; ++input) for (; TRUE; ++input) {
{ switch (ch = *input) {
switch (ch = *input)
{
case '$': case '$':
/* Variable expansion */ /* Variable expansion */
input = expand_variable(buffer, length, &out_pos, ++input, get_variable_func, info); input = expand_variable(buffer, length, &out_pos, ++input, get_variable_func, info);
@@ -1781,11 +1731,9 @@ int st_expr_expand (char *output, unsigned int length, const char *input,
case '~': case '~':
/* Home directory expansion */ /* Home directory expansion */
ch = input[1]; ch = input[1];
if ( isspace (ch) || (ch == '/') || (ch == '\0') ) if (isspace(ch) ||(ch == '/') ||(ch == '\0')) {
{
/* User's own home directory: leave separator for next time */ /* User's own home directory: leave separator for next time */
if ( ( env = getenv ("HOME") ) == NULL ) if ((env = getenv("HOME")) == NULL) {
{
msg_logger(LOG_INFO, bb_msg_variable_not_found, "HOME"); msg_logger(LOG_INFO, bb_msg_variable_not_found, "HOME");
return FALSE; return FALSE;
} }
@@ -1804,8 +1752,7 @@ int st_expr_expand (char *output, unsigned int length, const char *input,
goto st_expr_expand_out; goto st_expr_expand_out;
safe_memcpy(tmp, input, len); safe_memcpy(tmp, input, len);
input = ptr - 1; input = ptr - 1;
if ( ( pwent = getpwnam (tmp) ) == NULL ) if ((pwent = getpwnam(tmp)) == NULL) {
{
msg_logger(LOG_INFO, "no pwent for: %s", tmp); msg_logger(LOG_INFO, "no pwent for: %s", tmp);
return FALSE; return FALSE;
} }
@@ -1821,8 +1768,7 @@ int st_expr_expand (char *output, unsigned int length, const char *input,
if (out_pos >= length) if (out_pos >= length)
goto st_expr_expand_out; goto st_expr_expand_out;
buffer[out_pos++] = ch; buffer[out_pos++] = ch;
if (ch == '\0') if (ch == '\0') {
{
memcpy(output, buffer, out_pos); memcpy(output, buffer, out_pos);
return TRUE; return TRUE;
} }
@@ -1866,8 +1812,7 @@ static const char *expand_variable (char *buffer, unsigned int length,
debug_msg_logger(LOG_INFO, __FUNCTION__); debug_msg_logger(LOG_INFO, __FUNCTION__);
ch = input[0]; ch = input[0];
if (ch == '$') if (ch == '$') {
{
/* Special case for "$$": PID */ /* Special case for "$$": PID */
sprintf(tmp, "%d",(int) getpid()); sprintf(tmp, "%d",(int) getpid());
len = strlen(tmp); len = strlen(tmp);
@@ -1879,8 +1824,7 @@ static const char *expand_variable (char *buffer, unsigned int length,
return input; return input;
} }
/* Ordinary variable expansion, possibly in braces */ /* Ordinary variable expansion, possibly in braces */
if (ch != '{') if (ch != '{') {
{
/* Simple variable expansion */ /* Simple variable expansion */
for (ptr = input; isalnum(ch) || (ch == '_') || (ch == ':'); ch = *++ptr) for (ptr = input; isalnum(ch) || (ch == '_') || (ch == ':'); ch = *++ptr)
/* VOID */ ; /* VOID */ ;
@@ -1890,8 +1834,7 @@ static const char *expand_variable (char *buffer, unsigned int length,
safe_memcpy(tmp, input, len); safe_memcpy(tmp, input, len);
input = ptr - 1; input = ptr - 1;
if ( ( env = get_variable_v2 (tmp, func, info) ) == NULL ) if ((env = get_variable_v2(tmp, func, info)) == NULL) {
{
msg_logger(LOG_INFO, bb_msg_variable_not_found, tmp); msg_logger(LOG_INFO, bb_msg_variable_not_found, tmp);
return NULL; return NULL;
} }
@@ -1907,8 +1850,7 @@ static const char *expand_variable (char *buffer, unsigned int length,
ch = *++input; ch = *++input;
for (ptr = input; isalnum(ch) || (ch == '_'); ch = *++ptr) for (ptr = input; isalnum(ch) || (ch == '_'); ch = *++ptr)
/* VOID */; /* VOID */;
if (ch == '}') if (ch == '}') {
{
/* Must be simple variable expansion with "${var}" */ /* Must be simple variable expansion with "${var}" */
len = ptr - input; len = ptr - input;
if ((size_t)len >= sizeof tmp) if ((size_t)len >= sizeof tmp)
@@ -1920,8 +1862,7 @@ static const char *expand_variable (char *buffer, unsigned int length,
return NULL; return NULL;
return input + len; return input + len;
} }
if (ch != ':' || ptr[1] != '-' ) if (ch != ':' || ptr[1] != '-') {
{
msg_logger(LOG_INFO, "illegal char in var name"); msg_logger(LOG_INFO, "illegal char in var name");
return NULL; return NULL;
} }
@@ -1936,10 +1877,8 @@ static const char *expand_variable (char *buffer, unsigned int length,
/* First skip to closing brace, taking note of nested expressions */ /* First skip to closing brace, taking note of nested expressions */
ptr += 2; ptr += 2;
ch = ptr[0]; ch = ptr[0];
for (open_braces = 1; open_braces > 0; ch = *++ptr) for (open_braces = 1; open_braces > 0; ch = *++ptr) {
{ switch (ch) {
switch (ch)
{
case '{': case '{':
++open_braces; ++open_braces;
break; break;
@@ -1955,8 +1894,7 @@ static const char *expand_variable (char *buffer, unsigned int length,
} }
--ptr; --ptr;
/* At this point ptr should point to closing brace of "${var:-word}" */ /* At this point ptr should point to closing brace of "${var:-word}" */
if ( ( env = get_variable_v2 (tmp, func, info) ) != NULL ) if ((env = get_variable_v2(tmp, func, info)) != NULL) {
{
/* Found environment variable, so skip the input to the closing brace /* Found environment variable, so skip the input to the closing brace
and return the variable */ and return the variable */
input = ptr; input = ptr;
@@ -2007,8 +1945,7 @@ static const char *get_variable_v2 (const char *variable,
debug_msg_logger(LOG_INFO, __FUNCTION__); debug_msg_logger(LOG_INFO, __FUNCTION__);
if (func != NULL) if (func != NULL) {
{
value = (*func)(variable, info); value = (*func)(variable, info);
if (value != NULL) if (value != NULL)
return value; return value;

View File

@@ -6986,7 +6986,7 @@ typecmd(int argc, char **argv)
int verbose = 1; int verbose = 1;
/* type -p ... ? (we don't bother checking for 'p') */ /* type -p ... ? (we don't bother checking for 'p') */
if (argv[1][0] == '-') { if (argv[1] && argv[1][0] == '-') {
i++; i++;
verbose = 0; verbose = 0;
} }