Skip to content
This repository has been archived by the owner on Aug 22, 2021. It is now read-only.

Commit

Permalink
ncd: modules/daemon: Implement custom retry time.
Browse files Browse the repository at this point in the history
  • Loading branch information
ambrop72 committed Mar 1, 2015
1 parent 79524cb commit 1cdcaf8
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions ncd/modules/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
* start the 'agetty' program.
* "username":username_string - Start the process under the permissions of the
* specified user.
* "retry_time":milliseconds - Wait for this long after the daemon exits
* unexpectedtly before starting it again.
*/

#include <stdlib.h>
Expand All @@ -61,7 +63,7 @@

#include <generated/blog_channel_ncd_daemon.h>

#define RETRY_TIME 10000
#define DEFAULT_RETRY_TIME 10000

#define STATE_RETRYING 1
#define STATE_RUNNING 2
Expand All @@ -70,6 +72,7 @@
struct instance {
NCDModuleInst *i;
NCDValRef cmd_arg;
btime_t retry_time;
NCDBProcessOpts opts;
BTimer timer;
BProcess process;
Expand Down Expand Up @@ -214,6 +217,21 @@ static void process_handler (struct instance *o, int normally, uint8_t normally_
o->state = STATE_RETRYING;
}

static int opts_func_unknown (void *user, NCDValRef key, NCDValRef val)
{
struct instance *o = user;

if (NCDVal_IsString(key) && NCDVal_StringEquals(key, "retry_time")) {
if (!ncd_read_time(val, &o->retry_time)) {
ModuleLog(o->i, BLOG_ERROR, "retry_time: bad value");
return 0;
}
return 1;
}

return 0;
}

static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new_params *params)
{
struct instance *o = vo;
Expand All @@ -229,12 +247,13 @@ static void func_new (void *vo, NCDModuleInst *i, const struct NCDModuleInst_new
}

// init options
if (!NCDBProcessOpts_Init(&o->opts, opts_arg, NULL, NULL, i, BLOG_CURRENT_CHANNEL)) {
o->retry_time = DEFAULT_RETRY_TIME;
if (!NCDBProcessOpts_Init(&o->opts, opts_arg, opts_func_unknown, o, i, BLOG_CURRENT_CHANNEL)) {
goto fail0;
}

// init timer
BTimer_Init(&o->timer, RETRY_TIME, (BTimer_handler)timer_handler, o);
BTimer_Init(&o->timer, o->retry_time, (BTimer_handler)timer_handler, o);

// signal up
NCDModuleInst_Backend_Up(i);
Expand Down

0 comments on commit 1cdcaf8

Please sign in to comment.