aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-08-03 22:14:02 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-08-03 22:14:02 +0000
commitb2dc913527f2cb9a4590fe5e553bcc2c456007e0 (patch)
treed5fc65f660764c05f9a0c95ae2dccdeb61383da9
parent7ce47e698e247acfa3737281ab539eaa1c2787c7 (diff)
downloadbusybox-w32-b2dc913527f2cb9a4590fe5e553bcc2c456007e0.tar.gz
busybox-w32-b2dc913527f2cb9a4590fe5e553bcc2c456007e0.tar.bz2
busybox-w32-b2dc913527f2cb9a4590fe5e553bcc2c456007e0.zip
makedevs: shrink by Vladimir
function old new delta makedevs_main 1071 1049 -22 packed_usage 24744 24708 -36
-rw-r--r--miscutils/makedevs.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c
index 91da16924..be080552b 100644
--- a/miscutils/makedevs.c
+++ b/miscutils/makedevs.c
@@ -15,7 +15,7 @@ makedevs NAME TYPE MAJOR MINOR FIRST LAST [s]
15TYPEs: 15TYPEs:
16b Block device 16b Block device
17c Character device 17c Character device
18p FIFO 18f FIFO
19 19
20FIRST..LAST specify numbers appended to NAME. 20FIRST..LAST specify numbers appended to NAME.
21If 's' is the last argument, the base device is created as well. 21If 's' is the last argument, the base device is created as well.
@@ -82,28 +82,27 @@ int makedevs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
82int makedevs_main(int argc UNUSED_PARAM, char **argv) 82int makedevs_main(int argc UNUSED_PARAM, char **argv)
83{ 83{
84 parser_t *parser; 84 parser_t *parser;
85 char *rootdir = NULL;
86 char *line = (char *)"-"; 85 char *line = (char *)"-";
87 int linenum;
88 int ret = EXIT_SUCCESS; 86 int ret = EXIT_SUCCESS;
89 87
90 opt_complementary = "=1"; /* exactly one param */ 88 opt_complementary = "=1"; /* exactly one param */
91 getopt32(argv, "d:", &line); 89 getopt32(argv, "d:", &line);
92 rootdir = argv[optind]; 90 argv += optind;
93 parser = config_open(line);
94 91
95 xchdir(rootdir); 92 xchdir(*argv); /* ensure root dir exists */
96 93
97 umask(0); 94 umask(0);
98 95
99 printf("rootdir=%s\n", rootdir); 96 printf("rootdir=%s\ntable=", *argv);
100 if (NOT_LONE_DASH(line)) { 97 if (NOT_LONE_DASH(line)) {
101 printf("table='%s'\n", line); 98 printf("'%s'\n", line);
102 } else { 99 } else {
103 printf("table=<stdin>\n"); 100 puts("<stdin>");
104 } 101 }
105 102
103 parser = config_open(line);
106 while (config_read(parser, &line, 1, 1, "# \t", PARSE_NORMAL)) { 104 while (config_read(parser, &line, 1, 1, "# \t", PARSE_NORMAL)) {
105 int linenum;
107 char type; 106 char type;
108 unsigned mode = 0755; 107 unsigned mode = 0755;
109 unsigned major = 0; 108 unsigned major = 0;
@@ -114,7 +113,7 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv)
114 char name[41]; 113 char name[41];
115 char user[41]; 114 char user[41];
116 char group[41]; 115 char group[41];
117 char *full_name; 116 char *full_name = name;
118 uid_t uid; 117 uid_t uid;
119 gid_t gid; 118 gid_t gid;
120 119
@@ -132,7 +131,10 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv)
132 131
133 gid = (*group) ? get_ug_id(group, xgroup2gid) : getgid(); 132 gid = (*group) ? get_ug_id(group, xgroup2gid) : getgid();
134 uid = (*user) ? get_ug_id(user, xuname2uid) : getuid(); 133 uid = (*user) ? get_ug_id(user, xuname2uid) : getuid();
135 full_name = concat_path_file(rootdir, name); 134 /* We are already in the right root dir,
135 * so make absolute paths relative */
136 if ('/' == *full_name)
137 full_name++;
136 138
137 if (type == 'd') { 139 if (type == 'd') {
138 bb_make_directory(full_name, mode | S_IFDIR, FILEUTILS_RECUR); 140 bb_make_directory(full_name, mode | S_IFDIR, FILEUTILS_RECUR);
@@ -140,20 +142,20 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv)
140 chown_fail: 142 chown_fail:
141 bb_perror_msg("line %d: can't chown %s", linenum, full_name); 143 bb_perror_msg("line %d: can't chown %s", linenum, full_name);
142 ret = EXIT_FAILURE; 144 ret = EXIT_FAILURE;
143 goto loop; 145 continue;
144 } 146 }
145 if (chmod(full_name, mode) < 0) { 147 if (chmod(full_name, mode) < 0) {
146 chmod_fail: 148 chmod_fail:
147 bb_perror_msg("line %d: can't chmod %s", linenum, full_name); 149 bb_perror_msg("line %d: can't chmod %s", linenum, full_name);
148 ret = EXIT_FAILURE; 150 ret = EXIT_FAILURE;
149 goto loop; 151 continue;
150 } 152 }
151 } else if (type == 'f') { 153 } else if (type == 'f') {
152 struct stat st; 154 struct stat st;
153 if ((stat(full_name, &st) < 0 || !S_ISREG(st.st_mode))) { 155 if ((stat(full_name, &st) < 0 || !S_ISREG(st.st_mode))) {
154 bb_perror_msg("line %d: regular file '%s' does not exist", linenum, full_name); 156 bb_perror_msg("line %d: regular file '%s' does not exist", linenum, full_name);
155 ret = EXIT_FAILURE; 157 ret = EXIT_FAILURE;
156 goto loop; 158 continue;
157 } 159 }
158 if (chown(full_name, uid, gid) < 0) 160 if (chown(full_name, uid, gid) < 0)
159 goto chown_fail; 161 goto chown_fail;
@@ -173,7 +175,7 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv)
173 } else { 175 } else {
174 bb_error_msg("line %d: unsupported file type %c", linenum, type); 176 bb_error_msg("line %d: unsupported file type %c", linenum, type);
175 ret = EXIT_FAILURE; 177 ret = EXIT_FAILURE;
176 goto loop; 178 continue;
177 } 179 }
178 180
179 full_name_inc = xmalloc(strlen(full_name) + sizeof(int)*3 + 2); 181 full_name_inc = xmalloc(strlen(full_name) + sizeof(int)*3 + 2);
@@ -195,8 +197,6 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv)
195 } 197 }
196 free(full_name_inc); 198 free(full_name_inc);
197 } 199 }
198loop:
199 free(full_name);
200 } 200 }
201 if (ENABLE_FEATURE_CLEAN_UP) 201 if (ENABLE_FEATURE_CLEAN_UP)
202 config_close(parser); 202 config_close(parser);