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>
22 #define PROGRAM_SIZE 100
25 #define strfieldcpy(to, from) \
27 to[sizeof(to)-1] = '\0'; \
28 strncpy(to, from, sizeof(to)-1); \
31 int execute_program(char *path, char *value, int len)
39 char arg[PROGRAM_SIZE];
40 char *argv[sizeof(arg) / 2];
45 if (strchr(path, ' ')) {
46 strfieldcpy(arg, path);
50 /* don't separate if in apostrophes */
52 argv[i] = strsep(&pos, "\'");
56 argv[i] = strsep(&pos, " ");
78 /* dup write side of pipe to STDOUT */
81 retval = execv(argv[0], argv);
87 /* parent reads from fds[0] */
92 count = read(fds[0], value + i, len - i-1);
106 if (i > 0 && value[i-1] == '\n')
113 if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
120 apply_format (char * string, char * cmd, struct path * pp)
136 pos = strchr(string, '%');
137 myfree = CALLOUT_MAX_SIZE;
144 len = (int) (pos - string) + 1;
150 snprintf(p, len, "%s", string);
156 len = strlen(pp->dev) + 1;
162 snprintf(p, len, "%s", pp->dev);
166 len = strlen(pp->dev_t) + 1;
172 snprintf(p, len, "%s", pp->dev_t);
183 len = strlen(pos) + 1;
189 snprintf(p, len, "%s", pos);
190 condlog(3, "reformated callout = %s", dst);