diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2022-08-25 16:58:38 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2022-08-26 04:05:02 +0200 |
commit | 532b3ae9b5cd8609237e04db768cc1f750d8631d (patch) | |
tree | f65253a6ce9970d1d93e6bb6c65758d6fa98373a /src/ci_queue.c | |
parent | cmake: ignore unused parameters for now (diff) | |
download | cimple-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 '')
-rw-r--r-- | src/ci_queue.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/ci_queue.c b/src/ci_queue.c new file mode 100644 index 0000000..d87d3c0 --- /dev/null +++ b/src/ci_queue.c @@ -0,0 +1,92 @@ +#include "ci_queue.h" +#include "log.h" + +#include <stdlib.h> +#include <string.h> +#include <sys/queue.h> + +int ci_queue_entry_create(struct ci_queue_entry **entry, const char *_url, const char *_rev) +{ + char *url, *rev; + + url = strdup(_url); + if (!url) { + print_errno("strdup"); + goto fail; + } + + rev = strdup(_rev); + if (!rev) { + print_errno("strdup"); + goto free_url; + } + + *entry = malloc(sizeof(struct ci_queue_entry)); + if (!*entry) { + print_errno("malloc"); + goto free_rev; + } + (*entry)->url = url; + (*entry)->rev = rev; + + return 0; + +free_rev: + free(rev); + +free_url: + free(url); + +fail: + return -1; +} + +void ci_queue_entry_destroy(struct ci_queue_entry *entry) +{ + free(entry->rev); + free(entry->url); + free(entry); +} + +void ci_queue_create(struct ci_queue *queue) +{ + STAILQ_INIT(queue); +} + +void ci_queue_destroy(struct ci_queue *queue) +{ + struct ci_queue_entry *entry1, *entry2; + + entry1 = STAILQ_FIRST(queue); + while (entry1) { + entry2 = STAILQ_NEXT(entry1, entries); + ci_queue_entry_destroy(entry1); + entry1 = entry2; + } + STAILQ_INIT(queue); +} + +int ci_queue_is_empty(const struct ci_queue *queue) +{ + return STAILQ_EMPTY(queue); +} + +void ci_queue_push(struct ci_queue *queue, struct ci_queue_entry *entry) +{ + STAILQ_INSERT_TAIL(queue, entry, entries); +} + +void ci_queue_push_head(struct ci_queue *queue, struct ci_queue_entry *entry) +{ + STAILQ_INSERT_HEAD(queue, entry, entries); +} + +struct ci_queue_entry *ci_queue_pop(struct ci_queue *queue) +{ + struct ci_queue_entry *entry; + + entry = STAILQ_FIRST(queue); + STAILQ_REMOVE_HEAD(queue, entries); + + return entry; +} |