git: b826e88d38c1 - main - fstat: Use POSIX str2sig(3)
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 11 Jun 2025 23:16:41 UTC
The branch main has been updated by imp:
URL: https://cgit.FreeBSD.org/src/commit/?id=b826e88d38c163528aa1b091294a6f4169f0309e
commit b826e88d38c163528aa1b091294a6f4169f0309e
Author: Ricardo Branco <rbranco@suse.de>
AuthorDate: 2025-05-10 21:43:47 +0000
Commit: Warner Losh <imp@FreeBSD.org>
CommitDate: 2025-06-11 23:16:22 +0000
fstat: Use POSIX str2sig(3)
Reviewed by: imp, kib, des, jilles
Pull Request: https://github.com/freebsd/freebsd-src/pull/1696
---
usr.bin/fstat/fuser.c | 34 +++-------------------------------
1 file changed, 3 insertions(+), 31 deletions(-)
diff --git a/usr.bin/fstat/fuser.c b/usr.bin/fstat/fuser.c
index 2e2befde6392..c38a520d4ce3 100644
--- a/usr.bin/fstat/fuser.c
+++ b/usr.bin/fstat/fuser.c
@@ -43,7 +43,6 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#include <sysexits.h>
#include <unistd.h>
@@ -108,7 +107,6 @@ struct reqfile {
static int flags = 0; /* Option flags. */
static void printflags(struct consumer *consumer);
-static int str2sig(const char *str);
static void usage(void) __dead2;
static int addfile(const char *path, struct reqfile *reqfile);
static void dofiles(struct procstat *procstat, struct kinfo_proc *kp,
@@ -164,7 +162,7 @@ do_fuser(int argc, char *argv[])
struct kinfo_proc *procs;
struct procstat *procstat;
struct reqfile *reqfiles;
- char *ep, *nlistf, *memf;
+ char *nlistf, *memf;
int ch, sig;
unsigned int i, cnt, nfiles;
@@ -199,17 +197,8 @@ do_fuser(int argc, char *argv[])
flags |= KFLAG;
break;
case 's':
- if (isdigit(*optarg)) {
- sig = strtol(optarg, &ep, 10);
- if (*ep != '\0' || sig < 0 || sig >= sys_nsig)
- errx(EX_USAGE, "illegal signal number" ": %s",
- optarg);
- } else {
- sig = str2sig(optarg);
- if (sig < 0)
- errx(EX_USAGE, "illegal signal name: "
- "%s", optarg);
- }
+ if (str2sig(optarg, &sig) != 0)
+ errx(EX_USAGE, "invalid signal: %s", optarg);
break;
case 'h':
/* PASSTHROUGH */
@@ -348,20 +337,3 @@ dofiles(struct procstat *procstat, struct kinfo_proc *kp,
}
procstat_freefiles(procstat, head);
}
-
-/*
- * Returns signal number for it's string representation.
- */
-static int
-str2sig(const char *str)
-{
- int i;
-
- if (!strncasecmp(str, "SIG", 3))
- str += 3;
- for (i = 1; i < sys_nsig; i++) {
- if (!strcasecmp(sys_signame[i], str))
- return (i);
- }
- return (-1);
-}