Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Oct 2001 00:15:19 -0500 (EST)
From:      Mikhail Teterin <mi@aldan.algebra.com>
To:        arch@FreeBSD.org
Subject:   dump(8) and proctitle, SIGINFO
Message-ID:  <200110290515.f9T5FMa61978@aldan.algebra.com>

next in thread | raw e-mail | index | archive | help
--0-1714636915-1004332525=:4898
Content-Type: TEXT/plain; charset=us-ascii

Well, it took  me a while, but here  it is :) The last  round of reviews
had no  problem with the proctitle  setting itself, but the  handling of
SIGINFO  caused  concerns, since  it  was  doing  some things  a  signal
handlers are not allowed to do.

In this version of the patch, the statistics are not printed immediately
in  the  signal  handling.  The   signal  simply  reschedules  the  next
statistics-printing after  writing the current block.  I assume, calling
time(3) is fine for a signal handler.

I also  removed the arbitrary limit,  that the amount of  blocks written
since the last  statistics report (5 minutes earlier) needs  to be above
500 for  the new line  of stats  to be output.  Dump will now  print the
stats every 5 minutes or after every SIGINFO. Period.

Please, review. Thanks!

	-mi

P.S. Should  this version  cause no  objections, could  someone, please,
advise me at my  possible next step -- I'm only a  ports commiter, so, I
guess, someone else will have to commit this, right?


--0-1714636915-1004332525=:4898
Content-Type: TEXT/plain; name=patch-dump-stats-title
Content-Description: patch dump(8) to use proctitle and handle SIGINFO
Content-Disposition: attachment; filename=patch-dump-stats-title

Index: dump.8
===================================================================
RCS file: /home/ncvs/src/sbin/dump/dump.8,v
retrieving revision 1.39
diff -U2 -r1.39 dump.8
--- dump.8	2001/07/15 14:00:19	1.39
+++ dump.8	2001/10/29 05:06:26
@@ -320,5 +320,6 @@
 .Pp
 .Nm Dump
-tells the operator what is going on at periodic intervals,
+tells the operator what is going on at periodic intervals --
+every 5 minutes, or after writing the next block after receiving SIGINFO --
 including usually low estimates of the number of blocks to write,
 the number of tapes it will take, the time to completion, and
Index: dump.h
===================================================================
RCS file: /home/ncvs/src/sbin/dump/dump.h,v
retrieving revision 1.10
diff -U2 -r1.10 dump.h
--- dump.h	2001/09/05 15:37:01	1.10
+++ dump.h	2001/10/29 05:06:27
@@ -101,6 +101,7 @@
 int	query __P((char *question));
 void	quit __P((const char *fmt, ...)) __printflike(1, 2);
-void	timeest __P((void));
+void	timeest __P((int)); /* accepts the signal number */
 time_t	unctime __P((char *str));
+void	title __P((void));
 
 /* mapping rouintes */
Index: main.c
===================================================================
RCS file: /home/ncvs/src/sbin/dump/main.c,v
retrieving revision 1.28
diff -U2 -r1.28 main.c
--- main.c	2001/10/28 20:01:38	1.28
+++ main.c	2001/10/29 05:06:27
@@ -341,4 +341,5 @@
 		exit(X_STARTUP);
 	}
+	title();
 	sync();
 	sblock = (struct fs *)sblock_buf;
@@ -367,7 +368,9 @@
 
 	msg("mapping (Pass I) [regular files]\n");
+	title();
 	anydirskipped = mapfiles(maxino, &tapesize);
 
 	msg("mapping (Pass II) [directories]\n");
+	title();
 	while (anydirskipped) {
 		anydirskipped = mapdirs(maxino, &tapesize);
@@ -419,4 +422,5 @@
 		    tapesize, fetapes);
 	}
