]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
tweak improve code readability in cancel_cmd
authorAlain Spineux <alain@baculasystems.com>
Thu, 1 Dec 2022 10:45:28 +0000 (11:45 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:57:00 +0000 (13:57 +0200)
- it is useless to test for nb != -1 because nb is always >=0
- maybe the idea behind the comment was to test for ret and not nb ???
- &= is a bitwise operator, not for boolean
- notice that the two lines below don't work the same because
    ret = cancel_job(ua, jcr, 60, cancel) && ret;
    ret = ret && cancel_job(ua, jcr, 60, cancel);
  I chose the first one, but maybe because of the comment that I have
  removed, we should use the first one

bacula/src/dird/job.c
bacula/src/dird/ua_cmds.c

index 1c935adfb667d31b44d96b70c91ee5524e6e70ff..a880717fa8a5726c2d10558163d426851264b822 100644 (file)
@@ -748,8 +748,8 @@ cancel_job(UAContext *ua, JCR *jcr, int wait,  bool cancel)
          break;
    }
 
-   /* If job has not been started at all, there is no need to stoping it,
-    * can be simply canceled and removed from the watiting queue*/
+   /* If job has not been started at all, there is no need to stop it,
+    * can be simply canceled and removed from the waiting queue*/
    if (cancel || not_running) {
       status = JS_Canceled;
       reason = _("canceled");
index 74c27c7ec963d398ff64855c0d0e70f82d31cbd8..e3d7652c7c6edd07ae63e29c3392fbfe2fd0306e 100644 (file)
@@ -519,11 +519,10 @@ static int cancel_cmd(UAContext *ua, const char *cmd)
 {
    JCR    *jcr;
    bool    ret = true;
-   int     nb;
    bool    cancel = strcasecmp(commands[ua->cmd_index].key, "cancel") == 0;
    alist  *jcrs = New(alist(5, not_owned_by_alist));
 
-   /* If the user explicitely ask, we can send the cancel command to
+   /* If the user explicitly ask, we can send the cancel command to
     * the FD.
     */
    if (find_arg(ua, "inactive") > 0) {
@@ -531,13 +530,10 @@ static int cancel_cmd(UAContext *ua, const char *cmd)
       goto bail_out;
    }
 
-   nb = select_running_jobs(ua, jcrs, commands[ua->cmd_index].key);
+   select_running_jobs(ua, jcrs, commands[ua->cmd_index].key);
 
    foreach_alist(jcr, jcrs) {
-      /* Execute the cancel command only if we don't have an error */
-      if (nb != -1) {
-         ret &= cancel_job(ua, jcr, 60, cancel);
-      }
+      ret = cancel_job(ua, jcr, 60, cancel) && ret;
       free_jcr(jcr);
    }