diff --git a/inc/lektor/net.h b/inc/lektor/net.h index e9985dfc49d267bc0ff314e1f099954e08da16d8..0e69299543c0735b6485c3e316b5269bbd1ff603 100644 --- a/inc/lektor/net.h +++ b/inc/lektor/net.h @@ -43,7 +43,7 @@ struct lkt_repo { }; /* Load the repo as a module */ -int load_repo_https(void *mod, struct lkt_state *srv, void *handle); +int load_repo_https(va_list *); /* Download stuff */ int repo_get_id (struct lkt_repo *const repo, const uint64_t id, struct kara_metadata *mdt); diff --git a/inc/lektor/reg.h b/inc/lektor/reg.h index 0ac197100001c0c4e31ffa5dc87de0d42f72c909..1e43acb6958dff9dcd906f9e5e67a322636437ed 100644 --- a/inc/lektor/reg.h +++ b/inc/lektor/reg.h @@ -12,7 +12,7 @@ struct module_reg { const char *name; union { reg_func func; - void *obj; + struct module_reg *obj; }; }; @@ -32,8 +32,9 @@ struct module_reg { #endif /* Import a reg */ +#define REG_DECLARE(reg) extern struct module_reg *reg; #define REG_IMPORT(reg, as) \ - extern struct module_reg *reg; \ + REG_DECLARE(reg) \ static struct module_reg *as = reg; /* Call a function from a reg. */ diff --git a/src/main/server.c b/src/main/server.c index a7e772c3d81f349ace4135d52053ab39e00660ac..02a9023594212187e0236b070c244a4fb4e15074 100644 --- a/src/main/server.c +++ b/src/main/server.c @@ -16,17 +16,18 @@ #include <unistd.h> #include <string.h> #include <strings.h> -#include <pwd.h> #include <pthread.h> -REG_BEGIN(server_reg) -REG_ADD(load_repo_https) -REG_END() +REG_DECLARE(repo_reg) int main(int argc, char *argv[]) { - struct passwd *pw = getpwuid(getuid()); + REG_BEGIN(server_reg) + REG_ADD(load_repo_https) + REG_REGISTER("repo", repo_reg) + REG_END() + char exe[PATH_MAX]; int autoclear, check_exclusive = 1, opt; char *conf_file = safe_zero_malloc(PATH_MAX * sizeof(char)); @@ -110,12 +111,11 @@ normal_launch: lkt_queue_make_available(&srv.queue, lkt_event_prop); char *module = safe_malloc(sizeof(char) * PATH_MAX); - struct module_reg *player_mod; - void *player_handle; + struct module_reg *player_mod, *repo_mod; + void *player_handle, *repo_handle; database_config_get_text(srv.db, "player", "module", module, PATH_MAX); reg_import(module, &player_mod, &player_handle); - RETURN_IF(load_module_by_name(&srv, "player", &srv.win), "Can't load module player", 3); - RETURN_IF(load_module_by_name(&srv, "repo", &srv.repo), "Can't load module repo", 3); + reg_import("repo", &repo_mod, &repo_handle); free(module); void *handle = NULL; @@ -129,9 +129,8 @@ normal_launch: lkt_queue_send(&srv.queue, lkt_event_play_pos, (void *) (size_t) strtol(env_current, NULL, 0)); } - LOG_INFO("GENERAL", "Lektor was %s, user: %s, shell: %s, home: %s", - env_get(LKT_ENV_RESTART) ? "restarted" : "started", - pw->pw_name, pw->pw_shell, pw->pw_dir); + LOG_INFO("GENERAL", "Lektor was %s", + env_get(LKT_ENV_RESTART) ? "restarted" : "started"); lkt_listen(&srv); return EXIT_FAILURE; diff --git a/src/module/repo.c b/src/module/repo.c index 19f2cf662ea83ae7dcaf41e5dcf76b4b3f69c933..aa9dace4e90068156672f897bd34226e8e638a87 100644 --- a/src/module/repo.c +++ b/src/module/repo.c @@ -12,6 +12,7 @@ #include <sys/stat.h> #include <fcntl.h> #include <time.h> +#include <stdarg.h> #include <common/common.h> #include <mthread/mthread.h> @@ -91,12 +92,15 @@ repo_new(struct lkt_repo *const repo_, struct lkt_state *srv) } int -load_repo_https(void *mod, struct lkt_state *srv, void *handle) +load_repo_https(va_list *va) { - UNUSED(handle); - RETURN_UNLESS(mod, "Invalid argument", 1); - struct lkt_repo *repo = mod; - return repo_new(repo, srv); + va_list copy; + va_copy(copy, *va); + struct lkt_repo *repo = va_arg(copy, struct lkt_repo *); + struct lkt_state *srv = va_arg(copy, struct lkt_state *); + int ret = repo_new(repo, srv); + va_end(copy); + return ret; } void