Skip to content

Commit 5dbfd19

Browse files
postwaitgdamore
authored andcommitted
3713 Implement accept4()
3714 Implement pipe2() 3715 Implement dup3() 3716 Implement mkostemp() and mkostemps() 3719 so_socketpair syscall should preserve FD_CLOEXEC flag Reviewed by: Dan McDonald <danmcd@nexenta.com> Reviewed by: Robert Mustacchi <rm@joyent.com> Approved by: Garrett D'Amore <garrett@damore.org>
1 parent 6136c58 commit 5dbfd19

39 files changed

+577
-157
lines changed

usr/src/cmd/truss/codes.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ const char *const FCNTLname[] = {
146146
"F_GETLK64",
147147
"F_SETLK64",
148148
"F_SETLKW64",
149-
NULL, /* 36 */
150-
NULL, /* 37 */
149+
"F_DUP2FD_CLOEXEC",
150+
"F_DUPFD_CLOEXEC",
151151
NULL, /* 38 */
152152
NULL, /* 39 */
153153
"F_SHARE",

usr/src/cmd/truss/print.c

+71-1
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,48 @@ prt_ioa(private_t *pri, int raw, long val) /* print ioctl argument */
370370
}
371371
}
372372

373+
void
374+
prt_pip(private_t *pri, int raw, long val) /* print pipe code */
375+
{
376+
const char *s = NULL;
377+
378+
if (!raw) {
379+
switch (val) {
380+
case O_CLOEXEC:
381+
s = "O_CLOEXEC";
382+
break;
383+
case O_NONBLOCK:
384+
s = "O_NONBLOCK";
385+
break;
386+
case O_CLOEXEC|O_NONBLOCK:
387+
s = "O_CLOEXEC|O_NONBLOCK";
388+
break;
389+
}
390+
}
391+
392+
if (s == NULL)
393+
prt_dex(pri, 0, val);
394+
else
395+
outstring(pri, s);
396+
}
397+
398+
void
399+
prt_pfd(private_t *pri, int raw, long val) /* print pipe code */
400+
{
401+
int fds[2];
402+
char str[32];
403+
404+
/* the fds only have meaning if the return value is 0 */
405+
if (!raw &&
406+
pri->Rval1 >= 0 &&
407+
Pread(Proc, fds, sizeof (fds), (long)val) == sizeof (fds)) {
408+
snprintf(str, sizeof (str), "[%d,%d]", fds[0], fds[1]);
409+
outstring(pri, str);
410+
} else {
411+
prt_hex(pri, 0, val);
412+
}
413+
}
414+
373415
void
374416
prt_fcn(private_t *pri, int raw, long val) /* print fcntl code */
375417
{
@@ -1741,6 +1783,32 @@ prt_skv(private_t *pri, int raw, long val)
17411783
}
17421784
}
17431785

1786+
/*
1787+
* Print accept4() flags argument.
1788+
*/
1789+
void
1790+
prt_acf(private_t *pri, int raw, long val)
1791+
{
1792+
int first = 1;
1793+
if (raw || !val ||
1794+
(val & ~(SOCK_CLOEXEC|SOCK_NDELAY|SOCK_NONBLOCK))) {
1795+
prt_dex(pri, 0, val);
1796+
return;
1797+
}
1798+
1799+
if (val & SOCK_CLOEXEC) {
1800+
outstring(pri, "|SOCK_CLOEXEC" + first);
1801+
first = 0;
1802+
}
1803+
if (val & SOCK_NDELAY) {
1804+
outstring(pri, "|SOCK_NDELAY" + first);
1805+
first = 0;
1806+
}
1807+
if (val & SOCK_NONBLOCK) {
1808+
outstring(pri, "|SOCK_NONBLOCK" + first);
1809+
}
1810+
}
1811+
17441812

