Skip to content

Commit

Permalink
many: build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Meulengracht committed Nov 6, 2024
1 parent 6b698bc commit 6dd3273
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 67 deletions.
19 changes: 12 additions & 7 deletions daemons/cookd/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <vlog.h>

#include "private.h"

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions daemons/cookd/include/threading.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <windows.h>
Expand Down
13 changes: 6 additions & 7 deletions daemons/cookd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions daemons/cookd/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*
*/

#ifndef __COOKD_SERVER_H__
#define __COOKD_SERVER_H__
#ifndef __COOKD_PRIVATE_H__
#define __COOKD_PRIVATE_H__

#include <gracht/client.h>

Expand All @@ -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__
4 changes: 2 additions & 2 deletions daemons/cookd/server/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
15 changes: 8 additions & 7 deletions daemons/cookd/server/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <libfridge.h>
#include <server.h>
#include <stdlib.h>
#include <string.h>
#include <threading.h>
#include <vlog.h>

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion daemons/waiterd/api/waiterd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tools/bake/commands/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
95 changes: 58 additions & 37 deletions tools/bake/commands/fridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,33 @@
#include <stdlib.h>
#include <string.h>

#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 <command> [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");
Expand All @@ -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;
Expand All @@ -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);
}
3 changes: 2 additions & 1 deletion tools/bake/commands/remote_download.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <chef/dirs.h>
#include <chef/list.h>
#include <chef/platform.h>
#include <chef/remote.h>
#include <chef/storage/download.h>
#include <ctype.h>
#include <stdio.h>
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6dd3273

Please sign in to comment.