Module Name:    src
Committed By:   pooka
Date:           Fri Dec 18 21:24:13 UTC 2009

Modified Files:
        src/tests/syscall: t_cmsg.c

Log Message:
Must use CMSG_SPACE instead of CMSG_LEN for control message buffer.
Fixes test on sparc64 (and possible other alignment-picky ports).
from mlelstv


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/syscall/t_cmsg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/syscall/t_cmsg.c
diff -u src/tests/syscall/t_cmsg.c:1.12 src/tests/syscall/t_cmsg.c:1.13
--- src/tests/syscall/t_cmsg.c:1.12	Thu Nov 26 17:33:23 2009
+++ src/tests/syscall/t_cmsg.c	Fri Dec 18 21:24:13 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_cmsg.c,v 1.12 2009/11/26 17:33:23 pooka Exp $	*/
+/*	$NetBSD: t_cmsg.c,v 1.13 2009/12/18 21:24:13 pooka Exp $	*/
 
 #include <sys/types.h>
 #include <sys/mount.h>
@@ -40,7 +40,7 @@
 	if (rump_sys_socketpair(AF_LOCAL, SOCK_STREAM, 0, s) == -1)
 		atf_tc_fail("rump_sys_socket");
 
-	cmp = malloc(CMSG_LEN(sizeof(int)));
+	cmp = malloc(CMSG_SPACE(sizeof(int)));
 
 	iov.iov_base = &fd;
 	iov.iov_len = sizeof(int);
@@ -54,7 +54,7 @@
 	msg.msg_name = NULL;
 	msg.msg_namelen = 0;
 	msg.msg_control = cmp;
-	msg.msg_controllen = CMSG_LEN(sizeof(int));
+	msg.msg_controllen = CMSG_SPACE(sizeof(int));
 
 	/*
 	 * ERROR HERE: trying to pass invalid fd
@@ -128,14 +128,14 @@
 	    sizeof(MAGICSTRING))
 		atf_tc_fail_errno("pipe write"); /* XXX: errno */
 
-	cmp = malloc(CMSG_LEN(sizeof(int)));
+	cmp = malloc(CMSG_SPACE(sizeof(int)));
 
 	iov.iov_base = &storage;
 	iov.iov_len = sizeof(int);
 
 	cmp->cmsg_level = SOL_SOCKET;
 	cmp->cmsg_type = SCM_RIGHTS;
-	cmp->cmsg_len = CMSG_LEN(sizeof(int));
+	cmp->cmsg_len = CMSG_SPACE(sizeof(int));
 
 	msg.msg_iov = &iov;
 	msg.msg_iovlen = 1;
@@ -149,6 +149,13 @@
 	if (rump_sys_sendmsg(s2, &msg, 0) == -1)
 		atf_tc_fail_errno("sendmsg failed");
 
+	/*
+	 * We will read to the same cmsg space.  Overwrite the space
+	 * with an invalid fd to make sure we get an explicit error
+	 * if we don't manage to read the fd.
+	 */
+	*(int *)CMSG_DATA(cmp) = -1;
+
 	/* switch back to original proc */
 	rump_pub_lwp_switch(l1);
 

Reply via email to