udev_test_udev_SOURCES = \
$(udev_common_sources) \
udev/test-udev.c
-udev_test_udev_LDADD = libudev/libudev-private.la
+udev_test_udev_CFLAGS = $(udev_common_CFLAGS)
+udev_test_udev_LDADD = $(udev_common_LDADD)
# ------------------------------------------------------------------------------
# firmware - firmware loading
exit 0
}
-$srcdir/test/rule-syntax-check.py `find $srcdir/rules -type f`
+$srcdir/test/rule-syntax-check.py `find $srcdir/rules -name '*.rules'`
return blkid_do_safeprobe(pr);
}
-static int builtin_blkid(struct udev_device *dev, const char *command, bool test)
+static int builtin_blkid(struct udev_device *dev, int argc, char *argv[], bool test)
{
char *device = "/dev/sda3";
int64_t offset = 0;
.name = "blkid",
.cmd = builtin_blkid,
.help = "filesystem and partition probing",
- .run_once = false,
+ .run_once = true,
};
udev_builtin_add_property(dev, test, "ID_INPUT_KEYBOARD", "1");
}
-static int builtin_input_id(struct udev_device *dev, const char *command, bool test)
+static int builtin_input_id(struct udev_device *dev, int argc, char *argv[], bool test)
{
struct udev_device *pdev;
unsigned long bitmask_ev[NBITS(EV_MAX)];
static char *kmod;
-static int builtin_kmod(struct udev_device *dev, const char *command, bool test)
+static int builtin_kmod(struct udev_device *dev, int argc, char *argv[], bool test)
{
- printf("soon we load a module here: '%s'\n", command);
+ struct udev *udev = udev_device_get_udev(dev);
+
+ if (argc < 3) {
+ err(udev, "missing command + argument\n");
+ return EXIT_FAILURE;
+ }
+
+ printf("soon we '%s' the module '%s' (%i) here\n", argv[1], argv[2], argc);
printf("test: %s\n", kmod);
return EXIT_SUCCESS;
}
static int builtin_kmod_load(struct udev *udev)
{
- printf("load module index\n");
- asprintf(&kmod, "pid: %u\n", getpid());
+ info(udev, "load module index\n");
+ asprintf(&kmod, "pid: %u", getpid());
return 0;
}
static int builtin_kmod_unload(struct udev *udev)
{
- printf("unload module index\n");
+ info(udev, "unload module index\n");
free(kmod);
return 0;
}
return parent;
}
-static int builtin_path_id(struct udev_device *dev, const char *command, bool test)
+static int builtin_path_id(struct udev_device *dev, int argc, char *argv[], bool test)
{
struct udev_device *parent;
char *path = NULL;
* 6.) If the device supplies a serial number, this number
* is concatenated with the identification with an underscore '_'.
*/
-static int builtin_usb_id(struct udev_device *dev, const char *command, bool test)
+static int builtin_usb_id(struct udev_device *dev, int argc, char *argv[], bool test)
{
char vendor_str[64];
char vendor_str_enc[256];
int udev_builtin_run(struct udev_device *dev, enum udev_builtin_cmd cmd, const char *command, bool test)
{
- return builtins[cmd]->cmd(dev, command, test);
+ char arg[UTIL_PATH_SIZE];
+ int argc;
+ char *argv[128];
+
+ util_strscpy(arg, sizeof(arg), command);
+ udev_build_argv(udev_device_get_udev(dev), arg, &argc, argv);
+ return builtins[cmd]->cmd(dev, argc, argv, test);
}
int udev_builtin_add_property(struct udev_device *dev, bool test, const char *key, const char *val, ...)
return err;
}
+int udev_build_argv(struct udev *udev, 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 (pos[0] == '\'') {
+ /* do not separate quotes */
+ pos++;
+ argv[i] = strsep(&pos, "\'");
+ if (pos != NULL)
+ while (pos[0] == ' ')
+ pos++;
+ } else {
+ argv[i] = strsep(&pos, " ");
+ if (pos != NULL)
+ while (pos[0] == ' ')
+ pos++;
+ }
+ dbg(udev, "argv[%i] '%s'\n", i, argv[i]);
+ i++;
+ }
+out:
+ argv[i] = NULL;
+ if (argc)
+ *argc = i;
+ return 0;
+}
+
int udev_event_spawn(struct udev_event *event,
const char *cmd, char **envp, const sigset_t *sigmask,
char *result, size_t ressize)
int errpipe[2] = {-1, -1};
pid_t pid;
char arg[UTIL_PATH_SIZE];
+ char *argv[128];
char program[UTIL_PATH_SIZE];
- char *argv[((sizeof(arg) + 1) / 2) + 1];
- int i;
int err = 0;
- /* build argv from command */
util_strscpy(arg, sizeof(arg), cmd);
- i = 0;
- if (strchr(arg, ' ') != NULL) {
- char *pos = arg;
-
- while (pos != NULL && pos[0] != '\0') {
- if (pos[0] == '\'') {
- /* do not separate quotes */
- pos++;
- argv[i] = strsep(&pos, "\'");
- if (pos != NULL)
- while (pos[0] == ' ')
- pos++;
- } else {
- argv[i] = strsep(&pos, " ");
- if (pos != NULL)
- while (pos[0] == ' ')
- pos++;
- }
- dbg(udev, "arg[%i] '%s'\n", i, argv[i]);
- i++;
- }
- argv[i] = NULL;
- } else {
- argv[0] = arg;
- argv[1] = NULL;
- }
+ udev_build_argv(event->udev, arg, NULL, argv);
/* pipes from child to parent */
if (result != NULL || udev_get_log_priority(udev) >= LOG_INFO) {
char *result, size_t ressize);
int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules, const sigset_t *sigset);
int udev_event_execute_run(struct udev_event *event, const sigset_t *sigset);
+int udev_build_argv(struct udev *udev, char *cmd, int *argc, char *argv[]);
/* udev-watch.c */
int udev_watch_init(struct udev *udev);
};
struct udev_builtin {
const char *name;
- int (*cmd)(struct udev_device *dev, const char *command, bool test);
+ int (*cmd)(struct udev_device *dev, int argc, char *argv[], bool test);
const char *help;
int (*load)(struct udev *udev);
int (*unload)(struct udev *udev);
goto out;
}
}
+
command = argv[optind++];
if (command == NULL) {
fprintf(stderr, "command missing\n");
goto out;
}
+ udev_builtin_load(udev);
+
+ cmd = udev_builtin_lookup(command);
+ if (cmd >= UDEV_BUILTIN_MAX) {
+ fprintf(stderr, "unknown command '%s'\n", command);
+ help(udev);
+ rc = 5;
+ goto out;
+ }
+
/* add /sys if needed */
if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0)
util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), syspath, NULL);
goto out;
}
- udev_builtin_load(udev);
-
- cmd = udev_builtin_lookup(command);
- if (cmd >= UDEV_BUILTIN_MAX) {
- fprintf(stderr, "unknown command '%s'\n", command);
- help(udev);
- rc = 5;
- goto out;
- }
-
if (udev_builtin_run(dev, cmd, command, true) < 0) {
fprintf(stderr, "error executing '%s'\n\n", command);
rc = 6;