where it can potentially blow lots of stacks.
$Log$
+ Revision 640.12 2005/02/17 16:13:59 ajc
+ * Removed "Log Hooks." This enabled the removal of a buf[SIZ] in lprintf,
+ where it can potentially blow lots of stacks.
+
Revision 640.11 2005/02/17 03:52:16 ajc
* setup.c: clarify some of the messages
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
+
#include "snprintf.h"
#endif
-struct LogFunctionHook *LogHookTable = NULL;
struct CleanupFunctionHook *CleanupHookTable = NULL;
struct SessionFunctionHook *SessionHookTable = NULL;
struct UserFunctionHook *UserHookTable = NULL;
-void CtdlRegisterLogHook(void (*fcn_ptr) (char *), int loglevel)
-{
-
- struct LogFunctionHook *newfcn;
-
- newfcn = (struct LogFunctionHook *)
- malloc(sizeof(struct LogFunctionHook));
- newfcn->next = LogHookTable;
- newfcn->h_function_pointer = fcn_ptr;
- newfcn->loglevel = loglevel;
- LogHookTable = newfcn;
-
- lprintf(CTDL_INFO, "Registered a new logging function\n");
-}
-
-
-void CtdlUnregisterLogHook(void (*fcn_ptr) (char *), int loglevel)
-{
- struct LogFunctionHook *cur, *p;
-
- for (cur = LogHookTable; cur != NULL; cur = cur->next) {
- /* This will also remove duplicates if any */
- while (cur != NULL &&
- fcn_ptr == cur->h_function_pointer &&
- loglevel == cur->loglevel) {
- lprintf(CTDL_INFO, "Unregistered logging function\n");
- p = cur->next;
- if (cur == LogHookTable) {
- LogHookTable = p;
- }
- free(cur);
- cur = p;
- }
- }
-}
-
-
void CtdlRegisterCleanupHook(void (*fcn_ptr) (void))
{
}
}
-void PerformLogHooks(int loglevel, char *logmsg)
-{
- struct LogFunctionHook *fcn;
-
- for (fcn = LogHookTable; fcn != NULL; fcn = fcn->next) {
- if (fcn->loglevel >= loglevel) {
- (*fcn->h_function_pointer) (logmsg);
- }
- }
-}
-
void PerformUserHooks(struct ctdluser *usbuf, int EventType)
{
struct UserFunctionHook *fcn;
int DLoader_Exec_Cmd(char *cmdbuf);
char *Dynamic_Module_Init(void);
-void CtdlRegisterLogHook(void (*fcn_ptr)(char *), int loglevel);
-void CtdlUnregisterLogHook(void (*fcn_ptr)(char *), int loglevel);
-void PerformLogHooks(int loglevel, char *logmsg);
-
void CtdlRegisterSessionHook(void (*fcn_ptr)(void), int EventType);
void CtdlUnregisterSessionHook(void (*fcn_ptr)(void), int EventType);
void PerformSessionHooks(int EventType);
lprintf(CTDL_DEBUG, "--- Hello, %s ---\n", CC->curr_user);
}
-void LogTest(char *buf) {
- fprintf(stderr,"%c[1m%s%c[0m", 27, buf, 27);
- fflush(stderr);
- }
-
-
char *serv_test_init(void)
{
CtdlRegisterCleanupHook(CleanupTest);
CtdlRegisterSessionHook(SessionStartTest, EVT_START);
CtdlRegisterSessionHook(SessionStopTest, EVT_STOP);
CtdlRegisterSessionHook(LoginTest, EVT_LOGIN);
- CtdlRegisterLogHook(LogTest, 1);
return "$Id$";
}
/*
* lprintf() ... Write logging information
- *
- * Note: the variable "buf" below needs to be large enough to handle any
- * log data sent through this function. BE CAREFUL!
*/
extern int running_as_daemon;
static int enable_syslog = 1;
va_end(arg_ptr);
}
- if (enable_syslog && LogHookTable == 0) return;
-
- /* legacy output code; hooks get processed first */
- char buf[SIZ];
- va_start(arg_ptr, format);
- vsnprintf(buf, sizeof(buf), format, arg_ptr);
- va_end(arg_ptr);
- PerformLogHooks(loglevel, buf);
-
+ /* stderr output code */
if (enable_syslog || running_as_daemon) return;
/* if we run in forground and syslog is disabled, log to terminal */
localtime_r(&unixtime, &tim);
if (CC->cs_pid != 0) {
fprintf(stderr,
- "%04d/%02d/%02d %2d:%02d:%02d.%06ld [%3d] %s",
+ "%04d/%02d/%02d %2d:%02d:%02d.%06ld [%3d] ",
tim.tm_year + 1900, tim.tm_mon + 1,
tim.tm_mday, tim.tm_hour, tim.tm_min,
tim.tm_sec, (long)tv.tv_usec,
- CC->cs_pid, buf);
+ CC->cs_pid);
} else {
fprintf(stderr,
- "%04d/%02d/%02d %2d:%02d:%02d.%06ld %s",
+ "%04d/%02d/%02d %2d:%02d:%02d.%06ld ",
tim.tm_year + 1900, tim.tm_mon + 1,
tim.tm_mday, tim.tm_hour, tim.tm_min,
- tim.tm_sec, (long)tv.tv_usec, buf);
+ tim.tm_sec, (long)tv.tv_usec);
}
+ va_start(arg_ptr, format);
+ vfprintf(stderr, format, arg_ptr);
+ va_end(arg_ptr);
fflush(stderr);
}
}