From: Alain Spineux Date: Thu, 1 Dec 2022 10:45:28 +0000 (+0100) Subject: tweak improve code readability in cancel_cmd X-Git-Tag: Beta-15.0.0~332 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f69d7c4e4db3f0c943fa4270037b446107a8db6a;p=thirdparty%2Fbacula.git tweak improve code readability in cancel_cmd - 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 --- diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 1c935adfb..a880717fa 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -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"); diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 74c27c7ec..e3d7652c7 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -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); }