X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev%2Fudevadm.c;h=aa0befed3be311721f20a590670b9c7af50c1c2c;hb=32bf83996b1f7d7df83f99e6bf063685146ffe06;hp=7adb7c5732885abdff943ec459b71c6aea563550;hpb=01618658fd82dbc5e6315b639f00e87c6fee3c54;p=elogind.git diff --git a/udev/udevadm.c b/udev/udevadm.c index 7adb7c573..aa0befed3 100644 --- a/udev/udevadm.c +++ b/udev/udevadm.c @@ -49,20 +49,20 @@ void log_message(int priority, const char *format, ...) struct command { const char *name; - int (*cmd)(int argc, char *argv[], char *envp[]); + int (*cmd)(int argc, char *argv[]); const char *help; int debug; }; static const struct command cmds[]; -static int version(int argc, char *argv[], char *envp[]) +static int version(int argc, char *argv[]) { printf("%s\n", VERSION); return 0; } -static int help(int argc, char *argv[], char *envp[]) +static int help(int argc, char *argv[]) { const struct command *cmd; @@ -76,32 +76,32 @@ static int help(int argc, char *argv[], char *envp[]) static const struct command cmds[] = { { .name = "info", - .cmd = udevinfo, + .cmd = udevadm_info, .help = "query sysfs or the udev database", }, { .name = "trigger", - .cmd = udevtrigger, + .cmd = udevadm_trigger, .help = "request events from the kernel", }, { .name = "settle", - .cmd = udevsettle, "", + .cmd = udevadm_settle, "", .help = "wait for the event queue to finish", }, { .name = "control", - .cmd = udevcontrol, + .cmd = udevadm_control, .help = "control the udev daemon", }, { .name = "monitor", - .cmd = udevmonitor, + .cmd = udevadm_monitor, .help = "listen to kernel and udev events", }, { .name = "test", - .cmd = udevtest, + .cmd = udevadm_test, .help = "simulation run", .debug = 1, }, @@ -118,51 +118,54 @@ static const struct command cmds[] = { {} }; -int main(int argc, char *argv[], char *envp[]) +int main(int argc, char *argv[]) { - const char *command; + const char *command = argv[1]; + int i; const char *pos; - const struct command *cmd; int rc; - /* get binary or symlink name */ - pos = strrchr(argv[0], '/'); + /* find command */ + if (command != NULL) + for (i = 0; cmds[i].cmd != NULL; i++) { + if (strcmp(cmds[i].name, command) == 0) { + debug = cmds[i].debug; + rc = cmds[i].cmd(argc-1, &argv[1]); + goto out; + } + } + + /* try to find compat link, will be removed in a future release */ + command = argv[0]; + pos = strrchr(command, '/'); if (pos != NULL) command = &pos[1]; - else - command = argv[0]; - /* the trailing part of the binary or symlink name is the command */ + /* the trailing part of the binary or link name is the command */ if (strncmp(command, "udev", 4) == 0) command = &command[4]; - if (command == NULL || command[0] == '\0') - goto err_unknown; - - /* udevadm itself needs to strip its name from the passed options */ - if (strcmp(command, "adm") == 0) { - command = argv[1]; - argv++; - argc--; - } - - if (command == NULL) - goto err_unknown; - - /* allow command to be specified as an option */ - if (strncmp(command, "--", 2) == 0) - command += 2; - - /* find and execute command */ - for (cmd = cmds; cmd->name != NULL; cmd++) { - if (strcmp(cmd->name, command) == 0) { - debug = cmd->debug; - rc = cmd->cmd(argc, argv, envp); + for (i = 0; cmds[i].cmd != NULL; i++) { + if (strcmp(cmds[i].name, command) == 0) { + char path[128]; + char prog[512]; + ssize_t len; + + snprintf(path, sizeof(path), "/proc/%lu/exe", (unsigned long) getppid()); + len = readlink(path, prog, sizeof(prog)); + if (len > 0) { + prog[len] = '\0'; + fprintf(stderr, "the program '%s' called '%s', it should use 'udevadm %s ', " + "this will stop working in a future release\n", prog, argv[0], command); + info("the program '%s' called '%s', it should use 'udevadm %s ', " + "this will stop working in a future release\n", prog, argv[0], command); + } + debug = cmds[i].debug; + rc = cmds[i].cmd(argc, argv); goto out; } } -err_unknown: fprintf(stderr, "unknown command, try help\n\n"); rc = 2; out: