diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2016-01-09 09:37:37 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2016-01-09 09:37:37 +0200 |
commit | 346535b7d14be92dd2b853058039bca67bb380dd (patch) | |
tree | b9c72955dd7eed72c5949751fbad031fd92a040d | |
parent | 489432d354d88049afe4af54c29965d382d67f7a (diff) | |
download | pies-346535b7d14be92dd2b853058039bca67bb380dd.tar.gz pies-346535b7d14be92dd2b853058039bca67bb380dd.tar.bz2 |
piesctl: optionally bind to local IP
* configure.ac (GRECS_SETUP): Request sockaddr-list
* grecs: Upgrade.
* po/POTFILES.in: Remove meta.c
* src/piesctl-cl.opt: Use client.url
* src/piesctl.c (client_conn): New struct.
(instance_keywords,piesctl_keywords): New keyword: "source".
(parse_config): Initialize grecs_sockaddr_hints.
(shttp_connect): Optionally bind to the selected local IP
before connecting.
* src/utmp.c (write_wtmpx,write_utmpx): Remove spurious notice.
-rw-r--r-- | configure.ac | 2 | ||||
m--------- | grecs | 0 | ||||
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | src/pies.c | 1 | ||||
-rw-r--r-- | src/piesctl-cl.opt | 2 | ||||
-rw-r--r-- | src/piesctl.c | 63 | ||||
-rw-r--r-- | src/utmp.c | 11 |
7 files changed, 53 insertions, 27 deletions
diff --git a/configure.ac b/configure.ac index d6d4e4f..114fc07 100644 --- a/configure.ac +++ b/configure.ac @@ -74,3 +74,3 @@ gl_INIT # Grecs -GRECS_SETUP([grecs],[tests git2chg getopt json]) +GRECS_SETUP([grecs],[tests git2chg getopt json sockaddr-list]) GRECS_HOST_PROJECT_INCLUDES='-I$(top_srcdir)/gnu -I$(top_builddir)/gnu' diff --git a/grecs b/grecs -Subproject 384b8c088c290f06f70835402f903627c67de6f +Subproject 3df291f812208a8ce07a2878784a0a73e458719 diff --git a/po/POTFILES.in b/po/POTFILES.in index f696480..acc6127 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -22,3 +22,2 @@ src/diag.c src/limits.c -src/meta.c src/meta1gram.y @@ -1797,3 +1797,2 @@ pies_schedule_action (int act) action = act; - /*FIXME: got_alarm?*/ } diff --git a/src/piesctl-cl.opt b/src/piesctl-cl.opt index b787a5c..41e982b 100644 --- a/src/piesctl-cl.opt +++ b/src/piesctl-cl.opt @@ -63,3 +63,3 @@ OPTION(url,u,URL, BEGIN - if (pies_url_create (&url, optarg)) + if (pies_url_create (&client.url, optarg)) { diff --git a/src/piesctl.c b/src/piesctl.c index dba8988..ff205d5 100644 --- a/src/piesctl.c +++ b/src/piesctl.c @@ -40,3 +40,8 @@ struct pies_url *default_url; /* Control socket URL */ -struct pies_url *url; +struct grecs_sockaddr *source_addr; +struct client_conn +{ + struct pies_url *url; + struct grecs_sockaddr *source_addr; +} client; char const *instance = "pies"; @@ -48,2 +53,4 @@ int dump; +struct grecs_sockaddr_hints hints = { .flags = GRECS_AH_PASSIVE }; + #define EX_OK 0 @@ -62,3 +69,8 @@ static struct grecs_keyword instance_keywords[] = { grecs_type_string, GRECS_DFLT, - NULL, 0, conf_callback_url}, + NULL, offsetof(struct client_conn,url), conf_callback_url}, + {"source", + N_("arg"), + N_("Source IP address."), + grecs_type_sockaddr, GRECS_DFLT, + NULL, offsetof(struct client_conn,source_addr) }, { NULL } @@ -82,6 +94,6 @@ callback_instance (enum grecs_callback_command cmd, return 1; - if (!url && strcmp (value->v.string, instance) == 0) - *(struct pies_url ***) cb_data = &url; + if (strcmp (value->v.string, instance) == 0) + *(struct client_conn **) cb_data = &client; else - *(struct pies_url ***) cb_data = NULL; + *(struct client_conn **) cb_data = NULL; break; @@ -103,2 +115,7 @@ struct grecs_keyword piesctl_keywords[] = { &default_url, 0, conf_callback_url}, + {"source", + N_("arg"), + N_("Source IP address."), + grecs_type_sockaddr, GRECS_DFLT, + &source_addr }, {"instance", @@ -122,3 +139,4 @@ parse_config () grecs_preprocessor = pp_command_line (); - + grecs_sockaddr_hints = &hints; + if (config_file) @@ -143,3 +161,3 @@ parse_config () exit (EX_CONFIG); - if (!url && verbose) + if (!client.url && verbose) printf (_("%s: URL not found in %s\n"), @@ -148,3 +166,3 @@ parse_config () - if (!url) + if (!client.url) { @@ -168,3 +186,3 @@ parse_config () node->v.value, GRECS_TYPE_STRING); - if (pies_url_create (&url, node->v.value->v.string)) + if (pies_url_create (&client.url, node->v.value->v.string)) { @@ -182,3 +200,3 @@ parse_config () - if (!url) + if (!client.url) { @@ -187,6 +205,6 @@ parse_config () if (default_url) - url = default_url; + client.url = default_url; else { - if (pies_url_create (&url, DEFAULT_PIES_CONTROL_URL)) + if (pies_url_create (&client.url, DEFAULT_PIES_CONTROL_URL)) { @@ -198,5 +216,8 @@ parse_config () } + + if (!client.source_addr) + client.source_addr = source_addr; if (verbose) - printf (_("%s: using URL %s\n"), program_name, url->string); + printf (_("%s: using URL %s\n"), program_name, client.url->string); } @@ -387,3 +408,3 @@ shttp_io_free (struct shttp_io *io) static struct shttp_connection * -shttp_connect (struct pies_url *url) +shttp_connect (struct pies_url *url, struct grecs_sockaddr *source_addr) { @@ -498,3 +519,13 @@ shttp_connect (struct pies_url *url) - // FIXME: Bind to local address + if (source_addr) + { + if (source_addr->sa->sa_family != addr.s.sa_family) + grecs_error (NULL, 0, + _("source and destination address family differ")); + else if (bind (fd, source_addr->sa, source_addr->len) < 0) + { + grecs_error (NULL, errno, _("failed to bind")); + exit (EX_UNAVAILABLE); + } + } @@ -1815,3 +1846,3 @@ main (int argc, char **argv) - conn = shttp_connect (url); + conn = shttp_connect (client.url, client.source_addr); if (!conn) @@ -107,5 +107,2 @@ fill_utmp (UTMPX *utmp, - -int wtmpxreboot = 0; - void @@ -115,6 +112,7 @@ write_wtmpx (int type, const char *user, const char *id, pid_t pid, UTMPX utmp; + static int wtmpxreboot = 0; + debug (2, (_("cannot open %s for writing"), WTMP_FILE)); if (access (WTMP_FILE, W_OK)) { - logmsg (LOG_NOTICE, _("cannot open %s for writing"), WTMP_FILE); if (type == BOOT_TIME) @@ -133,4 +131,2 @@ write_wtmpx (int type, const char *user, const char *id, pid_t pid, -int utmpreboot = 0; - void @@ -140,2 +136,3 @@ write_utmpx (int type, const char *user, const char *id, pid_t pid, UTMPX utmp; + static int utmpreboot = 0; @@ -143,3 +140,3 @@ write_utmpx (int type, const char *user, const char *id, pid_t pid, { - logmsg (LOG_NOTICE, _("cannot open %s for writing"), UTMP_FILE); + debug (1, (_("cannot open %s for writing"), UTMP_FILE)); if (type == BOOT_TIME) |