From 532b3ae9b5cd8609237e04db768cc1f750d8631d Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 25 Aug 2022 16:58:38 +0200 Subject: add some more code This adds a basic "worker" program. You can now do something like ./server & ./worker & ./client ci_run URL REV and the server should pass a message to worker, after which it should clone the repository at URL, checkout REV, and try to run the CI script. It's extremely unfinished: I need to sort out the graceful shutdown, how the server manages workers, etc. --- src/worker_main.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/worker_main.c (limited to 'src/worker_main.c') diff --git a/src/worker_main.c b/src/worker_main.c new file mode 100644 index 0000000..d88071d --- /dev/null +++ b/src/worker_main.c @@ -0,0 +1,86 @@ +#include "const.h" +#include "worker.h" + +#include +#include +#include + +static struct settings default_settings() +{ + struct settings settings = {DEFAULT_HOST, DEFAULT_PORT}; + return settings; +} + +static void print_usage(const char *argv0) +{ + printf("usage: %s [-h|--help] [-V|--version] [-H|--host HOST] [-p|--port PORT]\n", argv0); +} + +static void print_version() +{ + printf("%s\n", VERSION); +} + +static int parse_settings(struct settings *settings, int argc, char *argv[]) +{ + int opt, longind; + + *settings = default_settings(); + + static struct option long_options[] = { + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, + {"host", required_argument, 0, 'H'}, + {"port", required_argument, 0, 'p'}, + {0, 0, 0, 0}, + }; + + while ((opt = getopt_long(argc, argv, "hVH:p:", long_options, &longind)) != -1) { + switch (opt) { + case 'h': + print_usage(argv[0]); + exit(0); + break; + case 'V': + print_version(); + exit(0); + break; + case 'H': + settings->host = optarg; + break; + case 'p': + settings->port = optarg; + break; + default: + print_usage(argv[0]); + exit(1); + break; + } + } + + return 0; +} + +int main(int argc, char *argv[]) +{ + struct settings settings; + struct worker worker; + int ret = 0; + + ret = parse_settings(&settings, argc, argv); + if (ret < 0) + return ret; + + ret = worker_create(&worker, &settings); + if (ret < 0) + return ret; + + ret = worker_main(&worker, argc - optind, argv + optind); + if (ret < 0) + goto destroy_worker; + +destroy_worker: + worker_destroy(&worker); + + return ret; +} -- cgit v1.2.3