]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-scripts: New variable CTDB_PLATFORM_STYLE
authorMartin Schwenke <mschwenke@ddn.com>
Thu, 5 Mar 2026 03:37:20 +0000 (14:37 +1100)
committerAmitay Isaacs <amitay@samba.org>
Thu, 9 Jul 2026 16:02:43 +0000 (16:02 +0000)
CTDB_PLATFORM_STYLE is effectively a rename of CTDB_INIT_STYLE, since
a variable is needed that will be used for more purposes than "init".

The new variable is automatically set when sourcing the functions
file.

CTDB_INIT_STYLE is now deprecated and can still be set be calling
detect_init_style().  This provides backward compatibility for
site-local scripts.

Avoid using a state file.  Given that detect_platform_style() is now
only called in 1 place (i.e. immediately after its definition), the
state file is an unnecessary optimisation.  Also, using a state file,
and setting the variable automatically when sourcing the file, means
that CTDB_SCRIPT_VARDIR needs to be overridden in more UNIT test
suites.  For example, the tools ctdb lvs/natgw unit tests indirectly test
the ctdb_lvs/ctdb_natgw scripts, which source the functions file.

The previous sub-shell wasn't useful protection against a poisoned
/etc/os-release file.  Evil commands are evil commands, so if someone
can poison that file then we're in more trouble than this script can
handle.  However, limiting to a couple of variables with the eval/grep
trick seems like a a useful idea because those variables can then be
manually unset when they are no longer needed.  Using eval to do the
parsing also means that full manual parsing does not need to be
implemented, which would require handling (optional) quotes around
values.

Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
14 files changed:
ctdb/config/ctdb.init
ctdb/config/ctdb.sysconfig
ctdb/config/events/legacy/31.clamd.script
ctdb/config/events/legacy/41.httpd.script
ctdb/config/events/legacy/47.samba-dcerpcd.script
ctdb/config/events/legacy/48.netbios.script
ctdb/config/events/legacy/50.samba.script
ctdb/config/functions
ctdb/doc/ctdb.sysconfig.5.xml
ctdb/tests/UNIT/eventscripts/48.netbios.shutdown.011.sh
ctdb/tests/UNIT/eventscripts/48.netbios.startup.011.sh
ctdb/tests/UNIT/eventscripts/50.samba.shutdown.011.sh
ctdb/tests/UNIT/eventscripts/50.samba.startup.011.sh
ctdb/tests/UNIT/eventscripts/etc-ctdb/rc.local

index 237fa6a1ef0a0fc0363fd256dcd0e1df8bd2b5a1..de03f88a7acd03222bbbf8ee9105d6ee5ef2b97d 100755 (executable)
@@ -51,9 +51,6 @@ fi
 
 load_system_config "ctdb"
 
-detect_init_style
-export CTDB_INIT_STYLE
-
 ctdbd="${CTDBD:-/usr/sbin/ctdbd}"
 ctdb="${CTDB:-/usr/bin/ctdb}"
 pidfile="/var/run/ctdb/ctdbd.pid"
@@ -64,7 +61,7 @@ start()
 {
        printf "Starting ctdbd service: "
 
-       case "$CTDB_INIT_STYLE" in
+       case "$CTDB_PLATFORM_STYLE" in
        suse)
                startproc "$ctdbd"
                rc_status -v
@@ -86,7 +83,7 @@ stop()
 {
        printf "Shutting down ctdbd service: "
 
-       case "$CTDB_INIT_STYLE" in
+       case "$CTDB_PLATFORM_STYLE" in
        suse)
                "$ctdb" "shutdown"
                rc_status -v
@@ -117,7 +114,7 @@ restart()
 
 check_status()
 {
-       case "$CTDB_INIT_STYLE" in
+       case "$CTDB_PLATFORM_STYLE" in
        suse)
                checkproc -p "$pidfile" "$ctdbd"
                rc_status -v
index fc57929fc6840498729cf42c11224b3c582ae264..42ffeeda931b92510b9cec1adec14954dff05bf7 100644 (file)
@@ -8,4 +8,4 @@ ulimit -n 1048576
 ulimit -c unlimited
 
 # Useful if default detection doesn't work
-# CTDB_INIT_STYLE=debian
+# CTDB_PLATFORM_STYLE=debian
index c4e28adc240a38f615de583c02e037d397aa51e2..fd69e2ad5281378952e38e966ac4f49f32d4c0e6 100755 (executable)
@@ -6,9 +6,7 @@
 
 . "${CTDB_BASE}/functions"
 
-detect_init_style
-
-case $CTDB_INIT_STYLE in
+case "$CTDB_PLATFORM_STYLE" in
 redhat)
        service_name="clamd"
        ;;