+	title();
 
 	/*
@@ -432,4 +436,5 @@
 
 	msg("dumping (Pass III) [directories]\n");
+	title();
 	dirty = 0;		/* XXX just to get gcc to shut up */
 	for (map = dumpdirmap, ino = 1; ino < maxino; ino++) {
@@ -450,4 +455,5 @@
 
 	msg("dumping (Pass IV) [regular files]\n");
+	title();
 	for (map = dumpinomap, ino = 1; ino < maxino; ino++) {
 		int mode;
@@ -487,4 +493,5 @@
 		    tend_writing - tstart_writing,
 		    spcl.c_tapea / (tend_writing - tstart_writing));
+	title();
 
 	putdumptime();
@@ -545,4 +552,5 @@
 			quit("Signal on pipe: cannot recover\n");
 		msg("Rewriting attempted as response to unknown signal.\n");
+		title();
 		(void)fflush(stderr);
 		(void)fflush(stdout);
Index: optr.c
===================================================================
RCS file: /home/ncvs/src/sbin/dump/optr.c,v
retrieving revision 1.15
diff -U2 -r1.15 optr.c
--- optr.c	2001/10/28 06:13:47	1.15
+++ optr.c	2001/10/29 05:06:27
@@ -191,14 +191,23 @@
 
 void
-timeest()
+timeest(signal)
 {
 	time_t	tnow;
 	int deltat;
 
-	(void) time((time_t *) &tnow);
+	(void) time(&tnow);
+	if (signal != 0) {
+		/*
+		 * We might be called to handle SIGINFO. Re-schedule
+		 * the reporting to occur the next time we are called
+		 * regularly and bail out -- don't do reporting as a
+		 * signal handler -- it involves malloc-ing and other
+		 * things signal handler are not supposed to do.
+		 */
+		tschedule = tnow;
+		return;
+	}
 	if (tnow >= tschedule) {
 		tschedule = tnow + 300;
-		if (blockswritten < 500)
-			return;
 		deltat = tstart_writing - tnow +
 			(1.0 * (tnow - tstart_writing))
@@ -207,4 +216,5 @@
 			(blockswritten * 100.0) / tapesize,
 			deltat / 3600, (deltat % 3600) / 60);
+		title();
 	}
 }
@@ -235,4 +245,31 @@
 	(void) vsnprintf(lastmsg, sizeof(lastmsg), fmt, ap);
 	va_end(ap);
+}
+
+/*
+ * This function can be called to place, what msg() above pushed to
+ * stderr, into the process title, viewable with the ps-command.
+ * A side effect of this function, is it replaces the final '\n' (if any)
+ * with the '\0' in the global variable lastmsg -- to avoid the literal
+ * "\n" being put into the proctitle.
+ * So, if the lastmsg needs to be output elsewhere, that should happen
+ * before calling title().
+ */
+void title()
+{
+	int lastlen;
+
+	lastlen = strlen(lastmsg);
+	if (lastmsg[lastlen-1] == '\n')
+		lastmsg[lastlen-1] = '\0';
+
+	/*
+	 * It would be unwise to run multiple dumps of same disk
+	 * at  the  same time.  So  ``disk''  is sufficient  for
+	 * identifying, to  which family of dump  processes this
+	 * one belongs  -- the other processes  continue to have
+	 * the original titles.
+	 */
+	setproctitle("%s: %s", disk, lastmsg);
 }
 
Index: tape.c
===================================================================
RCS file: /home/ncvs/src/sbin/dump/tape.c,v
retrieving revision 1.13
diff -U2 -r1.13 tape.c
--- tape.c	2001/01/28 21:21:37	1.13
+++ tape.c	2001/10/29 05:06:28
@@ -315,5 +315,5 @@
 		startnewtape(0);
 	}
-	timeest();
+	timeest(0);
 }
 
@@ -532,4 +532,5 @@
 	 *	All signals are inherited...
 	 */
+	setproctitle(NULL); /* restore the proctitle modified by title() */
 	childpid = fork();
 	if (childpid < 0) {
@@ -622,4 +625,5 @@
 
 		enslave();  /* Share open tape file descriptor with slaves */
+		signal(SIGINFO, timeest); /* report progress on SIGINFO */
 
 		asize = 0;

--0-1714636915-1004332525=:4898--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200110290515.f9T5FMa61978>