Skip to content

Commit

Permalink
Some tweaks to the sigchld handling in the server. Other misc minor c…
Browse files Browse the repository at this point in the history
…leanup.

git-svn-id: file:///home/mbr/svn/fwknop/trunk@222 510a4753-2344-4c79-9c09-4d669213fbeb
  • Loading branch information
Damien Stuart committed Jun 22, 2010
1 parent 68b171d commit aef097a
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 95 deletions.
2 changes: 1 addition & 1 deletion client/config_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ usage(void)
" -u, --user-agent Set the HTTP User-Agent for resolving the\n"
" external IP via -R, or for sending SPA\n"
" packets over HTTP.\n"
" -H, --http-proxy Specify and HTTP proxy URL through which the\n"
" -H, --http-proxy Specify an HTTP proxy URL through which the\n"
" SPA packet will be sent.\n"
" -U, --spoof-user Set the username within outgoing SPA packet.\n"
" -q, --quiet Perform fwknop functions quietly.\n"
Expand Down
104 changes: 51 additions & 53 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AC_PREREQ(2.61)

dnl Define our name, version and email.
m4_define(my_package, [fwknop])
m4_define(my_version, [2.0.0-alpha-pre2])
m4_define(my_version, [2.0.0-beta-rc1])
m4_define(my_bug_email, [dstuart@dstuart.org])

AC_INIT(my_package, my_version, my_bug_email)
Expand Down Expand Up @@ -240,59 +240,59 @@ dnl
dnl Check for sendmail
dnl
AC_ARG_WITH([sendmail],
[AS_HELP_STRING([--with-sendmail=/path/to/sendmail],
[Specify path to the sendmail executable @<:@default=check path@:>@])],
[
AS_IF([ test "x$withval" = x -o "x$withval" = xyes -o "x$withval" = xno ],
[AC_MSG_ERROR([--with-sendmail requires an argument specifying a path to sendmail])],
[
AC_CHECK_FILE([$withval], [], [
AC_MSG_WARN([Specified path to sendmail does not exist on this system])
sendmail_exe_warn="*not found*"
])
SENDMAIL_EXE=$withval
]
)
],
[
AC_PATH_PROG(SENDMAIL_EXE, [sendmail], [], [$APP_PATH])
]
)
AS_IF([test "x$SENDMAIL_EXE" != x],
[
AC_DEFINE_UNQUOTED([SENDMAIL_EXE], ["$SENDMAIL_EXE"], [Path to sendmail executable])
sendmail_exe=$SENDMAIL_EXE
], [ sendmail_exe="(not found)"]
)
dnl AC_ARG_WITH([sendmail],
dnl [AS_HELP_STRING([--with-sendmail=/path/to/sendmail],
dnl [Specify path to the sendmail executable @<:@default=check path@:>@])],
dnl [
dnl AS_IF([ test "x$withval" = x -o "x$withval" = xyes -o "x$withval" = xno ],
dnl [AC_MSG_ERROR([--with-sendmail requires an argument specifying a path to sendmail])],
dnl [
dnl AC_CHECK_FILE([$withval], [], [
dnl AC_MSG_WARN([Specified path to sendmail does not exist on this system])
dnl sendmail_exe_warn="*not found*"
dnl ])
dnl SENDMAIL_EXE=$withval
dnl ]
dnl )
dnl ],
dnl [
dnl AC_PATH_PROG(SENDMAIL_EXE, [sendmail], [], [$APP_PATH])
dnl ]
dnl )
dnl AS_IF([test "x$SENDMAIL_EXE" != x],
dnl [
dnl AC_DEFINE_UNQUOTED([SENDMAIL_EXE], ["$SENDMAIL_EXE"], [Path to sendmail executable])
dnl sendmail_exe=$SENDMAIL_EXE
dnl ], [ sendmail_exe="(not found)"]
dnl )
dnl Check for mail
dnl
AC_ARG_WITH([mail],
[AS_HELP_STRING([--with-mail=/path/to/mail],
[Specify path to the mail executable @<:@default=check path@:>@])],
[
AS_IF([ test "x$withval" = x -o "x$withval" = xyes -o "x$withval" = xno ],
[AC_MSG_ERROR([--with-mail requires an argument specifying a path to mail])],
[
AC_CHECK_FILE([$withval], [], [
AC_MSG_WARN([Specified path to mail does not exist on this system])
mail_exe_warn="*not found*"
])
MAIL_EXE=$withval
]
)
],
[
AC_PATH_PROG(MAIL_EXE, [mail], [], [$APP_PATH])
]
)
AS_IF([test "x$MAIL_EXE" != x],
[
AC_DEFINE_UNQUOTED([MAIL_EXE], ["$MAIL_EXE"], [Path to mail executable])
mail_exe=$MAIL_EXE
], [ mail_exe="(not found)"]
)
dnl AC_ARG_WITH([mail],
dnl [AS_HELP_STRING([--with-mail=/path/to/mail],
dnl [Specify path to the mail executable @<:@default=check path@:>@])],
dnl [
dnl AS_IF([ test "x$withval" = x -o "x$withval" = xyes -o "x$withval" = xno ],
dnl [AC_MSG_ERROR([--with-mail requires an argument specifying a path to mail])],
dnl [
dnl AC_CHECK_FILE([$withval], [], [
dnl AC_MSG_WARN([Specified path to mail does not exist on this system])
dnl mail_exe_warn="*not found*"
dnl ])
dnl MAIL_EXE=$withval
dnl ]
dnl )
dnl ],
dnl [
dnl AC_PATH_PROG(MAIL_EXE, [mail], [], [$APP_PATH])
dnl ]
dnl )
dnl AS_IF([test "x$MAIL_EXE" != x],
dnl [
dnl AC_DEFINE_UNQUOTED([MAIL_EXE], ["$MAIL_EXE"], [Path to mail executable])
dnl mail_exe=$MAIL_EXE
dnl ], [ mail_exe="(not found)"]
dnl )
dnl Check for sh
dnl
Expand Down Expand Up @@ -350,8 +350,6 @@ if [test $want_server = "yes" ]; then
echo " Server support programs:
iptables: $iptables_exe $iptables_exe_warn
ipfw: $ipfw_exe $ipfw_exe_warn
sendmail: $sendmail_exe $sendmail_exe_warn
mail: $mail_exe $mail_exe_warn
sh: $sh_exe $sh_exe_warn
"
fi
Expand Down
8 changes: 3 additions & 5 deletions server/fwknopd.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,7 @@ main(int argc, char **argv)
}
else
{
res = run_tcp_server(&opts);
//if(res < 0)
// log_msg(LOG_WARNING, "Fork error from run_tcp_serv.");
//else
// opts.tcp_server_pid = res;
run_tcp_server(&opts);
}
}

