From f58973cb6e8c82d8970602c70dd99d0e1c19335a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 1 Jan 2016 20:43:23 +0100 Subject: remove satd-rm and satd-r and let satrm and satr do everything (not done yet) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/README | 13 +++++------ src/daemon.c | 13 +++++++++++ src/daemon.h | 39 +++++++++++++++++++------------- src/satd-diminished.c | 2 -- src/satd-rm.c | 57 ---------------------------------------------- src/satd-run.c | 62 --------------------------------------------------- src/satq.c | 15 +++---------- src/satr.c | 25 ++++++++++++--------- src/satrm.c | 17 +++++++------- 9 files changed, 67 insertions(+), 176 deletions(-) delete mode 100644 src/satd-rm.c delete mode 100644 src/satd-run.c (limited to 'src') diff --git a/src/README b/src/README index c4a0b15..6780080 100644 --- a/src/README +++ b/src/README @@ -1,14 +1,11 @@ sat.c The satd program, ask satd to queue a job. -satq.c The satq program, ask satd for a list of queued jobs. -satr.c The satr program, ask satd to run jobs early. -satrm.c The satrm program, ask satd to remove jobs from the queue. +satq.c The satq program, prints the job queue. +satr.c The satr program, runs jobs and then pokes the daemon. +satrm.c The satrm program, removes jobs and then pokes the daemon. satd.c The initialisation part of satd. satd-diminished.c The rest of satd, satd.c exec:s to this. satd-add.c The part of satd responding to sat, satd-diminished.c fork–exec:s to this. -satd-rm.c The part of satd responding to satrm, satd-diminished.c fork–exec:s to this. -satd-list.c The part of satd responding to satlist, satd-diminished.c fork–exec:s to this. -satd-run.c The part of satd responding to satr, satd-diminished.c fork–exec:s to this. satd-timer.c The part of satd responsible for running expired jobs and setting timers to wait for new expirations, satd-diminished.c fork–exec:s to this. @@ -18,10 +15,10 @@ parse_time.[ch] Use by sat.c to parse the time argument. daemonise.[ch] From ; daemonisation of the process. Used by satd.c -client.[ch] Used by sat{,r,rm}.c, code for communicating +client.[ch] Used by sat.c, code for communicating with satd, starts satd transparently if necessary. -daemon.[ch] Used by sat{q,d*}.c, some shared code for daemons objects. +daemon.[ch] Used by sat{q,r,rm,d*}.c, some shared code for daemons objects. common.h Used by sat{,q,r,rm,d*}.c, some shared code. Included via client.h and daemon.h. diff --git a/src/daemon.c b/src/daemon.c index ab97dff..a39b0e3 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -473,3 +473,16 @@ fail: return fd; } + +/** + * Let the daemon know that it may need to + * update the timers, and perhaps exit. + * + * @return 0 on success, -1 on error. + */ +int +poke_daemon(void) +{ + return 0; /* TODO poke_daemon */ +} + diff --git a/src/daemon.h b/src/daemon.h index dc8a355..1d4a747 100644 --- a/src/daemon.h +++ b/src/daemon.h @@ -67,21 +67,6 @@ */ #define SAT_QUEUE 0 -/** - * Command: remove jobs. - */ -#define SAT_REMOVE 1 - -/** - * Command: print job queue. - */ -#define SAT_PRINT 2 - -/** - * Command: run jobs. - */ -#define SAT_RUN 3 - /** @@ -140,6 +125,22 @@ fail: \ FD = WANT +#define PROLOGUE(USAGE_ASSUMPTION, ...) \ + int state = -1; \ + if (argc > 0) argv0 = argv[0]; \ + if (!(USAGE_ASSUMPTION)) usage(); \ + GET_FD(state, STATE_FILENO, open_state(__VA_ARGS__)) + +#define CLEANUP_START \ + errno = 0; \ +fail: \ + if (errno) perror(argv[0]); \ + if (state >= 0) close(state) + +#define CLEANUP_END \ + return !!errno + + /** * Wrapper for `pread` that reads the required amount of data. @@ -276,3 +277,11 @@ int dup2_and_null(int old, int new); */ int open_state(int open_flags, char **state_path); +/** + * Let the daemon know that it may need to + * update the timers, and perhaps exit. + * + * @return 0 on success, -1 on error. + */ +int poke_daemon(void); + diff --git a/src/satd-diminished.c b/src/satd-diminished.c index 845fa13..0ea60d2 100644 --- a/src/satd-diminished.c +++ b/src/satd-diminished.c @@ -134,8 +134,6 @@ spawn(int command, int fd, char *argv[], char *envp[]) /* Child. */ switch (command) { IMAGE(SAT_QUEUE, "add"); - IMAGE(SAT_REMOVE, "rm"); - IMAGE(SAT_RUN, "run"); IMAGE(-1, "timer"); default: fprintf(stderr, "%s: invalid command received.\n", argv[0]); diff --git a/src/satd-rm.c b/src/satd-rm.c deleted file mode 100644 index d33160c..0000000 --- a/src/satd-rm.c +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright © 2015, 2016 Mattias Andrée - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ -#include "daemon.h" - - - -/** - * Subroutine to the sat daemon: remove jobs. - * - * @param argc Should be 3. - * @param argv The name of the process, the pathname of the socket, - * and the pathname to the state file. - * @return 0 The process was successful. - * @return 1 The process failed queuing the job. - */ -int -main(int argc, char *argv[]) -{ - size_t n = 0; - char *message = NULL; - char **msg_argv = NULL; - char **arg; - DAEMON_PROLOGUE; - - /* Receive and validate message. */ - t (readall(SOCK_FILENO, &message, &n) || !n || message[n - 1]); - t (!(msg_argv = restore_array(message, n, NULL))); - - /* Perform action. */ - for (arg = msg_argv; *arg; arg++) - t (remove_job(*arg, 0) && errno); - - DAEMON_CLEANUP_START; - free(msg_argv); - free(message); - DAEMON_CLEANUP_END; -} - diff --git a/src/satd-run.c b/src/satd-run.c deleted file mode 100644 index cf3f065..0000000 --- a/src/satd-run.c +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright © 2015, 2016 Mattias Andrée - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ -#include "daemon.h" - - - -/** - * Subroutine to the sat daemon: run jobs early. - * - * @param argc Should be 3. - * @param argv The name of the process, the pathname of the socket, - * and the pathname to the state file. - * @return 0 The process was successful. - * @return 1 The process failed queuing the job. - */ -int -main(int argc, char *argv[]) -{ - size_t n = 0; - char *message = NULL; - char **msg_argv = NULL; - char **arg; - DAEMON_PROLOGUE; - - /* Receive and validate message. */ - t (readall(SOCK_FILENO, &message, &n) || (n && message[n - 1])); - t (n && !(msg_argv = restore_array(message, n, NULL))); - - /* Perform action. */ - if (msg_argv) { - for (arg = msg_argv; *arg; arg++) - t (remove_job(*arg, 1) && errno); - } else { - while (!remove_job(NULL, 1)); - t (errno); - } - - DAEMON_CLEANUP_START; - free(msg_argv); - free(message); - DAEMON_CLEANUP_END; -} - diff --git a/src/satq.c b/src/satq.c index f2fef92..c097bfd 100644 --- a/src/satq.c +++ b/src/satq.c @@ -247,25 +247,16 @@ main(int argc, char *argv[]) { struct job **jobs = NULL; struct job **job; - int state = -1; + PROLOGUE(argc < 2, O_RDONLY, NULL); - if (argc > 0) argv0 = argv[0]; - if (argc > 1) usage(); - - GET_FD(state, STATE_FILENO, open_state(O_RDONLY, NULL)); t (!(jobs = get_jobs())); for (job = jobs; *job; job++) t (print_job(*job)); - errno = 0; -fail: - if (errno) - perror(argv[0]); + CLEANUP_START; for (job = jobs; jobs && *job; job++) free(*job); free(jobs); - if (state >= 0) - close(state); - return !!errno; + CLEANUP_END; } diff --git a/src/satr.c b/src/satr.c index 42bfda4..3a46079 100644 --- a/src/satr.c +++ b/src/satr.c @@ -19,7 +19,7 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ -#include "client.h" +#include "daemon.h" @@ -41,16 +41,19 @@ USAGE("[JOB-ID]...") int main(int argc, char *argv[]) { - size_t n = 0; - char *msg = NULL; - - if (argc > 0) argv0 = argv[0]; - if (argc < 2) goto run; - + PROLOGUE(1, O_RDWR, NULL); NO_OPTIONS; - CONSTRUCT_MESSAGE; -run: - SEND(SAT_RUN, n, msg); - END(msg); + + if (argc > 1) { + for (argv++; *argv; argv++) + t (remove_job(*argv, 1) && errno); + } else { + while (!remove_job(NULL, 1)); + t (errno); + } + t (poke_daemon()); + + CLEANUP_START; + CLEANUP_END; } diff --git a/src/satrm.c b/src/satrm.c index fda6288..115373c 100644 --- a/src/satrm.c +++ b/src/satrm.c @@ -19,7 +19,7 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ -#include "client.h" +#include "daemon.h" @@ -42,15 +42,14 @@ USAGE("JOB-ID...") int main(int argc, char *argv[]) { - size_t n; - char *msg = NULL; + PROLOGUE(argc >= 2, O_RDWR, NULL); + NO_OPTIONS; - if (argc > 0) argv0 = argv[0]; - if (argc < 2) usage(); + for (argv++; *argv; argv++) + t (remove_job(*argv, 0) && errno); + t (poke_daemon()); - NO_OPTIONS; - CONSTRUCT_MESSAGE; - SEND(SAT_REMOVE, n, msg); - END(msg); + CLEANUP_START; + CLEANUP_END; } -- cgit v1.2.3-70-g09d2