^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #define _GNU_SOURCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <sys/msg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "../kselftest.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define MAX_MSG_SIZE 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) struct msg1 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) int msize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) long mtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) char mtext[MAX_MSG_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define TEST_STRING "Test sysv5 msg"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define MSG_TYPE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define ANOTHER_TEST_STRING "Yet another test sysv5 msg"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define ANOTHER_MSG_TYPE 26538
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct msgque_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) key_t key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) int msq_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) int qbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) int qnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct msg1 *messages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) int restore_queue(struct msgque_data *msgque)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int fd, ret, id, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) char buf[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) fd = open("/proc/sys/kernel/msg_next_id", O_WRONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (fd == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) printf("Failed to open /proc/sys/kernel/msg_next_id\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) sprintf(buf, "%d", msgque->msq_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) ret = write(fd, buf, strlen(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (ret != strlen(buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) printf("Failed to write to /proc/sys/kernel/msg_next_id\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) return -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) id = msgget(msgque->key, msgque->mode | IPC_CREAT | IPC_EXCL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (id == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) printf("Failed to create queue\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (id != msgque->msq_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) printf("Restored queue has wrong id (%d instead of %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) id, msgque->msq_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) goto destroy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) for (i = 0; i < msgque->qnum; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (msgsnd(msgque->msq_id, &msgque->messages[i].mtype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) msgque->messages[i].msize, IPC_NOWAIT) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) printf("msgsnd failed (%m)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) ret = -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) goto destroy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) destroy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (msgctl(id, IPC_RMID, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) printf("Failed to destroy queue: %d\n", -errno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) int check_and_destroy_queue(struct msgque_data *msgque)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct msg1 message;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) int cnt = 0, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) ret = msgrcv(msgque->msq_id, &message.mtype, MAX_MSG_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 0, IPC_NOWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (errno == ENOMSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) printf("Failed to read IPC message: %m\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) ret = -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (ret != msgque->messages[cnt].msize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) printf("Wrong message size: %d (expected %d)\n", ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) msgque->messages[cnt].msize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (message.mtype != msgque->messages[cnt].mtype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) printf("Wrong message type\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (memcmp(message.mtext, msgque->messages[cnt].mtext, ret)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) printf("Wrong message content\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (cnt != msgque->qnum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) printf("Wrong message number\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (msgctl(msgque->msq_id, IPC_RMID, NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) printf("Failed to destroy queue: %d\n", -errno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) int dump_queue(struct msgque_data *msgque)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct msqid_ds ds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int kern_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) for (kern_id = 0; kern_id < 256; kern_id++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) ret = msgctl(kern_id, MSG_STAT, &ds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (errno == EINVAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) printf("Failed to get stats for IPC queue with id %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) kern_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (ret == msgque->msq_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) msgque->messages = malloc(sizeof(struct msg1) * ds.msg_qnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (msgque->messages == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) printf("Failed to get stats for IPC queue\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) msgque->qnum = ds.msg_qnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) msgque->mode = ds.msg_perm.mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) msgque->qbytes = ds.msg_qbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) for (i = 0; i < msgque->qnum; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) ret = msgrcv(msgque->msq_id, &msgque->messages[i].mtype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) MAX_MSG_SIZE, i, IPC_NOWAIT | MSG_COPY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) printf("Failed to copy IPC message: %m (%d)\n", errno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) msgque->messages[i].msize = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) int fill_msgque(struct msgque_data *msgque)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct msg1 msgbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) msgbuf.mtype = MSG_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) memcpy(msgbuf.mtext, TEST_STRING, sizeof(TEST_STRING));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (msgsnd(msgque->msq_id, &msgbuf.mtype, sizeof(TEST_STRING),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) IPC_NOWAIT) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) printf("First message send failed (%m)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) msgbuf.mtype = ANOTHER_MSG_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) memcpy(msgbuf.mtext, ANOTHER_TEST_STRING, sizeof(ANOTHER_TEST_STRING));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (msgsnd(msgque->msq_id, &msgbuf.mtype, sizeof(ANOTHER_TEST_STRING),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) IPC_NOWAIT) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) printf("Second message send failed (%m)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int main(int argc, char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) int msg, pid, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct msgque_data msgque;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (getuid() != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return ksft_exit_skip(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) "Please run the test as root - Exiting.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) msgque.key = ftok(argv[0], 822155650);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (msgque.key == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) printf("Can't make key: %d\n", -errno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return ksft_exit_fail();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) msgque.msq_id = msgget(msgque.key, IPC_CREAT | IPC_EXCL | 0666);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (msgque.msq_id == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) err = -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) printf("Can't create queue: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) err = fill_msgque(&msgque);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) printf("Failed to fill queue: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) goto err_destroy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) err = dump_queue(&msgque);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) printf("Failed to dump queue: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) goto err_destroy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) err = check_and_destroy_queue(&msgque);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) printf("Failed to check and destroy queue: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) err = restore_queue(&msgque);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) printf("Failed to restore queue: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) goto err_destroy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) err = check_and_destroy_queue(&msgque);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) printf("Failed to test queue: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return ksft_exit_pass();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) err_destroy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (msgctl(msgque.msq_id, IPC_RMID, NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) printf("Failed to destroy queue: %d\n", -errno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return ksft_exit_fail();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return ksft_exit_fail();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }