[systemd-devel] [PATCH 1/7] make utmp/wtmp support configurable

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Thu Sep 25 19:43:13 PDT 2014


On Wed, Sep 24, 2014 at 05:25:00PM +0200, Emil Renner Berthing wrote:
> For now just stub out the functions in utmp-wtmp.h
> so code will still compile. These stubs will be
> removed in the last commit in this patch series.
> ---
>  Makefile.am                         | 34 +++++++++++++++++++++++++++-------
>  configure.ac                        | 11 +++++++++++
>  man/runlevel.xml                    |  3 ++-
>  man/systemd-update-utmp.service.xml |  2 +-
>  src/core/build.h                    |  7 +++++++
>  src/shared/utmp-wtmp.h              | 28 ++++++++++++++++++++++++++++
>  6 files changed, 76 insertions(+), 9 deletions(-)
Hm, I understand why this is wanted, but the approach is rather intrusive.
Can you instead modify utmp-wtmp.c to provide noop stubs when utmp
is disabled? Other places should simply call the utmp_* functions as before.
Possibly if there are other places where significant prepration is
done before calling utmp_*, like server_forward_wall, stub implementations
could be provided too, but only if it seems to make a significant difference
at runtime. In general please try to minimize ifdefs, we have too many
of those already.

Zbyszek

