diff --git a/inc/common/queue.h b/inc/common/queue.h index d80806a5dc940281409157b9de03927e2c248ac3..14187549552a44f6fb574c19e5fae24370e75f45 100644 --- a/inc/common/queue.h +++ b/inc/common/queue.h @@ -4,7 +4,7 @@ #include <sys/stat.h> #include <mqueue.h> -#define LEKTORD_QUEUE_NAME "LEKTORD_QUEUE" +#define LEKTORD_QUEUE_NAME "/LEKTORD_QUEUE" enum lkt_event_type { lkt_event_null = 0, /* NULL */ diff --git a/src/commands.c b/src/commands.c index f4f0c7cfca956bc828b9ebc2ab59a5685551a85c..9a1b7c4013ec33f77216a0949a33427ea820a82d 100644 --- a/src/commands.c +++ b/src/commands.c @@ -31,6 +31,7 @@ command_restart(struct lkt_state *srv, size_t c) } close(srv->fds[0].fd); database_queue_state(srv->db, &sta); + lkt_queue_close(srv->queue); env_set(LKT_ENV_RESTART, "1"); int len = long_length(sta.current); if (len > 0) { @@ -89,6 +90,7 @@ command_kill(struct lkt_state *srv, size_t c) RETURN_UNLESS(lkt_client_auth(srv, c, false), "Failed to authentificate user", false); LOG_INFO_SCT("GENERAL", "%s", "Stopping lektord"); close(srv->fds[0].fd); + lkt_queue_close(srv->queue); database_close_all(); exit(EXIT_SUCCESS); } diff --git a/src/queue.c b/src/queue.c index 07bec454643fba428de45675bbf6bb361fca6b14..a7ae48a380b64e9de9d1ca8b2b6a5b99ce355ba1 100644 --- a/src/queue.c +++ b/src/queue.c @@ -12,7 +12,14 @@ mqd_t lkt_queue_open(void) { errno = 0; - mqd_t ret = mq_open(LEKTORD_QUEUE_NAME, O_RDONLY | O_CREAT | O_NONBLOCK); /* Check EAGAIN */ + struct mq_attr attr = { + .mq_flags = O_NONBLOCK, + .mq_maxmsg = 8, + .mq_msgsize = sizeof(void *), + .mq_curmsgs = 1, + }; + UNUSED(&attr); + mqd_t ret = mq_open(LEKTORD_QUEUE_NAME, O_RDWR | O_CREAT, 0622, &attr); switch (errno) { case 0: @@ -20,17 +27,17 @@ lkt_queue_open(void) case EACCES: LOG_ERROR_SCT("QUEUE", "Queue %s already exists", LEKTORD_QUEUE_NAME); - return 0; + return ret; case ENOMEM: LOG_ERROR_SCT("QUEUE", "%s", "Out of memory"); exit(EXIT_FAILURE); default: - LOG_ERROR_SCT("QUEUE", "Unhandled error '%s' (%d)", strerror(errno), errno); + LOG_ERROR_SCT("QUEUE", "Unhandled error '%s' (%d)", + strerror(errno), errno); exit(EXIT_FAILURE); } - } void @@ -43,13 +50,16 @@ lkt_queue_close(mqd_t queue) void lkt_queue_send(enum lkt_event_type type, void *attr) { + errno = 0; mqd_t queue = mq_open(LEKTORD_QUEUE_NAME, O_WRONLY); - if (queue >= 0) { + if (queue != (mqd_t) -1) { if (mq_send(queue, attr, sizeof(void *), type)) - LOG_WARN_SCT("QUEUE", "Failed to send msg of type %d", type); + LOG_WARN_SCT("QUEUE", "Failed to send msg of type %d: %s", + type, strerror(errno)); mq_close(queue); } else - LOG_ERROR_SCT("QUEUE", "Failed to open queue '%s'", LEKTORD_QUEUE_NAME); + LOG_ERROR_SCT("QUEUE", "Failed to open queue '%s': %s", + LEKTORD_QUEUE_NAME, strerror(errno)); } lkt_event