17451813
/*
17461814
* Print setsockopt()/getsockopt() 2nd argument.
@@ -2699,7 +2767,7 @@ void (* const Print[])() = {
26992767
prt_rst, /* RST -- print string returned by syscall */
27002768
prt_smf, /* SMF -- print streams message flags */
27012769
prt_ioa, /* IOA -- print ioctl argument */
2702-
prt_nov, /* Was SIX, now available for reuse */
2770+
prt_pip, /* PIP -- print pipe flags */
27032771
prt_mtf, /* MTF -- print mount flags */
27042772
prt_mft, /* MFT -- print mount file system type */
27052773
prt_iob, /* IOB -- print contents of I/O buffer */
@@ -2774,5 +2842,7 @@ void (* const Print[])() = {
27742842
prt_mob, /* MOB -- print mmapobj() flags */
27752843
prt_snf, /* SNF -- print AT_SYMLINK_[NO]FOLLOW flag */
27762844
prt_skc, /* SKC -- print sockconfig() subcode */
2845+
prt_acf, /* ACF -- print accept4 flags */
2846+
prt_pfd, /* PFD -- print pipe fds */
27772847
prt_dec, /* HID -- hidden argument, make this the last one */
27782848
};

usr/src/cmd/truss/print.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2727
/* All Rights Reserved */
2828

29+
/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All right reserved. */
2930

