aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
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 (limited to 'src')
-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
6 files changed, 38 insertions, 37 deletions
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
@@ -59,2 +59,7 @@ int mailer_argc;
char **mailer_argv;
+
+char *default_control_url[2] = {
+ DEFAULT_PIES_CONTROL_URL,
+ DEFAULT_INIT_CONTROL_URL
+};
@@ -1751,2 +1756,14 @@ config_parse (char const *name)
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);
+ }
+ }
@@ -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
{
- 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
@@ -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.