Expand All @@ -275,6 +271,8 @@ main(int argc, char **argv)
{
log_msg(LOG_WARNING, "Got SIGHUP. Re-reading configs.");
free_configs(&opts);
kill(opts.tcp_server_pid, SIGTERM);
usleep(1000000);
got_sighup = 0;
}
else if(got_sigint)
Expand Down
80 changes: 44 additions & 36 deletions server/pcap_capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,53 @@ pcap_capture(fko_srv_options_t *opts)
*/
while(1)
{
/* If we got a SIGCHLD and it was the tcp server, then handle it here.
*/
if(got_sigchld)
{
if(opts->tcp_server_pid > 0)
{
child_pid = waitpid(0, &status, WNOHANG);

if(child_pid == opts->tcp_server_pid)
{
if(WIFSIGNALED(status))
log_msg(LOG_WARNING, "TCP server got signal: %i", WTERMSIG(status));

log_msg(LOG_WARNING, "TCP server exited with status of %i. Attempting restart.",
WEXITSTATUS(status));

opts->tcp_server_pid = 0;

/* Attempt to restart tcp server ? */
usleep(1000000);
run_tcp_server(opts);
}
}

got_sigchld = 0;
}


/* Any signal except USR1, USR2, and SIGCHLD mean break the loop.
*/
if((got_signal != 0) && ((got_sigusr1 + got_sigusr2 + got_sigchld) == 0))
if(got_signal != 0)
{
pcap_breakloop(pcap);
pending_break = 1;
signal(SIGCHLD, SIG_IGN);
if(got_sigint || got_sigterm || got_sighup)
{
signal(SIGCHLD, SIG_IGN);
pcap_breakloop(pcap);
pending_break = 1;
}
else if(got_sigusr1 || got_sigusr2)
{
/* Not doing anything with these yet.
*/
got_sigusr1 = got_sigusr2 = 0;
got_signal = 0;
}
else
got_signal = 0;
}

res = pcap_dispatch(pcap, 1, (pcap_handler)&process_packet, (unsigned char *)opts);
Expand Down Expand Up @@ -229,38 +269,6 @@ pcap_capture(fko_srv_options_t *opts)
*/
check_firewall_rules(opts);

/* If we got a SIGCHLD and it was the tcp server, then handle it here.
*/
if(got_sigchld && pending_break != 1)
{
if(opts->tcp_server_pid > 0)
{
child_pid = waitpid(0, &status, WNOHANG);

if(child_pid == opts->tcp_server_pid)
{
if(WIFSIGNALED(status))
log_msg(LOG_WARNING, "TCP server got signal: %i", WTERMSIG(status));

log_msg(LOG_WARNING, "TCP server exited with status of %i. Attempting restart.",
WEXITSTATUS(status));

opts->tcp_server_pid = 0;

/* Attempt to restart tcp server ? */
usleep(1000000);
res = run_tcp_server(opts);
//if(res < 0)
// log_msg(LOG_WARNING, "Fork error from run_tcp_serv.");
//else
// opts->tcp_server_pid = res;
}
}

got_sigchld = 0;
got_signal = 0;
}

usleep(10000);
}
#endif /* HAVE_LIBPCAP */
Expand Down

0 comments on commit aef097a

Please sign in to comment.