aboutsummaryrefslogtreecommitdiff
path: root/util-linux/mdev.c
diff options
context:
space:
mode:
Diffstat (limited to 'util-linux/mdev.c')
-rw-r--r--util-linux/mdev.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index a18e44835..b8c0090fa 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -1,7 +1,7 @@
1/* vi:set ts=4: 1/* vi:set ts=4:
2 * 2 *
3 * mdev - Mini udev for busybox 3 * mdev - Mini udev for busybox
4 * 4 *
5 * Copyright 2005 Rob Landley <rob@landley.net> 5 * Copyright 2005 Rob Landley <rob@landley.net>
6 * Copyright 2005 Frank Sorenson <frank@tuxrocks.com> 6 * Copyright 2005 Frank Sorenson <frank@tuxrocks.com>
7 * 7 *
@@ -38,21 +38,21 @@ static void make_device(char *path)
38 RESERVE_CONFIG_BUFFER(temp,PATH_MAX); 38 RESERVE_CONFIG_BUFFER(temp,PATH_MAX);
39 39
40 /* Try to read major/minor string */ 40 /* Try to read major/minor string */
41 41
42 snprintf(temp, PATH_MAX, "%s/dev", path); 42 snprintf(temp, PATH_MAX, "%s/dev", path);
43 fd = open(temp, O_RDONLY); 43 fd = open(temp, O_RDONLY);
44 len = read(fd, temp, PATH_MAX-1); 44 len = read(fd, temp, PATH_MAX-1);
45 if (len<1) goto end; 45 if (len<1) goto end;
46 close(fd); 46 close(fd);
47 47
48 /* Determine device name, type, major and minor */ 48 /* Determine device name, type, major and minor */
49 49
50 device_name = strrchr(path, '/') + 1; 50 device_name = strrchr(path, '/') + 1;
51 type = strncmp(path+5, "block/" ,6) ? S_IFCHR : S_IFBLK; 51 type = strncmp(path+5, "block/" ,6) ? S_IFCHR : S_IFBLK;
52 if(sscanf(temp, "%d:%d", &major, &minor) != 2) goto end; 52 if(sscanf(temp, "%d:%d", &major, &minor) != 2) goto end;
53 53
54 /* If we have a config file, look up permissions for this device */ 54 /* If we have a config file, look up permissions for this device */
55 55
56 if (ENABLE_FEATURE_MDEV_CONF) { 56 if (ENABLE_FEATURE_MDEV_CONF) {
57 char *conf,*pos,*end; 57 char *conf,*pos,*end;
58 58
@@ -67,7 +67,7 @@ static void make_device(char *path)
67 for (pos=conf;pos-conf<len;) { 67 for (pos=conf;pos-conf<len;) {
68 int field; 68 int field;
69 char *end2; 69 char *end2;
70 70
71 line++; 71 line++;
72 /* find end of this line */ 72 /* find end of this line */
73 for(end=pos;end-conf<len && *end!='\n';end++); 73 for(end=pos;end-conf<len && *end!='\n';end++);
@@ -88,11 +88,11 @@ static void make_device(char *path)
88 regmatch_t off; 88 regmatch_t off;
89 int result; 89 int result;
90 90
91 /* Is this it? */ 91 /* Is this it? */
92 xregcomp(&match,regex,REG_EXTENDED); 92 xregcomp(&match,regex,REG_EXTENDED);
93 result=regexec(&match,device_name,1,&off,0); 93 result=regexec(&match,device_name,1,&off,0);
94 regfree(&match); 94 regfree(&match);
95 95
96 /* If not this device, skip rest of line */ 96 /* If not this device, skip rest of line */
97 if(result || off.rm_so 97 if(result || off.rm_so
98 || off.rm_eo!=strlen(device_name)) 98 || off.rm_eo!=strlen(device_name))
@@ -159,7 +159,7 @@ found_device:
159 bb_perror_msg_and_die("mknod %s failed", temp); 159 bb_perror_msg_and_die("mknod %s failed", temp);
160 160
161 if (ENABLE_FEATURE_MDEV_CONF) chown(temp,uid,gid); 161 if (ENABLE_FEATURE_MDEV_CONF) chown(temp,uid,gid);
162 162
163end: 163end:
164 RELEASE_CONFIG_BUFFER(temp); 164 RELEASE_CONFIG_BUFFER(temp);
165} 165}
@@ -177,7 +177,7 @@ static void find_dev(char *path)
177 177
178 for (;;) { 178 for (;;) {
179 struct dirent *entry = readdir(dir); 179 struct dirent *entry = readdir(dir);
180 180
181 if (!entry) break; 181 if (!entry) break;
182 182
183 /* Skip "." and ".." (also skips hidden files, which is ok) */ 183 /* Skip "." and ".." (also skips hidden files, which is ok) */
@@ -189,12 +189,12 @@ static void find_dev(char *path)
189 find_dev(path); 189 find_dev(path);
190 path[len] = 0; 190 path[len] = 0;
191 } 191 }
192 192
193 /* If there's a dev entry, mknod it */ 193 /* If there's a dev entry, mknod it */
194 194
195 if (!strcmp(entry->d_name, "dev")) make_device(path); 195 if (!strcmp(entry->d_name, "dev")) make_device(path);
196 } 196 }
197 197
198 closedir(dir); 198 closedir(dir);
199} 199}
200 200
@@ -205,7 +205,7 @@ int mdev_main(int argc, char *argv[])
205 RESERVE_CONFIG_BUFFER(temp,PATH_MAX); 205 RESERVE_CONFIG_BUFFER(temp,PATH_MAX);
206 206
207 /* Scan */ 207 /* Scan */
208 208
209 if (argc == 2 && !strcmp(argv[1],"-s")) { 209 if (argc == 2 && !strcmp(argv[1],"-s")) {
210 strcpy(temp,"/sys/block"); 210 strcpy(temp,"/sys/block");
211 find_dev(temp); 211 find_dev(temp);
@@ -218,7 +218,7 @@ int mdev_main(int argc, char *argv[])
218 action = getenv("ACTION"); 218 action = getenv("ACTION");
219 env_path = getenv("DEVPATH"); 219 env_path = getenv("DEVPATH");
220 if (!action || !env_path) bb_show_usage(); 220 if (!action || !env_path) bb_show_usage();
221 221
222 if (!strcmp(action, "add")) { 222 if (!strcmp(action, "add")) {
223 sprintf(temp, "/sys%s", env_path); 223 sprintf(temp, "/sys%s", env_path);
224 make_device(temp); 224 make_device(temp);