aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-01-08 11:29:13 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2016-01-08 11:29:13 +0200
commit3325fed2895f079486b88c65409c73153fec306f (patch)
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.
-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 +1,2 @@
+/ABOUT-NLS~
*.a
diff --git a/configure.ac b/configure.ac
index 3b34059..d6d4e4f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -131,4 +131,7 @@ AH_BOTTOM([
-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])
diff --git a/lib/libpies.h b/lib/libpies.h
index b04182e..1c83b8e 100644
--- a/lib/libpies.h
+++ b/lib/libpies.h
@@ -73,2 +73,3 @@ struct pies_url
+int pies_basic_url_create (struct pies_url **purl, const char *str);
int pies_url_create (struct pies_url **purl, const char *str);
diff --git a/lib/url.c b/lib/url.c
index 41f5c04..11d220d 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -327,3 +327,3 @@ 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)
{
@@ -347,2 +347,19 @@ pies_url_create (struct pies_url **purl, const char *str)
+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 *
diff --git a/po/.gitignore b/po/.gitignore
index d00dd8d..b45a955 100644
--- a/po/.gitignore
+++ b/po/.gitignore
@@ -1 +1,2 @@
+/Rules-quot~
/Makevars.template~
diff --git a/src/Makefile.am b/src/Makefile.am
index 9fb29d2..01149c6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -89,3 +89,4 @@ AM_CPPFLAGS=\
-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)"'
diff --git a/src/ctl.c b/src/ctl.c
index 78490cb..46038a2 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -1235,21 +1235,4 @@ ctl_accept (int socket, void *data)
-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)
{
@@ -1257,3 +1240,2 @@ ctl_open ()
- pies_control_url ();
fd = create_socket (control.url, SOCK_STREAM, NULL, 077);
@@ -1263,3 +1245,3 @@ ctl_open ()
control.url->string);
- exit (EX_UNAVAILABLE);
+ return -1;
}
@@ -1270,3 +1252,3 @@ ctl_open ()
control.url->string, strerror (errno));
- exit (EX_UNAVAILABLE);
+ return -1;
}
@@ -1274,2 +1256,4 @@ ctl_open ()
register_socket (fd, ctl_accept, NULL, NULL, NULL);
+
+ return 0;
}
diff --git a/src/pies.c b/src/pies.c
index 875684a..09f9fab 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -60,2 +60,7 @@ char **mailer_argv;
+char *default_control_url[2] = {
+ DEFAULT_PIES_CONTROL_URL,
+ DEFAULT_INIT_CONTROL_URL
+};
+
struct config_file
@@ -1752,2 +1757,14 @@ config_parse (char const *name)
+ 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);
@@ -1933,2 +1950,4 @@ pies_check_status (pid_t *ppid)
+#define pies_control_url() control.url->string
+
void
@@ -2232,3 +2251,3 @@ main (int argc, char **argv)
}
-
+ setenv ("PIES_INSTANCE", instance, 1);
log_tag = instance;
@@ -2373,5 +2392,8 @@ main (int argc, char **argv)
- if (!init_process)
- {
+ if (init_process)
ctl_open ();
+ else
+ {
+ 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
@@ -294,2 +294,3 @@ extern size_t pies_master_argc;
extern char **pies_master_argv;
+extern char *default_control_url[2];
@@ -551,3 +552,2 @@ 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
@@ -97,2 +97,3 @@ 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
@@ -190,13 +190,6 @@ parse_config ()
{
- 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.