From: Yu Watanabe Date: Mon, 22 Oct 2018 04:47:06 +0000 (+0900) Subject: udevadm-test-builtin: use find_device() X-Git-Tag: v240~493^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=45a73f4be32481eacdb652c0869d69025fab354c;p=thirdparty%2Fsystemd.git udevadm-test-builtin: use find_device() This also fixes minor memleak. --- diff --git a/src/udev/udevadm-test-builtin.c b/src/udev/udevadm-test-builtin.c index 01e6b9da959..6be3871d0b5 100644 --- a/src/udev/udevadm-test-builtin.c +++ b/src/udev/udevadm-test-builtin.c @@ -6,15 +6,13 @@ #include #include -#include "libudev-private.h" -#include "path-util.h" -#include "string-util.h" -#include "strxcpyx.h" +#include "log.h" #include "udev-builtin.h" #include "udevadm.h" +#include "udevadm-util.h" static const char *arg_command = NULL; -static char arg_syspath[UTIL_PATH_SIZE] = {}; +static const char *arg_syspath = NULL; static int help(void) { printf("%s test-builtin [OPTIONS] COMMAND DEVPATH\n\n" @@ -36,7 +34,6 @@ static int parse_argv(int argc, char *argv[]) { {} }; - const char *s; int c; while ((c = getopt_long(argc, argv, "Vh", options, NULL)) >= 0) @@ -57,18 +54,12 @@ static int parse_argv(int argc, char *argv[]) { return -EINVAL; } - s = argv[optind++]; - if (!s) { + arg_syspath = argv[optind++]; + if (!arg_syspath) { log_error("syspath missing."); return -EINVAL; } - /* add /sys if needed */ - if (!path_startswith(s, "/sys")) - strscpyl(arg_syspath, sizeof(arg_syspath), "/sys", s, NULL); - else - strscpy(arg_syspath, sizeof(arg_syspath), s); - return 1; } @@ -92,7 +83,7 @@ int builtin_main(int argc, char *argv[], void *userdata) { goto finish; } - r = sd_device_new_from_syspath(&dev, arg_syspath); + r = find_device(arg_syspath, "/sys", &dev); if (r < 0) { log_error_errno(r, "Failed to open device '%s': %m", arg_syspath); goto finish;