This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
[PATCH 1/2] Simplify creation of groups during installation
Use the "-f" option of "groupadd", rather than calling it a second
time if the desired GID is already in use.
Do not call "getent" twice. We know that a group exists if the first
call to "getent" returned successfully, or otherwise if "groupadd"
returned successfully.
---
stapbpf/Makefile.am | 3 +--
stapbpf/Makefile.in | 3 +--
staprun/Makefile.am | 6 +++---
staprun/Makefile.in | 6 +++---
systemtap.spec | 8 ++++----
5 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/stapbpf/Makefile.am b/stapbpf/Makefile.am
index fa2035d..1626e4a 100644
--- a/stapbpf/Makefile.am
+++ b/stapbpf/Makefile.am
@@ -43,8 +43,7 @@ git_version.stamp ../git_version.h:
# make install, and have "sudo stap ...." or "sudo stapbpf ...." work later.
install-exec-hook:
if [ `id -u` -eq 0 ]; then \
- getent group stapusr >/dev/null || groupadd -g 156 -r stapusr 2>/dev/null || groupadd -r stapusr; \
- getent group stapusr >/dev/null \
+ (getent group stapusr >/dev/null || groupadd -f -g 156 -r stapusr) \
&& chgrp stapusr "$(DESTDIR)$(bindir)/stapbpf" \
&& chmod 04110 "$(DESTDIR)$(bindir)/stapbpf"; \
fi
diff --git a/stapbpf/Makefile.in b/stapbpf/Makefile.in
index f7f20b6..487da04 100644
--- a/stapbpf/Makefile.in
+++ b/stapbpf/Makefile.in
@@ -849,8 +849,7 @@ uninstall-man: uninstall-man8
# make install, and have "sudo stap ...." or "sudo stapbpf ...." work later.
@HAVE_BPF_DECLS_TRUE@install-exec-hook:
@HAVE_BPF_DECLS_TRUE@ if [ `id -u` -eq 0 ]; then \
-@HAVE_BPF_DECLS_TRUE@ getent group stapusr >/dev/null || groupadd -g 156 -r stapusr 2>/dev/null || groupadd -r stapusr; \
-@HAVE_BPF_DECLS_TRUE@ getent group stapusr >/dev/null \
+@HAVE_BPF_DECLS_TRUE@ (getent group stapusr >/dev/null || groupadd -f -g 156 -r stapusr) \
@HAVE_BPF_DECLS_TRUE@ && chgrp stapusr "$(DESTDIR)$(bindir)/stapbpf" \
@HAVE_BPF_DECLS_TRUE@ && chmod 04110 "$(DESTDIR)$(bindir)/stapbpf"; \
@HAVE_BPF_DECLS_TRUE@ fi
diff --git a/staprun/Makefile.am b/staprun/Makefile.am
index 73ddc41..f1a7a69 100644
--- a/staprun/Makefile.am
+++ b/staprun/Makefile.am
@@ -78,7 +78,7 @@ git_version.stamp ../git_version.h:
# make install, and have "sudo stap ...." or "sudo staprun ...." work later.
install-exec-hook:
if [ `id -u` -eq 0 ]; then \
- getent group stapusr >/dev/null || groupadd -g 156 -r stapusr 2>/dev/null || groupadd -r stapusr; \
- getent group stapusr >/dev/null && chgrp stapusr "$(DESTDIR)$(bindir)/staprun"; \
- chmod 04110 "$(DESTDIR)$(bindir)/staprun"; \
+ (getent group stapusr >/dev/null || groupadd -f -g 156 -r stapusr) \
+ && chgrp stapusr "$(DESTDIR)$(bindir)/staprun" \
+ && chmod 04110 "$(DESTDIR)$(bindir)/staprun"; \
fi
diff --git a/staprun/Makefile.in b/staprun/Makefile.in
index 6cb3966..c518c7d 100644
--- a/staprun/Makefile.in
+++ b/staprun/Makefile.in
@@ -1162,9 +1162,9 @@ git_version.stamp ../git_version.h:
# make install, and have "sudo stap ...." or "sudo staprun ...." work later.
install-exec-hook:
if [ `id -u` -eq 0 ]; then \
- getent group stapusr >/dev/null || groupadd -g 156 -r stapusr 2>/dev/null || groupadd -r stapusr; \
- getent group stapusr >/dev/null && chgrp stapusr "$(DESTDIR)$(bindir)/staprun"; \
- chmod 04110 "$(DESTDIR)$(bindir)/staprun"; \
+ (getent group stapusr >/dev/null || groupadd -f -g 156 -r stapusr) \
+ && chgrp stapusr "$(DESTDIR)$(bindir)/staprun" \
+ && chmod 04110 "$(DESTDIR)$(bindir)/staprun"; \
fi
# Tell versions [3.59,3.63) of GNU make to not export all variables.
diff --git a/systemtap.spec b/systemtap.spec
index c3a9a32..26bfad0 100644
--- a/systemtap.spec
+++ b/systemtap.spec
@@ -767,13 +767,13 @@ done
%endif
%pre runtime
-getent group stapusr >/dev/null || groupadd -g 156 -r stapusr 2>/dev/null || groupadd -r stapusr
-getent group stapsys >/dev/null || groupadd -g 157 -r stapsys 2>/dev/null || groupadd -r stapsys
-getent group stapdev >/dev/null || groupadd -g 158 -r stapdev 2>/dev/null || groupadd -r stapdev
+getent group stapusr >/dev/null || groupadd -f -g 156 -r stapusr
+getent group stapsys >/dev/null || groupadd -f -g 157 -r stapsys
+getent group stapdev >/dev/null || groupadd -f -g 158 -r stapdev
exit 0
%pre server
-getent group stap-server >/dev/null || groupadd -g 155 -r stap-server 2>/dev/null || groupadd -r stap-server
+getent group stap-server >/dev/null || groupadd -f -g 155 -r stap-server
getent passwd stap-server >/dev/null || \
useradd -c "Systemtap Compile Server" -u 155 -g stap-server -d %{_localstatedir}/lib/stap-server -r -s /sbin/nologin stap-server 2>/dev/null || \
useradd -c "Systemtap Compile Server" -g stap-server -d %{_localstatedir}/lib/stap-server -r -s /sbin/nologin stap-server
--
1.8.3.1