From df1c6dde40a4943264f5e2c24046b32501c4a6c5 Mon Sep 17 00:00:00 2001 From: Gordon Ross Date: Sun, 28 May 2017 14:12:51 -0400 Subject: 8279 socketpair(AF_UNIX, SOCK_DGRAM,...) broken after 7590 Reviewed by: Igor Kozhukhov Reviewed by: Yuri Pankov Approved by: Dan McDonald --- usr/src/test/os-tests/tests/sockfs/sockpair.c | 82 +++++++++++++-------------- usr/src/uts/common/fs/sockfs/socktpi.c | 11 ++-- 2 files changed, 47 insertions(+), 46 deletions(-) diff --git a/usr/src/test/os-tests/tests/sockfs/sockpair.c b/usr/src/test/os-tests/tests/sockfs/sockpair.c index 2032970e6f..536aa9dd89 100644 --- a/usr/src/test/os-tests/tests/sockfs/sockpair.c +++ b/usr/src/test/os-tests/tests/sockfs/sockpair.c @@ -33,6 +33,8 @@ #include #include +extern char *__progname; + static void * server(void *varg) { @@ -62,66 +64,40 @@ server(void *varg) strerror(errno)); exit(1); } + if (ret == 0) { + printf("SERVER: got HUP\n"); + break; + } printf("SERVER:%s\n", (char *)msg.msg_iov->iov_base); fflush(stdout); } - exit(0); + close(sock); + return (NULL); } -/* - * This should be a place only root is allowed to write. - * The test will create and destroy this directory. - */ -char testdir[100] = "/var/run/os-tests-sockfs"; -struct sockaddr_un addr; -int test_uid = UID_NOBODY; - -int -main(int argc, char **argv) +void +runtest(int sotype) { - int ret; int sfds[2]; int sock; + int ret; unsigned int i; - if (argc > 1) { - ret = strlcpy(testdir, argv[1], sizeof (testdir)); - if (ret >= sizeof (testdir)) { - fprintf(stderr, "%s: too long\n", argv[1]); - exit(1); - } - } - - addr.sun_family = AF_UNIX; - (void) sprintf(addr.sun_path, "%s/s", testdir); - - if (mkdir(testdir, 0700) != 0) { - switch (errno) { - case EEXIST: - case EISDIR: - break; - default: - perror(testdir); - exit(1); - } - } - (void) unlink(addr.sun_path); - /* Create socketpair */ - ret = socketpair(AF_UNIX, SOCK_STREAM, 0, sfds); + ret = socketpair(AF_UNIX, sotype, 0, sfds); if (ret == -1) { fprintf(stderr, "%s - socketpair fail %s\n", - argv[0], strerror(errno)); + __progname, strerror(errno)); exit(1); } - /* Set up the server. */ + /* Set up the server. It closes sfds[0] when done. */ ret = pthread_create(NULL, NULL, server, sfds); if (ret == -1) { fprintf(stderr, "%s - thread create fail %s\n", - argv[0], strerror(errno)); + __progname, strerror(errno)); exit(1); } @@ -131,7 +107,7 @@ main(int argc, char **argv) sock = sfds[1]; /* Send some messages */ - for (i = 0; i < 5; i++) { + for (i = 0; i < 3; i++) { struct iovec iov; struct msghdr msg; uint8_t buf[4096]; @@ -155,7 +131,7 @@ main(int argc, char **argv) if (ret == -1) { fprintf(stderr, "%s - sendmsg fail %s\n", - argv[0], strerror(errno)); + __progname, strerror(errno)); exit(1); } @@ -163,6 +139,28 @@ main(int argc, char **argv) sleep(1); } - close(sock); + /* + * Tell sever to terminate + */ + if (sotype == SOCK_STREAM) { + printf("CLIENT: close\n"); + close(sock); + } else { + printf("CLIENT: send 0\n"); + send(sock, "", 0, 0); + } + sleep(1); +} + +int +main(int argc, char **argv) +{ + + printf("%s SOCK_STREAM test...\n", argv[0]); + runtest(SOCK_STREAM); + + printf("%s SOCK_DGRAM test...\n", argv[0]); + runtest(SOCK_DGRAM); + return (0); } diff --git a/usr/src/uts/common/fs/sockfs/socktpi.c b/usr/src/uts/common/fs/sockfs/socktpi.c index aaad07d5d3..bbeee8ce4b 100644 --- a/usr/src/uts/common/fs/sockfs/socktpi.c +++ b/usr/src/uts/common/fs/sockfs/socktpi.c @@ -2388,13 +2388,16 @@ sotpi_connect(struct sonode *so, if (so->so_family == AF_UNIX) { if (sti->sti_faddr_noxlate) { /* - * Already have a transport internal address. Do not - * pass any (transport internal) source address. + * sti_faddr is a transport-level address, so + * don't pass it as an option. Do save it in + * sti_ux_faddr, used for connected DG send. */ - addr = sti->sti_faddr_sa; - addrlen = (t_uscalar_t)sti->sti_faddr_len; src = NULL; srclen = 0; + addr = sti->sti_faddr_sa; + addrlen = (t_uscalar_t)sti->sti_faddr_len; + bcopy(addr, &sti->sti_ux_faddr, + sizeof (sti->sti_ux_faddr)); } else { /* * Pass the sockaddr_un source address as an option -- cgit v1.2.3