Skip to content

Commit

Permalink
3713 Implement accept4()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
postwait authored and gdamore committed Apr 22, 2013
1 parent 6136c58 commit 5dbfd19
Show file tree
Hide file tree
Showing 39 changed files with 577 additions and 157 deletions.
4 changes: 2 additions & 2 deletions usr/src/cmd/truss/codes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
72 changes: 71 additions & 1 deletion usr/src/cmd/truss/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,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 */
{
Expand Down Expand Up @@ -1741,6 +1783,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.
Expand Down Expand Up @@ -2699,7 +2767,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 */
Expand Down Expand Up @@ -2774,5 +2842,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 */
};
7 changes: 5 additions & 2 deletions usr/src/cmd/truss/print.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */

/*
Expand Down
6 changes: 4 additions & 2 deletions usr/src/cmd/truss/systable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down
4 changes: 4 additions & 0 deletions usr/src/head/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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 *);
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions usr/src/head/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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__) */
Expand Down Expand Up @@ -415,6 +418,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__)
Expand Down Expand Up @@ -608,6 +612,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__) */
Expand Down
4 changes: 3 additions & 1 deletion usr/src/lib/libc/amd64/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#
# Copyright (c) 2004, 2010, Oracle and/or its affiliates. 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.
#
Expand Down Expand Up @@ -222,6 +223,7 @@ COMSYSOBJS= \
pathconf.o \
pause.o \
pcsample.o \
pipe2.o \
pollsys.o \
pread.o \
priocntlset.o \
Expand Down Expand Up @@ -278,7 +280,6 @@ SYSOBJS= \
gettimeofday.o \
lwp_private.o \
nuname.o \
pipe.o \
syscall.o \
sysi86.o \
tls_get_addr.o \
Expand Down Expand Up @@ -467,6 +468,7 @@ PORTGEN= \
pfmt.o \
pfmt_data.o \
pfmt_print.o \
pipe.o \
plock.o \
poll.o \
posix_fadvise.o \
Expand Down
7 changes: 6 additions & 1 deletion usr/src/lib/libc/common/sys/_so_accept.s
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,16 @@
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* 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)
4 changes: 3 additions & 1 deletion usr/src/lib/libc/i386/Makefile.com
Original file line number Diff line number Diff line change
Expand Up @@ -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 2011 Nexenta Systems, Inc. All rights reserved.
# Use is subject to license terms.
Expand Down Expand Up @@ -244,6 +245,7 @@ COMSYSOBJS= \
pathconf.o \
pause.o \
pcsample.o \
pipe2.o \
pollsys.o \
pread.o \
priocntlset.o \
Expand Down Expand Up @@ -300,7 +302,6 @@ SYSOBJS= \
gettimeofday.o \
lwp_private.o \
nuname.o \
pipe.o \
ptrace.o \
syscall.o \
sysi86.o \
Expand Down Expand Up @@ -498,6 +499,7 @@ PORTGEN= \
pfmt.o \
pfmt_data.o \
pfmt_print.o \
pipe.o \
plock.o \
poll.o \
posix_fadvise.o \
Expand Down
27 changes: 27 additions & 0 deletions usr/src/lib/libc/port/gen/dup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -30,6 +32,7 @@
#include "lint.h"
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>

#pragma weak _dup = dup
int
Expand All @@ -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));
}
Loading

0 comments on commit 5dbfd19

Please sign in to comment.