]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib: split ul_default_shell() from shells.c into default_shell.c
authorKarel Zak <kzak@redhat.com>
Mon, 4 May 2026 11:57:41 +0000 (13:57 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 11 May 2026 09:05:41 +0000 (11:05 +0200)
Move ul_default_shell() and UL_SHELL_* flags into a new
lib/default_shell.c and include/default_shell.h pair, and add the
new file to libcommon (autotools and meson).

ul_default_shell() has no dependency on libeconf -- it simply checks
$SHELL, passwd, and falls back to _PATH_BSHELL. Separating it from
shells.c (which depends on libeconf for /etc/shells enumeration)
allows binaries that only need the default shell lookup (flock,
script, scriptlive, more, exec_shell.c users) to avoid unnecessary
libeconf linkage.

Update callers that only use ul_default_shell() to include
default_shell.h instead of shells.h.

Signed-off-by: Karel Zak <kzak@redhat.com>
12 files changed:
include/Makemodule.am
include/default_shell.h [new file with mode: 0644]
include/shells.h
lib/Makemodule.am
lib/default_shell.c [new file with mode: 0644]
lib/exec_shell.c
lib/meson.build
lib/shells.c
sys-utils/flock.c
term-utils/script.c
term-utils/scriptlive.c
text-utils/more.c

index 8a9d6be00b0df649a41c44553df8eff282d13d3e..adf103d146303f08868bd33f56e82f000b3bbd83 100644 (file)
@@ -21,6 +21,7 @@ dist_noinst_HEADERS += \
        include/crc64.h \
        include/c_strtod.h \
        include/debug.h \
+       include/default_shell.h \
        include/encode.h \
        include/env.h \
        include/exec_shell.h \
diff --git a/include/default_shell.h b/include/default_shell.h
new file mode 100644 (file)
index 0000000..8b493bc
--- /dev/null
@@ -0,0 +1,14 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef UTIL_LINUX_DEFAULT_SHELL_H
+#define UTIL_LINUX_DEFAULT_SHELL_H
+
+#include <pwd.h>
+
+#define UL_SHELL_NOENV  (1 << 0)
+#define UL_SHELL_NOPWD  (1 << 1)
+
+const char *ul_default_shell(int flags, const struct passwd *pw);
+
+#endif /* UTIL_LINUX_DEFAULT_SHELL_H */
index 9e9114f652844f8a636da115816e88585eeb7fe8..9a3306349bfc78a4f83c3ecc5798d49d9e5e6250 100644 (file)
@@ -4,22 +4,14 @@
 #ifndef UTIL_LINUX_SHELLS_H
 #define UTIL_LINUX_SHELLS_H
 
-#include <pwd.h>
+#include <stdio.h>
 
 #if defined (HAVE_LIBECONF) && defined (USE_VENDORDIR)
 # include <libeconf.h>
-#endif
-
-#define UL_SHELL_NOENV  (1 << 0)
-#define UL_SHELL_NOPWD  (1 << 1)
-
-#if defined (HAVE_LIBECONF) && defined (USE_VENDORDIR)
 econf_file *open_etc_shells(void);
 #endif
 
 extern void print_shells(FILE *out, const char *format);
 extern int is_known_shell(const char *shell_name);
 
-const char *ul_default_shell(int flags, const struct passwd *pw);
-
 #endif /* UTIL_LINUX_SHELLS_H */
index cfaddf8e8d517b980ac4a2d3f8afe701c17d7e7b..10947e3e86065f8333cca98606b27e77c7a92fb9 100644 (file)
@@ -22,6 +22,7 @@ libcommon_la_SOURCES = \
        lib/crc64.c \
        lib/c_strtod.c \
        lib/debug.c \
+       lib/default_shell.c \
        lib/encode.c \
        lib/env.c \
        lib/fileutils.c \
diff --git a/lib/default_shell.c b/lib/default_shell.c
new file mode 100644 (file)
index 0000000..acada7e
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include <paths.h>
+
+#include "c.h"
+#include "default_shell.h"
+
+const char *ul_default_shell(int flags, const struct passwd *pw)
+{
+       const char *shell = NULL;
+
+       if (!(flags & UL_SHELL_NOENV)) {
+               shell = getenv("SHELL");
+               if (shell && *shell)
+                       return shell;
+       }
+       if (!(flags & UL_SHELL_NOPWD)) {
+               if (!pw)
+                       pw = getpwuid(getuid());
+               if (pw)
+                       shell = pw->pw_shell;
+               if (shell && *shell)
+                       return shell;
+       }
+
+       return _PATH_BSHELL;
+}
index 8f10ea4df4933b55b331305c6ddb25675c778df8..4e842c4c799d079a2ba25d4e5abe0ff28c16626a 100644 (file)
@@ -26,7 +26,7 @@
 #include "xalloc.h"
 
 #include "exec_shell.h"
-#include "shells.h"
+#include "default_shell.h"
 
 void __attribute__((__noreturn__)) exec_shell(void)
 {
index 6b017f659b987a93885c1d804a7a4f7a6d152e19..2164d57dd110af853554cde203d9dab641810fef 100644 (file)
@@ -8,6 +8,7 @@ lib_common_sources = '''
        crc64.c
        c_strtod.c
        debug.c
+       default_shell.c
        encode.c
        env.c
        fileutils.c
index ca7a8461d057f635e255c42e43cb8b56a52947c6..0e457605818f2ab24d314d79c07063eff4b07854 100644 (file)
@@ -121,24 +121,3 @@ extern int is_known_shell(const char *shell_name)
 #endif
        return ret;
 }
-
-const char *ul_default_shell(int flags, const struct passwd *pw)
-{
-       const char *shell = NULL;
-
-       if (!(flags & UL_SHELL_NOENV)) {
-               shell = getenv("SHELL");
-               if (shell && *shell)
-                       return shell;
-       }
-       if (!(flags & UL_SHELL_NOPWD)) {
-               if (!pw)
-                       pw = getpwuid(getuid());
-               if (pw)
-                       shell = pw->pw_shell;
-               if (shell && *shell)
-                       return shell;
-       }
-
-       return _PATH_BSHELL;
-}
index bfd7356591454f662f183a13e72bdecb561dcb4c..0708cf63b7de224b82d66ee11bac4ab07f3b9562 100644 (file)
@@ -47,7 +47,7 @@
 #include "closestream.h"
 #include "monotonic.h"
 #include "timer.h"
-#include "shells.h"
+#include "default_shell.h"
 
 #ifndef F_OFD_GETLK
 #define F_OFD_GETLK    36
index 1da9402dd6e2f99ac6b9494a1c6af78e4f07fb29..ae5caaa87ccebf09935112520ea5884b37c774b2 100644 (file)
@@ -70,7 +70,7 @@
 #include "signames.h"
 #include "pty-session.h"
 #include "debug.h"
-#include "shells.h"
+#include "default_shell.h"
 #include "fileutils.h"
 
 static UL_DEBUG_DEFINE_MASK(script);
index f36998a9945e95246dcc00116753b61b37e7c819..bf7c31244f93a75a38212b37013a9aab18958b7d 100644 (file)
@@ -38,7 +38,7 @@
 #include "pty-session.h"
 #include "script-playutils.h"
 #include "monotonic.h"
-#include "shells.h"
+#include "default_shell.h"
 
 
 #define SCRIPT_MIN_DELAY 0.0001                /* from original scriptreplay.pl */
index aa53e289c60ee52f01be32342d3355d35cc554a6..9cea37356c0071a6440df87f223f28c82f66a253 100644 (file)
@@ -89,7 +89,7 @@
 #include "widechar.h"
 #include "closestream.h"
 #include "env.h"
-#include "shells.h"
+#include "default_shell.h"
 
 #ifdef TEST_PROGRAM
 # define NON_INTERACTIVE_MORE 1