3031
#ifndef _TRUSS_PRINT_H
3132
#define _TRUSS_PRINT_H
@@ -61,7 +62,7 @@ extern "C" {
6162
#define RST 21 /* print string returned by sys call */
6263
#define SMF 22 /* print streams message flags */
6364
#define IOA 23 /* print ioctl argument */
64-
/* Number 24 now available for reuse */
65+
#define PIP 24 /* print pipe flags */
6566
#define MTF 25 /* print mount flags */
6667
#define MFT 26 /* print mount file system type */
6768
#define IOB 27 /* print contents of I/O buffer */
@@ -136,7 +137,9 @@ extern "C" {
136137
#define MOB 96 /* print mmapobj() flags */
137138
#define SNF 97 /* print AT_SYMLINK_[NO]FOLLOW flag */
138139
#define SKC 98 /* print sockconfig subcode */
139-
#define HID 99 /* hidden argument, don't print */
140+
#define ACF 99 /* accept4 flags */
141+
#define PFD 100 /* pipe fds[2] */
142+
#define HID 101 /* hidden argument, don't print */
140143
/* make sure HID is always the last member */
141144

142145
/*

usr/src/cmd/truss/systable.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2727
/* All Rights Reserved */
2828

29+
/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
30+
2931
#include <stdio.h>
3032
#include <stdlib.h>
3133
#include <fcntl.h>
@@ -258,7 +260,7 @@ const struct systable systable[] = {
258260
{"pgrpsys", 3, DEC, NOV, DEC, DEC, DEC}, /* 39 */
259261
{"uucopystr", 3, DEC, NOV, STG, RST, UNS}, /* 40 */
260262
{ NULL, 8, HEX, HEX, HEX, HEX, HEX, HEX, HEX, HEX, HEX, HEX},
261-
{"pipe", 0, DEC, DEC}, /* 42 */
263+
{"pipe", 2, DEC, NOV, PFD, PIP}, /* 42 */
262264
{"times", 1, DEC, NOV, HEX}, /* 43 */
263265
{"profil", 4, DEC, NOV, HEX, UNS, HEX, OCT}, /* 44 */
264266
{"faccessat", 4, DEC, NOV, ATC, STG, ACC, FAT}, /* 45 */
@@ -450,7 +452,7 @@ const struct systable systable[] = {
450452
{"so_socketpair", 1, DEC, NOV, HEX}, /* 231 */
451453
{"bind", 4, DEC, NOV, DEC, HEX, DEC, SKV}, /* 232 */
452454
{"listen", 3, DEC, NOV, DEC, DEC, SKV}, /* 233 */
453-
{"accept", 4, DEC, NOV, DEC, HEX, HEX, SKV}, /* 234 */
455+
{"accept", 5, DEC, NOV, DEC, HEX, HEX, SKV, ACF}, /* 234 */
454456
{"connect", 4, DEC, NOV, DEC, HEX, DEC, SKV}, /* 235 */
455457
{"shutdown", 3, DEC, NOV, DEC, SHT, SKV}, /* 236 */
456458
{"recv", 4, DEC, NOV, DEC, IOB, DEC, DEC}, /* 237 */

usr/src/head/stdlib.h

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
* Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
2424
*/
2525

26+
/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
27+
2628
/* Copyright (c) 1988 AT&T */
2729
/* All Rights Reserved */
2830

@@ -216,6 +218,7 @@ extern int clearenv(void);
216218
extern void closefrom(int);
217219
extern int daemon(int, int);
218220
extern int dup2(int, int);
221+
extern int dup3(int, int, int);
219222
extern int fdwalk(int (*)(void *, int), void *);
220223
extern char *qecvt(long double, int, int *, int *);
221224
extern char *qfcvt(long double, int, int *, int *);
@@ -323,6 +326,7 @@ extern int clearenv();
323326
extern void closefrom();
324327
extern int daemon();
325328
extern int dup2();
329+
extern int dup3();
326330
extern int fdwalk();
327331
extern char *qecvt();
328332
extern char *qfcvt();

usr/src/head/unistd.h

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
/* Copyright (c) 1988 AT&T */
2727
/* All Rights Reserved */
2828

29+
/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
30+
2931
#ifndef _UNISTD_H
3032
#define _UNISTD_H
3133

@@ -274,6 +276,7 @@ extern char *cuserid(char *);
274276
#endif
275277
extern int dup(int);
276278
extern int dup2(int, int);
279+
extern int dup3(int, int, int);
277280
#if defined(_XPG4) || defined(__EXTENSIONS__)
278281
extern void encrypt(char *, int);
279282
#endif /* defined(XPG4) || defined(__EXTENSIONS__) */
@@ -415,6 +418,7 @@ extern int mincore(caddr_t, size_t, char *);
415418
extern long pathconf(const char *, int);
416419
extern int pause(void);
417420
extern int pipe(int *);
421+
extern int pipe2(int *, int);
418422
#if !defined(_POSIX_C_SOURCE) || defined(_XPG5) || \
419423
(defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64) || \
420424
defined(__EXTENSIONS__)
@@ -608,6 +612,7 @@ extern char *cuserid();
608612
#endif
609613
extern int dup();
610614
extern int dup2();
615+
extern int dup3();
611616
#if defined(_XPG4) || defined(__EXTENSIONS__)
612617
extern void encrypt();
613618
#endif /* defined(_XPG4) || defined(__EXTENSIONS__) */

usr/src/lib/libc/amd64/Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#
2222
# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
2323
#
24+
# Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
2425
# Copyright 2011 Nexenta Systems, Inc. All rights reserved.
2526
# Use is subject to license terms.
2627
#
@@ -222,6 +223,7 @@ COMSYSOBJS= \
222223
pathconf.o \
223224
pause.o \
224225
pcsample.o \
226+
pipe2.o \
225227
pollsys.o \
226228
pread.o \
227229
priocntlset.o \
@@ -278,7 +280,6 @@ SYSOBJS= \
278280
gettimeofday.o \
279281
lwp_private.o \
280282
nuname.o \
281-
pipe.o \
282283
syscall.o \
283284
sysi86.o \
284285
tls_get_addr.o \
@@ -467,6 +468,7 @@ PORTGEN= \
467468
pfmt.o \
468469
pfmt_data.o \
469470
pfmt_print.o \
471+
pipe.o \
470472
plock.o \
471473
poll.o \
472474
posix_fadvise.o \

usr/src/lib/libc/common/sys/_so_accept.s

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@
2727
* Use is subject to license terms.
2828
*/
2929

30+
/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
31+
3032
.file "_so_accept.s"
3133

3234
/* C library -- __so_accept */
33-
/* int __so_accept(int sock, struct sockaddr *addr, int *addrlen, int vers) */
35+
/*
36+
* int __so_accept(int sock, struct sockaddr *addr, int *addrlen, int vers,
37+
* int flags)
38+
*/
3439

3540
#include "SYS.h"
3641

usr/src/lib/libc/i386/sys/pipe.s usr/src/lib/libc/common/sys/pipe2.s

+7-16
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,16 @@
1717
* information: Portions Copyright [yyyy] [name of copyright owner]
1818
*
1919
* CDDL HEADER END
20-
*/
21-
/*
22-
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
23-
* Use is subject to license terms.
2420
*/
2521

26-
.file "pipe.s"
22+
/* Copyright 2013 OmniTI Computer Consulting, Inc. All rights reserved. */
2723

28-
#include <sys/asm_linkage.h>
29-
30-
ANSI_PRAGMA_WEAK(pipe,function)
24+
/* int pipe2 (int *fds, int flags) */
3125

3226
#include "SYS.h"
3327

34-
ENTRY(pipe)
35-
SYSTRAP_2RVALS(pipe)
36-
SYSCERROR
37-
movl 4(%esp), %ecx
38-
movl %eax, (%ecx)
39-
movl %edx, 4(%ecx)
40-
RETC
41-
SET_SIZE(pipe)
28+
.file "pipe2.s"
29+
30+
SYSCALL2(pipe2,pipe);
31+
RET
32+
SET_SIZE(pipe2)

usr/src/lib/libc/i386/Makefile.com

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#
2121
#
2222
# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
23+
# Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
2324
#
2425
# Copyright 2011 Nexenta Systems, Inc. All rights reserved.
2526
# Use is subject to license terms.
@@ -244,6 +245,7 @@ COMSYSOBJS= \
244245
pathconf.o \
245246
pause.o \
246247
pcsample.o \
248+
pipe2.o \
247249
pollsys.o \
248250
pread.o \
249251
priocntlset.o \
@@ -300,7 +302,6 @@ SYSOBJS= \
300302
gettimeofday.o \
301303
lwp_private.o \
302304
nuname.o \
303-
pipe.o \
304305
ptrace.o \
305306
syscall.o \
306307
sysi86.o \
@@ -498,6 +499,7 @@ PORTGEN= \
498499
pfmt.o \
499500
pfmt_data.o \
500501
pfmt_print.o \
502+
pipe.o \
501503
plock.o \
502504
poll.o \
503505
posix_fadvise.o \

usr/src/lib/libc/port/gen/dup.c

+27
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* CDDL HEADER END
2020
*/
2121

22+
/* Copyright 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
23+
2224
/*
2325
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
2426
* Use is subject to license terms.
@@ -30,6 +32,7 @@
3032
#include "lint.h"
3133
#include <sys/types.h>
3234
#include <fcntl.h>
35+
#include <errno.h>
3336

3437
#pragma weak _dup = dup
3538
int
@@ -44,3 +47,27 @@ dup2(int fildes, int fildes2)
4447
{
4548
return (fcntl(fildes, F_DUP2FD, fildes2));
4649
}
50+
51+
int
52+
dup3(int fildes, int fildes2, int flags)
53+
{
54+
/*
55+
* The only valid flag is O_CLOEXEC.
56+
*/
57+
if (flags & ~O_CLOEXEC) {
58+
errno = EINVAL;
59+
return (-1);
60+
}
61+
62+
/*
63+
* This call differs from dup2 such that it is an error when
64+
* fildes == fildes2
65+
*/
66+
if (fildes == fildes2) {
67+
errno = EINVAL;
68+
return (-1);
69+
}
70+
71+
return (fcntl(fildes, (flags == 0) ? F_DUP2FD : F_DUP2FD_CLOEXEC,
72+
fildes2));
73+
}

0 commit comments

Comments
 (0)