diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-11-27 23:27:54 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-11-27 23:27:54 +0100 |
commit | 2c769c69b269f43d8c9ecf4a7f5ce5cce290750a (patch) | |
tree | 1d68a329e6419f721ee5dda0cabeafc16c79834b | |
parent | bff71d3b9d4244abc5182c38d0a98f4913188391 (diff) | |
download | busybox-w32-2c769c69b269f43d8c9ecf4a7f5ce5cce290750a.tar.gz busybox-w32-2c769c69b269f43d8c9ecf4a7f5ce5cce290750a.tar.bz2 busybox-w32-2c769c69b269f43d8c9ecf4a7f5ce5cce290750a.zip |
makedevs: make special node creation idempotent
When makedevs is called for a second time with the same device file,
it fails because the files already exist and mknod() gives -EEXIST.
Ignore EEXIST errors.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/makedevs.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c index 6278ee77c..c5eeed0e0 100644 --- a/miscutils/makedevs.c +++ b/miscutils/makedevs.c | |||
@@ -157,8 +157,11 @@ int makedevs_main(int argc, char **argv) | |||
157 | 157 | ||
158 | /* if mode != S_IFCHR and != S_IFBLK, | 158 | /* if mode != S_IFCHR and != S_IFBLK, |
159 | * third param in mknod() ignored */ | 159 | * third param in mknod() ignored */ |
160 | if (mknod(nodname, mode, makedev(Smajor, Sminor))) | 160 | if (mknod(nodname, mode, makedev(Smajor, Sminor)) != 0 |
161 | && errno != EEXIST | ||
162 | ) { | ||
161 | bb_perror_msg("can't create '%s'", nodname); | 163 | bb_perror_msg("can't create '%s'", nodname); |
164 | } | ||
162 | 165 | ||
163 | /*if (nodname == basedev)*/ /* ex. /dev/hda - to /dev/hda1 ... */ | 166 | /*if (nodname == basedev)*/ /* ex. /dev/hda - to /dev/hda1 ... */ |
164 | nodname = buf; | 167 | nodname = buf; |
@@ -279,7 +282,9 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv) | |||
279 | for (i = start; i <= start + count; i++) { | 282 | for (i = start; i <= start + count; i++) { |
280 | sprintf(full_name_inc, count ? "%s%u" : "%s", full_name, i); | 283 | sprintf(full_name_inc, count ? "%s%u" : "%s", full_name, i); |
281 | rdev = makedev(major, minor + (i - start) * increment); | 284 | rdev = makedev(major, minor + (i - start) * increment); |
282 | if (mknod(full_name_inc, mode, rdev) < 0) { | 285 | if (mknod(full_name_inc, mode, rdev) != 0 |
286 | && errno != EEXIST | ||
287 | ) { | ||
283 | bb_perror_msg("line %d: can't create node %s", linenum, full_name_inc); | 288 | bb_perror_msg("line %d: can't create node %s", linenum, full_name_inc); |
284 | ret = EXIT_FAILURE; | 289 | ret = EXIT_FAILURE; |
285 | } else if (chown(full_name_inc, uid, gid) < 0) { | 290 | } else if (chown(full_name_inc, uid, gid) < 0) { |