diff options
author | Anthony Iliopoulos <ailiopoulos@suse.com> | 2020-01-16 02:15:51 +0100 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2020-01-16 12:24:06 +0100 |
commit | ffe6b92fd223cf56971f6d3790eb446b7f94c34c (patch) | |
tree | e85999b7e4fe9f1e338e997adaab5cdbb10fc425 | |
parent | 29a394f40fd9caa6bc5bbcee05310b906351b24a (diff) | |
download | l2md-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.c | 4 | ||||
-rw-r--r-- | env.c | 7 | ||||
-rw-r--r-- | l2md.c | 4 | ||||
-rw-r--r-- | l2md.h | 1 |
4 files changed, 12 insertions, 4 deletions
@@ -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; } @@ -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) @@ -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; @@ -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) \ |