Blame SOURCES/002-pacemakerd-options.patch

2a3635
From 0d40ebf10b1794ece2c5c9768ea7222d3834d3b3 Mon Sep 17 00:00:00 2001
2a3635
From: Chris Lumens <clumens@redhat.com>
2a3635
Date: Thu, 13 May 2021 11:42:18 -0400
2a3635
Subject: [PATCH 1/4] Build: Use a different variable to find man page
2a3635
 includes.
2a3635
2a3635
With other programs outside of the tools directory being converted to
2a3635
use glib for command line handling, their includes are not going to be
2a3635
in tools/.  So we need to use a different autoconf variable to find
2a3635
them.
2a3635
---
2a3635
 mk/common.mk | 6 +++---
2a3635
 1 file changed, 3 insertions(+), 3 deletions(-)
2a3635
2a3635
diff --git a/mk/common.mk b/mk/common.mk
2a3635
index b247670..aa59feb 100644
2a3635
--- a/mk/common.mk
2a3635
+++ b/mk/common.mk
2a3635
@@ -1,5 +1,5 @@
2a3635
 #
2a3635
-# Copyright 2014-2020 the Pacemaker project contributors
2a3635
+# Copyright 2014-2021 the Pacemaker project contributors
2a3635
 #
2a3635
 # The version control history for this file may have further details.
2a3635
 #
2a3635
@@ -68,11 +68,11 @@ HELP2MAN_ARGS = -N --section 8 --name "Part of the Pacemaker cluster resource ma
2a3635
 #       and all wrappers to C code.
2a3635
 %.8:	% $(MAN8DEPS)
2a3635
 	$(AM_V_at)chmod a+x $(abs_builddir)/$<
2a3635
-	$(AM_V_MAN)if [ -f $(top_srcdir)/tools/$@.inc ]; then			\
2a3635
+	$(AM_V_MAN)if [ -f $(abs_srcdir)/$@.inc ]; then			\
2a3635
 		PATH=$(abs_builddir):$$PATH $(HELP2MAN) $(HELP2MAN_ARGS)	\
2a3635
 			-h --help-all 						\
2a3635
 			--no-discard-stderr 					\
2a3635
-			-i $(top_srcdir)/tools/$@.inc $(abs_builddir)/$<		\
2a3635
+			-i $(abs_srcdir)/$@.inc $(abs_builddir)/$<		\
2a3635
 			| sed -f $(top_srcdir)/tools/fix-manpages > $@ ; \
2a3635
 	else									\
2a3635
 		PATH=$(abs_builddir):$$PATH $(HELP2MAN) $(HELP2MAN_ARGS)	\
2a3635
-- 
2a3635
1.8.3.1
2a3635
2a3635
2a3635
From c7ab1d901bcbbf0137277e783e072777ca2f82d9 Mon Sep 17 00:00:00 2001
2a3635
From: Chris Lumens <clumens@redhat.com>
2a3635
Date: Thu, 13 May 2021 11:44:16 -0400
2a3635
Subject: [PATCH 2/4] Refactor: daemons: Remove the pid_file variable from
2a3635
 pacemakerd.
2a3635
2a3635
It's never used anywhere.
2a3635
---
2a3635
 daemons/pacemakerd/pacemakerd.c | 3 ---
2a3635
 1 file changed, 3 deletions(-)
2a3635
2a3635
diff --git a/daemons/pacemakerd/pacemakerd.c b/daemons/pacemakerd/pacemakerd.c
2a3635
index 8ec9708..03d688e 100644
2a3635
--- a/daemons/pacemakerd/pacemakerd.c
2a3635
+++ b/daemons/pacemakerd/pacemakerd.c
2a3635
@@ -27,8 +27,7 @@
2a3635
 
2a3635
 static crm_trigger_t *shutdown_trigger = NULL;
2a3635
 static crm_trigger_t *startup_trigger = NULL;
2a3635
-static const char *pid_file = PCMK_RUN_DIR "/pacemaker.pid";
2a3635
2a3635
 /* state we report when asked via pacemakerd-api status-ping */
