Skip to content

Commit

Permalink
Overwrite the Tcl notifier with our own version of it if possible.
Browse files Browse the repository at this point in the history
Integrate Tcl events and sockets into our own eventloop and socketlist.
Don't fork() before initializing Tcl anymore with overwritten notifier.
Replace max-dcc with a dynamically enlarging array, limited by the new setting max-socks.
Add two configure checks against the Tcl library to check if the notifier can be replaced.
  • Loading branch information
thommey committed Jun 29, 2010
1 parent 479c5b3 commit 12cff44
Show file tree
Hide file tree
Showing 31 changed files with 962 additions and 481 deletions.
34 changes: 33 additions & 1 deletion aclocal.m4
Expand Up @@ -16,7 +16,7 @@ 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
dnl
dnl $Id: aclocal.m4,v 1.115 2010/03/14 18:21:59 pseudo Exp $
dnl $Id: aclocal.m4,v 1.116 2010/06/29 15:52:23 thommey Exp $
dnl


Expand Down Expand Up @@ -1374,6 +1374,38 @@ AC_DEFUN([EGG_TCL_CHECK_GETCURRENTTHREAD],
])


dnl EGG_TCL_CHECK_GETTHREADDATA
dnl
AC_DEFUN([EGG_TCL_CHECK_GETTHREADDATA],
[
if test "$egg_tcl_changed" = yes; then
EGG_CACHE_UNSET(egg_cv_var_tcl_getthreaddata)
fi
# Check for Tcl_GetThreadData()
AC_CHECK_LIB($TCL_TEST_LIB, Tcl_GetThreadData, [egg_cv_var_tcl_getthreaddata="yes"], [egg_cv_var_tcl_getthreaddata="no"], $TCL_TEST_OTHERLIBS)
if test "$egg_cv_var_tcl_getthreaddata" = yes; then
AC_DEFINE(HAVE_TCL_GETTHREADDATA, 1, [Define for Tcl that has Tcl_GetThreadData() (8.1a2 and later).])
fi
])


dnl EGG_TCL_CHECK_SETNOTIFIER
dnl
AC_DEFUN([EGG_TCL_CHECK_SETNOTIFIER],
[
if test "$egg_tcl_changed" = yes; then
EGG_CACHE_UNSET(egg_cv_var_tcl_setnotifier)
fi
# Check for Tcl_SetNotifier()
AC_CHECK_LIB($TCL_TEST_LIB, Tcl_SetNotifier, [egg_cv_var_tcl_setnotifier="yes"], [egg_cv_var_tcl_setnotifier="no"], $TCL_TEST_OTHERLIBS)
if test "$egg_cv_var_tcl_setnotifier" = yes; then
AC_DEFINE(HAVE_TCL_SETNOTIFIER, 1, [Define for Tcl that has Tcl_SetNotifier() (8.2b1 and later).])
fi
])


