- /* end of field parsing */
- break; /* we found matching line, stop */
- next_line:
- free(line);
- } /* end of "while line is read from /etc/mdev.conf" */
-
- free(line); /* in case we used "break" to get here */
- fclose(fp);
- }
- end_parse:
-
- if (!delete && sscanf(dev_maj_min, "%u:%u", &major, &minor) == 2) {
-
- if (ENABLE_FEATURE_MDEV_RENAME)
+# else
+ alias = xstrdup(a + 1);
+# endif
+ }
+# endif /* ENABLE_FEATURE_MDEV_RENAME */
+
+# if ENABLE_FEATURE_MDEV_EXEC
+ /* The rest (opt): @|$|*command */
+ if (!val)
+ goto line_matches;
+ {
+ const char *s = "@$*";
+ const char *s2 = strchr(s, val[0]);
+
+ if (!s2)
+ bb_error_msg_and_die("bad line %u", parser->lineno);
+
+ /* Correlate the position in the "@$*" with the delete
+ * step so that we get the proper behavior:
+ * @cmd: run on create
+ * $cmd: run on delete
+ * *cmd: run on both
+ */
+ if ((s2 - s + 1) /*1/2/3*/ & /*1/2*/ (1 + delete)) {
+ command = xstrdup(val + 1);
+ }
+ }
+# endif
+ /* End of field parsing */
+ line_matches:
+#endif /* ENABLE_FEATURE_MDEV_CONF */
+
+ /* "Execute" the line we found */
+
+ if (!delete && major >= 0) {
+ if (ENABLE_FEATURE_MDEV_RENAME)
+ unlink(device_name);
+ if (mknod(device_name, mode | type, makedev(major, minor)) && errno != EEXIST)
+ bb_perror_msg_and_die("mknod %s", device_name);
+ if (major == root_major && minor == root_minor)
+ symlink(device_name, "root");
+#if ENABLE_FEATURE_MDEV_CONF
+ chown(device_name, ugid.uid, ugid.gid);
+# if ENABLE_FEATURE_MDEV_RENAME
+ if (alias) {
+ alias = build_alias(alias, device_name);
+ /* move the device, and optionally
+ * make a symlink to moved device node */
+ if (rename(device_name, alias) == 0 && aliaslink == '>')
+ symlink(alias, device_name);
+ free(alias);
+ }
+# endif
+#endif
+ }
+#if ENABLE_FEATURE_MDEV_EXEC
+ if (command) {
+ /* setenv will leak memory, use putenv/unsetenv/free */
+ char *s = xasprintf("%s=%s", "MDEV", device_name);
+ char *s1 = xasprintf("%s=%s", "SUBSYSTEM", subsystem);
+ putenv(s);
+ putenv(s1);
+ if (system(command) == -1)
+ bb_perror_msg_and_die("can't run '%s'", command);
+ unsetenv("SUBSYSTEM");
+ free(s1);
+ unsetenv("MDEV");
+ free(s);
+ free(command);
+ }
+#endif
+ if (delete) {