diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/ctl.c | 28 | ||||
-rw-r--r-- | src/pies.c | 28 | ||||
-rw-r--r-- | src/pies.h | 4 | ||||
-rw-r--r-- | src/piesctl-cl.opt | 1 | ||||
-rw-r--r-- | src/piesctl.c | 11 |
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 | ||
92 | AM_YFLAGS=-dvt -pmeta1 | 93 | AM_YFLAGS=-dvt -pmeta1 |
93 | AM_LFLAGS=-dvp -Pmeta1 -olex.yy.c | 94 | AM_LFLAGS=-dvp -Pmeta1 -olex.yy.c |
@@ -1233,45 +1233,29 @@ ctl_accept (int socket, void *data) | |||
1233 | return 0; | 1233 | return 0; |
1234 | } | 1234 | } |
1235 | 1235 | ||
1236 | char const * | 1236 | int |
1237 | pies_control_url (void) | 1237 | ctl_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 | |||
1253 | void | ||
1254 | ctl_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 | ||
1277 | static void | 1261 | static void |
@@ -57,6 +57,11 @@ char *mailer_program = "/usr/sbin/sendmail"; | |||
57 | char *mailer_command_line = "/usr/sbin/sendmail -oi -t"; | 57 | char *mailer_command_line = "/usr/sbin/sendmail -oi -t"; |
58 | int mailer_argc; | 58 | int mailer_argc; |
59 | char **mailer_argv; | 59 | char **mailer_argv; |
60 | |||
61 | char *default_control_url[2] = { | ||
62 | DEFAULT_PIES_CONTROL_URL, | ||
63 | DEFAULT_INIT_CONTROL_URL | ||
64 | }; | ||
60 | 65 | ||
61 | struct config_file | 66 | struct 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 | |||
1934 | void | 1953 | void |
1935 | request_restart_components (size_t cc, char **cv) | 1954 | request_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 | ||
@@ -292,6 +292,7 @@ extern int dfl_level; | |||
292 | 292 | ||
293 | extern size_t pies_master_argc; | 293 | extern size_t pies_master_argc; |
294 | extern char **pies_master_argv; | 294 | extern char **pies_master_argv; |
295 | extern char *default_control_url[2]; | ||
295 | 296 | ||
296 | enum config_syntax | 297 | enum config_syntax |
297 | { | 298 | { |
@@ -549,5 +550,4 @@ struct control | |||
549 | 550 | ||
550 | extern struct control control; | 551 | extern struct control control; |
551 | 552 | ||
552 | void ctl_open(void); | 553 | int ctl_open(void); |
553 | char 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 | |||
95 | parse_options(int argc, char *argv[], int *index) | 95 | parse_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 | } |