aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Iliopoulos <ailiopoulos@suse.com>2020-01-16 02:15:51 +0100
committerDaniel Borkmann <daniel@iogearbox.net>2020-01-16 12:24:06 +0100
commitffe6b92fd223cf56971f6d3790eb446b7f94c34c (patch)
treee85999b7e4fe9f1e338e997adaab5cdbb10fc425
parent29a394f40fd9caa6bc5bbcee05310b906351b24a (diff)
downloadl2md-ffe6b92fd223cf56971f6d3790eb446b7f94c34c.tar.gz
l2md: add oneshot option to sync once and exit
By default l2md will loop forever and periodically fetch and sync. Add a config option that enables l2md to sync once and exit, so that it could also be invoked for oneshot operation (e.g. via crontab), instead of running as a daemon service. Signed-off-by: Anthony Iliopoulos <ailiopoulos@suse.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r--config.c4
-rw-r--r--env.c7
-rw-r--r--l2md.c4
-rw-r--r--l2md.h1
4 files changed, 12 insertions, 4 deletions
diff --git a/config.c b/config.c
index dd277cb..e4dab04 100644
--- a/config.c
+++ b/config.c
@@ -42,6 +42,8 @@ static void config_dump(struct config *cfg)
url->oid_known ? url->oid : "[unknown]");
}
}
+
+ verbose("oneshot = %d\n", cfg->oneshot);
}
static void config_probe_oids(struct config *cfg)
@@ -258,6 +260,8 @@ struct config *config_init(int argc, char **argv)
config_set_out(cfg, tmp, true);
} else if (sscanf(buff, "\tbase = %1023s", tmp) == 1) {
config_set_basedir(cfg, tmp);
+ } else if (sscanf(buff, "\toneshot = %u", &val) == 1) {
+ cfg->oneshot = val;
} else {
goto state_next;
}
diff --git a/env.c b/env.c
index f72d15c..f821562 100644
--- a/env.c
+++ b/env.c
@@ -66,9 +66,12 @@ void bootstrap_env(struct config *cfg)
void sync_done(struct config *cfg)
{
- verbose("Sync done. Sleeping %us.\n", cfg->general.period);
+ verbose("Sync done. ");
- sleep(cfg->general.period);
+ if (!cfg->oneshot) {
+ verbose("Sleeping %us.\n", cfg->general.period);
+ sleep(cfg->general.period);
+ }
}
void sync_env(struct config *cfg)
diff --git a/l2md.c b/l2md.c
index 458cda0..d4f7445 100644
--- a/l2md.c
+++ b/l2md.c
@@ -37,13 +37,13 @@ int main(int argc, char **argv)
bootstrap_env(cfg);
signal(SIGINT, signal_handler);
- while (!sigint) {
+ do {
sync_mail(cfg);
sync_done(cfg);
if (sigint)
break;
sync_env(cfg);
- }
+ } while (!sigint && !cfg->oneshot);
config_uninit(cfg);
return 0;
diff --git a/l2md.h b/l2md.h
index c127937..46ad443 100644
--- a/l2md.h
+++ b/l2md.h
@@ -72,6 +72,7 @@ struct config {
struct config_repo *repos;
uint32_t repos_num;
const struct mail_ops *ops;
+ bool oneshot;
};
#define repo_for_each(cfg, repo, i) \