> diff --git a/Makefile.am b/Makefile.am
> index 6b2ca29..47a1c07 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -378,7 +378,6 @@ rootlibexec_PROGRAMS = \
>  	systemd \
>  	systemd-cgroups-agent \
>  	systemd-initctl \
> -	systemd-update-utmp \
>  	systemd-shutdownd \
>  	systemd-shutdown \
>  	systemd-remount-fs \
> @@ -391,6 +390,11 @@ rootlibexec_PROGRAMS = \
>  	systemd-socket-proxyd \
>  	systemd-update-done
>  
> +if HAVE_UTMP
> +rootlibexec_PROGRAMS += \
> +	systemd-update-utmp
> +endif
> +
>  systemgenerator_PROGRAMS = \
>  	systemd-getty-generator \
>  	systemd-fstab-generator \
> @@ -517,8 +521,6 @@ nodist_systemunit_DATA = \
>  	units/systemd-initctl.service \
>  	units/systemd-shutdownd.service \
>  	units/systemd-remount-fs.service \
> -	units/systemd-update-utmp.service \
> -	units/systemd-update-utmp-runlevel.service \
>  	units/systemd-ask-password-wall.service \
>  	units/systemd-ask-password-console.service \
>  	units/systemd-sysctl.service \
> @@ -544,6 +546,12 @@ nodist_systemunit_DATA = \
>  	units/systemd-nspawn at .service \
>  	units/systemd-update-done.service
>  
> +if HAVE_UTMP
> +nodist_systemunit_DATA += \
> +	units/systemd-update-utmp.service \
> +	units/systemd-update-utmp-runlevel.service
> +endif
> +
>  dist_userunit_DATA = \
>  	units/user/basic.target \
>  	units/user/default.target \
> @@ -565,8 +573,6 @@ EXTRA_DIST += \
>  	units/systemd-initctl.service.in \
>  	units/systemd-shutdownd.service.in \
>  	units/systemd-remount-fs.service.in \
> -	units/systemd-update-utmp.service.in \
> -	units/systemd-update-utmp-runlevel.service.in \
>  	units/systemd-ask-password-wall.service.in \
>  	units/systemd-ask-password-console.service.in \
>  	units/systemd-sysctl.service.in \
> @@ -589,6 +595,12 @@ EXTRA_DIST += \
>  	units/systemd-nspawn at .service.in \
>  	units/systemd-update-done.service.in
>  
> +if HAVE_UTMP
> +EXTRA_DIST += \
> +	units/systemd-update-utmp.service.in \
> +	units/systemd-update-utmp-runlevel.service.in
> +endif
> +
>  CLEANFILES += \
>  	units/console-shell.service.m4 \
>  	units/console-getty.service.m4 \
> @@ -805,7 +817,6 @@ libsystemd_shared_la_SOURCES = \
>  	src/shared/cgroup-show.h \
>  	src/shared/unit-name.c \
>  	src/shared/unit-name.h \
> -	src/shared/utmp-wtmp.c \
>  	src/shared/utmp-wtmp.h \
>  	src/shared/watchdog.c \
>  	src/shared/watchdog.h \
> @@ -879,6 +890,11 @@ libsystemd_shared_la_SOURCES = \
>  	src/shared/switch-root.c \
>  	src/shared/nss-util.h
>  
> +if HAVE_UTMP
> +libsystemd_shared_la_SOURCES += \
> +	src/shared/utmp-wtmp.c
> +endif
> +
>  nodist_libsystemd_shared_la_SOURCES = \
>  	src/shared/errno-from-name.h \
>  	src/shared/errno-to-name.h \
> @@ -5920,8 +5936,12 @@ RUNLEVEL5_TARGET_WANTS += \
>  	systemd-update-utmp-runlevel.service
>  endif
>  
> +if HAVE_UTMP
> +SYSINIT_TARGET_WANTS += \
> +	systemd-update-utmp.service
> +endif
> +
>  SYSINIT_TARGET_WANTS += \
> -	systemd-update-utmp.service \
>  	systemd-update-done.service
>  
>  LOCAL_FS_TARGET_WANTS += \
> diff --git a/configure.ac b/configure.ac
> index 38a165c..34282b6 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -346,6 +346,16 @@ AS_IF([test "x$enable_dbus" != "xno"], [
>  AM_CONDITIONAL(HAVE_DBUS, [test "$have_dbus" = "yes"])
>  
>  # ------------------------------------------------------------------------------
> +have_utmp=yes
> +AC_ARG_ENABLE([utmp], AS_HELP_STRING([--disable-utmp], [disable utmp/wtmp log handling]),
> +        AS_CASE("x${enableval}",
> +                [xyes], [have_utmp=yes],
> +                [xno],  [have_utmp=no],
> +                AC_MSG_ERROR(bad value ${enableval} for --enable-utmp)))
> +AS_IF([test "x$have_utmp" = "xyes"], [AC_DEFINE(HAVE_UTMP, 1, [Define if utmp/wtmp support is enabled])])
> +AM_CONDITIONAL([HAVE_UTMP], [test "x$have_utmp" = "xyes"])
> +
> +# ------------------------------------------------------------------------------
>  have_compat_libs=no
>  AC_ARG_ENABLE([compat_libs], AS_HELP_STRING([--enable-compat-libs],[Enable creation of compatibility libraries]),
>                  [case "${enableval}" in
> @@ -1381,6 +1391,7 @@ AC_MSG_RESULT([
>          Split /usr:              ${enable_split_usr}
>          SysV compatibility:      ${SYSTEM_SYSV_COMPAT}
>          compatibility libraries: ${have_compat_libs}
> +        utmp/wtmp support:       ${have_utmp}
>  
>          prefix:                  ${prefix}
>          rootprefix:              ${with_rootprefix}
> diff --git a/man/runlevel.xml b/man/runlevel.xml
> index 976753a..db9a436 100644
> --- a/man/runlevel.xml
> +++ b/man/runlevel.xml
> @@ -22,7 +22,8 @@
>  -->
>  
>  <refentry id="runlevel"
> -          xmlns:xi="http://www.w3.org/2001/XInclude">
> +          xmlns:xi="http://www.w3.org/2001/XInclude"
> +          conditional="HAVE_UTMP">
>  
>          <refentryinfo>
>                  <title>runlevel</title>
> diff --git a/man/systemd-update-utmp.service.xml b/man/systemd-update-utmp.service.xml
> index 7d9e32e..caa1d8f 100644
> --- a/man/systemd-update-utmp.service.xml
> +++ b/man/systemd-update-utmp.service.xml
> @@ -19,7 +19,7 @@
>    You should have received a copy of the GNU Lesser General Public License
>    along with systemd; If not, see <http://www.gnu.org/licenses/>.
>  -->
> -<refentry id="systemd-update-utmp.service">
> +<refentry id="systemd-update-utmp.service" conditional="HAVE_UTMP">
>  
>          <refentryinfo>
>                  <title>systemd-update-utmp.service</title>
> diff --git a/src/core/build.h b/src/core/build.h
> index a7f12a3..361f612 100644
> --- a/src/core/build.h
> +++ b/src/core/build.h
> @@ -21,6 +21,12 @@
>    along with systemd; If not, see <http://www.gnu.org/licenses/>.
>  ***/
>  
> +#ifdef HAVE_UTMP
> +#define _UTMP_FEATURE_ "+UTMP"
> +#else
> +#define _UTMP_FEATURE_ "-UTMP"
> +#endif
> +
>  #ifdef HAVE_PAM
>  #define _PAM_FEATURE_ "+PAM"
>  #else
> @@ -130,6 +136,7 @@
>  #endif
>  
>  #define SYSTEMD_FEATURES                                                \
> +        _UTMP_FEATURE_ " "                                              \
>          _PAM_FEATURE_ " "                                               \
>          _AUDIT_FEATURE_ " "                                             \
>          _SELINUX_FEATURE_ " "                                           \
> diff --git a/src/shared/utmp-wtmp.h b/src/shared/utmp-wtmp.h
> index 040a16e..87d004e 100644
> --- a/src/shared/utmp-wtmp.h
> +++ b/src/shared/utmp-wtmp.h
> @@ -23,6 +23,7 @@
>  
>  #include "util.h"
>  
> +#ifdef HAVE_UTMP
>  int utmp_get_runlevel(int *runlevel, int *previous);
>  
>  int utmp_put_shutdown(void);
> @@ -33,3 +34,30 @@ int utmp_put_dead_process(const char *id, pid_t pid, int code, int status);
>  int utmp_put_init_process(const char *id, pid_t pid, pid_t sid, const char *line);
>  
>  int utmp_wall(const char *message, const char *username, bool (*match_tty)(const char *tty));
> +
> +#else /* HAVE_UTMP */
> +
> +static inline int utmp_get_runlevel(int *runlevel, int *previous) {
> +        return -ESRCH;
> +}
> +static inline int utmp_put_shutdown(void) {
> +        return 0;
> +}
> +static inline int utmp_put_reboot(usec_t timestamp) {
> +        return 0;
> +}
> +static inline int utmp_put_runlevel(int runlevel, int previous) {
> +        return 0;
> +}
> +static inline int utmp_put_dead_process(const char *id, pid_t pid, int code, int status) {
> +        return 0;
> +}
> +static inline int utmp_put_init_process(const char *id, pid_t pid, pid_t sid, const char *line) {
> +        return 0;
> +}
> +static inline int utmp_wall(const char *message, const char *username,
> +                bool (*match_tty)(const char *tty)) {
> +        return 0;
> +}
> +
> +#endif /* HAVE_UTMP */
> -- 
> 2.1.0
> 
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel
> 


More information about the systemd-devel mailing list