main: store session data to disk on receipt of SIGUSR1 or SIGHUP. On HUP terminate self and re-exec

This commit is contained in:
Jo-Philipp Wich 2013-09-04 17:09:51 +02:00
parent aa2afdb739
commit 524032c291
3 changed files with 36 additions and 4 deletions

2
exec.c
View file

@ -50,7 +50,7 @@ rpc_errno_status(void)
}
}
static const char *
const char *
rpc_exec_lookup(const char *cmd)
{
struct stat s;

View file

@ -78,6 +78,8 @@ struct rpc_exec_context {
rpc_exec_done_cb_t finish_cb;
};
const char *rpc_exec_lookup(const char *cmd);
int rpc_exec(const char **args, rpc_exec_write_cb_t in,
rpc_exec_read_cb_t out, rpc_exec_read_cb_t err,
rpc_exec_done_cb_t end, void *priv, struct ubus_context *ctx,

36
main.c
View file

@ -26,8 +26,34 @@
#include <rpcd/session.h>
#include <rpcd/uci.h>
#include <rpcd/plugin.h>
#include <rpcd/exec.h>
static struct ubus_context *ctx;
static bool respawn = false;
static void
handle_signal(int sig)
{
rpc_session_freeze();
uloop_cancelled = true;
respawn = (sig == SIGHUP);
}
static void
exec_self(int argc, char **argv)
{
int i;
const char *cmd = rpc_exec_lookup(argv[0]);
char **args = calloc(argc + 1, sizeof(char *));
if (!cmd || !args)
return;
for (i = 0; i < argc; i++)
args[i] = argv[i];
execv(cmd, (char * const *)args);
}
int main(int argc, char **argv)
{
@ -45,9 +71,8 @@ int main(int argc, char **argv)
}
signal(SIGPIPE, SIG_IGN);
argc -= optind;
argv += optind;
signal(SIGHUP, handle_signal);
signal(SIGUSR1, handle_signal);
uloop_init();
@ -63,9 +88,14 @@ int main(int argc, char **argv)
rpc_uci_api_init(ctx);
rpc_plugin_api_init(ctx);
rpc_session_thaw();
uloop_run();
ubus_free(ctx);
uloop_done();
if (respawn)
exec_self(argc, argv);
return 0;
}