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 @@
1/ABOUT-NLS~
1*.a 2*.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([
131 131
132AC_SUBST([DEFAULT_CONTROL_URL],[unix:///tmp/%s.ctl]) 132AC_SUBST([DEFAULT_PIES_CONTROL_URL],['unix:///tmp/$${PIES_INSTANCE}.ctl'])
133AC_ARG_VAR([DEFAULT_CONTROL_URL], 133AC_ARG_VAR([DEFAULT_PIES_CONTROL_URL],
134 [URL of the default control socket])
135AC_SUBST([DEFAULT_INIT_CONTROL_URL],['unix:///dev/init.ctl'])
136AC_ARG_VAR([DEFAULT_INIT_CONTROL_URL],
134 [URL of the default control socket]) 137 [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
73 73
74int pies_basic_url_create (struct pies_url **purl, const char *str);
74int pies_url_create (struct pies_url **purl, const char *str); 75int 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)
327int 327int
328pies_url_create (struct pies_url **purl, const char *str) 328pies_basic_url_create (struct pies_url **purl, const char *str)
329{ 329{
@@ -346,2 +346,19 @@ pies_url_create (struct pies_url **purl, const char *str)
346} 346}
347
348extern char **environ;
349
350int
351pies_url_create (struct pies_url **purl, const char *str)
352{
353 struct wordsplit ws;
354 int rc;
355
356 ws.ws_env = (const char**) environ;
357 if (wordsplit (str, &ws,
358 WRDSF_NOCMD | WRDSF_QUOTE | WRDSF_NOSPLIT | WRDSF_ENV))
359 return -1;
360 rc = pies_basic_url_create (purl, ws.ws_wordv[0]);
361 wordsplit_free (&ws);
362 return rc;
363}
347 364
diff --git a/po/.gitignore b/po/.gitignore
index d00dd8d..b45a955 100644
--- a/po/.gitignore
+++ b/po/.gitignore
@@ -1 +1,2 @@
1/Rules-quot~
1/Makevars.template~ 2/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=\
89 -DDEFAULT_STATE_DIR=\"$(pkgstatedir)\"\ 89 -DDEFAULT_STATE_DIR=\"$(pkgstatedir)\"\
90 -DDEFAULT_CONTROL_URL=\"$(DEFAULT_CONTROL_URL)\" 90 -DDEFAULT_PIES_CONTROL_URL='"$(DEFAULT_PIES_CONTROL_URL)"'\
91 -DDEFAULT_INIT_CONTROL_URL='"$(DEFAULT_INIT_CONTROL_URL)"'
91 92
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)
1235 1235
1236char const * 1236int
1237pies_control_url (void) 1237ctl_open (void)
1238{
1239 if (!control.url)
1240 {
1241 char *str = xasprintf (DEFAULT_CONTROL_URL, instance);
1242 if (pies_url_create (&control.url, str))
1243 {
1244 logmsg (LOG_CRIT, _("%s: cannot create URL: %s"),
1245 str, strerror (errno));
1246 exit (EX_OSERR);
1247 }
1248 free (str);
1249 }
1250 return control.url->string;
1251}
1252
1253void
1254ctl_open ()
1255{ 1238{
@@ -1257,3 +1240,2 @@ ctl_open ()
1257 1240
1258 pies_control_url ();
1259 fd = create_socket (control.url, SOCK_STREAM, NULL, 077); 1241 fd = create_socket (control.url, SOCK_STREAM, NULL, 077);
@@ -1263,3 +1245,3 @@ ctl_open ()
1263 control.url->string); 1245 control.url->string);
1264 exit (EX_UNAVAILABLE); 1246 return -1;
1265 } 1247 }
@@ -1270,3 +1252,3 @@ ctl_open ()
1270 control.url->string, strerror (errno)); 1252 control.url->string, strerror (errno));
1271 exit (EX_UNAVAILABLE); 1253 return -1;
1272 } 1254 }
@@ -1274,2 +1256,4 @@ ctl_open ()
1274 register_socket (fd, ctl_accept, NULL, NULL, NULL); 1256 register_socket (fd, ctl_accept, NULL, NULL, NULL);
1257
1258 return 0;
1275} 1259}
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;
59char **mailer_argv; 59char **mailer_argv;
60
61char *default_control_url[2] = {
62 DEFAULT_PIES_CONTROL_URL,
63 DEFAULT_INIT_CONTROL_URL
64};
60 65
@@ -1751,2 +1756,14 @@ config_parse (char const *name)
1751 config_error (); 1756 config_error ();
1757
1758 if (!control.url)
1759 {
1760 char const *str = default_control_url[init_process];
1761 if (pies_url_create (&control.url, str))
1762 {
1763 logmsg (LOG_CRIT, _("%s: cannot create control URL: %s"),
1764 str, strerror (errno));
1765 if (!init_process)
1766 exit (EX_OSERR);
1767 }
1768 }
1752 1769
@@ -1933,2 +1950,4 @@ pies_check_status (pid_t *ppid)
1933 1950
1951#define pies_control_url() control.url->string
1952
1934void 1953void
@@ -2232,3 +2251,3 @@ main (int argc, char **argv)
2232 } 2251 }
2233 2252 setenv ("PIES_INSTANCE", instance, 1);
2234 log_tag = instance; 2253 log_tag = instance;
@@ -2373,5 +2392,8 @@ main (int argc, char **argv)
2373 2392
2374 if (!init_process) 2393 if (init_process)
2394 ctl_open ();
2395 else
2375 { 2396 {
2376 ctl_open (); 2397 if (ctl_open ())
2398 exit (EX_UNAVAILABLE);
2377 create_pidfile (pidfile); 2399 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;
294extern char **pies_master_argv; 294extern char **pies_master_argv;
295extern char *default_control_url[2];
295 296
@@ -551,3 +552,2 @@ extern struct control control;
551 552
552void ctl_open(void); 553int ctl_open(void);
553char const *pies_control_url (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)
97 GETOPT(argc, argv, *index) 97 GETOPT(argc, argv, *index)
98 setenv ("PIES_INSTANCE", instance, 1);
98} 99}
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 ()
190 { 190 {
191 int rc; 191 if (pies_url_create (&url, DEFAULT_PIES_CONTROL_URL))
192 size_t len = 0;
193 file_name = NULL;
194 grecs_asprintf (&file_name, &len, DEFAULT_CONTROL_URL, instance);
195 rc = pies_url_create (&url, file_name);
196 free (file_name);
197
198 if (rc)
199 { 192 {
200 grecs_error (NULL, 0, _("%s: cannot create URL: %s"), 193 grecs_error (NULL, 0, _("%s: cannot create URL: %s"),
201 DEFAULT_CONTROL_URL, strerror (errno)); 194 DEFAULT_PIES_CONTROL_URL, strerror (errno));
202 exit (EX_SOFTWARE); 195 exit (EX_SOFTWARE);

Return to:

Send suggestions and report system problems to the System administrator.