Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/nathanw_sa]: src/lib/libpthread Instead of always doing the equivalent o...
details: https://anonhg.NetBSD.org/src/rev/6fe9c9a96354
branches: nathanw_sa
changeset: 504898:6fe9c9a96354
user: nathanw <nathanw%NetBSD.org@localhost>
date: Tue Jul 24 21:26:58 2001 +0000
description:
Instead of always doing the equivalent of tail -f on the log, add a -f
option to do that and make the default simply to display the log.
Add a -i option to initialize (clear) the log.
Oh, and add getopt framework and usage().
diffstat:
lib/libpthread/debuglog.c | 60 +++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 53 insertions(+), 7 deletions(-)
diffs (107 lines):
diff -r 7972707a7162 -r 6fe9c9a96354 lib/libpthread/debuglog.c
--- a/lib/libpthread/debuglog.c Tue Jul 24 21:25:18 2001 +0000
+++ b/lib/libpthread/debuglog.c Tue Jul 24 21:26:58 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debuglog.c,v 1.1.2.1 2001/07/17 20:22:41 nathanw Exp $ */
+/* $NetBSD: debuglog.c,v 1.1.2.2 2001/07/24 21:26:58 nathanw Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -40,13 +40,15 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
#include <sys/shm.h>
#include "pthread.h"
#include "pthread_int.h"
-void pthread__debuglog_read(void);
+void pthread__debuglog_read(int);
+void usage(void);
static struct pthread_msgbuf* debugbuf;
@@ -54,21 +56,57 @@
int
main(int argc, char *argv[])
{
+ int ch;
+ extern int optind;
+ extern char *optarg;
+
+ int follow, initialize;
+
+ follow = 0;
+ initialize = 0;
+
+ while ((ch = getopt(argc, argv, "fi")) != -1)
+ switch (ch) {
+ case 'f':
+ follow = 1;
+ break;
+ case 'i':
+ initialize = 1;
+ break;
+
+ default:
+ usage();
+ /* NOTREACHED */
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 0)
+ usage();
debugbuf = pthread__debuglog_init();
- pthread__debuglog_read();
+ if (initialize) {
+ /* Initialize */
+ debugbuf->msg_magic = BUF_MAGIC;
+ debugbuf->msg_bufw = 0;
+ debugbuf->msg_bufr = 0;
+ debugbuf->msg_bufs = PTHREAD__DEBUG_SHMSIZE;
+ }
+ pthread__debuglog_read(follow);
+
return 0;
}
void
-pthread__debuglog_read(void)
+pthread__debuglog_read(int follow)
{
int readp, writep;
- while (1) {
+ do {
readp = debugbuf->msg_bufr;
writep = debugbuf->msg_bufw;
@@ -84,9 +122,17 @@
debugbuf->msg_bufr = writep;
- sleep(1);
- }
+ if (follow)
+ sleep(1);
+ } while (follow);
}
+
+void usage()
+{
+
+ fprintf(stderr,"usage: debuglog [-fi]\n");
+ exit(1);
+}
Home |
Main Index |
Thread Index |
Old Index