summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/makedevs
diff options
context:
space:
mode:
authorHerb Kuta <herb.kuta@lge.com>2013-12-09 18:10:55 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-12-10 17:42:42 +0000
commit2a3119efb1277631bc8df9ebaa5cc2196701a7cf (patch)
tree4aedda3a0b1fb09f143961da3885e0e84ccc1909 /meta/recipes-devtools/makedevs
parent7b2be6012e74c10f50d8a537743f693e86936451 (diff)
downloadpoky-2a3119efb1277631bc8df9ebaa5cc2196701a7cf.tar.gz
makedevs: Add trace option and fix permissions on files if they already exist
* update version to 1.0.1 (From OE-Core rev: ce460dd1b9c137b00d1142801b133c083ce55e74) Signed-off-by: Herb Kuta <herb.kuta@lge.com> Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/makedevs')
-rw-r--r--meta/recipes-devtools/makedevs/makedevs/COPYING.patch (renamed from meta/recipes-devtools/makedevs/makedevs-1.0.0/COPYING.patch)0
-rw-r--r--meta/recipes-devtools/makedevs/makedevs/makedevs.c (renamed from meta/recipes-devtools/makedevs/makedevs-1.0.0/makedevs.c)120
-rw-r--r--meta/recipes-devtools/makedevs/makedevs_1.0.1.bb (renamed from meta/recipes-devtools/makedevs/makedevs_1.0.0.bb)5
3 files changed, 88 insertions, 37 deletions
diff --git a/meta/recipes-devtools/makedevs/makedevs-1.0.0/COPYING.patch b/meta/recipes-devtools/makedevs/makedevs/COPYING.patch
index 3a8902b97a..3a8902b97a 100644
--- a/meta/recipes-devtools/makedevs/makedevs-1.0.0/COPYING.patch
+++ b/meta/recipes-devtools/makedevs/makedevs/COPYING.patch
diff --git a/meta/recipes-devtools/makedevs/makedevs-1.0.0/makedevs.c b/meta/recipes-devtools/makedevs/makedevs/makedevs.c
index 003d4c3fa4..771f33ef5a 100644
--- a/meta/recipes-devtools/makedevs/makedevs-1.0.0/makedevs.c
+++ b/meta/recipes-devtools/makedevs/makedevs/makedevs.c
@@ -21,16 +21,18 @@
21#ifndef PATH_MAX 21#ifndef PATH_MAX
22#define PATH_MAX 4096 22#define PATH_MAX 4096
23#endif 23#endif
24#define VERSION "1.0.1"
24 25
25/* These are all stolen from busybox's libbb to make 26/* These are all stolen from busybox's libbb to make
26 * error handling simpler (and since I maintain busybox, 27 * error handling simpler (and since I maintain busybox,
27 * I'm rather partial to these for error handling). 28 * I'm rather partial to these for error handling).
28 * -Erik 29 * -Erik
29 */ 30 */
30static const char *const app_name = "makedevs"; 31static const char *const app_name = "makedevs";
31static const char *const memory_exhausted = "memory exhausted"; 32static const char *const memory_exhausted = "memory exhausted";
32static char default_rootdir[]="."; 33static char default_rootdir[]=".";
33static char *rootdir = default_rootdir; 34static char *rootdir = default_rootdir;
35static int trace = 0;
34 36
35struct name_id { 37struct name_id {
36 char name[MAX_NAME_LEN+1]; 38 char name[MAX_NAME_LEN+1];
@@ -224,56 +226,95 @@ static void free_list(struct name_id *list)
224 } 226 }
225} 227}
226 228
227static void add_new_directory(char *name, char *path, 229static void add_new_directory(char *name, char *path,
228 unsigned long uid, unsigned long gid, unsigned long mode) 230 unsigned long uid, unsigned long gid, unsigned long mode)
229{ 231{
230 mkdir(path, mode); 232 if (trace)
233 fprintf(stderr, "Directory: %s %s UID: %ld GID %ld MODE: %04lo", path, name, uid, gid, mode);
234
235 if (mkdir(path, mode) < 0) {
236 if (EEXIST == errno) {
237 /* Unconditionally apply the mode setting to the existing directory.
238 * XXX should output something when trace */
239 chmod(path, mode & ~S_IFMT);
240 }
241 }
242 if (trace)
243 putc('\n', stderr);
231 chown(path, uid, gid); 244 chown(path, uid, gid);
232// printf("Directory: %s %s UID: %ld GID %ld MODE: %04lo\n", path, name, uid, gid, mode);
233} 245}
234 246
235static void add_new_device(char *name, char *path, unsigned long uid, 247static void add_new_device(char *name, char *path, unsigned long uid,
236 unsigned long gid, unsigned long mode, dev_t rdev) 248 unsigned long gid, unsigned long mode, dev_t rdev)
237{ 249{
238 int status; 250 int status;
239 struct stat sb; 251 struct stat sb;
240 252
253 if (trace) {
254 fprintf(stderr, "Device: %s %s UID: %ld GID: %ld MODE: %04lo MAJOR: %d MINOR: %d",
255 path, name, uid, gid, mode, (short)(rdev >> 8), (short)(rdev & 0xff));
256 }
257
241 memset(&sb, 0, sizeof(struct stat)); 258 memset(&sb, 0, sizeof(struct stat));
242 status = lstat(path, &sb); 259 status = lstat(path, &sb);
243
244 if (status >= 0) { 260 if (status >= 0) {
245 /* It is ok for some types of files to not exit on disk (such as 261 /* It is ok for some types of files to not exit on disk (such as
246 * device nodes), but if they _do_ exist the specified mode had 262 * device nodes), but if they _do_ exist, the file type bits had
247 * better match the actual file or strange things will happen.... */ 263 * better match those of the actual file or strange things will happen... */
248 if ((mode & S_IFMT) != (sb.st_mode & S_IFMT)) 264 if ((mode & S_IFMT) != (sb.st_mode & S_IFMT)) {
249 error_msg_and_die("%s: file type does not match specified type!", path); 265 if (trace)
266 putc('\n', stderr);
267 error_msg_and_die("%s: existing file (04%o) type does not match specified file type (04%lo)!",
268 path, (sb.st_mode & S_IFMT), (mode & S_IFMT));
269 }
270 if (mode != sb.st_mode) {
271 if (trace)
272 fprintf(stderr, " -- applying new mode 04%lo (old was 04%o)\n", mode & ~S_IFMT, sb.st_mode & ~S_IFMT);
273 /* Apply the mode setting to the existing device node */
274 chmod(path, mode & ~S_IFMT);
275 }
276 else {
277 if (trace)
278 fprintf(stderr, " -- extraneous entry in table\n", path);
279 }
280 }
281 else {
282 mknod(path, mode, rdev);
283 if (trace)
284 putc('\n', stderr);
285
250 } 286 }
251 287
252 mknod(path, mode, rdev);
253 chown(path, uid, gid); 288 chown(path, uid, gid);
254// printf("Device: %s %s UID: %ld GID: %ld MODE: %04lo MAJOR: %d MINOR: %d\n",
255// path, name, uid, gid, mode, (short)(rdev >> 8), (short)(rdev & 0xff));
256} 289}
257 290
258static void add_new_file(char *name, char *path, unsigned long uid, 291static void add_new_file(char *name, char *path, unsigned long uid,
259 unsigned long gid, unsigned long mode) 292 unsigned long gid, unsigned long mode)
260{ 293{
294 if (trace) {
295 fprintf(stderr, "File: %s %s UID: %ld GID: %ld MODE: %04lo\n",
296 path, name, gid, uid, mode);
297 }
298
261 int fd = open(path,O_CREAT | O_WRONLY, mode); 299 int fd = open(path,O_CREAT | O_WRONLY, mode);
262 if (fd < 0) { 300 if (fd < 0) {
263 error_msg_and_die("%s: file can not be created!", path); 301 error_msg_and_die("%s: file can not be created!", path);
264 } else { 302 } else {
265 close(fd); 303 close(fd);
266 } 304 }
267 chmod(path, mode); 305 chmod(path, mode);
268 chown(path, uid, gid); 306 chown(path, uid, gid);
269// printf("File: %s %s UID: %ld GID: %ld MODE: %04lo\n",
270// path, name, gid, uid, mode);
271} 307}
272 308
273 309
274static void add_new_fifo(char *name, char *path, unsigned long uid, 310static void add_new_fifo(char *name, char *path, unsigned long uid,
275 unsigned long gid, unsigned long mode) 311 unsigned long gid, unsigned long mode)
276{ 312{
313 if (trace) {
314 printf("Fifo: %s %s UID: %ld GID: %ld MODE: %04lo\n",
315 path, name, gid, uid, mode);
316 }
317
277 int status; 318 int status;
278 struct stat sb; 319 struct stat sb;
279 320
@@ -289,8 +330,6 @@ static void add_new_fifo(char *name, char *path, unsigned long uid,
289 error_msg_and_die("%s: file can not be created with mknod!", path); 330 error_msg_and_die("%s: file can not be created with mknod!", path);
290 } 331 }
291 chown(path, uid, gid); 332 chown(path, uid, gid);
292// printf("File: %s %s UID: %ld GID: %ld MODE: %04lo\n",
293// path, name, gid, uid, mode);
294} 333}
295 334
296 335
@@ -299,7 +338,7 @@ static void add_new_fifo(char *name, char *path, unsigned long uid,
299 /dev/mem c 640 0 0 1 1 0 0 - 338 /dev/mem c 640 0 0 1 1 0 0 -
300 /dev/zero c 644 root root 1 5 - - - 339 /dev/zero c 644 root root 1 5 - - -
301 340
302 type can be one of: 341 type can be one of:
303 f A regular file 342 f A regular file
304 d Directory 343 d Directory
305 c Character special device file 344 c Character special device file
@@ -323,8 +362,9 @@ static int interpret_table_entry(char *line)
323 362
324 if (0 > sscanf(line, "%40s %c %lo %40s %40s %lu %lu %lu %lu %lu", path, 363 if (0 > sscanf(line, "%40s %c %lo %40s %40s %lu %lu %lu %lu %lu", path,
325 &type, &mode, usr_buf, grp_buf, &major, &minor, &start, 364 &type, &mode, usr_buf, grp_buf, &major, &minor, &start,
326 &increment, &count)) 365 &increment, &count))
327 { 366 {
367 fprintf(stderr, "%s: sscanf returned < 0 for line '%s'\n", app_name, line);
328 return 1; 368 return 1;
329 } 369 }
330 370
@@ -335,8 +375,10 @@ static int interpret_table_entry(char *line)
335 error_msg_and_die("Device table entries require absolute paths"); 375 error_msg_and_die("Device table entries require absolute paths");
336 } 376 }
337 name = xstrdup(path + 1); 377 name = xstrdup(path + 1);
378 /* prefix path with rootdir */
338 sprintf(path, "%s/%s", rootdir, name); 379 sprintf(path, "%s/%s", rootdir, name);
339 380
381 /* XXX Why is name passed into all of the add_new_*() routines? */
340 switch (type) { 382 switch (type) {
341 case 'd': 383 case 'd':
342 mode |= S_IFDIR; 384 mode |= S_IFDIR;
@@ -361,13 +403,14 @@ static int interpret_table_entry(char *line)
361 for (i = start; i < start + count; i++) { 403 for (i = start; i < start + count; i++) {
362 sprintf(buf, "%s%d", name, i); 404 sprintf(buf, "%s%d", name, i);
363 sprintf(path, "%s/%s%d", rootdir, name, i); 405 sprintf(path, "%s/%s%d", rootdir, name, i);
364 /* FIXME: MKDEV uses illicit insider knowledge of kernel 406 /* FIXME: MKDEV uses illicit insider knowledge of kernel
365 * major/minor representation... */ 407 * major/minor representation... */
366 rdev = MKDEV(major, minor + (i - start) * increment); 408 rdev = MKDEV(major, minor + (i - start) * increment);
409 sprintf(path, "%s/%s\0", rootdir, buf);
367 add_new_device(buf, path, uid, gid, mode, rdev); 410 add_new_device(buf, path, uid, gid, mode, rdev);
368 } 411 }
369 } else { 412 } else {
370 /* FIXME: MKDEV uses illicit insider knowledge of kernel 413 /* FIXME: MKDEV uses illicit insider knowledge of kernel
371 * major/minor representation... */ 414 * major/minor representation... */
372 dev_t rdev = MKDEV(major, minor); 415 dev_t rdev = MKDEV(major, minor);
373 add_new_device(name, path, uid, gid, mode, rdev); 416 add_new_device(name, path, uid, gid, mode, rdev);
@@ -391,8 +434,9 @@ static void parse_device_table(FILE * file)
391 error_msg_and_die(memory_exhausted); 434 error_msg_and_die(memory_exhausted);
392 } 435 }
393 /* Looks ok so far. The general plan now is to read in one 436 /* Looks ok so far. The general plan now is to read in one
394 * line at a time, check for leading comment delimiters ('#'), 437 * line at a time, trim off leading and trailing whitespace,
395 * then try and parse the line as a device table. If we fail 438 * check for leading comment delimiters ('#') or a blank line,
439 * then try and parse the line as a device table entry. If we fail
396 * to parse things, try and help the poor fool to fix their 440 * to parse things, try and help the poor fool to fix their
397 * device table with a useful error msg... */ 441 * device table with a useful error msg... */
398 442
@@ -406,8 +450,8 @@ static void parse_device_table(FILE * file)
406 /* trim leading whitespace */ 450 /* trim leading whitespace */
407 memmove(line, &line[strspn(line, " \n\r\t\v")], len + 1); 451 memmove(line, &line[strspn(line, " \n\r\t\v")], len + 1);
408 452
409 /* If this is NOT a comment line, try to interpret it */ 453 /* If this is NOT a comment or an empty line, try to interpret it */
410 if (*line != '#') interpret_table_entry(line); 454 if (*line != '#' && *line != '\0') interpret_table_entry(line);
411 } 455 }
412 456
413 if (line) 457 if (line)
@@ -434,6 +478,7 @@ static int parse_devtable(FILE * devtable)
434static struct option long_options[] = { 478static struct option long_options[] = {
435 {"root", 1, NULL, 'r'}, 479 {"root", 1, NULL, 'r'},
436 {"help", 0, NULL, 'h'}, 480 {"help", 0, NULL, 'h'},
481 {"trace", 0, NULL, 't'},
437 {"version", 0, NULL, 'v'}, 482 {"version", 0, NULL, 'v'},
438 {"devtable", 1, NULL, 'D'}, 483 {"devtable", 1, NULL, 'D'},
439 {NULL, 0, NULL, 0} 484 {NULL, 0, NULL, 0}
@@ -446,11 +491,10 @@ static char *helptext =
446 " -r, -d, --root=DIR Build filesystem from directory DIR (default: cwd)\n" 491 " -r, -d, --root=DIR Build filesystem from directory DIR (default: cwd)\n"
447 " -D, --devtable=FILE Use the named FILE as a device table file\n" 492 " -D, --devtable=FILE Use the named FILE as a device table file\n"
448 " -h, --help Display this help text\n" 493 " -h, --help Display this help text\n"
494 " -t, --trace Be verbose\n"
449 " -v, --version Display version information\n\n"; 495 " -v, --version Display version information\n\n";
450 496
451 497
452static char *revtext = "$Revision: 0.1 $";
453
454int main(int argc, char **argv) 498int main(int argc, char **argv)
455{ 499{
456 int c, opt; 500 int c, opt;
@@ -470,7 +514,7 @@ int main(int argc, char **argv)
470 exit(1); 514 exit(1);
471 } 515 }
472 516
473 while ((opt = getopt_long(argc, argv, "D:d:r:qhv", 517 while ((opt = getopt_long(argc, argv, "D:d:r:htv",
474 long_options, &c)) >= 0) { 518 long_options, &c)) >= 0) {
475 switch (opt) { 519 switch (opt) {
476 case 'D': 520 case 'D':
@@ -493,12 +537,20 @@ int main(int argc, char **argv)
493 } else { 537 } else {
494 closedir(dir); 538 closedir(dir);
495 } 539 }
496 rootdir = xstrdup(optarg); 540 /* If "/" is specified, use "" because rootdir is always prepended to a
541 * string that starts with "/" */
542 if (0 == strcmp(optarg, "/"))
543 rootdir = xstrdup("");
544 else
545 rootdir = xstrdup(optarg);
546 break;
547
548 case 't':
549 trace = 1;
497 break; 550 break;
498 551
499 case 'v': 552 case 'v':
500 printf("makedevs revision %.*s\n", 553 printf("%s: %s\n", app_name, VERSION);
501 (int) strlen(revtext) - 13, revtext + 11);
502 exit(0); 554 exit(0);
503 default: 555 default:
504 fprintf(stderr, helptext); 556 fprintf(stderr, helptext);
diff --git a/meta/recipes-devtools/makedevs/makedevs_1.0.0.bb b/meta/recipes-devtools/makedevs/makedevs_1.0.1.bb
index 17b9fcec03..6aa75a8743 100644
--- a/meta/recipes-devtools/makedevs/makedevs_1.0.0.bb
+++ b/meta/recipes-devtools/makedevs/makedevs_1.0.1.bb
@@ -4,7 +4,6 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=393a5ca445f6965873eca0259a17f833"
4SECTION = "base" 4SECTION = "base"
5SRC_URI = "file://makedevs.c \ 5SRC_URI = "file://makedevs.c \
6 file://COPYING.patch" 6 file://COPYING.patch"
7PR = "r7"
8 7
9FILES_${PN}_append_class-nativesdk = " ${datadir}" 8FILES_${PN}_append_class-nativesdk = " ${datadir}"
10 9
@@ -22,8 +21,8 @@ do_install() {
22} 21}
23 22
24do_install_append_class-nativesdk() { 23do_install_append_class-nativesdk() {
25 install -d ${D}${datadir} 24 install -d ${D}${datadir}
26 install -m 644 ${COREBASE}/meta/files/device_table-minimal.txt ${D}${datadir}/ 25 install -m 644 ${COREBASE}/meta/files/device_table-minimal.txt ${D}${datadir}/
27} 26}
28 27
29BBCLASSEXTEND = "native nativesdk" 28BBCLASSEXTEND = "native nativesdk"