forked from pool/open-iscsi
91 lines
2.0 KiB
Plaintext
91 lines
2.0 KiB
Plaintext
commit fa1429ee35e2dc2ea4895ec38216482afc3d95b5
|
|
Author: Hannes Reinecke <hare@suse.de>
|
|
Date: Wed Apr 2 11:31:18 2008 +0200
|
|
|
|
log_syslog might crash upon failure
|
|
|
|
log_dequeue returns 1 on two conditions; either the log queue is empty entirely
|
|
or this is the last message on the queue. When the first condition is true the
|
|
logger will crash as it tries to access an invalid message.
|
|
|
|
Signed-off-by: Hannes Reinecke <hare@suse.de>
|
|
|
|
diff --git a/usr/iscsid.c b/usr/iscsid.c
|
|
index 2959821..2fbc387 100644
|
|
--- a/usr/iscsid.c
|
|
+++ b/usr/iscsid.c
|
|
@@ -388,7 +388,7 @@ int main(int argc, char *argv[])
|
|
|
|
if ((mgmt_ipc_fd = mgmt_ipc_listen()) < 0) {
|
|
log_close(log_pid);
|
|
- exit(-1);
|
|
+ exit(1);
|
|
}
|
|
|
|
if (log_daemon) {
|
|
@@ -413,7 +413,7 @@ int main(int argc, char *argv[])
|
|
|
|
if ((control_fd = ipc->ctldev_open()) < 0) {
|
|
log_close(log_pid);
|
|
- exit(-1);
|
|
+ exit(1);
|
|
}
|
|
|
|
chdir("/");
|
|
@@ -430,7 +430,7 @@ int main(int argc, char *argv[])
|
|
} else {
|
|
if ((control_fd = ipc->ctldev_open()) < 0) {
|
|
log_close(log_pid);
|
|
- exit(-1);
|
|
+ exit(1);
|
|
}
|
|
}
|
|
|
|
diff --git a/usr/log.c b/usr/log.c
|
|
index 9b82c46..a738454 100644
|
|
--- a/usr/log.c
|
|
+++ b/usr/log.c
|
|
@@ -196,7 +196,7 @@ int log_dequeue (void * buff)
|
|
int len;
|
|
|
|
if (la->empty)
|
|
- return 1;
|
|
+ return 0;
|
|
|
|
len = strlen((char *)&src->str) * sizeof(char) +
|
|
sizeof(struct logmsg) + 1;
|
|
@@ -215,7 +215,7 @@ int log_dequeue (void * buff)
|
|
|
|
memset((void *)src, 0, len);
|
|
|
|
- return la->empty;
|
|
+ return len;
|
|
}
|
|
|
|
/*
|
|
@@ -314,19 +314,22 @@ static void __dump_char(int level, unsigned char *buf, int *cp, int ch)
|
|
|
|
static void log_flush(void)
|
|
{
|
|
+ int msglen;
|
|
+
|
|
while (!la->empty) {
|
|
la->ops[0].sem_op = -1;
|
|
if (semop(la->semid, la->ops, 1) < 0) {
|
|
syslog(LOG_ERR, "semop up failed %d", errno);
|
|
exit(1);
|
|
}
|
|
- log_dequeue(la->buff);
|
|
+ msglen = log_dequeue(la->buff);
|
|
la->ops[0].sem_op = 1;
|
|
if (semop(la->semid, la->ops, 1) < 0) {
|
|
syslog(LOG_ERR, "semop down failed");
|
|
exit(1);
|
|
}
|
|
- log_syslog(la->buff);
|
|
+ if (msglen)
|
|
+ log_syslog(la->buff);
|
|
}
|
|
}
|
|
|