]> granicus.if.org Git - fcron/commitdiff
added runatresume / @resume suspend
authorThibault Godouet <fcron@free.fr>
Sun, 26 Jun 2016 14:56:00 +0000 (15:56 +0100)
committerThibault Godouet <fcron@free.fr>
Sun, 26 Jun 2016 14:56:00 +0000 (15:56 +0100)
database.c
database.h
doc/en/changes.sgml
doc/en/faq.sgml
doc/en/fcrontab.5.sgml
doc/en/todo.sgml
fileconf.c
option.h

index 91a90a82c80fa5da70a22a75ad27c808f79fad30..7965e99ec932234c31dd1d9294e81e219c12c441 100644 (file)
@@ -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)
index 4a28ec5bbfe891e8145a7c9369cd9e26a7cb1489..70926db1d4f49f3e97fcbea1767e9579e7cd31ed 100644 (file)
@@ -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) */
index 057de10966d5801faab8dfdeb94d78217db238f9..c2d1b012439a5b8cf17bc54ab9979f5d632b065c 100644 (file)
@@ -21,6 +21,9 @@ A copy of the license is included in gfdl.sgml.
                <para>Refactored the socket (for fcrondyn), suspend and select code.</para>
             </listitem>
             <listitem>
+               <para>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.</para>
+            </listitem>
+             <listitem>
                <para>The installation script now supports systemd fully.</para>
             </listitem>
       </itemizedlist>
index b03a3b6f51a7026e49b1a9603236dcdee6044599..5cc60be1e7b656f2f6f2395b941b400d319c5220 100644 (file)
@@ -95,7 +95,7 @@ every day at 2:30, it will run at 3:30 the day of this kind of DST change.
            </question>
            <answer>
               <para>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.</para>
+               On resume it will adjust the task schedules accordingly, run runatresume tasks if any, and report non-execution of noticenotrun tasks.</para>
                <para>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.
index 48dd51a9fc79c49391b467562b9bf6590f3191d4..b0331ba0ff2c1546d9a31455b5456bb6e8a3c439 100644 (file)
@@ -392,7 +392,7 @@ will run only ONCE either at 2:15, 3:15 OR 4:15.</para>
 linkend="uptent">lines based on elapsed system up time</link> is recommended instead.</para>
            <para>A task using a Vixie cron shortcut is of the form:</para>
            <programlisting>shortcut command</programlisting>
-           <para>Below is a list of available shortcuts with their fcron equivalent:</para>
+           <para>Below is a list of available shortcuts, plus some fcron-specific additions, with their fcron equivalent:</para>
            <table>
                <title>Vixie cron shortcuts </title>
                <tgroup cols="2">
@@ -411,6 +411,12 @@ linkend="uptent">lines based on elapsed system up time</link> is recommended ins
                            <entry>@runatreboot,runonce(true)</entry>
                            <entry>   </entry>
                        </row>
+                       <row>
+                           <entry>@resume </entry>
+                           <entry>Run once, at resume from suspend/hibernate </entry>
+                           <entry>@runatresume,runonce(true)</entry>
+                           <entry>   </entry>
+                       </row>
                        <row>
                            <entry>@yearly </entry>
                            <entry>Run once a year </entry>
index fbe26ec183fefbdeeb85f6895af6d7a2fdfcfb2a..5614794d822833df9e38a1e6d03d38876458f44c 100644 (file)
@@ -26,9 +26,6 @@ A copy of the license is included in gfdl.sgml.
            <listitem>
               <para>Option to compile and install from git sources without generating the doc</para>
            </listitem>
-           <listitem>
-              <para>split bootrun into bootrun vs. resumerun, to run when the computer resumes? (similar to bootrun)</para>
-           </listitem>
            <listitem>
               <para>use ask_user() in boot-install</para>
            </listitem>
index 1f452a640f14a47b1e891f1a7eff8939c5daea39..3c5f0c3fff62db974c801dbad538884991ba1594 100644 (file)
@@ -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);
index 4b7ddb9322fbdb3c522433ea9afdb13559c15220..877034bcdacc281a97ae577583c48ebca0468865 100644 (file)
--- 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)
 
 */
 
        (_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
 
 /*
   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) \
 #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__ */