2a3635
 static const char *pacemakerd_state = XML_PING_ATTR_PACEMAKERDSTATE_INIT;
2a3635
 static gboolean running_with_sbd = FALSE; /* local copy */
2a3635
@@ -224,7 +222,6 @@ main(int argc, char **argv)
2a3635
                 /* Legacy */
2a3635
                 break;
2a3635
             case 'p':
2a3635
-                pid_file = optarg;
2a3635
                 break;
2a3635
             case 's':
2a3635
                 pcmk__set_env_option("node_start_state", "standby");
2a3635
-- 
2a3635
1.8.3.1
2a3635
2a3635
2a3635
From 98990eed9f6a5dbde7c8a5aa0783e93d5479295b Mon Sep 17 00:00:00 2001
2a3635
From: Chris Lumens <clumens@redhat.com>
2a3635
Date: Thu, 13 May 2021 13:14:38 -0400
2a3635
Subject: [PATCH 3/4] Refactor: daemons: Use glib for command line handling in
2a3635
 pacemakerd.
2a3635
2a3635
---
2a3635
 daemons/pacemakerd/Makefile.am      |   2 +
2a3635
 daemons/pacemakerd/pacemakerd.8.inc |   5 +
2a3635
 daemons/pacemakerd/pacemakerd.c     | 195 ++++++++++++++++++------------------
2a3635
 3 files changed, 102 insertions(+), 100 deletions(-)
2a3635
 create mode 100644 daemons/pacemakerd/pacemakerd.8.inc
2a3635
2a3635
diff --git a/daemons/pacemakerd/Makefile.am b/daemons/pacemakerd/Makefile.am
2a3635
index cc657f5..84517a3 100644
2a3635
--- a/daemons/pacemakerd/Makefile.am
2a3635
+++ b/daemons/pacemakerd/Makefile.am
2a3635
@@ -15,6 +15,8 @@ if BUILD_SYSTEMD
2a3635
 systemdsystemunit_DATA	= pacemaker.service
2a3635
 endif
2a3635
 
2a3635
+EXTRA_DIST 	= pacemakerd.8.inc
2a3635
+
2a3635
 ## SOURCES
2a3635
 
2a3635
 noinst_HEADERS		= pacemakerd.h
2a3635
diff --git a/daemons/pacemakerd/pacemakerd.8.inc b/daemons/pacemakerd/pacemakerd.8.inc
2a3635
new file mode 100644
2a3635
index 0000000..902af4e
2a3635
--- /dev/null
2a3635
+++ b/daemons/pacemakerd/pacemakerd.8.inc
2a3635
@@ -0,0 +1,5 @@
2a3635
+[synopsis]
2a3635
+pacemakerd [options]
2a3635
+
2a3635
+/subsidiary Pacemaker daemons/
2a3635
+.SH OPTIONS
2a3635
diff --git a/daemons/pacemakerd/pacemakerd.c b/daemons/pacemakerd/pacemakerd.c
2a3635
index 03d688e..ce194bf 100644
2a3635
--- a/daemons/pacemakerd/pacemakerd.c
2a3635
+++ b/daemons/pacemakerd/pacemakerd.c
2a3635
@@ -23,12 +23,54 @@
2a3635
 #include <crm/msg_xml.h>
2a3635
 #include <crm/common/ipc_internal.h>
2a3635
 #include <crm/common/mainloop.h>
2a3635
+#include <crm/common/cmdline_internal.h>
2a3635
 #include <crm/cluster/internal.h>
2a3635
 #include <crm/cluster.h>
2a3635
 
2a3635
 #include <dirent.h>
2a3635
 #include <ctype.h>
2a3635
 