index 048cf3286d73481d61d53fec18d2790d8e54b162..7d2b642a3a84e4be09b96e4988dc260295802f4f 100755 (executable)
@@ -6,9 +6,7 @@
 
 . "${CTDB_BASE}/functions"
 
-detect_init_style
-
-case $CTDB_INIT_STYLE in
+case "$CTDB_PLATFORM_STYLE" in
 redhat)
        service_name="httpd"
        ;;
index f2c0a9a23ab583c841258a1e38505ed450d44f8c..cb5fe91bba452c85ecfeee7d1b99663129972f8b 100755 (executable)
@@ -6,9 +6,7 @@
 
 . "${CTDB_BASE}/functions"
 
-detect_init_style
-
-case $CTDB_INIT_STYLE in
+case "$CTDB_PLATFORM_STYLE" in
 *)
        # distributions don't have this yet,
        # but assume samba-dcerpcd as service name
index cf2d1450af10e6ae862f8e5c07640b3573c06148..f18b5afe31d455f6a71c2646812da2f24a445267 100755 (executable)
@@ -6,9 +6,7 @@
 
 . "${CTDB_BASE}/functions"
 
-detect_init_style
-
-case $CTDB_INIT_STYLE in
+case $CTDB_PLATFORM_STYLE in
 suse)
        CTDB_SERVICE_NMB=${CTDB_SERVICE_NMB:-nmb}
        ;;
index fbffcec06e508d565d0379b35741a291d15d570a..9005cb6b0800ea1254bc400b553f47cf338d9d7f 100755 (executable)
@@ -6,9 +6,7 @@
 
 . "${CTDB_BASE}/functions"
 
-detect_init_style
-
-case $CTDB_INIT_STYLE in
+case "$CTDB_PLATFORM_STYLE" in
 suse)
        CTDB_SERVICE_SMB=${CTDB_SERVICE_SMB:-smb}
        ;;
index e6b1c848e2338886cfe1505d8f96243299311023..99b2905d142be9bd3704646977460e74eb096ed9 100755 (executable)
@@ -157,51 +157,54 @@ ctdb_check_args()
 }
 
 ##############################################################
-# determine on what type of system (init style) we are running
-detect_init_style()
+# determine on what type of system we are running
+detect_platform_style()
 {
-       _init_style_file="${CTDB_SCRIPT_VARDIR}/init-style"
+       CTDB_PLATFORM_STYLE=""
 
-       if [ ! -f "$_init_style_file" ]; then
-               if [ -n "$CTDB_INIT_STYLE" ]; then
-                       echo "$CTDB_INIT_STYLE" >"$_init_style_file"
-                       return
-               fi
+       _os_release="${CTDB_SYS_ETCDIR}/os-release"
+       if [ -f "$_os_release" ]; then
+               # Limit the variables that might be set
+               eval "$(grep '^ID=\|^ID_LIKE=' "$_os_release")"
 
-               # Subshell to contain variables in os-release file
-               (
-                       _os_release="${CTDB_SYS_ETCDIR}/os-release"
-                       if [ -f "$_os_release" ]; then
-                               . "$_os_release"
-                               case "$ID" in
-                               centos | fedora | rhel)
-                                       echo "redhat"
-                                       ;;
-                               debian | ubuntu)
-                                       echo "debian"
-                                       ;;
-                               sles | suse)
-                                       echo "suse"
-                                       ;;
-                               *)
-                                       case "$ID_LIKE" in
-                                       *centos* | *rhel*)
-                                               echo "redhat"
-                                               ;;
-                                       *)
-                                               echo "$ID"
-                                               ;;
-                                       esac
-                                       ;;
-                               esac
-                       else
-                               echo "WARNING: unknown distribution ${ID}" >&2
-                               echo "unknown"
-                       fi
-               ) >"$_init_style_file"
+               case "$ID" in
+               centos | fedora | rhel)
+                       CTDB_PLATFORM_STYLE="redhat"
+                       ;;
+               debian | ubuntu)
+                       CTDB_PLATFORM_STYLE="debian"
+                       ;;
+               sles | suse)
+                       CTDB_PLATFORM_STYLE="suse"
+                       ;;
+               *)
+                       case "$ID_LIKE" in
+                       *centos* | *rhel*)
+                               CTDB_PLATFORM_STYLE="redhat"
+                               ;;
+                       *)
+                               CTDB_PLATFORM_STYLE="$ID"
+                               ;;
+                       esac
+                       ;;
+               esac
+
+               unset -v ID ID_LIKE 2>/dev/null
+       fi
+
+       if [ -z "$CTDB_PLATFORM_STYLE" ]; then
+               echo "WARNING: unknown platform" >&2
+               CTDB_PLATFORM_STYLE="unknown"
        fi
