cleanup style ... just because you use less spaces doesnt mean the resulting code is smaller
This commit is contained in:
parent
248d2220f9
commit
a421ba8203
@ -23,6 +23,7 @@
|
|||||||
#include "xregex.h"
|
#include "xregex.h"
|
||||||
|
|
||||||
#define DEV_PATH "/dev"
|
#define DEV_PATH "/dev"
|
||||||
|
#define MDEV_CONF "/etc/mdev.conf"
|
||||||
|
|
||||||
#include <busybox.h>
|
#include <busybox.h>
|
||||||
|
|
||||||
@ -49,7 +50,8 @@ static void make_device(char *path)
|
|||||||
|
|
||||||
device_name = strrchr(path, '/') + 1;
|
device_name = strrchr(path, '/') + 1;
|
||||||
type = strncmp(path+5, "block/", 6) ? S_IFCHR : S_IFBLK;
|
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 */
|
/* 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;
|
char *conf, *pos, *end;
|
||||||
|
|
||||||
/* mmap the config file */
|
/* 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);
|
len = lseek(fd, 0, SEEK_END);
|
||||||
conf = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
|
conf = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||||
if (conf) {
|
if (conf) {
|
||||||
@ -70,15 +72,19 @@ static void make_device(char *path)
|
|||||||
|
|
||||||
line++;
|
line++;
|
||||||
/* find end of this 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 */
|
/* Three fields: regex, uid:gid, mode */
|
||||||
for (field=3; field; field--) {
|
for (field=3; field; field--) {
|
||||||
/* Skip whitespace */
|
/* Skip whitespace */
|
||||||
while (pos<end && isspace(*pos)) pos++;
|
while (pos<end && isspace(*pos))
|
||||||
if (pos==end || *pos=='#') break;
|
pos++;
|
||||||
for (end2=pos;
|
if (pos==end || *pos=='#')
|
||||||
end2<end && !isspace(*end2) && *end2!='#'; end2++);
|
break;
|
||||||
|
for (end2=pos; end2<end && !isspace(*end2) && *end2!='#'; end2++)
|
||||||
|
;
|
||||||
|
|
||||||
switch (field) {
|
switch (field) {
|
||||||
/* Regex to match this device */
|
/* Regex to match this device */
|
||||||
case 3:
|
case 3:
|
||||||
@ -94,8 +100,7 @@ static void make_device(char *path)
|
|||||||
regfree(&match);
|
regfree(&match);
|
||||||
|
|
||||||
/* If not this device, skip rest of line */
|
/* If not this device, skip rest of line */
|
||||||
if(result || off.rm_so
|
if (result || off.rm_so || off.rm_eo!=strlen(device_name))
|
||||||
|| off.rm_eo!=strlen(device_name))
|
|
||||||
goto end_line;
|
goto end_line;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -106,15 +111,18 @@ static void make_device(char *path)
|
|||||||
char *s2;
|
char *s2;
|
||||||
|
|
||||||
/* Find : */
|
/* Find : */
|
||||||
for(s=pos;s<end2 && *s!=':';s++);
|
for(s=pos; s<end2 && *s!=':'; s++)
|
||||||
if(s==end2) goto end_line;
|
;
|
||||||
|
if (s == end2)
|
||||||
|
goto end_line;
|
||||||
|
|
||||||
/* Parse UID */
|
/* Parse UID */
|
||||||
uid = strtoul(pos,&s2,10);
|
uid = strtoul(pos,&s2,10);
|
||||||
if (s != s2) {
|
if (s != s2) {
|
||||||
struct passwd *pass;
|
struct passwd *pass;
|
||||||
pass = getpwnam(strndupa(pos,s-pos));
|
pass = getpwnam(strndupa(pos,s-pos));
|
||||||
if(!pass) goto end_line;
|
if (!pass)
|
||||||
|
goto end_line;
|
||||||
uid = pass->pw_uid;
|
uid = pass->pw_uid;
|
||||||
}
|
}
|
||||||
s++;
|
s++;
|
||||||
@ -123,7 +131,8 @@ static void make_device(char *path)
|
|||||||
if (end2 != s2) {
|
if (end2 != s2) {
|
||||||
struct group *grp;
|
struct group *grp;
|
||||||
grp = getgrnam(strndupa(s,end2-s));
|
grp = getgrnam(strndupa(s,end2-s));
|
||||||
if(!grp) goto end_line;
|
if (!grp)
|
||||||
|
goto end_line;
|
||||||
gid = grp->gr_gid;
|
gid = grp->gr_gid;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -132,7 +141,9 @@ static void make_device(char *path)
|
|||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
mode = strtoul(pos,&pos,8);
|
mode = strtoul(pos,&pos,8);
|
||||||
if(pos!=end2) goto end_line;
|
if (pos != end2)
|
||||||
|
goto end_line;
|
||||||
|
else
|
||||||
goto found_device;
|
goto found_device;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,7 +191,8 @@ static void find_dev(char *path)
|
|||||||
|
|
||||||
/* Skip "." and ".." (also skips hidden files, which is ok) */
|
/* 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) {
|
if (entry->d_type == DT_DIR) {
|
||||||
snprintf(path+len, PATH_MAX-len, "/%s", entry->d_name);
|
snprintf(path+len, PATH_MAX-len, "/%s", entry->d_name);
|
||||||
@ -214,7 +226,8 @@ int mdev_main(int argc, char *argv[])
|
|||||||
} else {
|
} else {
|
||||||
action = getenv("ACTION");
|
action = getenv("ACTION");
|
||||||
env_path = getenv("DEVPATH");
|
env_path = getenv("DEVPATH");
|
||||||
if (!action || !env_path) bb_show_usage();
|
if (!action || !env_path)
|
||||||
|
bb_show_usage();
|
||||||
|
|
||||||
if (!strcmp(action, "add")) {
|
if (!strcmp(action, "add")) {
|
||||||
sprintf(temp, "/sys%s", env_path);
|
sprintf(temp, "/sys%s", env_path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user