Add SIGCHLD signal(3) handling to prevent zombie processes

This commit is contained in:
Mario Sergio Fujikawa Ferreira 2002-11-19 02:12:55 +00:00
parent a59bb3d05b
commit bdaf558d2d
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=70449
6 changed files with 208 additions and 0 deletions

View File

@ -7,6 +7,7 @@
PORTNAME= dctc
PORTVERSION= 0.65
PORTREVISION= 1
CATEGORIES= net gnome
MASTER_SITES= http://unixpages.org/distfiles/ \
http://ac2i.tzo.com/dctc/
@ -31,8 +32,15 @@ CONFIGURE_ARGS= --with-gnome=${X11BASE} \
--enable-manual-db-detect \
--with-libiconv-prefix=${LOCALBASE}
ADDITIONAL_SRCS= sig_chld.c
#
DOC_FILES= COPYING ChangeLog README TODO
post-extract:
.for file in ${ADDITIONAL_SRCS}
@${CP} ${FILESDIR}/${file} ${WRKSRC}/src
.endfor
post-patch:
@${FIND} ${WRKSRC} -type f | ${XARGS} -n 10 -x ${REINPLACE_CMD} -E -e \
's|ldb-4.0|ldb4|; \
@ -52,6 +60,13 @@ post-patch:
@${FIND} ${WRKSRC} -type f \
-name "*.bak" \
| ${XARGS} -n 10 -x ${RM}
# add sigchld handler
.for file in ${ADDITIONAL_SRCS}
@${REINPLACE_CMD} -E -e \
's|^(dc_gui_SOURCES.+)$$|\1 ${file}|; \
s|^(dc_gui_OBJECTS[^\\]+)(\\*)$$|\1 ${file:S/.c$/.o/} \2|' \
${WRKSRC}/src/Makefile.in
.endfor
post-configure:
@${ECHO_CMD} '#ifndef MSG_NOSIGNAL' >> ${CONFIGURE_WRKSRC}/config.h

View File

@ -0,0 +1,36 @@
--- src/main.c.orig Mon Nov 18 23:53:50 2002
+++ src/main.c Mon Nov 18 23:55:01 2002
@@ -43,6 +43,9 @@
GtkWidget *done_popup=NULL;
GtkWidget *fav_popup=NULL;
+/* sigchld handling */
+extern void sig_chld(int);
+
/* this string is "$HOME/.dctc" */
GString *dctc_main_dir=NULL;
@@ -289,11 +292,9 @@
sigset_t set;
/* ignore SIGPIPE */
- /* ignore SIGCHLD */
/* ignore SIGHUP */
sigemptyset(&set);
sigaddset(&set,SIGPIPE);
- sigaddset(&set,SIGCHLD);
sigaddset(&set,SIGHUP);
act.sa_handler=SIG_IGN;
act.sa_mask=set;
@@ -301,8 +302,10 @@
sigprocmask(SIG_UNBLOCK,&set,NULL);
sigaction(SIGPIPE,&act,NULL);
- sigaction(SIGCHLD,&act,NULL);
sigaction(SIGHUP,&act,NULL);
+
+ /* handle SIGCHLD */
+ signal(SIGCHLD, sig_chld); /* Prevents zombies */
}
static void start_dctc_client_from_huburl(char *dchub_url,char *profile)

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2000, 2001, 2002
* Mario Sergio Fujikawa Ferreira <lioux@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD
*/
#include <sys/types.h>
#include <sys/wait.h>
/*
#include <sys/time.h>
#include <sys/resource.h>
*/
/*
* SIGCHLD handler
*
* Let's take care of our children.
* Otherwise, they may get involved with bad ppl
* and become zombies.
*/
void
sig_chld(int signo)
{
pid_t pid;
int stat;
while ( (pid = waitpid(-1, &stat, WNOHANG)) > 0);
return;
}

View File

@ -7,6 +7,7 @@
PORTNAME= dctc
PORTVERSION= 0.65
PORTREVISION= 1
CATEGORIES= net gnome
MASTER_SITES= http://unixpages.org/distfiles/ \
http://ac2i.tzo.com/dctc/
@ -31,8 +32,15 @@ CONFIGURE_ARGS= --with-gnome=${X11BASE} \
--enable-manual-db-detect \
--with-libiconv-prefix=${LOCALBASE}
ADDITIONAL_SRCS= sig_chld.c
#
DOC_FILES= COPYING ChangeLog README TODO
post-extract:
.for file in ${ADDITIONAL_SRCS}
@${CP} ${FILESDIR}/${file} ${WRKSRC}/src
.endfor
post-patch:
@${FIND} ${WRKSRC} -type f | ${XARGS} -n 10 -x ${REINPLACE_CMD} -E -e \
's|ldb-4.0|ldb4|; \
@ -52,6 +60,13 @@ post-patch:
@${FIND} ${WRKSRC} -type f \
-name "*.bak" \
| ${XARGS} -n 10 -x ${RM}
# add sigchld handler
.for file in ${ADDITIONAL_SRCS}
@${REINPLACE_CMD} -E -e \
's|^(dc_gui_SOURCES.+)$$|\1 ${file}|; \
s|^(dc_gui_OBJECTS[^\\]+)(\\*)$$|\1 ${file:S/.c$/.o/} \2|' \
${WRKSRC}/src/Makefile.in
.endfor
post-configure:
@${ECHO_CMD} '#ifndef MSG_NOSIGNAL' >> ${CONFIGURE_WRKSRC}/config.h

View File

@ -0,0 +1,36 @@
--- src/main.c.orig Mon Nov 18 23:53:50 2002
+++ src/main.c Mon Nov 18 23:55:01 2002
@@ -43,6 +43,9 @@
GtkWidget *done_popup=NULL;
GtkWidget *fav_popup=NULL;
+/* sigchld handling */
+extern void sig_chld(int);
+
/* this string is "$HOME/.dctc" */
GString *dctc_main_dir=NULL;
@@ -289,11 +292,9 @@
sigset_t set;
/* ignore SIGPIPE */
- /* ignore SIGCHLD */
/* ignore SIGHUP */
sigemptyset(&set);
sigaddset(&set,SIGPIPE);
- sigaddset(&set,SIGCHLD);
sigaddset(&set,SIGHUP);
act.sa_handler=SIG_IGN;
act.sa_mask=set;
@@ -301,8 +302,10 @@
sigprocmask(SIG_UNBLOCK,&set,NULL);
sigaction(SIGPIPE,&act,NULL);
- sigaction(SIGCHLD,&act,NULL);
sigaction(SIGHUP,&act,NULL);
+
+ /* handle SIGCHLD */
+ signal(SIGCHLD, sig_chld); /* Prevents zombies */
}
static void start_dctc_client_from_huburl(char *dchub_url,char *profile)

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2000, 2001, 2002
* Mario Sergio Fujikawa Ferreira <lioux@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD
*/
#include <sys/types.h>
#include <sys/wait.h>
/*
#include <sys/time.h>
#include <sys/resource.h>
*/
/*
* SIGCHLD handler
*
* Let's take care of our children.
* Otherwise, they may get involved with bad ppl
* and become zombies.
*/
void
sig_chld(int signo)
{
pid_t pid;
int stat;
while ( (pid = waitpid(-1, &stat, WNOHANG)) > 0);
return;
}