Aaron Stone wrote: > On Mon, Aug 22, 2005, [EMAIL PROTECTED] said: > > >>---------------------------------------------------------------------- >> mavetju - 22-Aug-05 13:15 CEST >>---------------------------------------------------------------------- >>the recursive malloc is because of calling the trace() in the signal >>handler of alarm(10) in your patch. >> >>See the man page of malloc(3): >> recursive call A process has attempted to call an allocation >>function >> recursively. This is not permitted. In particular, signal handlers >> should not attempt to allocate memory. >> >>sprintf() and friends call malloc(). > > > I'm not sure why sprintf would call malloc... but looking at the glibc > code, it gets called quite a lot! Looks like they're fully preparing the > strings before any output happens, rather than output-on-the-fly. > > I wonder if we should have a function like trace_static() that either > doesn't use a formatstring, or for which we write our own printf-style > format code. Using a static buffer and/or byte-at-a-time output, we can > avoid malloc.
I'm now doing: static char message[TRACE_MESSAGE_SIZE]; memset(message,'\0',sizeof(message)); va_start(argp, formatstring); vsnprintf(message, sizeof(message) - 1, formatstring, argp); va_end(argp); ... syslog(LOG_NOTICE, "%s", message); I'm not all confident this won't actually call malloc, so I might also use: syslog(LOG_NOTICE, message); but I'd want to scan for '%' in message first I guess. -- ________________________________________________________________ Paul Stevens paul at nfg.nl NET FACILITIES GROUP GPG/PGP: 1024D/11F8CD31 The Netherlands________________________________http://www.nfg.nl