X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fudev%2Fudevadm-test-builtin.c;h=35a73494391f68f4209daaf3e26b9cb1dda70a65;hb=e530ed5e1407e0571afc01552e41365ffb01befa;hp=e63b1f4eb7bc2dff065b27fd6a8b8c317255ddc4;hpb=6ada823a9a0979ea145fd70add1007c21caa45c0;p=elogind.git diff --git a/src/udev/udevadm-test-builtin.c b/src/udev/udevadm-test-builtin.c index e63b1f4eb..35a734943 100644 --- a/src/udev/udevadm-test-builtin.c +++ b/src/udev/udevadm-test-builtin.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Kay Sievers + * Copyright (C) 2011 Kay Sievers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,33 +17,24 @@ #include #include -#include #include -#include #include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include #include "udev.h" -static void help(struct udev *udev) -{ - fprintf(stderr, "\n"); - fprintf(stderr, "Usage: udevadm builtin [--help] \n"); +static void help(struct udev *udev) { + printf("%s builtin [--help] COMMAND SYSPATH\n\n" + "Test a built-in command.\n\n" + " -h --help Print this message\n" + " --version Print version of the program\n\n" + "Commands:\n" + , program_invocation_short_name); + udev_builtin_list(udev); - fprintf(stderr, "\n"); } -static int adm_builtin(struct udev *udev, int argc, char *argv[]) -{ +static int adm_builtin(struct udev *udev, int argc, char *argv[]) { static const struct option options[] = { { "help", no_argument, NULL, 'h' }, {} @@ -53,21 +44,14 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[]) char filename[UTIL_PATH_SIZE]; struct udev_device *dev = NULL; enum udev_builtin_cmd cmd; - int rc = EXIT_SUCCESS; - - for (;;) { - int option; + int rc = EXIT_SUCCESS, c; - option = getopt_long(argc, argv, "h", options, NULL); - if (option == -1) - break; - - switch (option) { + while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) + switch (c) { case 'h': help(udev); goto out; } - } command = argv[optind++]; if (command == NULL) { @@ -79,7 +63,7 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[]) syspath = argv[optind++]; if (syspath == NULL) { - fprintf(stderr, "syspath missing\n\n"); + fprintf(stderr, "syspath missing\n"); rc = 3; goto out; } @@ -95,10 +79,10 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[]) } /* add /sys if needed */ - if (strncmp(syspath, "/sys", strlen("/sys")) != 0) - util_strscpyl(filename, sizeof(filename), "/sys", syspath, NULL); + if (!startswith(syspath, "/sys")) + strscpyl(filename, sizeof(filename), "/sys", syspath, NULL); else - util_strscpy(filename, sizeof(filename), syspath); + strscpy(filename, sizeof(filename), syspath); util_remove_trailing_chars(filename, '/'); dev = udev_device_new_from_syspath(udev, filename); @@ -108,8 +92,9 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[]) goto out; } - if (udev_builtin_run(dev, cmd, command, true) < 0) { - fprintf(stderr, "error executing '%s'\n\n", command); + rc = udev_builtin_run(dev, cmd, command, true); + if (rc < 0) { + fprintf(stderr, "error executing '%s', exit code %i\n\n", command, rc); rc = 6; } out: @@ -121,6 +106,6 @@ out: const struct udevadm_cmd udevadm_test_builtin = { .name = "test-builtin", .cmd = adm_builtin, - .help = "test a built-in command", + .help = "Test a built-in command", .debug = true, };