From ce11c3649bf8801bc2ec8614ca0f78171120053f Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 31 Dec 2015 13:07:17 +0100 Subject: syslogd: prepare error handling on sem_down() We prepare ourselves to handle a semaphore timeout on sem_down(), so for this we first want to be able to return an error code. --- sysklogd/logread.c | 6 ++++-- sysklogd/syslogd.c | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/sysklogd/logread.c b/sysklogd/logread.c index c0137ea..4a867a3 100644 --- a/sysklogd/logread.c +++ b/sysklogd/logread.c @@ -69,10 +69,11 @@ static inline void sem_up(int semid) /* * sem_down - down()'s a semaphore */ -static inline void sem_down(int semid) +static inline int sem_down(int semid) { if ( semop(semid, SMrdn, 2) == -1 ) error_exit("semop[SMrdn]"); + return 0; } extern int logread_main(int argc, char **argv) @@ -119,7 +120,8 @@ extern int logread_main(int argc, char **argv) int log_len,j; #endif - sem_down(log_semid); + if (sem_down(log_semid) < 0) + goto output_end; //printf("head: %i tail: %i size: %i\n",buf->head,buf->tail,buf->size); if (buf->head == buf->tail || i==buf->tail) { diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index d06794c..5b13e5d 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c @@ -166,15 +166,16 @@ static inline void sem_up(int semid) } /* - * sem_down - down()'s a semaphore + * sem_down - down()'s a semaphore. Returns >=0 on success, <0 on failure. */ -static inline void sem_down(int semid) +static inline int sem_down(int semid) { do { if (semop(semid, SMwdn, 3) != -1) - return; + return 0; } while (errno == EAGAIN || errno == EINTR); bb_perror_msg_and_die("semop[SMwdn]"); + return -1; } /* @@ -237,7 +238,8 @@ static void circ_message(const char *msg) { int l = strlen(msg) + 1; /* count the whole message w/ '\0' included */ - sem_down(s_semid); + if (sem_down(s_semid) < 0) + return; /* * Circular Buffer Algorithm: -- 1.7.12.1