From: Pete Zaitcev <zaitcev@redhat.com>
To: Jeff Garzik <jeff@garzik.org>
Cc: Project Hail List <hail-devel@vger.kernel.org>
Subject: [Patch 3/3] tabled: use "auto" keyword
Date: Tue, 29 Sep 2009 15:42:10 -0600 [thread overview]
Message-ID: <20090929154210.6edbe3d2@redhat.com> (raw)
The current implementation of automatic listening ports was configured
implicitly by adding <PortFile> clause. This turned out to be a silly
idea. A special keyword for <Port> is more convenient.
This should be built after both CLD and Chunk implement "auto" keyword.
Signed-off-by: Pete Zaitcev <zaitcev@redhat.com>
diff --git a/server/config.c b/server/config.c
index 505524c..c7a994f 100644
--- a/server/config.c
+++ b/server/config.c
@@ -75,13 +75,8 @@ static void cfg_elm_end_listen(struct config_context *cc)
return;
}
- if (cc->tmp_listen.port && cc->tmp_listen.port_file) {
- applog(LOG_ERR, "cfgfile: Listen with both Port and PortFile");
- goto err;
- }
-
- if (!cc->tmp_listen.port && !cc->tmp_listen.port_file) {
- applog(LOG_ERR, "cfgfile: Listen with no Port or PortFile");
+ if (!cc->tmp_listen.port) {
+ applog(LOG_ERR, "cfgfile: Listen with no Port");
goto err;
}
@@ -270,7 +265,8 @@ static void cfg_elm_end (GMarkupParseContext *context,
if (cc->in_listen) {
n = strtol(cc->text, NULL, 10);
- if (n > 0 && n < 65536) {
+ if ((n > 0 && n < 65536) ||
+ !strcmp(cc->text, "auto")) {
free(cc->tmp_listen.port);
cc->tmp_listen.port = cc->text;
} else {
diff --git a/server/server.c b/server/server.c
index f1c49be..d9320ec 100644
--- a/server/server.c
+++ b/server/server.c
@@ -1480,15 +1480,32 @@ static int net_open_socket(int addr_fam, int sock_type, int sock_prot,
return fd;
}
+static int net_write_port(const char *port_file,
+ const char *host, const char *port)
+{
+ FILE *portf;
+ int rc;
+
+ portf = fopen(port_file, "w");
+ if (portf == NULL) {
+ rc = errno;
+ applog(LOG_INFO, "Cannot create port file %s: %s",
+ port_file, strerror(rc));
+ return -rc;
+ }
+ fprintf(portf, "%s:%s\n", tabled_srv.ourhost, port);
+ fclose(portf);
+ return 0;
+}
+
/*
* This, annoyingly, has to have a side effect: it fills out tabled_srv.port
* so that we can later export it into CLD.
*/
-static int net_open_any(char *portfile)
+static int net_open_any(void)
{
struct sockaddr_in addr4;
struct sockaddr_in6 addr6;
- FILE *portf;
int fd4, fd6;
socklen_t addr_len;
unsigned short port;
@@ -1533,7 +1550,7 @@ static int net_open_any(char *portfile)
port = ntohs(addr4.sin_port);
}
- applog(LOG_INFO, "Listening on port %u file %s", port, portfile);
+ applog(LOG_INFO, "Listening on port %u", port);
rc = asprintf(&tabled_srv.port, "%u", port);
if (rc < 0) {
@@ -1541,17 +1558,6 @@ static int net_open_any(char *portfile)
return -ENOMEM;
}
- portf = fopen(portfile, "w");
- if (portf == NULL) {
- rc = errno;
- applog(LOG_INFO, "Cannot create port file %s: %s",
- portfile, strerror(rc));
- return -rc;
- }
- fprintf(portf, "%s:%u\n", tabled_srv.ourhost, port);
- fclose(portf);
-
- tabled_srv.state_net = ST_NET_OPEN;
return 0;
}
@@ -1623,10 +1629,24 @@ err_addr:
static int net_open(void)
{
- if (tabled_srv.port_file)
- return net_open_any(tabled_srv.port_file);
+ int rc;
+
+ if (!strcmp(tabled_srv.port, "auto"))
+ rc = net_open_any();
else
- return net_open_known(tabled_srv.port);
+ rc = net_open_known(tabled_srv.port);
+ if (rc)
+ return rc;
+
+ if (tabled_srv.port_file) {
+ rc = net_write_port(tabled_srv.port_file,
+ tabled_srv.ourhost, tabled_srv.port);
+ if (rc)
+ return rc;
+ }
+
+ tabled_srv.state_net = ST_NET_OPEN;
+ return 0;
}
static void net_listen(void)
diff --git a/test/chunkd-test.conf b/test/chunkd-test.conf
index 3785eb5..00cf024 100644
--- a/test/chunkd-test.conf
+++ b/test/chunkd-test.conf
@@ -1,6 +1,6 @@
<Listen>
- <PortFile>/dev/null</PortFile>
+ <Port>auto</Port>
</Listen>
<PID>chunkd.pid</PID>
<Path>data/chunk</Path>
diff --git a/test/start-daemon b/test/start-daemon
index 589bfe5..2761d55 100755
--- a/test/start-daemon
+++ b/test/start-daemon
@@ -17,7 +17,7 @@ then
fi
# May be different on Solaris... like /usr/libexec or such.
-cld -d data/cld -P cld.pid --port-file=cld.port -E
+cld -d data/cld -P cld.pid -p auto --port-file=cld.port -E
chunkd -C $top_srcdir/test/chunkd-test.conf -E
../server/tabled -C $top_srcdir/test/tabled-test.conf -E -D
diff --git a/test/tabled-test.conf b/test/tabled-test.conf
index 2de599c..068ed00 100644
--- a/test/tabled-test.conf
+++ b/test/tabled-test.conf
@@ -1,7 +1,10 @@
<PID>tabled.pid</PID>
<ForceHost>localhost.localdomain</ForceHost>
-<Listen><PortFile>tabled.acc</PortFile></Listen>
+<Listen>
+ <Port>auto</Port>
+ <PortFile>tabled.acc</PortFile>
+</Listen>
<TDB>data/tdb</TDB>
<TDBRepPort>18083</TDBRepPort>
next reply other threads:[~2009-09-29 21:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-29 21:42 Pete Zaitcev [this message]
2009-09-30 22:40 ` [Patch 3/3] tabled: use "auto" keyword Jeff Garzik
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=20090929154210.6edbe3d2@redhat.com \
--to=zaitcev@redhat.com \
--cc=hail-devel@vger.kernel.org \
--cc=jeff@garzik.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.