diff --git a/src/test/meson.build b/src/test/meson.build index 97cca3269c..da500473c8 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -636,18 +636,6 @@ tests += [ libacl], '', 'manual', '-DLOG_REALM=LOG_REALM_UDEV'], - [['src/test/test-udev-build-argv.c'], - [libudev_core, - libudev_static, - libsystemd_network, - libshared], - [threads, - librt, - libblkid, - libkmod, - libacl], - '', '', '-DLOG_REALM=LOG_REALM_UDEV'], - [['src/test/test-id128.c'], [], []], diff --git a/src/test/test-udev-build-argv.c b/src/test/test-udev-build-argv.c deleted file mode 100644 index c71c706e2e..0000000000 --- a/src/test/test-udev-build-argv.c +++ /dev/null @@ -1,78 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1+ */ - -#include "alloc-util.h" -#include "string-util.h" -#include "strv.h" -#include "tests.h" -#include "udev.h" - -static void test_udev_build_argv_one(const char *c) { - _cleanup_strv_free_ char **a = NULL; - _cleanup_free_ char *arg = NULL; - char *argv[128], **p; - int argc; - size_t i; - - assert_se(a = strv_split_full(c, NULL, SPLIT_QUOTES | SPLIT_RELAX)); - - assert_se(arg = strdup(c)); - assert_se(udev_build_argv(arg, &argc, argv) >= 0); - - log_info("command: %s", c); - - i = 0; - log_info("strv_split:"); - STRV_FOREACH(p, a) - log_info("argv[%zu] = '%s'", i++, *p); - - i = 0; - log_info("udev_build_argv:"); - STRV_FOREACH(p, argv) - log_info("argv[%zu] = '%s'", i++, *p); - - assert_se(strv_equal(argv, a)); - assert_se(argc == (int) strv_length(a)); - -} - -static void test_udev_build_argv(void) { - test_udev_build_argv_one("one two three"); - test_udev_build_argv_one("one 'two three ' \" four five \" 'aaa bbb "); - test_udev_build_argv_one("/bin/echo -e \\101"); - test_udev_build_argv_one("/bin/echo -n special-device"); - test_udev_build_argv_one("/bin/echo -n special-device"); - test_udev_build_argv_one("/bin/echo test"); - test_udev_build_argv_one("/bin/echo -n test-%b"); - test_udev_build_argv_one("/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9"); - test_udev_build_argv_one("/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'"); - test_udev_build_argv_one("/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'"); - test_udev_build_argv_one("/bin/sh -c 'printf %%s \\\"foo1 foo2\\\" | grep \\\"foo1 foo2\\\"'"); - test_udev_build_argv_one("/bin/sh -c \\\"printf %%s 'foo1 foo2' | grep 'foo1 foo2'\\\""); - test_udev_build_argv_one("/bin/sh -c 'printf \\\"%%s %%s\\\" \\\"foo1 foo2\\\" \\\"foo3\\\"| grep \\\"foo1 foo2\\\"'"); - test_udev_build_argv_one("/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9"); - test_udev_build_argv_one("/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9"); - test_udev_build_argv_one("/bin/echo -n foo"); - test_udev_build_argv_one("/bin/echo -n usb-%b"); - test_udev_build_argv_one("/bin/echo -n scsi-%b"); - test_udev_build_argv_one("/bin/echo -n foo-%b"); - test_udev_build_argv_one("/bin/echo test"); - test_udev_build_argv_one("/bin/echo symlink test this"); - test_udev_build_argv_one("/bin/echo symlink test this"); - test_udev_build_argv_one("/bin/echo link test this"); - test_udev_build_argv_one("/bin/echo -n node link1 link2"); - test_udev_build_argv_one("/bin/echo -n node link1 link2 link3 link4"); - test_udev_build_argv_one("/usr/bin/test -b %N"); - test_udev_build_argv_one("/bin/echo -e name; (/usr/bin/badprogram)"); - test_udev_build_argv_one("/bin/echo -e \\xc3\\xbcber"); - test_udev_build_argv_one("/bin/echo -e \\xef\\xe8garbage"); - test_udev_build_argv_one("/bin/echo 1 1 0400"); - test_udev_build_argv_one("/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890"); -} - -int main(int argc, char *argv[]) { - test_setup_logging(LOG_DEBUG); - - test_udev_build_argv(); - - return 0; -} diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index e46cf1563f..dc3a398c8d 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -697,41 +697,6 @@ static int spawn_wait(struct udev_event *event, return ret; } -int udev_build_argv(char *cmd, int *argc, char *argv[]) { - int i = 0; - char *pos; - - if (strchr(cmd, ' ') == NULL) { - argv[i++] = cmd; - goto out; - } - - pos = cmd; - while (pos != NULL && pos[0] != '\0') { - if (IN_SET(pos[0], '\'', '"')) { - /* do not separate quotes or double quotes */ - char delim[2] = { pos[0], '\0' }; - - pos++; - argv[i] = strsep(&pos, delim); - if (pos != NULL) - while (pos[0] == ' ') - pos++; - } else { - argv[i] = strsep(&pos, " "); - if (pos != NULL) - while (pos[0] == ' ') - pos++; - } - i++; - } -out: - argv[i] = NULL; - if (argc) - *argc = i; - return 0; -} - int udev_event_spawn(struct udev_event *event, usec_t timeout_usec, usec_t timeout_warn_usec, diff --git a/src/udev/udev.h b/src/udev/udev.h index b7b2c0420c..1164d2fb1b 100644 --- a/src/udev/udev.h +++ b/src/udev/udev.h @@ -75,7 +75,6 @@ void udev_event_execute_rules(struct udev_event *event, struct udev_list *properties_list, struct udev_rules *rules); void udev_event_execute_run(struct udev_event *event, usec_t timeout_usec, usec_t timeout_warn_usec); -int udev_build_argv(char *cmd, int *argc, char *argv[]); /* udev-watch.c */ int udev_watch_init(void);