+}
+
+detect_platform_style
 
-       read -r CTDB_INIT_STYLE <"$_init_style_file"
+detect_init_style()
+{
+       # CTDB_INIT_STYLE may be used by 3rd party scripts
+       # shellcheck disable=SC2034
+       CTDB_INIT_STYLE="$CTDB_PLATFORM_STYLE"
 }
 
 ######################################################
index b4cdaaf633ee17f10885240ae12486b528c0e5f1..c229b016a758db8b7bcd3426504a000bfd3ba8a3 100644 (file)
     <variablelist>
 
       <varlistentry>
-       <term>CTDB_INIT_STYLE=debian|redhat|suse</term>
+       <term>CTDB_PLATFORM_STYLE=debian|redhat|suse|freebsd</term>
        <listitem>
          <para>
-           This is the init style used by the Linux distribution (or
+           This characterises the Linux distribution (or
            other operating system) being used.  This is usually
            determined dynamically by checking the system.  This
-           variable is used by the initscript to determine which init
-           system primitives to use.  It is also used by some
-           eventscripts to choose the name of initscripts for certain
-           services, since these can vary between distributions.
+           variable is used by:
          </para>
+         <itemizedlist>
+           <listitem>
+             <para>
+               The initscript to determine which init system
+               primitives to use.
+             </para>
+           </listitem>
+           <listitem>
+             <para>
+               Some event scripts to determine services names, since
+               these can vary between distributions.
+             </para>
+           </listitem>
+           <listitem>
+             <para>
+               Some shell functions to determine which options to use
+               for certain commands.
+             </para>
+           </listitem>
+         </itemizedlist>
          <para>
            If using CTDB's event scripts are unable to determine an
            appropriate default then this option can also be placed in
@@ -59,8 +76,8 @@
            <manvolnum>5</manvolnum></citerefentry> file.
          </para>
          <para>
-           Default: NONE.  Guessed, based on features of
-           distribution.
+           Default: Based on contents of
+           <filename>/etc/os-release</filename>.
          </para>
        </listitem>
       </varlistentry>
index 06498138577eacacfed440f5e50de70aeb7337ba..1d186992d5e8722c31725861c5df924440378261 100755 (executable)
@@ -6,7 +6,7 @@ define_test "shutdown, Debian init style"
 
 setup
 
-export EVENTSCRIPT_TESTS_INIT_STYLE="debian"
+export EVENTSCRIPT_TESTS_PLATFORM_STYLE="debian"
 
 ok <<EOF
 Stopping nmbd: OK
index 40b90a10e650486d91599c7e92604a4fdb4fdc78..d9066a75646e70587b8856763db859a5e0005788 100755 (executable)
@@ -6,7 +6,7 @@ define_test "shutdown, Debian init style"
 
 setup
 
-export EVENTSCRIPT_TESTS_INIT_STYLE="debian"
+export EVENTSCRIPT_TESTS_PLATFORM_STYLE="debian"
 
 ok <<EOF
 Starting nmbd: OK
index 94867e0a71f72e2908f57fd73c54727f30f7fa34..36baaaa955354763226386e9beac39405fe84eb1 100755 (executable)
@@ -6,7 +6,7 @@ define_test "shutdown, Debian init style"
 
 setup
 
-export EVENTSCRIPT_TESTS_INIT_STYLE="debian"
+export EVENTSCRIPT_TESTS_PLATFORM_STYLE="debian"
 
 ok <<EOF
 Stopping smbd: OK
index 8c4699d45d2d3d5a7114bfa75bf69f4d350299e3..4daf7e89cc8ec20f6b1a2ed00baa3b6d4ddb5b8e 100755 (executable)
@@ -6,7 +6,7 @@ define_test "shutdown, Debian init style"
 
 setup
 
-export EVENTSCRIPT_TESTS_INIT_STYLE="debian"
+export EVENTSCRIPT_TESTS_PLATFORM_STYLE="debian"
 
 ok <<EOF
 Starting smbd: OK
index 777aeaff8b3159867cf488666603198ca62d8210..54e6869ce2ee709f0dbc6923ba7fc417587f3131 100755 (executable)
@@ -51,6 +51,6 @@ background_with_logging ()
     "$@" 2>&1 </dev/null | sed -e 's@^@\&@'
 }
 
-if [ -n "$EVENTSCRIPT_TESTS_INIT_STYLE" ]; then
-       CTDB_INIT_STYLE="$EVENTSCRIPT_TESTS_INIT_STYLE"
+if [ -n "$EVENTSCRIPT_TESTS_PLATFORM_STYLE" ]; then
+       CTDB_PLATFORM_STYLE="$EVENTSCRIPT_TESTS_PLATFORM_STYLE"
 fi