From a421ba8203df8cd8a09d4bfb158057d9e717648f Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 3 Feb 2006 00:25:37 +0000 Subject: [PATCH] cleanup style ... just because you use less spaces doesnt mean the resulting code is smaller --- util-linux/mdev.c | 113 ++++++++++++++++++++++++++-------------------- 1 file changed, 63 insertions(+), 50 deletions(-) diff --git a/util-linux/mdev.c b/util-linux/mdev.c index c100e0fa6..aef84ac45 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -23,19 +23,20 @@ #include "xregex.h" #define DEV_PATH "/dev" +#define MDEV_CONF "/etc/mdev.conf" #include /* mknod in /dev based on a path like "/sys/block/hda/hda1" */ static void make_device(char *path) { - char *device_name,*s; - int major,minor,type,len,fd; - int mode=0660; - uid_t uid=0; - gid_t gid=0; + char *device_name, *s; + int major, minor, type, len, fd; + int mode = 0660; + uid_t uid = 0; + gid_t gid = 0; - RESERVE_CONFIG_BUFFER(temp,PATH_MAX); + RESERVE_CONFIG_BUFFER(temp, PATH_MAX); /* Try to read major/minor string */ @@ -43,60 +44,64 @@ static void make_device(char *path) fd = open(temp, O_RDONLY); len = read(fd, temp, PATH_MAX-1); close(fd); - if (len<1) goto end; + if (len < 1) goto end; /* Determine device name, type, major and minor */ device_name = strrchr(path, '/') + 1; - type = strncmp(path+5, "block/" ,6) ? S_IFCHR : S_IFBLK; - if(sscanf(temp, "%d:%d", &major, &minor) != 2) goto end; + type = strncmp(path+5, "block/", 6) ? S_IFCHR : S_IFBLK; + if (sscanf(temp, "%d:%d", &major, &minor) != 2) + goto end; /* If we have a config file, look up permissions for this device */ if (ENABLE_FEATURE_MDEV_CONF) { - char *conf,*pos,*end; + char *conf, *pos, *end; /* mmap the config file */ - if (-1!=(fd=open("/etc/mdev.conf",O_RDONLY))) { - len=lseek(fd,0,SEEK_END); - conf=mmap(NULL,len,PROT_READ,MAP_PRIVATE,fd,0); + if (-1 != (fd=open(MDEV_CONF,O_RDONLY))) { + len = lseek(fd, 0, SEEK_END); + conf = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0); if (conf) { - int line=0; + int line = 0; /* Loop through lines in mmaped file*/ - for (pos=conf;pos-confpw_uid; + pass = getpwnam(strndupa(pos,s-pos)); + if (!pass) + goto end_line; + uid = pass->pw_uid; } s++; /* parse GID */ - gid=strtoul(s,&s2,10); - if(end2!=s2) { + gid = strtoul(s,&s2,10); + if (end2 != s2) { struct group *grp; - grp=getgrnam(strndupa(s,end2-s)); - if(!grp) goto end_line; - gid=grp->gr_gid; + grp = getgrnam(strndupa(s,end2-s)); + if (!grp) + goto end_line; + gid = grp->gr_gid; } break; } /* mode */ case 1: { - mode=strtoul(pos,&pos,8); - if(pos!=end2) goto end_line; - goto found_device; + mode = strtoul(pos,&pos,8); + if (pos != end2) + goto end_line; + else + goto found_device; } } - pos=end2; + pos = end2; } end_line: /* Did everything parse happily? */ if (field && field!=3) - bb_error_msg_and_die("Bad line %d",line); + bb_error_msg_and_die("Bad line %d",line); /* Next line */ - pos=++end; + pos = ++end; } found_device: - munmap(conf,len); + munmap(conf, len); } close(fd); } @@ -170,7 +181,7 @@ end: static void find_dev(char *path) { DIR *dir; - size_t len=strlen(path); + size_t len = strlen(path); struct dirent *entry; if ((dir = opendir(path)) == NULL) @@ -180,7 +191,8 @@ static void find_dev(char *path) /* Skip "." and ".." (also skips hidden files, which is ok) */ - if (entry->d_name[0]=='.') continue; + if (entry->d_name[0] == '.') + continue; if (entry->d_type == DT_DIR) { snprintf(path+len, PATH_MAX-len, "/%s", entry->d_name); @@ -214,7 +226,8 @@ int mdev_main(int argc, char *argv[]) } else { action = getenv("ACTION"); env_path = getenv("DEVPATH"); - if (!action || !env_path) bb_show_usage(); + if (!action || !env_path) + bb_show_usage(); if (!strcmp(action, "add")) { sprintf(temp, "/sys%s", env_path); @@ -225,6 +238,6 @@ int mdev_main(int argc, char *argv[]) } } - if(ENABLE_FEATURE_CLEAN_UP) RELEASE_CONFIG_BUFFER(temp); + if (ENABLE_FEATURE_CLEAN_UP) RELEASE_CONFIG_BUFFER(temp); return 0; }