[PATCH] cups: fix a build race-condition around empty directories removal

Yoann Congal via Gimp-print-devel <[email protected]> Thu, 3 Jul 2025 18:42:44 +0200
Newsgroups gmane.linux.printing.gimp-print.devel
Message-ID <[email protected]>
From: Yoann Congal <[email protected]>

In automake, install-exec and install-data happen in parallel.
install-exec installs executables and install-data finishes with
install-data-hook that removes empty directories. If install-data-hook
happen before install-exec finishes, it might remove a directory while
it is used by the install process and make it fail.

Fix this by adding an explicit dependency between install-data-hook and
install-exec.

For example, here is the log of such a failure:
| make  install-data-hook
|  hosttools/mkdir -p 'image/usr/libexec/cups/backend'
| make[5]: Entering directory '$WORKDIR/build/src/cups'
| Expect a number of "rmdir: Directory not empty" warnings
|   /bin/bash ../../libtool   --mode=install $HOSTTOOLS/install -c backend_gutenprint '$WORKDIR/image/usr/libexec/cups/backend'
 # Start of the install process (from install-exec)
| These messages are harmless and should be ignored.
...
| rmdir $WORKDIR/image/usr/libexec/cups/backend
 # empty /usr/libexec/cups/backend is removed (from install-data-hook)
...
| libtool: install: $HOSTTOOLS/install -c backend_gutenprint $WORKDIR/image/usr/libexec/cups/backend
 # install in a non-existing directory: backend_gutenprint is installed
 # as /usr/libexec/cups/backend (this is now a file instead of a
 # directory)
| make  install-exec-hook
| make[5]: Entering directory '$WORKDIR/build/src/cups'
| chmod 700 $WORKDIR/image/usr/libexec/cups/backend/backend_gutenprint
| chmod: cannot access '$WORKDIR/image/usr/libexec/cups/backend/backend_gutenprint': Not a directory
 # chmod fails because /usr/libexec/cups/backend is a file and not a
 # directory
| make[5]: *** [Makefile:2166: install-exec-hook] Error 1

Signed-off-by: Yoann Congal <[email protected]>
---
 src/cups/Makefile.am | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/cups/Makefile.am b/src/cups/Makefile.am
index c22a8632..9774abaa 100644
--- a/src/cups/Makefile.am
+++ b/src/cups/Makefile.am
@@ -206,8 +206,9 @@ uninstall-local: $(INSTALL_DATA_LOCAL_DEPS) $(INSTALL_BLACKLIST)
 	$(RM) -f "$(DESTDIR)$(cupsdata_blacklistdir)/net.sf.gimp-print.usb-quirks"
 	$(RM) -f "$(DESTDIR)$(pkglibdir)/backend/gutenprint$(GUTENPRINT_MAJOR_VERSION)$(GUTENPRINT_MINOR_VERSION)+usb"
 
-install-data-hook:
+install-data-hook: install-exec
 # Remove unused directories in install tree
+# Note: it removes "exec" directories, so it must happen after install-exec.
 	-@echo 'Expect a number of "rmdir: Directory not empty" warnings'
 	-@echo 'These messages are harmless and should be ignored.'
 	-rmdir $(DESTDIR)$(cups_modeldir)