summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith M Wesolowski <wesolows@foobazco.org>2013-05-08 18:18:49 +0000
committerKeith M Wesolowski <wesolows@foobazco.org>2013-05-08 18:18:49 +0000
commit43840e901cacf50a9bb41148069e34ca307524e8 (patch)
tree2836162f69bba2534e8b9acf9797e5892f103258
parentabd43b3991c3becf4fd3cc1a370aeafdc8749a30 (diff)
parent5dbfd19ad5fcc2b779f40f80fa05c1bd28fd0b4e (diff)
downloadillumos-joyent-43840e901cacf50a9bb41148069e34ca307524e8.tar.gz
[illumos-gate merge]
commit 5dbfd19ad5fcc2b779f40f80fa05c1bd28fd0b4e 3713 Implement accept4() 3714 Implement pipe2() 3715 Implement dup3() 3716 Implement mkostemp() and mkostemps() 3719 so_socketpair syscall should preserve FD_CLOEXEC flag commit 6136c589445a3ea081bd34ab72db1060875b6bcc 3722 link-editor is over restrictive of R_AMD64_32 addends Conflicts: usr/src/lib/libc/sparcv9/Makefile.com [copyright] usr/src/lib/libc/sparc/Makefile.com [copyright] usr/src/lib/libc/i386/Makefile.com [copyright]
-rw-r--r--usr/src/cmd/sgs/packages/common/SUNWonld-README1
-rw-r--r--usr/src/cmd/truss/codes.c4
-rw-r--r--usr/src/cmd/truss/print.c72
-rw-r--r--usr/src/cmd/truss/print.h7
-rw-r--r--usr/src/cmd/truss/systable.c6
-rw-r--r--usr/src/head/stdlib.h4
-rw-r--r--usr/src/head/unistd.h5
-rw-r--r--usr/src/lib/libc/amd64/Makefile4
-rw-r--r--usr/src/lib/libc/common/sys/_so_accept.s7
-rw-r--r--usr/src/lib/libc/common/sys/pipe2.s (renamed from usr/src/lib/libc/i386/sys/pipe.s)23
-rw-r--r--usr/src/lib/libc/i386/Makefile.com4
-rw-r--r--usr/src/lib/libc/port/gen/dup.c27
-rw-r--r--usr/src/lib/libc/port/gen/mkstemp.c30
-rw-r--r--usr/src/lib/libc/port/gen/pipe.c (renamed from usr/src/lib/libc/amd64/sys/pipe.s)27
-rw-r--r--usr/src/lib/libc/port/llib-lc8
-rw-r--r--usr/src/lib/libc/port/mapfile-vers15
-rw-r--r--usr/src/lib/libc/port/threads/scalls.c9
-rw-r--r--usr/src/lib/libc/sparc/Makefile.com4
-rw-r--r--usr/src/lib/libc/sparc/sys/pipe.s52
-rw-r--r--usr/src/lib/libc/sparcv9/Makefile.com4
-rw-r--r--usr/src/lib/libsocket/common/llib-lsocket3
-rw-r--r--usr/src/lib/libsocket/common/mapfile-vers7
-rw-r--r--usr/src/lib/libsocket/socket/weaks.c11
-rw-r--r--usr/src/man/man2/Makefile4
-rw-r--r--usr/src/man/man2/fcntl.227
-rw-r--r--usr/src/man/man2/pipe.277
-rw-r--r--usr/src/man/man3c/Makefile8
-rw-r--r--usr/src/man/man3c/dup2.3c32
-rw-r--r--usr/src/man/man3c/mkstemp.3c21
-rw-r--r--usr/src/man/man3socket/Makefile6
-rw-r--r--usr/src/man/man3socket/accept.3socket66
-rw-r--r--usr/src/pkg/manifests/system-kernel.man2.inc2
-rw-r--r--usr/src/pkg/manifests/system-library.man3c.inc4
-rw-r--r--usr/src/pkg/manifests/system-library.man3socket.inc2
-rw-r--r--usr/src/uts/common/fs/sockfs/socksyscalls.c44
-rw-r--r--usr/src/uts/common/os/sysent.c5
-rw-r--r--usr/src/uts/common/sys/fcntl.h3
-rw-r--r--usr/src/uts/common/sys/socket.h8
-rw-r--r--usr/src/uts/common/syscall/fcntl.c18
-rw-r--r--usr/src/uts/common/syscall/pipe.c74
-rw-r--r--usr/src/uts/intel/amd64/krtld/doreloc.c25
41 files changed, 594 insertions, 166 deletions
diff --git a/usr/src/cmd/sgs/packages/common/SUNWonld-README b/usr/src/cmd/sgs/packages/common/SUNWonld-README
index 2a6d570955..32672515c4 100644
--- a/usr/src/cmd/sgs/packages/common/SUNWonld-README
+++ b/usr/src/cmd/sgs/packages/common/SUNWonld-README
@@ -1646,3 +1646,4 @@ Bugid Risk Synopsis
3451 archive libraries with no symbols shouldn't require a string table
3616 SHF_GROUP sections should not be discarded via other COMDAT mechanisms
3709 need sloppy relocation for GNU .debug_macro
+3722 link-editor is over restrictive of R_AMD64_32 addends
diff --git a/usr/src/cmd/truss/codes.c b/usr/src/cmd/truss/codes.c
index dcab90e5fa..87fae4f257 100644
--- a/usr/src/cmd/truss/codes.c
+++ b/usr/src/cmd/truss/codes.c
@@ -146,8 +146,8 @@ const char *const FCNTLname[] = {
"F_GETLK64",
"F_SETLK64",
"F_SETLKW64",
- NULL, /* 36 */
- NULL, /* 37 */
+ "F_DUP2FD_CLOEXEC",
+ "F_DUPFD_CLOEXEC",
NULL, /* 38 */
NULL, /* 39 */
"F_SHARE",
diff --git a/usr/src/cmd/truss/print.c b/usr/src/cmd/truss/print.c
index 9fbbefbe62..fc236bd556 100644
--- a/usr/src/cmd/truss/print.c
+++ b/usr/src/cmd/truss/print.c
@@ -372,6 +372,48 @@ prt_ioa(private_t *pri, int raw, long val) /* print ioctl argument */
}
void
+prt_pip(private_t *pri, int raw, long val) /* print pipe code */
+{
+ const char *s = NULL;
+
+ if (!raw) {
+ switch (val) {
+ case O_CLOEXEC:
+ s = "O_CLOEXEC";
+ break;
+ case O_NONBLOCK:
+ s = "O_NONBLOCK";
+ break;
+ case O_CLOEXEC|O_NONBLOCK:
+ s = "O_CLOEXEC|O_NONBLOCK";
+ break;
+ }
+ }
+
+ if (s == NULL)
+ prt_dex(pri, 0, val);
+ else
+ outstring(pri, s);
+}
+
+void
+prt_pfd(private_t *pri, int raw, long val) /* print pipe code */
+{
+ int fds[2];
+ char str[32];
+
+ /* the fds only have meaning if the return value is 0 */
+ if (!raw &&
+ pri->Rval1 >= 0 &&
+ Pread(Proc, fds, sizeof (fds), (long)val) == sizeof (fds)) {
+ snprintf(str, sizeof (str), "[%d,%d]", fds[0], fds[1]);
+ outstring(pri, str);
+ } else {
+ prt_hex(pri, 0, val);
+ }
+}
+
+void
prt_fcn(private_t *pri, int raw, long val) /* print fcntl code */
{
const char *s = raw? NULL : fcntlname(val);
@@ -1747,6 +1789,32 @@ prt_skv(private_t *pri, int raw, long val)
}
}
+/*
+ * Print accept4() flags argument.
+ */
+void
+prt_acf(private_t *pri, int raw, long val)
+{
+ int first = 1;
+ if (raw || !val ||
+ (val & ~(SOCK_CLOEXEC|SOCK_NDELAY|SOCK_NONBLOCK))) {
+ prt_dex(pri, 0, val);
+ return;
+ }
+
+ if (val & SOCK_CLOEXEC) {
+ outstring(pri, "|SOCK_CLOEXEC" + first);
+ first = 0;
+ }
+ if (val & SOCK_NDELAY) {
+ outstring(pri, "|SOCK_NDELAY" + first);
+ first = 0;
+ }
+ if (val & SOCK_NONBLOCK) {
+ outstring(pri, "|SOCK_NONBLOCK" + first);
+ }
+}
+
/*
* Print setsockopt()/getsockopt() 2nd argument.
@@ -2708,7 +2776,7 @@ void (* const Print[])() = {
prt_rst, /* RST -- print string returned by syscall */
prt_smf, /* SMF -- print streams message flags */
prt_ioa, /* IOA -- print ioctl argument */
- prt_nov, /* Was SIX, now available for reuse */
+ prt_pip, /* PIP -- print pipe flags */
prt_mtf, /* MTF -- print mount flags */
prt_mft, /* MFT -- print mount file system type */
prt_iob, /* IOB -- print contents of I/O buffer */
@@ -2783,5 +2851,7 @@ void (* const Print[])() = {
prt_mob, /* MOB -- print mmapobj() flags */
prt_snf, /* SNF -- print AT_SYMLINK_[NO]FOLLOW flag */
prt_skc, /* SKC -- print sockconfig() subcode */
+ prt_acf, /* ACF -- print accept4 flags */
+ prt_pfd, /* PFD -- print pipe fds */
prt_dec, /* HID -- hidden argument, make this the last one */
};
diff --git a/usr/src/cmd/truss/print.h b/usr/src/cmd/truss/print.h
index 98c2223052..9a9a43b4cb 100644
--- a/usr/src/cmd/truss/print.h
+++ b/usr/src/cmd/truss/print.h
@@ -26,6 +26,7 @@
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
+/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All right reserved. */
#ifndef _TRUSS_PRINT_H
#define _TRUSS_PRINT_H
@@ -61,7 +62,7 @@ extern "C" {
#define RST 21 /* print string returned by sys call */
#define SMF 22 /* print streams message flags */
#define IOA 23 /* print ioctl argument */
-/* Number 24 now available for reuse */
+#define PIP 24 /* print pipe flags */
#define MTF 25 /* print mount flags */
#define MFT 26 /* print mount file system type */
#define IOB 27 /* print contents of I/O buffer */
@@ -136,7 +137,9 @@ extern "C" {
#define MOB 96 /* print mmapobj() flags */
#define SNF 97 /* print AT_SYMLINK_[NO]FOLLOW flag */
#define SKC 98 /* print sockconfig subcode */
-#define HID 99 /* hidden argument, don't print */
+#define ACF 99 /* accept4 flags */
+#define PFD 100 /* pipe fds[2] */
+#define HID 101 /* hidden argument, don't print */
/* make sure HID is always the last member */
/*
diff --git a/usr/src/cmd/truss/systable.c b/usr/src/cmd/truss/systable.c
index 66ae2525f4..3cd07c698b 100644
--- a/usr/src/cmd/truss/systable.c
+++ b/usr/src/cmd/truss/systable.c
@@ -26,6 +26,8 @@
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
+/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
+
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
@@ -258,7 +260,7 @@ const struct systable systable[] = {
{"pgrpsys", 3, DEC, NOV, DEC, DEC, DEC}, /* 39 */
{"uucopystr", 3, DEC, NOV, STG, RST, UNS}, /* 40 */
{ NULL, 8, HEX, HEX, HEX, HEX, HEX, HEX, HEX, HEX, HEX, HEX},
-{"pipe", 0, DEC, DEC}, /* 42 */
+{"pipe", 2, DEC, NOV, PFD, PIP}, /* 42 */
{"times", 1, DEC, NOV, HEX}, /* 43 */
{"profil", 4, DEC, NOV, HEX, UNS, HEX, OCT}, /* 44 */
{"faccessat", 4, DEC, NOV, ATC, STG, ACC, FAT}, /* 45 */
@@ -450,7 +452,7 @@ const struct systable systable[] = {
{"so_socketpair", 1, DEC, NOV, HEX}, /* 231 */
{"bind", 4, DEC, NOV, DEC, HEX, DEC, SKV}, /* 232 */
{"listen", 3, DEC, NOV, DEC, DEC, SKV}, /* 233 */
-{"accept", 4, DEC, NOV, DEC, HEX, HEX, SKV}, /* 234 */
+{"accept", 5, DEC, NOV, DEC, HEX, HEX, SKV, ACF}, /* 234 */
{"connect", 4, DEC, NOV, DEC, HEX, DEC, SKV}, /* 235 */
{"shutdown", 3, DEC, NOV, DEC, SHT, SKV}, /* 236 */
{"recv", 4, DEC, NOV, DEC, IOB, DEC, DEC}, /* 237 */
diff --git a/usr/src/head/stdlib.h b/usr/src/head/stdlib.h
index 66a4bb444a..329f654da6 100644
--- a/usr/src/head/stdlib.h
+++ b/usr/src/head/stdlib.h
@@ -23,6 +23,8 @@
* Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
*/
+/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
+
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
@@ -216,6 +218,7 @@ extern int clearenv(void);
extern void closefrom(int);
extern int daemon(int, int);
extern int dup2(int, int);
+extern int dup3(int, int, int);
extern int fdwalk(int (*)(void *, int), void *);
extern char *qecvt(long double, int, int *, int *);
extern char *qfcvt(long double, int, int *, int *);
@@ -323,6 +326,7 @@ extern int clearenv();
extern void closefrom();
extern int daemon();
extern int dup2();
+extern int dup3();
extern int fdwalk();
extern char *qecvt();
extern char *qfcvt();
diff --git a/usr/src/head/unistd.h b/usr/src/head/unistd.h
index 4b464d5c47..43b34fa303 100644
--- a/usr/src/head/unistd.h
+++ b/usr/src/head/unistd.h
@@ -26,6 +26,8 @@
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
+/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
+
#ifndef _UNISTD_H
#define _UNISTD_H
@@ -274,6 +276,7 @@ extern char *cuserid(char *);
#endif
extern int dup(int);
extern int dup2(int, int);
+extern int dup3(int, int, int);
#if defined(_XPG4) || defined(__EXTENSIONS__)
extern void encrypt(char *, int);
#endif /* defined(XPG4) || defined(__EXTENSIONS__) */
@@ -418,6 +421,7 @@ extern int mincore(caddr_t, size_t, char *);
extern long pathconf(const char *, int);
extern int pause(void);
extern int pipe(int *);
+extern int pipe2(int *, int);
#if !defined(_POSIX_C_SOURCE) || defined(_XPG5) || \
(defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64) || \
defined(__EXTENSIONS__)
@@ -611,6 +615,7 @@ extern char *cuserid();
#endif
extern int dup();
extern int dup2();
+extern int dup3();
#if defined(_XPG4) || defined(__EXTENSIONS__)
extern void encrypt();
#endif /* defined(_XPG4) || defined(__EXTENSIONS__) */
diff --git a/usr/src/lib/libc/amd64/Makefile b/usr/src/lib/libc/amd64/Makefile
index 2f37212a55..396c536387 100644
--- a/usr/src/lib/libc/amd64/Makefile
+++ b/usr/src/lib/libc/amd64/Makefile
@@ -22,6 +22,7 @@
# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2012, Joyent, Inc. All rights reserved.
#
+# Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
# Copyright 2011 Nexenta Systems, Inc. All rights reserved.
# Use is subject to license terms.
#
@@ -223,6 +224,7 @@ COMSYSOBJS= \
pathconf.o \
pause.o \
pcsample.o \
+ pipe2.o \
pollsys.o \
pread.o \
priocntlset.o \
@@ -279,7 +281,6 @@ SYSOBJS= \
gettimeofday.o \
lwp_private.o \
nuname.o \
- pipe.o \
syscall.o \
sysi86.o \
tls_get_addr.o \
@@ -468,6 +469,7 @@ PORTGEN= \
pfmt.o \
pfmt_data.o \
pfmt_print.o \
+ pipe.o \
plock.o \
poll.o \
posix_fadvise.o \
diff --git a/usr/src/lib/libc/common/sys/_so_accept.s b/usr/src/lib/libc/common/sys/_so_accept.s
index 75759faaad..ea5abbe5d1 100644
--- a/usr/src/lib/libc/common/sys/_so_accept.s
+++ b/usr/src/lib/libc/common/sys/_so_accept.s
@@ -27,10 +27,15 @@
* Use is subject to license terms.
*/
+/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
+
.file "_so_accept.s"
/* C library -- __so_accept */
-/* int __so_accept(int sock, struct sockaddr *addr, int *addrlen, int vers) */
+/*
+ * int __so_accept(int sock, struct sockaddr *addr, int *addrlen, int vers,
+ * int flags)
+ */
#include "SYS.h"
diff --git a/usr/src/lib/libc/i386/sys/pipe.s b/usr/src/lib/libc/common/sys/pipe2.s
index d17b720124..939fa51f8b 100644
--- a/usr/src/lib/libc/i386/sys/pipe.s
+++ b/usr/src/lib/libc/common/sys/pipe2.s
@@ -18,24 +18,15 @@
*
* CDDL HEADER END
*/
-/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
- .file "pipe.s"
+/* Copyright 2013 OmniTI Computer Consulting, Inc. All rights reserved. */
-#include <sys/asm_linkage.h>
-
- ANSI_PRAGMA_WEAK(pipe,function)
+/* int pipe2 (int *fds, int flags) */
#include "SYS.h"
- ENTRY(pipe)
- SYSTRAP_2RVALS(pipe)
- SYSCERROR
- movl 4(%esp), %ecx
- movl %eax, (%ecx)
- movl %edx, 4(%ecx)
- RETC
- SET_SIZE(pipe)
+ .file "pipe2.s"
+
+ SYSCALL2(pipe2,pipe);
+ RET
+ SET_SIZE(pipe2)
diff --git a/usr/src/lib/libc/i386/Makefile.com b/usr/src/lib/libc/i386/Makefile.com
index 41721e4f3f..d5826d8e45 100644
--- a/usr/src/lib/libc/i386/Makefile.com
+++ b/usr/src/lib/libc/i386/Makefile.com
@@ -20,6 +20,7 @@
#
#
# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
# Copyright (c) 2012, Joyent, Inc. All rights reserved.
#
# Copyright 2011 Nexenta Systems, Inc. All rights reserved.
@@ -245,6 +246,7 @@ COMSYSOBJS= \
pathconf.o \
pause.o \
pcsample.o \
+ pipe2.o \
pollsys.o \
pread.o \
priocntlset.o \
@@ -301,7 +303,6 @@ SYSOBJS= \
gettimeofday.o \
lwp_private.o \
nuname.o \
- pipe.o \
ptrace.o \
syscall.o \
sysi86.o \
@@ -499,6 +500,7 @@ PORTGEN= \
pfmt.o \
pfmt_data.o \
pfmt_print.o \
+ pipe.o \
plock.o \
poll.o \
posix_fadvise.o \
diff --git a/usr/src/lib/libc/port/gen/dup.c b/usr/src/lib/libc/port/gen/dup.c
index 8b5db30b19..4fd562934f 100644
--- a/usr/src/lib/libc/port/gen/dup.c
+++ b/usr/src/lib/libc/port/gen/dup.c
@@ -19,6 +19,8 @@
* CDDL HEADER END
*/
+/* Copyright 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
+
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
@@ -30,6 +32,7 @@
#include "lint.h"
#include <sys/types.h>
#include <fcntl.h>
+#include <errno.h>
#pragma weak _dup = dup
int
@@ -44,3 +47,27 @@ dup2(int fildes, int fildes2)
{
return (fcntl(fildes, F_DUP2FD, fildes2));
}
+
+int
+dup3(int fildes, int fildes2, int flags)
+{
+ /*
+ * The only valid flag is O_CLOEXEC.
+ */
+ if (flags & ~O_CLOEXEC) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ /*
+ * This call differs from dup2 such that it is an error when
+ * fildes == fildes2
+ */
+ if (fildes == fildes2) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ return (fcntl(fildes, (flags == 0) ? F_DUP2FD : F_DUP2FD_CLOEXEC,
+ fildes2));
+}
diff --git a/usr/src/lib/libc/port/gen/mkstemp.c b/usr/src/lib/libc/port/gen/mkstemp.c
index 72c79ac47f..d9de436d13 100644
--- a/usr/src/lib/libc/port/gen/mkstemp.c
+++ b/usr/src/lib/libc/port/gen/mkstemp.c
@@ -19,6 +19,8 @@
* CDDL HEADER END
*/
+/* Copyright (c) 2013 OmniTI Computer Consulting, Inc. All rights reserved. */
+
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
@@ -33,13 +35,13 @@
* California.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <sys/feature_tests.h>
#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
#define mkstemp mkstemp64
#define mkstemps mkstemps64
+#define mkostemp mkostemp64
+#define mkostemps mkostemps64
#define libc_mkstemps libc_mkstemps64 /* prefer unique statics */
#pragma weak _mkstemp64 = mkstemp64
#else
@@ -59,7 +61,7 @@
extern char *libc_mktemps(char *, int);
static int
-libc_mkstemps(char *as, int slen)
+libc_mkstemps(char *as, int slen, int flags)
{
int fd;
int len;
@@ -91,11 +93,13 @@ libc_mkstemps(char *as, int slen)
}
}
#if _FILE_OFFSET_BITS == 64
- if ((fd = open64(as, O_CREAT|O_EXCL|O_RDWR, 0600)) != -1) {
+ if ((fd = open64(as, O_CREAT|O_EXCL|O_RDWR|flags,
+ 0600)) != -1) {
return (fd);
}
#else
- if ((fd = open(as, O_CREAT|O_EXCL|O_RDWR, 0600)) != -1) {
+ if ((fd = open(as, O_CREAT|O_EXCL|O_RDWR|flags,
+ 0600)) != -1) {
return (fd);
}
#endif /* _FILE_OFFSET_BITS == 64 */
@@ -116,11 +120,23 @@ libc_mkstemps(char *as, int slen)
int
mkstemp(char *as)
{
- return (libc_mkstemps(as, 0));
+ return (libc_mkstemps(as, 0, 0));
}
int
mkstemps(char *as, int slen)
{
- return (libc_mkstemps(as, slen));
+ return (libc_mkstemps(as, slen, 0));
+}
+
+int
+mkostemp(char *as, int flags)
+{
+ return (libc_mkstemps(as, 0, flags));
+}
+
+int
+mkostemps(char *as, int slen, int flags)
+{
+ return (libc_mkstemps(as, slen, flags));
}
diff --git a/usr/src/lib/libc/amd64/sys/pipe.s b/usr/src/lib/libc/port/gen/pipe.c
index fd659bea1f..66e16de083 100644
--- a/usr/src/lib/libc/amd64/sys/pipe.s
+++ b/usr/src/lib/libc/port/gen/pipe.c
@@ -18,25 +18,18 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
+ * Copyright 2013 OmniTI Computer Consulting, Inc. All rights reserved.
*/
- .file "pipe.s"
-
-#include <sys/asm_linkage.h>
-
- ANSI_PRAGMA_WEAK(pipe,function)
+#pragma weak _pipe = pipe
-#include "SYS.h"
+#include "lint.h"
+#include <unistd.h>
- ENTRY(pipe)
- pushq %rdi /* preserve the pointer */
- SYSTRAP_2RVALS(pipe)
- popq %rdi
- SYSCERROR
- movl %eax, (%rdi)
- movl %edx, 4(%rdi)
- RETC
- SET_SIZE(pipe)
+int
+pipe(int *fds)
+{
+ return (pipe2(fds, 0));
+}
diff --git a/usr/src/lib/libc/port/llib-lc b/usr/src/lib/libc/port/llib-lc
index 117009a044..1781f34b2b 100644
--- a/usr/src/lib/libc/port/llib-lc
+++ b/usr/src/lib/libc/port/llib-lc
@@ -22,6 +22,7 @@
/*
* Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
+ * Copyright 2013 OmniTI Computer Consulting, Inc. All rights reserved.
*/
/* LINTLIBRARY */
@@ -379,8 +380,10 @@ void lcong48(unsigned short param[7]);
long nrand48(unsigned short *xsubi);
long jrand48(unsigned short *xsubi);
-/* dup2.c */
+/* dup.c */
+int dup(int fildes);
int dup2(int fildes, int fildes2);
+int dup3(int fildes, int fildes2, int flags);
/* ecvt.c */
char *ecvt(double value, int ndigit, int *_RESTRICT_KYWD decpt,
@@ -741,6 +744,9 @@ DIR *opendir(const char *filename);
/* perror.c */
void perror(const char *s);
+/* pipe.c */
+int pipe(int *fds);
+
/* psiginfo.c */
void psiginfo(siginfo_t *sip, char *s);
diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers
index c5587adf3d..469b73e9ca 100644
--- a/usr/src/lib/libc/port/mapfile-vers
+++ b/usr/src/lib/libc/port/mapfile-vers
@@ -26,7 +26,7 @@
#
# Copyright (c) 2012, Joyent, Inc. All rights reserved.
# Copyright (c) 2012 by Delphix. All rights reserved.
-#
+# Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
#
# MAPFILE HEADER START
@@ -91,6 +91,19 @@ $if _x86 && _ELF64
$add amd64
$endif
+SYMBOL_VERSION ILLUMOS_0.4 { # Illumos additions
+ protected:
+ pipe2;
+ dup3;
+ mkostemp;
+ mkostemps;
+
+$if lf64
+ mkostemp64;
+ mkostemps64;
+$endif
+} ILLUMOS_0.3;
+
SYMBOL_VERSION ILLUMOS_0.3 { # Illumos additions
protected:
assfail3;
diff --git a/usr/src/lib/libc/port/threads/scalls.c b/usr/src/lib/libc/port/threads/scalls.c
index afcdb4bcaa..18b6b1c05f 100644
--- a/usr/src/lib/libc/port/threads/scalls.c
+++ b/usr/src/lib/libc/port/threads/scalls.c
@@ -24,6 +24,8 @@
* Use is subject to license terms.
*/
+/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
+
#include "lint.h"
#include "thr_uberdata.h"
#include <stdarg.h>
@@ -1022,12 +1024,13 @@ sigqueue(pid_t pid, int signo, const union sigval value)
}
int
-_so_accept(int sock, struct sockaddr *addr, uint_t *addrlen, int version)
+_so_accept(int sock, struct sockaddr *addr, uint_t *addrlen, int version,
+ int flags)
{
- extern int __so_accept(int, struct sockaddr *, uint_t *, int);
+ extern int __so_accept(int, struct sockaddr *, uint_t *, int, int);
int rv;
- PERFORM(__so_accept(sock, addr, addrlen, version))
+ PERFORM(__so_accept(sock, addr, addrlen, version, flags))
}
int
diff --git a/usr/src/lib/libc/sparc/Makefile.com b/usr/src/lib/libc/sparc/Makefile.com
index 8b27e58b92..4840990414 100644
--- a/usr/src/lib/libc/sparc/Makefile.com
+++ b/usr/src/lib/libc/sparc/Makefile.com
@@ -20,6 +20,7 @@
#
#
# Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
# Copyright (c) 2012, Joyent, Inc. All rights reserved.
#
# Copyright 2011 Nexenta Systems, Inc. All rights reserved.
@@ -266,6 +267,7 @@ COMSYSOBJS= \
pathconf.o \
pause.o \
pcsample.o \
+ pipe2.o \
pollsys.o \
pread.o \
priocntlset.o \
@@ -319,7 +321,6 @@ SYSOBJS= \
forkx.o \
forkallx.o \
gettimeofday.o \
- pipe.o \
ptrace.o \
syscall.o \
tls_get_addr.o \
@@ -532,6 +533,7 @@ PORTGEN= \
pfmt.o \
pfmt_data.o \
pfmt_print.o \
+ pipe.o \
plock.o \
poll.o \
posix_fadvise.o \
diff --git a/usr/src/lib/libc/sparc/sys/pipe.s b/usr/src/lib/libc/sparc/sys/pipe.s
deleted file mode 100644
index d9eadc070c..0000000000
--- a/usr/src/lib/libc/sparc/sys/pipe.s
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/* Copyright (c) 1988 AT&T */
-/* All Rights Reserved */
-
-
-/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
- .ident "%Z%%M% %I% %E% SMI"
-
-/* C library -- pipe */
-/* int pipe (int fildes[2]); */
-
- .file "pipe.s"
-
-#include <sys/asm_linkage.h>
-
- ANSI_PRAGMA_WEAK(pipe,function)
-
-#include "SYS.h"
-
- ENTRY(pipe)
- mov %o0, %o2 /* save ptr to array */
- SYSTRAP_2RVALS(pipe)
- SYSCERROR
- st %o0, [%o2]
- st %o1, [%o2 + 4]
- RETC
-
- SET_SIZE(pipe)
diff --git a/usr/src/lib/libc/sparcv9/Makefile.com b/usr/src/lib/libc/sparcv9/Makefile.com
index fa727d133c..669e06395c 100644
--- a/usr/src/lib/libc/sparcv9/Makefile.com
+++ b/usr/src/lib/libc/sparcv9/Makefile.com
@@ -20,6 +20,7 @@
#
#
# Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
# Copyright (c) 2012, Joyent, Inc. All rights reserved.
#
# Copyright 2011 Nexenta Systems, Inc. All rights reserved.
@@ -251,6 +252,7 @@ COMSYSOBJS= \
pathconf.o \
pause.o \
pcsample.o \
+ pipe2.o \
pollsys.o \
pread.o \
priocntlset.o \
@@ -304,7 +306,6 @@ SYSOBJS= \
forkx.o \
forkallx.o \
gettimeofday.o \
- pipe.o \
sparc_utrap_install.o \
syscall.o \
tls_get_addr.o \
@@ -494,6 +495,7 @@ PORTGEN= \
pfmt.o \
pfmt_data.o \
pfmt_print.o \
+ pipe.o \
plock.o \
poll.o \
posix_fadvise.o \
diff --git a/usr/src/lib/libsocket/common/llib-lsocket b/usr/src/lib/libsocket/common/llib-lsocket
index 104dc78235..3e2bc0a167 100644
--- a/usr/src/lib/libsocket/common/llib-lsocket
+++ b/usr/src/lib/libsocket/common/llib-lsocket
@@ -22,6 +22,7 @@
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
+/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
/* LINTLIBRARY */
/* PROTOLIB1 */
@@ -82,6 +83,7 @@ int __xnet_socketpair(int domain, int type, int protocol, int *sv);
int bind(int s, const struct sockaddr *name, socklen_t namelen);
int listen(int s, int backlog);
int accept(int s, struct sockaddr *addr, Psocklen_t addrlen);
+int accept4(int s, struct sockaddr *addr, Psocklen_t addrlen, int flags);
int connect(int s, const struct sockaddr *name, socklen_t namelen);
int shutdown(int s, int how);
ssize_t recv(int s, void *buf, size_t len, int flags);
@@ -100,6 +102,7 @@ int setsockopt(int s, int level, int optname, const void *optval, socklen_t optl
int _bind(int s, const struct sockaddr *name, int namelen);
int _listen(int s, int backlog);
int _accept(int s, struct sockaddr *addr, int *addrlen);
+int _accept4(int s, struct sockaddr *addr, int *addrlen, int flags);
int _connect(int s, struct sockaddr *name, int namelen);
int _shutdown(int s, int how);
int _recv(int s, char *buf, int len, int flags);
diff --git a/usr/src/lib/libsocket/common/mapfile-vers b/usr/src/lib/libsocket/common/mapfile-vers
index 4ecd9350f2..2f7777f395 100644
--- a/usr/src/lib/libsocket/common/mapfile-vers
+++ b/usr/src/lib/libsocket/common/mapfile-vers
@@ -21,6 +21,7 @@
#
# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
#
+# Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
#
# MAPFILE HEADER START
@@ -38,6 +39,11 @@
$mapfile_version 2
+SYMBOL_VERSION ILLUMOS_0.1 { # Illumos additions
+ global:
+ accept4;
+} SUNW_1.7;
+
SYMBOL_VERSION SUNW_1.7 {
global:
freeifaddrs;
@@ -191,6 +197,7 @@ $endif
SYMBOL_VERSION SUNWprivate_1.3 {
global:
+ _accept4;
_link_aton;
_link_ntoa;
_nss_initf_ethers;
diff --git a/usr/src/lib/libsocket/socket/weaks.c b/usr/src/lib/libsocket/socket/weaks.c
index ffd794647e..51e8d13e06 100644
--- a/usr/src/lib/libsocket/socket/weaks.c
+++ b/usr/src/lib/libsocket/socket/weaks.c
@@ -24,7 +24,7 @@
* Use is subject to license terms.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
+/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
#include <sys/types.h>
#include <sys/socket.h>
@@ -44,6 +44,7 @@
#pragma weak bind = _bind
#pragma weak listen = _listen
#pragma weak accept = _accept
+#pragma weak accept4 = _accept4
#pragma weak connect = _connect
#pragma weak shutdown = _shutdown
#pragma weak recv = _recv
@@ -92,7 +93,13 @@ _listen(int sock, int backlog)
int
_accept(int sock, struct sockaddr *addr, int *addrlen)
{
- return (_so_accept(sock, addr, addrlen, SOV_DEFAULT));
+ return (_so_accept(sock, addr, addrlen, SOV_DEFAULT, 0));
+}
+
+int
+_accept4(int sock, struct sockaddr *addr, int *addrlen, int flags)
+{
+ return (_so_accept(sock, addr, addrlen, SOV_DEFAULT, flags));
}
int
diff --git a/usr/src/man/man2/Makefile b/usr/src/man/man2/Makefile
index 449177c4df..8e93920613 100644
--- a/usr/src/man/man2/Makefile
+++ b/usr/src/man/man2/Makefile
@@ -10,6 +10,7 @@
#
# Copyright 2011, Richard Lowe
+# Copyright 2013, OmniTI Computer Consulting, Inc
include ../../Makefile.master
@@ -207,6 +208,7 @@ MANSOFILES = _Exit.2 \
lstat.2 \
openat.2 \
pathconf.2 \
+ pipe2.2 \
pread.2 \
pset_assign.2 \
pset_destroy.2 \
@@ -328,6 +330,8 @@ setustack.2 := SOSRC = man2/getustack.2
openat.2 := SOSRC = man2/open.2
+pipe2.2 := SOSRC = man2/pipe.2
+
pset_assign.2 := SOSRC = man2/pset_create.2
pset_destroy.2 := SOSRC = man2/pset_create.2
diff --git a/usr/src/man/man2/fcntl.2 b/usr/src/man/man2/fcntl.2
index 637a62ebf1..c7d769f874 100644
--- a/usr/src/man/man2/fcntl.2
+++ b/usr/src/man/man2/fcntl.2
@@ -1,4 +1,5 @@
'\" te
+.\" Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
.\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright 1989 AT&T
.\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
@@ -9,7 +10,7 @@
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
-.TH FCNTL 2 "Jan 17, 2007"
+.TH FCNTL 2 "Apr 19, 2013"
.SH NAME
fcntl \- file control
.SH SYNOPSIS
@@ -64,6 +65,27 @@ equivalent to \fBdup2\fR(\fIfildes\fR, \fIarg\fR).
.sp
.ne 2
.na
+\fB\fBF_DUPFD_CLOEXEC\fR\fR
+.ad
+.RS 15n
+Similar to \fBF_DUPFD\fR except that instead of clearing \fBFD_CLOEXEC\fR
+it is explicitly set on the returned file descriptor.
+.RE
+
+.sp
+.ne 2
+.na
+\fB\fBF_DUP2FD_CLOEXEC\fR\fR
+.ad
+.RS 15n
+Similar to \fBF_DUP2FD\fR with two exceptions. The \fBFD_CLOEXEC\fR flag is
+explicitly set on the returned file descriptor. If \fIfiledes\fR equals
+\fIarg\fR, the call will fail setting \fBerrno\fR to \fBEINVAL\fR.
+.RE
+
+.sp
+.ne 2
+.na
\fB\fBF_FREESP\fR\fR
.ad
.RS 15n
@@ -762,6 +784,9 @@ or equal to \fBOPEN_MAX\fR; or the \fIcmd\fR argument is \fBF_GETLK\fR,
.sp
The \fIcmd\fR argument is \fBF_UNSHARE\fR and a reservation with this
\fBf_id\fR for this process does not exist.
+.sp
+The \fIcmd\fR argument is \fBF_DUP2FD_CLOEXEC\fR and \fIfildes\fR is equal
+to \fBarg\fR.
.RE
.sp
diff --git a/usr/src/man/man2/pipe.2 b/usr/src/man/man2/pipe.2
index c2e8d94e24..88b625bf52 100644
--- a/usr/src/man/man2/pipe.2
+++ b/usr/src/man/man2/pipe.2
@@ -2,6 +2,7 @@
.\" Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright 1989 AT&T
.\" Portions Copyright (c) 2001, the Institute of Electrical and Electronics Engineers, Inc. and The Open Group. All Rights Reserved.
+.\" Portions Copyright (c) 2013, OmniTI Computer Consulting, Inc. All Rights Reserved
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
.\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
@@ -9,7 +10,7 @@
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
-.TH PIPE 2 "Apr 23, 2002"
+.TH PIPE 2 "Apr 19, 2013"
.SH NAME
pipe \- create an interprocess channel
.SH SYNOPSIS
@@ -18,17 +19,50 @@ pipe \- create an interprocess channel
#include <unistd.h>
\fBint\fR \fBpipe\fR(\fBint\fR \fIfildes\fR[2]);
+
+\fBint\fR \fBpipe2\fR(\fBint\fR \fIfildes\fR[2], \fBint\fR \fIflags\fR);
.fi
.SH DESCRIPTION
.sp
.LP
-The \fBpipe()\fR function creates an I/O mechanism called a pipe and returns
-two file descriptors, \fIfildes\fR[\fB0\fR] and \fIfildes\fR[\fB1\fR]. The
-files associated with \fIfildes\fR[\fB0\fR] and \fIfildes\fR[\fB1\fR] are
-streams and are both opened for reading and writing. The \fBO_NDELAY\fR,
-\fBO_NONBLOCK\fR, and \fBFD_CLOEXEC\fR flags are cleared on both file
-descriptors. The \fBfcntl\fR(2) function can be used to set these flags.
+The \fBpipe()\fR and pipe2() functions create an I/O mechanism called a
+pipe and returns two file descriptors, \fIfildes\fR[\fB0\fR] and
+\fIfildes\fR[\fB1\fR]. The files associated with \fIfildes\fR[\fB0\fR]
+and \fIfildes\fR[\fB1\fR] are streams and are both opened for reading and
+writing. The \fBpipe()\fR call will clear the \fBO_NDELAY\fR,
+\fBO_NONBLOCK\fR, and \fBFD_CLOEXEC\fR flags on both file descriptors. The
+\fBfcntl\fR(2) function can be used to set these flags.
+.sp
+.LP
+The \fBpipe2()\fR call will clear the \fBO_NDELAY\fR on both filedescriptors.
+The \fIflags\fR argument may be used to specify attributes on both file
+descriptors. \fBpipe2()\fR called with a \fIflags\fR value of 0 will
+behave identically to \fBpipe()\fR. Values for \fIflags\fR are constructed
+by a bitwise-inclusive-OR of flags from the following list, defined in
+<\fBfcntl.h\fR>.
+.RE
+
+.sp
+.ne 2
+.na
+\fB\fBO_NONBLOCK\fR\fR
+.ad
+.RS 12n
+Both file descriptors will be placed in non-blocking mode. This corresponds
+to the \fBO_NONBLOCK\fR flag to \fBfcntl\fR(2).
+.RE
+
+.sp
+.ne 2
+.na
+\fB\fBO_CLOEXEC\fR\fR
+.ad
+.RS 12n
+Both file descriptors will be opened with the FD_CLOEXEC flag set. Both file
+descriptors will be closed prior to any future exec() calls.
+.RE
+
.sp
.LP
A read from \fIfildes\fR[\fB0\fR] accesses the data written to
@@ -47,7 +81,7 @@ returned and \fBerrno\fR is set to indicate the error.
.SH ERRORS
.sp
.LP
-The \fBpipe()\fR function will fail if:
+The \fBpipe()\fR and \fBpipe2()\fR functions will fail if:
.sp
.ne 2
.na
@@ -67,6 +101,29 @@ The number of simultaneously open files in the system would exceed a
system-imposed limit.
.RE
+.sp
+.ne 2
+.na
+\fB\fBEFAULT\fR\fR
+.ad
+.RS 10n
+The \fIfildes[2]\fR argument points to an illegal address.
+.RE
+
+.sp
+.LP
+The \fBpipe2()\fR function will also fail if:
+.sp
+.ne 2
+.na
+\fB\fBEINVAL\fR\fR
+.ad
+.RS 10n
+The \fIflags\fR argument is illegal. Valid \fIflags\fR are zero or a
+bitwise inclusive-OR of \fBO_CLOEXEC\fR and \fBO_NONBLOCK\fR.
+.RE
+
+
.SH ATTRIBUTES
.sp
.LP
@@ -89,8 +146,8 @@ MT-Level Async-Signal-Safe
.sp
.LP
\fBsh\fR(1), \fBfcntl\fR(2), \fBfstat\fR(2), \fBgetmsg\fR(2), \fBpoll\fR(2),
-\fBputmsg\fR(2), \fBread\fR(2), \fBwrite\fR(2), \fBattributes\fR(5),
-\fBstandards\fR(5), \fBstreamio\fR(7I)
+\fBputmsg\fR(2), \fBread\fR(2), \fBwrite\fR(2), \fBopen\fR(2),
+\fBattributes\fR(5), \fBstandards\fR(5), \fBstreamio\fR(7I)
.SH NOTES
.sp
.LP
diff --git a/usr/src/man/man3c/Makefile b/usr/src/man/man3c/Makefile
index ed669e9a40..ae5b8542bd 100644
--- a/usr/src/man/man3c/Makefile
+++ b/usr/src/man/man3c/Makefile
@@ -10,6 +10,7 @@
#
# Copyright 2011, Richard Lowe
+# Copyright 2013, OmniTI Computer Consulting, Inc. All rights reserved.
include ../../Makefile.master
@@ -671,6 +672,7 @@ MANSOFILES = FD_CLR.3c \
csetno.3c \
ctermid_r.3c \
ctime_r.3c \
+ dup3.3c \
dbm_clearerr.3c \
dbm_close.3c \
dbm_delete.3c \
@@ -848,6 +850,8 @@ MANSOFILES = FD_CLR.3c \
memset.3c \
minor.3c \
mkdtemp.3c \
+ mkostemp.3c \
+ mkostemps.3c \
mkstemps.3c \
mq_reltimedreceive_np.3c \
mq_reltimedsend_np.3c \
@@ -1651,6 +1655,8 @@ memset.3c := SOSRC = man3c/memory.3c
mkdtemp.3c := SOSRC = man3c/mkstemp.3c
mkstemps.3c := SOSRC = man3c/mkstemp.3c
+mkostemp.3c := SOSRC = man3c/mkstemp.3c
+mkostemps.3c := SOSRC = man3c/mkstemp.3c
munlock.3c := SOSRC = man3c/mlock.3c
@@ -1678,6 +1684,8 @@ dbm_nextkey.3c := SOSRC = man3c/ndbm.3c
dbm_open.3c := SOSRC = man3c/ndbm.3c
dbm_store.3c := SOSRC = man3c/ndbm.3c
+dup3.3c := SOSRC = man3c/dup2.3c
+
fdopendir.3c := SOSRC = man3c/opendir.3c
errno.3c := SOSRC = man3c/perror.3c
diff --git a/usr/src/man/man3c/dup2.3c b/usr/src/man/man3c/dup2.3c
index eb19b74ff5..a2742a732f 100644
--- a/usr/src/man/man3c/dup2.3c
+++ b/usr/src/man/man3c/dup2.3c
@@ -1,12 +1,13 @@
'\" te
+.\" Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
.\" Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright 1989 AT&T
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
-.TH DUP2 3C "Dec 19, 2003"
+.TH DUP2 3C "Apr 19, 2013"
.SH NAME
-dup2 \- duplicate an open file descriptor
+dup2, dup3 \- duplicate an open file descriptor
.SH SYNOPSIS
.LP
.nf
@@ -15,6 +16,11 @@ dup2 \- duplicate an open file descriptor
\fBint\fR \fBdup2\fR(\fBint\fR \fIfildes\fR, \fBint\fR \fIfildes2\fR);
.fi
+.LP
+.nf
+\fBint\fR \fBdup3\fR(\fBint\fR \fIfildes\fR, \fBint\fR \fIfildes2\fR, \dBint\fR \fIflags\fR);
+.fi
+
.SH DESCRIPTION
.sp
.LP
@@ -30,6 +36,14 @@ to \fIfildes\fR, or if \fIfildes\fR is not a valid open file descriptor,
.LP
The \fBdup2()\fR function is equivalent to \fBfcntl\fR(\fIfildes\fR,
\fBF_DUP2FD\fR, \fIfildes2\fR).
+.sp
+.LP
+Ths \fBdup3()\fR function works similarly to the \fBdup2()\fR function with
+two exceptions. If \fIfildes\fR and \fIfildes2\fR point to the same file
+descriptor, -1 is returned and errno set to \fBEINVAL\fR. If \fIflags\fR
+is \fBO_CLOEXEC\fR, then \fIfiledes2\fB will have the \fBFD_CLOEXEC\fR flag
+set causing the file descriptor to be closed during any future call of
+\fBexec\fR(2).
.SH RETURN VALUES
.sp
.LP
@@ -39,7 +53,7 @@ set to indicate the error.
.SH ERRORS
.sp
.LP
-The \fBdup2()\fR function will fail if:
+The \fBdup2()\fR and \fBdup3()\fR functions will fail if:
.sp
.ne 2
.na
@@ -77,6 +91,18 @@ A signal was caught during the \fBdup2()\fR call.
The process has too many open files. See \fBfcntl\fR(2).
.RE
+.sp
+.LP
+Additionally, the \fBdup3()\fR function will fail if:
+.sp
+.ne 2
+.na
+\fB\fBEINVAL\fR\fR
+.ad
+.RS 10n
+\fIflags\fR has a value other than 0 or \fBO_CLOEXEC\fR or \fIfildes\fR and \fIfildes2\fB point to the same file descriptor.
+.RE
+
.SH ATTRIBUTES
.sp
.LP
diff --git a/usr/src/man/man3c/mkstemp.3c b/usr/src/man/man3c/mkstemp.3c
index 697cba2a2e..4d7f4c572e 100644
--- a/usr/src/man/man3c/mkstemp.3c
+++ b/usr/src/man/man3c/mkstemp.3c
@@ -1,4 +1,5 @@
'\" te
+.\" Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
.\" Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. Portions Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved.
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
@@ -7,9 +8,9 @@
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
-.TH MKSTEMP 3C "Feb 22, 2006"
+.TH MKSTEMP 3C "Apr 19, 2013"
.SH NAME
-mkstemp, mkstemps, mkdtemp \- make a unique file name from a template and open
+mkstemp, mkstemps, mkostemp, mkostemps, mkdtemp \- make a unique file name from a template and open
the file
.SH SYNOPSIS
.LP
@@ -21,11 +22,21 @@ the file
.LP
.nf
+\fBint\fR \fBmkostemp\fR(\fBchar *\fR\fItemplate\fR, \fBint\fR \fIflags\fR);
+.fi
+
+.LP
+.nf
\fBint\fR \fBmkstemps\fR(\fBchar *\fR\fItemplate\fR, \fBint\fR \fIslen\fR);
.fi
.LP
.nf
+\fBint\fR \fBmkostemps\fR(\fBchar *\fR\fItemplate\fR, \fBint\fR \fIslen\fR, \fBint\fR \fIflags\fR);
+.fi
+
+.LP
+.nf
\fBchar *\fR\fBmkdtemp\fR(\fBchar *\fR\fItemplate\fR);
.fi
@@ -48,6 +59,12 @@ permits a suffix to exist in the template. The template should be of the form
specifies the length of the suffix string.
.sp
.LP
+The \fBmkostemp()\fR and \fBmkostemps\fR are like their \fBmkstemp()\fR and
+\fBmkstemps()\fR couterparts except that the \fIflags\fR argument is present
+and used to supplement (as a bitwise inclusive-OR) flags to internal
+\fBopen()\fR calls. (e.g. \fBO_SYNC\fR, \fBO_APPEND\fR, and \fBO_CLOEXEC\fR).
+.sp
+.LP
The \fBmkdtemp()\fR function makes the same replacement to the template as in
\fBmktemp\fR(3C) and creates the template directory using \fBmkdir\fR(2),
passing a \fImode\fR argument of 0700.
diff --git a/usr/src/man/man3socket/Makefile b/usr/src/man/man3socket/Makefile
index 3ac8e626cf..77d818b6cc 100644
--- a/usr/src/man/man3socket/Makefile
+++ b/usr/src/man/man3socket/Makefile
@@ -10,6 +10,7 @@
#
# Copyright 2011, Richard Lowe
+# Copyright 2013, OmniTI Computer Consulting, Inc.
include ../../Makefile.master
@@ -53,7 +54,8 @@ MANFILES = accept.3socket \
socketpair.3socket \
spray.3socket
-MANSOFILES = endnetent.3socket \
+MANSOFILES = accept4.3socket \
+ endnetent.3socket \
endprotoent.3socket \
endservent.3socket \
ether_aton.3socket \
@@ -135,6 +137,8 @@ MANSOFILES = endnetent.3socket \
MANFILES += $(MANSOFILES)
+accept4.3socket := SOSRC = man3socket/accept.3socket
+
htonl.3socket := SOSRC = man3socket/byteorder.3socket
htonll.3socket := SOSRC = man3socket/byteorder.3socket
htons.3socket := SOSRC = man3socket/byteorder.3socket
diff --git a/usr/src/man/man3socket/accept.3socket b/usr/src/man/man3socket/accept.3socket
index e9ff5df69c..c6afea7625 100644
--- a/usr/src/man/man3socket/accept.3socket
+++ b/usr/src/man/man3socket/accept.3socket
@@ -1,10 +1,11 @@
'\" te
.\" Copyright 1989 AT&T
.\" Copyright (C) 2002, Sun Microsystems, Inc. All Rights Reserved
+.\" Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
-.TH ACCEPT 3SOCKET "Jan 24, 2002"
+.TH ACCEPT 3SOCKET "Apr 19, 2013"
.SH NAME
accept \- accept a connection on a socket
.SH SYNOPSIS
@@ -15,6 +16,9 @@ accept \- accept a connection on a socket
#include <sys/socket.h>
\fBint\fR \fBaccept\fR(\fBint\fR \fIs\fR, \fBstruct sockaddr *\fR\fIaddr\fR, \fBsocklen_t *\fR\fIaddrlen\fR);
+
+\fBint\fR \fBaccept4\fR(\fBint\fR \fIs\fR, \fBstruct sockaddr *\fR\fIaddr\fR, \fBsocklen_t *\fR\fIaddrlen\fR,
+ \fBint\fR \fIflags\fR);
.fi
.SH DESCRIPTION
@@ -53,6 +57,47 @@ The \fBaccept()\fR function is used with connection-based socket types,
currently with \fBSOCK_STREAM\fR.
.sp
.LP
+The \fBaccept4()\fR function allows flags that control the behavior of a
+successfully accepted socket. If \fIflags\fR is 0, \fBaccept4()\fR acts
+identically to \fBaccept()\fR. Values for \fIflags\fR are constructed by
+a bitwise-inclusive-OR of flags from the following list, defined in
+<sys/socketvar.h>.
+.sp
+.ne 2
+.na
+\fB\fBSOCK_CLOEXEC\fR\fR
+.ad
+.RS 12n
+The accepted socket will have the FD_CLOEXEC flag set as if \fBfcntl()\fR
+was called on it. This flag is set before the socket is passed to the
+caller thus avoiding the race condition between \fBaccept()\fR and
+\fBfcntl()\fR. See, \fBO_CLOEXEC\fR in \fBopen(2)\fR for more details.
+.RE
+
+.sp
+.ne 2
+.na
+\fB\fBSOCK_NDELAY\fR\fR
+.ad
+.RS 12n
+The accepted socket will have the \fBO_NDELAY\fR flag set as if \fBfcntl()\fR
+was called on it. This sets the socket into non-blocking mode. See
+\fBO_NDELAY\fR in \fBfcntl.h(3HEAD)\fR for more details.
+.RE
+
+.sp
+.ne 2
+.na
+\fB\fBSOCK_NONBLOCK\fR\fR
+.ad
+.RS 12n
+The accepted socket will have the \fBO_NONBLOCK\fR flag set as if
+\fBfcntl()\fR was called on it. This sets the socket into non-blocking mode
+(POSIX; see \fBstandards(5)\fR). See \fBO_NONBLOCK\fR in \fBfcntl.h(3HEAD)\fR
+for more details.
+.RE
+.sp
+.LP
It is possible to \fBselect\fR(3C) or \fBpoll\fR(2) a socket for the purpose of
an \fBaccept()\fR by selecting or polling it for a read. However, this will
only indicate when a connect indication is pending; it is still necessary to
@@ -65,7 +110,7 @@ returns a non-negative integer that is a descriptor for the accepted socket.
.SH ERRORS
.sp
.LP
-\fBaccept()\fR will fail if:
+\fBaccept()\fR and \fBaccept4()\fR will fail if:
.sp
.ne 2
.na
@@ -179,6 +224,20 @@ The socket is marked as non-blocking and no connections are present to be
accepted.
.RE
+.sp
+.LP
+\fBAdditionally, \fBaccept4()\fR will fail if:
+.sp
+.ne 2
+.na
+\fB\fBEINVAL\fR\fR
+.ad
+.RS 16n
+The \fIflags\fR value is invalid. The \fIflags\fR argument can only be the
+bitwise inclusive-OR of \fBSOCK_CLOEXEC\fR, \fBSOCK_NONBLOCK\fR, and
+\fBSOCK_NDELAY\fR.
+.RE
+
.SH ATTRIBUTES
.sp
.LP
@@ -200,4 +259,5 @@ MT-Level Safe
.LP
\fBpoll\fR(2), \fBbind\fR(3SOCKET), \fBconnect\fR(3SOCKET),
\fBlisten\fR(3SOCKET), \fBselect\fR(3C), \fBsocket.h\fR(3HEAD),
-\fBsocket\fR(3SOCKET), \fBnetconfig\fR(4), \fBattributes\fR(5)
+\fBsocket\fR(3SOCKET), \fBnetconfig\fR(4), \fBattributes\fR(5),
+\fBfcntl.h(3HEAD)\fR, \fBfcntl(2)\fR, \fBstandards(5)\fR
diff --git a/usr/src/pkg/manifests/system-kernel.man2.inc b/usr/src/pkg/manifests/system-kernel.man2.inc
index a5028ab67a..53928ed071 100644
--- a/usr/src/pkg/manifests/system-kernel.man2.inc
+++ b/usr/src/pkg/manifests/system-kernel.man2.inc
@@ -10,6 +10,7 @@
#
# Copyright 2011, Richard Lowe
+# Copyright 2013, OmniTI Computer Consulting, Inc.
file path=usr/share/man/man2/Intro.2
file path=usr/share/man/man2/_Exit.2
@@ -137,6 +138,7 @@ file path=usr/share/man/man2/pathconf.2
file path=usr/share/man/man2/pause.2
file path=usr/share/man/man2/pcsample.2
file path=usr/share/man/man2/pipe.2
+file path=usr/share/man/man2/pipe2.2
file path=usr/share/man/man2/poll.2
file path=usr/share/man/man2/pread.2
file path=usr/share/man/man2/priocntl.2
diff --git a/usr/src/pkg/manifests/system-library.man3c.inc b/usr/src/pkg/manifests/system-library.man3c.inc
index 57c67eef9f..4f8e3aca51 100644
--- a/usr/src/pkg/manifests/system-library.man3c.inc
+++ b/usr/src/pkg/manifests/system-library.man3c.inc
@@ -12,6 +12,7 @@
#
# Copyright 2011, Richard Lowe
# Copyright 2011 Nexenta Systems, Inc. All rights reserved.
+# Copyright 2013 OmniTI Computer Consulting, Inc. All rights reserved.
#
file path=usr/share/man/man3c/FD_CLR.3c
@@ -282,6 +283,7 @@ file path=usr/share/man/man3c/door_unbind.3c
file path=usr/share/man/man3c/double_to_decimal.3c
file path=usr/share/man/man3c/drand48.3c
file path=usr/share/man/man3c/dup2.3c
+file path=usr/share/man/man3c/dup3.3c
file path=usr/share/man/man3c/econvert.3c
file path=usr/share/man/man3c/ecvt.3c
file path=usr/share/man/man3c/edata.3c
@@ -555,6 +557,8 @@ file path=usr/share/man/man3c/memset.3c
file path=usr/share/man/man3c/minor.3c
file path=usr/share/man/man3c/mkdtemp.3c
file path=usr/share/man/man3c/mkfifo.3c
+file path=usr/share/man/man3c/mkostemp.3c
+file path=usr/share/man/man3c/mkostemps.3c
file path=usr/share/man/man3c/mkstemp.3c
file path=usr/share/man/man3c/mkstemps.3c
file path=usr/share/man/man3c/mktemp.3c
diff --git a/usr/src/pkg/manifests/system-library.man3socket.inc b/usr/src/pkg/manifests/system-library.man3socket.inc
index 915eb9fa38..afdb8b4bab 100644
--- a/usr/src/pkg/manifests/system-library.man3socket.inc
+++ b/usr/src/pkg/manifests/system-library.man3socket.inc
@@ -10,8 +10,10 @@
#
# Copyright 2011, Richard Lowe
+# Copyright 2013, OmniTI Computer Consulting, Inc.
file path=usr/share/man/man3socket/accept.3socket
+file path=usr/share/man/man3socket/accept4.3socket
file path=usr/share/man/man3socket/bind.3socket
file path=usr/share/man/man3socket/byteorder.3socket
file path=usr/share/man/man3socket/connect.3socket
diff --git a/usr/src/uts/common/fs/sockfs/socksyscalls.c b/usr/src/uts/common/fs/sockfs/socksyscalls.c
index d4f36470e7..078b32fa76 100644
--- a/usr/src/uts/common/fs/sockfs/socksyscalls.c
+++ b/usr/src/uts/common/fs/sockfs/socksyscalls.c
@@ -338,6 +338,7 @@ so_socketpair(int sv[2])
int svs[2];
struct sonode *so1, *so2;
int error;
+ int orig_flags;
struct sockaddr_ux *name;
size_t namelen;
sotpi_info_t *sti1;
@@ -494,13 +495,23 @@ so_socketpair(int sv[2])
releasef(svs[0]);
releasef(svs[1]);
- svs[0] = nfd;
+
+ /*
+ * If FD_CLOEXEC was set on the filedescriptor we're
+ * swapping out, we should set it on the new one too.
+ */
+ VERIFY(f_getfd_error(svs[0], &orig_flags) == 0);
+ if (orig_flags & FD_CLOEXEC) {
+ f_setfd(nfd, FD_CLOEXEC);
+ }
/*
* The socketpair library routine will close the original
* svs[0] when this code passes out a different file
* descriptor.
*/
+ svs[0] = nfd;
+
if (copyout(svs, sv, sizeof (svs))) {
(void) closeandsetf(nfd, NULL);
eprintline(EFAULT);
@@ -586,9 +597,10 @@ listen(int sock, int backlog, int version)
return (0);
}
-/*ARGSUSED3*/
+/*ARGSUSED4*/
int
-accept(int sock, struct sockaddr *name, socklen_t *namelenp, int version)
+accept(int sock, struct sockaddr *name, socklen_t *namelenp, int version,
+ int flags)
{
struct sonode *so;
file_t *fp;
@@ -598,12 +610,24 @@ accept(int sock, struct sockaddr *name, socklen_t *namelenp, int version)
struct vnode *nvp;
struct file *nfp;
int nfd;
+ int ssflags;
struct sockaddr *addrp;
socklen_t addrlen;
dprint(1, ("accept(%d, %p, %p)\n",
sock, (void *)name, (void *)namelenp));
+ if (flags & ~(SOCK_CLOEXEC|SOCK_NONBLOCK|SOCK_NDELAY)) {
+ return (set_errno(EINVAL));
+ }
+
+ /* Translate SOCK_ flags to their SS_ variant */
+ ssflags = 0;
+ if (flags & SOCK_NONBLOCK)
+ ssflags |= SS_NONBLOCK;
+ if (flags & SOCK_NDELAY)
+ ssflags |= SS_NDELAY;
+
if ((so = getsonode(sock, &error, &fp)) == NULL)
return (set_errno(error));
@@ -682,15 +706,23 @@ accept(int sock, struct sockaddr *name, socklen_t *namelenp, int version)
setf(nfd, nfp);
/*
+ * Act on SOCK_CLOEXEC from flags
+ */
+ if (flags & SOCK_CLOEXEC) {
+ f_setfd(nfd, FD_CLOEXEC);
+ }
+
+ /*
* Copy FNDELAY and FNONBLOCK from listener to acceptor
+ * and from ssflags
*/
- if (so->so_state & (SS_NDELAY|SS_NONBLOCK)) {
+ if ((ssflags | so->so_state) & (SS_NDELAY|SS_NONBLOCK)) {
uint_t oflag = nfp->f_flag;
int arg = 0;
- if (so->so_state & SS_NONBLOCK)
+ if ((ssflags | so->so_state) & SS_NONBLOCK)
arg |= FNONBLOCK;
- else if (so->so_state & SS_NDELAY)
+ else if ((ssflags | so->so_state) & SS_NDELAY)
arg |= FNDELAY;
/*
diff --git a/usr/src/uts/common/os/sysent.c b/usr/src/uts/common/os/sysent.c
index a79b101796..48ae2ed349 100644
--- a/usr/src/uts/common/os/sysent.c
+++ b/usr/src/uts/common/os/sysent.c
@@ -24,6 +24,7 @@
/*
* Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2012 Milan Jurik. All rights reserved.
+ * Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
@@ -742,7 +743,7 @@ struct sysent sysent[NSYSCALL] =
/* 231 */ SYSENT_CI("so_socketpair", so_socketpair, 1),
/* 232 */ SYSENT_CI("bind", bind, 4),
/* 233 */ SYSENT_CI("listen", listen, 3),
- /* 234 */ SYSENT_CI("accept", accept, 4),
+ /* 234 */ SYSENT_CI("accept", accept, 5),
/* 235 */ SYSENT_CI("connect", connect, 4),
/* 236 */ SYSENT_CI("shutdown", shutdown, 3),
/* 237 */ SYSENT_CL("recv", recv, 4),
@@ -1073,7 +1074,7 @@ struct sysent sysent32[NSYSCALL] =
/* 231 */ SYSENT_CI("so_socketpair", so_socketpair, 1),
/* 232 */ SYSENT_CI("bind", bind, 4),
/* 233 */ SYSENT_CI("listen", listen, 3),
- /* 234 */ SYSENT_CI("accept", accept, 4),
+ /* 234 */ SYSENT_CI("accept", accept, 5),
/* 235 */ SYSENT_CI("connect", connect, 4),
/* 236 */ SYSENT_CI("shutdown", shutdown, 3),
/* 237 */ SYSENT_CI("recv", recv32, 4),
diff --git a/usr/src/uts/common/sys/fcntl.h b/usr/src/uts/common/sys/fcntl.h
index f3ca84fff1..aa74cab8b5 100644
--- a/usr/src/uts/common/sys/fcntl.h
+++ b/usr/src/uts/common/sys/fcntl.h
@@ -120,6 +120,9 @@ extern "C" {
#define F_CHKFL 8 /* Unused */
#define F_DUP2FD 9 /* Duplicate fildes at third arg */
+#define F_DUP2FD_CLOEXEC 36 /* Like F_DUP2FD with O_CLOEXEC set */
+ /* EINVAL is fildes matches arg1 */
+#define F_DUPFD_CLOEXEC 37 /* Like F_DUPFD with O_CLOEXEC set */
#define F_ISSTREAM 13 /* Is the file desc. a stream ? */
#define F_PRIV 15 /* Turn on private access to file */
diff --git a/usr/src/uts/common/sys/socket.h b/usr/src/uts/common/sys/socket.h
index 0b91740d3a..2733c50faa 100644
--- a/usr/src/uts/common/sys/socket.h
+++ b/usr/src/uts/common/sys/socket.h
@@ -106,9 +106,11 @@ typedef void *_RESTRICT_KYWD Psocklen_t;
#define SOCK_TYPE_MASK 0xffff /* type reside in these bits only */
/*
- * Flags for socket()
+ * Flags for socket() and accept4()
*/
-#define SOCK_CLOEXEC 0x80000 /* like open(2) O_CLOEXEC for socket */
+#define SOCK_CLOEXEC 0x080000 /* like open(2) O_CLOEXEC for socket */
+#define SOCK_NONBLOCK 0x100000 /* like O_NONBLOCK */
+#define SOCK_NDELAY 0x200000 /* like O_NDELAY */
/*
* Option flags per-socket.
@@ -522,6 +524,7 @@ struct cmsghdr {
#if !defined(_KERNEL) || defined(_BOOT)
#ifdef __STDC__
extern int accept(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
+extern int accept4(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t, int);
extern int bind(int, const struct sockaddr *, socklen_t);
extern int connect(int, const struct sockaddr *, socklen_t);
extern int getpeername(int, struct sockaddr *_RESTRICT_KYWD, Psocklen_t);
@@ -546,6 +549,7 @@ extern int sockatmark(int);
#endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
#else /* __STDC__ */
extern int accept();
+extern int accept4();
extern int bind();
extern int connect();
extern int getpeername();
diff --git a/usr/src/uts/common/syscall/fcntl.c b/usr/src/uts/common/syscall/fcntl.c
index 4a6e58f6b0..43a50d6d58 100644
--- a/usr/src/uts/common/syscall/fcntl.c
+++ b/usr/src/uts/common/syscall/fcntl.c
@@ -22,6 +22,7 @@
/* ONC_PLUS EXTRACT START */
/*
* Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
@@ -32,6 +33,7 @@
* under license from the Regents of the University of California.
*/
+
/* ONC_PLUS EXTRACT END */
#include <sys/param.h>
@@ -151,6 +153,7 @@ fcntl(int fdes, int cmd, intptr_t arg)
/* ONC_PLUS EXTRACT END */
case F_DUPFD:
+ case F_DUPFD_CLOEXEC:
p = curproc;
if ((uint_t)iarg >= p->p_fno_ctl) {
if (iarg >= 0)
@@ -178,9 +181,21 @@ fcntl(int fdes, int cmd, intptr_t arg)
fp->f_count--;
mutex_exit(&fp->f_tlock);
error = EMFILE;
+ } else {
+ if (cmd == F_DUPFD_CLOEXEC) {
+ f_setfd(retval, FD_CLOEXEC);
+ }
}
goto done;
+ case F_DUP2FD_CLOEXEC:
+ if (fdes == iarg) {
+ error = EINVAL;
+ goto done;
+ }
+
+ /* lint -fallthrough */
+
case F_DUP2FD:
p = curproc;
if (fdes == iarg) {
@@ -208,6 +223,9 @@ fcntl(int fdes, int cmd, intptr_t arg)
mutex_exit(&fp->f_tlock);
releasef(fdes);
if ((error = closeandsetf(iarg, fp)) == 0) {
+ if (cmd == F_DUP2FD_CLOEXEC) {
+ f_setfd(iarg, FD_CLOEXEC);
+ }
retval = iarg;
} else {
mutex_enter(&fp->f_tlock);
diff --git a/usr/src/uts/common/syscall/pipe.c b/usr/src/uts/common/syscall/pipe.c
index a626b2364a..1b9ea4f6db 100644
--- a/usr/src/uts/common/syscall/pipe.c
+++ b/usr/src/uts/common/syscall/pipe.c
@@ -19,6 +19,7 @@
* CDDL HEADER END
*/
/*
+ * Copyright 2013 OmniTI Computer Consulting, Inc. All rights reserved.
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright (c) 2011 Bayard G. Bell. All rights reserved.
@@ -41,6 +42,7 @@
#include <sys/errno.h>
#include <sys/debug.h>
#include <sys/fs/fifonode.h>
+#include <sys/fcntl.h>
/*
* This is the loadable module wrapper.
@@ -48,11 +50,11 @@
#include <sys/modctl.h>
#include <sys/syscall.h>
-longlong_t pipe();
+int pipe(intptr_t fds, int);
static struct sysent pipe_sysent = {
- 0,
- SE_32RVAL1 | SE_32RVAL2 | SE_NOUNLOAD | SE_ARGC,
+ 2,
+ SE_ARGC | SE_32RVAL1 | SE_NOUNLOAD,
(int (*)())pipe
};
@@ -102,16 +104,22 @@ _info(struct modinfo *modinfop)
* each end of the pipe with a vnode, a file descriptor and
* one of the streams.
*/
-longlong_t
-pipe()
+int
+pipe(intptr_t arg, int flags)
{
vnode_t *vp1, *vp2;
struct file *fp1, *fp2;
int error = 0;
+ int flag1, flag2, iflags;
int fd1, fd2;
- rval_t r;
/*
+ * Validate allowed flags.
+ */
+ if (flags & ~(FCLOEXEC|FNONBLOCK) != 0) {
+ return (set_errno(EINVAL));
+ }
+ /*
* Allocate and initialize two vnodes.
*/
makepipe(&vp1, &vp2);
@@ -124,7 +132,7 @@ pipe()
if (error = falloc(vp1, FWRITE|FREAD, &fp1, &fd1)) {
VN_RELE(vp1);
VN_RELE(vp2);
- return ((longlong_t)set_errno(error));
+ return (set_errno(error));
}
if (error = falloc(vp2, FWRITE|FREAD, &fp2, &fd2))
@@ -147,6 +155,36 @@ pipe()
VTOF(vp1)->fn_ino = VTOF(vp2)->fn_ino = fifogetid();
/*
+ * Set the O_NONBLOCK flag if requested.
+ */
+ if (flags & FNONBLOCK) {
+ flag1 = fp1->f_flag;
+ flag2 = fp2->f_flag;
+ iflags = flags & FNONBLOCK;
+
+ if (error = VOP_SETFL(vp1, flag1, iflags, fp1->f_cred, NULL)) {
+ goto out_vop_close;
+ }
+ fp1->f_flag |= iflags;
+
+ if (error = VOP_SETFL(vp2, flag2, iflags, fp2->f_cred, NULL)) {
+ goto out_vop_close;
+ }
+ fp2->f_flag |= iflags;
+ }
+
+ /*
+ * Return the file descriptors to the user. They now
+ * point to two different vnodes which have different
+ * stream heads.
+ */
+ if (copyout(&fd1, &((int *)arg)[0], sizeof (int)) ||
+ copyout(&fd2, &((int *)arg)[1], sizeof (int))) {
+ error = EFAULT;
+ goto out_vop_close;
+ }
+
+ /*
* Now fill in the entries that falloc reserved
*/
mutex_exit(&fp1->f_tlock);
@@ -155,20 +193,24 @@ pipe()
setf(fd2, fp2);
/*
- * Return the file descriptors to the user. They now
- * point to two different vnodes which have different
- * stream heads.
+ * Optionally set the FCLOEXEC flag
*/
- r.r_val1 = fd1;
- r.r_val2 = fd2;
- return (r.r_vals);
+ if ((flags & FCLOEXEC) != 0) {
+ f_setfd(fd1, FD_CLOEXEC);
+ f_setfd(fd2, FD_CLOEXEC);
+ }
+
+ return (0);
+out_vop_close:
+ (void) VOP_CLOSE(vp1, FWRITE|FREAD, 1, (offset_t)0, fp1->f_cred, NULL);
+ (void) VOP_CLOSE(vp2, FWRITE|FREAD, 1, (offset_t)0, fp2->f_cred, NULL);
out:
- unfalloc(fp2);
setf(fd2, NULL);
+ unfalloc(fp2);
out2:
- unfalloc(fp1);
setf(fd1, NULL);
+ unfalloc(fp1);
VN_RELE(vp1);
VN_RELE(vp2);
- return ((longlong_t)set_errno(error));
+ return (set_errno(error));
}
diff --git a/usr/src/uts/intel/amd64/krtld/doreloc.c b/usr/src/uts/intel/amd64/krtld/doreloc.c
index a74f480f26..aac6f6dcc7 100644
--- a/usr/src/uts/intel/amd64/krtld/doreloc.c
+++ b/usr/src/uts/intel/amd64/krtld/doreloc.c
@@ -175,7 +175,13 @@ const Rel_entry reloc_table[R_AMD64_NUM] = {
* entry
*/
-#define HIBITS 0xffffffff80000000ULL
+
+/*
+ * Bits that must be cleared or identical for a value to act as if extended in
+ * the given way.
+ */
+#define ZEROEXBITS 0xffffffff00000000ULL
+#define SIGNEXBITS 0xffffffff80000000ULL
#if defined(_KERNEL)
#define lml 0 /* Needed by arglist of REL_ERR_* macros */
@@ -244,10 +250,11 @@ do_reloc_rtld(uchar_t rtype, uchar_t *off, Xword *value, const char *sym,
*/
if (rtype == R_AMD64_32) {
/*
- * Verify that this value will 'zero-extend', this
- * requires that the upper 33bits all be 'zero'.
+ * Verify that this value will act as a zero-extended
+ * unsigned 32 bit value. That is, that the upper
+ * 32 bits are zero.
*/
- if ((*value & HIBITS) != 0) {
+ if ((*value & ZEROEXBITS) != 0) {
/*
* To keep chkmsg() happy:
* MSG_INTL(MSG_REL_NOFIT)
@@ -258,12 +265,12 @@ do_reloc_rtld(uchar_t rtype, uchar_t *off, Xword *value, const char *sym,
} else if ((rtype == R_AMD64_32S) || (rtype == R_AMD64_PC32) ||
(rtype == R_AMD64_GOTPCREL) || (rtype == R_AMD64_GOTPC32)) {
/*
- * Verify that this value will properly sign extend.
- * This is true of the upper 33bits are all either
- * 'zero' or all 'one'.
+ * Verify that this value will act as a sign-extended
+ * signed 32 bit value, that is that the upper 33 bits
+ * are either all zero or all one.
*/
- if (((*value & HIBITS) != HIBITS) &&
- ((*value & HIBITS) != 0)) {
+ if (((*value & SIGNEXBITS) != SIGNEXBITS) &&
+ ((*value & SIGNEXBITS) != 0)) {
/*
* To keep chkmsg() happy:
* MSG_INTL(MSG_REL_NOFIT)