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
@@ -87,7 +87,8 @@ AM_CPPFLAGS=\
87 -DDEFAULT_VERSION_INCLUDE_DIR=\"$(incdir)\"\ 87 -DDEFAULT_VERSION_INCLUDE_DIR=\"$(incdir)\"\
88 -DDEFAULT_INCLUDE_DIR=\"$(pkgdatadir)/include\"\ 88 -DDEFAULT_INCLUDE_DIR=\"$(pkgdatadir)/include\"\
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
92AM_YFLAGS=-dvt -pmeta1 93AM_YFLAGS=-dvt -pmeta1
93AM_LFLAGS=-dvp -Pmeta1 -olex.yy.c 94AM_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)
1233 return 0; 1233 return 0;
1234} 1234}
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{
1256 int fd; 1239 int fd;
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);
1260 if (fd == -1) 1242 if (fd == -1)
1261 { 1243 {
1262 logmsg (LOG_CRIT, _("can't create control socket %s"), 1244 logmsg (LOG_CRIT, _("can't create control socket %s"),
1263 control.url->string); 1245 control.url->string);
1264 exit (EX_UNAVAILABLE); 1246 return -1;
1265 } 1247 }
1266 1248
1267 if (listen (fd, 8)) 1249 if (listen (fd, 8))
1268 { 1250 {
1269 logmsg (LOG_CRIT, _("can't listen on control socket %s: %s"), 1251 logmsg (LOG_CRIT, _("can't listen on control socket %s: %s"),
1270 control.url->string, strerror (errno)); 1252 control.url->string, strerror (errno));
1271 exit (EX_UNAVAILABLE); 1253 return -1;
1272 } 1254 }
1273 1255
1274 register_socket (fd, ctl_accept, NULL, NULL, NULL); 1256 register_socket (fd, ctl_accept, NULL, NULL, NULL);
1257
1258 return 0;
1275} 1259}
1276 1260
1277static void 1261static 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";
57char *mailer_command_line = "/usr/sbin/sendmail -oi -t"; 57char *mailer_command_line = "/usr/sbin/sendmail -oi -t";
58int mailer_argc; 58int 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
61struct config_file 66struct config_file
62{ 67{
@@ -1749,6 +1754,18 @@ config_parse (char const *name)
1749 1754
1750 if (grecs_tree_process (tree, pies_keywords)) 1755 if (grecs_tree_process (tree, pies_keywords))
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
1753 grecs_tree_free (tree); 1770 grecs_tree_free (tree);
1754} 1771}
@@ -1931,6 +1948,8 @@ pies_check_status (pid_t *ppid)
1931 return pies_status_running; 1948 return pies_status_running;
1932} 1949}
1933 1950
1951#define pies_control_url() control.url->string
1952
1934void 1953void
1935request_restart_components (size_t cc, char **cv) 1954request_restart_components (size_t cc, char **cv)
1936{ 1955{
@@ -2230,7 +2249,7 @@ main (int argc, char **argv)
2230 else 2249 else
2231 instance++; 2250 instance++;
2232 } 2251 }
2233 2252 setenv ("PIES_INSTANCE", instance, 1);
2234 log_tag = instance; 2253 log_tag = instance;
2235 2254
2236 if (!init_process) 2255 if (!init_process)
@@ -2371,9 +2390,12 @@ main (int argc, char **argv)
2371 diag_setup (DIAG_TO_SYSLOG); 2390 diag_setup (DIAG_TO_SYSLOG);
2372 } 2391 }
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);
2378 } 2400 }
2379 2401
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;
292 292
293extern size_t pies_master_argc; 293extern size_t pies_master_argc;
294extern char **pies_master_argv; 294extern char **pies_master_argv;
295extern char *default_control_url[2];
295 296
296enum config_syntax 297enum config_syntax
297 { 298 {
@@ -549,5 +550,4 @@ struct control
549 550
550extern struct control control; 551extern 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
@@ -95,6 +95,7 @@ void
95parse_options(int argc, char *argv[], int *index) 95parse_options(int argc, char *argv[], int *index)
96{ 96{
97 GETOPT(argc, argv, *index) 97 GETOPT(argc, argv, *index)
98 setenv ("PIES_INSTANCE", instance, 1);
98} 99}
99 100
100 101
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 ()
188 url = default_url; 188 url = default_url;
189 else 189 else
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);
203 } 196 }
204 } 197 }

Return to:

Send suggestions and report system problems to the System administrator.