1#!/bin/sh 2 3# 4# SPDX-License-Identifier: BSD-2-Clause-FreeBSD 5# 6# Copyright (c) 2018 Dell EMC Isilon 7# 8# Redistribution and use in source and binary forms, with or without 9# modification, are permitted provided that the following conditions 10# are met: 11# 1. Redistributions of source code must retain the above copyright 12# notice, this list of conditions and the following disclaimer. 13# 2. Redistributions in binary form must reproduce the above copyright 14# notice, this list of conditions and the following disclaimer in the 15# documentation and/or other materials provided with the distribution. 16# 17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27# SUCH DAMAGE. 28# 29 30# UNIX datagram socket test. 31 32# "panic: mutex unp not owned at ../../../kern/uipc_usrreq.c:879" seen. 33# Fixed by r334756. 34 35. ../default.cfg 36 37cd /tmp 38cat > datagram3.c <<EOF 39#include <sys/param.h> 40#include <sys/socket.h> 41#include <sys/un.h> 42#include <sys/wait.h> 43 44#include <netinet/in.h> 45 46#include <err.h> 47#include <errno.h> 48#include <netdb.h> 49#include <signal.h> 50#include <stdio.h> 51#include <stdlib.h> 52#include <string.h> 53#include <unistd.h> 54 55char *filename = "/tmp/datagram3.socket"; 56 57int 58main(void) { 59 60 struct message { struct cmsghdr msg_hdr; int fd; } m; 61 struct msghdr mh; 62 struct sockaddr_un addr; 63 ssize_t len; 64 int i, sockfd; 65 66 unlink(filename); 67 memset(&addr, 0, sizeof(addr)); 68 addr.sun_family = AF_UNIX; 69 strncpy(addr.sun_path, filename, 104); 70 71 if ((sockfd = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) 72 err(1, "socket"); 73 74 if (bind(sockfd, (struct sockaddr *) &addr, 75 sizeof(addr)) == -1) 76 err(1, "bind"); 77 78 if (connect(sockfd, (struct sockaddr *) &addr, 79 sizeof(addr)) == -1) 80 err(1, "connect"); 81 82 for (i = 0; i < 32; i++) { 83 bzero(&mh, sizeof(mh)); 84 bzero(&m, sizeof(m)); 85 mh.msg_control = &m; 86 mh.msg_controllen = sizeof(m); 87 m.msg_hdr.cmsg_len = sizeof(m); 88 m.msg_hdr.cmsg_level = SOL_SOCKET; 89 m.msg_hdr.cmsg_type = SCM_RIGHTS; 90 m.fd = sockfd; 91 len = sendmsg(sockfd, &mh, 0); 92 if (len < 0) 93 err(1, "sendmsg"); 94 } 95 96 return (0); 97} 98EOF 99 100mycc -o datagram3 -Wall -Wextra -O2 -g datagram3.c || exit 1 101rm -f datagram3.c datagram3.socket 102 103./datagram3 104 105rm datagram3 datagram3.socket 106exit 0 107