From: Thibault Godouet Date: Sun, 26 Jun 2016 14:56:00 +0000 (+0100) Subject: added runatresume / @resume X-Git-Tag: ver3_3_0~7^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6d47cfac0b7d2589d814ea6c89b48410d2ba152d;p=thirdparty%2Ffcron.git added runatresume / @resume --- diff --git a/database.c b/database.c index 91a90a8..7965e99 100644 --- a/database.c +++ b/database.c @@ -1391,7 +1391,8 @@ set_next_exe_startup(struct cl_t *cl, const int context, } if (context == CONTEXT_BOOT - || (context == CONTEXT_DEFAULT && is_volatile(cl->cl_option))) { + || (context == CONTEXT_DEFAULT && is_volatile(cl->cl_option)) + || (context == CONTEXT_RESUME && is_runatresume(cl->cl_option))) { clear_hasrun(cl->cl_option); } @@ -1404,7 +1405,8 @@ set_next_exe_startup(struct cl_t *cl, const int context, else if (is_td(cl->cl_option)) { /* set the time and date of the next execution */ - if (context == CONTEXT_BOOT && is_runatreboot(cl->cl_option)) { + if ((context == CONTEXT_BOOT && is_runatreboot(cl->cl_option)) + || (context == CONTEXT_RESUME && is_runatresume(cl->cl_option))) { if (is_notice_notrun(cl->cl_option)) { @@ -1482,7 +1484,8 @@ set_next_exe_startup(struct cl_t *cl, const int context, } /* standard @-lines */ - if (context == CONTEXT_BOOT && is_runatreboot(cl->cl_option)) { + if ((context == CONTEXT_BOOT && is_runatreboot(cl->cl_option)) + || (context == CONTEXT_RESUME && is_runatresume(cl->cl_option))) { cl->cl_nextexe = now; } else if (is_new_file || is_volatile(cl->cl_option) diff --git a/database.h b/database.h index 4a28ec5..70926db 100644 --- a/database.h +++ b/database.h @@ -39,7 +39,7 @@ extern void set_next_exe_notrun(struct cl_t *line, char context); #define LAVG 1 /* set_next_exe_notrun() : context */ #define SYSDOWN 2 /* set_next_exe_notrun() : context */ #define QUEUE_FULL 3 /* set_next_exe_notrun() : context */ -#define SYSDOWN_RUNATREBOOT 4 /* set_next_exe_notrun() : context */ +#define SYSDOWN_RUNATREBOOT 4 /* set_next_exe_notrun() : context - runatreboot or runatresume */ extern void set_next_exe_startup(struct cl_t *cl, const int context, const time_t sleep_duration); #define CONTEXT_DEFAULT 1 /* a new file was loaded (and the machine didn't just boot) */ diff --git a/doc/en/changes.sgml b/doc/en/changes.sgml index 057de10..c2d1b01 100644 --- a/doc/en/changes.sgml +++ b/doc/en/changes.sgml @@ -21,6 +21,9 @@ A copy of the license is included in gfdl.sgml. Refactored the socket (for fcrondyn), suspend and select code. + Added a new option 'runatresume' (as well as a Vixie-cron-style '@resume' shortcut), to run a job when the system resumes from suspend/hibernation. + + The installation script now supports systemd fully. diff --git a/doc/en/faq.sgml b/doc/en/faq.sgml index b03a3b6..5cc60be 100644 --- a/doc/en/faq.sgml +++ b/doc/en/faq.sgml @@ -95,7 +95,7 @@ every day at 2:30, it will run at 3:30 the day of this kind of DST change. fcron now fully supports suspend (to memory or disk). - On resume it will adjust the task schedules accordingly, run runatreboot tasks if appropriate, and report non-execution of noticenotrun tasks. + On resume it will adjust the task schedules accordingly, run runatresume tasks if any, and report non-execution of noticenotrun tasks. fcron will try to notice suspends by itself without external help. On Linux it can do so reliably via system APIs, but on other OSes it will instead check if it wakes up later than it expected after a sleep. diff --git a/doc/en/fcrontab.5.sgml b/doc/en/fcrontab.5.sgml index 48dd51a..b0331ba 100644 --- a/doc/en/fcrontab.5.sgml +++ b/doc/en/fcrontab.5.sgml @@ -392,7 +392,7 @@ will run only ONCE either at 2:15, 3:15 OR 4:15. linkend="uptent">lines based on elapsed system up time is recommended instead. A task using a Vixie cron shortcut is of the form: shortcut command - Below is a list of available shortcuts with their fcron equivalent: + Below is a list of available shortcuts, plus some fcron-specific additions, with their fcron equivalent: Vixie cron shortcuts @@ -411,6 +411,12 @@ linkend="uptent">lines based on elapsed system up time is recommended ins @runatreboot,runonce(true) + + @resume + Run once, at resume from suspend/hibernate + @runatresume,runonce(true) + + @yearly Run once a year diff --git a/doc/en/todo.sgml b/doc/en/todo.sgml index fbe26ec..5614794 100644 --- a/doc/en/todo.sgml +++ b/doc/en/todo.sgml @@ -26,9 +26,6 @@ A copy of the license is included in gfdl.sgml. Option to compile and install from git sources without generating the doc - - split bootrun into bootrun vs. resumerun, to run when the computer resumes? (similar to bootrun) - use ask_user() in boot-install diff --git a/fileconf.c b/fileconf.c index 1f452a6..3c5f0c3 100644 --- a/fileconf.c +++ b/fileconf.c @@ -664,6 +664,18 @@ read_opt(char *ptr, cl_t * cl) } + else if (strcmp(opt_name, "runatresume") == 0) { + if (in_brackets && (ptr = get_bool(ptr, &i)) == NULL) + Handle_err; + if (i == 0) + clear_runatresume(cl->cl_option); + else + set_runatresume(cl->cl_option); + if (debug_opt) + fprintf(stderr, " Opt : \"%s\" %d\n", opt_name, i); + } + + else if (strcmp(opt_name, "runonce") == 0) { if (in_brackets && (ptr = get_bool(ptr, &i)) == NULL) Handle_err; @@ -1337,6 +1349,20 @@ read_shortcut(char *ptr, cf_t * cf) if (debug_opt) fprintf(stderr, " Shc : @reboot\n"); } + if (strcmp(shortcut, "resume") == 0) { + set_freq(cl->cl_option); + set_runatresume(cl->cl_option); + set_runonce(cl->cl_option); + clear_volatile(cl->cl_option); + cl->cl_runfreq = 0; + cl->cl_first = 0; + /* the job will not be rescheduled after the first execution (flag is_hasrun), + * we set timefreq to LONG_MAX just in case */ + cl->cl_timefreq = LONG_MAX; + + if (debug_opt) + fprintf(stderr, " Shc : @resume\n"); + } else if (strcmp(shortcut, "yearly") == 0 || strcmp(shortcut, "annually") == 0) { bit_set(cl->cl_mins, 0); diff --git a/option.h b/option.h index 4b7ddb9..877034b 100644 --- a/option.h +++ b/option.h @@ -95,6 +95,7 @@ 28 runatreboot: if set then run the job at each system startup 29 runonce: if set then run the job only once 30 hasrun: set if the job has been run at least once + 31 runatresume: if set then run the job at each system resume (from suspend/hibernation) */ @@ -438,7 +439,7 @@ (_bit_clear(opt, 24)) /* - bit 25 : set to 1 : if fcron is running in the forground, then also let jobs print + bit 25 : set to 1 : if fcron is running in the foreground, then also let jobs print to stderr/stdout instead of mailing or discarding it set to 0 : if fcron is not running in the foreground or this bit is not set, then treat it as specified with the other options @@ -500,7 +501,8 @@ /* bit 30 : set to 1 : the job has run at least once since system reboot - (or since fcron restart if volatile is set) + (or since fcron restart if volatile is set, + or since last resume if runatresume is set) set to 0 : job hasn't run yet */ #define is_hasrun(opt) \ @@ -510,4 +512,15 @@ #define clear_hasrun(opt) \ (_bit_clear(opt, 30)) +/* + bit 31 : set to 1 : run the job immediately after the system resume (from suspend/hibernation) + set to 0 : leave the nextexe time as it +*/ +#define is_runatresume(opt) \ + (_bit_test(opt, 31)) +#define set_runatresume(opt) \ + (_bit_set(opt, 31)) +#define clear_runatresume(opt) \ + (_bit_clear(opt, 31)) + #endif /* __OPTIONH__ */