mirror of
https://github.com/sheumann/hush.git
synced 2025-08-15 19:27:40 +00:00
cleanup style ... just because you use less spaces doesnt mean the resulting code is smaller
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include "xregex.h"
|
||||
|
||||
#define DEV_PATH "/dev"
|
||||
#define MDEV_CONF "/etc/mdev.conf"
|
||||
|
||||
#include <busybox.h>
|
||||
|
||||
@@ -49,7 +50,8 @@ static void make_device(char *path)
|
||||
|
||||
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;
|
||||
if (sscanf(temp, "%d:%d", &major, &minor) != 2)
|
||||
goto end;
|
||||
|
||||
/* If we have a config file, look up permissions for this device */
|
||||
|
||||
@@ -57,7 +59,7 @@ static void make_device(char *path)
|
||||
char *conf, *pos, *end;
|
||||
|
||||
/* mmap the config file */
|
||||
if (-1!=(fd=open("/etc/mdev.conf",O_RDONLY))) {
|
||||
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) {
|
||||
@@ -70,15 +72,19 @@ static void make_device(char *path)
|
||||
|
||||
line++;
|
||||
/* find end of this line */
|
||||
for(end=pos;end-conf<len && *end!='\n';end++);
|
||||
for(end=pos; end-conf<len && *end!='\n'; end++)
|
||||
;
|
||||
|
||||
/* Three fields: regex, uid:gid, mode */
|
||||
for (field=3; field; field--) {
|
||||
/* Skip whitespace */
|
||||
while (pos<end && isspace(*pos)) pos++;
|
||||
if (pos==end || *pos=='#') break;
|
||||
for (end2=pos;
|
||||
end2<end && !isspace(*end2) && *end2!='#'; end2++);
|
||||
while (pos<end && isspace(*pos))
|
||||
pos++;
|
||||
if (pos==end || *pos=='#')
|
||||
break;
|
||||
for (end2=pos; end2<end && !isspace(*end2) && *end2!='#'; end2++)
|
||||
;
|
||||
|
||||
switch (field) {
|
||||
/* Regex to match this device */
|
||||
case 3:
|
||||
@@ -94,8 +100,7 @@ static void make_device(char *path)
|
||||
regfree(&match);
|
||||
|
||||
/* If not this device, skip rest of line */
|
||||
if(result || off.rm_so
|
||||
|| off.rm_eo!=strlen(device_name))
|
||||
if (result || off.rm_so || off.rm_eo!=strlen(device_name))
|
||||
goto end_line;
|
||||
|
||||
break;
|
||||
@@ -106,15 +111,18 @@ static void make_device(char *path)
|
||||
char *s2;
|
||||
|
||||
/* Find : */
|
||||
for(s=pos;s<end2 && *s!=':';s++);
|
||||
if(s==end2) goto end_line;
|
||||
for(s=pos; s<end2 && *s!=':'; s++)
|
||||
;
|
||||
if (s == end2)
|
||||
goto end_line;
|
||||
|
||||
/* Parse UID */
|
||||
uid = strtoul(pos,&s2,10);
|
||||
if (s != s2) {
|
||||
struct passwd *pass;
|
||||
pass = getpwnam(strndupa(pos,s-pos));
|
||||
if(!pass) goto end_line;
|
||||
if (!pass)
|
||||
goto end_line;
|
||||
uid = pass->pw_uid;
|
||||
}
|
||||
s++;
|
||||
@@ -123,7 +131,8 @@ static void make_device(char *path)
|
||||
if (end2 != s2) {
|
||||
struct group *grp;
|
||||
grp = getgrnam(strndupa(s,end2-s));
|
||||
if(!grp) goto end_line;
|
||||
if (!grp)
|
||||
goto end_line;
|
||||
gid = grp->gr_gid;
|
||||
}
|
||||
break;
|
||||
@@ -132,7 +141,9 @@ static void make_device(char *path)
|
||||
case 1:
|
||||
{
|
||||
mode = strtoul(pos,&pos,8);
|
||||
if(pos!=end2) goto end_line;
|
||||
if (pos != end2)
|
||||
goto end_line;
|
||||
else
|
||||
goto found_device;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
Reference in New Issue
Block a user