diff options
Diffstat (limited to '')
-rw-r--r-- | src/daemon.c | 5 | ||||
-rw-r--r-- | src/sat.c | 40 | ||||
-rw-r--r-- | src/satd-list.c | 17 |
3 files changed, 33 insertions, 29 deletions
diff --git a/src/daemon.c b/src/daemon.c index 12c1aea..e9c79d9 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -279,7 +279,7 @@ run_job_or_hook(struct job *job, const char *hook) t (!(args = restore_array(job->payload, job->n, &argsn))); t (!(argv = sublist(args, (size_t)(job->argc)))); - t (!(envp = sublist(args + job->argc, argsn - (size_t)(job->argc)))); + t (!(envp = sublist(args + job->argc, argsn - (size_t)(job->argc)))); /* Includes wdir. */ free(args), args = NULL; if (hook) { @@ -298,7 +298,8 @@ run_job_or_hook(struct job *job, const char *hook) close(STATE_FILENO); close(BOOT_FILENO); close(REAL_FILENO); - environ = envp; + (void)(status = chdir(envp[0])); + environ = envp + 1; execvp(*argv, argv); exit(1); default: @@ -23,6 +23,7 @@ #include "client.h" #include "common.h" #include <errno.h> +#include <unistd.h> @@ -50,10 +51,13 @@ USAGE("TIME COMMAND...") int main(int argc, char *argv[], char *envp[]) { +#define E(CASE, DESC) case CASE: return fprintf(stderr, "%s: %s: %s\n", argv0, DESC, argv[1]), 2 + struct timespec ts; clockid_t clk; char *msg = NULL; - size_t n; + void *new; + size_t n, size = 64; if ((argc < 3) || (argv[1][0] == '-')) usage(); @@ -63,33 +67,29 @@ main(int argc, char *argv[], char *envp[]) /* Parse the time argument. */ if (parse_time(argv[1], &ts, &clk)) { switch (errno) { - case EINVAL: - fprintf(stderr, - "%s: time parameter cound not be parsed, perhaps " - "you need an external parser: %s\n", argv0, argv[1]); - return 2; - case ERANGE: - fprintf(stderr, - "%s: the specified time is beyond the limit of what " - "can be represented by `struct timespec`: %s\n", argv0, argv[1]); - return 2; - case EDOM: - fprintf(stderr, - "%s: the specified time is in past, and more than " - "a day ago: %s\n", argv0, argv[1]); - return 2; - default: - goto fail; + E (EINVAL, "time parameter cound not be parsed, perhaps you need an external parser"); + E (ERANGE, "the specified time is beyond the limit of what can be stored"); + E (EDOM, "the specified time is in past, and more than a day ago"); + default: goto fail; } } argc -= 2; argv += 2; +retry: + /* Get the size of the current working directory's pathname. */ + t (!(new = realloc(msg, size <<= 1))); + if (!getcwd(msg = new, size)) { + t (errno != ERANGE); + goto retry; + } + size = strlen(getcwd(msg, size)) + 1, free(msg); + /* Construct message to send to the daemon. */ - n = measure_array(argv) + measure_array(envp); + n = measure_array(argv) + size + measure_array(envp); t (!(msg = malloc(n + sizeof(int) + sizeof(clk) + sizeof(ts)))); - store_array(store_array(msg, argv), envp); + store_array(getcwd(store_array(msg, argv), size) + size, envp); memcpy(msg + n, &argc, sizeof(int)), n += sizeof(int); memcpy(msg + n, &clk, sizeof(clk)), n += sizeof(clk); memcpy(msg + n, &ts, sizeof(ts)), n += sizeof(ts); diff --git a/src/satd-list.c b/src/satd-list.c index 0591368..75f7996 100644 --- a/src/satd-list.c +++ b/src/satd-list.c @@ -73,7 +73,6 @@ quote(const char *str) rc[i++] = (char)*s; if (*s == '\'') rc[i++] = '\\', rc[i++] = '\'', rc[i++] = '\''; - } break; default: @@ -146,6 +145,7 @@ send_job_human(struct job *job) const char *clk; char rem_s[3 * sizeof(time_t) + sizeof("d00:00:00")]; char *qstr = NULL; + char *wdir = NULL; char line[sizeof("job: %zu clock: unrecognised argc: %i remaining: , argv[0]: ") + 3 * sizeof(size_t) + 3 * sizeof(int) + sizeof(rem_s) + 9]; char timestr_a[sizeof("-00-00 00:00:00") + 3 * sizeof(time_t)]; @@ -195,17 +195,19 @@ send_job_human(struct job *job) /* Get arguments. */ t (!(args = restore_array(job->payload, job->n, &argsn))); t (!(argv = sublist(args, (size_t)(job->argc)))); - t (!(envp = sublist(args + job->argc, argsn - (size_t)(job->argc)))); + t (!(envp = sublist(args + job->argc, argsn - (size_t)(job->argc)))); /* Includes wdir. */ /* Send message. */ t (!(qstr = quote(args[0]))); + t (!(wdir = quote(envp[0]))); sprintf(line, "job: %zu clock: %s argc: %i remaining: %s.%09li argv[0]: ", job->no, clk, job->argc, rem_s, rem.tv_nsec); t (send_string(SOCK_FILENO, STDOUT_FILENO, - line, qstr, "\n", - " time: ", timestr_a, ".", timestr_b, "\n", - " argv:", - NULL)); + line, qstr, "\n", + " time: ", timestr_a, ".", timestr_b, "\n", + " wdir:", wdir, "\n", + " argv:", + NULL)); for (arg = argv; *arg; arg++) { free(qstr); t (!(qstr = quote(*arg))); @@ -213,7 +215,7 @@ send_job_human(struct job *job) } free(qstr), qstr = NULL; t (send_string(SOCK_FILENO, STDOUT_FILENO, "\n envp:", NULL)); - for (arg = envp; *arg; arg++) { + for (arg = envp + 1; *arg; arg++) { t (!(qstr = quote(*arg))); t (send_string(SOCK_FILENO, STDOUT_FILENO, " ", qstr, NULL)); free(qstr); @@ -226,6 +228,7 @@ done: free(qstr); free(args); free(argv); + free(wdir); free(envp); errno = saved_errno; return rc; |