diff options
author | Eric Andersen <andersen@codepoet.org> | 2005-07-18 09:28:36 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2005-07-18 09:28:36 +0000 |
commit | e8614dbcd75915e6bf5badb8669efc04e62453f8 (patch) | |
tree | f943b6891fccf9c5c5f0d672dee008c28ff61b8a /miscutils/makedevs.c | |
parent | 10427ab5282582f407fab329638c187ae6b0c244 (diff) | |
download | busybox-w32-e8614dbcd75915e6bf5badb8669efc04e62453f8.tar.gz busybox-w32-e8614dbcd75915e6bf5badb8669efc04e62453f8.tar.bz2 busybox-w32-e8614dbcd75915e6bf5badb8669efc04e62453f8.zip |
Fixup device table based makedevs so it actually works
Diffstat (limited to 'miscutils/makedevs.c')
-rw-r--r-- | miscutils/makedevs.c | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c index 2c9a0a9af..eb3e3680d 100644 --- a/miscutils/makedevs.c +++ b/miscutils/makedevs.c | |||
@@ -91,35 +91,42 @@ int makedevs_main(int argc, char **argv) | |||
91 | * | 91 | * |
92 | */ | 92 | */ |
93 | 93 | ||
94 | static const struct option makedevs_long_options[] = { | ||
95 | {"root", 1, NULL, 'r'}, | ||
96 | {0, 0, 0, 0} | ||
97 | }; | ||
98 | |||
99 | extern int makedevs_main(int argc, char **argv) | 94 | extern int makedevs_main(int argc, char **argv) |
100 | { | 95 | { |
101 | FILE *table; | ||
102 | int opt; | 96 | int opt; |
103 | char *rootdir = "./"; | 97 | FILE *table = stdin; |
104 | char *line; | 98 | char *rootdir = NULL; |
99 | char *line = NULL; | ||
100 | int linenum = 0; | ||
105 | int ret = EXIT_SUCCESS; | 101 | int ret = EXIT_SUCCESS; |
106 | 102 | ||
107 | bb_opt_complementaly = "d~r"; | 103 | while ((opt = getopt(argc, argv, "d:")) != -1) { |
108 | bb_applet_long_options = makedevs_long_options; | 104 | switch(opt) { |
109 | opt = bb_getopt_ulflags(argc, argv, "d:r:", &rootdir, &rootdir); | 105 | case 'd': |
106 | table = bb_xfopen((line=optarg), "r"); | ||
107 | break; | ||
108 | default: | ||
109 | bb_show_usage(); | ||
110 | } | ||
111 | } | ||
110 | 112 | ||
111 | if (optind + 1 == argc) { | 113 | if (optind >= argc || (rootdir=argv[optind])==NULL) { |
112 | table = bb_xfopen(argv[optind], "r"); | 114 | bb_error_msg_and_die("root directory not speficied"); |
113 | } else { | ||
114 | table = stdin; | ||
115 | } | 115 | } |
116 | 116 | ||
117 | if (chdir(rootdir) == -1) { | 117 | if (chdir(rootdir) != 0) { |
118 | bb_perror_msg_and_die("Couldnt chdor to %s", rootdir); | 118 | bb_perror_msg_and_die("Couldnt chdir to %s", rootdir); |
119 | } | 119 | } |
120 | 120 | ||
121 | umask(0); | 121 | umask(0); |
122 | 122 | ||
123 | printf("rootdir=%s\n", rootdir); | ||
124 | if (line) { | ||
125 | printf("table='%s'\n", line); | ||
126 | } else { | ||
127 | printf("table=<stdin>\n"); | ||
128 | } | ||
129 | |||
123 | while ((line = bb_get_chomped_line_from_file(table))) { | 130 | while ((line = bb_get_chomped_line_from_file(table))) { |
124 | char type; | 131 | char type; |
125 | unsigned int mode = 0755; | 132 | unsigned int mode = 0755; |
@@ -135,11 +142,16 @@ extern int makedevs_main(int argc, char **argv) | |||
135 | uid_t uid; | 142 | uid_t uid; |
136 | gid_t gid; | 143 | gid_t gid; |
137 | 144 | ||
145 | linenum++; | ||
146 | |||
138 | if ((2 > sscanf(line, "%40s %c %o %40s %40s %u %u %u %u %u", name, | 147 | if ((2 > sscanf(line, "%40s %c %o %40s %40s %u %u %u %u %u", name, |
139 | &type, &mode, user, group, &major, | 148 | &type, &mode, user, group, &major, |
140 | &minor, &start, &increment, &count)) || | 149 | &minor, &start, &increment, &count)) || |
141 | ((major | minor | start | count | increment) > 255)) { | 150 | ((major | minor | start | count | increment) > 255)) |
142 | bb_error_msg("Ignoring invalid line\n%s\n", line); | 151 | { |
152 | if (*line=='\0' || *line=='#' || isspace(*line)) | ||
153 | continue; | ||
154 | bb_error_msg("line %d invalid: '%s'\n", linenum, line); | ||
143 | ret = EXIT_FAILURE; | 155 | ret = EXIT_FAILURE; |
144 | continue; | 156 | continue; |
145 | } | 157 | } |
@@ -159,9 +171,9 @@ extern int makedevs_main(int argc, char **argv) | |||
159 | full_name = concat_path_file(rootdir, name); | 171 | full_name = concat_path_file(rootdir, name); |
160 | 172 | ||
161 | if (type == 'd') { | 173 | if (type == 'd') { |
162 | bb_make_directory(full_name, mode | S_IFDIR, 0); | 174 | bb_make_directory(full_name, mode | S_IFDIR, FILEUTILS_RECUR); |
163 | if (chown(full_name, uid, gid) == -1) { | 175 | if (chown(full_name, uid, gid) == -1) { |
164 | bb_perror_msg("chown failed for %s", full_name); | 176 | bb_perror_msg("line %d: chown failed for %s", linenum, full_name); |
165 | ret = EXIT_FAILURE; | 177 | ret = EXIT_FAILURE; |
166 | goto loop; | 178 | goto loop; |
167 | } | 179 | } |
@@ -177,7 +189,7 @@ extern int makedevs_main(int argc, char **argv) | |||
177 | else if (type == 'b') { | 189 | else if (type == 'b') { |
178 | mode |= S_IFBLK; | 190 | mode |= S_IFBLK; |
179 | } else { | 191 | } else { |
180 | bb_error_msg("Unsupported file type %c", type); | 192 | bb_error_msg("line %d: Unsupported file type %c", linenum, type); |
181 | ret = EXIT_FAILURE; | 193 | ret = EXIT_FAILURE; |
182 | goto loop; | 194 | goto loop; |
183 | } | 195 | } |
@@ -191,11 +203,11 @@ extern int makedevs_main(int argc, char **argv) | |||
191 | sprintf(full_name_inc, "%s%d", full_name, i); | 203 | sprintf(full_name_inc, "%s%d", full_name, i); |
192 | rdev = (major << 8) + minor + (i * increment - start); | 204 | rdev = (major << 8) + minor + (i * increment - start); |
193 | if (mknod(full_name_inc, mode, rdev) == -1) { | 205 | if (mknod(full_name_inc, mode, rdev) == -1) { |
194 | bb_perror_msg("Couldnt create node %s", full_name_inc); | 206 | bb_perror_msg("line %d: Couldnt create node %s", linenum, full_name_inc); |
195 | ret = EXIT_FAILURE; | 207 | ret = EXIT_FAILURE; |
196 | } | 208 | } |
197 | else if (chown(full_name_inc, uid, gid) == -1) { | 209 | else if (chown(full_name_inc, uid, gid) == -1) { |
198 | bb_perror_msg("chown failed for %s", full_name_inc); | 210 | bb_perror_msg("line %d: chown failed for %s", linenum, full_name_inc); |
199 | ret = EXIT_FAILURE; | 211 | ret = EXIT_FAILURE; |
200 | } | 212 | } |
201 | } | 213 | } |
@@ -203,11 +215,11 @@ extern int makedevs_main(int argc, char **argv) | |||
203 | } else { | 215 | } else { |
204 | rdev = (major << 8) + minor; | 216 | rdev = (major << 8) + minor; |
205 | if (mknod(full_name, mode, rdev) == -1) { | 217 | if (mknod(full_name, mode, rdev) == -1) { |
206 | bb_perror_msg("Couldnt create node %s", full_name); | 218 | bb_perror_msg("line %d: Couldnt create node %s", linenum, full_name); |
207 | ret = EXIT_FAILURE; | 219 | ret = EXIT_FAILURE; |
208 | } | 220 | } |
209 | else if (chown(full_name, uid, gid) == -1) { | 221 | else if (chown(full_name, uid, gid) == -1) { |
210 | bb_perror_msg("chown failed for %s", full_name); | 222 | bb_perror_msg("line %d: chown failed for %s", linenum, full_name); |
211 | ret = EXIT_FAILURE; | 223 | ret = EXIT_FAILURE; |
212 | } | 224 | } |
213 | } | 225 | } |
@@ -220,6 +232,7 @@ loop: | |||
220 | 232 | ||
221 | return 0; | 233 | return 0; |
222 | } | 234 | } |
235 | |||
223 | #else | 236 | #else |
224 | # error makdedevs configuration error, either leaf or table must be selected | 237 | # error makdedevs configuration error, either leaf or table must be selected |
225 | #endif | 238 | #endif |