aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/worker_main.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-08-25 16:58:38 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2022-08-26 04:05:02 +0200
commit532b3ae9b5cd8609237e04db768cc1f750d8631d (patch)
treef65253a6ce9970d1d93e6bb6c65758d6fa98373a /src/worker_main.c
parentcmake: ignore unused parameters for now (diff)
downloadcimple-532b3ae9b5cd8609237e04db768cc1f750d8631d.tar.gz
cimple-532b3ae9b5cd8609237e04db768cc1f750d8631d.zip
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.
Diffstat (limited to 'src/worker_main.c')
-rw-r--r--src/worker_main.c86
1 files changed, 86 insertions, 0 deletions
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 <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+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;
+}