summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2016-01-08 09:29:13 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2016-01-08 09:29:13 (GMT)
commit3325fed2895f079486b88c65409c73153fec306f (patch) (side-by-side diff)
tree65165fde1e48346892cd0c0dfd7f7a4980ba1665
parent46b2745b25176c14c42bcc9612b290c310929aa0 (diff)
downloadpies-3325fed2895f079486b88c65409c73153fec306f.tar.gz
pies-3325fed2895f079486b88c65409c73153fec306f.tar.bz2
Enable control socket when run as init process.
* configure.ac (DEFAULT_CONTROL_URL): Rename to DEFAULT_PIES_CONTROL_URL. Change default value. (DEFAULT_INIT_CONTROL_URL): New subst variable. * lib/libpies.h (pies_basic_url_create): New prototype. * lib/url.c (pies_basic_url_create): New function (renamed from pies_url_create). (pies_url_create): Expand variable references in the input string. * src/Makefile.am (AM_CPPFLAGS): Pass DEFAULT_INIT_CONTROL_URL * src/ctl.c (pies_control_url) (ctl_open): Don't exit on errors, return -1 instead. * src/pies.c (default_control_url): New variable. (config_parse): Create default socket url. (pies_control_url): New macro (main): Set environment variable PIES_INSTANCE. Try to open control socket in init process mode as well. * src/pies.h (default_control_url): New extern. (ctl_open): Change prototype. (pies_control_url): Remove. * src/piesctl-cl.opt (parse_options): Set environment variable PIES_INSTANCE. * src/piesctl.c (parse_config): Use pies_url_create and DEFAULT_PIES_CONTROL_URL when falling back to the default socket.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--.gitignore1
-rw-r--r--configure.ac7
-rw-r--r--lib/libpies.h1
-rw-r--r--lib/url.c19
-rw-r--r--po/.gitignore1
-rw-r--r--src/Makefile.am3
-rw-r--r--src/ctl.c28
-rw-r--r--src/pies.c28
-rw-r--r--src/pies.h4
-rw-r--r--src/piesctl-cl.opt1
-rw-r--r--src/piesctl.c11
11 files changed, 64 insertions, 40 deletions
diff --git a/.gitignore b/.gitignore
index f7b417d..216d2e5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+/ABOUT-NLS~
*.a
*.la
*.lo
diff --git a/configure.ac b/configure.ac
index 3b34059..d6d4e4f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -129,8 +129,11 @@ AH_BOTTOM([
# endif
])
-AC_SUBST([DEFAULT_CONTROL_URL],[unix:///tmp/%s.ctl])
-AC_ARG_VAR([DEFAULT_CONTROL_URL],
+AC_SUBST([DEFAULT_PIES_CONTROL_URL],['unix:///tmp/$${PIES_INSTANCE}.ctl'])
+AC_ARG_VAR([DEFAULT_PIES_CONTROL_URL],
+ [URL of the default control socket])
+AC_SUBST([DEFAULT_INIT_CONTROL_URL],['unix:///dev/init.ctl'])
+AC_ARG_VAR([DEFAULT_INIT_CONTROL_URL],
[URL of the default control socket])
IMPRIMATUR_INIT
diff --git a/lib/libpies.h b/lib/libpies.h
index b04182e..1c83b8e 100644
--- a/lib/libpies.h
+++ b/lib/libpies.h
@@ -71,6 +71,7 @@ struct pies_url
char **argv;
};
+int pies_basic_url_create (struct pies_url **purl, const char *str);
int pies_url_create (struct pies_url **purl, const char *str);
void pies_url_destroy (struct pies_url **purl);
const char *pies_url_get_arg (struct pies_url *url, const char *argname);
diff --git a/lib/url.c b/lib/url.c
index 41f5c04..11d220d 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -325,7 +325,7 @@ pies_url_copy (struct pies_url **purl, struct pies_url *src)
}
int
-pies_url_create (struct pies_url **purl, const char *str)
+pies_basic_url_create (struct pies_url **purl, const char *str)
{
int rc;
struct pies_url *url;
@@ -344,6 +344,23 @@ pies_url_create (struct pies_url **purl, const char *str)
}
return rc;
}
+
+extern char **environ;
+
+int
+pies_url_create (struct pies_url **purl, const char *str)
+{
+ struct wordsplit ws;
+ int rc;
+
+ ws.ws_env = (const char**) environ;
+ if (wordsplit (str, &ws,
+ WRDSF_NOCMD | WRDSF_QUOTE | WRDSF_NOSPLIT | WRDSF_ENV))
+ return -1;
+ rc = pies_basic_url_create (purl, ws.ws_wordv[0]);
+ wordsplit_free (&ws);
+ return rc;
+}
const char *
pies_url_get_arg (struct pies_url *url, const char *argname)
diff --git a/po/.gitignore b/po/.gitignore
index d00dd8d..b45a955 100644
--- a/po/.gitignore
+++ b/po/.gitignore
@@ -1,3 +1,4 @@
+/Rules-quot~
/Makevars.template~
/Makefile.in.in~
*.gmo
diff --git a/src/Makefile.am b/src/Makefile.am
index 9fb29d2..01149c6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -87,7 +87,8 @@ AM_CPPFLAGS=\
-DDEFAULT_VERSION_INCLUDE_DIR=\"$(incdir)\"\
-DDEFAULT_INCLUDE_DIR=\"$(pkgdatadir)/include\"\
-DDEFAULT_STATE_DIR=\"$(pkgstatedir)\"\
- -DDEFAULT_CONTROL_URL=\"$(DEFAULT_CONTROL_URL)\"
+ -DDEFAULT_PIES_CONTROL_URL='"$(DEFAULT_PIES_CONTROL_URL)"'\
+ -DDEFAULT_INIT_CONTROL_URL='"$(DEFAULT_INIT_CONTROL_URL)"'
AM_YFLAGS=-dvt -pmeta1
AM_LFLAGS=-dvp -Pmeta1 -olex.yy.c
diff --git a/src/ctl.c b/src/ctl.c
index 78490cb..46038a2 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -1233,45 +1233,29 @@ ctl_accept (int socket, void *data)
return 0;
}
-char const *
-pies_control_url (void)
-{
- if (!control.url)
- {
- char *str = xasprintf (DEFAULT_CONTROL_URL, instance);
- if (pies_url_create (&control.url, str))
- {
- logmsg (LOG_CRIT, _("%s: cannot create URL: %s"),
- str, strerror (errno));
- exit (EX_OSERR);
- }
- free (str);
- }
- return control.url->string;
-}
-
-void
-ctl_open ()
+int
+ctl_open (void)
{
int fd;
- pies_control_url ();
fd = create_socket (control.url, SOCK_STREAM, NULL, 077);
if (fd == -1)
{
logmsg (LOG_CRIT, _("can't create control socket %s"),
control.url->string);
- exit (EX_UNAVAILABLE);
+ return -1;
}
if (listen (fd, 8))
{
logmsg (LOG_CRIT, _("can't listen on control socket %s: %s"),
control.url->string, strerror (errno));
- exit (EX_UNAVAILABLE);
+ return -1;
}
register_socket (fd, ctl_accept, NULL, NULL, NULL);
+
+ return 0;
}
static void
diff --git a/src/pies.c b/src/pies.c
index 875684a..09f9fab 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -57,6 +57,11 @@ char *mailer_program = "/usr/sbin/sendmail";
char *mailer_command_line = "/usr/sbin/sendmail -oi -t";
int mailer_argc;
char **mailer_argv;
+
+char *default_control_url[2] = {
+ DEFAULT_PIES_CONTROL_URL,
+ DEFAULT_INIT_CONTROL_URL
+};
struct config_file
{
@@ -1749,6 +1754,18 @@ config_parse (char const *name)
if (grecs_tree_process (tree, pies_keywords))
config_error ();
+
+ if (!control.url)
+ {
+ char const *str = default_control_url[init_process];
+ if (pies_url_create (&control.url, str))
+ {
+ logmsg (LOG_CRIT, _("%s: cannot create control URL: %s"),
+ str, strerror (errno));
+ if (!init_process)
+ exit (EX_OSERR);
+ }
+ }
grecs_tree_free (tree);
}
@@ -1931,6 +1948,8 @@ pies_check_status (pid_t *ppid)
return pies_status_running;
}
+#define pies_control_url() control.url->string
+
void
request_restart_components (size_t cc, char **cv)
{
@@ -2230,7 +2249,7 @@ main (int argc, char **argv)
else
instance++;
}
-
+ setenv ("PIES_INSTANCE", instance, 1);
log_tag = instance;
if (!init_process)
@@ -2371,9 +2390,12 @@ main (int argc, char **argv)
diag_setup (DIAG_TO_SYSLOG);
}
- if (!init_process)
+ if (init_process)
+ ctl_open ();
+ else
{
- ctl_open ();
+ if (ctl_open ())
+ exit (EX_UNAVAILABLE);
create_pidfile (pidfile);
}
diff --git a/src/pies.h b/src/pies.h
index f69c512..f22ccb2 100644
--- a/src/pies.h
+++ b/src/pies.h
@@ -292,6 +292,7 @@ extern int dfl_level;
extern size_t pies_master_argc;
extern char **pies_master_argv;
+extern char *default_control_url[2];
enum config_syntax
{
@@ -549,5 +550,4 @@ struct control
extern struct control control;
-void ctl_open(void);
-char const *pies_control_url (void);
+int ctl_open(void);
diff --git a/src/piesctl-cl.opt b/src/piesctl-cl.opt
index b8e4fc1..b787a5c 100644
--- a/src/piesctl-cl.opt
+++ b/src/piesctl-cl.opt
@@ -95,6 +95,7 @@ void
parse_options(int argc, char *argv[], int *index)
{
GETOPT(argc, argv, *index)
+ setenv ("PIES_INSTANCE", instance, 1);
}
diff --git a/src/piesctl.c b/src/piesctl.c
index 301e7ac..dba8988 100644
--- a/src/piesctl.c
+++ b/src/piesctl.c
@@ -188,17 +188,10 @@ parse_config ()
url = default_url;
else
{
- int rc;
- size_t len = 0;
- file_name = NULL;
- grecs_asprintf (&file_name, &len, DEFAULT_CONTROL_URL, instance);
- rc = pies_url_create (&url, file_name);
- free (file_name);
-
- if (rc)
+ if (pies_url_create (&url, DEFAULT_PIES_CONTROL_URL))
{
grecs_error (NULL, 0, _("%s: cannot create URL: %s"),
- DEFAULT_CONTROL_URL, strerror (errno));
+ DEFAULT_PIES_CONTROL_URL, strerror (errno));
exit (EX_SOFTWARE);
}
}

Return to:

Send suggestions and report system problems to the System administrator.