From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 88320 invoked by alias); 30 Jan 2019 05:38:06 -0000 Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org Received: (qmail 88260 invoked by uid 89); 30 Jan 2019 05:38:05 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,UNPARSEABLE_RELAY autolearn=ham version=3.3.2 spammy=H*r:sk:systemt X-HELO: llmx2.ll.mit.edu Received: from LLMX2.LL.MIT.EDU (HELO llmx2.ll.mit.edu) (129.55.12.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 30 Jan 2019 05:38:01 +0000 Received: from LLE2K16-MBX01.mitll.ad.local (LLE2K16-MBX01.mitll.ad.local) by llmx2.ll.mit.edu (unknown) with ESMTP id x0U5bxVK012682 for ; Wed, 30 Jan 2019 00:37:59 -0500 From: David Ward To: Subject: [PATCH 1/2] Simplify creation of groups during installation Date: Wed, 30 Jan 2019 05:38:00 -0000 Message-ID: <1548826676-25560-2-git-send-email-david.ward@ll.mit.edu> In-Reply-To: <1548826676-25560-1-git-send-email-david.ward@ll.mit.edu> References: <1548826676-25560-1-git-send-email-david.ward@ll.mit.edu> MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2019-q1/txt/msg00024.txt.bz2 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