From c572d9f270b6e0f36329bc51ec6a4901bb8a300d Mon Sep 17 00:00:00 2001
From: "Gao,Yan" <ygao@suse.com>
Date: Thu, 14 Apr 2022 11:42:18 +0200
Subject: [PATCH 1/3] Refactor: tools: set commands in crm_resource before
 changing any options

So that we detect any specifying of multiple commands and handle that first.
---
 tools/crm_resource.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

Index: pacemaker-2.0.4+20200616.2deceaa3a/tools/crm_resource.c
===================================================================
--- pacemaker-2.0.4+20200616.2deceaa3a.orig/tools/crm_resource.c
+++ pacemaker-2.0.4+20200616.2deceaa3a/tools/crm_resource.c
@@ -25,6 +25,8 @@
 #include <libgen.h>
 #include <time.h>
 
+#define SET_COMMAND(cmd) do { rsc_cmd = (cmd); } while (0)
+
 bool BE_QUIET = FALSE;
 bool scope_master = FALSE;
 int cib_options = cib_sync_call;
@@ -687,7 +689,7 @@ main(int argc, char **argv)
                     recursive = TRUE;
 
                 } else if (safe_str_eq("wait", longname)) {
-                    rsc_cmd = flag;
+                    SET_COMMAND(flag);
                     rsc_long_cmd = longname;
                     require_resource = FALSE;
                     require_dataset = FALSE;
@@ -700,7 +702,7 @@ main(int argc, char **argv)
                     || safe_str_eq("force-start",   longname)
                     || safe_str_eq("force-promote", longname)
                     || safe_str_eq("force-check",   longname)) {
-                    rsc_cmd = flag;
+                    SET_COMMAND(flag);
                     rsc_long_cmd = longname;
                     find_flags = pe_find_renamed|pe_find_anon;
                     crm_log_args(argc, argv);
@@ -887,12 +889,12 @@ main(int argc, char **argv)
 
             case 'C':
             case 'R':
+                SET_COMMAND(flag);
                 crm_log_args(argc, argv);
                 require_resource = FALSE;
                 if (cib_file == NULL) {
                     require_crmd = TRUE;
                 }
-                rsc_cmd = flag;
                 find_flags = pe_find_renamed|pe_find_anon;
                 break;
 
@@ -905,23 +907,23 @@ main(int argc, char **argv)
                 break;
 
             case 'D':
+                SET_COMMAND(flag);
                 require_dataset = FALSE;
                 crm_log_args(argc, argv);
-                rsc_cmd = flag;
                 find_flags = pe_find_renamed|pe_find_any;
                 break;
 
             case 'F':
+                SET_COMMAND(flag);
                 require_crmd = TRUE;
                 crm_log_args(argc, argv);
-                rsc_cmd = flag;
                 break;
 
             case 'U':
             case 'B':
             case 'M':
+                SET_COMMAND(flag);
                 crm_log_args(argc, argv);
-                rsc_cmd = flag;
                 find_flags = pe_find_renamed|pe_find_anon;
                 break;
 
@@ -930,49 +932,49 @@ main(int argc, char **argv)
             case 'l':
             case 'O':
             case 'o':
+                SET_COMMAND(flag);
                 require_resource = FALSE;
-                rsc_cmd = flag;
                 break;
 
             case 'Y':
+                SET_COMMAND(flag);
                 require_resource = FALSE;
-                rsc_cmd = flag;
                 find_flags = pe_find_renamed|pe_find_anon;
                 break;
 
             case 'q':
             case 'w':
-                rsc_cmd = flag;
+                SET_COMMAND(flag);
                 find_flags = pe_find_renamed|pe_find_any;
                 break;
 
             case 'W':
             case 'A':
             case 'a':
-                rsc_cmd = flag;
+                SET_COMMAND(flag);
                 find_flags = pe_find_renamed|pe_find_anon;
                 break;
 
             case 'S':
+                SET_COMMAND(flag);
                 require_dataset = FALSE;
                 crm_log_args(argc, argv);
                 prop_name = optarg;
-                rsc_cmd = flag;
                 find_flags = pe_find_renamed|pe_find_any;
                 break;
 
             case 'p':
             case 'd':
+                SET_COMMAND(flag);
                 crm_log_args(argc, argv);
                 prop_name = optarg;
-                rsc_cmd = flag;
                 find_flags = pe_find_renamed|pe_find_any;
                 break;
 
             case 'G':
             case 'g':
+                SET_COMMAND(flag);
                 prop_name = optarg;
-                rsc_cmd = flag;
                 find_flags = pe_find_renamed|pe_find_any;
                 break;
 
