[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2 1/7] xenstore-read: add support for a retry open limit on xenstored
From: "Luis R. Rodriguez" <mcgrof@xxxxxxxx> This adds support for a customizable retry limit on trying to open the xenstored, each retry is separated by 1 second. This should allow us to simplify both our LSB init scripts and eventually our systemd service files for starting the xenstored. Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> Cc: Ian Campbell <ian.campbell@xxxxxxxxxx> Cc: Jan RÄkorajski <baggins@xxxxxxxxxxxxx> Cc: M A Young <m.a.young@xxxxxxxxxxxx> Cc: Jacek Konieczny <jajcus@xxxxxxxxxx> Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx Signed-off-by: Luis R. Rodriguez <mcgrof@xxxxxxxx> --- tools/xenstore/xenstore_client.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/tools/xenstore/xenstore_client.c b/tools/xenstore/xenstore_client.c index 0ec103f..87972b7 100644 --- a/tools/xenstore/xenstore_client.c +++ b/tools/xenstore/xenstore_client.c @@ -77,7 +77,8 @@ usage(enum mode mode, int incl_mode, const char *progname) errx(1, "Usage: %s <mode> [-h] [...]", progname); case MODE_read: mstr = incl_mode ? "read " : ""; - errx(1, "Usage: %s %s[-h] [-p] [-s] key [...]", progname, mstr); + errx(1, "Usage: %s %s[-h] [-p] [-s] [ -l <num_open_tries> ] key [...]", + progname, mstr); case MODE_write: mstr = incl_mode ? "write " : ""; errx(1, "Usage: %s %s[-h] [-s] key value [...]", progname, mstr); @@ -493,9 +494,9 @@ static enum mode lookup_mode(const char *m) int main(int argc, char **argv) { - struct xs_handle *xsh; + struct xs_handle *xsh = NULL; xs_transaction_t xth = XBT_NULL; - int ret = 0, socket = 0; + int ret = 0, socket = 0, limit = 1, open_tries; int prefix = 0; int tidy = 0; int upto = 0; @@ -535,10 +536,11 @@ main(int argc, char **argv) {"upto", 0, 0, 'u'}, /* MODE_chmod */ {"recurse", 0, 0, 'r'}, /* MODE_chmod */ {"number", 1, 0, 'n'}, /* MODE_watch */ + {"limit", 1, 0, 'l'}, /* MODE_read */ {0, 0, 0, 0} }; - c = getopt_long(argc - switch_argv, argv + switch_argv, "hfspturn:", + c = getopt_long(argc - switch_argv, argv + switch_argv, "hfspturn:l:", long_options, &index); if (c == -1) break; @@ -589,6 +591,16 @@ main(int argc, char **argv) else usage(mode, switch_argv, argv[0]); break; + case 'l': + if (mode == MODE_read) + limit = atoi(optarg); + else + usage(mode, switch_argv, argv[0]); + if (limit < 0) { + limit = 1; + usage(mode, switch_argv, argv[0]); + } + break; } } @@ -632,8 +644,15 @@ main(int argc, char **argv) max_width = ws.ws_col - 2; } - xsh = xs_open(socket ? XS_OPEN_SOCKETONLY : 0); - if (xsh == NULL) err(1, "xs_open"); + for (open_tries = 0; open_tries < limit; open_tries++) { + xsh = xs_open(socket ? XS_OPEN_SOCKETONLY : 0); + if (xsh) + break; + if (limit > 1) + sleep(1); + } + if (!xsh) + err(1, "xs_open"); again: if (transaction) { -- 1.9.0 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |