From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>, Ian Jackson <iwj@xenproject.org>,
Wei Liu <wl@xen.org>, Julien Grall <julien.grall@amazon.com>
Subject: [PATCH v11 18/27] tools/xenstore: handle CLOEXEC flag for local files and pipes
Date: Thu, 14 Jan 2021 16:37:54 +0100 [thread overview]
Message-ID: <20210114153803.2591-19-jgross@suse.com> (raw)
In-Reply-To: <20210114153803.2591-1-jgross@suse.com>
For support of live update the locally used files need to have the
"close on exec" flag set. Fortunately the used Xen libraries are
already doing this, so only the logging and tdb related files and
pipes are affected. openlog() has the close on exec attribute, too.
In order to be able to keep the event channels open specify the
XENEVTCHN_NO_CLOEXEC flag when calling xenevtchn_open().
Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Julien Grall <julien.grall@amazon.com>
---
V4:
- disable LU in case of O_CLOEXEC not supported (Julien Grall)
V5:
- add comment (Paul Durrant)
V7:
- set XENEVTCHN_NO_CLOEXEC
---
tools/xenstore/xenstored_control.c | 6 ++++++
tools/xenstore/xenstored_core.c | 6 ++++--
tools/xenstore/xenstored_core.h | 8 ++++++++
tools/xenstore/xenstored_domain.c | 2 +-
tools/xenstore/xenstored_posix.c | 12 ++++++++++++
5 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/tools/xenstore/xenstored_control.c b/tools/xenstore/xenstored_control.c
index 206948d7e5..25b407e153 100644
--- a/tools/xenstore/xenstored_control.c
+++ b/tools/xenstore/xenstored_control.c
@@ -41,6 +41,7 @@ Interactive commands for Xen Store Daemon.
#define MAP_ANONYMOUS MAP_ANON
#endif
+#ifndef NO_LIVE_UPDATE
struct live_update {
/* For verification the correct connection is acting. */
struct connection *conn;
@@ -90,6 +91,7 @@ static const char *lu_begin(struct connection *conn)
return NULL;
}
+#endif
struct cmd_s {
char *cmd;
@@ -214,6 +216,7 @@ static int do_control_print(void *ctx, struct connection *conn,
return 0;
}
+#ifndef NO_LIVE_UPDATE
static const char *lu_abort(const void *ctx, struct connection *conn)
{
syslog(LOG_INFO, "live-update: abort\n");
@@ -575,6 +578,7 @@ static int do_control_lu(void *ctx, struct connection *conn,
send_reply(conn, XS_CONTROL, resp, strlen(resp) + 1);
return 0;
}
+#endif
static int do_control_help(void *, struct connection *, char **, int);
@@ -582,6 +586,7 @@ static struct cmd_s cmds[] = {
{ "check", do_control_check, "" },
{ "log", do_control_log, "on|off" },
+#ifndef NO_LIVE_UPDATE
/*
* The parameters are those of the xenstore-control utility!
* Depending on environment (Mini-OS or daemon) the live-update
@@ -601,6 +606,7 @@ static struct cmd_s cmds[] = {
{ "live-update", do_control_lu,
"[-c <cmdline>] [-F] [-t <timeout>] <file>\n"
" Default timeout is 60 seconds.", 4 },
+#endif
#ifdef __MINIOS__
{ "memreport", do_control_memreport, "" },
#else
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 97e7277791..b0656eb3e4 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -198,7 +198,8 @@ void reopen_log(void)
if (tracefile) {
close_log();
- tracefd = open(tracefile, O_WRONLY|O_CREAT|O_APPEND, 0600);
+ tracefd = open(tracefile,
+ O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0600);
if (tracefd < 0)
perror("Could not open tracefile");
@@ -1689,7 +1690,8 @@ static void setup_structure(void)
if (!(tdb_flags & TDB_INTERNAL))
unlink(tdbname);
- tdb_ctx = tdb_open_ex(tdbname, 7919, tdb_flags, O_RDWR|O_CREAT|O_EXCL,
+ tdb_ctx = tdb_open_ex(tdbname, 7919, tdb_flags,
+ O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC,
0640, &tdb_logger, NULL);
if (!tdb_ctx)
barf_perror("Could not create tdb file %s", tdbname);
diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_core.h
index 22287ddfe9..c7567eaf0b 100644
--- a/tools/xenstore/xenstored_core.h
+++ b/tools/xenstore/xenstored_core.h
@@ -35,6 +35,14 @@
#include "tdb.h"
#include "hashtable.h"
+#ifndef O_CLOEXEC
+#define O_CLOEXEC 0
+/* O_CLOEXEC support is needed for Live Update in the daemon case. */
+#ifndef __MINIOS__
+#define NO_LIVE_UPDATE
+#endif
+#endif
+
/* DEFAULT_BUFFER_SIZE should be large enough for each errno string. */
#define DEFAULT_BUFFER_SIZE 16
diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_domain.c
index 919a4d98cf..38d250fbed 100644
--- a/tools/xenstore/xenstored_domain.c
+++ b/tools/xenstore/xenstored_domain.c
@@ -743,7 +743,7 @@ void domain_init(void)
talloc_set_destructor(xgt_handle, close_xgt_handle);
- xce_handle = xenevtchn_open(NULL, 0);
+ xce_handle = xenevtchn_open(NULL, XENEVTCHN_NO_CLOEXEC);
if (xce_handle == NULL)
barf_perror("Failed to open evtchn device");
diff --git a/tools/xenstore/xenstored_posix.c b/tools/xenstore/xenstored_posix.c
index 1f9603fea2..ae3e63e07f 100644
--- a/tools/xenstore/xenstored_posix.c
+++ b/tools/xenstore/xenstored_posix.c
@@ -90,9 +90,21 @@ void finish_daemonize(void)
void init_pipe(int reopen_log_pipe[2])
{
+ int flags;
+ unsigned int i;
+
if (pipe(reopen_log_pipe)) {
barf_perror("pipe");
}
+
+ for (i = 0; i < 2; i++) {
+ flags = fcntl(reopen_log_pipe[i], F_GETFD);
+ if (flags < 0)
+ barf_perror("pipe get flags");
+ flags |= FD_CLOEXEC;
+ if (fcntl(reopen_log_pipe[i], F_SETFD, flags) < 0)
+ barf_perror("pipe set flags");
+ }
}
void unmap_xenbus(void *interface)
--
2.26.2
next prev parent reply other threads:[~2021-01-14 15:50 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-14 15:37 [PATCH v11 00/27] tools/xenstore: support live update for xenstored Juergen Gross
2021-01-14 15:37 ` [PATCH v11 01/27] tools/libxenevtchn: switch to standard xen coding style Juergen Gross
2021-01-14 19:07 ` Andrew Cooper
2021-01-15 6:13 ` Jürgen Groß
2021-01-14 15:37 ` [PATCH v11 02/27] tools/libxenevtchn: rename open_flags to flags Juergen Gross
2021-01-14 19:22 ` Andrew Cooper
2021-01-15 6:14 ` Jürgen Groß
2021-01-14 15:37 ` [PATCH v11 03/27] tools/libxenevtchn: check xenevtchn_open() flags for not supported bits Juergen Gross
2021-01-14 19:24 ` Andrew Cooper
2021-01-15 6:19 ` Jürgen Groß
2021-01-14 15:37 ` [PATCH v11 04/27] tools/libxenevtchn: propagate xenevtchn_open() flags parameter Juergen Gross
2021-01-14 19:26 ` Andrew Cooper
2021-01-14 15:37 ` [PATCH v11 05/27] tools/libxenevtchn: add possibility to not close file descriptor on exec Juergen Gross
2021-01-15 1:01 ` Andrew Cooper
2021-01-15 7:11 ` Jürgen Groß
2021-01-14 15:37 ` [PATCH v11 06/27] tools/xenstore: refactor XS_CONTROL handling Juergen Gross
2021-01-14 15:37 ` [PATCH v11 07/27] tools/xenstore: add live update command to xenstore-control Juergen Gross
2021-01-14 15:37 ` [PATCH v11 08/27] tools/xenstore: add basic live-update command parsing Juergen Gross
2021-01-14 15:37 ` [PATCH v11 09/27] tools/xenstore: introduce live update status block Juergen Gross
2021-01-14 15:37 ` [PATCH v11 10/27] tools/xenstore: save new binary for live update Juergen Gross
2021-01-14 15:37 ` [PATCH v11 11/27] tools/xenstore: add command line handling " Juergen Gross
2021-01-14 15:37 ` [PATCH v11 12/27] tools/xenstore: add support for delaying execution of a xenstore request Juergen Gross
2021-01-14 15:37 ` [PATCH v11 13/27] tools/xenstore: add the basic framework for doing the live update Juergen Gross
2021-01-14 15:37 ` [PATCH v11 14/27] tools/xenstore: allow live update only with no transaction active Juergen Gross
2021-01-14 15:37 ` [PATCH v11 15/27] docs: update the xenstore migration stream documentation Juergen Gross
2021-01-14 15:37 ` [PATCH v11 16/27] tools/xenstore: add include file for state structure definitions Juergen Gross
2021-01-14 15:37 ` [PATCH v11 17/27] tools/xenstore: dump the xenstore state for live update Juergen Gross
2021-01-14 15:37 ` Juergen Gross [this message]
2021-01-14 15:37 ` [PATCH v11 19/27] tools/xenstore: split off domain introduction from do_introduce() Juergen Gross
2021-01-14 15:37 ` [PATCH v11 20/27] tools/xenstore: evaluate the live update flag when starting Juergen Gross
2021-01-14 15:37 ` [PATCH v11 21/27] tools/xenstore: read internal state when doing live upgrade Juergen Gross
2021-01-14 15:37 ` [PATCH v11 22/27] tools/xenstore: add reading global state for live update Juergen Gross
2021-01-14 15:37 ` [PATCH v11 23/27] tools/xenstore: add read connection " Juergen Gross
2021-01-14 15:38 ` [PATCH v11 24/27] tools/xenstore: add read node " Juergen Gross
2021-01-14 15:38 ` [PATCH v11 25/27] tools/xenstore: add read watch " Juergen Gross
2021-01-14 15:38 ` [PATCH v11 26/27] tools/xenstore: handle dying domains in " Juergen Gross
2021-01-14 15:38 ` [PATCH v11 27/27] tools/xenstore: activate new binary for " Juergen Gross
2021-01-14 16:48 ` [PATCH v11 00/27] tools/xenstore: support live update for xenstored Jürgen Groß
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210114153803.2591-19-jgross@suse.com \
--to=jgross@suse.com \
--cc=iwj@xenproject.org \
--cc=julien.grall@amazon.com \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.