From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 4EA1215838C for ; Wed, 24 Jan 2024 22:53:26 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 75A9CE2A5E; Wed, 24 Jan 2024 22:53:25 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 54783E2A5E for ; Wed, 24 Jan 2024 22:53:25 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 42E0A3433E2 for ; Wed, 24 Jan 2024 22:53:24 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 5D6F5EC0 for ; Wed, 24 Jan 2024 22:53:22 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1706136700.a8a823e6acf88625fd482e15b2ba69c5f165fe46.vapier@gentoo> Subject: [gentoo-commits] proj/pax-utils:master commit in: / X-VCS-Repository: proj/pax-utils X-VCS-Files: pspax.c X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: a8a823e6acf88625fd482e15b2ba69c5f165fe46 X-VCS-Branch: master Date: Wed, 24 Jan 2024 22:53:22 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 77ecc34c-792a-499a-b107-6cb0732a06d0 X-Archives-Hash: db8f29040e9300535d187e0af05146f3 commit: a8a823e6acf88625fd482e15b2ba69c5f165fe46 Author: Mike Frysinger gentoo org> AuthorDate: Wed Jan 24 22:51:40 2024 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Wed Jan 24 22:51:40 2024 +0000 URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=a8a823e6 pspax: replace proc_fopen with fopenat_r Switch to the common helper we have in paxinc already that does exactly the same thing as this proc_fopen. Signed-off-by: Mike Frysinger gentoo.org> pspax.c | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/pspax.c b/pspax.c index 97d51c6..81392b1 100644 --- a/pspax.c +++ b/pspax.c @@ -40,33 +40,12 @@ static pid_t show_pid = 0; static uid_t show_uid = (uid_t)-1; static gid_t show_gid = (gid_t)-1; -static int proc_open(int pfd, const char *file) -{ - return openat(pfd, file, O_RDONLY|O_CLOEXEC); -} - -static FILE *proc_fopen(int pfd, const char *file) -{ - int fd; - FILE *fp; - - fd = proc_open(pfd, file); - if (fd == -1) - return NULL; - - fp = fdopen(fd, "re"); - if (fp == NULL) - close(fd); - - return fp; -} - static elfobj *proc_readelf(int pfd) { int fd; elfobj *elf; - fd = proc_open(pfd, "exe"); + fd = openat(pfd, "exe", O_RDONLY|O_CLOEXEC); if (fd == -1) return NULL; @@ -80,7 +59,7 @@ static const char *get_proc_name_cmdline(int pfd) FILE *fp; static char str[1024]; - fp = proc_fopen(pfd, "cmdline"); + fp = fopenat_r(pfd, "cmdline"); if (fp == NULL) return NULL; @@ -107,7 +86,7 @@ static const char *get_proc_name(int pfd) if (wide_output) return get_proc_name_cmdline(pfd); - fp = proc_fopen(pfd, "stat"); + fp = fopenat_r(pfd, "stat"); if (fp == NULL) return NULL; @@ -142,7 +121,7 @@ static int get_proc_maps(int pfd) FILE *fp; static char str[BUFSIZ]; - if ((fp = proc_fopen(pfd, "maps")) == NULL) + if ((fp = fopenat_r(pfd, "maps")) == NULL) return -1; while (fgets(str, sizeof(str), fp)) { @@ -178,7 +157,7 @@ static int print_executable_mappings(int pfd) FILE *fp; static char str[BUFSIZ]; - if ((fp = proc_fopen(pfd, "maps")) == NULL) + if ((fp = fopenat_r(pfd, "maps")) == NULL) return -1; while (fgets(str, sizeof(str), fp)) { @@ -224,7 +203,7 @@ static const char *get_proc_status(int pfd, const char *name) size_t len; static char str[BUFSIZ]; - if ((fp = proc_fopen(pfd, "status")) == NULL) + if ((fp = fopenat_r(pfd, "status")) == NULL) return NULL; len = strlen(name); @@ -248,7 +227,7 @@ static const char *get_pid_attr(int pfd) char *p; static char buf[BUFSIZ]; - if ((fp = proc_fopen(pfd, "attr/current")) == NULL) + if ((fp = fopenat_r(pfd, "attr/current")) == NULL) return NULL; if (fgets(buf, sizeof(buf), fp) != NULL) @@ -265,7 +244,7 @@ static const char *get_pid_addr(int pfd) char *p; static char buf[BUFSIZ]; - if ((fp = proc_fopen(pfd, "ipaddr")) == NULL) + if ((fp = fopenat_r(pfd, "ipaddr")) == NULL) return NULL; if (fgets(buf, sizeof(buf), fp) != NULL)