2 * Source: copy of the udev package source file
4 * Copyrights of the source file apply
5 * Copyright (c) 2004 Christophe Varoqui
11 #include <sys/types.h>
16 #define PROGRAM_SIZE 100
19 #define strfieldcpy(to, from) \
21 to[sizeof(to)-1] = '\0'; \
22 strncpy(to, from, sizeof(to)-1); \
25 int execute_program(char *path, char *value, int len)
33 char arg[PROGRAM_SIZE];
34 char *argv[sizeof(arg) / 2];
39 if (strchr(path, ' ')) {
40 strfieldcpy(arg, path);
44 /* don't separate if in apostrophes */
46 argv[i] = strsep(&pos, "\'");
50 argv[i] = strsep(&pos, " ");
72 /* dup write side of pipe to STDOUT */
75 retval = execv(argv[0], argv);
81 /* parent reads from fds[0] */
86 count = read(fds[0], value + i, len - i-1);
100 if (i > 0 && value[i-1] == '\n')
107 if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))