--- ./sysklogd/syslogd.c~ 2009-10-20 09:25:05 +0200 +++ ./sysklogd/syslogd.c 2009-10-20 11:43:04 +0200 @@ -144,8 +144,8 @@ char data[1]; // data/messages } *buf = NULL; // shared memory pointer -static struct sembuf SMwup[1] = { {1, -1, IPC_NOWAIT} }; // set SMwup -static struct sembuf SMwdn[3] = { {0, 0}, {1, 0}, {1, +1} }; // set SMwdn +static struct sembuf SMwup[1] = { {1, -1, IPC_NOWAIT|SEM_UNDO} }; // set SMwup +static struct sembuf SMwdn[3] = { {0, 0}, {1, 0}, {1, +1, SEM_UNDO} }; // set SMwdn static int shmid = -1; // ipc shared memory id static int s_semid = -1; // ipc semaphore id @@ -172,6 +172,16 @@ } } +/* + * sem_owned - return 1 if we own the write semaphore, otherwise zero + */ +static inline int sem_owned(int semid) +{ + if (semctl(semid, 1, GETVAL) != 0) + return 1; + return 0; +} + static void ipcsyslog_cleanup(void) { @@ -507,6 +517,13 @@ static void quit_signal(int sig) { +#ifdef CONFIG_FEATURE_IPC_SYSLOG + /* if we receive SIGTERM during a write to the SHM, we already hold the + * semaphore, and we'll block, so we need to release it now. + */ + if (sem_owned(s_semid)) + sem_up(s_semid); +#endif logMessage(LOG_SYSLOG | LOG_INFO, "System log daemon exiting."); unlink(lfile); if (pidFilePath)