2a3635
+#define SUMMARY "pacemakerd - primary Pacemaker daemon that launches and monitors all subsidiary Pacemaker daemons"
2a3635
+
2a3635
+struct {
2a3635
+    gboolean features;
2a3635
+    gboolean foreground;
2a3635
+    gboolean shutdown;
2a3635
+    gboolean standby;
2a3635
+} options;
2a3635
+
2a3635
+static gboolean
2a3635
+pid_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **err) {
2a3635
+    return TRUE;
2a3635
+}
2a3635
+
2a3635
+static gboolean
2a3635
+standby_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **err) {
2a3635
+    options.standby = TRUE;
2a3635
+    pcmk__set_env_option("node_start_state", "standby");
2a3635
+    return TRUE;
2a3635
+}
2a3635
+
2a3635
+static GOptionEntry entries[] = {
2a3635
+    { "features", 'F', 0, G_OPTION_ARG_NONE, &options.features,
2a3635
+      "Display full version and list of features Pacemaker was built with",
2a3635
+      NULL },
2a3635
+    { "foreground", 'f', 0, G_OPTION_ARG_NONE, &options.foreground,
2a3635
+      "(Ignored) Pacemaker always runs in the foreground",
2a3635
+      NULL },
2a3635
+    { "pid-file", 'p', 0, G_OPTION_ARG_CALLBACK, pid_cb,
2a3635
+      "(Ignored) Daemon pid file location",
2a3635
+      "FILE" },
2a3635
+    { "shutdown", 'S', 0, G_OPTION_ARG_NONE, &options.shutdown,
2a3635
+      "Instruct Pacemaker to shutdown on this machine",
2a3635
+      NULL },
2a3635
+    { "standby", 's', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, standby_cb,
2a3635
+      "Start node in standby state",
2a3635
+      NULL },
2a3635
+
2a3635
+    { NULL }
2a3635
+};
2a3635
+
2a3635
 static gboolean fatal_error = FALSE;
2a3635
 static GMainLoop *mainloop = NULL;
2a3635
 static bool global_keep_tracking = false;
2a3635
@@ -642,49 +685,6 @@ pcmk_sigquit(int nsig)
2a3635
     .connection_destroyed = pcmk_ipc_destroy
2a3635
 };
2a3635
 
2a3635
-static pcmk__cli_option_t long_options[] = {
2a3635
-    // long option, argument type, storage, short option, description, flags
2a3635
-    {
2a3635
-        "help", no_argument, NULL, '?',
2a3635
-        "\tThis text", pcmk__option_default
2a3635
-    },
2a3635
-    {
2a3635
-        "version", no_argument, NULL, '$',
2a3635
-        "\tVersion information", pcmk__option_default
2a3635
-    },
2a3635
-    {
2a3635
-        "verbose", no_argument, NULL, 'V',
2a3635
-        "\tIncrease debug output", pcmk__option_default
2a3635
-    },
2a3635
-    {
2a3635
-        "shutdown", no_argument, NULL, 'S',
2a3635
-        "\tInstruct Pacemaker to shutdown on this machine", pcmk__option_default
2a3635
-    },
2a3635
-    {
2a3635
-        "features", no_argument, NULL, 'F',
2a3635
-        "\tDisplay full version and list of features Pacemaker was built with",
2a3635
-        pcmk__option_default
2a3635
-    },
2a3635
-    {
2a3635
-        "-spacer-", no_argument, NULL, '-',
2a3635
-        "\nAdditional Options:", pcmk__option_default
2a3635
-    },
2a3635
-    {
2a3635
-        "foreground", no_argument, NULL, 'f',
2a3635
-        "\t(Ignored) Pacemaker always runs in the foreground",
2a3635
-        pcmk__option_default
2a3635
-    },
2a3635
-    {
2a3635
-        "pid-file", required_argument, NULL, 'p',
2a3635
-        "\t(Ignored) Daemon pid file location", pcmk__option_default
2a3635
-    },
2a3635
-    {
2a3635
-        "standby", no_argument, NULL, 's',
2a3635
-        "\tStart node in standby state", pcmk__option_default
2a3635
-    },
2a3635
-    { 0, 0, 0, 0 }
2a3635
-};
2a3635
-
2a3635
 static void
