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>
23 int execute_program(char *path, char *value, int len)
31 char arg[CALLOUT_MAX_SIZE];
32 int argc = sizeof(arg) / 2;
38 if (strchr(path, ' ')) {
39 strlcpy(arg, path, sizeof(arg));
41 while (pos != NULL && i < argc) {
43 /* don't separate if in apostrophes */
45 argv[i] = strsep(&pos, "\'");
49 argv[i] = strsep(&pos, " ");
61 condlog(0, "error creating pipe for callout: %s", strerror(errno));
72 /* dup write side of pipe to STDOUT */
76 /* Ignore writes to stderr */
77 null_fd = open("/dev/null", O_WRONLY);
80 retval = dup(null_fd);
84 retval = execv(argv[0], argv);
85 condlog(0, "error execing %s : %s", argv[0], strerror(errno));
88 condlog(0, "fork failed: %s", strerror(errno));
93 /* parent reads from fds[0] */
98 count = read(fds[0], value + i, len - i-1);
104 condlog(0, "not enough space for response from %s", argv[0]);
111 condlog(0, "no response from %s", argv[0]);
115 if (i > 0 && value[i-1] == '\n')
123 if (WIFEXITED(status)) {
124 status = WEXITSTATUS(status);
128 condlog(0, "%s exitted with %d", argv[0], status);
130 else if (WIFSIGNALED(status))
131 condlog(0, "%s was terminated by signal %d", argv[0], WTERMSIG(status));
133 condlog(0, "%s terminated abnormally", argv[0]);
139 apply_format (char * string, char * cmd, struct path * pp)
156 pos = strchr(string, '%');
157 myfree = CALLOUT_MAX_SIZE;
164 len = (int) (pos - string) + 1;
170 snprintf(p, len, "%s", string);
176 len = strlen(pp->dev) + 1;
182 snprintf(p, len, "%s", pp->dev);
183 for (q = p; q < p + len; q++) {
190 len = strlen(pp->dev_t) + 1;
196 snprintf(p, len, "%s", pp->dev_t);
207 len = strlen(pos) + 1;
213 snprintf(p, len, "%s", pos);
214 condlog(3, "reformated callout = %s", dst);