Re: [Qemu-devel] [PATCH] qemu-ga: obey LISTEN_PID when using systemd socket activation
On Thu, Mar 16, 2017 at 05:15:35PM +0100, Paolo Bonzini wrote: > qemu-ga's socket activation support was not obeying the LISTEN_PID > environment variable, which avoids that a process uses a socket-activation > file descriptor meant for its parent. > > Mess can for example ensue if a process forks a children before consuming > the socket-activation file descriptor and therefore setting O_CLOEXEC > on it. > > Luckily, qemu-nbd also got socket activation code, and its copy does > support LISTEN_PID. Some extra fixups are needed to ensure that the > code can be used for both, but that's what this patch does. The > main change is to replace get_listen_fds's "consume" argument with > the FIRST_SOCKET_ACTIVATION_FD macro from the qemu-nbd code. > > Cc: "Richard W.M. Jones"> Cc: Stefan Hajnoczi > Signed-off-by: Paolo Bonzini Yes, it looks alright to me. Shame we can't support LISTEN_FDS > 1 :-( Reviewed-by: Richard W.M. Jones Rich. > include/qemu/systemd.h | 26 + > qemu-nbd.c | 100 > - > qga/main.c | 51 +++-- > util/Makefile.objs | 1 + > util/systemd.c | 77 + > 5 files changed, 125 insertions(+), 130 deletions(-) > create mode 100644 include/qemu/systemd.h > create mode 100644 util/systemd.c > > diff --git a/include/qemu/systemd.h b/include/qemu/systemd.h > new file mode 100644 > index 000..e6a877e > --- /dev/null > +++ b/include/qemu/systemd.h > @@ -0,0 +1,26 @@ > +/* > + * systemd socket activation support > + * > + * Copyright 2017 Red Hat, Inc. and/or its affiliates > + * > + * Authors: > + * Richard W.M. Jones > + * > + * This work is licensed under the terms of the GNU GPL, version 2 or later. > + * See the COPYING file in the top-level directory. > + */ > + > +#ifndef QEMU_SYSTEMD_H > +#define QEMU_SYSTEMD_H 1 > + > +#define FIRST_SOCKET_ACTIVATION_FD 3 /* defined by systemd ABI */ > + > +/* > + * Check if socket activation was requested via use of the > + * LISTEN_FDS and LISTEN_PID environment variables. > + * > + * Returns 0 if no socket activation, or the number of FDs. > + */ > +unsigned int check_socket_activation(void); > + > +#endif > diff --git a/qemu-nbd.c b/qemu-nbd.c > index e4fede6..f332d30 100644 > --- a/qemu-nbd.c > +++ b/qemu-nbd.c > @@ -28,6 +28,7 @@ > #include "qemu/config-file.h" > #include "qemu/bswap.h" > #include "qemu/log.h" > +#include "qemu/systemd.h" > #include "block/snapshot.h" > #include "qapi/util.h" > #include "qapi/qmp/qstring.h" > @@ -474,98 +475,6 @@ static void setup_address_and_port(const char **address, > const char **port) > } > } > > -#define FIRST_SOCKET_ACTIVATION_FD 3 /* defined by systemd ABI */ > - > -#ifndef _WIN32 > -/* > - * Check if socket activation was requested via use of the > - * LISTEN_FDS and LISTEN_PID environment variables. > - * > - * Returns 0 if no socket activation, or the number of FDs. > - */ > -static unsigned int check_socket_activation(void) > -{ > -const char *s; > -unsigned long pid; > -unsigned long nr_fds; > -unsigned int i; > -int fd; > -int err; > - > -s = getenv("LISTEN_PID"); > -if (s == NULL) { > -return 0; > -} > -err = qemu_strtoul(s, NULL, 10, ); > -if (err) { > -if (verbose) { > -fprintf(stderr, "malformed %s environment variable (ignored)\n", > -"LISTEN_PID"); > -} > -return 0; > -} > -if (pid != getpid()) { > -if (verbose) { > -fprintf(stderr, "%s was not for us (ignored)\n", > -"LISTEN_PID"); > -} > -return 0; > -} > - > -s = getenv("LISTEN_FDS"); > -if (s == NULL) { > -return 0; > -} > -err = qemu_strtoul(s, NULL, 10, _fds); > -if (err) { > -if (verbose) { > -fprintf(stderr, "malformed %s environment variable (ignored)\n", > -"LISTEN_FDS"); > -} > -return 0; > -} > -assert(nr_fds <= UINT_MAX); > - > -/* A limitation of current qemu-nbd is that it can only listen on > - * a single socket. When that limitation is lifted, we can change > - * this function to allow LISTEN_FDS > 1, and remove the assertion > - * in the main function below. > - */ > -if (nr_fds > 1) { > -error_report("qemu-nbd does not support socket activation with %s > > 1", > - "LISTEN_FDS"); > -exit(EXIT_FAILURE); > -} > - > -/* So these are not passed to any child processes we might start. */ > -unsetenv("LISTEN_FDS"); > -unsetenv("LISTEN_PID"); > - > -/* So the file descriptors don't leak into child processes. */ > -for (i = 0; i < nr_fds; ++i) { > -fd = FIRST_SOCKET_ACTIVATION_FD + i; > -if
Re: [Qemu-devel] [PATCH] qemu-ga: obey LISTEN_PID when using systemd socket activation
On Thu, Mar 16, 2017 at 05:34:30PM +0100, Paolo Bonzini wrote: > > > On 16/03/2017 17:19, Daniel P. Berrange wrote: > > On Thu, Mar 16, 2017 at 05:15:35PM +0100, Paolo Bonzini wrote: > >> qemu-ga's socket activation support was not obeying the LISTEN_PID > >> environment variable, which avoids that a process uses a socket-activation > >> file descriptor meant for its parent. > >> > >> Mess can for example ensue if a process forks a children before consuming > >> the socket-activation file descriptor and therefore setting O_CLOEXEC > >> on it. > >> > >> Luckily, qemu-nbd also got socket activation code, and its copy does > >> support LISTEN_PID. Some extra fixups are needed to ensure that the > >> code can be used for both, but that's what this patch does. The > >> main change is to replace get_listen_fds's "consume" argument with > >> the FIRST_SOCKET_ACTIVATION_FD macro from the qemu-nbd code. > >> > >> Cc: "Richard W.M. Jones"> >> Cc: Stefan Hajnoczi > >> Signed-off-by: Paolo Bonzini > >> --- > >> include/qemu/systemd.h | 26 + > >> qemu-nbd.c | 100 > >> - > >> qga/main.c | 51 +++-- > >> util/Makefile.objs | 1 + > >> util/systemd.c | 77 + > > > > A MAINTAINERS file entry for these new files ? > > No idea of who would be a candidate. The person who creates the file ;-P Regards, Daniel -- |: http://berrange.com -o-http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://entangle-photo.org -o-http://search.cpan.org/~danberr/ :|
Re: [Qemu-devel] [PATCH] qemu-ga: obey LISTEN_PID when using systemd socket activation
On 16/03/2017 17:19, Daniel P. Berrange wrote: > On Thu, Mar 16, 2017 at 05:15:35PM +0100, Paolo Bonzini wrote: >> qemu-ga's socket activation support was not obeying the LISTEN_PID >> environment variable, which avoids that a process uses a socket-activation >> file descriptor meant for its parent. >> >> Mess can for example ensue if a process forks a children before consuming >> the socket-activation file descriptor and therefore setting O_CLOEXEC >> on it. >> >> Luckily, qemu-nbd also got socket activation code, and its copy does >> support LISTEN_PID. Some extra fixups are needed to ensure that the >> code can be used for both, but that's what this patch does. The >> main change is to replace get_listen_fds's "consume" argument with >> the FIRST_SOCKET_ACTIVATION_FD macro from the qemu-nbd code. >> >> Cc: "Richard W.M. Jones">> Cc: Stefan Hajnoczi >> Signed-off-by: Paolo Bonzini >> --- >> include/qemu/systemd.h | 26 + >> qemu-nbd.c | 100 >> - >> qga/main.c | 51 +++-- >> util/Makefile.objs | 1 + >> util/systemd.c | 77 + > > A MAINTAINERS file entry for these new files ? No idea of who would be a candidate. Thanks for the fast review! Paolo >> 5 files changed, 125 insertions(+), 130 deletions(-) >> create mode 100644 include/qemu/systemd.h >> create mode 100644 util/systemd.c > > Reviewed-by: Daniel P. Berrange > > > Regards, > Daniel >
Re: [Qemu-devel] [PATCH] qemu-ga: obey LISTEN_PID when using systemd socket activation
Hi, This series failed automatic build test. Please find the testing commands and their output below. If you have docker installed, you can probably reproduce it locally. Type: series Subject: [Qemu-devel] [PATCH] qemu-ga: obey LISTEN_PID when using systemd socket activation Message-id: 20170316161535.22157-1-pbonz...@redhat.com === TEST SCRIPT BEGIN === #!/bin/bash set -e git submodule update --init dtc # Let docker tests dump environment info export SHOW_ENV=1 export J=16 make docker-test-quick@centos6 make docker-test-mingw@fedora make docker-test-build@min-glib === TEST SCRIPT END === Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 Switched to a new branch 'test' 2593c43 qemu-ga: obey LISTEN_PID when using systemd socket activation === OUTPUT BEGIN === Submodule 'dtc' (git://git.qemu-project.org/dtc.git) registered for path 'dtc' Cloning into 'dtc'... Submodule path 'dtc': checked out '558cd81bdd432769b59bff01240c44f82cfb1a9d' BUILD centos6 make[1]: Entering directory `/var/tmp/patchew-tester-tmp-4mm5kjs6/src' ARCHIVE qemu.tgz ARCHIVE dtc.tgz COPYRUNNER RUN test-quick in qemu:centos6 Packages installed: SDL-devel-1.2.14-7.el6_7.1.x86_64 ccache-3.1.6-2.el6.x86_64 epel-release-6-8.noarch gcc-4.4.7-17.el6.x86_64 git-1.7.1-4.el6_7.1.x86_64 glib2-devel-2.28.8-5.el6.x86_64 libfdt-devel-1.4.0-1.el6.x86_64 make-3.81-23.el6.x86_64 package g++ is not installed pixman-devel-0.32.8-1.el6.x86_64 tar-1.23-15.el6_8.x86_64 zlib-devel-1.2.3-29.el6.x86_64 Environment variables: PACKAGES=libfdt-devel ccache tar git make gcc g++ zlib-devel glib2-devel SDL-devel pixman-devel epel-release HOSTNAME=79f3fb15319b TERM=xterm MAKEFLAGS= -j16 HISTSIZE=1000 J=16 USER=root CCACHE_DIR=/var/tmp/ccache EXTRA_CONFIGURE_OPTS= V= SHOW_ENV=1 MAIL=/var/spool/mail/root PATH=/usr/lib/ccache:/usr/lib64/ccache:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PWD=/ LANG=en_US.UTF-8 TARGET_LIST= HISTCONTROL=ignoredups SHLVL=1 HOME=/root TEST_DIR=/tmp/qemu-test LOGNAME=root LESSOPEN=||/usr/bin/lesspipe.sh %s FEATURES= dtc DEBUG= G_BROKEN_FILENAMES=1 CCACHE_HASHDIR= _=/usr/bin/env Configure options: --enable-werror --target-list=x86_64-softmmu,aarch64-softmmu --prefix=/var/tmp/qemu-build/install No C++ compiler available; disabling C++ specific optional code Install prefix/var/tmp/qemu-build/install BIOS directory/var/tmp/qemu-build/install/share/qemu binary directory /var/tmp/qemu-build/install/bin library directory /var/tmp/qemu-build/install/lib module directory /var/tmp/qemu-build/install/lib/qemu libexec directory /var/tmp/qemu-build/install/libexec include directory /var/tmp/qemu-build/install/include config directory /var/tmp/qemu-build/install/etc local state directory /var/tmp/qemu-build/install/var Manual directory /var/tmp/qemu-build/install/share/man ELF interp prefix /usr/gnemul/qemu-%M Source path /tmp/qemu-test/src C compilercc Host C compiler cc C++ compiler Objective-C compiler cc ARFLAGS rv CFLAGS-O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -g QEMU_CFLAGS -I/usr/include/pixman-1 -I$(SRC_PATH)/dtc/libfdt -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -fPIE -DPIE -m64 -mcx16 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wendif-labels -Wno-missing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits -fstack-protector-all LDFLAGS -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -pie -m64 -g make make install install pythonpython -B smbd /usr/sbin/smbd module supportno host CPU x86_64 host big endian no target list x86_64-softmmu aarch64-softmmu tcg debug enabled no gprof enabled no sparse enabledno strip binariesyes profiler no static build no pixmansystem SDL support yes (1.2.14) GTK support no GTK GL supportno VTE support no TLS priority NORMAL GNUTLS supportno GNUTLS rndno libgcrypt no libgcrypt kdf no nettleno nettle kdfno libtasn1 no curses supportno virgl support no curl support no mingw32 support no Audio drivers oss Block whitelist (rw) Block whitelist (ro) VirtFS supportno VNC support yes VNC SASL support no VNC JPEG support no VNC PNG support no xen support no brlapi supportno bluez supportno Documentation no PIE yes vde support no netmap supportno Linux AIO support no ATTR/XATTR support yes Install blobs yes KVM support yes HAX support no RDMA support no TCG interpreter no fdt support yes preadv supportyes fdatasync yes
Re: [Qemu-devel] [PATCH] qemu-ga: obey LISTEN_PID when using systemd socket activation
On Thu, Mar 16, 2017 at 05:15:35PM +0100, Paolo Bonzini wrote: > qemu-ga's socket activation support was not obeying the LISTEN_PID > environment variable, which avoids that a process uses a socket-activation > file descriptor meant for its parent. > > Mess can for example ensue if a process forks a children before consuming > the socket-activation file descriptor and therefore setting O_CLOEXEC > on it. > > Luckily, qemu-nbd also got socket activation code, and its copy does > support LISTEN_PID. Some extra fixups are needed to ensure that the > code can be used for both, but that's what this patch does. The > main change is to replace get_listen_fds's "consume" argument with > the FIRST_SOCKET_ACTIVATION_FD macro from the qemu-nbd code. > > Cc: "Richard W.M. Jones"> Cc: Stefan Hajnoczi > Signed-off-by: Paolo Bonzini > --- > include/qemu/systemd.h | 26 + > qemu-nbd.c | 100 > - > qga/main.c | 51 +++-- > util/Makefile.objs | 1 + > util/systemd.c | 77 + A MAINTAINERS file entry for these new files ? > 5 files changed, 125 insertions(+), 130 deletions(-) > create mode 100644 include/qemu/systemd.h > create mode 100644 util/systemd.c Reviewed-by: Daniel P. Berrange Regards, Daniel -- |: http://berrange.com -o-http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://entangle-photo.org -o-http://search.cpan.org/~danberr/ :|
Re: [Qemu-devel] [PATCH] qemu-ga: obey LISTEN_PID when using systemd socket activation
Hi, This series seems to have some coding style problems. See output below for more information: Type: series Subject: [Qemu-devel] [PATCH] qemu-ga: obey LISTEN_PID when using systemd socket activation Message-id: 20170316161535.22157-1-pbonz...@redhat.com === TEST SCRIPT BEGIN === #!/bin/bash BASE=base n=1 total=$(git log --oneline $BASE.. | wc -l) failed=0 # Useful git options git config --local diff.renamelimit 0 git config --local diff.renames True commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..." if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then failed=1 echo fi n=$((n+1)) done exit $failed === TEST SCRIPT END === Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu - [tag update] patchew/20170315135021.6978-1-quint...@redhat.com -> patchew/20170315135021.6978-1-quint...@redhat.com * [new tag] patchew/20170316161535.22157-1-pbonz...@redhat.com -> patchew/20170316161535.22157-1-pbonz...@redhat.com Switched to a new branch 'test' 2593c43 qemu-ga: obey LISTEN_PID when using systemd socket activation === OUTPUT BEGIN === Checking PATCH 1/1: qemu-ga: obey LISTEN_PID when using systemd socket activation... ERROR: code indent should never use tabs #173: FILE: qemu-nbd.c:805: +^I/* qemu-nbd can only listen on a single socket. */$ ERROR: code indent should never use tabs #174: FILE: qemu-nbd.c:806: +^Iif (socket_activation > 1) {$ WARNING: line over 80 characters #175: FILE: qemu-nbd.c:807: +error_report("qemu-nbd does not support socket activation with %s > 1", ERROR: code indent should never use tabs #178: FILE: qemu-nbd.c:810: +^I}$ total: 3 errors, 1 warnings, 324 lines checked Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS. === OUTPUT END === Test command exited with code: 1 --- Email generated automatically by Patchew [http://patchew.org/]. Please send your feedback to patchew-de...@freelists.org
[Qemu-devel] [PATCH] qemu-ga: obey LISTEN_PID when using systemd socket activation
qemu-ga's socket activation support was not obeying the LISTEN_PID environment variable, which avoids that a process uses a socket-activation file descriptor meant for its parent. Mess can for example ensue if a process forks a children before consuming the socket-activation file descriptor and therefore setting O_CLOEXEC on it. Luckily, qemu-nbd also got socket activation code, and its copy does support LISTEN_PID. Some extra fixups are needed to ensure that the code can be used for both, but that's what this patch does. The main change is to replace get_listen_fds's "consume" argument with the FIRST_SOCKET_ACTIVATION_FD macro from the qemu-nbd code. Cc: "Richard W.M. Jones"Cc: Stefan Hajnoczi Signed-off-by: Paolo Bonzini --- include/qemu/systemd.h | 26 + qemu-nbd.c | 100 - qga/main.c | 51 +++-- util/Makefile.objs | 1 + util/systemd.c | 77 + 5 files changed, 125 insertions(+), 130 deletions(-) create mode 100644 include/qemu/systemd.h create mode 100644 util/systemd.c diff --git a/include/qemu/systemd.h b/include/qemu/systemd.h new file mode 100644 index 000..e6a877e --- /dev/null +++ b/include/qemu/systemd.h @@ -0,0 +1,26 @@ +/* + * systemd socket activation support + * + * Copyright 2017 Red Hat, Inc. and/or its affiliates + * + * Authors: + * Richard W.M. Jones + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef QEMU_SYSTEMD_H +#define QEMU_SYSTEMD_H 1 + +#define FIRST_SOCKET_ACTIVATION_FD 3 /* defined by systemd ABI */ + +/* + * Check if socket activation was requested via use of the + * LISTEN_FDS and LISTEN_PID environment variables. + * + * Returns 0 if no socket activation, or the number of FDs. + */ +unsigned int check_socket_activation(void); + +#endif diff --git a/qemu-nbd.c b/qemu-nbd.c index e4fede6..f332d30 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -28,6 +28,7 @@ #include "qemu/config-file.h" #include "qemu/bswap.h" #include "qemu/log.h" +#include "qemu/systemd.h" #include "block/snapshot.h" #include "qapi/util.h" #include "qapi/qmp/qstring.h" @@ -474,98 +475,6 @@ static void setup_address_and_port(const char **address, const char **port) } } -#define FIRST_SOCKET_ACTIVATION_FD 3 /* defined by systemd ABI */ - -#ifndef _WIN32 -/* - * Check if socket activation was requested via use of the - * LISTEN_FDS and LISTEN_PID environment variables. - * - * Returns 0 if no socket activation, or the number of FDs. - */ -static unsigned int check_socket_activation(void) -{ -const char *s; -unsigned long pid; -unsigned long nr_fds; -unsigned int i; -int fd; -int err; - -s = getenv("LISTEN_PID"); -if (s == NULL) { -return 0; -} -err = qemu_strtoul(s, NULL, 10, ); -if (err) { -if (verbose) { -fprintf(stderr, "malformed %s environment variable (ignored)\n", -"LISTEN_PID"); -} -return 0; -} -if (pid != getpid()) { -if (verbose) { -fprintf(stderr, "%s was not for us (ignored)\n", -"LISTEN_PID"); -} -return 0; -} - -s = getenv("LISTEN_FDS"); -if (s == NULL) { -return 0; -} -err = qemu_strtoul(s, NULL, 10, _fds); -if (err) { -if (verbose) { -fprintf(stderr, "malformed %s environment variable (ignored)\n", -"LISTEN_FDS"); -} -return 0; -} -assert(nr_fds <= UINT_MAX); - -/* A limitation of current qemu-nbd is that it can only listen on - * a single socket. When that limitation is lifted, we can change - * this function to allow LISTEN_FDS > 1, and remove the assertion - * in the main function below. - */ -if (nr_fds > 1) { -error_report("qemu-nbd does not support socket activation with %s > 1", - "LISTEN_FDS"); -exit(EXIT_FAILURE); -} - -/* So these are not passed to any child processes we might start. */ -unsetenv("LISTEN_FDS"); -unsetenv("LISTEN_PID"); - -/* So the file descriptors don't leak into child processes. */ -for (i = 0; i < nr_fds; ++i) { -fd = FIRST_SOCKET_ACTIVATION_FD + i; -if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { -/* If we cannot set FD_CLOEXEC then it probably means the file - * descriptor is invalid, so socket activation has gone wrong - * and we should exit. - */ -error_report("Socket activation failed: " - "invalid file descriptor fd = %d: %m", - fd); -exit(EXIT_FAILURE); -} -} - -return (unsigned int) nr_fds; -} - -#else