]> git.ipfire.org Git - pakfire.git/commitdiff
buildservice: Allow passing the event loop to the HTTP client
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 12 Aug 2024 15:02:01 +0000 (15:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 12 Aug 2024 15:02:01 +0000 (15:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
19 files changed:
src/_pakfire/buildservice.c
src/cli/lib/client-build.c
src/cli/lib/repo_create.c
src/cli/lib/repo_delete.c
src/cli/lib/repo_list.c
src/cli/lib/repo_show.c
src/cli/lib/upload_create.c
src/cli/lib/upload_delete.c
src/cli/lib/upload_list.c
src/libpakfire/buildservice.c
src/libpakfire/daemon.c
src/libpakfire/dist.c
src/libpakfire/httpclient.c
src/libpakfire/include/pakfire/buildservice.h
src/libpakfire/include/pakfire/httpclient.h
src/libpakfire/repo.c
src/libpakfire/transaction.c
tests/libpakfire/httpclient.c
tests/testsuite.c

index 7772df4601b59ead5ed4c46678aaa9001ff0dc97..a6099f63863305bf5edaa1791eabbbbb65ebf528 100644 (file)
@@ -41,7 +41,7 @@ static int BuildService_init(BuildServiceObject* self, PyObject* args, PyObject*
        if (!PyArg_ParseTuple(args, "O!", &CtxType, &ctx))
                return -1;
 
-       r = pakfire_buildservice_create(&self->service, ctx->ctx);
+       r = pakfire_buildservice_create(&self->service, ctx->ctx, NULL);
        if (r) {
                errno = -r;
 
index e76b72075fd17042eb94f92a6b54be49b847689a..32989feaef4a8696d422c0048c4229f3d16c2d1b 100644 (file)
@@ -111,7 +111,7 @@ int cli_client_build(void* data, int argc, char* argv[]) {
                goto ERROR;
 
        // Connect to the build service
-       r = pakfire_buildservice_create(&service, cli_config->ctx);
+       r = pakfire_buildservice_create(&service, cli_config->ctx, NULL);
        if (r)
                goto ERROR;
 
index f825f47bbadc51842cfe39298cb1b1f27113507f..cf6ac3773d29006df87429d3a51668f0375cfdea 100644 (file)
@@ -87,7 +87,7 @@ int cli_repo_create(void* data, int argc, char* argv[]) {
                goto ERROR;
 
        // Connect to the build service
-       r = pakfire_buildservice_create(&service, cli_config->ctx);
+       r = pakfire_buildservice_create(&service, cli_config->ctx, NULL);
        if (r)
                goto ERROR;
 
index 84a0ace4ce17d942cdaed1f11c096a2878c06094..76b2287f0df4d8efd965c09d6b170d47347bbc48 100644 (file)
@@ -74,7 +74,7 @@ int cli_repo_delete(void* data, int argc, char* argv[]) {
                goto ERROR;
 
        // Connect to the build service
-       r = pakfire_buildservice_create(&service, cli_config->ctx);
+       r = pakfire_buildservice_create(&service, cli_config->ctx, NULL);
        if (r)
                goto ERROR;
 
index a00c2bb79a4021287909401bb1899ac051d26b2a..3feba67e740804dcd241302deb51e9f5f3d07f9f 100644 (file)
@@ -66,7 +66,7 @@ int cli_repo_list(void* data, int argc, char* argv[]) {
                goto ERROR;
 
        // Connect to the build service
-       r = pakfire_buildservice_create(&service, cli_config->ctx);
+       r = pakfire_buildservice_create(&service, cli_config->ctx, NULL);
        if (r)
                goto ERROR;
 
index 9bdc7c7943bbf8bbebd629c7a5e5ca82874e58b6..2cedcfefc3d441a9c2dd7ea7839d21480d5ce2ba 100644 (file)
@@ -72,7 +72,7 @@ int cli_repo_show(void* data, int argc, char* argv[]) {
                goto ERROR;
 
        // Connect to the build service
-       r = pakfire_buildservice_create(&service, cli_config->ctx);
+       r = pakfire_buildservice_create(&service, cli_config->ctx, NULL);
        if (r)
                goto ERROR;
 
index e0d3b4498dc4b6d6e35658fa8a2496b9c87302df..09f49be2fe9ec42f292cb5a7d7b3fc8b7bd4d804 100644 (file)
@@ -69,7 +69,7 @@ int cli_upload_create(void* data, int argc, char* argv[]) {
                goto ERROR;
 
        // Connect to the build service
-       r = pakfire_buildservice_create(&service, cli_config->ctx);
+       r = pakfire_buildservice_create(&service, cli_config->ctx, NULL);
        if (r)
                goto ERROR;
 
index eeb09191f15956158895a8fe78870c27ff0da200..daccab6f2719023979b97def2eb9c6dbd913a3d0 100644 (file)
@@ -73,7 +73,7 @@ int cli_upload_delete(void* data, int argc, char* argv[]) {
                goto ERROR;
 
        // Connect to the build service
-       r = pakfire_buildservice_create(&service, cli_config->ctx);
+       r = pakfire_buildservice_create(&service, cli_config->ctx, NULL);
        if (r)
                goto ERROR;
 
index c8e5697e40092e6dbb638fa6292bcc9fc49f3967..7dc49cb51fdc4c6f5e0eab22414d25e342a54a19 100644 (file)
@@ -42,7 +42,7 @@ int cli_upload_list(void* data, int argc, char* argv[]) {
                goto ERROR;
 
        // Connect to the build service
-       r = pakfire_buildservice_create(&service, cli_config->ctx);
+       r = pakfire_buildservice_create(&service, cli_config->ctx, NULL);
        if (r)
                goto ERROR;
 
index d3bed7e969252ab5410a20ba8c025cecb5ad076f..9d449a90f0e22b75f7a847fb17f769117dd84164 100644 (file)
@@ -76,7 +76,7 @@ ERROR:
        return r;
 }
 
-static int pakfire_buildservice_setup(struct pakfire_buildservice* service) {
+static int pakfire_buildservice_setup(struct pakfire_buildservice* service, sd_event* loop) {
        struct pakfire_config* config = NULL;
        const char* url = NULL;
        const char* keytab = NULL;
@@ -111,7 +111,7 @@ static int pakfire_buildservice_setup(struct pakfire_buildservice* service) {
                goto ERROR;
 
        // Setup the HTTP client
-       r = pakfire_httpclient_create(&service->httpclient, service->ctx);
+       r = pakfire_httpclient_create(&service->httpclient, service->ctx, loop);
        if (r)
                goto ERROR;
 
@@ -139,7 +139,7 @@ static void pakfire_buildservice_free(struct pakfire_buildservice* service) {
 }
 
 PAKFIRE_EXPORT int pakfire_buildservice_create(
-               struct pakfire_buildservice** service, struct pakfire_ctx* ctx) {
+               struct pakfire_buildservice** service, struct pakfire_ctx* ctx, sd_event* loop) {
        struct pakfire_buildservice* s = NULL;
        int r;
 
@@ -155,7 +155,7 @@ PAKFIRE_EXPORT int pakfire_buildservice_create(
        s->nrefs = 1;
 
        // Setup everything
-       r = pakfire_buildservice_setup(s);
+       r = pakfire_buildservice_setup(s, loop);
        if (r)
                goto ERROR;
 
@@ -1015,3 +1015,10 @@ ERROR:
 
        return r;
 }
+
+/*
+       Called before the daemon's
+*/
+int pakfire_buildservice_daemon(struct pakfire_buildservice* service) {
+       return 0;
+}
index 9fd9cc5af69b3b4c2f0f9d087f818391f25748d4..5b3c796842f92cef67e5a6d0ef9cead8d2a9f346 100644 (file)
@@ -117,7 +117,7 @@ int pakfire_daemon_create(struct pakfire_daemon** daemon, struct pakfire_ctx* ct
                goto ERROR;
 
        // Connect to the buildservice
-       r = pakfire_buildservice_create(&d->service, d->ctx);
+       r = pakfire_buildservice_create(&d->service, d->ctx, d->loop);
        if (r)
                goto ERROR;
 
index eff633faf07dc606c3414192b269300182fdac6d..59b21d241c2de2bdb5cac6beef5ac6968b0dc307 100644 (file)
@@ -361,7 +361,7 @@ static int pakfire_dist_add_sources(struct pakfire* pakfire, struct pakfire_pack
        struct pakfire_ctx* ctx = pakfire_ctx(pakfire);
 
        // Create a HTTP client
-       r = pakfire_httpclient_create(&httpclient, ctx);
+       r = pakfire_httpclient_create(&httpclient, ctx, NULL);
        if (r)
                goto ERROR;
 
index 557bc789cf11e098bb65e87dfe127d496f7ded08..ebf7e974bcab6be3d23d964cdb5dc47d4e25437e 100644 (file)
@@ -276,15 +276,21 @@ ERROR:
        return r;
 }
 
-static int pakfire_httpclient_setup_loop(struct pakfire_httpclient* client) {
+static int pakfire_httpclient_setup_loop(struct pakfire_httpclient* client, sd_event* loop) {
        int r;
 
-       // Create a new event loop
-       r = sd_event_new(&client->loop);
-       if (r < 0) {
-               CTX_ERROR(client->ctx, "Could not setup event loop: %s\n", strerror(-r));
+       // Use the given loop
+       if (loop) {
+               client->loop = sd_event_ref(loop);
 
-               return r;
+       // Otherwise create a new loop
+       } else {
+               r = sd_event_new(&client->loop);
+               if (r < 0) {
+                       CTX_ERROR(client->ctx, "Could not setup event loop: %s\n", strerror(-r));
+
+                       return r;
+               }
        }
 
        // Create a new timer
@@ -409,7 +415,8 @@ static void pakfire_httpclient_free(struct pakfire_httpclient* client) {
        free(client);
 }
 
-int pakfire_httpclient_create(struct pakfire_httpclient** client, struct pakfire_ctx* ctx) {
+int pakfire_httpclient_create(struct pakfire_httpclient** client,
+               struct pakfire_ctx* ctx, sd_event* loop) {
        struct pakfire_httpclient* c = NULL;
        int r;
 
@@ -434,7 +441,7 @@ int pakfire_httpclient_create(struct pakfire_httpclient** client, struct pakfire
        c->max_parallel = DEFAULT_MAX_PARALLEL;
 
        // Setup event loop
-       r = pakfire_httpclient_setup_loop(c);
+       r = pakfire_httpclient_setup_loop(c, loop);
        if (r)
                goto ERROR;
 
index af11bc6b3ab3684c1dcc556ac2c2d1fbb606eee2..079a613f2fce99d690ed9776c9bebb3a3d6c41bf 100644 (file)
@@ -25,9 +25,12 @@ struct pakfire_buildservice;
 
 #include <json.h>
 
+#include <systemd/sd-event.h>
+
 #include <pakfire/ctx.h>
 
-int pakfire_buildservice_create(struct pakfire_buildservice** service, struct pakfire_ctx* ctx);
+int pakfire_buildservice_create(struct pakfire_buildservice** service,
+       struct pakfire_ctx* ctx, sd_event* loop);
 
 struct pakfire_buildservice* pakfire_buildservice_ref(struct pakfire_buildservice* service);
 struct pakfire_buildservice* pakfire_buildservice_unref(struct pakfire_buildservice* service);
@@ -72,4 +75,8 @@ int pakfire_buildservice_submit_stats(struct pakfire_buildservice* service);
 int pakfire_buildservice_job_finished(struct pakfire_buildservice* service,
        const char* uuid, int success, const char* logfile, const char** packages);
 
+// Daemon
+
+int pakfire_buildservice_daemon(struct pakfire_buildservice* service);
+
 #endif /* PAKFIRE_BUILDSERVICE_H */
index e937adb3c1a56094697a5790d80c485c8dd0e6ce..4c08a6c1dc2ca3409554c5b595cd087c68fee778 100644 (file)
 
 #include <curl/curl.h>
 
+#include <systemd/sd-event.h>
+
 struct pakfire_httpclient;
 
 #include <pakfire/ctx.h>
 #include <pakfire/xfer.h>
 
-int pakfire_httpclient_create(struct pakfire_httpclient** downloader, struct pakfire_ctx* ctx);
+int pakfire_httpclient_create(struct pakfire_httpclient** downloader,
+       struct pakfire_ctx* ctx, sd_event* loop);
 
 struct pakfire_httpclient* pakfire_httpclient_ref(struct pakfire_httpclient* downloader);
 struct pakfire_httpclient* pakfire_httpclient_unref(struct pakfire_httpclient* downloader);
index 4e1043997cc754e50bdc6be5e64a98830b74ab2f..36cd9dd58a9ff4f597364aa555235474a227ac05 100644 (file)
@@ -459,7 +459,7 @@ static int pakfire_repo_download_database(struct pakfire_repo* repo,
                return r;
 
        // Create a HTTP client
-       r = pakfire_httpclient_create(&httpclient, repo->ctx);
+       r = pakfire_httpclient_create(&httpclient, repo->ctx, NULL);
        if (r)
                goto ERROR;
 
@@ -626,7 +626,7 @@ static int pakfire_repo_refresh_mirrorlist(struct pakfire_repo* repo, const int
        }
 
        // Create a new HTTP client
-       r = pakfire_httpclient_create(&httpclient, repo->ctx);
+       r = pakfire_httpclient_create(&httpclient, repo->ctx, NULL);
        if (r)
                goto ERROR;
 
@@ -686,7 +686,7 @@ static int pakfire_repo_download_metadata(struct pakfire_repo* repo, const char*
        }
 
        // Create a HTTP client
-       r = pakfire_httpclient_create(&httpclient, repo->ctx);
+       r = pakfire_httpclient_create(&httpclient, repo->ctx, NULL);
        if (r)
                goto ERROR;
 
@@ -1296,7 +1296,7 @@ static int pakfire_repo_download(struct pakfire_repo* repo, const char* url,
        }
 
        // Create the HTTP client
-       r = pakfire_httpclient_create(&httpclient, repo->ctx);
+       r = pakfire_httpclient_create(&httpclient, repo->ctx, NULL);
        if (r)
                goto ERROR;
 
index 31b7e83f145a4936330a67cf8fdfc34eb62bf258..18b9ccbd8c39cdf3825ca683229bf9baad70ba07 100644 (file)
@@ -1903,7 +1903,7 @@ PAKFIRE_EXPORT int pakfire_transaction_download(struct pakfire_transaction* tran
        int r;
 
        // Initialize the HTTP client
-       r = pakfire_httpclient_create(&httpclient, transaction->ctx);
+       r = pakfire_httpclient_create(&httpclient, transaction->ctx, NULL);
        if (r) {
                ERROR(transaction->pakfire, "Could not initialize HTTP client: %m\n");
                return 1;
index fde51743e60f2827228691b0d1686b758ae0a1e5..78d7fa947d40dfbcc3132de069364fee504ad7b3 100644 (file)
@@ -31,7 +31,7 @@ static int test_create(const struct test* t) {
        int r = EXIT_FAILURE;
 
        // Create a HTTP client
-       ASSERT_SUCCESS(pakfire_httpclient_create(&client, t->ctx));
+       ASSERT_SUCCESS(pakfire_httpclient_create(&client, t->ctx, NULL));
 
        // Everything passed
        r = EXIT_SUCCESS;
index 9a0f55d21b3b28d6f76d70231552b5e08f272353..4f82c170098ace8caa8c66fd3796b431c7b4d051 100644 (file)
@@ -95,7 +95,7 @@ static int test_run(int i, struct test* t) {
 
        // Create a HTTP client (if requested)
        if (t->flags & TEST_WANTS_HTTPCLIENT) {
-               r = pakfire_httpclient_create(&t->httpclient, t->ctx);
+               r = pakfire_httpclient_create(&t->httpclient, t->ctx, NULL);
                if (r) {
                        LOG("ERROR: Could not initialize the HTTP client: %s\n", strerror(-r));
                        goto ERROR;