mdev: reduce excessive indentation

This commit is contained in:
Denis Vlasenko 2006-10-16 19:39:37 +00:00
parent 4e33e07f60
commit f46be09106

View File

@ -25,7 +25,7 @@ struct mdev_globals
static void make_device(char *path, int delete)
{
char *device_name;
int major, minor, type, len, fd;
int major, minor, type, len;
int mode = 0660;
uid_t uid = 0;
gid_t gid = 0;
@ -53,14 +53,19 @@ static void make_device(char *path, int delete)
if (ENABLE_FEATURE_MDEV_CONF) {
char *conf, *pos, *end;
int line, fd;
/* mmap the config file */
if (-1 != (fd=open("/etc/mdev.conf",O_RDONLY))) {
len = lseek(fd, 0, SEEK_END);
fd = open("/etc/mdev.conf", O_RDONLY);
if (fd < 0)
goto end_parse;
len = xlseek(fd, 0, SEEK_END);
conf = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
if (conf) {
int line = 0;
close(fd);
if (!conf)
goto end_parse;
line = 0;
/* Loop through lines in mmaped file*/
for (pos=conf; pos-conf<len;) {
int field;
@ -82,7 +87,7 @@ static void make_device(char *path, int delete)
end2<end && !isspace(*end2) && *end2!='#'; end2++)
;
if (!field) {
if (field == 0) {
/* Regex to match this device */
char *regex = strndupa(pos, end2-pos);
@ -99,8 +104,8 @@ static void make_device(char *path, int delete)
if (result || off.rm_so
|| off.rm_eo != strlen(device_name))
break;
} else if (field == 1) {
}
if (field == 1) {
/* uid:gid */
char *s, *s2;
@ -127,15 +132,18 @@ static void make_device(char *path, int delete)
if (!grp) break;
gid = grp->gr_gid;
}
} else if (field == 2) {
}
if (field == 2) {
/* mode */
mode = strtoul(pos, &pos, 8);
if (pos != end2) break;
} else if (ENABLE_FEATURE_MDEV_EXEC && field == 3) {
}
if (ENABLE_FEATURE_MDEV_EXEC && field == 3) {
// Command to run
char *s = "@$*", *s2;
if (!(s2 = strchr(s, *pos++))) {
s2 = strchr(s, *pos++);
if (!s2) {
// Force error
field = 1;
break;
@ -150,22 +158,20 @@ static void make_device(char *path, int delete)
/* Did everything parse happily? */
if (field > 2) break;
if (field) bb_error_msg_and_die("Bad line %d",line);
if (field) bb_error_msg_and_die("bad line %d",line);
/* Next line */
pos = ++end;
}
munmap(conf, len);
}
close(fd);
}
end_parse: /* nothing */ ;
}
umask(0);
if (!delete) {
if (sscanf(temp, "%d:%d", &major, &minor) != 2) return;
if (mknod(device_name, mode | type, makedev(major, minor)) && errno != EEXIST)
bb_perror_msg_and_die("mknod %s failed", device_name);
bb_perror_msg_and_die("mknod %s", device_name);
if (major == bbg.root_major && minor == bbg.root_minor)
symlink(device_name, "root");
@ -197,7 +203,8 @@ static void find_dev(char *path)
size_t len = strlen(path);
struct dirent *entry;
if ((dir = opendir(path)) == NULL)
dir = opendir(path);
if (dir == NULL)
return;
while ((entry = readdir(dir)) != NULL) {
@ -235,7 +242,7 @@ int mdev_main(int argc, char *argv[])
if (argc == 2 && !strcmp(argv[1],"-s")) {
struct stat st;
stat("/", &st); // If this fails, we have bigger problems.
xstat("/", &st);
bbg.root_major = major(st.st_dev);
bbg.root_minor = minor(st.st_dev);
strcpy(temp,"/sys/block");