2010-07-13 12:15:46 +00:00
|
|
|
/*
|
|
|
|
Serval Distributed Numbering Architecture (DNA)
|
|
|
|
Copyright (C) 2010 Paul Gardner-Stephen
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2012-07-26 09:01:23 +00:00
|
|
|
#include <signal.h>
|
2012-05-08 02:49:52 +00:00
|
|
|
#include <unistd.h>
|
2012-09-27 01:32:58 +00:00
|
|
|
#include <time.h>
|
2012-02-05 05:45:19 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
2012-05-08 01:57:07 +00:00
|
|
|
#include <sys/stat.h>
|
2012-02-05 05:45:19 +00:00
|
|
|
|
2012-02-23 02:15:42 +00:00
|
|
|
#include "serval.h"
|
2012-12-04 03:42:28 +00:00
|
|
|
#include "conf.h"
|
2012-07-02 03:22:21 +00:00
|
|
|
#include "strbuf.h"
|
2012-07-24 06:09:36 +00:00
|
|
|
#include "strbuf_helpers.h"
|
2010-07-13 12:15:46 +00:00
|
|
|
|
2012-05-08 02:49:52 +00:00
|
|
|
#define PIDFILE_NAME "servald.pid"
|
|
|
|
#define STOPFILE_NAME "servald.stop"
|
|
|
|
|
2012-07-24 06:09:36 +00:00
|
|
|
#define EXEC_NARGS 20
|
|
|
|
char *exec_args[EXEC_NARGS + 1];
|
2012-05-09 09:36:44 +00:00
|
|
|
int exec_argc = 0;
|
|
|
|
|
2012-05-14 09:02:10 +00:00
|
|
|
int serverMode=0;
|
2012-05-09 09:36:44 +00:00
|
|
|
int servalShutdown = 0;
|
|
|
|
|
2012-05-08 01:53:43 +00:00
|
|
|
static int server_getpid = 0;
|
2010-07-13 12:15:46 +00:00
|
|
|
|
2012-05-09 09:36:44 +00:00
|
|
|
void signal_handler(int signal);
|
2012-07-26 09:01:23 +00:00
|
|
|
void crash_handler(int signal);
|
2012-04-12 23:55:03 +00:00
|
|
|
int getKeyring(char *s);
|
2011-08-08 14:41:46 +00:00
|
|
|
|
2012-05-08 01:53:43 +00:00
|
|
|
/** Return the PID of the currently running server process, return 0 if there is none.
|
|
|
|
*/
|
|
|
|
int server_pid()
|
|
|
|
{
|
|
|
|
const char *instancepath = serval_instancepath();
|
|
|
|
struct stat st;
|
2012-05-24 07:41:55 +00:00
|
|
|
if (stat(instancepath, &st) == -1) {
|
|
|
|
WHY_perror("stat");
|
|
|
|
return WHYF("Instance path '%s' non existant or not accessable"
|
2012-05-08 01:53:43 +00:00
|
|
|
" (Set SERVALINSTANCE_PATH to specify an alternate location)",
|
2012-05-24 07:41:55 +00:00
|
|
|
instancepath
|
2012-05-08 01:53:43 +00:00
|
|
|
);
|
2012-05-24 07:41:55 +00:00
|
|
|
}
|
2012-05-08 01:53:43 +00:00
|
|
|
if ((st.st_mode & S_IFMT) != S_IFDIR)
|
2012-05-24 07:41:55 +00:00
|
|
|
return WHYF("Instance path '%s' is not a directory", instancepath);
|
2012-05-08 01:53:43 +00:00
|
|
|
char filename[1024];
|
2012-05-08 02:49:52 +00:00
|
|
|
if (!FORM_SERVAL_INSTANCE_PATH(filename, PIDFILE_NAME))
|
2012-05-08 01:53:43 +00:00
|
|
|
return -1;
|
|
|
|
FILE *f = NULL;
|
|
|
|
if ((f = fopen(filename, "r"))) {
|
|
|
|
char buf[20];
|
|
|
|
fgets(buf, sizeof buf, f);
|
|
|
|
fclose(f);
|
|
|
|
int pid = atoi(buf);
|
|
|
|
if (pid > 0 && kill(pid, 0) != -1)
|
|
|
|
return pid;
|
2012-10-08 04:26:55 +00:00
|
|
|
INFOF("Unlinking stale pidfile %s", filename);
|
2012-05-08 01:53:43 +00:00
|
|
|
unlink(filename);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2011-08-08 14:41:46 +00:00
|
|
|
|
2012-05-09 09:36:44 +00:00
|
|
|
void server_save_argv(int argc, const char *const *argv)
|
|
|
|
{
|
|
|
|
/* Save our argv[] to use for relaunching */
|
2012-07-24 06:09:36 +00:00
|
|
|
for (exec_argc = 0; exec_argc < argc && exec_argc < EXEC_NARGS; ++exec_argc)
|
2012-05-09 09:36:44 +00:00
|
|
|
exec_args[exec_argc] = strdup(argv[exec_argc]);
|
2012-07-24 06:09:36 +00:00
|
|
|
exec_args[exec_argc] = NULL;
|
2012-05-09 09:36:44 +00:00
|
|
|
}
|
|
|
|
|
2012-05-07 09:21:05 +00:00
|
|
|
int server(char *backing_file)
|
2010-07-13 12:15:46 +00:00
|
|
|
{
|
2013-02-15 20:21:33 +00:00
|
|
|
IN();
|
2012-12-14 05:57:04 +00:00
|
|
|
/* For testing, it can be very helpful to delay the start of the server process, for example to
|
|
|
|
* check that the start/stop logic is robust.
|
2012-06-26 06:09:20 +00:00
|
|
|
*/
|
|
|
|
const char *delay = getenv("SERVALD_SERVER_START_DELAY");
|
2012-08-21 04:04:29 +00:00
|
|
|
if (delay)
|
|
|
|
sleep_ms(atoi(delay));
|
2012-06-26 06:09:20 +00:00
|
|
|
|
2012-05-14 09:02:10 +00:00
|
|
|
serverMode = 1;
|
2012-07-26 09:01:23 +00:00
|
|
|
|
|
|
|
/* Catch crash signals so that we can log a backtrace before expiring. */
|
|
|
|
struct sigaction sig;
|
|
|
|
sig.sa_handler = crash_handler;
|
|
|
|
sigemptyset(&sig.sa_mask); // Don't block any signals during handler
|
|
|
|
sig.sa_flags = SA_NODEFER | SA_RESETHAND; // So the signal handler can kill the process by re-sending the same signal to itself
|
|
|
|
sigaction(SIGSEGV, &sig, NULL);
|
|
|
|
sigaction(SIGFPE, &sig, NULL);
|
|
|
|
sigaction(SIGILL, &sig, NULL);
|
|
|
|
sigaction(SIGBUS, &sig, NULL);
|
|
|
|
sigaction(SIGABRT, &sig, NULL);
|
|
|
|
|
|
|
|
/* Catch SIGHUP etc so that we can respond to requests to do things, eg, shut down. */
|
|
|
|
sig.sa_handler = signal_handler;
|
|
|
|
sigemptyset(&sig.sa_mask); // Block the same signals during handler
|
|
|
|
sigaddset(&sig.sa_mask, SIGHUP);
|
|
|
|
sigaddset(&sig.sa_mask, SIGINT);
|
|
|
|
sigaddset(&sig.sa_mask, SIGQUIT);
|
|
|
|
sig.sa_flags = 0;
|
|
|
|
sigaction(SIGHUP, &sig, NULL);
|
|
|
|
sigaction(SIGINT, &sig, NULL);
|
|
|
|
sigaction(SIGQUIT, &sig, NULL);
|
2012-05-09 09:36:44 +00:00
|
|
|
|
2012-05-08 01:53:43 +00:00
|
|
|
/* Record PID to advertise that the server is now running */
|
2012-03-04 22:57:31 +00:00
|
|
|
char filename[1024];
|
2012-05-08 02:49:52 +00:00
|
|
|
if (!FORM_SERVAL_INSTANCE_PATH(filename, PIDFILE_NAME))
|
2013-02-15 20:21:33 +00:00
|
|
|
RETURN(-1);
|
2012-03-04 22:57:31 +00:00
|
|
|
FILE *f=fopen(filename,"w");
|
|
|
|
if (!f) {
|
2012-05-08 05:15:26 +00:00
|
|
|
WHY_perror("fopen");
|
2013-02-15 20:21:33 +00:00
|
|
|
RETURN(WHYF("Could not write to PID file %s", filename));
|
2012-03-04 22:57:31 +00:00
|
|
|
}
|
2012-05-08 01:53:43 +00:00
|
|
|
server_getpid = getpid();
|
|
|
|
fprintf(f,"%d\n", server_getpid);
|
2012-03-04 22:57:31 +00:00
|
|
|
fclose(f);
|
|
|
|
|
2012-06-22 03:55:41 +00:00
|
|
|
overlayServerMode();
|
2011-08-14 08:36:39 +00:00
|
|
|
|
2013-02-15 20:21:33 +00:00
|
|
|
RETURN(0);
|
2011-08-08 14:41:46 +00:00
|
|
|
}
|
|
|
|
|
2012-12-14 05:57:04 +00:00
|
|
|
/* Called periodically by the server process in its main loop.
|
|
|
|
*/
|
|
|
|
void server_config_reload(struct sched_ent *alarm)
|
|
|
|
{
|
|
|
|
switch (cf_reload()) {
|
|
|
|
case -1:
|
|
|
|
WARN("server continuing with prior config");
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
INFO("server config successfully reloaded");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (alarm) {
|
|
|
|
time_ms_t now = gettime_ms();
|
|
|
|
alarm->alarm = now + SERVER_CONFIG_RELOAD_INTERVAL_MS;
|
|
|
|
alarm->deadline = alarm->alarm + 1000;
|
|
|
|
schedule(alarm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-08 01:53:43 +00:00
|
|
|
/* Called periodically by the server process in its main loop.
|
|
|
|
*/
|
2012-07-02 03:49:54 +00:00
|
|
|
void server_shutdown_check(struct sched_ent *alarm)
|
2012-05-08 01:53:43 +00:00
|
|
|
{
|
|
|
|
if (servalShutdown) {
|
2012-06-28 06:07:36 +00:00
|
|
|
INFO("Shutdown flag set -- terminating with cleanup");
|
2012-05-08 02:49:52 +00:00
|
|
|
serverCleanUp();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
if (server_check_stopfile() == 1) {
|
2012-06-28 06:07:36 +00:00
|
|
|
INFO("Shutdown file exists -- terminating with cleanup");
|
2012-05-08 01:53:43 +00:00
|
|
|
serverCleanUp();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
/* If this server has been supplanted with another or Serval has been uninstalled, then its PID
|
|
|
|
file will change or be unaccessible. In this case, shut down without all the cleanup.
|
|
|
|
Perform this check at most once per second. */
|
2012-08-09 02:44:32 +00:00
|
|
|
static time_ms_t server_pid_time_ms = 0;
|
|
|
|
time_ms_t now = gettime_ms();
|
|
|
|
if (server_pid_time_ms == 0 || now - server_pid_time_ms > 1000) {
|
|
|
|
server_pid_time_ms = now;
|
2012-05-08 01:53:43 +00:00
|
|
|
if (server_pid() != server_getpid) {
|
2012-06-28 06:07:36 +00:00
|
|
|
WARNF("Server pid file no longer contains pid=%d -- shutting down without cleanup", server_getpid);
|
2012-05-08 01:53:43 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2012-07-02 03:49:54 +00:00
|
|
|
if (alarm){
|
2012-08-09 02:44:32 +00:00
|
|
|
alarm->alarm = now + 1000;
|
|
|
|
alarm->deadline = alarm->alarm + 5000;
|
2012-07-02 03:49:54 +00:00
|
|
|
schedule(alarm);
|
|
|
|
}
|
2012-05-08 01:53:43 +00:00
|
|
|
}
|
|
|
|
|
2012-05-08 02:49:52 +00:00
|
|
|
int server_create_stopfile()
|
|
|
|
{
|
|
|
|
char stopfile[1024];
|
|
|
|
if (!FORM_SERVAL_INSTANCE_PATH(stopfile, STOPFILE_NAME))
|
|
|
|
return -1;
|
|
|
|
FILE *f;
|
2012-07-03 06:06:51 +00:00
|
|
|
if ((f = fopen(stopfile, "w")) == NULL) {
|
|
|
|
WHY_perror("fopen");
|
|
|
|
return WHYF("Could not create stopfile '%s'", stopfile);
|
|
|
|
}
|
2012-05-08 02:49:52 +00:00
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-08 03:23:59 +00:00
|
|
|
int server_remove_stopfile()
|
|
|
|
{
|
|
|
|
char stopfile[1024];
|
|
|
|
if (!FORM_SERVAL_INSTANCE_PATH(stopfile, STOPFILE_NAME))
|
|
|
|
return -1;
|
|
|
|
if (unlink(stopfile) == -1) {
|
|
|
|
if (errno == ENOENT)
|
|
|
|
return 0;
|
2012-07-03 06:06:51 +00:00
|
|
|
WHY_perror("unlink");
|
|
|
|
return WHYF("Could not unlink stopfile '%s'", stopfile);
|
2012-05-08 03:23:59 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-05-08 02:49:52 +00:00
|
|
|
int server_check_stopfile()
|
|
|
|
{
|
|
|
|
char stopfile[1024];
|
|
|
|
if (!FORM_SERVAL_INSTANCE_PATH(stopfile, STOPFILE_NAME))
|
|
|
|
return -1;
|
|
|
|
int r = access(stopfile, F_OK);
|
|
|
|
if (r == 0)
|
|
|
|
return 1;
|
|
|
|
if (r == -1 && errno == ENOENT)
|
|
|
|
return 0;
|
2012-07-03 06:06:51 +00:00
|
|
|
WHY_perror("access");
|
|
|
|
WHYF("Cannot access stopfile '%s'", stopfile);
|
2012-05-08 02:49:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void serverCleanUp()
|
|
|
|
{
|
|
|
|
/* Try to remove shutdown and PID files and exit */
|
2012-05-08 03:23:59 +00:00
|
|
|
server_remove_stopfile();
|
2012-05-08 02:49:52 +00:00
|
|
|
char filename[1024];
|
2012-05-08 03:23:59 +00:00
|
|
|
if (FORM_SERVAL_INSTANCE_PATH(filename, PIDFILE_NAME))
|
2012-05-08 02:49:52 +00:00
|
|
|
unlink(filename);
|
2012-09-14 02:17:48 +00:00
|
|
|
|
|
|
|
if (FORM_SERVAL_INSTANCE_PATH(filename, "mdp.socket")) {
|
|
|
|
unlink(filename);
|
2012-05-08 02:49:52 +00:00
|
|
|
}
|
2012-07-19 08:29:45 +00:00
|
|
|
dna_helper_shutdown();
|
2012-05-08 02:49:52 +00:00
|
|
|
}
|
|
|
|
|
2012-05-09 09:36:44 +00:00
|
|
|
static void signame(char *buf, size_t len, int signal)
|
|
|
|
{
|
|
|
|
const char *desc = "";
|
|
|
|
switch(signal) {
|
|
|
|
#ifdef SIGHUP
|
|
|
|
case SIGHUP: desc = "HUP"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGINT
|
|
|
|
case SIGINT: desc = "INT"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGQUIT
|
|
|
|
case SIGQUIT: desc = "QUIT"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGILL
|
|
|
|
case SIGILL: desc = "ILL (not reset when caught)"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTRAP
|
|
|
|
case SIGTRAP: desc = "TRAP (not reset when caught)"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGABRT
|
|
|
|
case SIGABRT: desc = "ABRT"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGPOLL
|
|
|
|
case SIGPOLL: desc = "POLL ([XSR] generated, not supported)"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGEMT
|
|
|
|
case SIGEMT: desc = "EMT"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGFPE
|
|
|
|
case SIGFPE: desc = "FPE"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGKILL
|
|
|
|
case SIGKILL: desc = "KILL (cannot be caught or ignored)"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGBUS
|
|
|
|
case SIGBUS: desc = "BUS"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGSEGV
|
|
|
|
case SIGSEGV: desc = "SEGV"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGSYS
|
|
|
|
case SIGSYS: desc = "SYS"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGPIPE
|
|
|
|
case SIGPIPE: desc = "PIPE"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGALRM
|
|
|
|
case SIGALRM: desc = "ALRM"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTERM
|
|
|
|
case SIGTERM: desc = "TERM"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGURG
|
|
|
|
case SIGURG: desc = "URG"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGSTOP
|
|
|
|
case SIGSTOP: desc = "STOP"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTSTP
|
|
|
|
case SIGTSTP: desc = "TSTP"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGCONT
|
|
|
|
case SIGCONT: desc = "CONT"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGCHLD
|
|
|
|
case SIGCHLD: desc = "CHLD"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTTIN
|
|
|
|
case SIGTTIN: desc = "TTIN"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTTOU
|
|
|
|
case SIGTTOU: desc = "TTOU"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGIO
|
|
|
|
#if SIGIO != SIGPOLL
|
|
|
|
case SIGIO: desc = "IO"; break;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef SIGXCPU
|
|
|
|
case SIGXCPU: desc = "XCPU"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGXFSZ
|
|
|
|
case SIGXFSZ: desc = "XFSZ"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGVTALRM
|
|
|
|
case SIGVTALRM: desc = "VTALRM"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGPROF
|
|
|
|
case SIGPROF: desc = "PROF"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGWINCH
|
|
|
|
case SIGWINCH: desc = "WINCH"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGINFO
|
|
|
|
case SIGINFO: desc = "INFO"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR1
|
|
|
|
case SIGUSR1: desc = "USR1"; break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR2
|
|
|
|
case SIGUSR2: desc = "USR2"; break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
snprintf(buf, len, "SIG%s (%d) %s", desc, signal, strsignal(signal));
|
|
|
|
buf[len - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
void signal_handler(int signal)
|
|
|
|
{
|
|
|
|
char buf[80];
|
|
|
|
signame(buf, sizeof(buf), signal);
|
2012-07-03 06:06:51 +00:00
|
|
|
INFOF("Caught %s", buf);
|
2013-02-15 22:39:36 +00:00
|
|
|
WHYF("The following clue may help: %s",crash_handler_clue);
|
2013-02-15 07:45:18 +00:00
|
|
|
dump_stack();
|
|
|
|
|
2012-05-09 09:36:44 +00:00
|
|
|
switch (signal) {
|
|
|
|
case SIGHUP:
|
|
|
|
case SIGINT:
|
|
|
|
/* Terminate the server process. The shutting down should be done from the main-line code
|
|
|
|
rather than here, so we first try to tell the mainline code to do so. If, however, this is
|
|
|
|
not the first time we have been asked to shut down, then we will do it here. */
|
2012-07-02 03:49:54 +00:00
|
|
|
server_shutdown_check(NULL);
|
2012-05-09 09:36:44 +00:00
|
|
|
WHY("Asking Serval process to shutdown cleanly");
|
|
|
|
servalShutdown = 1;
|
|
|
|
return;
|
|
|
|
}
|
2012-07-26 09:01:23 +00:00
|
|
|
serverCleanUp();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2013-02-15 22:39:36 +00:00
|
|
|
char crash_handler_clue[1024]="no clue";
|
2012-07-26 09:01:23 +00:00
|
|
|
void crash_handler(int signal)
|
|
|
|
{
|
|
|
|
char buf[80];
|
|
|
|
signame(buf, sizeof(buf), signal);
|
|
|
|
WHYF("Caught %s", buf);
|
2013-02-15 22:39:36 +00:00
|
|
|
WHYF("The following clue may help: %s",crash_handler_clue);
|
2012-07-26 09:01:23 +00:00
|
|
|
dump_stack();
|
|
|
|
BACKTRACE;
|
2012-12-04 03:42:28 +00:00
|
|
|
if (config.server.respawn_on_crash) {
|
2012-07-26 09:01:23 +00:00
|
|
|
int i;
|
|
|
|
for(i=0;i<overlay_interface_count;i++)
|
|
|
|
if (overlay_interfaces[i].alarm.poll.fd>-1)
|
|
|
|
close(overlay_interfaces[i].alarm.poll.fd);
|
|
|
|
char execpath[160];
|
|
|
|
if (get_self_executable_path(execpath, sizeof execpath) != -1) {
|
|
|
|
strbuf b = strbuf_alloca(1024);
|
|
|
|
for (i = 0; i < exec_argc; ++i)
|
|
|
|
strbuf_append_shell_quotemeta(strbuf_puts(b, i ? " " : ""), exec_args[i]);
|
|
|
|
INFOF("Respawning %s as %s", execpath, strbuf_str(b));
|
|
|
|
execv(execpath, exec_args);
|
|
|
|
/* Quit if the exec() fails */
|
|
|
|
WHY_perror("execv");
|
|
|
|
} else {
|
|
|
|
WHY("Cannot respawn");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Now die of the same signal, so that our exit status reflects the cause.
|
|
|
|
INFOF("Re-sending signal %d to self", signal);
|
|
|
|
kill(getpid(), signal);
|
|
|
|
// If that didn't work, then die normally.
|
|
|
|
INFOF("exit(%d)", -signal);
|
|
|
|
exit(-signal);
|
2012-05-09 09:36:44 +00:00
|
|
|
}
|
|
|
|
|
2012-04-12 23:55:03 +00:00
|
|
|
int getKeyring(char *backing_file)
|
2011-08-08 14:41:46 +00:00
|
|
|
{
|
|
|
|
if (!backing_file)
|
2012-04-12 23:55:03 +00:00
|
|
|
{
|
|
|
|
exit(WHY("Keyring requires a backing file"));
|
2010-07-13 12:15:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-13 00:05:22 +00:00
|
|
|
if (keyring)
|
2012-04-12 23:55:03 +00:00
|
|
|
exit(WHY("Keyring being opened twice"));
|
2012-04-13 00:05:22 +00:00
|
|
|
keyring=keyring_open(backing_file);
|
|
|
|
/* unlock all entries with blank pins */
|
2013-02-13 06:19:52 +00:00
|
|
|
keyring_enter_pin(keyring, "");
|
2010-07-13 12:15:46 +00:00
|
|
|
}
|
2012-04-12 23:55:03 +00:00
|
|
|
keyring_seed(keyring);
|
2011-08-09 06:10:27 +00:00
|
|
|
|
2012-04-12 23:55:03 +00:00
|
|
|
return 0;
|
2010-07-13 12:15:46 +00:00
|
|
|
}
|