search for: set_cloexec

Displaying 20 results from an estimated 34 matches for "set_cloexec".

2019 Aug 02
0
[nbdkit PATCH v2 07/17] build: Audit for use of pipe2
...the server's quit_fd definitely needs to be marked CLOEXEC (it's easy to use the sh plugin to show that we are currently leaking it to children), although doing so can occur without worrying about atomicity since it is called before threads begin. Finally, it's also worth updating our set_cloexec helper function to document that we still prefer atomicity where possible. Signed-off-by: Eric Blake <eblake@redhat.com> --- configure.ac | 1 + common/utils/utils.c | 4 ++-- plugins/nbd/nbd.c | 31 +++++++++++++++++++++++++++++++ server/quit.c | 18 ++++++++++++...
2020 Apr 28
2
[PATCH nbdkit] server/locks: Allow lock_request to be called when there is no current conn.
On Haiku tests/test-socket-activation failed with: nbdkit: locks.c:96:lock_request: conn != NULL called from server/sockets.c: accept_connection in the fallback path which does: lock_request (); thread_data->sock = set_cloexec (accept (listen_sock, NULL, NULL)); unlock_request () Because there is no current connection in this thread this code fails. However it should be possible to call lock_request without a connection, provided that thread_model <= NBDKIT_THREAD_MODEL_SERIALIZE_REQUESTS (which it is when the fal...
2020 Apr 28
2
[PATCH nbdkit] server: Fix parameters of lock_request, unlock_request
Patch itself is not controversial. However I do wonder if we want to change all these constructs so that instead of using #ifdef we use something like: if (HAVE_PIPE2) { // normal path } else { // fallback } (It wouldn't actually work as written above because HAVE_PIPE2 is not always defined, but you get the idea.) This would allow us to test that the fallback paths still
2020 Apr 28
0
[PATCH nbdkit] server: Fix parameters of lock_request, unlock_request on fallback path.
...assert (thread_model <= NBDKIT_THREAD_MODEL_SERIALIZE_ALL_REQUESTS); - lock_request (NULL); + lock_request (); if (pipe (conn->status_pipe)) { perror ("pipe"); - unlock_request (NULL); + unlock_request (); goto error2; } if (set_nonblock (set_cloexec (conn->status_pipe[0])) == -1) { perror ("fcntl"); close (conn->status_pipe[1]); - unlock_request (NULL); + unlock_request (); goto error2; } if (set_nonblock (set_cloexec (conn->status_pipe[1])) == -1) { perror ("fcntl");...
2019 Aug 02
23
[nbdkit PATCH v2 00/17] fd leak safety
This is a major rewrite compared to my v1 series, where I've tried a lot harder to ensure that we still accommodate building on Haiku (although I have not actually yet fired up a Haiku VM to try it for myself). I also managed to make the sh plugin fully parallel, on capable platforms. See also my question on patch 10 on whether I've picked the best naming convention. Eric Blake (17):
2019 Sep 18
1
[PATCH nbdkit] server: Remove useless thread local sockaddr.
...could be accepting * connections in one thread while another thread could be in a @@ -316,9 +310,7 @@ accept_connection (int listen_sock) assert (backend->thread_model (backend) <= NBDKIT_THREAD_MODEL_SERIALIZE_ALL_REQUESTS); lock_request (NULL); - thread_data->sock = set_cloexec (accept (listen_sock, - &thread_data->addr, - &thread_data->addrlen)); + thread_data->sock = set_cloexec (accept (listen_sock, NULL, NULL)); unlock_request (NULL); #endif if (thread_data-&gt...
2020 Apr 14
0
[nbdkit PATCH v2 2/3] server: Sanitize stdin/out before running plugin code
...(NULL); + if (listen_stdin || run) { +#ifndef F_DUPFD_CLOEXEC +#define F_DUPFD_CLOEXEC F_DUPFD +#endif + orig_in = fcntl (STDIN_FILENO, F_DUPFD_CLOEXEC, STDERR_FILENO + 1); + orig_out = fcntl (STDOUT_FILENO, F_DUPFD_CLOEXEC, STDERR_FILENO + 1); +#if F_DUPFD == F_DUPFD_CLOEXEC + orig_in = set_cloexec (orig_in); + orig_out = set_cloexec (orig_out); +#endif + if (orig_in == -1 || orig_out == -1) { + perror ("fcntl"); + exit (EXIT_FAILURE); + } + } + close (STDIN_FILENO); + close (STDOUT_FILENO); + if (open ("/dev/null", O_RDONLY) != STDIN_FILENO || +...
2020 Apr 04
0
[nbdkit PATCH 2/2] server: Sanitize stdin/out before running plugin code
.... + */ + if (listen_stdin || run) { +#ifndef F_DUPFD_CLOEXEC +#define F_DUPFD_CLOEXEC F_DUPFD +#endif + orig_in = fcntl (STDIN_FILENO, F_DUPFD_CLOEXEC, STDERR_FILENO + 1); + orig_out = fcntl (STDOUT_FILENO, F_DUPFD_CLOEXEC, STDERR_FILENO + 1); +#if F_DUPFD == F_DUPFD_CLOEXEC + orig_in = set_cloexec (orig_in); + orig_out = set_cloexec (orig_out); +#endif + if (orig_in == -1 || orig_out == -1) { + perror ("fcntl"); + exit (EXIT_FAILURE); + } + } + close (STDIN_FILENO); + close (STDOUT_FILENO); + if (open ("/dev/null", O_RDONLY) != STDIN_FILENO || +...
2020 Apr 15
2
Re: [PATCH nbdkit 6/9] common/utils: Add a copy_environ utility function.
...on.c | 116 +++++++++++++++++++++++++++++++++++++++ > 3 files changed, 119 insertions(+) > > +++ b/common/utils/utils.h > @@ -38,5 +38,6 @@ extern void uri_quote (const char *str, FILE *fp); > extern int exit_status_to_nbd_error (int status, const char *cmd); > extern int set_cloexec (int fd); > extern int set_nonblock (int fd); > +extern char **copy_environ (char **env, ...); Should use __attribute__((sentinel)), to let the compiler enforce that we don't forget a trailing NULL. > +++ b/common/utils/environ.c > + > +DEFINE_VECTOR_TYPE(environ_t, char *)...
2019 Oct 18
2
Re: [PATCH nbdkit] Add support for AF_VSOCK.
...exit (EXIT_FAILURE); > + } > + > +#ifdef SOCK_CLOEXEC > + sock = socket (AF_VSOCK, SOCK_STREAM|SOCK_CLOEXEC, 0); > +#else > + /* Fortunately, this code is only run at startup, so there is no > + * risk of the fd leaking to a plugin's fork() > + */ > + sock = set_cloexec (socket (AF_VSOCK, SOCK_STREAM, 0)); Even better, all known platforms with AF_VSOCK have SOCK_CLOEXEC. Make this #else just be an #error. > +#endif > + if (sock == -1) { > + perror ("bind_unix_socket: socket"); > + exit (EXIT_FAILURE); > + } Also, it wouldn'...
2019 Aug 27
1
[PATCH nbdkit] server: Try hard to maintain invariant that fds 0, 1 and 2 are always open.
...tions(-) diff --git a/common/utils/utils.h b/common/utils/utils.h index ebd5f66..a77d2cd 100644 --- a/common/utils/utils.h +++ b/common/utils/utils.h @@ -38,5 +38,6 @@ extern void uri_quote (const char *str, FILE *fp); extern int exit_status_to_nbd_error (int status, const char *cmd); extern int set_cloexec (int fd); extern int set_nonblock (int fd); +extern void close_or_nullify_fd (int fd); #endif /* NBDKIT_UTILS_H */ diff --git a/server/connections.c b/server/connections.c index c173df8..f57ab3e 100644 --- a/server/connections.c +++ b/server/connections.c @@ -489,7 +489,7 @@ static void raw_cl...
2005 Feb 26
1
[Fwd: [Xen-changelog] Move xcs to unix domain sockets.]
Just forwarding this changelog from yesterday. xcs now uses Unix domain sockets in unstable. This was a hot thread a couple months back with strong opinions on both sides and no clear resolution on the list, so I thought some people might like to know the developers'' resolution. This should be good news for those seeking tighter dom0''s, particularly those who
2020 Apr 28
0
Re: [PATCH nbdkit] server/locks: Allow lock_request to be called when there is no current conn.
...:45 AM, Richard W.M. Jones wrote: > On Haiku tests/test-socket-activation failed with: > > nbdkit: locks.c:96:lock_request: conn != NULL > > called from server/sockets.c: accept_connection > in the fallback path which does: > lock_request (); > thread_data->sock = set_cloexec (accept (listen_sock, NULL, NULL)); > unlock_request () > > Because there is no current connection in this thread this code fails. > > However it should be possible to call lock_request without a > connection, provided that > thread_model <= NBDKIT_THREAD_MODEL_SERIALIZ...
2020 Apr 15
0
Re: [PATCH nbdkit 6/9] common/utils: Add a copy_environ utility function.
...+++++++++++++++++++++++ > > 3 files changed, 119 insertions(+) > > > > >+++ b/common/utils/utils.h > >@@ -38,5 +38,6 @@ extern void uri_quote (const char *str, FILE *fp); > > extern int exit_status_to_nbd_error (int status, const char *cmd); > > extern int set_cloexec (int fd); > > extern int set_nonblock (int fd); > >+extern char **copy_environ (char **env, ...); > > Should use __attribute__((sentinel)), to let the compiler enforce > that we don't forget a trailing NULL. Ooops ... I had this in an earlier version and somehow managed...
2020 Apr 04
6
[nbdkit PATCH 0/2] stdin/out cleanups
This is what I've been playing with in response to my earlier question about what to do with 'nbdkit -s sh -' (https://www.redhat.com/archives/libguestfs/2020-April/msg00032.html) I'm still open to ideas on a better name, and/or whether adding <stdbool.h> to our public include files is a good idea (if not, returning int instead of bool is tolerable). Eric Blake (2):
2019 Aug 02
1
[nbdkit PATCH] server: Restrict thread model when no atomic CLOEXEC
...S([\ + accept4 \ fdatasync \ get_current_dir_name \ mkostemp \ diff --git a/common/utils/utils.c b/common/utils/utils.c index 9ac3443b..029b6685 100644 --- a/common/utils/utils.c +++ b/common/utils/utils.c @@ -140,13 +140,15 @@ exit_status_to_nbd_error (int status, const char *cmd) */ int set_cloexec (int fd) { -#if defined SOCK_CLOEXEC && defined HAVE_MKOSTEMP && defined HAVE_PIPE2 +#if (defined SOCK_CLOEXEC && defined HAVE_MKOSTEMP && defined HAVE_PIPE2 && \ + defined HAVE_ACCEPT4) nbdkit_error ("prefer creating fds with CLOEXEC atomically s...
2019 Oct 18
2
[PATCH nbdkit] Add support for AF_VSOCK.
This is a series of patches to libnbd and nbdkit adding AF_VSOCK support. On the host side it allows you to start an nbdkit instance which listens on a virtio-vsock socket: $ ./nbdkit -fv --vsock memory 1G ... nbdkit: debug: bound to vsock 2:10809 On the guest side you can then use libnbd to connect to the server: $ ./run nbdsh -c 'h.connect_vsock(2, 10809)' -c
2020 Apr 15
0
[PATCH nbdkit 6/9] common/utils: Add a copy_environ utility function.
...LAGS) diff --git a/common/utils/utils.h b/common/utils/utils.h index ebd5f66b..5c121ccb 100644 --- a/common/utils/utils.h +++ b/common/utils/utils.h @@ -38,5 +38,6 @@ extern void uri_quote (const char *str, FILE *fp); extern int exit_status_to_nbd_error (int status, const char *cmd); extern int set_cloexec (int fd); extern int set_nonblock (int fd); +extern char **copy_environ (char **env, ...); #endif /* NBDKIT_UTILS_H */ diff --git a/common/utils/environ.c b/common/utils/environ.c new file mode 100644 index 00000000..a43eeb71 --- /dev/null +++ b/common/utils/environ.c @@ -0,0 +1,116 @@ +/* nbdk...
2020 Aug 15
3
[PATCH EXPERIMENTAL nbdkit 0/2] Port to Windows using mingw.
The patches following do indeed allow you to compile nbdkit.exe, but it does not actually work yet. I'm posting this experimental series more as a work in progress and to get feedback. Note this does not require Windows itself to build or test. You can cross-compile it using mingw64-* packages on Fedora or Debian, and test it [spoiler alert: it fails] using Wine. Rich.
2020 Mar 17
2
[PATCH nbdkit v3] New tmpdisk plugin.
...gt;/dev/null before the shell fragment. We may want to do this in other places where we run external shell scripts, or more generally for all plugins, but this commit does not fix this. - Improve can_multi_conn comment. - Use mkostemp if available. If not we have to use a racy mkstemp + set_cloexec instead. - I still didn't implement .zero, because the implementation (see plugins/file/file.c) is really complicated even if you remove the block device code. I guess it would be nice to isolate all this complexity into common/ at some point, which would allow us to implement efficie...