diff -r 8f2a834d1d68 -r ef6827505bd2 src/server/daemon/webserver.c --- a/src/server/daemon/webserver.c Fri Feb 24 11:17:53 2017 +0100 +++ b/src/server/daemon/webserver.c Mon Mar 06 17:32:26 2017 +0100 @@ -48,6 +48,8 @@ #include "../util/io.h" #include "../util/util.h" +#include "../../ucx/utils.h" + #include "../safs/common.h" #include "func.h" @@ -57,6 +59,7 @@ #include "webserver.h" #include "log.h" #include "auth.h" +#include "srvctrl.h" extern struct FuncStruct webserver_funcs[]; @@ -91,20 +94,6 @@ // init caches auth_cache_init(); - // create tmp dir and pid file - char *mkdir_cmd = NULL; - asprintf(&mkdir_cmd, "mkdir -p %s", cfg->tmp.ptr); - system(mkdir_cmd); - free(mkdir_cmd); - - char *pid_file_path = NULL; - asprintf(&pid_file_path, "%s/pid", cfg->tmp.ptr); - FILE *pidfile = fopen(pid_file_path, "w"); // TODO: check error - pid_t pid = getpid(); - fprintf(pidfile, "%d", pid); - fclose(pidfile); - free(pid_file_path); - // init SAFs common_saf_init(); @@ -168,6 +157,50 @@ "server must be started as root to change uid"); } + // create tmp dir and pid file + char *mkdir_cmd = NULL; + asprintf(&mkdir_cmd, "mkdir -p %s", cfg->tmp.ptr); + system(mkdir_cmd); + free(mkdir_cmd); + + char *pid_file_path = NULL; + asprintf(&pid_file_path, "%s/pid", cfg->tmp.ptr); + FILE *pidfile = fopen(pid_file_path, "w"); // TODO: check error + pid_t pid = getpid(); + fprintf(pidfile, "%d", pid); + fclose(pidfile); + free(pid_file_path); + + // create unix domain socket for server control + sstr_t tmp_priv = ucx_sprintf("%s/private", cfg->tmp.ptr); + // TODO: remove existing private dir + if(mkdir(tmp_priv.ptr, S_IRWXU)) { + if(errno == EEXIST) { + if(chmod(tmp_priv.ptr, S_IRWXU)) { + log_ereport( + LOG_CATASTROPHE, + "cannot change permissions of tmp dir %s:", + tmp_priv.ptr, + strerror(errno)); + return 0; + } + } else { + log_ereport( + LOG_CATASTROPHE, + "cannot create tmp dir %s:", + tmp_priv.ptr, + strerror(errno)); + return -1; + } + } + + + // create srvctrl unix domain socket + // this socket is used for stop, reconfigure and other operations + if(srvctrl_init(cfg)) { + return -1; + } + //endpwent(); // TODO: close or not? //free(pwbuf); // TODO: ? @@ -190,6 +223,8 @@ void webserver_shutdown() { log_ereport(LOG_INFORM, "webserver shutdown"); + srvctrl_shutdown(); + // execute restart callbacks RestartCallback *re = atrestart; while(re) { @@ -198,6 +233,16 @@ } } +int webserver_reconfig() { + if(cfgmgr_load_config(NULL) != 0) { + return -1; + } + // start newly created listeners + start_all_listener(); + + return 0; +} + void webserver_atrestart(void (*fn)(void *), void *data) { RestartCallback *cb = malloc(sizeof(RestartCallback)); cb->func = fn;