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>
21 #define PROGRAM_SIZE 100
24 #define strfieldcpy(to, from) \
26 to[sizeof(to)-1] = '\0'; \
27 strncpy(to, from, sizeof(to)-1); \
30 int execute_program(char *path, char *value, int len)
38 char arg[PROGRAM_SIZE];
39 char *argv[sizeof(arg) / 2];
44 if (strchr(path, ' ')) {
45 strfieldcpy(arg, path);
49 /* don't separate if in apostrophes */
51 argv[i] = strsep(&pos, "\'");
55 argv[i] = strsep(&pos, " ");
77 /* dup write side of pipe to STDOUT */
80 retval = execv(argv[0], argv);
86 /* parent reads from fds[0] */
91 count = read(fds[0], value + i, len - i-1);
105 if (i > 0 && value[i-1] == '\n')
112 if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0))
119 apply_format (char * string, char * cmd, struct path * pp)
135 pos = strchr(string, '%');
136 myfree = CALLOUT_MAX_SIZE;
143 len = (int) (pos - string) + 1;
149 snprintf(p, len, "%s", string);
155 len = strlen(pp->dev) + 1;
161 snprintf(p, len, "%s", pp->dev);
165 len = strlen(pp->dev_t) + 1;
171 snprintf(p, len, "%s", pp->dev_t);
182 len = strlen(pos) + 1;
188 snprintf(p, len, "%s", pos);
189 condlog(3, "reformated callout = %s", dst);