Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/find Use /dev/tty for SIGINFO



details:   https://anonhg.NetBSD.org/src/rev/11a2b5a11fbe
branches:  trunk
changeset: 359781:11a2b5a11fbe
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Jan 22 14:08:19 2022 +0000

description:
Use /dev/tty for SIGINFO
Fix some size_t<->int

diffstat:

 usr.bin/find/extern.h |   4 ++--
 usr.bin/find/find.h   |   4 ++--
 usr.bin/find/misc.c   |  35 +++++++++++++++++++++++++----------
 3 files changed, 29 insertions(+), 14 deletions(-)

diffs (112 lines):

diff -r ef988f984887 -r 11a2b5a11fbe usr.bin/find/extern.h
--- a/usr.bin/find/extern.h     Sat Jan 22 14:00:45 2022 +0000
+++ b/usr.bin/find/extern.h     Sat Jan 22 14:08:19 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.29 2016/06/13 00:04:40 pgoyette Exp $     */
+/*     $NetBSD: extern.h,v 1.30 2022/01/22 14:08:19 christos Exp $     */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-void    brace_subst(char *, char **, char *, int *);
+void    brace_subst(char *, char **, char *, size_t *);
 PLAN   *find_create(char ***);
 int     find_execute(PLAN *, char **);
 PLAN   *find_formplan(char **);
diff -r ef988f984887 -r 11a2b5a11fbe usr.bin/find/find.h
--- a/usr.bin/find/find.h       Sat Jan 22 14:00:45 2022 +0000
+++ b/usr.bin/find/find.h       Sat Jan 22 14:08:19 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: find.h,v 1.27 2021/03/18 18:21:18 cheusov Exp $        */
+/*     $NetBSD: find.h,v 1.28 2022/01/22 14:08:19 christos Exp $       */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -79,7 +79,7 @@
                struct _ex {
                        char **_e_argv;         /* argv array */
                        char **_e_orig;         /* original strings */
-                       int *_e_len;            /* allocated length */
+                       size_t *_e_len;         /* allocated length */
                        char **_ep_bxp;         /* ptr to 1st addt'l arg */
                        char *_ep_p;            /* current buffer pointer */
                        char *_ep_bbp;          /* begin buffer pointer */
diff -r ef988f984887 -r 11a2b5a11fbe usr.bin/find/misc.c
--- a/usr.bin/find/misc.c       Sat Jan 22 14:00:45 2022 +0000
+++ b/usr.bin/find/misc.c       Sat Jan 22 14:08:19 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: misc.c,v 1.14 2006/10/11 19:51:10 apb Exp $    */
+/*     $NetBSD: misc.c,v 1.15 2022/01/22 14:08:19 christos Exp $       */
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "from: @(#)misc.c       8.2 (Berkeley) 4/1/94";
 #else
-__RCSID("$NetBSD: misc.c,v 1.14 2006/10/11 19:51:10 apb Exp $");
+__RCSID("$NetBSD: misc.c,v 1.15 2022/01/22 14:08:19 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -51,6 +51,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <paths.h>
+#include <fcntl.h>
 
 #include "find.h"
 
@@ -60,9 +62,9 @@
  *      area of memory set in store.
  */
 void
-brace_subst(char *orig, char **store, char *path, int *len)
+brace_subst(char *orig, char **store, char *path, size_t *len)
 {
-       int nlen, plen, rest;
+       size_t nlen, plen, rest;
        char ch, *p, *ostore;
 
        plen = strlen(path);
@@ -133,7 +135,9 @@
 show_path(int sig)
 {
        extern FTSENT *g_entry;
-       int errno_bak;
+       static int ttyfd = -2;
+       char buf[2048];
+       int oerrno, n;
 
        if (g_entry == NULL) {
                /*
@@ -143,9 +147,20 @@
                return;
        }
 
-       errno_bak = errno;
-       write(STDERR_FILENO, "find path: ", 11);
-       write(STDERR_FILENO, g_entry->fts_path, g_entry->fts_pathlen);
-       write(STDERR_FILENO, "\n", 1);
-       errno = errno_bak;
+       oerrno = errno;
+       if (ttyfd == -2)
+               ttyfd = open(_PATH_TTY, O_RDWR | O_CLOEXEC);
+
+       if (ttyfd == -1)
+               goto out;
+
+       n = snprintf_ss(buf, sizeof(buf), "%s: path %s\n", getprogname(), 
+           g_entry->fts_path);
+
+       if (n <= 0)
+               goto out;
+
+       write(ttyfd, buf, (size_t)n);
+out:
+       errno = oerrno;
 }



Home | Main Index | Thread Index | Old Index