Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/rcp Add SIGINFO support. Mostly stolen from scan_ffs(8).
details: https://anonhg.NetBSD.org/src/rev/23d5b51b642e
branches: trunk
changeset: 368161:23d5b51b642e
user: rin <rin%NetBSD.org@localhost>
date: Sun Jun 26 09:29:59 2022 +0000
description:
Add SIGINFO support. Mostly stolen from scan_ffs(8).
diffstat:
bin/rcp/rcp.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 45 insertions(+), 2 deletions(-)
diffs (107 lines):
diff -r 3604fa75aba9 -r 23d5b51b642e bin/rcp/rcp.c
--- a/bin/rcp/rcp.c Sun Jun 26 09:23:32 2022 +0000
+++ b/bin/rcp/rcp.c Sun Jun 26 09:29:59 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rcp.c,v 1.50 2020/05/06 18:15:40 aymeric Exp $ */
+/* $NetBSD: rcp.c,v 1.51 2022/06/26 09:29:59 rin Exp $ */
/*
* Copyright (c) 1983, 1990, 1992, 1993
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)rcp.c 8.2 (Berkeley) 4/2/94";
#else
-__RCSID("$NetBSD: rcp.c,v 1.50 2020/05/06 18:15:40 aymeric Exp $");
+__RCSID("$NetBSD: rcp.c,v 1.51 2022/06/26 09:29:59 rin Exp $");
#endif
#endif /* not lint */
@@ -58,6 +58,7 @@
#include <fcntl.h>
#include <locale.h>
#include <netdb.h>
+#include <paths.h>
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
@@ -79,6 +80,8 @@
int family = AF_UNSPEC;
static char dot[] = ".";
+static sig_atomic_t print_info = 0;
+
#define CMDNEEDS 64
char cmd[CMDNEEDS]; /* must hold "rcp -r -p -d\0" */
@@ -89,6 +92,8 @@
void tolocal(int, char *[]);
void toremote(char *, int, char *[]);
void usage(void);
+static void got_siginfo(int);
+static void progress(const char *, uintmax_t, uintmax_t);
int
main(int argc, char *argv[])
@@ -173,6 +178,7 @@
targetshouldbedirectory ? " -d" : "");
(void)signal(SIGPIPE, lostconn);
+ (void)signal(SIGINFO, got_siginfo);
if ((targ = colon(argv[argc - 1])) != NULL)/* Dest is remote host. */
toremote(targ, argc, argv);
@@ -385,6 +391,8 @@
/* Keep writing after an error so that we stay sync'd up. */
haderr = 0;
for (i = 0; i < stb.st_size; i += bp->cnt) {
+ if (print_info)
+ progress(name, i, stb.st_size);
amt = bp->cnt;
if (i + amt > stb.st_size)
amt = stb.st_size - i;
@@ -658,6 +666,8 @@
count = 0;
for (i = 0; i < size; i += BUFSIZ) {
+ if (print_info)
+ progress(np, i, size);
amt = BUFSIZ;
if (i + amt > size)
amt = size - i;
@@ -809,3 +819,36 @@
va_end(ap);
}
}
+
+static void
+got_siginfo(int signo)
+{
+
+ print_info = 1;
+}
+
+static void
+progress(const char *file, uintmax_t done, uintmax_t total)
+{
+ static int ttyfd = -2;
+ const double pcent = (100.0 * done) / total;
+ char buf[2048];
+ int n;
+
+ if (ttyfd == -2)
+ ttyfd = open(_PATH_TTY, O_RDWR | O_CLOEXEC);
+
+ if (ttyfd == -1)
+ return;
+
+ n = snprintf(buf, sizeof(buf),
+ "%s: %s: %ju/%ju bytes %3.2f%% written\n",
+ getprogname(), file, done, total, pcent);
+
+ if (n < 0)
+ return;
+
+ write(ttyfd, buf, (size_t)n);
+
+ print_info = 0;
+}
Home |
Main Index |
Thread Index |
Old Index