summaryrefslogtreecommitdiffstats
path: root/usr.sbin/iscsid
diff options
context:
space:
mode:
authorbenno <benno@openbsd.org>2016-09-02 16:22:31 +0000
committerbenno <benno@openbsd.org>2016-09-02 16:22:31 +0000
commite86986b3b6611db1d88c59a137bd284148cada85 (patch)
tree2bbeef09a82432e7140888303e0dc741e1c09fbe /usr.sbin/iscsid
parentwork on making log.c similar in all daemons: (diff)
downloadwireguard-openbsd-e86986b3b6611db1d88c59a137bd284148cada85.tar.xz
wireguard-openbsd-e86986b3b6611db1d88c59a137bd284148cada85.zip
work on making log.c similar in all daemons:
move daemon-local functions into new logmsg.c, and reduce the (mostly whitespace) differences so that log.c's can be diffed easily. ok claudio@
Diffstat (limited to 'usr.sbin/iscsid')
-rw-r--r--usr.sbin/iscsid/Makefile6
-rw-r--r--usr.sbin/iscsid/iscsid.h6
-rw-r--r--usr.sbin/iscsid/log.c84
-rw-r--r--usr.sbin/iscsid/log.h32
-rw-r--r--usr.sbin/iscsid/logmsg.c99
5 files changed, 127 insertions, 100 deletions
diff --git a/usr.sbin/iscsid/Makefile b/usr.sbin/iscsid/Makefile
index ed5ec76e26a..a604574e808 100644
--- a/usr.sbin/iscsid/Makefile
+++ b/usr.sbin/iscsid/Makefile
@@ -1,8 +1,8 @@
-# $OpenBSD: Makefile,v 1.3 2011/04/05 18:26:19 claudio Exp $
+# $OpenBSD: Makefile,v 1.4 2016/09/02 16:22:31 benno Exp $
PROG= iscsid
-SRCS= connection.c control.c initiator.c iscsid.c log.c pdu.c session.c \
- task.c util.c vscsi.c
+SRCS= connection.c control.c initiator.c iscsid.c log.c logmsg.c pdu.c \
+ session.c task.c util.c vscsi.c
MAN= iscsid.8
diff --git a/usr.sbin/iscsid/iscsid.h b/usr.sbin/iscsid/iscsid.h
index cf9497123df..b43fb5dcd99 100644
--- a/usr.sbin/iscsid/iscsid.h
+++ b/usr.sbin/iscsid/iscsid.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: iscsid.h,v 1.15 2016/08/16 18:41:57 tedu Exp $ */
+/* $OpenBSD: iscsid.h,v 1.16 2016/09/02 16:22:31 benno Exp $ */
/*
* Copyright (c) 2009 Claudio Jeker <claudio@openbsd.org>
@@ -390,3 +390,7 @@ void vscsi_data(unsigned long, int, void *, size_t);
void vscsi_status(int, int, void *, size_t);
void vscsi_event(unsigned long, u_int, u_int);
struct vscsi_stats *vscsi_stats(void);
+
+/* logmsg.c */
+void log_hexdump(void *, size_t);
+void log_pdu(struct pdu *, int);
diff --git a/usr.sbin/iscsid/log.c b/usr.sbin/iscsid/log.c
index 3ae75977e14..e1a6c753d05 100644
--- a/usr.sbin/iscsid/log.c
+++ b/usr.sbin/iscsid/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.6 2014/04/19 18:31:33 claudio Exp $ */
+/* $OpenBSD: log.c,v 1.7 2016/09/02 16:22:31 benno Exp $ */
/*
* Copyright (c) 2009 Claudio Jeker <claudio@openbsd.org>
@@ -16,30 +16,19 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-
-#include <scsi/iscsi.h>
#include <errno.h>
-#include <event.h>
-#include <netdb.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
-#include <unistd.h>
+#include <time.h>
-#include "iscsid.h"
#include "log.h"
-int debug;
-int verbose;
-
-void logit(int, const char *, ...);
+int debug;
+int verbose;
void
log_init(int n_debug)
@@ -165,68 +154,3 @@ fatalx(const char *emsg)
errno = 0;
fatal(emsg);
}
-
-void
-log_hexdump(void *buf, size_t len)
-{
- u_char b[16];
- size_t i, j, l;
-
- if (!debug)
- return;
-
- for (i = 0; i < len; i += l) {
- fprintf(stderr, "%4zi:", i);
- l = sizeof(b) < len - i ? sizeof(b) : len - i;
- memcpy(b, (char *)buf + i, l);
-
- for (j = 0; j < sizeof(b); j++) {
- if (j % 2 == 0)
- fprintf(stderr, " ");
- if (j % 8 == 0)
- fprintf(stderr, " ");
- if (j < l)
- fprintf(stderr, "%02x", (int)b[j]);
- else
- fprintf(stderr, " ");
- }
- fprintf(stderr, " |");
- for (j = 0; j < l; j++) {
- if (b[j] >= 0x20 && b[j] <= 0x7e)
- fprintf(stderr, "%c", b[j]);
- else
- fprintf(stderr, ".");
- }
- fprintf(stderr, "|\n");
- }
-}
-
-void
-log_pdu(struct pdu *p, int all)
-{
- struct iscsi_pdu *pdu;
- void *b;
- size_t s;
-
- if (!debug)
- return;
-
- if (!(pdu = pdu_getbuf(p, NULL, PDU_HEADER))) {
- log_debug("empty pdu");
- return;
- }
-
- fprintf(stderr, "PDU: op %x%s flags %02x%02x%02x ahs %d len %d\n",
- ISCSI_PDU_OPCODE(pdu->opcode), ISCSI_PDU_I(pdu) ? " I" : "",
- pdu->flags, pdu->_reserved1[0], pdu->_reserved1[1],
- pdu->ahslen, pdu->datalen[0] << 16 | pdu->datalen[1] << 8 |
- pdu->datalen[2]);
- fprintf(stderr, " lun %02x%02x%02x%02x%02x%02x%02x%02x itt %u "
- "cmdsn %u expstatsn %u\n", pdu->lun[0], pdu->lun[1], pdu->lun[2],
- pdu->lun[3], pdu->lun[4], pdu->lun[5], pdu->lun[6], pdu->lun[7],
- ntohl(pdu->itt), ntohl(pdu->cmdsn), ntohl(pdu->expstatsn));
- log_hexdump(pdu, sizeof(*pdu));
-
- if (all && (b = pdu_getbuf(p, &s, PDU_DATA)))
- log_hexdump(b, s);
-}
diff --git a/usr.sbin/iscsid/log.h b/usr.sbin/iscsid/log.h
index ef3bd1634e7..745933b2f4a 100644
--- a/usr.sbin/iscsid/log.h
+++ b/usr.sbin/iscsid/log.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.h,v 1.3 2016/07/18 21:18:48 benno Exp $ */
+/* $OpenBSD: log.h,v 1.4 2016/09/02 16:22:31 benno Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -16,29 +16,29 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#ifndef _LOG_H_
-#define _LOG_H_
+#ifndef LOG_H
+#define LOG_H
#include <stdarg.h>
+#include <sys/cdefs.h>
-void log_init(int);
-void log_verbose(int);
-void vlog(int, const char *, va_list)
+void log_init(int);
+void log_verbose(int);
+void logit(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+void vlog(int, const char *, va_list)
__attribute__((__format__ (printf, 2, 0)));
-void log_warn(const char *, ...)
+void log_warn(const char *, ...)
__attribute__((__format__ (printf, 1, 2)));
-void log_warnx(const char *, ...)
+void log_warnx(const char *, ...)
__attribute__((__format__ (printf, 1, 2)));
-void log_info(const char *, ...)
+void log_info(const char *, ...)
__attribute__((__format__ (printf, 1, 2)));
-void log_debug(const char *, ...)
+void log_debug(const char *, ...)
__attribute__((__format__ (printf, 1, 2)));
-void fatal(const char *) __dead
+void fatal(const char *) __dead
__attribute__((__format__ (printf, 1, 0)));
-void fatalx(const char *) __dead
+void fatalx(const char *) __dead
__attribute__((__format__ (printf, 1, 0)));
-void log_hexdump(void *, size_t);
-void log_pdu(struct pdu *, int);
-
-#endif /* _LOG_H_ */
+#endif /* LOG_H */
diff --git a/usr.sbin/iscsid/logmsg.c b/usr.sbin/iscsid/logmsg.c
new file mode 100644
index 00000000000..9e4dac68300
--- /dev/null
+++ b/usr.sbin/iscsid/logmsg.c
@@ -0,0 +1,99 @@
+/* $OpenBSD: logmsg.c,v 1.1 2016/09/02 16:22:31 benno Exp $ */
+
+/*
+ * Copyright (c) 2009 Claudio Jeker <claudio@openbsd.org>
+ * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <arpa/inet.h>
+#include <endian.h>
+#include <event.h>
+#include <scsi/iscsi.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/queue.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+
+#include "iscsid.h"
+#include "log.h"
+
+extern int debug;
+extern int verbose;
+
+void
+log_hexdump(void *buf, size_t len)
+{
+ u_char b[16];
+ size_t i, j, l;
+
+ if (!debug)
+ return;
+
+ for (i = 0; i < len; i += l) {
+ fprintf(stderr, "%4zi:", i);
+ l = sizeof(b) < len - i ? sizeof(b) : len - i;
+ memcpy(b, (char *)buf + i, l);
+
+ for (j = 0; j < sizeof(b); j++) {
+ if (j % 2 == 0)
+ fprintf(stderr, " ");
+ if (j % 8 == 0)
+ fprintf(stderr, " ");
+ if (j < l)
+ fprintf(stderr, "%02x", (int)b[j]);
+ else
+ fprintf(stderr, " ");
+ }
+ fprintf(stderr, " |");
+ for (j = 0; j < l; j++) {
+ if (b[j] >= 0x20 && b[j] <= 0x7e)
+ fprintf(stderr, "%c", b[j]);
+ else
+ fprintf(stderr, ".");
+ }
+ fprintf(stderr, "|\n");
+ }
+}
+
+void
+log_pdu(struct pdu *p, int all)
+{
+ struct iscsi_pdu *pdu;
+ void *b;
+ size_t s;
+
+ if (!debug)
+ return;
+
+ if (!(pdu = pdu_getbuf(p, NULL, PDU_HEADER))) {
+ log_debug("empty pdu");
+ return;
+ }
+
+ fprintf(stderr, "PDU: op %x%s flags %02x%02x%02x ahs %d len %d\n",
+ ISCSI_PDU_OPCODE(pdu->opcode), ISCSI_PDU_I(pdu) ? " I" : "",
+ pdu->flags, pdu->_reserved1[0], pdu->_reserved1[1],
+ pdu->ahslen, pdu->datalen[0] << 16 | pdu->datalen[1] << 8 |
+ pdu->datalen[2]);
+ fprintf(stderr, " lun %02x%02x%02x%02x%02x%02x%02x%02x itt %u "
+ "cmdsn %u expstatsn %u\n", pdu->lun[0], pdu->lun[1], pdu->lun[2],
+ pdu->lun[3], pdu->lun[4], pdu->lun[5], pdu->lun[6], pdu->lun[7],
+ ntohl(pdu->itt), ntohl(pdu->cmdsn), ntohl(pdu->expstatsn));
+ log_hexdump(pdu, sizeof(*pdu));
+
+ if (all && (b = pdu_getbuf(p, &s, PDU_DATA)))
+ log_hexdump(b, s);
+}