Skip to content

Commit

Permalink
16624 Want support for FD_CLOFORK and friends
Browse files Browse the repository at this point in the history
16638 Add some additional details to socket(3HEAD)
Reviewed by: C Fraire <cfraire@me.com>
Reviewed by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
Approved by: Gordon Ross <gordon.w.ross@gmail.com>
  • Loading branch information
rmustacc committed Jul 25, 2024
1 parent d0b93cc commit 0250c53
Show file tree
Hide file tree
Showing 47 changed files with 2,620 additions and 290 deletions.
25 changes: 23 additions & 2 deletions usr/src/cmd/ptools/pfiles/pfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
/*
* Copyright (c) 2017 Joyent, Inc. All Rights reserved.
* Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
* Copyright 2024 Oxide Computer Company
*/

#include <stdio.h>
Expand Down Expand Up @@ -318,6 +319,26 @@ show_files(struct ps_prochandle *Pr)
(void) Pfdinfo_iter(Pr, show_file, Pr);
}

static void
show_fdflags(int fdflags)
{
if (fdflags <= 0)
return;

/*
* show_fileflags() already has printed content here. We translate these
* back to the O_ versions for consistency with the flags that were
* already printed.
*/
if ((fdflags & FD_CLOEXEC) != 0) {
(void) printf("|O_CLOEXEC");
}

if ((fdflags & FD_CLOFORK) != 0) {
(void) printf("|O_CLOFORK");
}
}

