[DTrace-devel] [PATCH v2 8/9] build: make dtrace and dtprobed relocatable

Kris Van Hees kris.van.hees at oracle.com
Fri Aug 2 05:31:45 UTC 2024


On Thu, Aug 01, 2024 at 02:21:55PM +0100, Nick Alcock wrote:
> The majority of the complexity here involves figuring out what to
> do about the systemd service file.  We presume that if the user
> is installing such that the service file lands inone of the two fixed
> locations systemd knows how to find persistent service files in, or
> if the user has explicitly passed --systemd-unit-dir to configure,
> it makes sense to install the systemd service file (because systemd
> will find it): otherwise, we avoid installing it and print a
> warning that the user must do so if dtprobed is to be properly
> started.
> 
> Provide a new installation target, install-dtprobed-autostart, to do
> so.
> 
> (Regardless, the service file is changed to substitute in the real
> installed path of dtprobed.)
> 
> Signed-off-by: Nick Alcock <nick.alcock at oracle.com>

Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>

> ---
>  Maketargets                                   |  3 ++
>  cmd/Build                                     |  4 +--
>  dtprobed/Build                                | 36 ++++++++++++++-----
>  .../{dtprobed.service => dtprobed.service.in} |  2 +-
>  4 files changed, 34 insertions(+), 11 deletions(-)
>  rename dtprobed/{dtprobed.service => dtprobed.service.in} (95%)
> 
> diff --git a/Maketargets b/Maketargets
> index 11ad9fed4dcf..5b4906a86d26 100644
> --- a/Maketargets
> +++ b/Maketargets
> @@ -14,6 +14,9 @@ help::
>  	@printf "dlibs                          Build translator files\n" >&2
>  	@printf "install                        Install (DESTDIR supported)\n" >&2
>  	@printf "install-test                   Install testsuite (DESTDIR supported)\n" >&2
> +	@printf "install-dtprobed-autostart     Install udev / systemd rules to start dtprobed" >&2
> +	@printf "                               (done by make install unless prefix or sbindir" >&2
> +	@printf "                                are changed)" >&2
>  	@printf "clean / realclean              Clean up build tree\n" >&2
>  	@printf "TAGS / tags / gtags            Make tags files\n" >&2
>  	@printf "\n" >&2
> diff --git a/cmd/Build b/cmd/Build
> index 55c622c19dc0..68800fbeb5fc 100644
> --- a/cmd/Build
> +++ b/cmd/Build
> @@ -1,5 +1,5 @@
>  # Oracle Linux DTrace.
> -# Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
> +# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
>  # Licensed under the Universal Permissive License v 1.0 as shown at
>  # http://oss.oracle.com/licenses/upl.
>  
> @@ -36,7 +36,7 @@ if [[ -z \$$_DTRACE_CHECK_INSTALLED ]]; then\n\
>      export LD_LIBRARY_PATH=$(objdir)\n\
>      dtrace_cmd=$(objdir)/dtrace\n\
>  else\n\
> -    dtrace_cmd=/usr/sbin/dtrace\n\
> +    dtrace_cmd=$(SBINDIR)/dtrace\n\
>  fi\n\
>  \n\
>  if [[ -n \$$DTRACE_GDB ]]; then\n\
> diff --git a/dtprobed/Build b/dtprobed/Build
> index 0f5d1c08aee8..9132c3e31c8a 100644
> --- a/dtprobed/Build
> +++ b/dtprobed/Build
> @@ -42,17 +42,13 @@ dtprobed.c_CFLAGS := -Wno-pedantic
>  seccomp-assistance.c_CFLAGS := -fno-lto
>  endif
>  
> -install::
> -	mkdir -p $(INSTSBINDIR)
> -	$(call describe-install-target,$(INSTSBINDIR),dtprobed)
> -	install -m 755 $(objdir)/dtprobed $(INSTSBINDIR)
> -	mkdir -p $(INSTUDEVDIR)
> -	$(call describe-install-target,$(INSTUDEVDIR),60-dtprobed.rules)
> -	install -m 644 $(dtprobed_DIR)60-dtprobed.rules $(INSTUDEVDIR)
> +install-dtprobed-autostart::
>  ifdef HAVE_LIBSYSTEMD
>  	mkdir -p $(INSTSYSTEMDUNITDIR) $(INSTSYSTEMDPRESETDIR)
>  	$(call describe-install-target,$(INSTSYSTEMDUNITDIR),dtprobed.service)
> -	install -m 644 $(dtprobed_DIR)dtprobed.service $(INSTSYSTEMDUNITDIR)
> +	sed 's, at SBINDIR@,$(SBINDIR),' < $(dtprobed_DIR)dtprobed.service.in > $(INSTSYSTEMDUNITDIR)/dtprobed.service
> +        chown root:root $(INSTSYSTEMDUNITDIR)/dtprobed.service
> +	chmod 0644 $(INSTSYSTEMDUNITDIR)/dtprobed.service
>  	$(call describe-install-target,$(INSTSYSTEMDUNITDIR),dtrace-usdt.target)
>  	install -m 644 $(dtprobed_DIR)dtrace-usdt.target $(INSTSYSTEMDUNITDIR)
>  	$(call describe-install-target,$(INSTSYSTEMDPRESETDIR),50-dtprobed.preset)
> @@ -61,3 +57,27 @@ ifdef HAVE_LIBSYSTEMD
>  		systemctl enable dtprobed.service dtrace-usdt.target; \
>  	fi
>  endif
> +
> +install::
> +	mkdir -p $(INSTSBINDIR)
> +	$(call describe-install-target,$(INSTSBINDIR),dtprobed)
> +	install -m 755 $(objdir)/dtprobed $(INSTSBINDIR)
> +	mkdir -p $(INSTUDEVDIR)
> +	$(call describe-install-target,$(INSTUDEVDIR),60-dtprobed.rules)
> +	install -m 644 $(dtprobed_DIR)60-dtprobed.rules $(INSTUDEVDIR)
> +	if [[ "$(SYSTEMDUNITDIR)" = /usr/lib/systemd/system ]] || \
> +	   [[ "$(SYSTEMDUNITDIR)" = /usr/local/lib/systemd/system ]] || \
> +	   [[ -n "$(filter SYSTEMDUNITDIR,$(CONFIGURED_VARS))" ]] ; then \
> +		$(MAKE) install-dtprobed-autostart; \
> +	else \
> +		echo " === WARNING WARNING WARNING === " >&2; \
> +		echo "systemd service files for dtprobed not installed." >&2; \
> +		echo "USDT probes (and the testsuite) will not work unless this is" >&2; \
> +		echo "done.  Try make install-dtprobed-autostart, but this may not" >&2; \
> +		echo "be enough: you may need to manually move the systemd service" >&2; \
> +		echo "files somewhere udev and systemd will find them." >&2; \
> +		echo "If there is already a running dtprobed, it may or may not work" >&2; \
> +		echo "in conjunction with this DTrace." >&2; \
> +		echo "Configure with --systemd-unit-dir to override this decision." >&2; \
> +		echo " === WARNING WARNING WARNING === " >&2; \
> +	fi
> diff --git a/dtprobed/dtprobed.service b/dtprobed/dtprobed.service.in
> similarity index 95%
> rename from dtprobed/dtprobed.service
> rename to dtprobed/dtprobed.service.in
> index 8e491fe28ad1..2e590701d03e 100644
> --- a/dtprobed/dtprobed.service
> +++ b/dtprobed/dtprobed.service.in
> @@ -12,7 +12,7 @@ Before=basic.target
>  
>  [Service]
>  Type=notify
> -ExecStart=/usr/sbin/dtprobed -F
> +ExecStart=@SBINDIR@/dtprobed -F
>  Restart=on-failure
>  RestartPreventExitStatus=1
>  ProtectSystem=strict
> -- 
> 2.46.0.277.ge12b8151ed



More information about the DTrace-devel mailing list