2a3635
 mcp_chown(const char *path, uid_t uid, gid_t gid)
2a3635
 {
2a3635
@@ -1168,83 +1211,66 @@ request_shutdown(crm_ipc_t *ipc)
2a3635
     return status;
2a3635
 }
2a3635
 
2a3635
+static GOptionContext *
2a3635
+build_arg_context(pcmk__common_args_t *args) {
2a3635
+    GOptionContext *context = NULL;
2a3635
+
2a3635
+    context = pcmk__build_arg_context(args, NULL, NULL, NULL);
2a3635
+    pcmk__add_main_args(context, entries);
2a3635
+    return context;
2a3635
+}
2a3635
+
2a3635
 int
2a3635
 main(int argc, char **argv)
2a3635
 {
2a3635
-    int flag;
2a3635
-    int argerr = 0;
2a3635
+    crm_exit_t exit_code = CRM_EX_OK;
2a3635
+
2a3635
+    GError *error = NULL;
2a3635
+
2a3635
+    pcmk__common_args_t *args = pcmk__new_common_args(SUMMARY);
2a3635
+    gchar **processed_args = pcmk__cmdline_preproc(argv, "p");
2a3635
+    GOptionContext *context = build_arg_context(args);
2a3635
 
2a3635
-    int option_index = 0;
2a3635
     bool old_instance_connected = false;
2a3635
-    gboolean shutdown = FALSE;
2a3635
 
2a3635
     crm_ipc_t *old_instance = NULL;
2a3635
     qb_ipcs_service_t *ipcs = NULL;
2a3635
 
2a3635
     crm_log_preinit(NULL, argc, argv);
2a3635
-    pcmk__set_cli_options(NULL, "[options]", long_options,
2a3635
-                          "primary Pacemaker daemon that launches and "
2a3635
-                          "monitors all subsidiary Pacemaker daemons");
2a3635
     mainloop_add_signal(SIGHUP, pcmk_ignore);
2a3635
     mainloop_add_signal(SIGQUIT, pcmk_sigquit);
2a3635
 
2a3635
-    while (1) {
2a3635
-        flag = pcmk__next_cli_option(argc, argv, &option_index, NULL);
2a3635
-        if (flag == -1)
2a3635
-            break;
2a3635
-
2a3635
-        switch (flag) {
2a3635
-            case 'V':
2a3635
-                crm_bump_log_level(argc, argv);
2a3635
-                break;
2a3635
-            case 'f':
2a3635
-                /* Legacy */
2a3635
-                break;
2a3635
-            case 'p':
2a3635
-                break;
2a3635
-            case 's':
2a3635
-                pcmk__set_env_option("node_start_state", "standby");
2a3635
-                break;
2a3635
-            case '$':
2a3635
-            case '?':
2a3635
-                pcmk__cli_help(flag, CRM_EX_OK);
2a3635
-                break;
2a3635
-            case 'S':
2a3635
-                shutdown = TRUE;
2a3635
-                break;
2a3635
-            case 'F':
2a3635
-                printf("Pacemaker %s (Build: %s)\n Supporting v%s: %s\n", PACEMAKER_VERSION, BUILD_VERSION,
2a3635
-                       CRM_FEATURE_SET, CRM_FEATURES);
2a3635
-                crm_exit(CRM_EX_OK);
2a3635
-            default:
2a3635
-                printf("Argument code 0%o (%c) is not (?yet?) supported\n", flag, flag);
2a3635
-                ++argerr;
2a3635
-                break;
2a3635
-        }
2a3635
+    if (!g_option_context_parse_strv(context, &processed_args, &error)) {
2a3635
+        exit_code = CRM_EX_USAGE;
2a3635
+        goto done;
2a3635
     }
2a3635
 
2a3635
-    if (optind < argc) {
2a3635
-        printf("non-option ARGV-elements: ");
2a3635
-        while (optind < argc)
2a3635
-            printf("%s ", argv[optind++]);
2a3635
-        printf("\n");
2a3635
-    }
2a3635
-    if (argerr) {
2a3635
-        pcmk__cli_help('?', CRM_EX_USAGE);
2a3635
+    if (options.features) {
2a3635
+        printf("Pacemaker %s (Build: %s)\n Supporting v%s: %s\n", PACEMAKER_VERSION, BUILD_VERSION,
2a3635
+               CRM_FEATURE_SET, CRM_FEATURES);
2a3635
+        exit_code = CRM_EX_OK;
2a3635
+        goto done;
2a3635
     }
2a3635
 
2a3635
+    if (args->version) {
2a3635
+        g_strfreev(processed_args);
2a3635
+        pcmk__free_arg_context(context);
2a3635
+        /* FIXME:  When pacemakerd is converted to use formatted output, this can go. */
2a3635
+        pcmk__cli_help('v', CRM_EX_USAGE);
2a3635
+    }
2a3635
 
2a3635
     setenv("LC_ALL", "C", 1);
2a3635
 
2a3635
     pcmk__set_env_option("mcp", "true");
2a3635
 
2a3635
+    pcmk__cli_init_logging("pacemakerd", args->verbosity);
2a3635
     crm_log_init(NULL, LOG_INFO, TRUE, FALSE, argc, argv, FALSE);
2a3635
 
2a3635
     crm_debug("Checking for existing Pacemaker instance");
2a3635
     old_instance = crm_ipc_new(CRM_SYSTEM_MCP, 0);
2a3635
     old_instance_connected = crm_ipc_connect(old_instance);
2a3635
 
2a3635
-    if (shutdown) {
2a3635
+    if (options.shutdown) {
2a3635
         if (old_instance_connected) {
2a3635
             crm_exit(request_shutdown(old_instance));
2a3635
         } else {
2a3635
@@ -1253,22 +1279,25 @@ main(int argc, char **argv)
2a3635
                     "Pacemaker instance: %s", strerror(errno));
2a3635
             crm_ipc_close(old_instance);
2a3635
             crm_ipc_destroy(old_instance);
2a3635
-            crm_exit(CRM_EX_DISCONNECT);
2a3635
+            exit_code = CRM_EX_DISCONNECT;
2a3635
+            goto done;
2a3635
         }
2a3635
 
2a3635
     } else if (old_instance_connected) {
2a3635
         crm_ipc_close(old_instance);
2a3635
         crm_ipc_destroy(old_instance);
2a3635
         crm_err("Aborting start-up because active Pacemaker instance found");
2a3635
-        crm_exit(CRM_EX_FATAL);
2a3635
+        exit_code = CRM_EX_FATAL;
2a3635
+        goto done;
2a3635
     }
2a3635
 
2a3635
     crm_ipc_close(old_instance);
2a3635
     crm_ipc_destroy(old_instance);
2a3635
 
2a3635
 #ifdef SUPPORT_COROSYNC
2a3635
     if (mcp_read_config() == FALSE) {
2a3635
-        crm_exit(CRM_EX_UNAVAILABLE);
2a3635
+        exit_code = CRM_EX_UNAVAILABLE;
2a3635
+        goto done;
2a3635
     }
2a3635
 #endif
2a3635
 
2a3635
@@ -1292,7 +1321,8 @@ main(int argc, char **argv)
2a3635
 #ifdef SUPPORT_COROSYNC
2a3635
     /* Allows us to block shutdown */
2a3635
     if (!cluster_connect_cfg()) {
2a3635
-        crm_exit(CRM_EX_PROTOCOL);
2a3635
+        exit_code = CRM_EX_PROTOCOL;
2a3635
+        goto done;
2a3635
     }
2a3635
 #endif
2a3635
 
2a3635
@@ -1307,9 +1337,11 @@ main(int argc, char **argv)
2a3635
         case pcmk_rc_ok:
2a3635
             break;
2a3635
         case pcmk_rc_ipc_unauthorized:
2a3635
-            crm_exit(CRM_EX_CANTCREAT);
2a3635
+            exit_code = CRM_EX_CANTCREAT;
2a3635
+            goto done;
2a3635
         default:
2a3635
-            crm_exit(CRM_EX_FATAL);
2a3635
+            exit_code = CRM_EX_FATAL;
2a3635
+            goto done;
2a3635
     };
2a3635
 
2a3635
     mainloop_add_signal(SIGTERM, pcmk_shutdown);
2a3635
@@ -1342,5 +1374,11 @@ main(int argc, char **argv)
2a3635
 #ifdef SUPPORT_COROSYNC
2a3635
     cluster_disconnect_cfg();
2a3635
 #endif
2a3635
-    crm_exit(CRM_EX_OK);
2a3635
+
2a3635
+done:
2a3635
+    g_strfreev(processed_args);
2a3635
+    pcmk__free_arg_context(context);
2a3635
+
2a3635
+    pcmk__output_and_clear_error(error, NULL);
2a3635
+    crm_exit(exit_code);
2a3635
 }
2a3635
-- 
2a3635
1.8.3.1
2a3635
2a3635
2a3635
From 8f7924fbb2a012bedcad59335b7bebc5020b26e3 Mon Sep 17 00:00:00 2001
2a3635
From: Chris Lumens <clumens@redhat.com>
2a3635
Date: Thu, 13 May 2021 13:27:13 -0400
2a3635
Subject: [PATCH 4/4] Low: pacemaker.service: Don't start pacemakerd with -f.
2a3635
2a3635
This option is completely ignored by pacemakerd.
2a3635
---
2a3635
 daemons/pacemakerd/pacemaker.service.in           | 2 +-
2a3635
 doc/sphinx/Clusters_from_Scratch/verification.rst | 2 +-
2a3635
 2 files changed, 2 insertions(+), 2 deletions(-)
2a3635
2a3635
diff --git a/daemons/pacemakerd/pacemaker.service.in b/daemons/pacemakerd/pacemaker.service.in
2a3635
index b128ddc..0363a22 100644
2a3635
--- a/daemons/pacemakerd/pacemaker.service.in
2a3635
+++ b/daemons/pacemakerd/pacemaker.service.in
2a3635
@@ -44,7 +44,7 @@ EnvironmentFile=-@CONFIGDIR@/pacemaker
2a3635
 EnvironmentFile=-@CONFIGDIR@/sbd
2a3635
 SuccessExitStatus=100
2a3635
 
2a3635
-ExecStart=@sbindir@/pacemakerd -f
2a3635
+ExecStart=@sbindir@/pacemakerd
2a3635
 
2a3635
 # Systemd v227 and above can limit the number of processes spawned by a
2a3635
 # service. That is a bad idea for an HA cluster resource manager, so disable it
2a3635
diff --git a/doc/sphinx/Clusters_from_Scratch/verification.rst b/doc/sphinx/Clusters_from_Scratch/verification.rst
2a3635
index 9d647f8..b7fa20e 100644
2a3635
--- a/doc/sphinx/Clusters_from_Scratch/verification.rst
2a3635
+++ b/doc/sphinx/Clusters_from_Scratch/verification.rst
2a3635
@@ -103,7 +103,7 @@ the necessary processes are running:
2a3635
         2 ?        S      0:00 [kthreadd]
2a3635
     ...lots of processes...
2a3635
     17121 ?        SLsl   0:01 /usr/sbin/corosync -f
2a3635
-    17133 ?        Ss     0:00 /usr/sbin/pacemakerd -f
2a3635
+    17133 ?        Ss     0:00 /usr/sbin/pacemakerd
2a3635
     17134 ?        Ss     0:00  \_ /usr/libexec/pacemaker/pacemaker-based
2a3635
     17135 ?        Ss     0:00  \_ /usr/libexec/pacemaker/pacemaker-fenced
2a3635
     17136 ?        Ss     0:00  \_ /usr/libexec/pacemaker/pacemaker-execd
2a3635
-- 
2a3635
1.8.3.1
2a3635