From 37b02129149a602af175a39348acace4c0828914 Mon Sep 17 00:00:00 2001 From: Philip Meulengracht Date: Wed, 6 Nov 2024 15:32:31 +0100 Subject: [PATCH] many: build fixes --- daemons/cookd/client.c | 19 ++++-- daemons/cookd/include/threading.h | 5 +- daemons/cookd/main.c | 13 ++-- daemons/cookd/private.h | 6 +- daemons/cookd/server/api.c | 4 +- daemons/cookd/server/server.c | 15 +++-- daemons/waiterd/api/waiterd.c | 2 +- tools/bake/commands/CMakeLists.txt | 1 + tools/bake/commands/fridge.c | 95 ++++++++++++++++----------- tools/bake/commands/remote_download.c | 3 +- 10 files changed, 96 insertions(+), 67 deletions(-) diff --git a/daemons/cookd/client.c b/daemons/cookd/client.c index 265df69a..d8303fbb 100644 --- a/daemons/cookd/client.c +++ b/daemons/cookd/client.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "private.h" @@ -85,29 +86,30 @@ static int init_link_config(struct gracht_link_socket* link, enum gracht_link_ty socklen_t size; int domain = 0; int status; + VLOG_DEBUG("cookd", "init_link_config(link=%i, type=%s)\n", type, config->type); if (!strcmp(config->type, "local")) { status = __configure_local(&addr_storage, config->address); if (status) { - fprintf(stderr, "init_link_config failed to configure local link\n"); + VLOG_ERROR("cookd", "init_link_config failed to configure local link\n"); return status; } domain = AF_LOCAL; size = __local_size(); - printf("listening at %s\n", config->address); + VLOG_TRACE("cookd", "listening at %s\n", config->address); } else if (!strcmp(config->type, "inet4")) { __configure_inet4(&addr_storage, config); domain = AF_INET; size = sizeof(struct sockaddr_in); - printf("listening on %s:%u\n", config->address, config->port); + VLOG_TRACE("cookd", "listening on %s:%u\n", config->address, config->port); } else if (!strcmp(config->type, "inet6")) { // TODO domain = AF_INET6; size = sizeof(struct sockaddr_in6); } else { - fprintf(stderr, "init_link_config invalid link type %s\n", config->type); + VLOG_ERROR("cookd", "init_link_config invalid link type %s\n", config->type); return -1; } @@ -125,12 +127,13 @@ int cookd_initialize_client(gracht_client_t** clientOut) gracht_client_t* client = NULL; struct cookd_config_address apiAddress; int code; + VLOG_DEBUG("cookd", "cookd_initialize_client()\n"); cookd_config_api_address(&apiAddress); code = gracht_link_socket_create(&link); if (code) { - fprintf(stderr, "cookd_initialize_client: failed to initialize socket\n"); + VLOG_ERROR("cookd", "cookd_initialize_client: failed to initialize socket\n"); return code; } @@ -141,13 +144,15 @@ int cookd_initialize_client(gracht_client_t** clientOut) code = gracht_client_create(&clientConfiguration, &client); if (code) { - printf("cookd_initialize_client: error initializing client library %i, %i\n", errno, code); + VLOG_ERROR("cookd", "cookd_initialize_client: error initializing client library %i, %i\n", errno, code); return code; } code = gracht_client_connect(client); if (code) { - printf("cookd_initialize_client: failed to connect client %i, %i\n", errno, code); + VLOG_ERROR("cookd", "cookd_initialize_client: failed to connect client %i, %i\n", errno, code); + gracht_client_shutdown(client); + return code; } *clientOut = client; diff --git a/daemons/cookd/include/threading.h b/daemons/cookd/include/threading.h index 1e8847a7..6f924f2c 100644 --- a/daemons/cookd/include/threading.h +++ b/daemons/cookd/include/threading.h @@ -19,7 +19,7 @@ #ifndef __COOKD_THREADS_H__ #define __COOKD_THREADS_H__ -#include "cookd-config.h" +//#include "cookd-config.h" #if defined(__clang__) #define __TLS_VAR __thread @@ -52,9 +52,10 @@ typedef pthread_t thrd_t; #define cnd_destroy pthread_cond_destroy #define cnd_wait pthread_cond_wait #define cnd_signal pthread_cond_signal +#define cnd_broadcast pthread_cond_broadcast #define thrd_join(thr, ret) pthread_join(thr, (void**)ret) -#define thrd_create(thrp, func, arg) pthread_create(thrp, NULL, func, arg) +#define thrd_create(thrp, func, arg) pthread_create(thrp, NULL, (void * (*)(void *))func, arg) #elif defined(_WIN32) #include diff --git a/daemons/cookd/main.c b/daemons/cookd/main.c index 6de5b37e..2ef49a78 100644 --- a/daemons/cookd/main.c +++ b/daemons/cookd/main.c @@ -68,21 +68,21 @@ int main(int argc, char** argv) // initialize directories status = chef_dirs_initialize(); if (status) { - fprintf(stderr, "cookd: failed to initialize directories\n"); + VLOG_ERROR("cookd", "failed to initialize directories\n"); return -1; } // load config status = cookd_config_load(chef_dirs_config()); if (status) { - fprintf(stderr, "cookd: failed to load configuration\n"); + VLOG_ERROR("cookd", "failed to load configuration\n"); return -1; } // add log file to vlog debuglog = chef_dirs_contemporary_file("cookd", ".log", NULL); if (debuglog == NULL) { - fprintf(stderr, "cookd: failed to open log file\n"); + VLOG_ERROR("cookd", "failed to open log file\n"); return -1; } vlog_add_output(debuglog, 1); @@ -91,19 +91,18 @@ int main(int argc, char** argv) // initialize the client status = cookd_initialize_client(&client); if (status) { - fprintf(stderr, "cookd: failed to initialize the client\n"); + VLOG_ERROR("cookd", "failed to initialize the client\n"); goto cleanup; } // initialize the server status = cookd_server_init(1 /* needs to be configurable */); if (status) { - fprintf(stderr, "cookd: failed to initialize server subsystem\n"); + VLOG_ERROR("cookd", "failed to initialize server subsystem\n"); goto cleanup; } - // event loop - printf("entering main message loop"); + VLOG_TRACE("cookd", "entering main message loop"); for (;;) { gracht_client_wait_message(client, NULL, GRACHT_MESSAGE_BLOCK); } diff --git a/daemons/cookd/private.h b/daemons/cookd/private.h index a9afc54f..77407029 100644 --- a/daemons/cookd/private.h +++ b/daemons/cookd/private.h @@ -16,8 +16,8 @@ * */ -#ifndef __COOKD_SERVER_H__ -#define __COOKD_SERVER_H__ +#ifndef __COOKD_PRIVATE_H__ +#define __COOKD_PRIVATE_H__ #include @@ -42,4 +42,4 @@ extern void cookd_config_api_address(struct cookd_config_address* address); */ extern int cookd_initialize_client(gracht_client_t** clientOut); -#endif //!__COOKD_SERVER_H__ +#endif //!__COOKD_PRIVATE_H__ diff --git a/daemons/cookd/server/api.c b/daemons/cookd/server/api.c index b52b3499..7debf82d 100644 --- a/daemons/cookd/server/api.c +++ b/daemons/cookd/server/api.c @@ -76,10 +76,10 @@ void chef_waiterd_cook_event_build_request_invocation(gracht_client_t* client, c } status = chef_waiterd_cook_status(client, &msg, &(struct chef_cook_build_event) { - .id = id, + .id = (char*)id, .status = buildStatus }); if (status) { - + VLOG_ERROR("api", "failed to update the waiterd daemon for build id %s\n", id); } } diff --git a/daemons/cookd/server/server.c b/daemons/cookd/server/server.c index 48c38b1d..0b928a88 100644 --- a/daemons/cookd/server/server.c +++ b/daemons/cookd/server/server.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -68,10 +69,10 @@ static void __cookd_builder_request_delete(struct __cookd_builder_request* reque if (request == NULL) { return; } - free(request->options.architecture); - free(request->options.platform); - free(request->options.recipe_path); - free(request->options.url); + free((char*)request->options.architecture); + free((char*)request->options.platform); + free((char*)request->options.recipe_path); + free((char*)request->options.url); free(request->id); free(request); } @@ -144,7 +145,7 @@ static int __cookd_builder_main(void* arg) this->queue->queue.head = request->list_header.next; } mtx_unlock(&this->queue->lock); - cookd_server_build(request->id, &request->options); + __cookd_server_build(request->id, &request->options); __cookd_builder_request_delete(request); } @@ -193,8 +194,8 @@ static void __cookd_server_delete(struct __cookd_server* server) return; } - list_destroy(&server->builders, __cookd_builder_delete); - list_destroy(&server->queue, __cookd_builder_request_delete); + list_destroy(&server->builders, (void(*)(void*))__cookd_builder_delete); + list_destroy(&server->queue.queue, (void(*)(void*))__cookd_builder_request_delete); mtx_destroy(&server->queue.lock); cnd_destroy(&server->queue.signal); } diff --git a/daemons/waiterd/api/waiterd.c b/daemons/waiterd/api/waiterd.c index e605aaeb..a5872b66 100644 --- a/daemons/waiterd/api/waiterd.c +++ b/daemons/waiterd/api/waiterd.c @@ -55,7 +55,7 @@ void chef_waiterd_build_invocation( } // redirect request - chef_waiterd_cook_event_build_request_single(message->server, cook->client, request); + chef_waiterd_cook_event_build_request_single(message->server, cook->client, &wreq->guid[0], request); } void chef_waiterd_status_invocation(struct gracht_message* message, const char* id) diff --git a/tools/bake/commands/CMakeLists.txt b/tools/bake/commands/CMakeLists.txt index c0659928..5d4a9b69 100644 --- a/tools/bake/commands/CMakeLists.txt +++ b/tools/bake/commands/CMakeLists.txt @@ -12,6 +12,7 @@ add_library(bake-commands STATIC init.c recipe_specification.c remote_build.c + remote_download.c remote_init.c remote_resume.c remote.c diff --git a/tools/bake/commands/fridge.c b/tools/bake/commands/fridge.c index 0393006f..64f15aa2 100644 --- a/tools/bake/commands/fridge.c +++ b/tools/bake/commands/fridge.c @@ -24,15 +24,33 @@ #include #include +#include "chef-config.h" #include "commands.h" +int fridge_list_main(int argc, char** argv, char** envp, struct bake_command_options* options) { return 0; } +int fridge_update_main(int argc, char** argv, char** envp, struct bake_command_options* options) { return 0; } +int fridge_remove_main(int argc, char** argv, char** envp, struct bake_command_options* options) { return 0; } +int fridge_clean_main(int argc, char** argv, char** envp, struct bake_command_options* options) { return 0; } + +struct command_handler { + char* name; + int (*handler)(int argc, char** argv, char** envp, struct bake_command_options* options); +}; + +static struct command_handler g_commands[] = { + { "list", fridge_list_main }, + { "update", fridge_update_main }, + { "remove", fridge_remove_main }, + { "clean", fridge_clean_main } +}; + static void __print_help(void) { printf("Usage: bake fridge [options]\n"); printf(" This sub-command allows some management of the fridge for the current\n"); printf(" user. Ingredients are automatically added, however unless the recipe requires\n"); printf(" specific versions ingredients may need to be manually refreshed.\n\n"); - printf(" We also allow removal, cleaning and to see which ones are stored.\n\n"); + printf(" We also allow removal, cleaning and to list stored ingredients.\n\n"); printf("Commands:\n"); printf(" list go through the configuration wizard\n"); printf(" update executes a recipe remotely\n"); @@ -46,31 +64,23 @@ static void __print_help(void) printf(" Shows this help message\n"); } -int fridge_main(int argc, char** argv, char** envp, struct bake_command_options* options) +static struct command_handler* __get_command(const char* command) { - struct list_item* item; - int status; - const char* arch; - - // handle individual help command - if (argc > 2) { - for (int i = 2; i < argc; i++) { - if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { - __print_help(); - return 0; - } + for (int i = 0; i < sizeof(g_commands) / sizeof(struct command_handler); i++) { + if (!strcmp(command, g_commands[i].name)) { + return &g_commands[i]; } } + return NULL; +} - if (options->recipe == NULL) { - fprintf(stderr, "bake: no recipe specified\n"); - return -1; - } - - // get the architecture from the list - arch = ((struct list_item_string*)options->architectures.head)->value; +int fridge_main(int argc, char** argv, char** envp, struct bake_command_options* options) +{ + struct command_handler* command = NULL; + int i; + int status; - status = fridge_initialize(options->platform, arch); + status = fridge_initialize(CHEF_PLATFORM_STR, CHEF_ARCHITECTURE_STR); if (status != 0) { fprintf(stderr, "bake: failed to initialize fridge\n"); return -1; @@ -84,22 +94,33 @@ int fridge_main(int argc, char** argv, char** envp, struct bake_command_options* } atexit(chefclient_cleanup); - // iterate through all ingredients - printf("bake: fetching %i host ingredients\n", options->recipe->environment.host.ingredients.count); - for (item = options->recipe->environment.host.ingredients.head; item != NULL; item = item->next) { - struct recipe_ingredient* ingredient = (struct recipe_ingredient*)item; - - // fetch the ingredient - status = fridge_ensure_ingredient(&(struct fridge_ingredient) { - .name = ingredient->name, - .channel = ingredient->channel, - .version = ingredient->version, - .arch = arch, - .platform = options->platform - }, NULL); - if (status != 0) { - fprintf(stderr, "bake: failed to fetch ingredient %s\n", ingredient->name); + // handle individual commands as well as --help and --version + // locate the fridge command on the cmdline + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "fridge")) { + i++; + break; + } + } + + if (i < argc) { + if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { + __print_help(); + return 0; + } + + if (!strcmp(argv[i], "--version")) { + printf("bake: version " PROJECT_VER "\n"); + return 0; } + + command = __get_command(argv[i]); + } + + if (command == NULL) { + fprintf(stderr, "bake: command must be supplied for 'bake fridge'\n"); + __print_help(); + return -1; } - return 0; + return command->handler(argc, argv, envp, options); } diff --git a/tools/bake/commands/remote_download.c b/tools/bake/commands/remote_download.c index 0defdad0..3b51b540 100644 --- a/tools/bake/commands/remote_download.c +++ b/tools/bake/commands/remote_download.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -212,7 +213,7 @@ static int __discover_artifacts(gracht_client_t* client, struct list* builds, en list_foreach(builds, li) { struct __build* build = (struct __build*)li; - const char* link; + char* link; // if the build was not successful, then we don't query for the // package link