2 * Copyright (C) 2002-2003 Ardis Technolgies <roman@ardistech.com>
3 * Copyright (C) 2007 Vladislav Bolkhovitin
4 * Copyright (C) 2007 CMS Distribution Limited
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation, version 2
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
32 openlog("iscsi-scstd", 0, LOG_DAEMON);
35 static void dolog(int prio, const char *fmt, va_list ap)
38 int len = strlen(fmt);
41 sprintf(f, "%s\n", fmt);
43 sprintf(f, "%s", fmt);
48 gettimeofday(&time, NULL);
49 fprintf(stderr, "%ld.%06ld: ", time.tv_sec, time.tv_usec);
50 vfprintf(stderr, fmt, ap);
51 fprintf(stderr, "\n");
56 void log_info(const char *fmt, ...)
60 dolog(LOG_INFO, fmt, ap);
64 void log_warning(const char *fmt, ...)
68 dolog(LOG_WARNING, fmt, ap);
72 void log_error(const char *fmt, ...)
76 dolog(LOG_ERR, fmt, ap);
80 void log_debug(int level, const char *fmt, ...)
82 if (log_level > level) {
85 dolog(LOG_DEBUG, fmt, ap);
90 static void __dump_line(int level, unsigned char *buf, int *cp)
92 char line[16*3+5], *lp = line;
98 for (i = 0; i < 16; i++) {
100 lp += sprintf(lp, " %02x", buf[i]);
102 lp += sprintf(lp, " ");
104 lp += sprintf(lp, " |");
105 if (i >= cnt || !isprint(buf[i]))
108 log_debug(level, "%s %.16s |", line, buf);
112 static void __dump_char(int level, unsigned char *buf, int *cp, int ch)
118 __dump_line(level, buf, cp);
121 #define dump_line() __dump_line(level, char_buf, &char_cnt)
122 #define dump_char(ch) __dump_char(level, char_buf, &char_cnt, ch)
124 void log_pdu(int level, struct PDU *pdu)
126 unsigned char char_buf[16];
132 if (log_level <= level)
135 buf = (void *)&pdu->bhs;
136 log_debug(level, "BHS: (%p)", buf);
137 for (i = 0; i < BHS_SIZE; i++)
141 buf = (void *)pdu->ahs;
142 log_debug(level, "AHS: (%p)", buf);
143 for (i = 0; i < pdu->ahssize; i++)
147 buf = (void *)pdu->data;
148 log_debug(level, "Data: (%p)", buf);
149 for (i = 0; i < pdu->datasize; i++)