Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F143027316
D54862.id170359.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D54862.id170359.diff
View Options
diff --git a/include/spawn.h b/include/spawn.h
--- a/include/spawn.h
+++ b/include/spawn.h
@@ -123,6 +123,13 @@
const sigset_t * __restrict);
int posix_spawnattr_setsigmask(posix_spawnattr_t * __restrict,
const sigset_t * __restrict);
+
+#if __BSD_VISIBLE
+int posix_spawnattr_setexecfd_np(posix_spawnattr_t * __restrict, int);
+int posix_spawnattr_getexecfd_np(const posix_spawnattr_t * __restrict,
+ int * __restrict);
+#endif
+
__END_DECLS
#endif /* !_SPAWN_H_ */
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -274,6 +274,7 @@
posix_spawn.3 \
posix_spawn_file_actions_addopen.3 \
posix_spawn_file_actions_init.3 \
+ posix_spawnattr_getexecfd_np.3 \
posix_spawnattr_getflags.3 \
posix_spawnattr_getpgroup.3 \
posix_spawnattr_getschedparam.3 \
@@ -469,6 +470,7 @@
posix_spawn_file_actions_addopen.3 posix_spawn_file_actions_addfchdir_np.3 \
posix_spawn_file_actions_init.3 posix_spawn_file_actions_destroy.3 \
posix_spawnattr_getflags.3 posix_spawnattr_setflags.3 \
+ posix_spawnattr_getexecfd_np.3 posix_spawnattr_setexecfd_np.3 \
posix_spawnattr_getpgroup.3 posix_spawnattr_setpgroup.3 \
posix_spawnattr_getschedparam.3 posix_spawnattr_setschedparam.3 \
posix_spawnattr_getschedpolicy.3 posix_spawnattr_setschedpolicy.3 \
diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map
--- a/lib/libc/gen/Symbol.map
+++ b/lib/libc/gen/Symbol.map
@@ -474,6 +474,11 @@
str2sig;
};
+FBSD_1.9 {
+ posix_spawnattr_getexecfd_np;
+ posix_spawnattr_setexecfd_np;
+};
+
FBSDprivate_1.0 {
/* needed by thread libraries */
__thr_jtable;
diff --git a/lib/libc/gen/posix_spawn.c b/lib/libc/gen/posix_spawn.c
--- a/lib/libc/gen/posix_spawn.c
+++ b/lib/libc/gen/posix_spawn.c
@@ -50,6 +50,7 @@
int sa_schedpolicy;
sigset_t sa_sigdefault;
sigset_t sa_sigmask;
+ int sa_execfd;
};
struct __posix_spawn_file_actions {
@@ -260,7 +261,9 @@
_exit(127);
}
envp = psa->envp != NULL ? psa->envp : environ;
- if (psa->use_env_path)
+ if (psa->sa != NULL && (*(psa->sa))->sa_execfd != -1)
+ fexecve((*(psa->sa))->sa_execfd, psa->argv, envp);
+ else if (psa->use_env_path)
__libc_execvpe(psa->path, psa->argv, envp);
else
_execve(psa->path, psa->argv, envp);
@@ -578,6 +581,7 @@
sa = calloc(1, sizeof(struct __posix_spawnattr));
if (sa == NULL)
return (errno);
+ sa->sa_execfd = -1;
/* Set defaults as specified by POSIX, cleared above */
*ret = sa;
@@ -639,6 +643,14 @@
return (0);
}
+int
+posix_spawnattr_getexecfd_np(const posix_spawnattr_t * __restrict sa,
+ int * __restrict fdp)
+{
+ *fdp = (*sa)->sa_execfd;
+ return (0);
+}
+
int
posix_spawnattr_setflags(posix_spawnattr_t *sa, short flags)
{
@@ -688,3 +700,11 @@
(*sa)->sa_sigmask = *sigmask;
return (0);
}
+
+int
+posix_spawnattr_setexecfd_np(posix_spawnattr_t * __restrict sa,
+ int execfd)
+{
+ (*sa)->sa_execfd = execfd;
+ return (0);
+}
diff --git a/lib/libc/gen/posix_spawnattr_getexecfd_np.3 b/lib/libc/gen/posix_spawnattr_getexecfd_np.3
new file mode 100644
--- /dev/null
+++ b/lib/libc/gen/posix_spawnattr_getexecfd_np.3
@@ -0,0 +1,86 @@
+.\" Copyright 2026 The FreeBSD Foundation
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.\" This documentation was written by
+.\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship
+.\" from the FreeBSD Foundation.
+.\"
+.Dd January 25, 2026
+.Dt POSIX_SPAWNATTR_GETEXECFD_NP 3
+.Os
+.Sh NAME
+.Nm posix_spawnattr_getexecfd_np ,
+.Nm posix_spawnattr_setexecfd_np
+.Nd "get and set the spawn-execfd attribute of a spawn attributes object"
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In spawn.h
+.Ft int
+.Fo posix_spawnattr_getexecfd_np
+.Fa "const posix_spawnattr_t *restrict attr"
+.Fa "int *restrict fdp"
+.Fc
+.Ft int
+.Fo posix_spawnattr_setexecfd_np
+.Fa "posix_spawnattr_t *attr"
+.Fa "int fd"
+.Sh DESCRIPTION
+The
+.Fn posix_spawnattr_getexecfd_np
+function obtains the value of the spawn-execfd attribute from the
+attributes object referenced by
+.Fa attr .
+.Pp
+The
+.Fn posix_spawnattr_setexecfd_np
+function sets the spawn-execfd attribute in an initialized attributes
+object referenced by
+.Fa attr .
+.Pp
+The spawn-execfd attribute provides the file descriptor that is used
+to execute new image in the spawned process by the
+.Xr posix_spawn 3
+family of functions.
+If the attribute is set to a value different from \-1, it must be a valid
+file descriptor, which does not have the
+.Va O_CLOEXEC
+flag set.
+Then,
+.Fn posix_spawn
+executes the executable image referenced by the file descriptor, in the
+newly created process, using the
+.Xr fexecve 2
+system call.
+In this case, the
+.Fa path
+argument to
+.Fn posix_spawn
+is ignored.
+.Pp
+The default value for the spawn-execfd attribute is \-1, which
+means that the executed image is specified by the
+.Fa path
+argument to
+.Fn posix_spawn .
+.Sh RETURN VALUES
+The
+.Fn posix_spawnattr_getexecfd_np
+and
+.Fn posix_spawnattr_setexecfd_np
+functions return zero.
+.Sh SEE ALSO
+.Xr posix_spawn 3 ,
+.Xr posix_spawnattr_destroy 3 ,
+.Xr posix_spawnattr_init 3 ,
+.Xr posix_spawnp 3
+.Sh STANDARDS
+The
+.Fn posix_spawnattr_getexecfd_np
+and
+.Fn posix_spawnattr_setexecfd_np
+are
+.Fx
+extensions, first appeared in
+.Fx 16.0 .
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jan 26, 8:57 AM (16 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28002761
Default Alt Text
D54862.id170359.diff (5 KB)
Attached To
Mode
D54862: Add posix_spawnattr_get/setexecfd_np(3)
Attached
Detach File
Event Timeline
Log In to Comment