Some tweaks to the sigchld handling in the server. Other misc minor cleanup.

git-svn-id: file:///home/mbr/svn/fwknop/trunk@222 510a4753-2344-4c79-9c09-4d669213fbeb
This commit is contained in:
Damien Stuart
2010-06-22 01:14:42 +00:00
parent 68b171ddd4
commit aef097a31f
4 changed files with 99 additions and 95 deletions
+1 -1
View File
@@ -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"
+51 -53
View File
@@ -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)
@@ -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
@@ -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
+3 -5
View File
@@ -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);
}
}
@@ -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)
+44 -36
View File
@@ -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);
@@ -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 */