dnl EGG_TCL_LIB_REQS()
dnl
AC_DEFUN([EGG_TCL_LIB_REQS],
Expand Down
6 changes: 6 additions & 0 deletions config.h.in
Expand Up @@ -275,6 +275,12 @@
/* Define for Tcl that has Tcl_GetCurrentThread() (8.1a2 and later). */
#undef HAVE_TCL_GETCURRENTTHREAD

/* Define for Tcl that has Tcl_GetThreadData() (8.1a2 and later). */
#undef HAVE_TCL_GETTHREADDATA

/* Define for Tcl that has Tcl_SetNotifier() (8.2b1 and later). */
#undef HAVE_TCL_SETNOTIFIER

/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
`HAVE_STRUCT_TM_TM_ZONE' instead. */
#undef HAVE_TM_ZONE
Expand Down
123 changes: 119 additions & 4 deletions configure
@@ -1,5 +1,5 @@
#! /bin/sh
# From configure.ac Revision: 1.38 .
# From configure.ac Revision: 1.39 .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.65 for Eggdrop 1.6.20.
#
Expand Down Expand Up @@ -6803,6 +6803,7 @@ int
main ()
{
char *data, *data2, *data3;
const char *cdata2;
int i, pagesize;
int fd, fd2;
Expand All @@ -6827,10 +6828,10 @@ main ()
fd2 = open ("conftest.txt", O_RDWR | O_CREAT | O_TRUNC, 0600);
if (fd2 < 0)
return 4;
data2 = "";
if (write (fd2, data2, 1) != 1)
cdata2 = "";
if (write (fd2, cdata2, 1) != 1)
return 5;
data2 = mmap (0, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd2, 0L);
data2 = (char *) mmap (0, pagesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd2, 0L);
if (data2 == MAP_FAILED)
return 6;
for (i = 0; i < pagesize; ++i)
Expand Down Expand Up @@ -7532,6 +7533,120 @@ $as_echo "#define HAVE_TCL_GETCURRENTTHREAD 1" >>confdefs.h
fi
if test "$egg_tcl_changed" = yes; then
unset egg_cv_var_tcl_getthreaddata
fi
# Check for Tcl_GetThreadData()
as_ac_Lib=`$as_echo "ac_cv_lib_$TCL_TEST_LIB''_Tcl_GetThreadData" | $as_tr_sh`
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Tcl_GetThreadData in -l$TCL_TEST_LIB" >&5
$as_echo_n "checking for Tcl_GetThreadData in -l$TCL_TEST_LIB... " >&6; }
if { as_var=$as_ac_Lib; eval "test \"\${$as_var+set}\" = set"; }; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-l$TCL_TEST_LIB $TCL_TEST_OTHERLIBS $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char Tcl_GetThreadData ();
int
main ()
{
return Tcl_GetThreadData ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
eval "$as_ac_Lib=yes"
else
eval "$as_ac_Lib=no"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
eval ac_res=\$$as_ac_Lib
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
eval as_val=\$$as_ac_Lib
if test "x$as_val" = x""yes; then :
egg_cv_var_tcl_getthreaddata="yes"
else
egg_cv_var_tcl_getthreaddata="no"
fi
if test "$egg_cv_var_tcl_getthreaddata" = yes; then
$as_echo "#define HAVE_TCL_GETTHREADDATA 1" >>confdefs.h
fi
if test "$egg_tcl_changed" = yes; then
unset egg_cv_var_tcl_setnotifier
fi
# Check for Tcl_SetNotifier()
as_ac_Lib=`$as_echo "ac_cv_lib_$TCL_TEST_LIB''_Tcl_SetNotifier" | $as_tr_sh`
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Tcl_SetNotifier in -l$TCL_TEST_LIB" >&5
$as_echo_n "checking for Tcl_SetNotifier in -l$TCL_TEST_LIB... " >&6; }
if { as_var=$as_ac_Lib; eval "test \"\${$as_var+set}\" = set"; }; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-l$TCL_TEST_LIB $TCL_TEST_OTHERLIBS $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char Tcl_SetNotifier ();
int
main ()
{
return Tcl_SetNotifier ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
eval "$as_ac_Lib=yes"
else
eval "$as_ac_Lib=no"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
eval ac_res=\$$as_ac_Lib
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
eval as_val=\$$as_ac_Lib
if test "x$as_val" = x""yes; then :
egg_cv_var_tcl_setnotifier="yes"
else
egg_cv_var_tcl_setnotifier="no"
fi
if test "$egg_cv_var_tcl_setnotifier" = yes; then
$as_echo "#define HAVE_TCL_SETNOTIFIER 1" >>confdefs.h
fi
if test "$EGG_CYGWIN" = yes; then
TCL_REQS="${TCLLIB}/lib${TCLLIBFN}"
TCL_LIBS="-L$TCLLIB -l$TCLLIBFNS $EGG_MATH_LIB"
Expand Down
6 changes: 4 additions & 2 deletions configure.ac
@@ -1,11 +1,11 @@
dnl configure.ac: this file is processed by autoconf to produce ./configure.
dnl
dnl $Id: configure.ac,v 1.39 2010/03/14 18:21:59 pseudo Exp $
dnl $Id: configure.ac,v 1.40 2010/06/29 15:52:23 thommey Exp $

AC_PREREQ(2.60)
AC_INIT([Eggdrop],[1.6.20],[bugs@eggheads.org])
AC_COPYRIGHT([Copyright (C) 1999 - 2010 Eggheads Development Team])
AC_REVISION($Revision: 1.39 $)
AC_REVISION($Revision: 1.40 $)
AC_CONFIG_SRCDIR(src/eggdrop.h)
AC_CONFIG_AUX_DIR(misc)
AC_CONFIG_HEADER(config.h)
Expand Down Expand Up @@ -170,6 +170,8 @@ EGG_TCL_CHECK_PRE70
EGG_TCL_TESTLIBS
EGG_TCL_CHECK_FREE
EGG_TCL_CHECK_GETCURRENTTHREAD
EGG_TCL_CHECK_GETTHREADDATA
EGG_TCL_CHECK_SETNOTIFIER
EGG_TCL_LIB_REQS
EGG_TCL_LUSH

Expand Down
14 changes: 13 additions & 1 deletion doc/Changes1.6
@@ -1,11 +1,23 @@
$Id: Changes1.6,v 1.81 2010/06/28 21:13:26 thommey Exp $
$Id: Changes1.6,v 1.82 2010/06/29 15:52:23 thommey Exp $

Eggdrop Changes (since version 1.6.0)

_____________________________________________________________________

1.6.20 (CVS):

- Overwrite the Tcl notifier with our own version of it if possible.
Integrates Tcl events and sockets into our own eventloop and socketlist,
causing Tcl events happen without delay. It is thread-aware.
- If the Tcl notifier is overwritten, don't fork() before initializing
Tcl anymore. This used to be required to prevent hangs on startup.
- Replace the constant max-dcc upper limit with a dynamically enlarging
array that increases up to a new setting called max-socks. max-socks
also limits the number of Tcl socket connections (per thread).
- Added two configure checks against the Tcl library to check if it's
possible to replace the notifier.
Patch by: thommey

- Modified compat.tcl version of time to allow accessing Tcl's time
command if any arguments are passed to it.
Patch by: Pixelz
Expand Down
9 changes: 5 additions & 4 deletions doc/html/egg-core.html
@@ -1,5 +1,5 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!-- $Id: egg-core.html,v 1.48 2010/01/15 19:51:49 pseudo Exp $ -->
<!-- $Id: egg-core.html,v 1.49 2010/06/29 15:52:24 thommey Exp $ -->

<html>
<head>
Expand Down Expand Up @@ -835,11 +835,12 @@
Please select owners wisely and use this command ethically!</p>
</dd>

<dt><strong>set max-dcc 50</strong></dt>
<dt><strong>set max-socks 100</strong></dt>

<dd>
<p>Set here the maximum number of dcc connections you will allow.
You can increase this later, but never decrease it.</p>
<p>Set here the maximum number of socket connections you will allow. You
can increase this later, but never decrease it below current usage. If
you're using Tcl threads, this is a per thread maximum.</p>
</dd>

<dt><strong>set allow-dk-cmds 1</strong></dt>
Expand Down
9 changes: 5 additions & 4 deletions eggdrop.conf
@@ -1,7 +1,7 @@
#! /path/to/executable/eggdrop
# ^- This should contain a fully qualified path to your Eggdrop executable.
#
# $Id: eggdrop.conf,v 1.64 2010/03/24 13:14:50 pseudo Exp $
# $Id: eggdrop.conf,v 1.65 2010/06/29 15:52:23 thommey Exp $
#
# This is a sample Eggdrop configuration file which includes all possible
# settings that can be used to configure your bot.
Expand Down Expand Up @@ -398,9 +398,10 @@ set must-be-owner 1
# and use this command ethically!
unbind dcc n simul *dcc:simul

# Set here the maximum number of dcc connections you will allow. You can
# increase this later, but never decrease it.
set max-dcc 50
# Set here the maximum number of socket connections you will allow. You can
# increase this later, but never decrease it below current usage.
# If you're using Tcl threads, this is a per-thread maximum.
set max-socks 100

# Enable this setting if you want +d & +k users to use commands bound as -|-.
set allow-dk-cmds 1
Expand Down
2 changes: 1 addition & 1 deletion help/core.help
Expand Up @@ -185,7 +185,7 @@ sort-users
die-on-sighup
die-on-sigterm
remote-boots
max-dcc
max-socks
max-logs
protect-telnet
ident-timeout
Expand Down
9 changes: 5 additions & 4 deletions help/set/cmds1.help
Expand Up @@ -225,10 +225,11 @@
0 - allow *no* outside boots
1 - allow boots from sharebots
2 - allow any boots
%{help=set max-dcc}%{+n}
### %bset max-dcc%b <max dcc connections>
Set here the maximum number of dcc connections you will allow.
You can increase this later, but never decrease it.
%{help=set max-socks}%{+n}
### %bset max-socks%b <max dcc connections>
Set here the maximum number of socket connections you will allow. You can
increase this later, but never decrease it below current usage. If you're
using Tcl threads, this is a per-thread maximum.
%{help=set max-logs}%{+n}
### %bset max-logs%b <max number of logs>
This is the maximum number of logfiles allowed. This setting
Expand Down
8 changes: 4 additions & 4 deletions src/bg.c
Expand Up @@ -3,7 +3,7 @@
* moving the process to the background, i.e. forking, while keeping threads
* happy.
*
* $Id: bg.c,v 1.16 2010/01/26 03:12:15 tothwolf Exp $
* $Id: bg.c,v 1.17 2010/06/29 15:52:24 thommey Exp $
*/
/*
* Copyright (C) 1997 Robey Pointer
Expand Down Expand Up @@ -128,7 +128,7 @@ static void bg_do_detach(pid_t p)

void bg_prepare_split(void)
{
if (!tcl_threaded())
if (!fork_before_tcl())
return;

/* Create a pipe between parent and split process, fork to create a
Expand Down Expand Up @@ -208,7 +208,7 @@ static void bg_send_pidfile(void)

void bg_send_quit(bg_quit_t q)
{
if (!tcl_threaded())
if (!fork_before_tcl())
return;

if (bg.state == BG_PARENT) {
Expand All @@ -229,7 +229,7 @@ void bg_send_quit(bg_quit_t q)

void bg_do_split(void)
{
if (tcl_threaded()) {
if (fork_before_tcl()) {
/* Tell our parent process to go away now, as we don't need it anymore. */
bg_send_quit(BG_QUIT);

Expand Down
4 changes: 2 additions & 2 deletions src/botnet.c
Expand Up @@ -7,7 +7,7 @@
* linking, unlinking, and relaying to another bot
* pinging the bots periodically and checking leaf status
*
* $Id: botnet.c,v 1.64 2010/01/03 13:27:31 pseudo Exp $
* $Id: botnet.c,v 1.65 2010/06/29 15:52:24 thommey Exp $
*/
/*
* Copyright (C) 1997 Robey Pointer
Expand Down Expand Up @@ -1008,7 +1008,7 @@ int botlink(char *linker, int idx, char *nick)
dprintf(idx, "%s .chaddr %s %s\n",
MISC_USEFORMAT, nick, MISC_CHADDRFORMAT);
}
} else if (dcc_total == max_dcc) {
} else if (dcc_total == max_dcc && increase_socks_max()) {
if (idx >= 0)
dprintf(idx, "%s\n", DCC_TOOMANYDCCS1);
} else {
Expand Down

0 comments on commit 12cff44

Please sign in to comment.