|
7 | 7 | #include <errno.h> |
8 | 8 | #include <getopt.h> |
9 | 9 | #include <inttypes.h> |
| 10 | +#include <signal.h> |
10 | 11 |
|
11 | 12 | #include "cli_common.h" |
12 | 13 | #include "cli_root.h" |
|
15 | 16 | #include "commandline.h" |
16 | 17 | #include "env_utils.h" |
17 | 18 | #include "log.h" |
| 19 | +#include "pidfile.h" |
18 | 20 | #include "parsing_utils.h" |
19 | 21 | #include "string_utils.h" |
20 | 22 |
|
@@ -368,14 +370,40 @@ cli_config_set(int argc, char **argv) |
368 | 370 | } |
369 | 371 |
|
370 | 372 | /* now read the value from just written file */ |
371 | | - if (config_get_setting(&config, cfname, argv[0], value, BUFSIZE)) |
| 373 | + if (!config_get_setting(&config, cfname, argv[0], value, BUFSIZE)) |
372 | 374 | { |
373 | | - fformat(stdout, "%s\n", value); |
| 375 | + log_error("Failed to lookup option %s", argv[0]); |
| 376 | + exit(EXIT_CODE_BAD_ARGS); |
| 377 | + } |
| 378 | + |
| 379 | + /* now signal the pgcopydb process to reload config (SIGHUP) */ |
| 380 | + if (file_exists(copySpecs.cfPaths.pidfile)) |
| 381 | + { |
| 382 | + pid_t pid; |
| 383 | + |
| 384 | + log_debug("Reading pidfile \"%s\"", copySpecs.cfPaths.pidfile); |
| 385 | + |
| 386 | + if (!read_pidfile(copySpecs.cfPaths.pidfile, &pid)) |
| 387 | + { |
| 388 | + exit(EXIT_CODE_INTERNAL_ERROR); |
| 389 | + } |
| 390 | + |
| 391 | + log_notice("Signaling process %d with SIGHUP", pid); |
| 392 | + |
| 393 | + if (kill(pid, SIGHUP) != 0) |
| 394 | + { |
| 395 | + log_error("Failed to send SIGHUP signal to process %d: %m", pid); |
| 396 | + exit(EXIT_CODE_INTERNAL_ERROR); |
| 397 | + } |
374 | 398 | } |
375 | 399 | else |
376 | 400 | { |
377 | | - log_error("Failed to lookup option %s", argv[0]); |
378 | | - exit(EXIT_CODE_BAD_ARGS); |
| 401 | + log_error("Failed to send SIGHUP: pidfile does not exists: \"%s\"", |
| 402 | + copySpecs.cfPaths.pidfile); |
| 403 | + exit(EXIT_CODE_INTERNAL_ERROR); |
379 | 404 | } |
| 405 | + |
| 406 | + /* finally output the value we just set and signaled */ |
| 407 | + fformat(stdout, "%s\n", value); |
380 | 408 | } |
381 | 409 | } |
0 commit comments