Source-Changes-HG archive

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

[src/trunk]: src/sbin/iscsid Make the debugging printouts actually work when ...



details:   https://anonhg.NetBSD.org/src/rev/dd297e0bdd05
branches:  trunk
changeset: 779435:dd297e0bdd05
user:      riz <riz%NetBSD.org@localhost>
date:      Mon May 28 00:13:19 2012 +0000

description:
Make the debugging printouts actually work when setting the debug level,
and allow the level to be set numerically from the command line.

diffstat:

 sbin/iscsid/Makefile         |   4 +---
 sbin/iscsid/iscsid_globals.h |  12 ++----------
 sbin/iscsid/iscsid_main.c    |  38 +++++++++++++++++++++-----------------
 3 files changed, 24 insertions(+), 30 deletions(-)

diffs (143 lines):

diff -r 38ba1d74568b -r dd297e0bdd05 sbin/iscsid/Makefile
--- a/sbin/iscsid/Makefile      Sun May 27 23:54:45 2012 +0000
+++ b/sbin/iscsid/Makefile      Mon May 28 00:13:19 2012 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.3 2012/05/27 20:05:04 christos Exp $
+#      $NetBSD: Makefile,v 1.4 2012/05/28 00:13:19 riz Exp $
 
 PROG=  iscsid
 
@@ -13,8 +13,6 @@
 
 WARNS= 4
 
-# CPPFLAGS+= -DISCSI_DEBUG
-
 LDADD = -lpthread -lisns
 
 INCSDIR= /usr/include
diff -r 38ba1d74568b -r dd297e0bdd05 sbin/iscsid/iscsid_globals.h
--- a/sbin/iscsid/iscsid_globals.h      Sun May 27 23:54:45 2012 +0000
+++ b/sbin/iscsid/iscsid_globals.h      Mon May 28 00:13:19 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsid_globals.h,v 1.6 2012/05/27 22:03:16 riz Exp $   */
+/*     $NetBSD: iscsid_globals.h,v 1.7 2012/05/28 00:13:19 riz Exp $   */
 
 /*-
  * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -379,20 +379,12 @@
 
 /* Debugging stuff */
 
-#ifdef ISCSI_DEBUG
 
-int debug_level;                               /* How much info to display */
+extern int debug_level;                                /* How much info to display */
 
 #define DEBOUT(x) printf x
 #define DEB(lev,x) {if (debug_level >= lev) printf x ;}
 
-#else
-
-#define DEBOUT(x)
-#define DEB(lev,x)
-
-#endif
-
 /* Session list protection shortcuts */
 
 #if 0
diff -r 38ba1d74568b -r dd297e0bdd05 sbin/iscsid/iscsid_main.c
--- a/sbin/iscsid/iscsid_main.c Sun May 27 23:54:45 2012 +0000
+++ b/sbin/iscsid/iscsid_main.c Mon May 28 00:13:19 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: iscsid_main.c,v 1.6 2012/05/27 22:03:16 riz Exp $      */
+/*     $NetBSD: iscsid_main.c,v 1.7 2012/05/28 00:13:19 riz Exp $      */
 
 /*-
  * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc.
@@ -37,6 +37,7 @@
 #include <sys/sysctl.h>
 
 #include <ctype.h>
+#include <err.h>
 #include <fcntl.h>
 
 #define DEVICE    "/dev/iscsi0"
@@ -71,7 +72,7 @@
 static void __dead
 usage(void) 
 {
-       fprintf(stderr, "Usage: %s [-d]\n", getprogname());
+       fprintf(stderr, "Usage: %s [-d <lvl>] [-n]\n", getprogname());
        exit(EXIT_FAILURE);
 }
 
@@ -484,7 +485,6 @@
        dereg_all_isns_servers();
 #endif
 
-       close(client_sock);
        printf("iSCSI Daemon Exits\n");
        exit(0);
 }
@@ -512,6 +512,22 @@
        iscsid_request_t *req;
        iscsid_response_t *rsp;
        struct timeval seltout = { 2, 0 };      /* 2 second poll interval */
+       char *p;
+
+       while ((c = getopt(argc, argv, "d:n")) != -1)
+               switch (c) {
+               case 'n':
+                       nothreads++;
+                       break;
+               case 'd':
+                       debug_level=(int)strtol(optarg, &p, 10);
+                       if (*p)
+                               errx(EXIT_FAILURE, "illegal debug level -- %s",
+                                   optarg);
+                       break;
+               default:
+                       usage();
+               }
 
        client_sock = init_daemon();
        if (client_sock < 0)
@@ -519,18 +535,6 @@
 
        printf("iSCSI Daemon loaded\n");
 
-       while ((c = getopt(argc, argv, "dn")) != -1)
-               switch (c) {
-               case 'n':
-                       nothreads++;
-                       break;
-               case 'd':
-                       debug_level++;
-                       break;
-               default:
-                       usage();
-               }
-
        if (!debug_level)
                daemon(0, 1);
 
@@ -579,7 +583,7 @@
                        perror("Receiving from socket");
                        break;
                }
-               DEB(99, ("Request %d, parlen %d\n",
+               DEB(98, ("Request %d, parlen %d\n",
                                req->request, req->parameter_length));
 
                len += req->parameter_length;
@@ -625,7 +629,7 @@
                if (rsp == NULL)
                        break;
 
-               DEB(99, ("Sending reply: status %d, len %d\n",
+               DEB(98, ("Sending reply: status %d, len %d\n",
                                rsp->status, rsp->parameter_length));
 
                /* send the response */



Home | Main Index | Thread Index | Old Index