aboutsummaryrefslogtreecommitdiff
path: root/util-linux/mdev.c
diff options
context:
space:
mode:
Diffstat (limited to 'util-linux/mdev.c')
-rw-r--r--util-linux/mdev.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index 79871d30e..c592ef687 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -429,6 +429,18 @@ static const struct rule *next_rule(void)
429 429
430#endif 430#endif
431 431
432static void mkdir_recursive(char *name)
433{
434 /* if name has many levels ("dir1/dir2"),
435 * bb_make_directory() will create dir1 according to umask,
436 * not according to its "mode" parameter.
437 * Since we run with umask=0, need to temporarily switch it.
438 */
439 umask(022); /* "dir1" (if any) will be 0755 too */
440 bb_make_directory(name, 0755, FILEUTILS_RECUR);
441 umask(0);
442}
443
432/* Builds an alias path. 444/* Builds an alias path.
433 * This function potentionally reallocates the alias parameter. 445 * This function potentionally reallocates the alias parameter.
434 * Only used for ENABLE_FEATURE_MDEV_RENAME 446 * Only used for ENABLE_FEATURE_MDEV_RENAME
@@ -442,7 +454,7 @@ static char *build_alias(char *alias, const char *device_name)
442 dest = strrchr(alias, '/'); 454 dest = strrchr(alias, '/');
443 if (dest) { /* ">bar/[baz]" ? */ 455 if (dest) { /* ">bar/[baz]" ? */
444 *dest = '\0'; /* mkdir bar */ 456 *dest = '\0'; /* mkdir bar */
445 bb_make_directory(alias, 0755, FILEUTILS_RECUR); 457 mkdir_recursive(alias);
446 *dest = '/'; 458 *dest = '/';
447 if (dest[1] == '\0') { /* ">bar/" => ">bar/device_name" */ 459 if (dest[1] == '\0') { /* ">bar/" => ">bar/device_name" */
448 dest = alias; 460 dest = alias;
@@ -641,7 +653,7 @@ static void make_device(char *device_name, char *path, int operation)
641 char *slash = strrchr(node_name, '/'); 653 char *slash = strrchr(node_name, '/');
642 if (slash) { 654 if (slash) {
643 *slash = '\0'; 655 *slash = '\0';
644 bb_make_directory(node_name, 0755, FILEUTILS_RECUR); 656 mkdir_recursive(node_name);
645 *slash = '/'; 657 *slash = '/';
646 } 658 }
647 if (G.verbose) 659 if (G.verbose)
@@ -649,6 +661,8 @@ static void make_device(char *device_name, char *path, int operation)
649 if (mknod(node_name, rule->mode | type, makedev(major, minor)) && errno != EEXIST) 661 if (mknod(node_name, rule->mode | type, makedev(major, minor)) && errno != EEXIST)
650 bb_perror_msg("can't create '%s'", node_name); 662 bb_perror_msg("can't create '%s'", node_name);
651 if (ENABLE_FEATURE_MDEV_CONF) { 663 if (ENABLE_FEATURE_MDEV_CONF) {
664 if (G.verbose)
665 bb_error_msg("chmod: %o chown: %u:%u", rule->mode, rule->ugid.uid, rule->ugid.gid);
652 chmod(node_name, rule->mode); 666 chmod(node_name, rule->mode);
653 chown(node_name, rule->ugid.uid, rule->ugid.gid); 667 chown(node_name, rule->ugid.uid, rule->ugid.gid);
654 } 668 }
@@ -801,6 +815,7 @@ static void load_firmware(const char *firmware, const char *sysfs_path)
801 full_write(loading_fd, "-1", 2); 815 full_write(loading_fd, "-1", 2);
802 816
803 out: 817 out:
818 xchdir("/dev");
804 if (ENABLE_FEATURE_CLEAN_UP) { 819 if (ENABLE_FEATURE_CLEAN_UP) {
805 close(firmware_fd); 820 close(firmware_fd);
806 close(loading_fd); 821 close(loading_fd);
@@ -907,11 +922,13 @@ int mdev_main(int argc UNUSED_PARAM, char **argv)
907 } 922 }
908 923
909 { 924 {
910 int logfd = open("/dev/mdev.log", O_WRONLY | O_APPEND); 925 int logfd = open("mdev.log", O_WRONLY | O_APPEND);
911 if (logfd >= 0) { 926 if (logfd >= 0) {
912 xmove_fd(logfd, STDERR_FILENO); 927 xmove_fd(logfd, STDERR_FILENO);
913 G.verbose = 1; 928 G.verbose = 1;
914 bb_error_msg("seq: %s action: %s", seq, action); 929 if (seq)
930 applet_name = xasprintf("%s[%s]", applet_name, seq);
931 bb_error_msg("action: %s", action);
915 } 932 }
916 } 933 }
917 934