Start dna helper immediately (it's convenient for starting another service)

This commit is contained in:
Jeremy Lakeman 2012-09-18 12:24:33 +09:30
parent 09dd9332f8
commit e854409e0b
3 changed files with 23 additions and 17 deletions

View File

@ -144,9 +144,25 @@ dna_helper_close_pipes()
}
}
static int
dna_helper_start(const char *command, const char *arg, const char *mysid)
int
dna_helper_start()
{
const char *command = confValueGet("dna.helper.executable", NULL);
const char *arg = confValueGet("dna.helper.argv.1", NULL);
if (!command || !command[0]) {
/* Check if we have a helper configured. If not, then set
dna_helper_pid to magic value of 0 so that we don't waste time
in future looking up the dna helper configuration value. */
INFO("DNAHELPER none configured");
dna_helper_pid = 0;
return 0;
}
if (!my_subscriber)
return WHY("Unable to lookup my SID");
const char *mysid = alloca_tohex_sid(my_subscriber->sid);
dna_helper_close_pipes();
int stdin_fds[2], stdout_fds[2], stderr_fds[2];
if (pipe(stdin_fds) == -1)
@ -557,21 +573,7 @@ dna_helper_enqueue(overlay_mdp_frame *mdp, const char *did, const unsigned char
return 0;
// Only try to restart a DNA helper process if the previous one is well and truly gone.
if (dna_helper_pid == -1 && dna_helper_stdin == -1 && dna_helper_stdout == -1 && dna_helper_stderr == -1) {
const char *dna_helper_executable = confValueGet("dna.helper.executable", NULL);
const char *dna_helper_arg1 = confValueGet("dna.helper.argv.1", NULL);
if (!dna_helper_executable || !dna_helper_executable[0]) {
/* Check if we have a helper configured. If not, then set
dna_helper_pid to magic value of 0 so that we don't waste time
in future looking up the dna helper configuration value. */
INFO("DNAHELPER none configured");
dna_helper_pid = 0;
return 0;
}
if (!my_subscriber)
return WHY("Unable to lookup my SID");
if (dna_helper_start(dna_helper_executable, dna_helper_arg1, alloca_tohex_sid(my_subscriber->sid)) == -1) {
if (dna_helper_start() == -1) {
/* Something broke, bail out */
return WHY("DNAHELPER start failed");
}

View File

@ -150,6 +150,9 @@ schedule(&_sched_##X); }
the server's listen socket is in the list for poll() */
if (rhizome_enabled()) rhizome_http_server_start();
// start the dna helper if configured
dna_helper_start();
/* Pick next rhizome files to grab every few seconds
from the priority list continuously being built from observed
bundle announcements */

View File

@ -921,6 +921,7 @@ int stopAudio();
#define SERVER_RUNNING 4
int server_probe(int *pid);
int dna_helper_start();
int dna_helper_shutdown();
int dna_helper_enqueue(overlay_mdp_frame *mdp, const char *did, const unsigned char *requestorSid);
int dna_return_resolution(overlay_mdp_frame *mdp, unsigned char *fromSid,