diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-04-24 15:44:01 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-04-24 15:44:01 +0000 |
commit | 23c190d057f68de84cb17bf8555397642fc6f6a9 (patch) | |
tree | 48272c668c3c1986fefd49ab657396b8a2976247 /gacopyz | |
parent | 2e708415a056624b4845467c9eebbbab7c1ef0f2 (diff) | |
download | mailfromd-23c190d057f68de84cb17bf8555397642fc6f6a9.tar.gz mailfromd-23c190d057f68de84cb17bf8555397642fc6f6a9.tar.bz2 |
* src/lex.l (parse_require): Bugfix
* src/bi_mail.m4: Bugfix
* src/mtasim.c: Implement help, fix directory removal at exit,
implement readline history file. Bugfixes in smtp()
* tests/testsuite.at, tests/accept.at, tests/greylist.at,
tests/arg.at, tests/reject.at, tests/numrcpt.at,
tests/tempfail.at: Use mtasim -Xauto when necessary
* configure.ac, NEWS: Raise patchlevel to 92
* doc/mailfromd.texi: Update
* doc/mtasim.texi: mtasim documentation
* doc/Makefile.am: Add mtasim.texi
* gacopyz/gacopyz_priv.h (struct gacopyz_conn): Keep information
about children pids
* gacopyz/proc.c (gacopyz_register_child)
(gacopyz_unregister_child): New functions
(cleanup_children): Call gacopyz_unregister_child
(gacopyz_cleanup_conn): Terminate children individualy instead of
sending TERM to the whole process group, because we might be not
the group leader.
* gacopyz/gacopyz.c (gacopyz_handle_connection): Register child
pid after startup.
* bootstrap: Require save-cwd. Test if lib/daemon.c exists before
attempting to create it.
git-svn-id: file:///svnroot/mailfromd/trunk@1379 7a8a7f39-df28-0410-adc6-e0d955640f24
Diffstat (limited to 'gacopyz')
-rw-r--r-- | gacopyz/gacopyz.c | 6 | ||||
-rw-r--r-- | gacopyz/gacopyz_priv.h | 5 | ||||
-rw-r--r-- | gacopyz/proc.c | 44 |
3 files changed, 52 insertions, 3 deletions
diff --git a/gacopyz/gacopyz.c b/gacopyz/gacopyz.c index f61673cc..a7a50177 100644 --- a/gacopyz/gacopyz.c +++ b/gacopyz/gacopyz.c @@ -68,7 +68,10 @@ gacopyz_init(gacopyz_conn_t *pconn, struct smfiDesc *desc) void gacopyz_free(gacopyz_conn_t conn) { - free(conn); + if (conn) { + free(conn->pidtab); + free(conn); + } } int @@ -1361,6 +1364,7 @@ gacopyz_handle_connection(gacopyz_conn_t conn) return MI_FAILURE; } if (pid > 0) { + gacopyz_register_child(conn, pid); close(fd); return MI_SUCCESS; } diff --git a/gacopyz/gacopyz_priv.h b/gacopyz/gacopyz_priv.h index 9ec99ff2..30486f42 100644 --- a/gacopyz/gacopyz_priv.h +++ b/gacopyz/gacopyz_priv.h @@ -59,6 +59,8 @@ struct gacopyz_conn { struct timeval master_timeout; struct timeval ctx_timeout; struct smfiDesc desc; + pid_t *pidtab; + size_t pidcount; }; #define GACOPYZ_TIMEOUT 7210 @@ -88,3 +90,6 @@ int gacopyz_send_command(gacopyz_iod_t iod, int cmd, const void *data, size_t size); int gacopyz_read_command(gacopyz_iod_t iod, unsigned char *cmd, size_t *pcount, char **pbuf, size_t *psize); +int gacopyz_register_child(gacopyz_conn_t conn, pid_t pid); +int gacopyz_unregister_child(gacopyz_conn_t conn, pid_t pid); + diff --git a/gacopyz/proc.c b/gacopyz/proc.c index 5df987e1..d388c1fa 100644 --- a/gacopyz/proc.c +++ b/gacopyz/proc.c @@ -20,6 +20,42 @@ static int cleanup_needed; +#define PIDTAB_INCR 256 + +int +gacopyz_register_child(gacopyz_conn_t conn, pid_t pid) +{ + size_t i, newcount; + pid_t *p; + + for (i = 0; i < conn->pidcount; i++) + if (conn->pidtab[i] == 0) { + conn->pidtab[i] = pid; + return 0; + } + + newcount = conn->pidcount + PIDTAB_INCR; + p = realloc(conn->pidtab, newcount * sizeof(conn->pidtab[0])); + if (!p) + return 1; + memset(p + i, 0, PIDTAB_INCR * sizeof(conn->pidtab[0])); + conn->pidcount = newcount; + conn->pidtab = p; + + conn->pidtab[i++] = pid; + return 0; +} + +int +gacopyz_unregister_child(gacopyz_conn_t conn, pid_t pid) +{ + size_t i; + + for (i = 0; i < conn->pidcount; i++) + if (conn->pidtab[i] == pid) + conn->pidtab[i] = 0; +} + static void print_status(gacopyz_conn_t conn, pid_t pid, int status, int expect_term) { @@ -68,6 +104,7 @@ cleanup_children(gacopyz_conn_t conn, int expect_term) pid_t pid = waitpid((pid_t)-1, &status, WNOHANG); if (pid <= 0) break; + gacopyz_unregister_child(conn, pid); print_status(conn, pid, status, expect_term); } cleanup_needed = 0; @@ -82,9 +119,12 @@ gacopyz_cleanup_children(gacopyz_conn_t conn) void gacopyz_cleanup_conn(gacopyz_conn_t conn) { + size_t i; gacopyz_log(conn, SMI_LOG_DEBUG, "terminating subprocesses"); - signal(SIGTERM, SIG_IGN); - kill(0, SIGTERM); + + for (i = 0; i < conn->pidcount; i++) + if (conn->pidtab[i]) + kill(conn->pidtab[i], SIGTERM); cleanup_children(conn, 1); } |