aboutsummaryrefslogtreecommitdiff
path: root/jabberd/main.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2007-06-04 12:35:54 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2007-06-04 12:35:54 +0000
commite7ffd40909f60b2230879e2767ad0a057198eb9f (patch)
tree4572199ebe2170e6abc97b77d4e1c4e496009079 /jabberd/main.c
parentc4687307a4e3f4d08d5da97c0537fe0ce95960d1 (diff)
downloadgsc-e7ffd40909f60b2230879e2767ad0a057198eb9f.tar.gz
gsc-e7ffd40909f60b2230879e2767ad0a057198eb9f.tar.bz2
Implement long options, running instance control and component dependency checking
git-svn-id: file:///svnroot/gsc/trunk@254 d2de0444-eb31-0410-8365-af798a554d48
Diffstat (limited to 'jabberd/main.c')
-rw-r--r--jabberd/main.c412
1 files changed, 362 insertions, 50 deletions
diff --git a/jabberd/main.c b/jabberd/main.c
index e2a00ac..476abd8 100644
--- a/jabberd/main.c
+++ b/jabberd/main.c
@@ -28,7 +28,9 @@ char *syslog_tag = "jabberd";
28int log_facility = LOG_LOCAL7; 28int log_facility = LOG_LOCAL7;
29int x_argc; 29int x_argc;
30char **x_argv; 30char **x_argv;
31char *pidfile; 31char *pidfile = STATEDIR "/jabberd.pid";
32char *ctlfile = STATEDIR "/.jabberd.ctl";
33char *statfile = STATEDIR "/.jabberd.stat";
32unsigned long shutdown_timeout = 5; 34unsigned long shutdown_timeout = 5;
33mode_t jabberd_umask = 037; 35mode_t jabberd_umask = 037;
34 36
@@ -131,17 +133,27 @@ version ()
131void 133void
132usage () 134usage ()
133{ 135{
134 printf ("usage: jabberd [-Dfehv][-c config][-p pidfile]\n"); 136 printf ("usage: jabberd [-Dfehv][-c config][-r tag [tag...]]\n");
135 printf ("jabberd -- A dispatcher program for jabber 2.x\n"); 137 printf ("jabberd -- A dispatcher program for jabber 2.x\n");
136 printf ("\n"); 138 printf ("\n");
137 printf ("Options:\n"); 139 printf ("General-purpose options:\n");
138 printf (" -c FILE use this configuration file\n"); 140 printf (" -c, --config-file=FILE use this configuration file\n");
139 printf (" -D increase debugging level\n"); 141 printf (" -D, --debug increase debugging level\n");
140 printf (" -f run in foreground mode (implies -e)\n"); 142 printf (" -e, --stderr use standard error for diagnostics output\n");
141 printf (" -e use standard error for diagnostics output\n"); 143 printf (" -f, --foreground run in foreground mode (implies -e)\n");
142 printf (" -h display this help list\n"); 144 printf (" --force start up even if another copy seems to be running\n");
143 printf (" -p FILE write master process ID to FILE\n"); 145
144 printf (" -v display program version\n"); 146 printf ("\nControlling running instance:\n");
147 printf (" --status display status information\n");
148 printf (" --stop stop the running copy\n");
149 printf (" --reload, --hup reload the running copy\n");
150 printf (" -r, --restart tag [tag...] restart named components\n");
151
152 printf ("\nInformational options:\n");
153 printf (" -h, --help display this help list\n");
154 printf (" -v, --version display program version\n");
155
156
145 printf ("\n"); 157 printf ("\n");
146 printf ("Report bugs to <%s>\n", PACKAGE_BUGREPORT); 158 printf ("Report bugs to <%s>\n", PACKAGE_BUGREPORT);
147} 159}
@@ -356,6 +368,18 @@ cfg_pidfile (struct cfg_file *file, char *kw, char *val, void *unused)
356} 368}
357 369
358void 370void
371cfg_ctlfile (struct cfg_file *file, char *kw, char *val, void *unused)
372{
373 ctlfile = strdup (val);
374}
375
376void
377cfg_statfile (struct cfg_file *file, char *kw, char *val, void *unused)
378{
379 ctlfile = strdup (val);
380}
381
382void
359cfg_umask (struct cfg_file *file, char *kw, char *val, void *unused) 383cfg_umask (struct cfg_file *file, char *kw, char *val, void *unused)
360{ 384{
361 char *p; 385 char *p;
@@ -390,60 +414,76 @@ cfg_prog (struct cfg_file *file, char *kw, char *val, void *unused)
390 register_jabber_process (prog, val); 414 register_jabber_process (prog, val);
391} 415}
392 416
393struct exec_rec { 417struct transport_rec
418{
394 char *tag; 419 char *tag;
395 char *command; 420 char *command;
396 int facility; 421 int facility;
397 int retr[2]; 422 int retr[2];
423 int depc;
424 char **depv;
398}; 425};
399 426
400static void 427static void
401cfg_exec_command (struct cfg_file *file, char *kw, char *val, void *data) 428cfg_transport_command (struct cfg_file *file, char *kw, char *val, void *data)
402{ 429{
403 struct exec_rec *prec = data; 430 struct transport_rec *prec = data;
404 prec->command = strdup (val); 431 prec->command = strdup (val);
405} 432}
406 433
407void 434void
408cfg_exec_facility (struct cfg_file *file, char *kw, char *val, void *data) 435cfg_transport_facility (struct cfg_file *file, char *kw, char *val, void *data)
409{ 436{
410 struct exec_rec *prec = data; 437 struct transport_rec *prec = data;
411 if (str_to_facility (val, &prec->facility)) 438 if (str_to_facility (val, &prec->facility))
412 logmsg (LOG_ERR, "%s:%u: Unknown facility `%s'", 439 logmsg (LOG_ERR, "%s:%u: Unknown facility `%s'",
413 config_file, file->line, val); 440 config_file, file->line, val);
414} 441}
415 442
416void 443void
417cfg_exec_stdout (struct cfg_file *file, char *kw, char *val, void *data) 444cfg_transport_stdout (struct cfg_file *file, char *kw, char *val, void *data)
418{ 445{
419 struct exec_rec *prec = data; 446 struct transport_rec *prec = data;
420 if (str_to_priority (val, &prec->retr[RETR_OUT])) 447 if (str_to_priority (val, &prec->retr[RETR_OUT]))
421 logmsg (LOG_ERR, "%s:%u: Unknown priority `%s'", 448 logmsg (LOG_ERR, "%s:%u: Unknown priority `%s'",
422 config_file, file->line, val); 449 config_file, file->line, val);
423} 450}
424 451
425void 452void
426cfg_exec_stderr (struct cfg_file *file, char *kw, char *val, void *data) 453cfg_transport_stderr (struct cfg_file *file, char *kw, char *val, void *data)
427{ 454{
428 struct exec_rec *prec = data; 455 struct transport_rec *prec = data;
429 if (str_to_priority (val, &prec->retr[RETR_ERR])) 456 if (str_to_priority (val, &prec->retr[RETR_ERR]))
430 logmsg (LOG_ERR, "%s:%u: Unknown priority `%s'", 457 logmsg (LOG_ERR, "%s:%u: Unknown priority `%s'",
431 config_file, file->line, val); 458 config_file, file->line, val);
432} 459}
433 460
434void 461void
435cfg_exec (struct cfg_file *file, char *kw, char *val, void *unused) 462cfg_transport_depend (struct cfg_file *file, char *kw, char *val, void *data)
463{
464 struct transport_rec *prec = data;
465 int rc;
466 if (rc = argcv_get (val, NULL, NULL, &prec->depc, &prec->depv))
467 {
468 logmsg (LOG_ERR, "%s:%u: cannot split dependency line: %s",
469 config_file, file->line, strerror (rc));
470 }
471}
472
473void
474cfg_transport (struct cfg_file *file, char *kw, char *val, void *unused)
436{ 475{
437 int rc; 476 int rc;
438 int argc; 477 int argc;
439 char **argv; 478 char **argv;
440 479
441 struct exec_rec rec; 480 struct transport_rec rec;
442 static struct kw_handler kwtab[] = { 481 static struct kw_handler kwtab[] = {
443 { "command", cfg_exec_command }, 482 { "command", cfg_transport_command },
444 { "stdout", cfg_exec_stdout }, 483 { "stdout", cfg_transport_stdout },
445 { "stderr", cfg_exec_stderr }, 484 { "stderr", cfg_transport_stderr },
446 { "facility", cfg_exec_facility }, 485 { "facility", cfg_transport_facility },
486 { "depend", cfg_transport_depend },
447 { NULL } 487 { NULL }
448 }; 488 };
449 memset (&rec, 0, sizeof rec); 489 memset (&rec, 0, sizeof rec);
@@ -459,9 +499,10 @@ cfg_exec (struct cfg_file *file, char *kw, char *val, void *unused)
459 config_file, file->line, strerror (rc)); 499 config_file, file->line, strerror (rc));
460 return; 500 return;
461 } 501 }
462 register_prog (rec.tag, argv, rec.retr); 502 register_transport (rec.tag, argv, rec.retr, rec.depv);
463 free (rec.tag); 503 free (rec.tag);
464 free (rec.command); 504 free (rec.command);
505 argcv_free (rec.depc, rec.depv);
465 argcv_free (argc, argv); 506 argcv_free (argc, argv);
466} 507}
467 508
@@ -482,9 +523,12 @@ struct kw_handler kw_handler[] = {
482 { "user", cfg_user }, 523 { "user", cfg_user },
483 { "group", cfg_group }, 524 { "group", cfg_group },
484 { "pidfile", cfg_pidfile }, 525 { "pidfile", cfg_pidfile },
526 { "ctlfile", cfg_ctlfile },
527 { "statfile", cfg_statfile },
485 { "umask", cfg_umask }, 528 { "umask", cfg_umask },
486 { "prog", cfg_prog }, 529 { "prog", cfg_prog },
487 { "exec", cfg_exec }, 530 { "transport", cfg_transport },
531 { "exec", cfg_transport },
488 { "shutdown-timeout", cfg_shutdown_timeout }, 532 { "shutdown-timeout", cfg_shutdown_timeout },
489 { NULL } 533 { NULL }
490}; 534};
@@ -516,24 +560,59 @@ parse_config ()
516void 560void
517pidfile_write () 561pidfile_write ()
518{ 562{
519 if (pidfile) 563 FILE *fp = fopen (pidfile, "w");
564 if (!fp)
565 {
566 logmsg (LOG_CRIT, "cannot open pidfile `%s' for writing: %s",
567 pidfile, strerror (errno));
568 return;
569 }
570 fprintf (fp, "%lu\n", (unsigned long) getpid ());
571 fclose (fp);
572}
573
574pid_t
575pidfile_read (int must_exist)
576{
577 int c;
578 pid_t n = 0;
579 FILE *fp = fopen (pidfile, "r");
580 if (!fp)
520 { 581 {
521 FILE *fp = fopen (pidfile, "w"); 582 if (must_exist && errno != ENOENT)
522 if (!fp) 583 logmsg (LOG_ERR, "cannot open pid file `%s': %s",
584 pidfile,