aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/ci_queue.h33
-rw-r--r--src/const.h2
-rw-r--r--src/run_queue.c (renamed from src/ci_queue.c)36
-rw-r--r--src/run_queue.h33
-rw-r--r--src/server.c41
-rw-r--r--src/server.h6
-rw-r--r--src/server_main.c1
-rw-r--r--src/worker.c2
9 files changed, 76 insertions, 80 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9174061..f8b2a7c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -37,12 +37,12 @@ endfunction()
generate_sql_header(sqlite)
add_my_executable(server server_main.c server.c
- ci_queue.c
cmd_line.c
command.c
file.c
msg.c
net.c
+ run_queue.c
signal.c
sql/sqlite_sql.h
sqlite.c
diff --git a/src/ci_queue.h b/src/ci_queue.h
deleted file mode 100644
index a0e8ce5..0000000
--- a/src/ci_queue.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2022 Egor Tensin <Egor.Tensin@gmail.com>
- * This file is part of the "cimple" project.
- * For details, see https://github.com/egor-tensin/cimple.
- * Distributed under the MIT License.
- */
-
-#ifndef __CI_QUEUE_H__
-#define __CI_QUEUE_H__
-
-#include <sys/queue.h>
-
-struct ci_queue_entry;
-
-int ci_queue_entry_create(struct ci_queue_entry **, const char *url, const char *rev);
-void ci_queue_entry_destroy(struct ci_queue_entry *);
-
-const char *ci_queue_entry_get_url(const struct ci_queue_entry *);
-const char *ci_queue_entry_get_rev(const struct ci_queue_entry *);
-
-STAILQ_HEAD(ci_queue, ci_queue_entry);
-
-void ci_queue_create(struct ci_queue *);
-void ci_queue_destroy(struct ci_queue *);
-
-int ci_queue_is_empty(const struct ci_queue *);
-
-void ci_queue_add_first(struct ci_queue *, struct ci_queue_entry *);
-void ci_queue_add_last(struct ci_queue *, struct ci_queue_entry *);
-
-struct ci_queue_entry *ci_queue_remove_first(struct ci_queue *);
-
-#endif
diff --git a/src/const.h b/src/const.h
index c762dbe..f53ef7e 100644
--- a/src/const.h
+++ b/src/const.h
@@ -14,7 +14,7 @@
#define DEFAULT_PORT "5556"
#define DEFAULT_SQLITE_PATH "/var/lib/cimple/cimple.sqlite"
-#define CMD_CI_RUN "run"
+#define CMD_RUN "run"
#define CMD_NEW_WORKER "new-worker"
#endif
diff --git a/src/ci_queue.c b/src/run_queue.c
index 0928ff9..8b5052b 100644
--- a/src/ci_queue.c
+++ b/src/run_queue.c
@@ -5,22 +5,22 @@
* Distributed under the MIT License.
*/
-#include "ci_queue.h"
+#include "run_queue.h"
#include "log.h"
#include <stdlib.h>
#include <string.h>
#include <sys/queue.h>
-struct ci_queue_entry {
+struct run_queue_entry {
char *url;
char *rev;
- STAILQ_ENTRY(ci_queue_entry) entries;
+ STAILQ_ENTRY(run_queue_entry) entries;
};
-int ci_queue_entry_create(struct ci_queue_entry **_entry, const char *_url, const char *_rev)
+int run_queue_entry_create(struct run_queue_entry **_entry, const char *_url, const char *_rev)
{
- struct ci_queue_entry *entry = malloc(sizeof(struct ci_queue_entry));
+ struct run_queue_entry *entry = malloc(sizeof(struct run_queue_entry));
if (!entry) {
log_errno("malloc");
goto fail;
@@ -54,57 +54,57 @@ fail:
return -1;
}
-void ci_queue_entry_destroy(struct ci_queue_entry *entry)
+void run_queue_entry_destroy(struct run_queue_entry *entry)
{
free(entry->rev);
free(entry->url);
free(entry);
}
-const char *ci_queue_entry_get_url(const struct ci_queue_entry *entry)
+const char *run_queue_entry_get_url(const struct run_queue_entry *entry)
{
return entry->url;
}
-const char *ci_queue_entry_get_rev(const struct ci_queue_entry *entry)
+const char *run_queue_entry_get_rev(const struct run_queue_entry *entry)
{
return entry->rev;
}
-void ci_queue_create(struct ci_queue *queue)
+void run_queue_create(struct run_queue *queue)
{
STAILQ_INIT(queue);
}
-void ci_queue_destroy(struct ci_queue *queue)
+void run_queue_destroy(struct run_queue *queue)
{
- struct ci_queue_entry *entry1 = STAILQ_FIRST(queue);
+ struct run_queue_entry *entry1 = STAILQ_FIRST(queue);
while (entry1) {
- struct ci_queue_entry *entry2 = STAILQ_NEXT(entry1, entries);
- ci_queue_entry_destroy(entry1);
+ struct run_queue_entry *entry2 = STAILQ_NEXT(entry1, entries);
+ run_queue_entry_destroy(entry1);
entry1 = entry2;
}
STAILQ_INIT(queue);
}
-int ci_queue_is_empty(const struct ci_queue *queue)
+int run_queue_is_empty(const struct run_queue *queue)
{
return STAILQ_EMPTY(queue);
}
-void ci_queue_add_last(struct ci_queue *queue, struct ci_queue_entry *entry)
+void run_queue_add_last(struct run_queue *queue, struct run_queue_entry *entry)
{
STAILQ_INSERT_TAIL(queue, entry, entries);
}
-void ci_queue_add_first(struct ci_queue *queue, struct ci_queue_entry *entry)
+void run_queue_add_first(struct run_queue *queue, struct run_queue_entry *entry)
{
STAILQ_INSERT_HEAD(queue, entry, entries);
}
-struct ci_queue_entry *ci_queue_remove_first(struct ci_queue *queue)
+struct run_queue_entry *run_queue_remove_first(struct run_queue *queue)
{
- struct ci_queue_entry *entry = STAILQ_FIRST(queue);
+ struct run_queue_entry *entry = STAILQ_FIRST(queue);
STAILQ_REMOVE_HEAD(queue, entries);
return entry;
}
diff --git a/src/run_queue.h b/src/run_queue.h
new file mode 100644
index 0000000..629a8e0
--- /dev/null
+++ b/src/run_queue.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2022 Egor Tensin <Egor.Tensin@gmail.com>
+ * This file is part of the "cimple" project.
+ * For details, see https://github.com/egor-tensin/cimple.
+ * Distributed under the MIT License.
+ */
+
+#ifndef __RUN_QUEUE_H__
+#define __RUN_QUEUE_H__
+
+#include <sys/queue.h>
+
+struct run_queue_entry;
+
+int run_queue_entry_create(struct run_queue_entry **, const char *url, const char *rev);
+void run_queue_entry_destroy(struct run_queue_entry *);
+
+const char *run_queue_entry_get_url(const struct run_queue_entry *);
+const char *run_queue_entry_get_rev(const struct run_queue_entry *);
+
+STAILQ_HEAD(run_queue, run_queue_entry);
+
+void run_queue_create(struct run_queue *);
+void run_queue_destroy(struct run_queue *);
+
+int run_queue_is_empty(const struct run_queue *);
+
+void run_queue_add_first(struct run_queue *, struct run_queue_entry *);
+void run_queue_add_last(struct run_queue *, struct run_queue_entry *);
+
+struct run_queue_entry *run_queue_remove_first(struct run_queue *);
+
+#endif
diff --git a/src/server.c b/src/server.c
index db9f9c3..04a6847 100644
--- a/src/server.c
+++ b/src/server.c
@@ -6,12 +6,12 @@
*/
#include "server.h"
-#include "ci_queue.h"
#include "command.h"
#include "compiler.h"
#include "const.h"
#include "log.h"
#include "msg.h"
+#include "run_queue.h"
#include "signal.h"
#include "storage.h"
#include "storage_sqlite.h"
@@ -30,7 +30,7 @@ struct server {
struct tcp_server *tcp_server;
- struct ci_queue ci_queue;
+ struct run_queue run_queue;
};
int server_create(struct server **_server, const struct settings *settings)
@@ -71,7 +71,7 @@ int server_create(struct server **_server, const struct settings *settings)
if (ret < 0)
goto destroy_storage;
- ci_queue_create(&server->ci_queue);
+ run_queue_create(&server->run_queue);
*_server = server;
return ret;
@@ -95,7 +95,7 @@ void server_destroy(struct server *server)
{
log("Shutting down\n");
- ci_queue_destroy(&server->ci_queue);
+ run_queue_destroy(&server->run_queue);
tcp_server_destroy(server->tcp_server);
storage_destroy(&server->storage);
pthread_errno_if(pthread_cond_destroy(&server->server_cv), "pthread_cond_destroy");
@@ -105,16 +105,16 @@ void server_destroy(struct server *server)
static int server_has_runs(const struct server *server)
{
- return !ci_queue_is_empty(&server->ci_queue);
+ return !run_queue_is_empty(&server->run_queue);
}
-static int worker_ci_run(int fd, const struct ci_queue_entry *ci_run)
+static int worker_ci_run(int fd, const struct run_queue_entry *ci_run)
{
struct msg *request = NULL, *response = NULL;
int ret = 0;
- const char *argv[] = {CMD_CI_RUN, ci_queue_entry_get_url(ci_run),
- ci_queue_entry_get_rev(ci_run), NULL};
+ const char *argv[] = {CMD_RUN, run_queue_entry_get_url(ci_run),
+ run_queue_entry_get_rev(ci_run), NULL};
ret = msg_from_argv(&request, argv);
if (ret < 0)
@@ -139,7 +139,7 @@ free_response:
return ret;
}
-static int worker_dequeue_run(struct server *server, struct ci_queue_entry **ci_run)
+static int worker_dequeue_run(struct server *server, struct run_queue_entry **ci_run)
{
int ret = 0;
@@ -162,8 +162,9 @@ static int worker_dequeue_run(struct server *server, struct ci_queue_entry **ci_
goto unlock;
}
- *ci_run = ci_queue_remove_first(&server->ci_queue);
- log("Removed a CI run for repository %s from the queue\n", ci_queue_entry_get_url(*ci_run));
+ *ci_run = run_queue_remove_first(&server->run_queue);
+ log("Removed a CI run for repository %s from the queue\n",
+ run_queue_entry_get_url(*ci_run));
goto unlock;
unlock:
@@ -172,7 +173,7 @@ unlock:
return ret;
}
-static int worker_requeue_run(struct server *server, struct ci_queue_entry *ci_run)
+static int worker_requeue_run(struct server *server, struct run_queue_entry *ci_run)
{
int ret = 0;
@@ -182,8 +183,8 @@ static int worker_requeue_run(struct server *server, struct ci_queue_entry *ci_r
return ret;
}
- ci_queue_add_first(&server->ci_queue, ci_run);
- log("Requeued a CI run for repository %s\n", ci_queue_entry_get_url(ci_run));
+ run_queue_add_first(&server->run_queue, ci_run);
+ log("Requeued a CI run for repository %s\n", run_queue_entry_get_url(ci_run));
ret = pthread_cond_signal(&server->server_cv);
if (ret) {
@@ -200,7 +201,7 @@ unlock:
static int worker_iteration(struct server *server, int fd)
{
- struct ci_queue_entry *ci_run = NULL;
+ struct run_queue_entry *ci_run = NULL;
int ret = 0;
ret = worker_dequeue_run(server, &ci_run);
@@ -211,7 +212,7 @@ static int worker_iteration(struct server *server, int fd)
if (ret < 0)
goto requeue_run;
- ci_queue_entry_destroy(ci_run);
+ run_queue_entry_destroy(ci_run);
return ret;
requeue_run:
@@ -241,7 +242,7 @@ static int msg_new_worker_handler(int client_fd, UNUSED const struct msg *reques
static int msg_ci_run_queue(struct server *server, const char *url, const char *rev)
{
- struct ci_queue_entry *entry = NULL;
+ struct run_queue_entry *entry = NULL;
int ret = 0;
ret = pthread_mutex_lock(&server->server_mtx);
@@ -250,11 +251,11 @@ static int msg_ci_run_queue(struct server *server, const char *url, const char *
return ret;
}
- ret = ci_queue_entry_create(&entry, url, rev);
+ ret = run_queue_entry_create(&entry, url, rev);
if (ret < 0)
goto unlock;
- ci_queue_add_last(&server->ci_queue, entry);
+ run_queue_add_last(&server->run_queue, entry);
log("Added a new CI run for repository %s to the queue\n", url);
ret = pthread_cond_signal(&server->server_cv);
@@ -294,7 +295,7 @@ static int msg_ci_run_handler(UNUSED int client_fd, const struct msg *request, v
static struct cmd_desc commands[] = {
{CMD_NEW_WORKER, msg_new_worker_handler},
- {CMD_CI_RUN, msg_ci_run_handler},
+ {CMD_RUN, msg_ci_run_handler},
};
static int server_set_stopping(struct server *server)
diff --git a/src/server.h b/src/server.h
index 9c96db2..92ca37d 100644
--- a/src/server.h
+++ b/src/server.h
@@ -8,12 +8,6 @@
#ifndef __SERVER_H__
#define __SERVER_H__
-#include "ci_queue.h"
-#include "storage.h"
-#include "tcp_server.h"
-
-#include <pthread.h>
-
struct settings {
const char *port;
diff --git a/src/server_main.c b/src/server_main.c
index 7a407de..be2639f 100644
--- a/src/server_main.c
+++ b/src/server_main.c
@@ -10,6 +10,7 @@
#include "server.h"
#include <getopt.h>
+#include <stddef.h>
static struct settings default_settings(void)
{
diff --git a/src/worker.c b/src/worker.c
index 3cbe626..755ff35 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -129,7 +129,7 @@ static int msg_ci_run_handler(UNUSED int conn_fd, const struct msg *request, UNU
}
static struct cmd_desc cmds[] = {
- {CMD_CI_RUN, msg_ci_run_handler},
+ {CMD_RUN, msg_ci_run_handler},
};
int worker_main(struct worker *worker, UNUSED int argc, UNUSED char *argv[])