/* examine open file with fcntl() */
static void
dofcntl(struct ps_prochandle *Pr, const prfdinfo_t *info, int mandatory,
Expand All @@ -333,8 +354,8 @@ dofcntl(struct ps_prochandle *Pr, const prfdinfo_t *info, int mandatory,
(void) printf(" ");
if (fileflags != -1)
show_fileflags(fileflags);
if (fdflags != -1 && (fdflags & FD_CLOEXEC))
(void) printf(" FD_CLOEXEC");
if (fdflags != -1)
show_fdflags(fdflags);
if (isdoor && (Pstate(Pr) != PS_DEAD))
show_door(Pr, info);
(void) fputc('\n', stdout);
Expand Down
6 changes: 4 additions & 2 deletions usr/src/cmd/sgs/elfdump/common/corenote.c
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@ dump_prfdinfo(note_state_t *state, const char *title)
{
const sl_prfdinfo_layout_t *layout = state->ns_arch->prfdinfo;
char buf[1024];
uint32_t fileflags, mode;
uint32_t fileflags, mode, fdflags;

indent_enter(state, title, &layout->pr_fd);

Expand Down Expand Up @@ -1718,7 +1718,9 @@ dump_prfdinfo(note_state_t *state, const char *title)
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FILEFLAGS),
conv_cnote_fileflags(fileflags, 0, buf, sizeof (buf)));

PRINT_DEC(MSG_ORIG(MSG_CNOTE_T_PR_FDFLAGS), pr_fdflags);
fdflags = extract_as_word(state, &layout->pr_fdflags);
print_str(state, MSG_ORIG(MSG_CNOTE_T_PR_FDFLAGS),
conv_cnote_fdflags(fdflags, 0, buf, sizeof (buf)));

PRINT_STRBUF(MSG_ORIG(MSG_CNOTE_T_PR_PATH), pr_path);

Expand Down
4 changes: 3 additions & 1 deletion usr/src/cmd/sgs/include/conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* Copyright 2012 DEY Storage Systems, Inc. All rights reserved.
* Copyright (c) 2018, Joyent, Inc.
* Copyright 2016 RackTop Systems.
* Copyright 2022 Oxide Computer Company
* Copyright 2024 Oxide Computer Company
*/

#ifndef _CONV_H
Expand Down Expand Up @@ -869,6 +869,8 @@ extern const char *conv_cnote_syscall(Word, Conv_fmt_flags_t,
Conv_inv_buf_t *);
extern const char *conv_cnote_sysset(uint32_t *, int,
Conv_fmt_flags_t, Conv_cnote_sysset_buf_t *);
extern const char *conv_cnote_fdflags(uint32_t, Conv_fmt_flags_t,
char *, size_t);
extern const char *conv_cnote_fileflags(uint32_t, Conv_fmt_flags_t,
char *, size_t);
extern const char *conv_cnote_filemode(uint32_t, Conv_fmt_flags_t,
Expand Down
23 changes: 23 additions & 0 deletions usr/src/cmd/sgs/libconv/common/corenote.c
Original file line number Diff line number Diff line change
Expand Up @@ -2605,6 +2605,29 @@ conv_cnote_filemode(uint32_t mode, Conv_fmt_flags_t fmt_flags,
return (buf);
}

const char *
conv_cnote_fdflags(uint32_t flags, Conv_fmt_flags_t fmt_flags,
char *buf, size_t bufsize)
{
CONV_EXPN_FIELD_ARG arg = { 0 };

static const Val_desc fdflags[] = {
{ 0x01, MSG_FD_CLOEXEC },
{ 0x02, MSG_FD_CLOFORK },
{ 0, 0 }
};

if (flags == 0)
return (MSG_ORIG(MSG_GBL_ZERO));

arg.buf = buf;
arg.bufsize = bufsize;
arg.oflags = flags;
arg.rflags = flags;

(void) conv_expn_field(&arg, fdflags, fmt_flags);
return (buf);
}

#define PROCSECFLGSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
MSG_ASLR_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
Expand Down
3 changes: 3 additions & 0 deletions usr/src/cmd/sgs/libconv/common/corenote.msg
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,9 @@
@ MSG_PR_O_NOFOLLOW "O_NOFOLLOW"
@ MSG_PR_O_NOLINKS "O_NOLINKS"

@ MSG_FD_CLOEXEC "FD_CLOEXEC"
@ MSG_FD_CLOFORK "FD_CLOFORK"

@ MSG_S_IFIFO "S_IFIFO"
@ MSG_S_IFCHR "S_IFCHR"
@ MSG_S_IFDIR "S_IFDIR"
Expand Down
15 changes: 12 additions & 3 deletions usr/src/cmd/sgs/rtld/common/external.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
#include <libintl.h>
#include <debug.h>
#include <libc_int.h>
#include <fcntl.h>
#include "_elf.h"
#include "_rtld.h"

Expand Down Expand Up @@ -622,13 +623,21 @@ int
fcntl(int fildes, int cmd, ...)
{
extern int __fcntl(int, int, ...);
intptr_t arg;
intptr_t arg, arg1 = 0;
va_list ap;

va_start(ap, cmd);
arg = va_arg(ap, intptr_t);
switch (cmd) {
case F_DUP3FD:
arg = va_arg(ap, int);
arg1 = va_arg(ap, int);
break;
default:
arg = va_arg(ap, intptr_t);
break;
}
va_end(ap);
return (__fcntl(fildes, cmd, arg));
return (__fcntl(fildes, cmd, arg, arg1));
}

int
Expand Down
112 changes: 55 additions & 57 deletions usr/src/cmd/truss/codes.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* Copyright 2020 Joyent, Inc.
* Copyright (c) 2014, OmniTI Computer Consulting, Inc. All rights reserved.
* Copyright 2022 Garrett D'Amore <garrett@damore.org>
* Copyright 2024 Oxide Computer Company
*/

/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
Expand Down Expand Up @@ -111,63 +112,58 @@
#include "proto.h"

#define FCNTLMIN F_DUPFD
#define FCNTLMAX F_FLOCKW
#define FCNTLMAX F_DUP3FD
const char *const FCNTLname[] = {
"F_DUPFD",
"F_GETFD",
"F_SETFD",
"F_GETFL",
"F_SETFL",
"F_O_GETLK",
"F_SETLK",
"F_SETLKW",
"F_CHKFL",
"F_DUP2FD",
"F_ALLOCSP",
"F_FREESP",
NULL, /* 12 */
NULL, /* 13 */
"F_GETLK",
NULL, /* 15 */
NULL, /* 16 */
NULL, /* 17 */
NULL, /* 18 */
NULL, /* 19 */
NULL, /* 20 */
NULL, /* 21 */
NULL, /* 22 */
"F_GETOWN",
"F_SETOWN",
"F_REVOKE",
"F_HASREMOTELOCKS",
"F_FREESP64",
NULL, /* 28 */
NULL, /* 29 */
NULL, /* 30 */
NULL, /* 31 */
NULL, /* 32 */
"F_GETLK64",
"F_SETLK64",
"F_SETLKW64",
"F_DUP2FD_CLOEXEC",
"F_DUPFD_CLOEXEC",
NULL, /* 38 */
NULL, /* 39 */
"F_SHARE",
"F_UNSHARE",
"F_SETLK_NBMAND",
"F_SHARE_NBMAND",
"F_SETLK64_NBMAND",
NULL, /* 45 */
"F_BADFD",
"F_OFD_GETLK",
"F_OFD_SETLK",
"F_OFD_SETLKW",
NULL, /* 50 */
NULL, /* 51 */
NULL, /* 52 */
"F_FLOCK",
"F_FLOCKW"
[0] = "F_DUPFD",
[1] = "F_GETFD",
[2] = "F_SETFD",
[3] = "F_GETFL",
[4] = "F_SETFL",
[5] = "F_O_GETLK",
[6] = "F_SETLK",
[7] = "F_SETLKW",
[8] = "F_CHKFL",
[9] = "F_DUP2FD",
[10] = "F_ALLOCSP",
[11] = "F_FREESP",
[13] = "F_ISSTREAM",
[14] = "F_GETLK",
[15] = "F_PRIV",
[16] = "F_NPRIV",
[17] = "F_QUOTACTL",
[18] = "F_BLOCKS",
[19] = "F_BLKSIZE",
[23] = "F_GETOWN",
[24] = "F_SETOWN",
[25] = "F_REVOKE",
[26] = "F_HASREMOTELOCKS",
[27] = "F_FREESP64",
[28] = "F_ALLOCSP64",
[33] = "F_GETLK64",
[34] = "F_SETLK64",
[35] = "F_SETLKW64",
[36] = "F_DUP2FD_CLOEXEC",
[37] = "F_DUPFD_CLOEXEC",
[40] = "F_SHARE",
[41] = "F_UNSHARE",
[42] = "F_SETLK_NBMAND",
[43] = "F_SHARE_NBMAND",
[44] = "F_SETLK64_NBMAND",
[45] = "F_GETXFL",
[46] = "F_BADFD",
[47] = "F_OFD_GETLK",
[48] = "F_OFD_SETLK",
[49] = "F_OFD_SETLKW",
[50] = "F_OFD_GETLK64",
[51] = "F_OFD_SETLK64",
[52] = "F_OFD_SETLKW64",
[53] = "F_FLOCK",
[54] = "F_FLOCKW",
[55] = "F_FLOCK64",
[56] = "F_FLOCKW64",
[57] = "F_DUP2FD_CLOFORK",
[58] = "F_DUPFD_CLOFORK",
[59] = "F_DUP3FD"
};

#define SYSFSMIN GETFSIND
Expand Down Expand Up @@ -2203,7 +2199,7 @@ pathconfname(int code)
#define ALL_O_FLAGS \
(O_NDELAY|O_APPEND|O_SYNC|O_DSYNC|O_NONBLOCK|O_CREAT|O_TRUNC\
|O_EXCL|O_NOCTTY|O_LARGEFILE|O_RSYNC|O_XATTR|O_NOFOLLOW|O_NOLINKS\
|O_CLOEXEC|O_DIRECTORY|O_DIRECT|FXATTRDIROPEN)
|O_CLOEXEC|O_DIRECTORY|O_DIRECT|O_CLOFORK|FXATTRDIROPEN)

const char *
openarg(private_t *pri, int arg)
Expand Down Expand Up @@ -2267,6 +2263,8 @@ openarg(private_t *pri, int arg)
(void) strlcat(str, "|O_DIRECTORY", sizeof (pri->code_buf));
if (arg & O_DIRECT)
(void) strlcat(str, "|O_DIRECT", sizeof (pri->code_buf));
if (arg & O_CLOFORK)
(void) strlcat(str, "|O_CLOFORK", sizeof (pri->code_buf));
if (arg & FXATTRDIROPEN)
(void) strlcat(str, "|FXATTRDIROPEN", sizeof (pri->code_buf));

Expand Down
14 changes: 14 additions & 0 deletions usr/src/cmd/truss/expound.c
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,15 @@ show_ffg(private_t *pri)
(void) puts(pri->sys_string);
}

void
show_ffd(private_t *pri)
{
(void) putchar('\t');
(void) putchar('\t');
prt_ffd(pri, 0, pri->Rval1);
(void) puts(pri->sys_string);
}

/* print values in fcntl() pointed-to structure */
void
show_fcntl(private_t *pri)
Expand All @@ -1824,6 +1833,11 @@ show_fcntl(private_t *pri)
return;
}

if (pri->sys_nargs >= 2 && pri->sys_args[1] == F_GETFD) {
show_ffd(pri);
return;
}

if (pri->sys_nargs < 3 || (offset = pri->sys_args[2]) == 0)
return;

Expand Down
Loading

0 comments on commit 0250c53

Please sign in to comment.