From: Gui Hecheng <
guihe...@cmss.chinamobile.com>
If we try to start a new sheep while having a running sheep,
the new sheep will get a semaphore to protect logarea, later it find
that the 7000 port is taken, so it will free the semaphore.
But the new sheep actually frees the semaphore owned by the running
sheep together, then following log operation all get a EINVAL return.
Because semget() function use a semkey, generated by random() function,
to get a semaphore, and the random() function is known to return
the same random number upon each call, so the new sheep get the same
semaphore as the running sheep.
To fix it, we just use IPC_PRIVATE as semkey, then each sheep
will get a different semaphore on startup.
Signed-off-by: Gui Hecheng <
guihe...@cmss.chinamobile.com>
---
lib/logger.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/lib/logger.c b/lib/logger.c
index 7d7441a..f54d674 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -115,7 +115,6 @@ static char *log_nowname;
int sd_log_level = SDOG_INFO;
static pid_t sheep_pid;
pid_t logger_pid = -1;
-static key_t semkey;
static char *log_buff;
static int64_t max_logsize = 500 * 1024 * 1024; /*500MB*/
@@ -328,7 +327,7 @@ static int logarea_init(int size)
la->end = la->start + size;
la->tail = la->start;
- la->semid = semget(semkey, 1, 0666 | IPC_CREAT);
+ la->semid = semget(IPC_PRIVATE, 1, 0666 | IPC_CREAT);
if (la->semid < 0) {
syslog(LOG_ERR, "semget failed: %m");
shmdt(la->start);
@@ -667,8 +666,6 @@ int log_init(const char *program_name, enum log_dst_type type, int level,
pstrcpy(tmp, sizeof(tmp), outfile);
pstrcpy(log_dir, sizeof(log_dir), dirname(tmp));
- semkey = random();
-
switch (type) {
case LOG_DST_STDOUT:
if (is_stdout_console())
--
1.8.3.1