aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-09-15 10:40:29 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2009-09-15 10:40:54 +0300
commit989a5bbb74c3620abaa2191ce2c4f8d5968dbf0a (patch)
treec0b2324a523905c3c17201cc2468c9078976fc74
parentdbad35177723e19147ab49b59a3728e00fe05875 (diff)
downloadpies-989a5bbb74c3620abaa2191ce2c4f8d5968dbf0a.tar.gz
pies-989a5bbb74c3620abaa2191ce2c4f8d5968dbf0a.tar.bz2
Branch off from the Mailfromd project into a separate repository.
-rw-r--r--.gitignore29
l---------COPYING1
-rw-r--r--ChangeLog.mfd342
-rw-r--r--Makefile.am35
-rw-r--r--NEWS33
-rw-r--r--README0
-rw-r--r--THANKS0
-rw-r--r--am/aggr.m460
-rw-r--r--am/gcc.m467
-rw-r--r--am/proctitle.m479
-rw-r--r--bootstrap.conf13
-rw-r--r--configure.ac97
-rw-r--r--doc/.gitignore22
-rw-r--r--doc/Makefile.am39
-rw-r--r--doc/pies.texi176
-rw-r--r--gnulib.modules10
-rw-r--r--lib/Makefile.am33
-rw-r--r--lib/config.c115
-rw-r--r--lib/intprops.h79
-rw-r--r--lib/libpies.h70
-rw-r--r--lib/nls.c34
-rw-r--r--lib/parsetime.c109
-rw-r--r--lib/proctitle.c164
-rw-r--r--lib/userprivs.c291
-rw-r--r--po/.gitignore21
-rw-r--r--po/POTFILES.in19
-rw-r--r--src/.gitignore (renamed from pies/.gitignore)0
-rw-r--r--src/Makefile.am (renamed from pies/Makefile.am)5
-rw-r--r--src/depmap.c (renamed from pies/depmap.c)0
-rw-r--r--src/limits.c (renamed from pies/limits.c)0
-rw-r--r--src/meta1gram.y (renamed from pies/meta1gram.y)0
-rw-r--r--src/meta1lex.h (renamed from pies/meta1lex.h)0
-rw-r--r--src/meta1lex.l (renamed from pies/meta1lex.l)0
-rw-r--r--src/pies.c (renamed from pies/pies.c)10
-rw-r--r--src/pies.h (renamed from pies/pies.h)6
-rw-r--r--src/pies.rcin (renamed from pies/pies.rcin)0
-rw-r--r--src/progman.c (renamed from pies/progman.c)0
-rw-r--r--src/socket.c (renamed from pies/socket.c)0
38 files changed, 1874 insertions, 85 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f7b417d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,29 @@
+*.a
+*.la
+*.lo
+*.o
+*.tar.*
+*~
+.bootstrap
+.deps
+.emacs*
+.gdbinit
+.libs
+ABOUT-NLS
+ChangeLog
+INSTALL
+Makefile
+Makefile.in
+TAGS
+aclocal.m4
+autom4te.cache/
+build-aux
+config.h
+config.h.in
+config.log
+config.status
+configure
+core
+gnu
+m4
+stamp-h1
diff --git a/COPYING b/COPYING
new file mode 120000
index 0000000..6168a39
--- /dev/null
+++ b/COPYING
@@ -0,0 +1 @@
+/usr/share/automake-1.11/COPYING \ No newline at end of file
diff --git a/ChangeLog.mfd b/ChangeLog.mfd
new file mode 100644
index 0000000..7c4fcd5
--- /dev/null
+++ b/ChangeLog.mfd
@@ -0,0 +1,342 @@
+2009-08-27 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ Fix diagnostic and help messages.
+
+ 1. Option descriptions in `--help' output do not constitute
+ conceptual sentences. Therefore, they should not begin
+ with a capital letter, nor end with a final point.
+ 2. According to standards.texi, a diagnostic message in a
+ non-interactive program "should not begin with a capital letter
+ when it follows a program name and/or file name, because that
+ isn't the beginning of a sentence. (The sentence conceptually
+ starts at the beginning of the line.) Also, it should not end
+ with a period."
+
+ Affected files:
+
+ * pies/pies.c
+ * pies/progman.c
+
+2009-06-17 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ Bugfixes.
+
+ * pies/pies.c (main): Change main loop to do..while,
+ otherwise a signal arriving before entering the loop
+ might cause the program to terminate.
+
+2009-06-14 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ Fix and improve termination actions.
+
+ * pies/pies.h (MAX_RETURN_CODE): Remove.
+ (STATUS_SIG_BIT, STATUS_CODE): New defines
+ (struct action): New fields next, nstat, status, command.
+ (struct component): Keep singly-linked list of termination
+ actions.
+ * pies/progman.c (run_command): New function.
+ (progman_cleanup): Redo iteration over termination actions.
+ * pies/pies.c (return_code_cfg_param): Pass offsets in
+ struct component.
+ (create_action): Accept signal numbers (SIG.* or SIG\+[0-9]+)
+ in tag.
+ (return_code_section_parser): Update.
+ (pies_check_status): Set *pid before returning pies_status_stale.
+ * doc/pies.texi: Document changes.
+
+2009-06-04 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ MeTA1-related improvements.
+
+ * pies/pies.c (_cm_include_meta1): Fix coredump on syntax errors
+ in meta1.conf.
+
+2009-05-21 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ More work on `silent rules' mode
+
+ * pies/Makefile.am: Add silent rule markers.
+
+2009-05-13 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ Minor change
+
+ * pies/progman.c: Use _exit in child processes. This
+ is a work over a fault in MU design: it registers
+ the pidfile removal function via atexit.
+
+2008-12-26 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * doc/pies.texi: Update.
+
+ git-svn-id: file:///svnroot/mailfromd/trunk@1771
+ 7a8a7f39-df28-0410-adc6-e0d955640f24
+
+2008-12-01 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ Documentation and minor fixes.
+
+ * pies/pies.c, pies/progman.c, pies/meta1gram.y, pies/pies.h,
+ pies/meta1lex.l: Normalize output redirection terminology, fix the
+ debug levels.
+ * doc/pies.texi: Document the configuration.
+
+2008-11-21 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * pies/pies.c (component_cfg_param): New statement settle-timeout.
+ * pies/progman.c (recompute_alarm): New static;
+ (prog_start): Start the component only if all of its prerequisites
+ are running.
+ (progman_recompute_alarm): New function.
+ (progman_start): Reset recompute_alarm to 0.
+ (check_stopping): New function.
+ (progman_wake_sleeping): Handle also status_stopping and
+ status_enabled. Recompute alarm before leaving.
+ (prog_start_prerequisites): Return 0 or 1 depending on whether all
+ prerequisites have been started.
+ (prog_stop): Raise recompute_alarm for stopping components.
+ (progman_cleanup): Force status_enabled before attepmting to
+ start a component.
+ (progman_cleanup): Add a \n after debugging message.
+ Run progman_wake_sleeping unlsess expect_term is set.
+ * pies/meta1gram.y (translate_node_list): Force settle-timeout =
+ 1.
+ * pies/pies.h (struct component.settle_timeout): New member.
+
+ * pies/pies.c (main): New options --force, --dump-prereq and
+ --dump-depmap.
+ Refuse to start if another instance is already running.
+ (pies_check_status): New function.
+ (pies_status): Rewrite using pies_check_status.
+ * pies/progman.c (component_fixup_depend): Bugfix: move
+ mu_list_append off the conditional.
+ (progman_dump_prereq, progman_dump_depmap): New functions.
+ * pies/meta1gram.y (yyerror): Return 0.
+ * pies/pies.h (progman_dump_prereq, progman_dump_depmap): New
+ protos.
+ (meta1_parser_set_debug, meta1lex, meta1error)
+ (meta1parse): Likewise.
+
+ * pies/progman.c (print_dep): New function.
+ (progman_build_depmap): Call print_dep to facilitate fixing cyclic
+ dependencies.
+ (prog_start_prerequisites): Fix debugging output.
+ Remove spurious second loop (was it a typo or copy-paste
+ leftover?)
+ (prog_stop_dependents): Fix debugging output.
+ (progman_dump_stats): Avoid race conditions between running and
+ querying instances.
+
+2008-11-17 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ Fix handling of retranslators.
+
+ * pies/pies.c (main): Call progman_build_depmap and
+ progman_create_sockets before starting up components.
+ * pies/progman.c (struct prog): New member `retr'.
+ (destroy_prog): New function.
+ (retr_tag): Change signature. Fix erroneous condition for
+ xalloc_die.
+ (register_retr): Return prog. Make static. Initialize idx
+ with -1.
+ (update_retr): Register retranslator, if necessary.
+ (progman_register_retranslators): Remove.
+ (register_prog0): 2nd argument: index.
+ (register_prog): Do not create socket at once.
+ (prog_start): Remove debugging fprintf.
+ (progman_accept): Update call to register_prog0.
+ (progman_create_sockets): New function.
+ (progman_start): Remove calls to progman_register_retranslators
+ and progman_build_depmap. They must be done only once.
+ (prog_stop_retranslators): New function.
+ (prog_stop_dependents): Call prog_stop_retranslators.
+ (progman_cleanup): Remove dangling retranslators.
+ * pies/pies.h (progman_create_sockets): New prototype.
+
+2008-11-16 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ Improve pies.
+
+ * pies/pies.h (create_socket): Change proto to 3 arguments.
+ * pies/socket.c (create_socket): Take two additional arguments.
+ Allow to configure ownership and mode of created UNIX sockets.
+ * pies/progman.c (register_prog, prog_start): Update calls to
+ create_socket.
+
+2008-11-15 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ Improve handling of program privileges.
+
+ * pies/pies.h (struct pies_privs_data): Remove
+ (struct component): Change type of `privs' to struct mf_privs.
+ (priv_setup): Remove.
+ * pies/pies.c: Use mf_priv* stuff to manipulate privileges.
+ * pies/progman.c: Likewise.
+ * pies/meta1gram.y (list): allow for trailing comma.
+
+2008-10-31 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * pies/progman.c, pies/pies.h: Use umaxtostr, instead
+ of mu_umaxtostr.
+
+2008-10-15 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * pies/progman.c (env_setup): Port new implementation from Rush.
+
+2008-10-04 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * pies/pies.c (component_cfg_param): New configuration statement
+ `precious'.
+ * pies/progman.c (struct prog): New member `precious'.
+ (register_prog): Set precious.
+ (prog_start_dependencies): Do not mark disabled precious
+ dependencies of a disabled component.
+ * pies/pies.h (pies/pies.h): New member `precious'.
+ * pies/pies.rcin (mcp): Mark as precious.
+
+ * pies/pies.c (return_code_section_parser): Fix to work with tag
+ of any type.
+ * pies/pies.rcin: Minor change.
+
+ * pies/pies.c (main): Do cleanup after main action processing and
+ only if action == ACTION_CONT.
+ * pies/progman.c (struct prog): New member `prev'.
+ (link_prog): Maintain doubly-linked list.
+ (prog_stop_dependent): Avoid printing diagnostics if there are
+ no dependencies to be stopped.
+ (prog_stop): Do nothing if prog->pid is zero.
+ Do not call prog_stop_dependent, it will be done by
+ progman_cleanup.
+ (prog_stop_all): Terminate components from last to first.
+ * pies/pies.rcin: Improve example, by adding mcp component.
+
+ * pies/pies.c (_cb_depend): Handle single string value.
+ (_cb_retr): Fix diagnostic message.
+ (_cb_facility): New function.
+ (component_cfg_param): New statement `facility'.
+ (component_section_parser): Initialize comp.facility to the
+ default value.
+ * pies/progman.c (struct prog): New member `facility'.
+ (register_prog): Initialize facility.
+ (open_retranslator): Use master->facility.
+ * pies/pies.h (struct component): New member `facility'.
+
+2008-10-03 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * pies/progman.c (register_prog): Remove stray semicolon.
+ (retr_exit): Use _exit.
+ (prog_stop_dependent): Bugfix: stop retranlators as well as
+ components.
+
+2008-09-29 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * pies/pies.c: Rewrite configuration
+ file support to match changes in Mailutils.
+
+2008-09-09 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * pies/pies.c: Change description.
+
+2008-06-26 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * pies/pies.h: Include stdint.h
+
+2008-02-26 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * pies/pies.c: New configuration statement "chdir".
+ * pies/progman.c (struct prog.v.p): New member `dir'.
+ (register_prog): Initialize newp->v.p.dir;
+ (prog_start): Change to the working directory, if required by
+ config.
+
+2008-02-01 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * pies/pies.c (progman_wake_disabled): Renamed to
+ progman_wake_sleeping.
+ * pies/progman.c: Implement proper handling of dependencies.
+ * pies/pies.h ((progman_wake_disabled): Renamed to
+ progman_wake_sleeping.
+ (pies_depmap_t,pies_depmap_pos_t,enum pies_depmap_direction): New
+ types.
+ (depmap_alloc,depmap_copy,depmap_set,depmap_isset,depmap_tc)
+ (depmap_first,depmap_next): New functions.
+ * pies/depmap.c: New file.
+ * pies/Makefile.am (pies_SOURCES): Add depmap.c.
+
+ * pies/pies.c (return_code_section_parser): Allow to use symbolic
+ exit codes.
+ (priv_setup): Exit with EX_CONFIG if the user does not exist.
+ (main): Catch early sigchlds as well.
+ * pies/progman.c (progman_cleanup): Fix notice wording.
+ * pies/pies.rcin: Add sample return-code section.
+ (component pmult): Redirect stderr/stdout to syslog.
+
+2008-01-31 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ Implement configurable actions depending on the exit code of
+ a component.
+
+ * pies/pies.c: New configuration file section "return-code".
+ (capa): Add mailer and debug.
+ (main): Register "return-code" section and all mailer formats.
+ * pies/progman.c (enum prog_status): New type.
+ (struct prog): Remove `disabled'. New fields `status' and `act'.
+ (register_prog): Initialize act.
+ (prog_start): Exit with EX_SOFTWARE code if the component cannot
+ be started.
+ (progman_start): Do not start disabled components.
+ (progman_wake_disabled): Wake only components marked as
+ status_stopped.
+ (notify): New function.
+ (progman_cleanup): Act in accordance with the `act' field if the
+ component terminates.
+ (progman_stop_component,progman_dump_stats): Take into account
+ prog->v.p.status.
+ * pies/pies.h (MAX_RETURN_CODE): New define.
+ (enum return_action): New type.
+ (struct component.act): New member.
+ (default_component): New global.
+
+2008-01-24 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * pies/pies.c: Fix handling of the --log-tag option.
+
+ * pies/progman.c (prog_start): Remove unconditional debugging
+ output.
+
+2008-01-22 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * pies/pies.c (log_setup): Always set mu_debug_default_printer to
+ override bug in libmailutils.
+ (component_cfg_param): New keyword `env'.
+ (main): Bugfix: It is -R that allows arguments, not -r.
+ * pies/progman.c (struct prog): New member env.
+ (register_prog): Avoid unnecessary allocations. Copy env.
+ (env_setup): New function.
+ (prog_start): Set up environment.
+ * pies/pies.h (struct component): New member env.
+
+2008-01-14 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * pies/pies.c, pies/progman.c,
+ pies/pies.h, pmult/pmult.c: Sync with MU CVS: Use mu_log_facility
+ and mu_log_tag.
+
+2008-01-13 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * pies/pies.c (_cb_group): Bugfix: store group number in the list,
+ not its name.
+ (component_section_parser): Initialize retr to default values.
+ * pies/Makefile.am (LDADD): Place libgnu.a after
+ MAILUTILS_LIBS.
+
+ * pies: New directory.
+ * pies/Makefile.am: New file.
+ * pies/pies.c, pies/progman.c, pies/pies.h, pies/pies.rcin: New
+ files.
+
+Local Variables:
+mode: change-log
+version-control: never
+buffer-read-only: t
+End:
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..f665de1
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,35 @@
+ACLOCAL_AMFLAGS = -I m4 -I am
+
+SUBDIRS=gnu lib src doc po
+
+# Define the following variables in order to use the ChangeLog rule below:
+# prev_change_log [optional] Name of the previous ChangeLog file.
+# gen_start_date [optional] Start ChangeLog from this date.
+# changelog_dir [mandatory] Directory where to create ChangeLog
+prev_change_log = ChangeLog.mfd
+gen_start_date = 2009-09-04
+changelog_dir = .
+
+.PHONY: ChangeLog
+ChangeLog:
+ if test -d .git; then \
+ cmd=$(top_srcdir)/build-aux/gitlog-to-changelog; \
+ if test -n "$(gen_start_date)"; then \
+ cmd="$$cmd --since=\"$(gen_start_date)\""; \
+ fi; \
+ $$cmd --format='%s%n%n%b%n' | \
+ sed '/<unknown>$$/d' | fmt -s > $(changelog_dir)/cl-t; \
+ if test -n "$(prev_change_log)" && test -f "$(prev_change_log)"; \
+ then \
+ echo "" >> $(changelog_dir)/cl-t; \
+ cat "$(prev_change_log)" | \
+ sed '/^Local Variables:/,/^End:/d' >> $(changelog_dir)/cl-t; \
+ fi; \
+ echo "Local Variables:" >> $(changelog_dir)/cl-t; \
+ echo "mode: change-log" >> $(changelog_dir)/cl-t; \
+ echo "version-control: never" >> $(changelog_dir)/cl-t; \
+ echo "buffer-read-only: t" >> $(changelog_dir)/cl-t; \
+ echo "End:" >> $(changelog_dir)/cl-t; \
+ rm -f $(changelog_dir)/ChangeLog; \
+ mv $(changelog_dir)/cl-t $(changelog_dir)/ChangeLog; \
+ fi
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..105cf41
--- /dev/null
+++ b/NEWS
@@ -0,0 +1,33 @@
+Mailfromd NEWS -- history of user-visible changes. 2009-09-03
+Copyright (C) 2005, 2006, 2007, 2008, 2009 Sergey Poznyakoff
+See the end of file for copying conditions.
+
+Please send Mailfromd bug reports to <bug-mailfromd@gnu.org.ua>
+
+
+Version 1.0 (Git)
+
+
+=========================================================================
+Copyright information:
+
+Copyright (C) 2005, 2006, 2007, 2008, 2009 Sergey Poznyakoff
+
+ Permission is granted to anyone to make or distribute verbatim copies
+ of this document as received, in any medium, provided that the
+ copyright notice and this permission notice are preserved,
+ thus giving the recipient permission to redistribute in turn.
+
+ Permission is granted to distribute modified versions
+ of this document, or of portions of it,
+ under the above conditions, provided also that they
+ carry prominent notices stating who last changed them.
+
+Local variables:
+mode: outline
+paragraph-separate: "[ ]*$"
+eval: (add-hook 'write-file-hooks 'time-stamp)
+time-stamp-start: "changes. "
+time-stamp-format: "%:y-%02m-%02d"
+time-stamp-end: "\n"
+end:
diff --git a/README b/README
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/README
diff --git a/THANKS b/THANKS
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/THANKS
diff --git a/am/aggr.m4 b/am/aggr.m4
new file mode 100644
index 0000000..2bdbb46
--- /dev/null
+++ b/am/aggr.m4
@@ -0,0 +1,60 @@
+dnl Autoconf macros for checking for aggregate type members
+dnl
+dnl Copyright (C) 1996, 1997, 1998, 2002, 2004, 2005, 2007 Free Software Foundation, Inc.
+dnl
+dnl Mostly written by Miles Bader <miles@gnu.ai.mit.edu>
+dnl
+dnl This program is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 3, or (at your option)
+dnl any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+dnl GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; if not, write to the Free Software
+dnl Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+dnl
+
+dnl IU_CHECK_MEMBER(AGGREGATE.MEMBER,
+dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND],
+dnl [INCLUDES])
+dnl AGGREGATE.MEMBER is for instance `struct passwd.pw_gecos'.
+dnl The member itself can be of an aggregate type
+dnl Shell variables are not a valid argument.
+AC_DEFUN([IU_CHECK_MEMBER],
+[AS_LITERAL_IF([$1], [],
+ [AC_FATAL([$0: requires literal arguments])])dnl
+m4_bmatch([$1], [\.], ,
+ [m4_fatal([$0: Did not see any dot in `$1'])])dnl
+AS_VAR_PUSHDEF([ac_Member], [ac_cv_member_$1])dnl
+dnl Extract the aggregate name, and the member name
+AC_CACHE_CHECK([for $1], ac_Member,
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])],
+[dnl AGGREGATE ac_aggr;
+static m4_bpatsubst([$1], [\..*]) ac_aggr;
+dnl ac_aggr.MEMBER;
+if (sizeof(ac_aggr.m4_bpatsubst([$1], [^[^.]*\.])))
+return 0;])],
+ [AS_VAR_SET(ac_Member, yes)],
+ [AS_VAR_SET(ac_Member, no)])])
+AS_IF([test AS_VAR_GET(ac_Member) = yes], [$2], [$3])
+AS_VAR_POPDEF([ac_Member])dnl
+])dnl IU_CHECK_MEMBER
+
+dnl IU_CHECK_MEMBERS([AGGREGATE.MEMBER, ...],
+dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]
+dnl [INCLUDES])
+AC_DEFUN([IU_CHECK_MEMBERS],
+[m4_foreach([AC_Member], [$1],
+ [IU_CHECK_MEMBER(AC_Member,
+ [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]AC_Member), 1,
+ [Define to 1 if `]m4_bpatsubst(AC_Member,
+ [^[^.]*\.])[' is
+ member of `]m4_bpatsubst(AC_Member, [\..*])['.])
+$2],
+ [$3],
+ [$4])])])
diff --git a/am/gcc.m4 b/am/gcc.m4
new file mode 100644
index 0000000..37d90ac
--- /dev/null
+++ b/am/gcc.m4
@@ -0,0 +1,67 @@
+# This file is part of Mailfromd. -*- autoconf -*-
+# Copyright (C) 2009 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, 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/>.
+
+AC_DEFUN([MF_CC_OPT],[
+ m4_pushdef([mf_optname],translit($1,[-],[_]))
+ AC_MSG_CHECKING(whether $CC accepts $1)
+ mf_save_cc="$CC"
+ CC="$CC $1"
+ AC_TRY_RUN([int main() { return 0; }],
+ [mf_cv_cc_]mf_optname=yes,
+ [mf_cv_cc_]mf_optname=no,
+ [mf_cv_cc_]mf_optname=no)
+ CC="$mf_save_cc"
+ AC_MSG_RESULT($[mf_cv_cc_]mf_optname)
+
+ if test $[mf_cv_cc_]mf_optname = yes; then
+ ifelse([$2],,:,[$2])
+ ifelse([$3],,,else
+ [$3])
+ fi
+ m4_popdef([mf_optname])
+ ])
+
+AC_DEFUN([MF_CC_OPT_CFLAGS],[
+ MF_CC_OPT([$1],[CFLAGS="$CFLAGS $1"])
+])
+
+AC_DEFUN([MF_GCC_ALIAS_QUIRK],[
+ #
+ # Quoting Linus Torvalds:
+ # The gcc people are more interested in trying to find out what can be
+ # allowed by the c99 specs than about making things actually _work_. The
+ # aliasing code in particular is not even worth enabling, it's just not
+ # possible to sanely tell gcc when some things can alias.
+ # (see http://lkml.org/lkml/2003/2/26/158, for details)
+ #
+ # (The code below is borrowed from Python's configure.in)
+ MF_CC_OPT_CFLAGS([-fno-strict-aliasing])
+])
+
+AC_DEFUN([MF_GCC_PAREN_QUIRK],[
+ MF_CC_OPT_CFLAGS([-Wno-parentheses])
+])
+
+AC_DEFUN([MF_GCC_QUIRKS],[
+ case $GCC in
+ yes)
+ MF_GCC_ALIAS_QUIRK
+ MF_GCC_PAREN_QUIRK
+ ;;
+ *) # FIXME
+ ;;
+ esac])
+
diff --git a/am/proctitle.m4 b/am/proctitle.m4
new file mode 100644
index 0000000..c912072
--- /dev/null
+++ b/am/proctitle.m4
@@ -0,0 +1,79 @@
+dnl This file is part of Mailfromd.
+dnl Copyright (C) 2008 Sergey Poznyakoff
+dnl
+dnl This program is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 3, or (at your option)
+dnl any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+dnl GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+AC_DEFUN([MF_PROCTITLE],[
+ AH_TEMPLATE([MF_PROCTITLE_TYPE], [Type of setproctitle implementation])
+ AH_BOTTOM([
+#define MF_PROCTITLE_SETPROCTITLE 0
+#define MF_PROCTITLE_REPLACE_ARGV 1
+#define MF_PROCTITLE_REWRITE_ARGV 2
+#define MF_PROCTITLE_PSTAT 3
+#define MF_PROCTITLE_PSSTRINGS 4
+])
+ AC_SUBST(MF_PROCTITLE_LIBS)
+
+ AC_TRY_LINK([extern char *__progname, *__progname_full;],
+ [__progname = "foo"; __progname_full = "foo bar";],
+ [AC_DEFINE(HAVE___PROGNAME, 1,
+ [Define to 1 if libc has __progname])])
+
+ mf_proctitle_type=no
+ AC_CHECK_FUNC(setproctitle,
+ [mf_proctitle_type=MF_PROCTITLE_SETPROCTITLE],
+ [AC_CHECK_HEADERS(libutil.h)
+ AC_CHECK_LIB(util, setproctitle,
+ [mf_proctitle_type=MF_PROCTITLE_SETPROCTITLE
+ MF_PROCTITLE_LIBS="-lutil"])])
+
+ if test "$mf_proctitle_type" = no; then
+ AC_CHECK_HEADER([sys/pstat.h],
+ [AC_CHECK_FUNC([pstat],
+ [mf_proctitle_type=MF_PROCTITLE_PSTAT],
+ [mf_proctitle_type=MF_PROCTITLE_REWRITE_ARGV])])
+ if test "$mf_proctitle_type" = no; then
+ AC_TRY_COMPILE([#include <machine/vmparam.h>
+ #include <sys/exec.h>],
+ [
+#include <sys/types.h>
+#include <sys/proc.h>
+#include <vm/pmap.h>
+#include <machine/pmap.h>
+#include <machine/vmparam.h>
+#include <sys/exec.h>
+
+main()
+{
+ int i = PS_STRINGS;
+}
+],
+ [mf_proctitle_type=MF_PROCTITLE_PSSTRINGS])
+
+ if test "$mf_proctitle_type" = no; then
+ AC_EGREP_CPP(yes,[
+#if defined(__GNU_HURD__)
+ yes
+#endif
+],
+ [mf_proctitle_type=MF_PROCTITLE_REPLACE_ARGV],
+ [mf_proctitle_type=MF_PROCTITLE_REWRITE_ARGV])
+ fi
+ fi
+ fi
+
+ AC_DEFINE_UNQUOTED([MF_PROCTITLE_TYPE],$mf_proctitle_type)
+
+])
+ \ No newline at end of file
diff --git a/bootstrap.conf b/bootstrap.conf
index f7188de..ff05127 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -1,7 +1,7 @@
-# Bootstrap configuration for Mailfromd.
+# Bootstrap configuration for Pies.
# Copyright (C) 2008, 2009 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, or (at your option)
# any later version.
@@ -25,20 +25,13 @@ if [ -n "$MODAVOID" ]; then
fi
# gnulib modules used by this package.
gnulib_modules=`grep '^[^#]' gnulib.modules`
NLS_MARKERS="\
- MF_THROW:2\
- MF_ASSERT:3\
- parse_error:1\
- parse_error_locus:2\
- mu_error:1\
- gacopyz_io_log:3\
- gacopyz_logmsg:2\
- gacopyz_log:3"
+ mu_error:1"
# Additional xgettext options to use. Use "\\\newline" to break lines.
if [ -n "$NLS_MARKERS" ]; then
XGETTEXT_OPTIONS="$XGETTEXT_OPTIONS "`echo $NLS_MARKERS | tr ' ' '\n' | sed 's/.*/ --flag=&:pass-c-format\\\\\\\\\\\\/'`"
"
@@ -50,13 +43,13 @@ extract_bug_address='
s/[][]//g
s/.*=//p
}
'
COPYRIGHT_HOLDER="Sergey Poznyakoff"
-MSGID_BUGS_ADDRESS=`m4 -D'AC_INIT=AC-INIT-BUG-ADDRESS=$3' configure.ac | sed -n "$extract_bug_address"`
+MSGID_BUGS_ADDRESS=`echo 'changequote([,])' | m4 -D'AC_INIT=AC-INIT-BUG-ADDRESS=$3' - configure.ac | sed -n "$extract_bug_address"`
if test -z "$MSGID_BUGS_ADDRESS"; then
MSGID_BUGS_ADDRESS="bug-${package}@gnu.org.ua"
fi
# Read local configuration file
if [ -r .bootstrap ]; then
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..192fc53
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,97 @@
+# This file is part of Pies. -*- autoconf -*-
+# Copyright (C) 2009 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, 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/>.
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ([2.63])
+AC_INIT([pies], [1.0], [bug-mailfromd@gnu.org.ua])
+AC_CONFIG_SRCDIR([src/pies.h])
+AC_CONFIG_AUX_DIR([build-aux])
+AC_CONFIG_HEADERS([config.h])
+AM_INIT_AUTOMAKE([1.11 gnits tar-ustar dist-bzip2 std-options silent-rules])
+
+# Enable silent rules by default:
+AM_SILENT_RULES([yes])
+
+# Checks for programs.
+AC_PROG_CC
+gl_EARLY
+AC_PROG_MAKE_SET
+AC_PROG_RANLIB
+AC_PROG_YACC
+AC_PROG_LEX
+
+# Checks for libraries.
+
+# Checks for header files.
+AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/socket.h sys/time.h syslog.h unistd.h])
+
+# Checks for typedefs, structures, and compiler characteristics.
+AC_TYPE_UID_T
+AC_TYPE_MODE_T
+AC_TYPE_PID_T
+AC_TYPE_SIZE_T
+AC_TYPE_SIGNAL
+
+IU_CHECK_MEMBERS([struct msghdr.msg_control, struct msghdr.msg_accrights], , ,
+ [#include <sys/types.h>
+ #include <sys/socket.h>])
+
+# Checks for library functions.
+AC_FUNC_CHOWN
+AC_FUNC_FORK
+AC_CHECK_FUNCS([alarm dup2 gethostbyname isascii memmove memset select setenv socket strchr strcspn strtol strtoul sysconf getdtablesize])
+
+# Gnulib
+gl_INIT
+
+# **********************
+# Mailutils
+# **********************
+# FIXME
+AM_GNU_MAILUTILS(2.0, [mailer cfg argp], [:])
+
+# Test for setproctitle
+MF_PROCTITLE
+
+# Gettext.
+AM_ICONV
+AM_GNU_GETTEXT([external], [need-formatstring-macros])
+AM_GNU_GETTEXT_VERSION([0.17])
+
+# Doc hints.
+# Select a rendition level:
+# DISTRIB for stable releases (at most one dot in the version number)
+# and maintenance releases (two dots, patchlevel < 50)
+# PROOF for alpha releases.
+# PUBLISH can only be required manually when running make in doc/
+AC_SUBST(RENDITION)
+case `echo $VERSION|sed 's/[[^.]]//g'` in
+""|".") RENDITION=DISTRIB;;
+"..") if test `echo $VERSION | sed 's/.*\.//'` -lt 50; then
+ RENDITION=DISTRIB
+ else
+ RENDITION=PROOF
+ fi;;
+*) RENDITION=PROOF;;
+esac
+
+AC_CONFIG_FILES([Makefile
+ gnu/Makefile
+ lib/Makefile
+ src/Makefile
+ doc/Makefile
+ po/Makefile.in])
+AC_OUTPUT
diff --git a/doc/.gitignore b/doc/.gitignore
new file mode 100644
index 0000000..94d867b
--- /dev/null
+++ b/doc/.gitignore
@@ -0,0 +1,22 @@
+Makefile
+Makefile.in
+pies.info*
+stamp-vti
+version.texi
+pies.aux
+pies.cp
+pies.cps
+pies.dvi
+pies.fl
+pies.fn
+pies.kw
+pies.ky
+pies.log
+pies.mt
+pies.op
+pies.pg
+pies.pr
+pies.ps
+pies.toc
+pies.tp
+pies.vr
diff --git a/doc/Makefile.am b/doc/Makefile.am
index ee522f2..502c46e 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -1,50 +1,41 @@
-# This file is part of Mailfromd.
+# This file is part of Pies.
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Sergey Poznyakoff
#
-# Mailfromd is free software; you can redistribute it and/or modify
+# Pies 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.
#
-# Mailfromd is distributed in the hope that it will be useful,
+# Pies 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 Mailfromd. If not, see <http://www.gnu.org/licenses/>.
+# along with Pies. If not, see <http://www.gnu.org/licenses/>.
-info_TEXINFOS=mailfromd.texi
-mailfromd_TEXINFOS=\
+info_TEXINFOS=pies.texi
+pies_TEXINFOS=\
fdl.texi\
- gacopyz.texi\
macros.texi\
- mtasim.texi\
pies.texi\
- pmult.texi\
- pragma-database.texi\
- pragma-option.texi\
- rendition.texi\
- smap.texi\
- strftime.texi\
- upgrade.texi\
- values.texi
+ rendition.texi
EXTRA_DIST = \
check-docs.sh\
gendocs_template\
mastermenu.el\
untabify.el
clean-local:
@rm -rf manual
# Checking
check-format:
- @if test -n "`cat $(info_TEXINFOS) $(mailfromd_TEXINFOS) | tr -d -c '\t'`"; then \
+ @if test -n "`cat $(info_TEXINFOS) $(pies_TEXINFOS) | tr -d -c '\t'`"; then \
echo "Sources contain tabs; run make untabify"; \
false; \
fi
check-pragmas:
@check-docs.sh pragmas \
@@ -62,13 +53,13 @@ check-options:
$(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I $(srcdir) -E - \
$(info_TEXINFOS)
check-config:
@check-docs.sh 'configuration statements' \
'/mf_cfg_param\[\] *= *{/,/^}/s/[ \t]*{ *"\([^,"]*\)".*/\1/pg' \
- 's/@deffn {Mailfromd Conf} *\([^@,]*\).*/\1/p' \
+ 's/@deffn {Pies Conf} *\([^@,]*\).*/\1/p' \
$(top_srcdir)/mfd/main.c -- \
$(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I $(srcdir) -E - \
$(info_TEXINFOS)
check-sub-config:
@list=`sed -n '/mf_cfg_param\[\] *= *{/,/^}/{s/[ \t]*{ *"\([^,"]*\)", *mu_cfg_section *,.*/\1/pg}' $(top_srcdir)/mfd/main.c`; \
@@ -98,18 +89,18 @@ check-mflib:
$(info_TEXINFOS)
check-exceptions:
@check-docs.sh exceptions \
'/typedef enum mf_exception_code {/,/^};/s/[ \t]*mfe_\(.*\),.*/e_\1/p;/typedef enum mf_status_code {/,/^};/s/[ \t]*mf_\(.*\),.*/\1/p' \
's/@cindex \([^,][^,]*\), exception type/\1/p' \
- $(top_srcdir)/mfd/mailfromd.h -- \
+ $(top_srcdir)/mfd/pies.h -- \
$(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I $(srcdir) -E - \
$(info_TEXINFOS)
check-refs:
- @for file in $(info_TEXINFOS) $(mailfromd_TEXINFOS); \
+ @for file in $(info_TEXINFOS) $(pies_TEXINFOS); \
do \
sed -e = $$file | \
sed -n 'N;/@FIXME-.*ref/{s/\(^[0-9][0-9]*\).*@FIXME-.*ref{\([^}]*\)}.*/'$$file':\1: \2/gp}'; \
done > $@-t; \
if [ -s $@-t ]; then \
echo "Unresolved cross-references:"; \
@@ -117,13 +108,13 @@ check-refs:
rm $@-t; \
else \
rm -f $@-t; \
fi
check-fixmes:
- @for file in $(info_TEXINFOS) $(mailfromd_TEXINFOS); \
+ @for file in $(info_TEXINFOS) $(pies_TEXINFOS); \
do \
sed -e = $$file | \
sed -n 'N;/@FIXME{/{s/\(^[0-9][0-9]*\).*@FIXME{\([^}]*\).*/'$$file':\1: \2/gp}'; \
done > $@-t; \
if [ -s $@-t ]; then \
echo "Unresolved FIXMEs:"; \
@@ -132,24 +123,24 @@ check-fixmes:
false; \
else \
rm -f $@-t; \
fi
check-writeme:
- @grep -Hn @WRITEME $(info_TEXINFOS) $(mailfromd_TEXINFOS) > $@-t; \
+ @grep -Hn @WRITEME $(info_TEXINFOS) $(pies_TEXINFOS) > $@-t; \
if [ -s $@-t ]; then \
echo "Empty nodes:"; \
cat $@-t; \
rm $@-t; \
false;\
else \
rm $@-t; \
fi
check-unrevised:
- @grep -Hn @UNREVISED $(info_TEXINFOS) $(mailfromd_TEXINFOS) > $@-t; \
+ @grep -Hn @UNREVISED $(info_TEXINFOS) $(pies_TEXINFOS) > $@-t; \
if [ -s $@-t ]; then \
echo "Unrevised nodes:"; \
cat $@-t; \
rm $@-t; \
false;\
else \
@@ -167,13 +158,13 @@ check-docs:
#
master-menu:
$(AM_V_GEN)emacs -batch -l mastermenu.el -f make-master-menu $(info_TEXINFOS)
untabify:
- @emacs -batch -l untabify.el $(info_TEXINFOS) $(mailfromd_TEXINFOS)
+ @emacs -batch -l untabify.el $(info_TEXINFOS) $(pies_TEXINFOS)
final: untabify master-menu
# The rendering level is one of PUBLISH, DISTRIB or PROOF.
# Just call `make RENDITION=PROOF [target]' if you want PROOF rendition.
diff --git a/doc/pies.texi b/doc/pies.texi
index 7f020f1..cc35b5d 100644
--- a/doc/pies.texi
+++ b/doc/pies.texi
@@ -1,10 +1,106 @@
-@c This file is part of the Mailfromd manual.
-@c Copyright (C) 2008, 2009 Sergey Poznyakoff
-@c See file mailfromd.texi for copying conditions.
-@c *******************************************************************
+\input texinfo @c -*-texinfo-*-
+@smallbook
+@c %**start of header
+@setfilename pies.info
+@settitle Pies
+@c %**end of header
+@setchapternewpage odd
+
+@defcodeindex pr
+@defcodeindex op
+@c mt is the same as op, but used for mtasim options.
+@defcodeindex mt
+@defcodeindex kw
+@defcodeindex fl
+
+@syncodeindex fn cp
+@syncodeindex vr cp
+@syncodeindex ky cp
+@syncodeindex mt cp
+@syncodeindex pg cp
+@syncodeindex tp cp
+@syncodeindex op cp
+@syncodeindex pr cp
+@syncodeindex kw cp
+@syncodeindex fl cp
+
+@include version.texi
+@include rendition.texi
+@include macros.texi
+
+@ifinfo
+@dircategory GNU Utilities
+@direntry (pies) pies. Program execution supervisor.
+@end direntry
+@end ifinfo
+
+@copying
+Published by the Free Software Foundation,
+51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301 USA
+
+Copyright @copyright{} 2005, 2006, 2007, 2008, 2009 Sergey Poznyakoff
+
+Permission is granted to copy, distribute and/or modify this document
+under the terms of the GNU Free Documentation License, Version 1.2 or
+any later version published by the Free Software Foundation; with no
+Invariant Sections, with the Front-Cover texts being ``Pies Manual'',
+and with the Back-Cover Texts as in (a) below. A copy of the license
+is included in the section entitled ``GNU Free Documentation License''.
+
+(a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
+this GNU Manual, like GNU software. Copies published by the Free
+Software Foundation raise funds for GNU development.''
+@end copying
+
+@titlepage
+@title Program Invocation and Execution Supervisor
+@subtitle version @value{VERSION}, @value{UPDATED}
+@author Sergey Poznyakoff.
+@page
+@vskip 0pt plus 1filll
+@insertcopying
+@end titlepage
+
+@page
+@summarycontents
+@page
+@contents
+
+@ifnottex
+@node Top
+@top Pies
+
+This edition of the @cite{Pies Manual}, last updated @value{UPDATED},
+documents @command{pies} Version @value{VERSION}.
+@end ifnottex
+
+@menu
+* Intro::
+* Pies Configuration File::
+* Component Statement::
+* include-meta1::
+* Global Configuration::
+* Pies Debugging::
+* Configuration Example::
+* Command Line Usage::
+* Pies Invocation::
+
+Appendices
+
+* Copying This Manual:: The GNU Free Documentation License.
+* Concept Index:: Index of Concepts.
+
+@c @detailmenu
+@c @end detailmenu
+
+@end menu
+
+@node Intro
+@chapter Introduction
@cindex component, pies
The name @command{pies} (pronounced @samp{p-yes}) stands for
@samp{Program Invocation and Execution Supervisor}. This utility
starts and controls execution of external programs, called
@dfn{components}. Each component is a stand-alone program, which is
executed in the foreground. Upon startup, @command{pies} reads the list
@@ -82,32 +178,24 @@ configuration file and terminated in the reverse order. When starting or
stopping component dependencies, the same ordering is preserved.
This order is reversed for files included by @code{include-meta1}
statement (@pxref{include-meta1}).
@menu
-* Pies Configuration File::
-* Component Statement::
-* include-meta1::
-* Global Configuration::
-* Pies Debugging::
-* Configuration Example::
-* Command Line Usage::
-* Pies Invocation::
@end menu
@node Pies Configuration File
-@section Pies Configuration File
+@chapter Pies Configuration File
@command{Pies} reads its configuration from the main Mailutils
configuration file. @xref{configuration, Mailutils Configuration
File,, mailutils, GNU Mailutils Manual}, for a description of GNU
Mailutils configuration system. It is recommended to use
@code{include @var{directory}} statement (@pxref{Include, Include
Statement,, mailutils, GNU Mailutils Manual}), and to place
@command{pies} configuration in file @file{@var{directory}/pies}.
-@xref{MeTA1}, for an example.
+@xref{MeTA1,,, mailfromd, Mailfromd Manual}, for an example.
The following standard Mailutils configuration statements are understood:
@multitable @columnfractions 0.3 0.6
@headitem Statement @tab Reference
@item debug @tab @xref{Debug Statement, Mailutils Debug Statement,,
@@ -120,13 +208,13 @@ mailutils, GNU Mailutils Manual}.
mailutils, GNU Mailutils Manual}.
@item acl @tab @xref{ACL Statement, ACL Statement,,
mailutils, GNU Mailutils Manual}.
@end multitable
@node Component Statement
-@section Component Statement
+@chapter Component Statement
@kwindex component
The @code{component} statement defines a new component:
@smallexample
component @var{tag} @{
@dots{}
@@ -200,13 +288,13 @@ respawn too fast.
* Inetd-Style Components::
* Meta1-Style Components::
* Component Syntax Summary::
@end menu
@node Prerequisites
-@subsection Component Prerequisites
+@section Component Prerequisites
@cindex declaring prerequisites
@cindex prerequisites, declaring
Prerequisites (@pxref{component prerequisite}) for a component are
declared using the following statement:
@deffn {Pies Conf} prerequisites @var{tag-list}
@@ -227,13 +315,13 @@ No prerequisites. This is the default.
@deffn {Pies Conf} dependents @var{tag-list}
Declare dependents for this component. @var{var-list} is a list of
component tags.
@end deffn
@node Component Privileges
-@subsection Component Privileges
+@section Component Privileges
@cindex privileges, pies
Following statements control the privileges the component
is executed with.
@deffn {Pies Conf} user @var{user-name}
Start component with the UID and GID of this user.
@@ -247,13 +335,13 @@ Retain supplementary groups, specified in @var{group-list}.
Retain all supplementary groups of which the user (as given with
@command{user} statement) is a member. This is the default for
components specified in @file{meta1.conf} file (@pxref{include-meta1}).
@end deffn
@node Resources
-@subsection Resources
+@section Resources
@deffn {Pies Conf} limits @var{string}
Impose limits on system resources, as defined by @var{string}. The
argument consists of @dfn{commands}, optionally separated by any
amount of whitespace. A command is a single command letter followed
by a number, that specifies the limit. The command letters are
@@ -337,13 +425,13 @@ created and @var{value} is assigned to it. However, if @var{value}
ends with a punctuation character, this character is removed from it
before assignment.
@end table
@end deffn
@node Actions Before Startup
-@subsection Actions Before Startup
+@section Actions Before Startup
Several statements are available that specify actions to perform
immediately before starting the component:
@deffn {Pies Conf} chdir @var{dir}
Change to the directory @var{dir}.
@@ -362,13 +450,13 @@ Wait @var{number} seconds. This is kind of kludge. Currently it is
used for components imported from @file{meta1.conf} file
(@pxref{include-meta1}), where @code{settle-timeout 1} is implied.
This may change in future versions.
@end deffn
@node Exit Actions
-@subsection Exit Actions
+@section Exit Actions
@kwindex return-code
The default behavior of @command{pies} if an @samp{init-style}
component terminates is to restart it. Unless the component
terminates with 0 exit code, a corresponding error message is issued
to the log file. This behavior can be modified using
@code{return-code} statement:
@@ -474,13 +562,13 @@ body.
The following macro-variables are expanded within @var{string}:
@multitable @columnfractions 0.5 0.5
@headitem Variable @tab Expansion
@item canonical-program-name @tab @samp{pies}
@item program-name @tab Program name of the @command{pies} binary.
-@item package @tab Package name (@samp{Mailfromd}).
+@item package @tab Package name (@samp{Pies}).
@item version @tab Package version (@value{VERSION}).
@item mu-version @tab Version of GNU Mailutils.
@item component @tab Name of the terminated component.
@item retcode @tab Component exit code, in decimal.
@end multitable
@@ -501,13 +589,13 @@ that their @var{codes} do not intersect.
Such statements can also be used outside of @code{component} block.
In this case, they supply global actions, i.e. actions applicable to
all components. Any @code{return-code} statements appearing within a
@code{component} block override the global ones.
@node Output Redirectors
-@subsection Output Redirectors
+@section Output Redirectors
@cindex repeater
Output redirectors allow to redirect the standard error and/or standard
output of a component to a file or @command{syslog} facility.
@deffn {Pies Conf} stderr @var{type} @var{channel}
@deffnx {Pies Conf} stdout @var{type} @var{channel}
@@ -547,13 +635,13 @@ Specify the syslog facility to use in syslog redirectors. Allowed
values for @var{syslog-facility} are: @samp{user}, @samp{daemon},
@samp{auth}, @samp{authpriv}, @samp{mail}, @samp{cron}, @samp{local0}
through @samp{local7} (all names case-insensitive), or a facility number.
@end deffn
@node Inetd-Style Components
-@subsection Inetd-Style Components
+@section Inetd-Style Components
@cindex inetd-style components
Inetd-style components are declared using @code{mode inetd}
statement. You must also declare a socket to listen for requests for
such components:
@anchor{inetd-socket}
@@ -605,13 +693,13 @@ Notice, that @command{pies} version @value{VERSION} handles only
@acronym{TCP} sockets and only IPv4 addresses. Support for IPv6 will
be added in future versions. Support for @acronym{UDP} sockets will
be added if there is a demand.
@end deffn
@node Meta1-Style Components
-@subsection Meta1-Style Components
+@section Meta1-Style Components
@cindex meta1-style components
Meta1-style components are declared using @code{mode pass}
statement. For such components, you must declare both a socket to
listen on (@pxref{inetd-socket} and a @acronym{UNIX} socket name to
pass the file descriptor to the component. The latter is defined
using @code{pass-fd-socket} statement:
@@ -624,13 +712,13 @@ socket will be looked under @var{dir}.
This socket file is supposed to be created by the component binary
upon its startup.
@end deffn
@node Component Syntax Summary
-@subsection Component Syntax Summary
+@section Component Syntax Summary
This subsection summarizes the @code{component} summary. For each
statement, a reference to its detailed description is supplied.
@smallexample
component @var{tag} @{
# @r{Component execution mode.}
@@ -724,13 +812,13 @@ component @var{tag} @{
message @var{string};
@}
@}
@end smallexample
@node include-meta1
-@section Using MeTA1 Configuration File
+@chapter Using MeTA1 Configuration File
@cindex /etc/meta1/meta1.conf
@command{Pies} is able to take a list of components from MeTA1
configuration file:
@deffn {Pies Conf} include-meta1 @var{file}
Parse @var{file} as MeTA1 configuration file and incorporate
@@ -779,13 +867,13 @@ component smtps @{
facility local1;
stderr syslog debug;
@}
@end smallexample
@node Global Configuration
-@section Global Configuration
+@chapter Global Configuration
The statements described in this section affect @command{pies}
behavior as a whole.
@deffn {Pies Conf} umask @var{number}
Set the default umask. The @var{number} must be an octal value not greater
than @samp{777}. The default umask is inherited at startup.
@@ -808,13 +896,13 @@ Default is 5 seconds.
@menu
* Less Useful Statements::
@end menu
@node Less Useful Statements
-@subsection Less Useful Statements
+@section Less Useful Statements
Some configuration file statements are provided for completeness and
are rarely, if at all used. If used improperly, they may severely
impair the functionality of @command{pies} or even render it
useless. Do not use them, unless you have a good knowledge of
@command{pies} internals and understand their impact.
@@ -823,13 +911,13 @@ useless. Do not use them, unless you have a good knowledge of
needed by @command{pies}. Use them only if the defaults does not
suit your needs:
@deffn {Pies Conf} pidfile @var{file}
Write PID of the master @command{pies} process to @var{file}. By
default, master PID is stored in @file{@var{statedir}/pies.pid}
-(@pxref{statedir}).
+(@FIXME-pxref{statedir}).
@end deffn
@deffn {Pies Conf} control-file @var{file}
Set file name of the @command{pies} control file. Default is
@file{@var{statedir}/pies.ctl}
@end deffn
@@ -855,13 +943,13 @@ Retain supplementary groups, specified in @var{group-list}.
@deffn {Pies Conf} allgroups @var{bool}
Retain all supplementary groups of which user, given with
@command{user} statement, is a member.
@end deffn
@node Pies Debugging
-@section Pies Debugging
+@chapter Pies Debugging
The amount of debugging information produced by @command{pies} is configured
by the following two configuration statements. First of all, the standard
@code{debug} block statement controls debugging of the underlying GNU
Mailutils libraries (@pxref{Debug Statement, Mailutils Configuration
File,, mailutils, GNU Mailutils Manual}). Secondly, the @code{debug}
statement controls debugging output of the @command{pies} utility
@@ -891,25 +979,26 @@ Debug the parser of MeTA1 configuration grammar.
@item trace7
Debug the lexical analyzer of MeTA1 configuration file.
@end table
@end deffn
@node Configuration Example
-@section Configuration Example
+@chapter Configuration Example
In this section we provide several examples of working @command{pies}
configuration files.
@menu
* Simple Pies::
* Hairy Pies::
* Inetd Pies::
@end menu
@node Simple Pies
-@subsection Simplest Case: Using Pies to Run Pmult
- The example below runs @command{pmult} (@pxref{pmult}) utility with
+@section Simplest Case: Using Pies to Run Pmult
+ The example below runs @command{pmult} (@pxref{pmult, Pmilter
+multiplexer program,, mailfromd, Mailfromd Manual}) utility with
the privileges of @samp{meta1} user. Both standard error and standard
output are redirected to the syslog facility @samp{mail}, priorities
@samp{err} and @samp{info}, correspondingly.
@smallexample
component pmult @{
@@ -919,13 +1008,13 @@ component pmult @{
stderr syslog err;
stdout syslog info;
@}
@end smallexample
@node Hairy Pies
-@subsection Using Pies to Run Pmult and MeTA1
+@section Using Pies to Run Pmult and MeTA1
The example below is a working configuration file for running
@command{pmult} and all components of MeTA1, configured in
@file{/etc/meta1/meta1.conf}. The global @code{return-code} statement
is used to configure @command{pies} behavior for some exit codes.
@smallexample
@@ -961,13 +1050,13 @@ component pmult @{
@}
include-meta1 "/etc/meta1/meta1.conf";
@end smallexample
@node Inetd Pies
-@subsection Running Pies Instead of Inetd
+@section Running Pies Instead of Inetd
This configuration file allows to run @command{pies} instead of
@command{initd}. It starts two services: @samp{ftp} and @samp{pop3d},
and restricts access to them to two local subnets:
@smallexample
@@ -994,13 +1083,13 @@ component pop3d @{
program "/usr/sbin/pop3d";
command "pop3d --inetd";
@}
@end smallexample
@node Command Line Usage
-@section Command Line Usage
+@chapter Command Line Usage
When run without arguments, @command{pies} parses and loads the
configuration file, detaches itself from the controlling terminal
(becomes a daemon), and starts all components. Before actually
starting up, it ensures that no another instance of it is
already running, by looking for a PID file and verifying that the PID
@@ -1103,13 +1192,13 @@ $ pies --dump-prereq
qmgr: smar
smtpc: qmgr
smtps: smar qmgr
@end smallexample
@node Pies Invocation
-@section Pies Invocation
+@chapter Pies Invocation
This section summarizes @command{pies} command line options.
@table @option
@item --force
Force startup even if another instance may be running.
@@ -1154,6 +1243,19 @@ Dump prerequisite charts. @xref{dump-prereq}.
@end table
Apart from these, the common GNU Mailutils options are understood, which
are useful for checking @command{pies} configuration file for syntax
errors. @xref{Common Options, Common Options, , mailutils, GNU
Mailutils Manual}, for a detailed description of these.
+
+@node Copying This Manual
+@appendix GNU Free Documentation License
+@include fdl.texi
+
+@node Concept Index
+@unnumbered Concept Index
+
+This is a general index of all issues discussed in this manual
+
+@printindex cp
+
+@bye
diff --git a/gnulib.modules b/gnulib.modules
new file mode 100644
index 0000000..ef40e06
--- /dev/null
+++ b/gnulib.modules
@@ -0,0 +1,10 @@
+# List of gnulib modules needed for Pies.
+# A module name per line. Empty lines and comments are ignored.
+
+gettext
+gitlog-to-changelog
+inttostr
+inttypes
+xalloc
+sysexits
+c-ctype
diff --git a/lib/Makefile.am b/lib/Makefile.am
new file mode 100644
index 0000000..f83e7e3
--- /dev/null
+++ b/lib/Makefile.am
@@ -0,0 +1,33 @@
+# This file is part of Mailfromd.
+# Copyright (C) 2005, 2006, 2007, 2008 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, 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/>.
+
+noinst_LIBRARIES=libmf.a
+
+noinst_HEADERS = libpies.h
+
+libmf_a_SOURCES=\
+ config.c\
+ nls.c\
+ parsetime.c\
+ proctitle.c\
+ userprivs.c
+
+libmf_a_LIBADD=$(LIBOBJS)
+
+INCLUDES = -I$(top_srcdir)/gnu -I../gnu
+
+AM_CPPFLAGS=-DLOCALEDIR=\"$(localedir)\"
+
diff --git a/lib/config.c b/lib/config.c
new file mode 100644
index 0000000..8fcb926
--- /dev/null
+++ b/lib/config.c
@@ -0,0 +1,115 @@
+/* This file is part of Pies.
+ Copyright (C) 2007, 2008, 2009 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, 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 <libpies.h>
+
+
+char **
+config_array_to_argv (mu_config_value_t *val, mu_debug_t debug)
+{
+ int i, j;
+ int argc;
+ char **argv;
+
+ argc = val->v.arg.c;
+ argv = xcalloc (argc + 1, sizeof (argv[0]));
+ for (i = j = 0; i < argc; i++)
+ {
+ if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING,
+ debug) == 0)
+ argv[j++] = xstrdup (val->v.arg.v[i].v.string);
+ }
+ argv[j] = NULL;
+ return argv;
+}
+
+char *
+config_array_to_string (mu_config_value_t *val, mu_debug_t debug)
+{
+ size_t len = 0;
+ int i;
+ char *str, *p;
+
+ for (i = 0; i < val->v.arg.c; i++)
+ {
+ if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING, debug))
+ return NULL;
+ len += strlen (val->v.arg.v[i].v.string) + 1;
+ }
+
+ str = xmalloc (len);
+ p = str;
+ for (i = 0; i < val->v.arg.c; i++)
+ {
+ size_t n = strlen (val->v.arg.v[i].v.string);
+ memcpy (p, val->v.arg.v[i].v.string, n);
+ p += n;
+ *p++ = ' ';
+ }
+ str[len-1] = 0;
+ return str;
+}
+
+
+int
+config_cb_timeout (struct timeval *pt, mu_debug_t debug,
+ mu_config_value_t *val)
+{
+ int rc;
+ const char *endp;
+ time_t t;
+ const char *str;
+ char *alloc_str = NULL;
+
+ switch (val->type)
+ {
+ case MU_CFG_STRING:
+ str = val->v.string;
+ break;
+
+ case MU_CFG_ARRAY:
+ str = alloc_str = config_array_to_string (val, debug);
+ if (!str)
+ return 1;
+ break;
+
+ case MU_CFG_LIST:
+ mu_cfg_format_error (debug, MU_DEBUG_ERROR,
+ _("unexpected list"));
+ return 1;
+ }
+
+ rc = parse_time_interval (str, &t, &endp);
+ if (rc)
+ mu_cfg_format_error (debug, MU_DEBUG_ERROR,
+ _("unrecognized time format (near `%s')"),
+ endp);
+ else
+ {
+ pt->tv_usec = 0;
+ pt->tv_sec = t;
+ }
+ free (alloc_str);
+ return 0;
+}
+
+
+
+
diff --git a/lib/intprops.h b/lib/intprops.h
new file mode 100644
index 0000000..7db55e9
--- /dev/null
+++ b/lib/intprops.h
@@ -0,0 +1,79 @@
+/* intprops.h -- properties of integer types
+
+ Copyright (C) 2001, 2002, 2003, 2004, 2005,
+ 2007 Free Software Foundation, Inc.
+
+ 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, 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, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+/* Written by Paul Eggert. */
+
+#include <limits.h>
+
+/* The extra casts in the following macros work around compiler bugs,
+ e.g., in Cray C 5.0.3.0. */
+
+/* True if the arithmetic type T is an integer type. bool counts as
+ an integer. */
+#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
+
+/* True if negative values of the signed integer type T use two's
+ complement, ones' complement, or signed magnitude representation,
+ respectively. Much GNU code assumes two's complement, but some
+ people like to be portable to all possible C hosts. */
+#define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
+#define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
+#define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
+
+/* True if the arithmetic type T is signed. */
+#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+
+/* The maximum and minimum values for the integer type T. These
+ macros have undefined behavior if T is signed and has padding bits.
+ If this is a problem for you, please let us know how to fix it for
+ your host. */
+#define TYPE_MINIMUM(t) \
+ ((t) (! TYPE_SIGNED (t) \
+ ? (t) 0 \
+ : TYPE_SIGNED_MAGNITUDE (t) \
+ ? ~ (t) 0 \
+ : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))
+#define TYPE_MAXIMUM(t) \
+ ((t) (! TYPE_SIGNED (t) \
+ ? (t) -1 \
+ : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
+
+/* Return zero if T can be determined to be an unsigned type.
+ Otherwise, return 1.
+ When compiling with GCC, INT_STRLEN_BOUND uses this macro to obtain a
+ tighter bound. Otherwise, it overestimates the true bound by one byte
+ when applied to unsigned types of size 2, 4, 16, ... bytes.
+ The symbol signed_type_or_expr__ is private to this header file. */
+#if __GNUC__ >= 2
+# define signed_type_or_expr__(t) TYPE_SIGNED (__typeof__ (t))
+#else
+# define signed_type_or_expr__(t) 1
+#endif
+
+/* Bound on length of the string representing an integer type or expression T.
+ Subtract 1 for the sign bit if T is signed; log10 (2.0) < 146/485;
+ add 1 for integer division truncation; add 1 more for a minus sign
+ if needed. */
+#define INT_STRLEN_BOUND(t) \
+ ((sizeof (t) * CHAR_BIT - signed_type_or_expr__ (t)) * 146 / 485 \
+ + signed_type_or_expr__ (t) + 1)
+
+/* Bound on buffer size needed to represent an integer type or expression T,
+ including the terminating null. */
+#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)
diff --git a/lib/libpies.h b/lib/libpies.h
new file mode 100644
index 0000000..4733c63
--- /dev/null
+++ b/lib/libpies.h
@@ -0,0 +1,70 @@
+/* This file is part of Pies.
+ Copyright (C) 2009 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, 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 <unistd.h>
+#include <stdlib.h>
+#include <gettext.h>
+#include <mailutils/types.h>
+#include <mailutils/cfg.h>
+
+
+#define _(String) gettext(String)
+#define N_(String) String
+
+
+#if defined HAVE_SYSCONF && defined _SC_OPEN_MAX
+# define getmaxfd() sysconf(_SC_OPEN_MAX)
+#elif defined (HAVE_GETDTABLESIZE)
+# define getmaxfd() getdtablesize()
+#else
+# define getmaxfd() 256
+#endif
+
+
+
+void *xmalloc (size_t size);
+void *xzalloc (size_t size);
+void *xcalloc (size_t count, size_t size);
+char *xstrdup (const char *str);
+
+
+struct mf_privs
+{
+ char *user;
+ int allgroups;
+ mu_list_t groups;
+};
+
+int switch_to_privs (uid_t uid, gid_t gid, mu_list_t retain_groups);
+int get_user_groups (mu_list_t *pgrouplist, const char *user);
+
+void mf_priv_setup (struct mf_privs *);
+void mf_epriv_setup (struct mf_privs *);
+
+
+char **config_array_to_argv (mu_config_value_t *val, mu_debug_t debug);
+char *config_array_to_string (mu_config_value_t *val, mu_debug_t debug);
+
+int config_cb_timeout (struct timeval *pt, mu_debug_t debug,
+ mu_config_value_t *val);
+
+
+void mf_proctitle_init (int argc, char *argv[], char *env[]);
+void mf_proctitle_format (const char *fmt, ...);
+
+
+size_t longtostr (long i, char *buf, size_t size);
+size_t ulongtostr (unsigned long i, char *buf, size_t size);
diff --git a/lib/nls.c b/lib/nls.c
new file mode 100644
index 0000000..f2b067e
--- /dev/null
+++ b/lib/nls.c
@@ -0,0 +1,34 @@
+/* This file is part of Mailfromd.
+ Copyright (C) 2007, 2008 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, 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 <libpies.h>
+#include <locale.h>
+#include <mailutils/nls.h>
+
+void
+mf_init_nls ()
+{
+#ifdef ENABLE_NLS
+ mu_init_nls ();
+ setlocale (LC_ALL, "");
+ bindtextdomain (PACKAGE, LOCALEDIR);
+ bindtextdomain ("mailfromd", LOCALEDIR);
+ textdomain (PACKAGE);
+#endif
+}
diff --git a/lib/parsetime.c b/lib/parsetime.c
new file mode 100644
index 0000000..99d8079
--- /dev/null
+++ b/lib/parsetime.c
@@ -0,0 +1,109 @@
+/* This file is part of Pies.
+ Copyright (C) 2007, 2008, 2009 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, 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 <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <c-ctype.h>
+
+static int
+time_multiplier(const char *str, unsigned *m, unsigned *plen)
+{
+ static struct timetab {
+ char *name;
+ unsigned mul;
+ } tab[] = {
+ { "seconds", 1 },
+ { "minutes", 60 },
+ { "hours", 60*60 },
+ { "days", 24*60*60 },
+ { "weeks", 7*24*60*60 },
+ { "months", 31*7*24*60*60 },
+ { NULL }
+ };
+ struct timetab *p;
+ int slen;
+
+ for (slen = 0; str[slen]; slen++)
+ if (c_isspace(str[slen]))
+ break;
+
+ for (p = tab; p->name; p++) {
+ if (p->name[0] == c_tolower(str[0])) {
+ int nlen = strlen(p->name);
+
+ if (nlen > slen)
+ nlen = slen;
+
+ if (strncasecmp(p->name, str, nlen) == 0) {
+ *m = p->mul;
+ if (plen)
+ *plen = nlen;
+ return 0;
+ }
+ }
+ }
+ return 1;
+}
+
+int
+parse_time_interval(const char *str, time_t *pint, const char **endp)
+{
+ int rc = 0;
+ time_t interval = 0;
+
+ while (*str) {
+ char *p;
+ unsigned long n;
+ unsigned mul, len;
+
+ while (*str && c_isspace(*str))
+ str++;
+
+ if (!c_isdigit(*str) && time_multiplier(str, &mul, &len) == 0) {
+ n = 1;
+ str += len;
+ } else {
+ n = strtoul(str, &p, 10);
+ if (*p && !c_isspace(*p)) {
+ str = p;
+ rc = 1;
+ break;
+ }
+
+ while (*p && c_isspace(*p))
+ p++;
+
+ str = p;
+ if (*str) {
+ if (rc = time_multiplier(str, &mul, &len))
+ break;
+ str += len;
+ } else
+ mul = 1;
+ }
+ interval += n*mul;
+ }
+
+ if (rc && endp)
+ *endp = str;
+ *pint = interval;
+ return rc;
+}
+
diff --git a/lib/proctitle.c b/lib/proctitle.c
new file mode 100644
index 0000000..f9ff967
--- /dev/null
+++ b/lib/proctitle.c
@@ -0,0 +1,164 @@
+/* This file is part of Mailfromd.
+ Copyright (C) 2007, 2008 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, 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 <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#if MF_PROCTITLE_TYPE == MF_PROCTITLE_PSTAT
+# include <sys/pstat.h>
+#elif MF_PROCTITLE_TYPE == MF_PROCTITLE_PSSTRINGS
+# include <sys/proc.h>
+# include <vm/pmap.h>
+# include <machine/pmap.h>
+# include <machine/vmparam.h>
+# include <sys/exec.h>
+#endif
+
+extern char **environ;
+
+/* Move the environment to prepare more space for argv */
+static int
+move_env (char *env[])
+{
+ size_t size;
+ int i;
+ char **p;
+
+ size = 0;
+ for (i = 0; env[i]; i++)
+ size += strlen (env[i]) + 1;
+
+ p = calloc (i + 1, sizeof (*p));
+ if (!p)
+ return 1;
+
+ for (i = 0; env[i]; i++)
+ if ((p[i] = strdup(env[i])) == NULL) {
+ int j;
+ /* Free allocated memory and return */
+ for (j = 0; j < i; j++)
+ free(p[i]);
+ free(p);
+ return 1;
+ }
+ p[i] = NULL;
+ environ = p;
+ return 0;
+}
+
+static int orig_argc;
+static char **orig_argv;
+static char *orig_argv_end;
+static char *proctitle_buffer;
+#ifdef HAVE___PROGNAME
+extern char *__progname;
+extern char *__progname_full;
+#else
+static char *__progname;
+#endif
+
+void
+mf_proctitle_init (int argc, char *argv[], char *env[])
+{
+ int i;
+
+ move_env (env);
+
+ orig_argc = argc;
+ orig_argv = argv;
+ orig_argv_end = argv[0] + strlen (argv[0]);
+ __progname = strrchr (argv[0], '/');
+ if (__progname)
+ __progname++;
+ else
+ __progname = argv[0];
+ __progname = strdup (__progname);
+#ifdef HAVE___PROGNAME
+ __progname_full = strdup(argv[0]);
+#endif
+
+ for (i = 0; i < orig_argc; i++) {
+ if (orig_argv_end + 1 == argv[i])
+ orig_argv_end = argv[i] + strlen(argv[i]);
+ }
+
+ for (i = 0; env[i]; i++) {
+ if ((orig_argv_end + 1) == env[i])
+ orig_argv_end = env[i] + strlen(env[i]);
+ }
+}
+
+static void
+mf_proctitle_flush ()
+{
+#if MF_PROCTITLE_TYPE == MF_PROCTITLE_SETPROCTITLE
+ setproctitle ("%s", proctitle_buffer);
+#elif MF_PROCTITLE_TYPE == MF_PROCTITLE_REPLACE_ARGV
+ orig_argv[0] = proctitle_buffer;
+ for (i = 1; i < orig_argc; i++) {
+ orig_argv[i] = "";
+ }
+#elif MF_PROCTITLE_TYPE == MF_PROCTITLE_REWRITE_ARGV
+ size_t argv_size = orig_argv_end - orig_argv[0] - 2;
+ size_t len = strlen (proctitle_buffer);
+ memset (orig_argv[0], 0, argv_size);
+ if (len > argv_size)
+ len = argv_size;
+ memcpy (orig_argv[0], proctitle_buffer, len);
+ orig_argv[0][len] = 0;
+#elif MF_PROCTITLE_TYPE == MF_PROCTITLE_PSTAT
+ union pstun pst;
+ pst.pst_command = proc_title_buf;
+ pstat(PSTAT_SETCMD, pst, strlen (proctitle_buffer), 0, 0);
+#elif MF_PROCTITLE_TYPE == MF_PROCTITLE_PSSTRINGS
+ PS_STRINGS->ps_nargvstr = 1;
+ PS_STRINGS->ps_argvstr = proctitle_buffer;
+#endif
+}
+
+void
+mf_proctitle_format (const char *fmt, ...)
+{
+ va_list ap;
+ char *tmp = NULL;
+
+ if (!orig_argc)
+ return;
+ va_start (ap, fmt);
+ vasprintf (&tmp, fmt, ap);
+ va_end (ap);
+ if (tmp) {
+ free (proctitle_buffer);
+#if __FreeBSD__ >= 4
+ /* On FreeBSD the process name is prepended automatically */
+ proctitle_buffer = tmp;
+#else
+ /* Otherwise we need to do that manually */
+ asprintf (&proctitle_buffer, "%s: %s", __progname, tmp);
+ if (proctitle_buffer)
+ free (tmp);
+ else
+ proctitle_buffer = tmp;
+#endif
+ mf_proctitle_flush ();
+ }
+}
diff --git a/lib/userprivs.c b/lib/userprivs.c
new file mode 100644
index 0000000..8d13c38
--- /dev/null
+++ b/lib/userprivs.c
@@ -0,0 +1,291 @@
+/* This file is part of Mailfromd.
+ Copyright (C) 2007, 2008 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, 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 <stdlib.h>
+#include <string.h>
+#include <pwd.h>
+#include <grp.h>
+#include <unistd.h>
+#include <mailutils/assoc.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/errno.h>
+#include <mailutils/nls.h>
+#include <mailutils/list.h>
+#include <mailutils/iterator.h>
+/* FIXME: */
+#include <sysexits.h>
+#include "libpies.h"
+
+int
+get_user_groups (mu_list_t *pgrouplist, const char *user)
+{
+ int rc;
+ struct group *gr;
+ mu_list_t list;
+
+ if (!*pgrouplist)
+ {
+ rc = mu_list_create (pgrouplist);
+ if (rc)
+ {
+ mu_error (_("%s: cannot create list: %s"),
+ "get_user_groups", mu_strerror (rc));
+ return rc;
+ }
+ }
+ list = *pgrouplist;
+ setgrent ();
+ for (rc = 0; rc == 0 && (gr = getgrent ());)
+ {
+ char **p;
+ for (p = gr->gr_mem; *p; p++)
+ if (strcmp (*p, user) == 0)
+ {
+ /* FIXME: Avoid duplicating gids */
+ rc = mu_list_append (list, (void *) gr->gr_gid);
+ if (rc)
+ mu_error (_("%s: cannot append to list: %s"),
+ "get_user_groups", mu_strerror (rc));
+ break;
+ }
+ }
+ endgrent ();
+ return rc;
+}
+
+/* Switch to the given UID/GID */
+int
+switch_to_privs (uid_t uid, gid_t gid, mu_list_t retain_groups)
+{
+ int rc = 0;
+ gid_t *emptygidset;
+ size_t size = 1, j = 1;
+ mu_iterator_t itr;
+
+ if (uid == 0)
+ {
+ mu_error (_("Refusing to run as root"));
+ return 1;
+ }
+
+ /* Create a list of supplementary groups */
+ mu_list_count (retain_groups, &size);
+ size++;
+ emptygidset = xmalloc (size * sizeof emptygidset[0]);
+ emptygidset[0] = gid ? gid : getegid ();
+
+ if (mu_list_get_iterator (retain_groups, &itr) == 0)
+ {
+ for (mu_iterator_first (itr);
+ !mu_iterator_is_done (itr); mu_iterator_next (itr))
+ mu_iterator_current (itr, (void **) (emptygidset + j++));
+ mu_iterator_destroy (&itr);
+ }
+
+ /* Reset group permissions */
+ if (geteuid () == 0 && setgroups (j, emptygidset))
+ {
+ mu_error (_("setgroups(1, %lu) failed: %s"),
+ (unsigned long) emptygidset[0], mu_strerror (errno));
+ rc = 1;
+ }
+ free (emptygidset);
+
+ /* Switch to the user's gid. On some OSes the effective gid must
+ be reset first */
+
+#if defined(HAVE_SETEGID)
+ if ((rc = setegid (gid)) < 0)
+ mu_error (_("setegid(%lu) failed: %s"),
+ (unsigned long) gid, mu_strerror (errno));
+#elif defined(HAVE_SETREGID)
+ if ((rc = setregid (gid, gid)) < 0)
+ mu_error (_("setregid(%lu,%lu) failed: %s"),
+ (unsigned long) gid, (unsigned long) gid, mu_strerror (errno));
+#elif defined(HAVE_SETRESGID)
+ if ((rc = setresgid (gid, gid, gid)) < 0)
+ mu_error (_("setresgid(%lu,%lu,%lu) failed: %s"),
+ (unsigned long) gid,
+ (unsigned long) gid, (unsigned long) gid, mu_strerror (errno));
+#endif
+
+ if (rc == 0 && gid != 0)
+ {
+ if ((rc = setgid (gid)) < 0 && getegid () != gid)
+ mu_error (_("setgid(%lu) failed: %s"),
+ (unsigned long) gid, mu_strerror (errno));
+ if (rc == 0 && getegid () != gid)
+ {
+ mu_error (_("Cannot set effective gid to %lu"),
+ (unsigned long) gid);
+ rc = 1;
+ }
+ }
+
+ /* Now reset uid */
+ if (rc == 0 && uid != 0)
+ {
+ uid_t euid;
+
+ if (setuid (uid)
+ || geteuid () != uid
+ || (getuid () != uid && (geteuid () == 0 || getuid () == 0)))
+ {
+
+#if defined(HAVE_SETREUID)
+ if (geteuid () != uid)
+ {
+ if (setreuid (uid, -1) < 0)
+ {
+ mu_error (_("setreuid(%lu,-1) failed: %s"),
+ (unsigned long) uid, mu_strerror (errno));
+ rc = 1;
+ }
+ if (setuid (uid) < 0)
+ {
+ mu_error (_("second setuid(%lu) failed: %s"),
+ (unsigned long) uid, mu_strerror (errno));
+ rc = 1;
+ }
+ }
+ else
+#endif
+ {
+ mu_error (_("setuid(%lu) failed: %s"),
+ (unsigned long) uid, mu_strerror (errno));
+ rc = 1;
+ }
+ }
+
+ euid = geteuid ();
+ if (uid != 0 && setuid (0) == 0)
+ {
+ mu_error (_("seteuid(0) succeeded when it should not"));
+ rc = 1;
+ }
+ else if (uid != euid && setuid (euid) == 0)
+ {
+ mu_error (_("Cannot drop non-root setuid privileges"));
+ rc = 1;
+ }
+
+ }
+
+ return rc;
+}
+
+
+static int
+translate_item (void *item, void *data)
+{
+ mu_list_t dst = data;
+ struct group *group = getgrnam (item);
+ if (!group)
+ {
+ mu_error (_("Unknown group: %s"), (char *) item);
+ return 1;
+ }
+ return mu_list_append (dst, (void *) group->gr_gid);
+}
+
+static int
+grouplist_translate (mu_list_t * pdst, mu_list_t src)
+{
+ mu_list_t dst;
+ int rc;
+
+ if (!src)
+ return 0;
+ rc = mu_list_create (&dst);
+ if (rc)
+ {
+ mu_error (_("%s: cannot create list: %s"),
+ "grouplist_translate", mu_strerror (rc));
+ return rc;
+ }
+ *pdst = dst;
+ return mu_list_do (src, translate_item, dst);
+}
+
+void
+mf_priv_setup (struct mf_privs *privs)
+{
+ struct passwd *pw;
+ mu_list_t grp = NULL;
+
+ if (!privs || !privs->user)
+ return;
+
+ pw = getpwnam (privs->user);
+ if (!pw)
+ {
+ mu_error (_("No such user: %s"), privs->user);
+ exit (EX_CONFIG);
+ }
+
+ grouplist_translate (&grp, privs->groups);
+ if (privs->allgroups && get_user_groups (&grp, privs->user))
+ exit (EX_CONFIG);
+ if (switch_to_privs (pw->pw_uid, pw->pw_gid, grp))
+ exit (EX_SOFTWARE);
+ mu_list_destroy (&grp);
+}
+
+
+void
+mf_epriv_setup (struct mf_privs *privs)
+{
+ uid_t uid;
+ gid_t gid;
+
+ if (privs)
+ {
+ struct passwd *pw;
+ if (!privs->user)
+ return;
+
+ pw = getpwnam (privs->user);
+ if (!pw)
+ {
+ mu_error (_("No such user: %s"), privs->user);
+ exit (EX_CONFIG);
+ }
+ uid = pw->pw_uid;
+ gid = pw->pw_gid;
+ }
+ else
+ {
+ uid = 0;
+ gid = 0;
+ }
+
+ if (setegid (gid))
+ {
+ mu_error (_("Cannot switch to EGID %lu: %s"),
+ (unsigned long) gid, mu_strerror (errno));
+ exit (EX_USAGE);
+ }
+ if (seteuid (uid))
+ {
+ mu_error (_("Cannot switch to EUID %lu: %s"),
+ (unsigned long) uid, mu_strerror (errno));
+ exit (EX_USAGE);
+ }
+}
diff --git a/po/.gitignore b/po/.gitignore
new file mode 100644
index 0000000..641662d
--- /dev/null
+++ b/po/.gitignore
@@ -0,0 +1,21 @@
+*.gmo
+*.po
+*.po~
+.pot
+.reference/
+LINGUAS
+Makefile.in.in
+Makevars
+Makevars.template
+POTFILES
+Rules-quot
+boldquot.sed
+en@boldquot.header
+en@quot.header
+insert-header.sed
+insert-header.sin
+pies.pot
+quot.sed
+remove-potcdate.sed
+remove-potcdate.sin
+stamp-po
diff --git a/po/POTFILES.in b/po/POTFILES.in
new file mode 100644
index 0000000..32b939c
--- /dev/null
+++ b/po/POTFILES.in
@@ -0,0 +1,19 @@
+# List of files which contain translatable strings.
+
+# Copyright (C) 2007, 2008 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, 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/>.
+
+src/pies.c
+src/progman.c
diff --git a/pies/.gitignore b/src/.gitignore
index 8a4684a..8a4684a 100644
--- a/pies/.gitignore
+++ b/src/.gitignore
diff --git a/pies/Makefile.am b/src/Makefile.am
index 7aaf759..52648c8 100644
--- a/pies/Makefile.am
+++ b/src/Makefile.am
@@ -39,19 +39,18 @@ DISTCLEANFILES = pies.rc
meta1lex.c: meta1gram.h
INCLUDES = \
$(MAILUTILS_INCLUDES)\
$(MU_COMMON_INCLUDES)\
-I$(top_srcdir)/lib\
- -I$(top_srcdir)/gnu\
- -I../gnu
+ -I$(top_srcdir)/gnu
LDADD = \
../lib/libmf.a\
- $(MAILUTILS_LIBS)\
../gnu/libgnu.a\
+ $(MAILUTILS_LIBS)\
$(MF_PROCTITLE_LIBS)
AM_CPPFLAGS=-DSYSCONFDIR=\"$(sysconfdir)\"\
-DSTATEDIR=\"$(localstatedir)\"
AM_YFLAGS=-dvt -pmeta1
diff --git a/pies/depmap.c b/src/depmap.c
index 76b492f..76b492f 100644
--- a/pies/depmap.c
+++ b/src/depmap.c
diff --git a/pies/limits.c b/src/limits.c
index 90d6459..90d6459 100644
--- a/pies/limits.c
+++ b/src/limits.c
diff --git a/pies/meta1gram.y b/src/meta1gram.y
index 4966634..4966634 100644
--- a/pies/meta1gram.y
+++ b/src/meta1gram.y
diff --git a/pies/meta1lex.h b/src/meta1lex.h
index 8db32f9..8db32f9 100644
--- a/pies/meta1lex.h
+++ b/src/meta1lex.h
diff --git a/pies/meta1lex.l b/src/meta1lex.l
index 312a1fd..312a1fd 100644
--- a/pies/meta1lex.l
+++ b/src/meta1lex.l
diff --git a/pies/pies.c b/src/pies.c
index 5e8151a..10862c2 100644
--- a/pies/pies.c
+++ b/src/pies.c
@@ -1109,19 +1109,12 @@ static struct argp argp = {
NULL,
NULL,
NULL
};
-static void
-version (FILE *stream, struct argp_state *state)
-{
- mailfromd_version ("pies", stream);
-}
-
-
#define ACTION_CONT 0
#define ACTION_STOP 1
#define ACTION_RESTART 2
#define ACTION_COMPRELOAD 3
#define ACTION_DUMPSTATS 4
@@ -1413,18 +1406,19 @@ int
main (int argc, char **argv)
{
int rc;
int index;
pid_t pid;
extern char **environ;
+ extern char *program_invocation_short_name; /* FIXME */
mf_init_nls ();
mf_proctitle_init (argc, argv, environ);
if (!program_invocation_short_name)
program_invocation_short_name = argv[0];
- argp_program_version_hook = version;
+
/* Set default logging */
log_setup (!stderr_closed_p ());
mu_acl_cfg_init ();
return_code_cfg_init ();
component_cfg_init ();
mu_app_cfg_verifier = pies_cfg_verifier;
diff --git a/pies/pies.h b/src/pies.h
index 69683dd..add175c 100644
--- a/pies/pies.h
+++ b/src/pies.h
@@ -1,8 +1,8 @@
/* This file is part of Mailfromd.
- Copyright (C) 2008 Sergey Poznyakoff
+ Copyright (C) 2008, 2009 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, or (at your option)
any later version.
@@ -40,15 +40,15 @@
#include <mailutils/mailutils.h>
#include <mailutils/daemon.h>
#include <mailutils/libargp.h>
#include <mailutils/syslog.h>
#include "inttostr.h"
-#include "xalloc.h"
#include "c-ctype.h"
-#include "libmf.h"
+#include "xalloc.h"
+#include "libpies.h"
#define TESTTIME 2*60
#define SLEEPTIME 5*60
#define MAXSPAWN 10
#define RETR_OUT 0
diff --git a/pies/pies.rcin b/src/pies.rcin
index 85a2504..85a2504 100644
--- a/pies/pies.rcin
+++ b/src/pies.rcin
diff --git a/pies/progman.c b/src/progman.c
index 9383aae..9383aae 100644
--- a/pies/progman.c
+++ b/src/progman.c
diff --git a/pies/socket.c b/src/socket.c
index 03ee59c..03ee59c 100644
--- a/pies/socket.c
+++ b/src/socket.c

Return to:

Send suggestions and report system problems to the System administrator.