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, " ");
68 condlog(0, "error creating pipe for callout: %s", strerror(errno));
79 /* dup write side of pipe to STDOUT */
83 /* Ignore writes to stderr */
84 null_fd = open("/dev/null", O_WRONLY);
91 retval = execv(argv[0], argv);
92 condlog(0, "error execing %s : %s", argv[0], strerror(errno));
95 condlog(0, "fork failed: %s", strerror(errno));
100 /* parent reads from fds[0] */
105 count = read(fds[0], value + i, len - i-1);
111 condlog(0, "not enough space for response from %s", argv[0]);
118 condlog(0, "no response from %s", argv[0]);
122 if (i > 0 && value[i-1] == '\n')
130 if (WIFEXITED(status)) {
131 status = WEXITSTATUS(status);
135 condlog(0, "%s exitted with %d", argv[0], status);
137 else if (WIFSIGNALED(status))
138 condlog(0, "%s was terminated by signal %d", argv[0], WTERMSIG(status));
140 condlog(0, "%s terminated abnormally", argv[0]);
146 apply_format (char * string, char * cmd, struct path * pp)
162 pos = strchr(string, '%');
163 myfree = CALLOUT_MAX_SIZE;
170 len = (int) (pos - string) + 1;
176 snprintf(p, len, "%s", string);
182 len = strlen(pp->dev) + 1;
188 snprintf(p, len, "%s", pp->dev);
192 len = strlen(pp->dev_t) + 1;
198 snprintf(p, len, "%s", pp->dev_t);
209 len = strlen(pos) + 1;
215 snprintf(p, len, "%s", pos);
216 condlog(3, "reformated callout = %s", dst);