Contents of /trunk/mkinitrd-magellan/klibc/usr/utils/mkfifo.c
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1203 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1203 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
1 | #include <sys/stat.h> |
2 | #include <sys/types.h> |
3 | #include <errno.h> |
4 | #include <fcntl.h> |
5 | #include <signal.h> |
6 | #include <stdio.h> |
7 | #include <stdlib.h> |
8 | #include <string.h> |
9 | #include <unistd.h> |
10 | |
11 | #include "file_mode.h" |
12 | |
13 | static mode_t leaf_mode; |
14 | |
15 | char *progname; |
16 | |
17 | static int make_fifo(char *dir) |
18 | { |
19 | if (mkfifo(dir, leaf_mode)) { |
20 | /* |
21 | * We failed, remove the directory we created. |
22 | */ |
23 | fprintf(stderr, "%s: ", progname); |
24 | perror(dir); |
25 | return -1; |
26 | } |
27 | return 0; |
28 | } |
29 | |
30 | int main(int argc, char *argv[]) |
31 | { |
32 | int c, ret = 0; |
33 | mode_t saved_umask; |
34 | |
35 | progname = argv[0]; |
36 | |
37 | saved_umask = umask(0); |
38 | leaf_mode = |
39 | (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) & |
40 | ~saved_umask; |
41 | |
42 | do { |
43 | c = getopt(argc, argv, "m:"); |
44 | if (c == EOF) |
45 | break; |
46 | switch (c) { |
47 | case 'm': |
48 | leaf_mode = |
49 | parse_file_mode(optarg, leaf_mode, saved_umask); |
50 | break; |
51 | |
52 | case '?': |
53 | fprintf(stderr, "%s: invalid option -%c\n", |
54 | progname, optopt); |
55 | exit(1); |
56 | } |
57 | } while (1); |
58 | |
59 | if (optind == argc) { |
60 | fprintf(stderr, "Usage: %s [-m mode] file...\n", progname); |
61 | exit(1); |
62 | } |
63 | |
64 | while (optind < argc) { |
65 | if (make_fifo(argv[optind])) |
66 | ret = 255; /* seems to be what gnu mkdir does */ |
67 | optind++; |
68 | } |
69 | |
70 | return ret; |
71 | } |