summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2010-01-28 22:07:31 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2010-01-28 22:07:31 (GMT)
commitdf4a2a61ce0cde5190def22309e9807cb5a56ab0 (patch) (side-by-side diff)
tree364eb6562f6bd41eb3fe0ca15e497a2a76a4b57c
parent5f392fc3cf8e94112ed7b15b2038e51f1b2b3800 (diff)
downloadgsc-df4a2a61ce0cde5190def22309e9807cb5a56ab0.tar.gz
gsc-df4a2a61ce0cde5190def22309e9807cb5a56ab0.tar.bz2
Remove jabberd
git-svn-id: file:///svnroot/gsc/trunk@339 d2de0444-eb31-0410-8365-af798a554d48
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--ChangeLog6
-rw-r--r--Makefile.am3
-rw-r--r--configure.ac3
-rw-r--r--doc/gsc.texi449
-rw-r--r--jabberd/Makefile.am22
-rw-r--r--jabberd/jabberd.h62
-rw-r--r--jabberd/main.c910
-rw-r--r--jabberd/progman.c647
-rw-r--r--mc/trurl.mc15
9 files changed, 15 insertions, 2102 deletions
diff --git a/ChangeLog b/ChangeLog
index 6894c0e..b855c2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1 +1,7 @@
+2010-01-29 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * jabberd: Removed. Use GNU pies instead.
+ * Makefile.am, configure.ac: Update.
+ * doc/gsc.texi: Update.
+
2009-08-03 Sergey Poznyakoff <gray@gnu.org.ua>
diff --git a/Makefile.am b/Makefile.am
index 6215e1f..fcba8a0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -36,3 +36,2 @@ SUBDIRS=\
ppp\
- rc.d\
- jabberd
+ rc.d
diff --git a/configure.ac b/configure.ac
index 97a928d..d9dabeb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -118,4 +118,3 @@ mc
ppp
-rc.d
-jabberd'
+rc.d'
diff --git a/doc/gsc.texi b/doc/gsc.texi
index 29e5e1b..87e1ce5 100644
--- a/doc/gsc.texi
+++ b/doc/gsc.texi
@@ -121,3 +121,2 @@ Root Utilities
* session-cleanup:: Manage PHP Sessions.
-* jabberd:: Jabberd dispatcher daemon.
@@ -127,13 +126,2 @@ firewall
-Jabberd
-
-* jabintro:: Jabberd Operation Overview
-* jabopts:: Command Line Options.
-* jabberd.cfg:: Main Jabberd Configuration File.
-
-Jabberd Configuration File
-
-* cfgstat:: Configuration File Statements
-* example:: An Example of the Configuration file
-
Startup Scripts
@@ -843,3 +831,2 @@ cases, though not always. Such files should probably be inspected after
* session-cleanup:: Manage PHP Sessions.
-* jabberd:: Jabberd dispatcher daemon.
@end menu
@@ -1169,438 +1156,2 @@ actually remove them.
-@node jabberd
-@section Jabberd
-@cindex jabberd
- The @command{jabberd} utility is a dispatcher daemon for
-@samp{Jabberd 2.x}
-(@uref{http://www.jabber.org/software/jabberd2x.shtml}). It is
-intended as a replacement for the similar utility shipped with the
-@samp{jabberd 2.x} package. There were two reasons that urged for the
-replacement: first, the original @command{jabberd} is written in Perl
-and consumes way too many resources because of that. Secondly, it is
-not flexible enough. In particular, it is only able to control jabber
-daemons, but cannot control external transports (such as @acronym{GG}
-or @acronym{GIT}.
-
-@menu
-* jabintro:: Jabberd Operation Overview
-* jabopts:: Command Line Options.
-* jabberd.cfg:: Main Jabberd Configuration File.
-@end menu
-
-@node jabintro
-@subsection Jabberd Operation Overview
-
- The @acronym{GSC} @command{jabberd} is a supervisor daemon that
-starts a number of @dfn{components} and controls their execution.
-A component is either a jabberd core component (as,
-e.g. @command{c2s}) or some external program (e.g. a transport). The
-daemon reads the list of components from its configuration file upon
-startup. By default, the configuration file is named
-@file{jabberd.cfg} and is located in @code{$sysconfdir} directory, but
-its exact location can be overridden at startup (see @option{-c}
-option, below). If run with the root privileges, @command{jabberd}
-switches to the privileges of a selected user (by default
-@samp{jabber}) right after startup. Then, the program changes file
-creation mask to a safe value (the default is @samp{037}). Unless
-explicitly requested to remain in the foreground, the utility detaches
-itself from the controlling terminal and switches to the background.
-The daemon starts the configured components
-in the order of their appearance in the configuration file. The exact
-command line options and arguments for each component are specified
-in the configuration file. If a particular subprocess prints its
-diagnostics on stderr or stdout, you may instruct @command{jabberd} to
-capture and divert it to a particular @command{syslogd}
-priority (@pxref{stdout}). After launching the components
-@command{jabberd} enters its main loop. It sleeps until either some
-component finishes or a signal is delivered. If a component finishes,
-@command{jabberd} scans its internal list to find components that
-depend on the finished one. Each such component is then terminated
-by sending it @acronym{SIGTERM} signal. Then, the finished component and
-its dependent components are started again. If a process is
-restarted more than 10 times within a two minutes interval, it is
-disabled for the next five minutes (the same way the standard
-@acronym{UNIX} @command{init} utility operates).
-
- The @command{jabberd} utility exits if it recieves any of the
-following signals: @acronym{SIGTERM}, @acronym{SIGQUIT},
-@acronym{SIGINT}. It attempts to restart itself if delivered the
-@acronym{SIGHUP} signal. This is possible only if the utility is
-started using its absolute file name. In any case, before exiting,
-the utility shuts down all components @emph{in the reverse
-order} of their appearance in the configuration file. The processes
-are shut down by sending them @acronym{SIGTERM} signals. If a
-component does not exit within a 1 second interval, it is re-sent the
-same signal. This procedure continues until either all components
-terminate or the @dfn{shutdown timeout} interval expires, whichever
-happens first. If the latter happens, any components still left
-running are slayed using @acronym{SIGKILL} signal. The default
-shutdown timeout is 5 seconds and it may be changed using
-@code{shutdown-timeout} configuration file statement (@pxref{cfgstat}).
-
- Two signals are special to @command{jabberd}: @acronym{SIGUSR1}
-and @acronym{SIGUSR2}. The @acronym{SIGUSR1} signal instructs the
-program to shut down and restart a particular component or a set
-of components. The list of components to be restarted is passed to
-the running program via a @dfn{control file} (@pxref{ctlfile}). This
-mechanism is used by @command{jabberd
---restart}. @FIXME-xref{restarting selected components}.
-
- The @acronym{SIGUSR2} signal instructs @command{jabberd} to return
-statistics about running components. It is used by @command{jabberd
---status} (@FIXME-pxref{showing runtime statistics}).
-
-@node jabopts
-@subsection Jabberd Invocation
-@UNREVISED{}
-
- By default, @command{jabberd} attempts to start in @dfn{dispatcher
-mode}, which is described in the previous subsection. If started
-without additional options, the program will use compiled-in defaults.
-Otherwise, the following options may be given:
-
-@table @option
-@item --config-file=@var{file}
-@itemx -c @var{file}
- Use @var{file} as the main configuration file.
-
-@item --debug
-@itemx -D
- Increase debugging level.
-
-@item --foreground
-@itemx -f
- Do not disconnect from the controlling terminal, but run in
-foreground mode instead. This option is mainly useful for debugging.
-It implies @option{-e} (see below).
-
-@item --force
- Attempt to start up even if another instance of @command{jabberd}
-seems to be running.
-
-@item --stderr
-@itemx -e
- Print all diagnostics on the standard output.
-@end table
-
- A set of options may be used to control the running instance of the
-program and request a detailed information about it.
-
-@table @option
-@item --restart @var{tag} [@var{tags}...]
-@itemx -r @var{tag} [@var{tag}...]
- Restart named components. Any number of arguments can be
-specified. Each @var{tag} must correspond to a valid tag in
-@file{jabberd.cfg} file.
-
-@item --status
- Display information about the running instance. Return 0 if the
-instance is running, 1 otherwise.
-
-@smallexample
-$ jabberd --status
-jabberd: [INFO] jabberd is running; PID 537
-retranslator jit/stderr 548
-retranslator jit/stdout 547
-retranslator ggtrans/stderr 545
-retranslator ggtrans/stdout 544
-core router 539 router -c /usr/local/etc/jabberd/router.xml
-core resolver 540 resolver -c /usr/local/etc/jabberd/resolver.xml
-core sm 541 sm -c /usr/local/etc/jabberd/sm.xml
-core s2s 542 s2s -c /usr/local/etc/jabberd/s2s.xml
-core c2s 543 c2s -c /usr/local/etc/jabberd/c2s.xml
-transport ggtrans 546 /usr/local/sbin/jggtrans -f
-transport jit 549 /usr/local/bin/jabberd-jit -c /usr/local/etc/jit.xml
-@end smallexample
-
-@item --stop
- Stop the running instance by sending it the @acronym{SIGTERM} signal.
-
-@item --reload
-@item --hup
- Restart the running instance by sending it the @acronym{SIGHUP} signal.
-@end table
-
- The following are informational options:
-
-@table @option
-@item --help
-@itemx -h
- Display a terse usage summary.
-
-@item --version
-@itemx -v
- Print program version and licensing information and exit.
-@end table
-
-@node jabberd.cfg
-@subsection Jabberd Configuration File
-
- The configuration file has a line-oriented syntax. Empty lines are
-ignored. Comments are introduced by a pound sign (@samp{#}),
-everything starting from the first occurrence of @samp{#} up to the
-end of line is ignored.
-
- Configuration statements consist of @dfn{command word} and one or
-several @dfn{arguments}, separated by any amount of whitespace. There
-are @samp{simple} and @samp{compound} configuration statements.
-Simple statements occupy a single line. Compound statements begin
-with a simple statement, occupy several lines, and end with @code{end}
-statement, appearing on a line by itself. Compound statements in turn
-contain another simple statements.
-
- The simplest working @file{jabberd.cfg} file is:
-
-@smallexample
-prog router /usr/local/etc/jabberd/router.xml
-prog resolver /usr/local/etc/jabberd/resolver.xml
-prog sm /usr/local/etc/jabberd/sm.xml
-prog s2s /usr/local/etc/jabberd/s2s.xml
-prog c2s /usr/local/etc/jabberd/c2s.xml
-@end smallexample
-
- This file instructs @command{jabberd} to launch five basic jabber
-components and supply the given configuration files to them. The
-@code{prog} statement is a simple statement taking one to two
-arguments. The first one names the program to lauch, and an optional
-second one specifies its configuration file. All the programs will be
-launched in the order of their appearance in the @file{jabberd.cfg}
-file, and will be shut down in the reverse order. The @code{prog}
-statement is designed expressly to start jabber core programs, it
-should not be used to start third-party programs.
-
- To start third-party programs, e.g. transports, use @code{transport}
-statement. It is a compound statement that has the following
-structure:
-
-@smallexample
-transport @var{tag}
- command @var{command-line}
- depend @var{modlist}
- stdout @var{prio}
- stderr @var{prio}
-end
-@end smallexample
-
- The sub-statement @code{command} specifies the full command line of
-the program. Notice that most transports behave as daemons. If it is
-so, you will have to use a special command line option requiring the
-transport to remain in the foreground (see the transport documentation
-to find this option). If the program prints its diagnostics on the
-standard error, the @code{stderr} statement can be used to capture and
-redirect it to the syslog. For example, @code{stderr debug},
-instructs @command{jabberd} to divert the program's standard error to
-the syslog, using priority @samp{debug}. In this case the log entries
-will be prefixed with @var{tag}, or, if it is absent, with the first
-word of @var{command-line}.
-
- For example, the @acronym{GG} transport can be started using the
-following statement:
-
-@smallexample
-transport ggtrans
- command /usr/local/sbin/jggtrans -f
- depend all
- stdout notice
- stderr notice
-end
-@end smallexample
-
-
- Several configuration statemenst control various aspects of the
-behavior of the @command{jabberd}. For example, @code{user} statement
-instructs it to switch to privileges of the named user after startup.
-By default the utility will switch to the privileges of the user
-@samp{jabberd}, this statement can be used to change that, for
-example:
-
-@smallexample
-user nobody
-@end smallexample
-
- When switching to user privileges, @command{jabberd} retains only
-the main user group, as specified in @file{/etc/passwd} file and drops
-all supplementary groups the user might be a member of. To retain the
-privileges of a supplementary group, name it with @code{group}
-statement. This statement can be used several times, to retain
-several groups. For example, the following statement switches to the
-privileges of user @samp{nobody} and retains two supplementary groups:
-@samp{staff} and @samp{ftp}:
-
-@smallexample
-user nobody
-group staff
-group ftp
-@end smallexample
-
- The following subsubsection describes all configuration file
-statements in detail.
-
-@menu
-* cfgstat:: Configuration File Statements
-* example:: An Example of the Configuration file
-@end menu
-
-@node cfgstat
-@subsubsection Configuration File Statements
-
-@deffn {Jabber Statement} transport [@var{tag}]
-Schedule a third-party program (e.g. a transport) for startup.
-@var{tag} specifies the prefix to identify this program in the
-diagnostic poutput. The @code{transport} statement is a block statement
-that have the following structure:
-
-@smallexample
-transport @var{tag}
- command @var{command-line}
- depend @var{component-list}
- stdout @var{prio}
- stderr @var{prio}
- facility @var{fac}
-end
-@end smallexample
-
-The subordinate statements are:
-
-@deffn {transport statement} command @var{command-line}
-Set the command line of the transport. @var{command-line} is parsed
-much the same way as in shell, except that no variable substitution
-takes place.
-@end deffn
-
-@deffn {transport statement} depend @var{component-list}
-Declare that this module depends on the components listed in
-@var{component-list}. Whenever one of these components is restarted,
-the transport will be restarted as well.
-
-@var{component-list} is either a whitespace-separated list of
-components, or one of the following words: @samp{all}, meaning that
-this transport depends on all core components started before it, and
-@samp{none}, meaning that it does not depend on anything.
-
-The default is @samp{all}.
-@end deffn
-
-@anchor{stdout}
-@deffn {transport statement} stdout @var{prio}
-@deffnx {transport statement} stderr @var{prio}
-Redirect program's standard output (or error, in case of
-@code{stderr}) to the given syslog priority. Allowed values for
-@var{prio} are: @samp{EMERG}, @samp{ALERT}, @samp{CRIT}, @samp{ERR},
-@samp{WARNING}, @samp{NOTICE}, @samp{INFO}, and @samp{DEBUG},
-optionally prefixed with @samp{LOG_}. The string matching is
-case-insensitive.
-@end deffn
-
-@deffn {transport statement} facility @var{facility}
-This statement does nothing. It is reserved for future use.
-
-@deffn {transport statement} pidfile @var{file}
-Remove @var{file} before starting the transport. It may be useful if
-the transport fails to delete its pidfile at the exit.
-@end deffn
-@end deffn
-
-@end deffn
-@deffn {Jabber Statement} group @var{name}
-Retain supplementary group @var{name} after switching to the user's
-privileges.
-@end deffn
-
-@deffn {Jabber Statement} pidfile @var{file}
-Write master process @acronym{ID} to @var{file}
-@end deffn
-
-@anchor{ctlfile}
-@deffn {Jabber Statement} ctlfile @var{file}
-Set location of the control file. This file is used to pass additional
-information to the running daemon program (e.g., when running
-@command{jabberd --restart @var{comp}}). The default value is
-@file{/usr/local/var/jabberd/.jabberd.ctl}.
-@end deffn
-
-@deffn {Jabber Statement} statfile @var{file}
-Set location of the statistics output file. This file is used to pass
-statistics information from the running daemon program (e.g., when running
-@command{jabberd --status}). The default value is
-@file{/usr/local/var/jabberd/.jabberd.stat}.
-@end deffn
-
-@deffn {Jabber Statement} prog @var{command} [@var{config-file}]
-Schedule a jabber core program for startup. The program name is given
-by @var{command} argument. Optional @var{config-file} gives the
-location of its configuration file. The program command line will be
-(parts enclosed by square brackets being optional):
-
-@smallexample
-@var{command} [-c @var{config-file}] [-D]
-@end smallexample
-
- The @option{-D} is given only if the @command{jabberd} debugging
-level is greater than 2 (e.g. when running it as @command{jabberd -DDD}).
-@end deffn
-
-@deffn {Jabber Statement} umask @var{n}
-Set file creation mask to @var{n}. The default umask is @samp{037}.
-@end deffn
-
-@deffn {Jabber Statement} user @var{name}
-Run with this user privileges.
-@end deffn
-
-@deffn {Jabber Statement} shutdown-timeout @var{n}
-Wait @var{n} seconds for all children to shut down.
-@end deffn
-
-@deffn {Jabber Statement} syslog-facility @var{facility}
-Output diagnostics to the given syslog facility. The @var{facility}
-may be one of the following: @samp{USER}, @samp{DAEMON}, @samp{AUTH},
-@samp{AUTHPRIV}, @samp{LOCAL0} through @samp{LOCAL7}, and @samp{MAIL}.
-The string matching is case insensitive. Optionally, @samp{LOG_}
-prefix may be prepended to @var{facility}.
-@end deffn
-
-@deffn {Jabber Statement} syslog-tag @var{tag}
-Mark @command{jabberd} diagnostics with the given syslog tag. By
-default @samp{jabberd} is used.
-@end deffn
-
-@node example
-@subsubsection An Example of @file{jabberd.cfg} file
-
-@smallexample
-# @r{Run as user @samp{jabber}}
-user jabber
-# @r{Retain two supplementary groups:}
-group staff
-group nobody
-
-# @r{Store @acronym{PID} to the given file}
-pidfile /usr/local/var/jabberd/pid/jabberd.pid
-# @r{Wait 10 seconds for the shutdown of the children.}
-shutdown-timeout 10
-
-# @r{Start basic jabberd framework:}
-prog router /usr/local/etc/jabberd/router.xml
-prog resolver /usr/local/etc/jabberd/resolver.xml
-prog sm /usr/local/etc/jabberd/sm.xml
-prog s2s /usr/local/etc/jabberd/s2s.xml
-prog c2s /usr/local/etc/jabberd/c2s.xml
-
-# @r{Start @acronym{GG} transport and capture its output:}
-transport ggtrans
- command /usr/local/sbin/jggtrans -f
- stdout notice
- stderr notice
-end
-
-# @r{Start @acronym{ICQ} transport and capture its output:}
-transport jit
- command /usr/local/bin/jabberd-jit -c /usr/local/etc/jit.xml
- # @r{Ensure the pidfile is removed at the startup.}
- pidfile /usr/local/var/jabberd/pid/jit.pid
- stdout notice
- stderr notice
-end
-@end smallexample
-
@node Sendmail mc Files, Startup Scripts, Root Utilities, Top
diff --git a/jabberd/Makefile.am b/jabberd/Makefile.am
deleted file mode 100644
index 726eeb4..0000000
--- a/jabberd/Makefile.am
+++ b/dev/null
@@ -1,22 +0,0 @@
-# This file is part of GSC
-# Copyright (C) 2005, 2006, 2007 Sergey Poznyakoff
-#
-# GSC is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3, or (at your option)
-# any later version.
-#
-# GSC is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with GSC. If not, see <http://www.gnu.org/licenses/>.
-
-bin_PROGRAMS = jabberd
-jabberd_SOURCES = main.c progman.c jabberd.h
-LDADD = ../lib/libgsc.a ../gnu/libgnu.a
-INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gnu -I../gnu
-AM_CPPFLAGS=-DSYSCONFDIR=\"$(sysconfdir)\"\
- -DSTATEDIR=\"$(localstatedir)/jabberd\"
diff --git a/jabberd/jabberd.h b/jabberd/jabberd.h
deleted file mode 100644
index 1537db4..0000000
--- a/jabberd/jabberd.h
+++ b/dev/null
@@ -1,62 +0,0 @@
-/* jabberd - a dispatcher program for jabber 2.x
- Copyright (C) 2007 Sergey Poznyakoff
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 3 of the License, or (at your
- option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <getopt.h>
-#include <errno.h>
-#include <string.h>
-#include <pwd.h>
-#include <grp.h>
-#include <signal.h>
-
-#include "gsc.h"
-
-#define RETR_OUT 0
-#define RETR_ERR 1
-
-#define TESTTIME 2*60
-#define SLEEPTIME 5*60
-#define MAXSPAWN 10
-
-void register_transport (char *tag, char **argv, int retr[2], char **depv,
- char *pidfile);
-void register_jabber_process (char *cmd, char *cfg);
-void logmsg (int prio, char *fmt, ...);
-void signal_setup (RETSIGTYPE (*sf)(int));
-
-void *emalloc (size_t size);
-
-void progman_start (void);
-void progman_stop (void);
-void progman_cleanup (int);
-void progman_wake_disabled (void);
-void progman_stop_component (const char *);
-void progman_dump_stats (const char *);
-
-extern int debug_level;
-extern char *syslog_tag;
-extern int log_facility;
-extern unsigned long shutdown_timeout;
-
diff --git a/jabberd/main.c b/jabberd/main.c
deleted file mode 100644
index de0551f..0000000
--- a/jabberd/main.c
+++ b/dev/null
@@ -1,910 +0,0 @@
-/* jabberd - a dispatcher program for jabber 2.x
- Copyright (C) 2007 Sergey Poznyakoff
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 3 of the License, or (at your
- option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "jabberd.h"
-
-char *progname;
-char *config_file = SYSCONFDIR "/jabberd.cfg";
-int debug_level = 0;
-int foreground = 0;
-int log_to_stderr = 0;
-char *user = "jabber";
-char *syslog_tag = "jabberd";
-int log_facility = LOG_LOCAL7;
-int x_argc;
-char **x_argv;
-char *pidfile = STATEDIR "/jabberd.pid";
-char *ctlfile = STATEDIR "/.jabberd.ctl";
-char *statfile = STATEDIR "/.jabberd.stat";
-unsigned long shutdown_timeout = 5;
-mode_t jabberd_umask = 037;
-
-void
-syslog_printer (int prio, const char *fmt, va_list ap)
-{
-#if HAVE_VSYSLOG
- vsyslog (prio, fmt, ap);
-#else
- char buf[128];
- vsnprintf (buf, sizeof buf, fmt, ap);
- syslog (prio, "%s", buf);
-#endif
-}
-
-void
-stderr_printer (int prio, const char *fmt, va_list ap)
-{
- const char *p = gsc_syslog_priority_to_str (prio);
- fprintf (stderr, "%s: ", progname);
-
- if (p)
- fprintf (stderr, "[%s] ", p);
-
- vfprintf (stderr, fmt, ap);
- fputc ('\n', stderr);
-}
-
-
-static void (*log_printer) (int prio, const char *fmt, va_list ap) =
- stderr_printer;
-
-void
-logmsg (int prio, char *fmt, ...)
-{
- va_list ap;
- va_start (ap, fmt);
- log_printer (prio, fmt, ap);
- va_end (ap);
-}
-
-void *
-emalloc (size_t size)
-{
- char *p = malloc (size);
- if (!p)
- {
- logmsg (LOG_EMERG, "%s", strerror (errno));
- exit (1);
- }
- return p;
-}
-
-void
-usage ()
-{
- printf ("usage: jabberd [-Dfehv][-c config][-r tag [tag...]]\n");
- printf ("jabberd -- A dispatcher program for jabber 2.x\n");
- printf ("\n");
- printf ("General-purpose options:\n");
- printf (" -c, --config-file=FILE use this configuration file\n");
- printf (" -D, --debug increase debugging level\n");
- printf (" -e, --stderr use standard error for diagnostics output\n");
- printf (" -f, --foreground run in foreground mode (implies -e)\n");
- printf (" --force start up even if another copy seems to be running\n");
-
- printf ("\nControlling running instance:\n");
- printf (" --status display status information\n");
- printf (" --stop stop the running copy\n");
- printf (" --reload, --hup reload the running copy\n");
- printf (" -r, --restart tag [tag...] restart named components\n");
-
- printf ("\nInformational options:\n");
- printf (" -h, --help display this help list\n");
- printf (" -v, --version display program version\n");
-
-
- printf ("\n");
- printf ("Report bugs to <%s>\n", PACKAGE_BUGREPORT);
-}
-
-
-/* Configuration file handling */
-
-void
-cfg_syslog_tag (gsc_config_file_t *file, char *kw, char *val, void *unused)
-{
- syslog_tag = strdup (val);
-}
-
-void
-cfg_syslog_facility (gsc_config_file_t *file, char *kw, char *val, void *unused)
-{
- if (gsc_str_to_syslog_facility (val, &log_facility))
- file->error_msg (file->file_name, file->line, "Unknown facility `%s'",
- val);
-}
-
-void
-cfg_user (gsc_config_file_t *file, char *kw, char *val, void *unused)
-{
- struct passwd *pwd = getpwnam (val);
- if (!pwd)
- file->error_msg (file->file_name, file->line, "no such user `%s'",
- val);
- else if (pwd->pw_uid == 0)
- file->error_msg (file->file_name, file->line, "user `%s' has zero UID",
- val);
- else
- user = strdup (val);
-}
-
-struct group_list
-{
- struct group_list *next;
- gid_t gid;
-};
-
-static struct group_list *group_list;
-
-void
-cfg_group (gsc_config_file_t *file, char *kw, char *val, void *unused)
-{
- struct group *group = getgrnam (val);
- if (group)
- {
- struct group_list *p = emalloc (sizeof *p);
- p->gid = group->gr_gid;
- p->next = group_list;
- group_list = p;
- }
- else
- file->error_msg (file->file_name, file->line, "unknown group `%s'",
- val);
-}
-
-void
-cfg_pidfile (gsc_config_file_t *file, char *kw, char *val, void *unused)
-{
- pidfile = strdup (val);
-}
-
-void
-cfg_ctlfile (gsc_config_file_t *file, char *kw, char *val, void *unused)
-{
- ctlfile = strdup (val);
-}
-
-void
-cfg_statfile (gsc_config_file_t *file, char *kw, char *val, void *unused)
-{
- ctlfile = strdup (val);
-}
-
-void
-cfg_umask (gsc_config_file_t *file, char *kw, char *val, void *unused)
-{
- char *p;
- unsigned long n = strtoul (val, &p, 8);
- if (*p)
- file->error_msg (file->file_name, file->line,
- "invalid umask; stopped near `%s'", p);
- else
- jabberd_umask = (mode_t) n;
-}
-
-void
-cfg_prog (gsc_config_file_t *file, char *kw, char *val, void *unused)
-{
- char *prog = val;
- char *p = val;
-
- for (; *p && !isspace (*p); p++)
- ;
-
- if (*p)
- {
- *p++ = 0;
- for (; *p && isspace (*p); p++)
- ;
-
- val = p;
- }
- else
- val = 0;
-
- register_jabber_process (prog, val);
-}
-
-struct transport_rec
-{
- char *tag;
- char *command;
- int facility;
- int retr[2];
- int depc;
- char **depv;
- char *pidfile;
-};
-
-static void
-cfg_transport_command (gsc_config_file_t *file, char *kw, char *val, void *data)
-{
- struct transport_rec *prec = data;
- prec->command = strdup (val);
-}
-
-void
-cfg_transport_facility (gsc_config_file_t *file, char *kw, char *val, void *data)
-{
- struct transport_rec *prec = data;
- if (gsc_str_to_syslog_facility (val, &prec->facility))
- file->error_msg (file->file_name, file->line,
- "Unknown facility `%s'",
- val);
-}
-
-void
-cfg_transport_stdout (gsc_config_file_t *file, char *kw, char *val, void *data)
-{
- struct transport_rec *prec = data;
- if (gsc_str_to_syslog_priority (val, &prec->retr[RETR_OUT]))
- file->error_msg (file->file_name, file->line, "Unknown priority `%s'",
- val);
-}
-
-void
-cfg_transport_stderr (gsc_config_file_t *file, char *kw, char *val, void *data)
-{
- struct transport_rec *prec = data;
- if (gsc_str_to_syslog_priority (val, &prec->retr[RETR_ERR]))
- file->error_msg (file->file_name, file->line, "Unknown priority `%s'",
- val);
-}
-
-void
-cfg_transport_depend (gsc_config_file_t *file, char *kw, char *val, void *data)
-{
- struct transport_rec *prec = data;
- int rc;
- if (rc = argcv_get (val, NULL, NULL, &prec->depc, &prec->depv))
- file->error_msg (file->file_name, file->line,
- "cannot split dependency line: %s",
- strerror (rc));
-}
-
-void
-cfg_transport_pidfile (gsc_config_file_t *file, char *kw, char *val,
- void *data)
-{
- struct transport_rec *prec = data;
- prec->pidfile = strdup (val);
-}
-
-void
-cfg_transport (gsc_config_file_t *file, char *kw, char *val, void *unused)
-{
- int rc;
- int argc;
- char **argv;
-
- struct transport_rec rec;
- static struct gsc_config_keyword kwtab[] = {
- { "command", cfg_transport_command },
- { "stdout", cfg_transport_stdout },
- { "stderr", cfg_transport_stderr },
- { "facility", cfg_transport_facility },
- { "depend", cfg_transport_depend },
- { "pidfile", cfg_transport_pidfile },
- { NULL }
- };
- memset (&rec, 0, sizeof rec);
- rec.retr[RETR_OUT] = rec.retr[RETR_ERR] = -1;
- if (val)
- rec.tag = strdup (val);
-
- gsc_config_parse_block (file, &rec, kwtab, "end");
-
- if (rc = argcv_get (rec.command, NULL, NULL, &argc, &argv))
- {
- file->error_msg (file->file_name, file->line,
- "cannot split command line: %s",
- strerror (rc));
- return;
- }
- register_transport (rec.tag, argv, rec.retr, rec.depv, rec.pidfile);
- free (rec.tag);
- free (rec.command);
- free (rec.pidfile);
- argcv_free (rec.depc, rec.depv);
- argcv_free (argc, argv);
-}
-
-void
-cfg_shutdown_timeout (gsc_config_file_t *file, char *kw, char *val, void *unused)
-{
- char *p;
-
- shutdown_timeout = strtoul (val, &p, 10);
- if (*p)
- file->error_msg (file->file_name, file->line,
- "unrecognized timeout value, stopped near %s", p);
-}
-
-struct gsc_config_keyword kw_handler[] = {
- { "syslog-tag", cfg_syslog_tag },
- { "syslog-facility", cfg_syslog_facility },
- { "user", cfg_user },
- { "group", cfg_group },
- { "pidfile", cfg_pidfile },
- { "ctlfile", cfg_ctlfile },
- { "statfile", cfg_statfile },
- { "umask", cfg_umask },
- { "prog", cfg_prog },
- { "transport", cfg_transport },
- { "exec", cfg_transport },
- { "shutdown-timeout", cfg_shutdown_timeout },
- { NULL }
-};
-
-void
-jabber_cfg_error (const char *name, unsigned line, const char *fmt, ...)
-{
- va_list ap;
- size_t n;
- char buffer[128];
-
- n = snprintf (buffer, sizeof buffer, "%s:%u: ", name, line);
- va_start (ap, fmt);
- vsnprintf (buffer + n, sizeof buffer - n, fmt, ap);
- va_end (ap);
- logmsg (LOG_ERR, "%s", buffer);
-}
-
-void
-parse_config ()
-{
- switch (gsc_config_parse (config_file, jabber_cfg_error, kw_handler))
- {
- case gsc_config_success:
- break;
-
- case gsc_config_open:
- logmsg (LOG_EMERG, "cannot open config file `%s': %s",
- config_file, strerror (errno));
- exit (1);
-
- case gsc_config_error:
- exit (1);
- }
-}
-
-
-void
-pidfile_write ()
-{
- FILE *fp = fopen (pidfile, "w");
- if (!fp)
- {
- logmsg (LOG_CRIT, "cannot open pidfile `%s' for writing: %s",
- pidfile, strerror (errno));
- return;
- }
- fprintf (fp, "%lu\n", (unsigned long) getpid ());
- fclose (fp);
-}
-
-pid_t
-pidfile_read (int must_exist)
-{
- int c;
- pid_t n = 0;
- FILE *fp = fopen (pidfile, "r");
- if (!fp)
- {
- if (must_exist && errno != ENOENT)
- logmsg (LOG_ERR, "cannot open pid file `%s': %s",
- pidfile,
- strerror (errno));
- return -1;
- }
-
- while ((c = fgetc (fp)) != EOF)
- {
- if (isdigit (c))
- n = n * 10 + c - '0';
- else if (c == '\n')
- break;
- else
- {
- logmsg (LOG_ERR, "unexpected character %#03o in pidfile `%s'",
- c, pidfile);
- return -1;
- }
- }
- fclose (fp);
- if (kill (n, 0))
- {
- logmsg (LOG_ERR, "Cannot signal master process %lu: %s",
- (unsigned long) n, strerror (errno));
- if (errno == EPERM)
- return n; /* be on the safe side */
- return -1;
- }
- return n;
-}
-
-void
-pidfile_remove ()
-{
- if (unlink (pidfile))
- logmsg (LOG_ERR, "cannot remove pidfile `%s': %s",
- pidfile, strerror (errno));
-}
-
-
-/* Switch to the given UID/GID */
-int
-switch_to_privs (uid_t uid, gid_t gid)
-{
- int rc = 0;
- gid_t *emptygidset;
- size_t size = 1, j = 1;
- struct group_list *gp;
-
- if (uid == 0)
- {
- logmsg (LOG_EMERG, "refusing to run as root");
- return 1;
- }
-
- /* Create a list of supplementary groups */
- for (gp = group_list; gp; gp = gp->next)
- size++;
- emptygidset = emalloc (size * sizeof emptygidset[0]);
- emptygidset[0] = gid ? gid : getegid ();
-
- for (gp = group_list; gp; gp = gp->next)
- emptygidset[j++] = gp->gid;
-
- rc = gsc_userprivs (uid, emptygidset, j);
- free (emptygidset);
- if (rc)
- logmsg (LOG_ERR, "%s", gsc_userprivs_errstring ());
-
- return rc;
-}
-
-void
-priv_setup ()
-{
- if (getuid () == 0)
- {
- if (!user)
- {
- logmsg (LOG_ERR, "non-privileged user not given");
- exit (1);
- }
- else
- {
- struct passwd *pw = getpwnam (user);
- if (!pw)
- {
- logmsg (LOG_ERR, "No such user: %s", user);
- exit (1);
- }
- if (pw && switch_to_privs (pw->pw_uid, pw->pw_gid))
- exit (1);
- }
- }
-}
-
-
-#define ACTION_CONT 0
-#define ACTION_STOP 1
-#define ACTION_RESTART 2
-#define ACTION_COMPRELOAD 3
-#define ACTION_DUMPSTATS 4
-
-int action = ACTION_CONT;
-int children_cleanup = 0;
-int got_alarm = 0;
-
-RETSIGTYPE
-sig_handler(int sig)
-{
- switch (sig)
- {
- case SIGCHLD:
- children_cleanup = 1;
- break;
-
- case SIGTERM:
- case SIGINT:
- case SIGQUIT:
- action = ACTION_STOP;
- logmsg (LOG_NOTICE, "received signal %d", sig);
- break;
-
- case SIGHUP:
- logmsg (LOG_NOTICE, "received signal %d", sig);
- if (x_argc == 0)
- {
- logmsg (LOG_NOTICE,
- "SIGHUP: not started with an absolute pathname");
- action = ACTION_STOP;
- }
- else
- action = ACTION_RESTART;
- break;
-
- case SIGALRM:
- got_alarm = 1;
- break;
-
- case SIGUSR1:
- action = ACTION_COMPRELOAD;
- break;
-
- case SIGUSR2:
- action = ACTION_DUMPSTATS;
- break;
- }
- signal (sig, sig_handler);
-}
-
-void
-signal_setup (RETSIGTYPE (*sf)(int))
-{
- signal (SIGCHLD, sf);
- signal (SIGTERM, sf);
- signal (SIGQUIT, sf);
- signal (SIGINT, sf);
- signal (SIGHUP, sf);
- signal (SIGALRM, sf);
- signal (SIGUSR1, sf);
- signal (SIGUSR2, sf);
-}
-
-void
-syslog_setup ()
-{
- log_printer = syslog_printer;
-}
-
-
-
-void
-stop_components ()
-{
- FILE *fp;
- size_t size = 0;
- char *buf = NULL;
-
- logmsg (LOG_INFO, "stopping components");
-
- fp = fopen (ctlfile, "r");
- if (!fp)
- {
- logmsg (LOG_ERR, "cannot open control file `%s': %s",
- ctlfile, strerror (errno));
- return;
- }
- if (unlink (ctlfile))
- {
- logmsg (LOG_ERR, "cannot open control file `%s': %s",
- ctlfile, strerror (errno));
- fclose (fp);
- return;
- }
-
- while (getline (&buf, &size, fp) > 0)
- {
- size_t len = strlen (buf);
- if (len == 0)
- continue;
- if (buf[len-1] == '\n')
- buf[len-1] = 0;
- progman_stop_component (buf);
- }
-
- free (buf);
- fclose (fp);
-}
-
-int
-request_restart_components (char **argv)
-{
- FILE *fp;
- pid_t pid = pidfile_read (1);
-
- if (pid == -1)
- return 1;
-
- fp = fopen (ctlfile, "w");
- if (!fp)
- {
- logmsg (LOG_ERR, "cannot open control file `%s': %s",
- ctlfile, strerror (errno));
- return 1;
- }
- for (; *argv; argv++)
- fprintf (fp, "%s\n", *argv);
- fclose (fp);
-
- kill (pid, SIGUSR1);
- return 0;
-}
-
-
-int
-jabberd_reload ()
-{
- pid_t pid = pidfile_read (1);
-
- if (pid == -1)
- {
- logmsg (LOG_CRIT, "jabberd is not running");
- return 1;
- }
-
- logmsg (LOG_INFO, "reloading jabberd at PID %lu", (unsigned long) pid);
- return kill (pid, SIGHUP) ? 2 : 0;
-}
-
-int
-jabberd_status ()
-{
- FILE *fp;
- pid_t pid = pidfile_read (0);
- int i;
-
- if (pid == -1)
- {
- logmsg (LOG_INFO, "jabberd is not running");
- return 1;
- }
-
- if (kill (pid, SIGUSR2))
- {
- logmsg (LOG_INFO,
- "jabberd is not running, but a pidfile is found (pid %lu)\n",
- (unsigned long) pid);
- return 1;
- }
- logmsg (LOG_INFO, "jabberd is running; PID %lu",
- (unsigned long) pid);
-
- for (i = 0; i < 4 && access (statfile, R_OK); i++)
- sleep (1);
-
- fp = fopen (statfile, "r");
- if (!fp)
- logmsg (LOG_ERR, "cannot open statfile `%s': %s",
- statfile, strerror (errno));
- else
- {
- char c;
-
- if (unlink (statfile))
- logmsg (LOG_ERR, "cannot unlink statfile `%s': %s",
- statfile, strerror (errno));
- while ((c = fgetc (fp)) != EOF)
- fputc (c, stdout);
- fclose (fp);
- }
- return 0;
-}
-
-int
-jabberd_stop ()
-{
- pid_t pid = pidfile_read (1);
-
- if (pid == -1)
- {
- logmsg (LOG_CRIT, "jabberd is not running");
- return 1;
- }
-
- logmsg (LOG_INFO, "stopping jabberd at PID %lu", (unsigned long) pid);
- return kill (pid, SIGTERM) ? 2 : 0;
-}
-
-
-enum {
- OPTION_RELOAD = 256,
- OPTION_STATUS,
- OPTION_STOP,
- OPTION_FORCE
-};
-
-struct option options[] = {
- { "config-file", required_argument, NULL, 'c' },
- { "debug", no_argument, NULL, 'D' },
- { "foreground", no_argument, NULL, 'f' },
- { "stderr", no_argument, NULL, 'e' },
- { "help", no_argument, NULL, 'h' },
- { "restart-module", no_argument, NULL, 'r' },
- { "reload", no_argument, NULL, OPTION_RELOAD },
- { "hup", no_argument, NULL, OPTION_RELOAD },
- { "status", no_argument, NULL, OPTION_STATUS },
- { "stop", no_argument, NULL, OPTION_STOP },
- { "version", no_argument, NULL, 'v' },
- { "force", no_argument, NULL, OPTION_FORCE },
- { NULL }
-};
-
-int
-main(int argc, char **argv)
-{
- int c;
- int mode = 0;
- pid_t pid;
- int force = 0;
-
- progname = argv[0];
- while ((c = getopt_long (argc, argv, "c:Dfehrv", options, NULL)) != EOF)
- {
- switch (c)
- {
- case 'c':
- config_file = optarg;
- break;
-
- case 'D':
- debug_level++;
- break;
-
- case 'f':
- foreground = 1;
-
- case 'e':
- log_to_stderr = 1;
- break;
-
- case 'h':
- usage ();
- exit (0);
-
- case 'v':
- gsc_version ("jabberd");
- exit (0);
-
- case 'r':
- case OPTION_RELOAD:
- case OPTION_STATUS:
- case OPTION_STOP:
- log_to_stderr = 1;
- mode = c;
- break;
-
- case OPTION_FORCE:
- force = 1;
- break;
-
- default:
- logmsg (LOG_CRIT, "unknown option: %c", c);
- exit (1);
- }
- }
-
- if (argc != optind && mode != 'r')
- {
- logmsg (LOG_CRIT, "extra command line arguments");
- exit (1);
- }
-
- parse_config ();
-
- if (!log_to_stderr)
- {
- openlog (syslog_tag, LOG_PID, log_facility);
- log_printer = syslog_printer;
- }
-
- switch (mode)
- {
- case 'r':
- priv_setup ();
- umask (jabberd_umask);
- exit (request_restart_components (argv + optind));
-
- case OPTION_RELOAD:
- exit (jabberd_reload ());
-
- case OPTION_STATUS:
- exit (jabberd_status ());
-
- case OPTION_STOP:
- exit (jabberd_stop ());
-
- default:
- priv_setup ();
- umask (jabberd_umask);
- }
-
- if (!force)
- {
- pid = pidfile_read (0);
- if (pid != -1)
- {
- logmsg (LOG_ALERT,
- "jabberd seems to be already running at pid %lu",
- (unsigned long) pid);
- logmsg (LOG_INFO,
- "use --status to verify or --force to start up anyway");
- exit (1);
- }
- }
-
- if (argv[0][0] == '/')
- {
- x_argc = argc;
- x_argv = argv;
- }
- else
- logmsg (LOG_NOTICE,
- "jabberd not started as an absolute pathname; "
- "SIGHUP will not work");
-
- logmsg (LOG_NOTICE, "jabberd started");
- if (!foreground && daemon (0, 0) == -1)
- {
- logmsg (LOG_CRIT, "cannot become a daemon: %s",
- strerror (errno));
- exit (1);
- }
- pidfile_write ();
-
- signal_setup (sig_handler);
-
- progman_start ();
-
- while (action == ACTION_CONT)
- {
- pause ();
- if (children_cleanup)
- {
- children_cleanup = 0;
- progman_cleanup (0);
- }
- if (got_alarm)
- {
- got_alarm = 0;
- progman_wake_disabled ();
- }
- switch (action)
- {
- case ACTION_COMPRELOAD:
- stop_components ();
- action = ACTION_CONT;
- break;
-
- case ACTION_DUMPSTATS:
- progman_dump_stats (statfile);
- action = ACTION_CONT;
- break;
- }
- }
- progman_stop ();
-
- pidfile_remove ();
- if (action == ACTION_RESTART)
- {
- int i;
-
- for (i = getmaxfd (); i > 0; i--)
- close (i);
-
- signal_setup (SIG_DFL);
-
- execv (x_argv[0], x_argv);
- openlog (syslog_tag, LOG_PID, log_facility);
- logmsg (LOG_EMERG, "cannot restart: %s", strerror (errno));
- }
- logmsg (LOG_NOTICE, "jabberd finished");
- exit (0);
-}
diff --git a/jabberd/progman.c b/jabberd/progman.c
deleted file mode 100644
index 3dfe3ba..0000000
--- a/jabberd/progman.c
+++ b/dev/null
@@ -1,647 +0,0 @@
-/* jabberd - a dispatcher program for jabber 2.x
- Copyright (C) 2007 Sergey Poznyakoff
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 3 of the License, or (at your
- option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "jabberd.h"
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#define TYPE_CORE 0
-#define TYPE_TRANSPORT 1
-#define TYPE_RETR 2
-
-struct prog
-{
- struct prog *next; /* Next program in the list */
- int type;
- pid_t pid; /* PID */
- char *tag; /* Entry tag (for diagnostics purposes) */
- char **depend;
- union
- {
- struct
- {
- int argc;
- char **argv; /* Command line arguments */
- int retr[2];
- char *pidfile; /* Pidfile location */
- time_t timestamp; /* Time of last startup */
- size_t count; /* Number of failed starts since timestamp */
- int disabled; /* 1 if this entry is disabled */
- } p;
-
- struct
- {
- struct prog *master;
- } r;
- } v;
-};
-
-
-#define IS_PROG(p) ((p)->type == TYPE_CORE || (p)->type == TYPE_TRANSPORT)
-
-static struct prog *proghead, *progtail;
-static size_t prognum;
-
-static void prog_stop (struct prog *prog, int sig);
-
-void
-link_prog (struct prog *pp, int prepend)
-{
- if (prepend)
- {
- pp->next = proghead;
- proghead = pp;
- if (!progtail)
- progtail = pp;
- }
- else
- {
- pp->next = NULL;
- if (progtail)
- progtail->next = pp;
- else
- proghead = pp;
- progtail = pp;
- }
-}
-
-void
-register_retr (int type, struct prog *master, pid_t pid)
-{
- struct prog *pp;
- static char *retrstr[2] = { "stdout", "stderr" };
- size_t taglen = strlen (master->tag) + 1 + strlen (retrstr[type]);
- char *tag = emalloc (taglen + 1);
-
- strcpy (tag, master->tag);
- strcat (tag, "/");
- strcat (tag, retrstr[type]);
-
- for (pp = proghead; pp; pp = pp->next)
- if (pp->type == TYPE_RETR && pp->v.r.master == master
- && strcmp (pp->tag, tag) == 0)
- {
- free (tag);
- prog_stop (pp, SIGKILL);
- break;
- }
-
- if (!pp)
- {
- pp = emalloc (sizeof(*pp) + taglen + 1);
- memset (pp, 0, sizeof(*pp));
- pp->type = TYPE_RETR;
- pp->tag = (char *) (pp + 1);
- strcpy (pp->tag, tag);
- free (tag);
- pp->v.r.master = master;
- link_prog (pp, 1);
- }
-
- pp->pid = pid;
-}
-
-void
-register_prog (int type, char *tag, char **argv, int retr[2], char **depv,
- char *pidfile)
-{
- struct prog *p, *newp;
- char *pstr;
- int i;
- size_t size = 0;
- int dep_all = 0;
- int depc = 0;
-
- if (depv)
- {
- if (depv[0] && depv[1] == NULL)
- {
- if (strcmp (depv[0], "all") == 0)
- {
- dep_all = 1;
- for (p = proghead; p; p = p->next)
- if (p->type == TYPE_CORE)
- {
- depc++;
- size += strlen (p->tag) + 1;
- }
- }
- else if (strcmp (depv[0], "none") == 0)
- depv = NULL;
- }
-
- if (depc == 0)
- for (depc = 0; depv[depc]; depc++)
- ;
- size += sizeof (depv[0]) * (depc + 1);
- }
-
- for (i = 0; argv[i]; i++)
- size += strlen (argv[i]);
- size += i + sizeof (argv[0]) * (i + 1) + sizeof (*newp)
- + (tag ? (strlen (tag) + 1) : 0);
- if (pidfile)
- size += strlen (pidfile) + 1;
-
- newp = emalloc (size);
- memset (newp, 0, sizeof(*newp));
- newp->type = type;
- newp->pid = 0;
- newp->v.p.argc = i;
- newp->v.p.argv = (char **) (newp + 1);
- pstr = (char*) (newp->v.p.argv + i + 1);
-
- for (i = 0; argv[i]; i++)
- {
- strcpy (pstr, argv[i]);
- newp->v.p.argv[i] = pstr;
- pstr += strlen (pstr) + 1;
- }
- newp->v.p.argv[i] = NULL;
-
- if (tag)
- {
- newp->tag = strcpy (pstr, tag);
- pstr += strlen (pstr) + 1;
- }
- else
- newp->tag = newp->v.p.argv[0];
-
- if (pidfile)
- {
- newp->v.p.pidfile = strcpy (pstr, pidfile);
- pstr += strlen (pstr) + 1;
- }
- else
- newp->v.p.pidfile = NULL;
-
- if (depv)
- {
- newp->depend = (char**) pstr;
- pstr = (char*) (newp->depend + depc + 1);
- if (dep_all)
- {
- depc = 0;
- for (p = proghead; p; p = p->next)
- if (p->type == TYPE_CORE)
- {
- newp->depend[depc++] = pstr;
- strcpy (pstr, p->tag);
- pstr += strlen (pstr) + 1;
- }
- }
- else
- {
- for (depc = 0; depv[depc]; depc++)
- {
- newp->depend[depc] = pstr;
- strcpy (pstr, p->tag);
- pstr += strlen (pstr) + 1;
- }
- }
- depv[depc] = NULL;
- }
- else
- newp->depend = NULL;
-
- newp->v.p.retr[0] = retr[0];
- newp->v.p.retr[1] = retr[1];
-
- link_prog (newp, 0);
-}
-
-void
-register_transport (char *tag, char **argv, int retr[2], char **depv,
- char *pidfile)
-{
- static char *std_dep[] = { "all", NULL };
- if (!depv)
- depv = std_dep;
- register_prog (TYPE_TRANSPORT, tag, argv, retr, depv, pidfile);
-}
-
-void
-register_jabber_process (char *cmd, char *cfg)
-{
- int retr[2] = { -1, -1 };
- char *argv[5];
- int argc = 0;
-
- argv[argc++] = cmd;
- if (cfg)
- {
- argv[argc++] = "-c";
- argv[argc++] = cfg;
- }
- if (debug_level > 2)
- {
- argv[argc++] = "-D";
- retr[RETR_ERR] = LOG_DEBUG;
- }
- argv[argc] = NULL;
-
- register_prog (TYPE_CORE, NULL, argv, retr, NULL, NULL);
-}
-
-static struct prog *
-find_prog (pid_t pid)
-{
- struct prog *prog;
-
- for (prog = proghead; prog; prog = prog->next)
- if (prog->pid == pid)
- break;
- return prog;
-}
-
-size_t
-progman_running_count ()
-{
- size_t size = 0;
- struct prog *prog;
-
- for (prog = proghead; prog; prog = prog->next)
- if (prog->pid > 0)
- size++;
- return size;
-}
-
-RETSIGTYPE
-retr_exit (int sig)
-{
- exit (0);
-}
-
-int
-open_retranslator (struct prog *master, int type)
-{
- int p[2];
- FILE *fp;
- char *buf = NULL;
- size_t size = 0;
- pid_t pid;
-
- if (master->v.p.retr[type] == -1)
- return -1;
- pipe (p);
- switch (pid = fork ())
- {
- case 0:
- /* Retranslator process */
-
- syslog_setup ();
- signal_setup (retr_exit);
-
- close (p[1]);
- fp = fdopen (p[0], "r");
- if (fp == NULL)
- exit (1);
-
- openlog (master->tag, LOG_PID, log_facility);
-
- while (getline (&buf, &size, fp) > 0)
- logmsg (master->v.p.retr[type], "%s", buf);
- exit (0);
-
- case -1:
- logmsg (LOG_CRIT, "cannot run retranslator `%s': fork failed: %s",
- master->tag, strerror (errno));
- return -1;
-
- default:
- register_retr (type, master, pid);
-
- close (p[0]);
- return p[1];
- }
-}
-
-static void
-prog_start (struct prog *prog)
-{
- int i;
- pid_t pid;
- time_t now;
- int retr[2];
-
- time (&now);
-
- if (prog->v.p.timestamp + TESTTIME > now)
- prog->v.p.count++;
- else
- {
- prog->v.p.count = 0;
- prog->v.p.timestamp = now;
- }
-
- if (prog->v.p.count > MAXSPAWN)
- {
- int old_alarm;
-
- logmsg(LOG_ERR, "%s is respawning too fast, disabled for %d minutes",
- prog->tag, SLEEPTIME / 60);
- prog->v.p.timestamp = now;
- prog->v.p.disabled = 1;
-
- old_alarm = alarm (0);
- if (old_alarm > SLEEPTIME || old_alarm <= 0)
- old_alarm = SLEEPTIME;
- alarm (old_alarm);
- return;
- }
-
- logmsg (LOG_DEBUG, "starting %s", prog->tag);
-
- if (prog->v.p.pidfile)
- {
- if (unlink (prog->v.p.pidfile) && errno != ENOENT)
- logmsg (LOG_ERR, "%s: cannot remove pidfile `%s': %s",
- prog->tag, prog->v.p.pidfile, strerror (errno));
- }
-
- retr[RETR_OUT] = open_retranslator (prog, RETR_OUT);
- retr[RETR_ERR] = open_retranslator (prog, RETR_ERR);
-
- switch (pid = fork ())
- {
- /* The child branch. */
- case 0:
- if (retr[RETR_OUT] == -1)
- {
- close (1);
- open ("/dev/null", O_RDWR);
- }
- else if (retr[RETR_OUT] != 1)
- {
- close (1);
- dup2 (retr[RETR_OUT], 1);
- }
-
- if (retr[RETR_ERR] == -1)
- {
- close (2);
- open ("/dev/null", O_RDWR);
- }
- else if (retr[RETR_ERR] != 1)
- {
- close (2);
- dup2 (retr[RETR_ERR], 2);
- }
-
- /* Close unneded descripitors */
- for (i = getmaxfd (); i > 2; i--)
- close (i);
-
- signal_setup (SIG_DFL);
-
- execvp(prog->v.p.argv[0], prog->v.p.argv);
- openlog (syslog_tag, LOG_PID, log_facility);
- logmsg (LOG_CRIT, "cannot start `%s': %s", prog->tag,
- strerror (errno));
- exit (1);
-
- case -1:
- logmsg (LOG_CRIT, "cannot run `%s': fork failed: %s",
- prog->tag, strerror (errno));
- break;
-
- default:
- prog->pid = pid;
- }
-}
-
-void
-progman_start ()
-{
- struct prog *prog;
-
- for (prog = proghead; prog; prog = prog->next)
- if (IS_PROG (prog))
- prog_start (prog);
-}
-
-void
-progman_wake_disabled ()
-{
- struct prog *prog;
-
- for (prog = proghead; prog; prog = prog->next)
- if (IS_PROG (prog) && prog->v.p.disabled)
- {
- prog->v.p.disabled = 0;
- prog->v.p.count = 0;
- prog->v.p.timestamp = 0;
- prog_start (prog);
- }
-}
-
-static void
-prog_stop (struct prog *prog, int sig)
-{
- if (prog->pid > 0)
- {
- logmsg (LOG_DEBUG, "Stopping %s",
- prog->tag, (unsigned long) prog->pid);
- kill (prog->pid, sig);
- }
-}
-
-static void
-prog_stop_recursive (struct prog *prog, int sig)
-{
- if (!prog)
- return;
- prog_stop_recursive (prog->next, sig);
- prog_stop (prog, sig);
-}
-
-void
-progman_stop ()
-{
- unsigned long i;
-
- prog_stop_recursive (proghead, SIGTERM);
- for (i = 0; i < shutdown_timeout; i++)
- {
- progman_cleanup (1);
- if (progman_running_count () == 0)
- return;
- sleep (1);
- }
- prog_stop_recursive (proghead, SIGKILL);
-}
-
-static void
-print_status (char *tag, pid_t pid, int status, int expect_term)
-{
- if (WIFEXITED (status))
- {
- if (WEXITSTATUS (status) == 0)
- logmsg (LOG_DEBUG,
- "%s (%lu) exited successfully",
- tag, (unsigned long) pid);
- else
- logmsg (LOG_ERR,
- "%s (%lu) failed with status %d",
- tag, (unsigned long) pid,
- WEXITSTATUS (status));
- }
- else if (WIFSIGNALED (status))
- {
- int prio;
-
- if (expect_term && WTERMSIG (status) == SIGTERM)
- prio = LOG_DEBUG;
- else
- prio = LOG_ERR;
-
- logmsg(prio,
- "%s (%lu) terminated on signal %d",
- tag, (unsigned long) pid,
- WTERMSIG (status));
- }
- else if (WIFSTOPPED (status))
- logmsg(LOG_ERR,
- "%s (%lu) stopped on signal %d",
- tag, (unsigned long) pid,
- WSTOPSIG (status));
-#ifdef WCOREDUMP
- else if (WCOREDUMP (status))
- logmsg (LOG_ERR,
- "%s (%lu) dumped core",
- tag, (unsigned long) pid);
-#endif
- else
- logmsg(LOG_ERR,
- "%s (%lu) terminated with unrecognized status",
- tag, (unsigned long) pid);
-}
-
-void
-prog_stop_dependent (struct prog *prog)
-{
- struct prog *p;
-
- for (p = proghead; p; p = p->next)
- if (p->depend)
- {
- int i;
- for (i = 0; p->depend[i]; i++)
- if (strcmp (prog->tag, p->depend[i]) == 0)
- prog_stop (p, SIGTERM);
- }
-}
-
-void
-progman_cleanup (int expect_term)
-{
- pid_t pid;
- int status;
- while ((pid = waitpid (-1, &status, WNOHANG)) > 0)
- {
- struct prog *prog = find_prog (pid);
- if (!prog)
- {
- logmsg (LOG_NOTICE, "unknown child %lu finished",
- (unsigned long) pid);
- continue;
- }
- print_status (prog->tag, prog->pid, status, expect_term);
- prog->pid = 0;
- if (IS_PROG (prog))
- {
- prog_stop_dependent (prog);
- if (!expect_term)
- prog_start (prog);
- }
- }
-}
-
-void
-progman_stop_component (const char *name)
-{
- struct prog *prog;
-
- logmsg (LOG_INFO, "stopping component `%s'", name);
- for (prog = proghead; prog; prog = prog->next)
- if (IS_PROG (prog) && strcmp (prog->tag, name) == 0)
- {
- if (prog->v.p.disabled)
- logmsg (LOG_INFO, "stopping component `%s': component not started",
- name);
- else
- prog_stop (prog, SIGTERM);
- }
-}
-
-void
-progman_dump_stats (const char *filename)
-{
- FILE *fp;
- struct prog *prog;
- char *s;
- int rc;
-
- logmsg (LOG_INFO, "dumping statistics to `%s'", filename);
- fp = fopen (filename, "w");
- if (!fp)
- {
- logmsg (LOG_ERR, "cannot open file `%s' for writing: %s",
- filename, strerror (errno));
- return;
- }
-
- for (prog = proghead; prog; prog = prog->next)
- {
- switch (prog->type)
- {
- case TYPE_CORE:
- case TYPE_TRANSPORT:
- fprintf (fp, "%s %s ",
- prog->type == TYPE_CORE ? "core" : "transport",
- prog->tag);
- if (prog->pid)
- fprintf (fp, "%lu", (unsigned long) prog->pid);
- else if (prog->v.p.disabled)
- {
- char buf[48];
- time_t t = prog->v.p.timestamp + SLEEPTIME;
- strftime (buf, sizeof buf, "%c",
- localtime (&t));
- fprintf (fp, "[disabled; scheduled for %s]", buf);
- }
- else
- fprintf (fp, "[not running]");
- if (rc = argcv_string (prog->v.p.argc, prog->v.p.argv, &s))
- {
- logmsg (LOG_ERR, "cannot convert argument list: %s",
- strerror (rc));
- }
- else
- {
- fprintf (fp, " %s", s);
- free (s);
- }
- fputc ('\n', fp);
- break;
-
- case TYPE_RETR:
- fprintf (fp, "retranslator %s %lu\n", prog->tag,
- (unsigned long) prog->pid);
- }
- }
- fclose (fp);
-}
diff --git a/mc/trurl.mc b/mc/trurl.mc
index 8ed304d..a89701f 100644
--- a/mc/trurl.mc
+++ b/mc/trurl.mc
@@ -16,2 +16,3 @@ dnl * Include common defaults
include(common.mc)
+dnl include(`milter.conf')
@@ -27,5 +28,5 @@ FEATURE(relay_hosts_only)
FEATURE(blacklist_recipients)
-FEATURE(dnsbl, `rbl.maps.vix.com')
-FEATURE(dnsbl, `rbl.farlep.net')
-FEATURE(dnsbl, `dialup-rev.farlep.net')
+dnl FEATURE(dnsbl, `rbl.maps.vix.com')
+dnl FEATURE(dnsbl, `rbl.farlep.net')
+dnl FEATURE(dnsbl, `dialup-rev.farlep.net')
@@ -33,6 +34,4 @@ dnl * Mailers
undefine(`LOCAL_MAILER_PATH')
-define(`LOCAL_MAILER_PATH', `/usr/local/libexec/mail.local')
-# Use mail.local --message-id-header=X-Mailutils-Message-Id in
-# /etc/mailutils.rc
-define(`LOCAL_MAILER_ARGS', `mail.local -xl -S %h/.filter.sv $u')
+define(`LOCAL_MAILER_PATH', `/usr/local/sbin/maidag')
+define(`LOCAL_MAILER_ARGS', `maidag -xl --lang=sieve -s %h/.filter.sv $u')
@@ -41,3 +40,3 @@ MAILER(smtp)
-dnl * Identification string for mail.local/Sieve log messages.
+dnl * Identification string for maidag/Sieve log messages.
LOCAL_CONFIG

Return to:

Send suggestions and report system problems to the System administrator.