xref: /minix3/tests/lib/libc/sys/t_msgctl.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /* $NetBSD: t_msgctl.c,v 1.4 2014/02/27 00:59:50 joerg Exp $ */
211be35a1SLionel Sambuc 
311be35a1SLionel Sambuc /*-
411be35a1SLionel Sambuc  * Copyright (c) 2011 The NetBSD Foundation, Inc.
511be35a1SLionel Sambuc  * All rights reserved.
611be35a1SLionel Sambuc  *
711be35a1SLionel Sambuc  * This code is derived from software contributed to The NetBSD Foundation
811be35a1SLionel Sambuc  * by Jukka Ruohonen.
911be35a1SLionel Sambuc  *
1011be35a1SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
1111be35a1SLionel Sambuc  * modification, are permitted provided that the following conditions
1211be35a1SLionel Sambuc  * are met:
1311be35a1SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
1411be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
1511be35a1SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
1611be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
1711be35a1SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
1811be35a1SLionel Sambuc  *
1911be35a1SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2011be35a1SLionel Sambuc  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2111be35a1SLionel Sambuc  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2211be35a1SLionel Sambuc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2311be35a1SLionel Sambuc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2411be35a1SLionel Sambuc  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2511be35a1SLionel Sambuc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2611be35a1SLionel Sambuc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2711be35a1SLionel Sambuc  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2811be35a1SLionel Sambuc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2911be35a1SLionel Sambuc  * POSSIBILITY OF SUCH DAMAGE.
3011be35a1SLionel Sambuc  */
3111be35a1SLionel Sambuc #include <sys/cdefs.h>
32*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: t_msgctl.c,v 1.4 2014/02/27 00:59:50 joerg Exp $");
3311be35a1SLionel Sambuc 
3411be35a1SLionel Sambuc #include <sys/msg.h>
3511be35a1SLionel Sambuc #include <sys/stat.h>
3611be35a1SLionel Sambuc #include <sys/sysctl.h>
3711be35a1SLionel Sambuc #include <sys/wait.h>
3811be35a1SLionel Sambuc 
3911be35a1SLionel Sambuc #include <atf-c.h>
4011be35a1SLionel Sambuc #include <errno.h>
4111be35a1SLionel Sambuc #include <pwd.h>
4211be35a1SLionel Sambuc #include <stdio.h>
4311be35a1SLionel Sambuc #include <stdlib.h>
4411be35a1SLionel Sambuc #include <string.h>
4511be35a1SLionel Sambuc #include <sysexits.h>
4611be35a1SLionel Sambuc #include <time.h>
4711be35a1SLionel Sambuc #include <unistd.h>
4811be35a1SLionel Sambuc 
4911be35a1SLionel Sambuc #define MSG_KEY		12345689
5011be35a1SLionel Sambuc #define MSG_MTYPE_1	0x41
5111be35a1SLionel Sambuc 
5211be35a1SLionel Sambuc struct msg {
5311be35a1SLionel Sambuc 	long		 mtype;
5411be35a1SLionel Sambuc 	char		 buf[3];
5511be35a1SLionel Sambuc };
5611be35a1SLionel Sambuc 
5711be35a1SLionel Sambuc static void		clean(void);
5811be35a1SLionel Sambuc 
5911be35a1SLionel Sambuc static void
clean(void)6011be35a1SLionel Sambuc clean(void)
6111be35a1SLionel Sambuc {
6211be35a1SLionel Sambuc 	int id;
6311be35a1SLionel Sambuc 
6411be35a1SLionel Sambuc 	if ((id = msgget(MSG_KEY, 0)) != -1)
6511be35a1SLionel Sambuc 		(void)msgctl(id, IPC_RMID, 0);
6611be35a1SLionel Sambuc }
6711be35a1SLionel Sambuc 
6811be35a1SLionel Sambuc ATF_TC_WITH_CLEANUP(msgctl_err);
ATF_TC_HEAD(msgctl_err,tc)6911be35a1SLionel Sambuc ATF_TC_HEAD(msgctl_err, tc)
7011be35a1SLionel Sambuc {
7111be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test errors from msgctl(2)");
7211be35a1SLionel Sambuc }
7311be35a1SLionel Sambuc 
ATF_TC_BODY(msgctl_err,tc)7411be35a1SLionel Sambuc ATF_TC_BODY(msgctl_err, tc)
7511be35a1SLionel Sambuc {
7611be35a1SLionel Sambuc 	const int cmd[] = { IPC_STAT, IPC_SET, IPC_RMID };
7711be35a1SLionel Sambuc 	struct msqid_ds msgds;
7811be35a1SLionel Sambuc 	size_t i;
7911be35a1SLionel Sambuc 	int id;
8011be35a1SLionel Sambuc 
8111be35a1SLionel Sambuc 	(void)memset(&msgds, 0, sizeof(struct msqid_ds));
8211be35a1SLionel Sambuc 
8311be35a1SLionel Sambuc 	id = msgget(MSG_KEY, IPC_CREAT | 0600);
8411be35a1SLionel Sambuc 	ATF_REQUIRE(id != -1);
8511be35a1SLionel Sambuc 
8611be35a1SLionel Sambuc 	errno = 0;
8711be35a1SLionel Sambuc 	ATF_REQUIRE_ERRNO(EINVAL, msgctl(id, INT_MAX, &msgds) == -1);
8811be35a1SLionel Sambuc 
8911be35a1SLionel Sambuc 	errno = 0;
9011be35a1SLionel Sambuc 	ATF_REQUIRE_ERRNO(EFAULT, msgctl(id, IPC_STAT, (void *)-1) == -1);
9111be35a1SLionel Sambuc 
9211be35a1SLionel Sambuc 	for (i = 0; i < __arraycount(cmd); i++) {
9311be35a1SLionel Sambuc 		errno = 0;
9411be35a1SLionel Sambuc 		ATF_REQUIRE_ERRNO(EINVAL, msgctl(-1, cmd[i], &msgds) == -1);
9511be35a1SLionel Sambuc 	}
9611be35a1SLionel Sambuc 
9711be35a1SLionel Sambuc 	ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0);
9811be35a1SLionel Sambuc }
9911be35a1SLionel Sambuc 
ATF_TC_CLEANUP(msgctl_err,tc)10011be35a1SLionel Sambuc ATF_TC_CLEANUP(msgctl_err, tc)
10111be35a1SLionel Sambuc {
10211be35a1SLionel Sambuc 	clean();
10311be35a1SLionel Sambuc }
10411be35a1SLionel Sambuc 
10511be35a1SLionel Sambuc ATF_TC_WITH_CLEANUP(msgctl_perm);
ATF_TC_HEAD(msgctl_perm,tc)10611be35a1SLionel Sambuc ATF_TC_HEAD(msgctl_perm, tc)
10711be35a1SLionel Sambuc {
10811be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test permissions with msgctl(2)");
10911be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "require.user", "root");
11011be35a1SLionel Sambuc }
11111be35a1SLionel Sambuc 
ATF_TC_BODY(msgctl_perm,tc)11211be35a1SLionel Sambuc ATF_TC_BODY(msgctl_perm, tc)
11311be35a1SLionel Sambuc {
11411be35a1SLionel Sambuc 	struct msqid_ds msgds;
11511be35a1SLionel Sambuc 	struct passwd *pw;
11611be35a1SLionel Sambuc 	pid_t pid;
11711be35a1SLionel Sambuc 	int sta;
11811be35a1SLionel Sambuc 	int id;
11911be35a1SLionel Sambuc 
12011be35a1SLionel Sambuc 	(void)memset(&msgds, 0, sizeof(struct msqid_ds));
12111be35a1SLionel Sambuc 
12211be35a1SLionel Sambuc 	pw = getpwnam("nobody");
12311be35a1SLionel Sambuc 	id = msgget(MSG_KEY, IPC_CREAT | 0600);
12411be35a1SLionel Sambuc 
12511be35a1SLionel Sambuc 	ATF_REQUIRE(id != -1);
12611be35a1SLionel Sambuc 	ATF_REQUIRE(pw != NULL);
12711be35a1SLionel Sambuc 	ATF_REQUIRE(msgctl(id, IPC_STAT, &msgds) == 0);
12811be35a1SLionel Sambuc 
12911be35a1SLionel Sambuc 	pid = fork();
13011be35a1SLionel Sambuc 	ATF_REQUIRE(pid >= 0);
13111be35a1SLionel Sambuc 
13211be35a1SLionel Sambuc 	if (pid == 0) {
13311be35a1SLionel Sambuc 
13411be35a1SLionel Sambuc 		if (setuid(pw->pw_uid) != 0)
13511be35a1SLionel Sambuc 			_exit(EX_OSERR);
13611be35a1SLionel Sambuc 
13711be35a1SLionel Sambuc 		msgds.msg_perm.uid = getuid();
13811be35a1SLionel Sambuc 		msgds.msg_perm.gid = getgid();
13911be35a1SLionel Sambuc 
14011be35a1SLionel Sambuc 		errno = 0;
14111be35a1SLionel Sambuc 
14211be35a1SLionel Sambuc 		if (msgctl(id, IPC_SET, &msgds) == 0)
14311be35a1SLionel Sambuc 			_exit(EXIT_FAILURE);
14411be35a1SLionel Sambuc 
14511be35a1SLionel Sambuc 		if (errno != EPERM)
14611be35a1SLionel Sambuc 			_exit(EXIT_FAILURE);
14711be35a1SLionel Sambuc 
14811be35a1SLionel Sambuc 		(void)memset(&msgds, 0, sizeof(struct msqid_ds));
14911be35a1SLionel Sambuc 
15011be35a1SLionel Sambuc 		if (msgctl(id, IPC_STAT, &msgds) != 0)
15111be35a1SLionel Sambuc 			_exit(EX_OSERR);
15211be35a1SLionel Sambuc 
15311be35a1SLionel Sambuc 		msgds.msg_qbytes = 1;
15411be35a1SLionel Sambuc 
15511be35a1SLionel Sambuc 		if (msgctl(id, IPC_SET, &msgds) == 0)
15611be35a1SLionel Sambuc 			_exit(EXIT_FAILURE);
15711be35a1SLionel Sambuc 
15811be35a1SLionel Sambuc 		if (errno != EPERM)
15911be35a1SLionel Sambuc 			_exit(EXIT_FAILURE);
16011be35a1SLionel Sambuc 
16111be35a1SLionel Sambuc 		_exit(EXIT_SUCCESS);
16211be35a1SLionel Sambuc 	}
16311be35a1SLionel Sambuc 
16411be35a1SLionel Sambuc 	(void)wait(&sta);
16511be35a1SLionel Sambuc 
16611be35a1SLionel Sambuc 	if (WIFEXITED(sta) == 0) {
16711be35a1SLionel Sambuc 
16811be35a1SLionel Sambuc 		if (WEXITSTATUS(sta) == EX_OSERR)
16911be35a1SLionel Sambuc 			atf_tc_fail("system call failed");
17011be35a1SLionel Sambuc 
17111be35a1SLionel Sambuc 		if (WEXITSTATUS(sta) == EXIT_FAILURE)
17211be35a1SLionel Sambuc 			atf_tc_fail("UID %u manipulated root's "
17311be35a1SLionel Sambuc 			    "message queue", pw->pw_uid);
17411be35a1SLionel Sambuc 	}
17511be35a1SLionel Sambuc 
17611be35a1SLionel Sambuc 	ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0);
17711be35a1SLionel Sambuc }
17811be35a1SLionel Sambuc 
ATF_TC_CLEANUP(msgctl_perm,tc)17911be35a1SLionel Sambuc ATF_TC_CLEANUP(msgctl_perm, tc)
18011be35a1SLionel Sambuc {
18111be35a1SLionel Sambuc 	clean();
18211be35a1SLionel Sambuc }
18311be35a1SLionel Sambuc 
18411be35a1SLionel Sambuc ATF_TC_WITH_CLEANUP(msgctl_pid);
ATF_TC_HEAD(msgctl_pid,tc)18511be35a1SLionel Sambuc ATF_TC_HEAD(msgctl_pid, tc)
18611be35a1SLionel Sambuc {
18711be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test that PIDs are updated");
18811be35a1SLionel Sambuc }
18911be35a1SLionel Sambuc 
ATF_TC_BODY(msgctl_pid,tc)19011be35a1SLionel Sambuc ATF_TC_BODY(msgctl_pid, tc)
19111be35a1SLionel Sambuc {
19211be35a1SLionel Sambuc 	struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } };
19311be35a1SLionel Sambuc 	struct msqid_ds msgds;
19411be35a1SLionel Sambuc 	int id, sta;
19511be35a1SLionel Sambuc 	pid_t pid;
19611be35a1SLionel Sambuc 
19711be35a1SLionel Sambuc 	id = msgget(MSG_KEY, IPC_CREAT | 0600);
19811be35a1SLionel Sambuc 	ATF_REQUIRE(id != -1);
19911be35a1SLionel Sambuc 
20011be35a1SLionel Sambuc 	pid = fork();
20111be35a1SLionel Sambuc 	ATF_REQUIRE(pid >= 0);
20211be35a1SLionel Sambuc 
20311be35a1SLionel Sambuc 	if (pid == 0) {
20411be35a1SLionel Sambuc 
20511be35a1SLionel Sambuc 		(void)msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT);
20611be35a1SLionel Sambuc 
20711be35a1SLionel Sambuc 		_exit(EXIT_SUCCESS);
20811be35a1SLionel Sambuc 	}
20911be35a1SLionel Sambuc 
21011be35a1SLionel Sambuc 	(void)sleep(1);
21111be35a1SLionel Sambuc 	(void)wait(&sta);
21211be35a1SLionel Sambuc 	(void)memset(&msgds, 0, sizeof(struct msqid_ds));
21311be35a1SLionel Sambuc 
21411be35a1SLionel Sambuc 	ATF_REQUIRE(msgctl(id, IPC_STAT, &msgds) == 0);
21511be35a1SLionel Sambuc 
21611be35a1SLionel Sambuc 	if (pid != msgds.msg_lspid)
21711be35a1SLionel Sambuc 		atf_tc_fail("the PID of last msgsnd(2) was not updated");
21811be35a1SLionel Sambuc 
21911be35a1SLionel Sambuc 	pid = fork();
22011be35a1SLionel Sambuc 	ATF_REQUIRE(pid >= 0);
22111be35a1SLionel Sambuc 
22211be35a1SLionel Sambuc 	if (pid == 0) {
22311be35a1SLionel Sambuc 
22411be35a1SLionel Sambuc 		(void)msgrcv(id, &msg,
22511be35a1SLionel Sambuc 		    sizeof(struct msg), MSG_MTYPE_1, IPC_NOWAIT);
22611be35a1SLionel Sambuc 
22711be35a1SLionel Sambuc 		_exit(EXIT_SUCCESS);
22811be35a1SLionel Sambuc 	}
22911be35a1SLionel Sambuc 
23011be35a1SLionel Sambuc 	(void)sleep(1);
23111be35a1SLionel Sambuc 	(void)wait(&sta);
23211be35a1SLionel Sambuc 	(void)memset(&msgds, 0, sizeof(struct msqid_ds));
23311be35a1SLionel Sambuc 
23411be35a1SLionel Sambuc 	ATF_REQUIRE(msgctl(id, IPC_STAT, &msgds) == 0);
23511be35a1SLionel Sambuc 
23611be35a1SLionel Sambuc 	if (pid != msgds.msg_lrpid)
23711be35a1SLionel Sambuc 		atf_tc_fail("the PID of last msgrcv(2) was not updated");
23811be35a1SLionel Sambuc 
23911be35a1SLionel Sambuc 	ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0);
24011be35a1SLionel Sambuc }
24111be35a1SLionel Sambuc 
ATF_TC_CLEANUP(msgctl_pid,tc)24211be35a1SLionel Sambuc ATF_TC_CLEANUP(msgctl_pid, tc)
24311be35a1SLionel Sambuc {
24411be35a1SLionel Sambuc 	clean();
24511be35a1SLionel Sambuc }
24611be35a1SLionel Sambuc 
24711be35a1SLionel Sambuc ATF_TC_WITH_CLEANUP(msgctl_set);
ATF_TC_HEAD(msgctl_set,tc)24811be35a1SLionel Sambuc ATF_TC_HEAD(msgctl_set, tc)
24911be35a1SLionel Sambuc {
25011be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test msgctl(2) with IPC_SET");
25111be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "require.user", "root");
25211be35a1SLionel Sambuc }
25311be35a1SLionel Sambuc 
ATF_TC_BODY(msgctl_set,tc)25411be35a1SLionel Sambuc ATF_TC_BODY(msgctl_set, tc)
25511be35a1SLionel Sambuc {
25611be35a1SLionel Sambuc 	struct msqid_ds msgds;
25711be35a1SLionel Sambuc 	struct passwd *pw;
25811be35a1SLionel Sambuc 	int id;
25911be35a1SLionel Sambuc 
26011be35a1SLionel Sambuc 	(void)memset(&msgds, 0, sizeof(struct msqid_ds));
26111be35a1SLionel Sambuc 
26211be35a1SLionel Sambuc 	pw = getpwnam("nobody");
26311be35a1SLionel Sambuc 	id = msgget(MSG_KEY, IPC_CREAT | 0600);
26411be35a1SLionel Sambuc 
26511be35a1SLionel Sambuc 	ATF_REQUIRE(id != -1);
26611be35a1SLionel Sambuc 	ATF_REQUIRE(pw != NULL);
26711be35a1SLionel Sambuc 	ATF_REQUIRE(msgctl(id, IPC_STAT, &msgds) == 0);
26811be35a1SLionel Sambuc 
26911be35a1SLionel Sambuc 	msgds.msg_perm.uid = pw->pw_uid;
27011be35a1SLionel Sambuc 
27111be35a1SLionel Sambuc 	if (msgctl(id, IPC_SET, &msgds) != 0)
27211be35a1SLionel Sambuc 		atf_tc_fail("root failed to change the UID of message queue");
27311be35a1SLionel Sambuc 
27411be35a1SLionel Sambuc 	msgds.msg_perm.uid = getuid();
27511be35a1SLionel Sambuc 	msgds.msg_perm.gid = pw->pw_gid;
27611be35a1SLionel Sambuc 
27711be35a1SLionel Sambuc 	if (msgctl(id, IPC_SET, &msgds) != 0)
27811be35a1SLionel Sambuc 		atf_tc_fail("root failed to change the GID of message queue");
27911be35a1SLionel Sambuc 
28011be35a1SLionel Sambuc 	/*
28111be35a1SLionel Sambuc 	 * Note: setting the qbytes to zero fails even as root.
28211be35a1SLionel Sambuc 	 */
28311be35a1SLionel Sambuc 	msgds.msg_qbytes = 1;
28411be35a1SLionel Sambuc 	msgds.msg_perm.gid = getgid();
28511be35a1SLionel Sambuc 
28611be35a1SLionel Sambuc 	if (msgctl(id, IPC_SET, &msgds) != 0)
28711be35a1SLionel Sambuc 		atf_tc_fail("root failed to change qbytes of message queue");
28811be35a1SLionel Sambuc 
28911be35a1SLionel Sambuc 	ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0);
29011be35a1SLionel Sambuc }
29111be35a1SLionel Sambuc 
ATF_TC_CLEANUP(msgctl_set,tc)29211be35a1SLionel Sambuc ATF_TC_CLEANUP(msgctl_set, tc)
29311be35a1SLionel Sambuc {
29411be35a1SLionel Sambuc 	clean();
29511be35a1SLionel Sambuc }
29611be35a1SLionel Sambuc 
29711be35a1SLionel Sambuc ATF_TC_WITH_CLEANUP(msgctl_time);
ATF_TC_HEAD(msgctl_time,tc)29811be35a1SLionel Sambuc ATF_TC_HEAD(msgctl_time, tc)
29911be35a1SLionel Sambuc {
30011be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test that access times are updated");
30111be35a1SLionel Sambuc }
30211be35a1SLionel Sambuc 
ATF_TC_BODY(msgctl_time,tc)30311be35a1SLionel Sambuc ATF_TC_BODY(msgctl_time, tc)
30411be35a1SLionel Sambuc {
30511be35a1SLionel Sambuc 	struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } };
30611be35a1SLionel Sambuc 	struct msqid_ds msgds;
30711be35a1SLionel Sambuc 	time_t t;
30811be35a1SLionel Sambuc 	int id;
30911be35a1SLionel Sambuc 
31011be35a1SLionel Sambuc 	id = msgget(MSG_KEY, IPC_CREAT | 0600);
31111be35a1SLionel Sambuc 	ATF_REQUIRE(id != -1);
31211be35a1SLionel Sambuc 
31311be35a1SLionel Sambuc 	t = time(NULL);
31411be35a1SLionel Sambuc 
31511be35a1SLionel Sambuc 	(void)memset(&msgds, 0, sizeof(struct msqid_ds));
31611be35a1SLionel Sambuc 	(void)msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT);
31711be35a1SLionel Sambuc 	(void)msgctl(id, IPC_STAT, &msgds);
31811be35a1SLionel Sambuc 
319*0a6a1f1dSLionel Sambuc 	if (llabs(t - msgds.msg_stime) > 1)
32011be35a1SLionel Sambuc 		atf_tc_fail("time of last msgsnd(2) was not updated");
32111be35a1SLionel Sambuc 
32211be35a1SLionel Sambuc 	if (msgds.msg_rtime != 0)
32311be35a1SLionel Sambuc 		atf_tc_fail("time of last msgrcv(2) was updated incorrectly");
32411be35a1SLionel Sambuc 
32511be35a1SLionel Sambuc 	t = time(NULL);
32611be35a1SLionel Sambuc 
32711be35a1SLionel Sambuc 	(void)memset(&msgds, 0, sizeof(struct msqid_ds));
32811be35a1SLionel Sambuc 	(void)msgrcv(id, &msg, sizeof(struct msg), MSG_MTYPE_1, IPC_NOWAIT);
32911be35a1SLionel Sambuc 	(void)msgctl(id, IPC_STAT, &msgds);
33011be35a1SLionel Sambuc 
331*0a6a1f1dSLionel Sambuc 	if (llabs(t - msgds.msg_rtime) > 1)
33211be35a1SLionel Sambuc 		atf_tc_fail("time of last msgrcv(2) was not updated");
33311be35a1SLionel Sambuc 
33411be35a1SLionel Sambuc 	/*
33511be35a1SLionel Sambuc 	 * Note: this is non-zero even after the memset(3).
33611be35a1SLionel Sambuc 	 */
33711be35a1SLionel Sambuc 	if (msgds.msg_stime == 0)
33811be35a1SLionel Sambuc 		atf_tc_fail("time of last msgsnd(2) was updated incorrectly");
33911be35a1SLionel Sambuc 
34011be35a1SLionel Sambuc 	ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0);
34111be35a1SLionel Sambuc }
34211be35a1SLionel Sambuc 
ATF_TC_CLEANUP(msgctl_time,tc)34311be35a1SLionel Sambuc ATF_TC_CLEANUP(msgctl_time, tc)
34411be35a1SLionel Sambuc {
34511be35a1SLionel Sambuc 	clean();
34611be35a1SLionel Sambuc }
34711be35a1SLionel Sambuc 
ATF_TP_ADD_TCS(tp)34811be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
34911be35a1SLionel Sambuc {
35011be35a1SLionel Sambuc 
35111be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, msgctl_err);
35211be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, msgctl_perm);
35311be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, msgctl_pid);
35411be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, msgctl_set);
35511be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, msgctl_time);
35611be35a1SLionel Sambuc 
35711be35a1SLionel Sambuc 	return atf_no_error();
35811be35a1SLionel Sambuc }
359