[opensuse-programming] any problems with vsyslog on 64bit systems?
I've taken some existing code written for a standard 32 bit system and recompiled it for 64 bit. And now it promptly segfaults in vsyslog(). Well, the segfault happens in a strlen() call at some point, but removing the vsyslog call "fixes" the problem, so clearly there's something dodgy with vsyslog. Has anyone else seen this? /Per Jessen, Zürich --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
On Tue, Feb 26, 2008 at 06:09:08PM +0100, Per Jessen wrote:
I've taken some existing code written for a standard 32 bit system and recompiled it for 64 bit. And now it promptly segfaults in vsyslog(). Well, the segfault happens in a strlen() call at some point, but removing the vsyslog call "fixes" the problem, so clearly there's something dodgy with vsyslog.
Has anyone else seen this?
You likely use vsyslog and its va_args argument wrong. Care to show us the function? Ciao, Marcus --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
Marcus Meissner wrote:
On Tue, Feb 26, 2008 at 06:09:08PM +0100, Per Jessen wrote:
I've taken some existing code written for a standard 32 bit system and recompiled it for 64 bit. And now it promptly segfaults in vsyslog(). Well, the segfault happens in a strlen() call at some point, but removing the vsyslog call "fixes" the problem, so clearly there's something dodgy with vsyslog.
Has anyone else seen this?
You likely use vsyslog and its va_args argument wrong. Care to show us the function?
I sure hope I'm using it right - don't want to make myself look stupid in public: void message( int level, char *format, ... ) { int pri; va_list v; // if we print/log this message, depends on the verbosity-level if ( level<2 || level<=get_verbosity() ) { switch ( level ) { case 0: pri=LOG_WARNING; break; case 1: pri=LOG_NOTICE; break; case 2: pri=LOG_INFO; break; default: pri=LOG_DEBUG; break; } va_start( v, format ); // if we're not running as a daemon, we also log stdout. if ( 0==get_daemonize() ) { vfprintf( stdout, format, v ); fputc( '\n', stdout ); } vsyslog( pri, format, v ); va_end(v); } } /Per Jessen, Zürich --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
I sure hope I'm using it right - don't want to make myself look stupid in public:
va_start( v, format );
// if we're not running as a daemon, we also log stdout. if ( 0==get_daemonize() ) { vfprintf( stdout, format, v ); // FIRST USE fputc( '\n', stdout ); } vsyslog( pri, format, v ); // SECOND USE
va_end(v);
No, you are using the va_list _twice_. You can do that on i386 perhaps, but not on x86_64, it will just crash. Use va_copy (v2, v); to get a second list, and pass this to vfprintf(). Perhaps try: va_list v2; va_start ( v, format ); if 0==get_daemonize()) { va_copy (v2, v); vfprintf ( stdout, format , v2); fputc ('\n', stdout); va_end (v2); } vsyslog( pri, format, v ); // SECOND USE va_end(v); --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
Wouldn't it also work to just end the list and starting again? I.e. doing va_list v; va_start ( v, format ); if 0==get_daemonize()) { vfprintf ( stdout, format , v2); fputc ('\n', stdout); } va_end(v); va_start(v, format); vsyslog( pri, format, v ); va_end(v); Philipp --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
Marcus Meissner wrote:
No, you are using the va_list _twice_. You can do that on i386 perhaps, but not on x86_64, it will just crash.
Yep, that is exactly my experience.
Use va_copy (v2, v); to get a second list, and pass this to vfprintf().
Thanks - it would have taken me a loooong time to find that solution. /Per Jessen, Zürich --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
On Tue, 26 Feb 2008 18:09:08 +0100, Per Jessen wrote:
Well, the segfault happens in a strlen() call at some point, but removing the vsyslog call "fixes" the problem, so clearly there's something dodgy with vsyslog.
Not necessarily. What's the backtrace you get when running your app under catchsegv (i.e. 'catchsegv your_app')? Philipp --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
Philipp Thomas wrote:
On Tue, 26 Feb 2008 18:09:08 +0100, Per Jessen wrote:
Well, the segfault happens in a strlen() call at some point, but removing the vsyslog call "fixes" the problem, so clearly there's something dodgy with vsyslog.
Not necessarily. What's the backtrace you get when running your app under catchsegv (i.e. 'catchsegv your_app')?
# catchsegv /home/per/workspace/nnnnnnnn/bwsatellited -d --verbosity=3 *** Segmentation fault Backtrace: /lib64/libc.so.6(strlen+0x20)[0x2b788a6e1d70] /lib64/libc.so.6(_IO_vfprintf+0x3d3f)[0x2b788a6b334f] /lib64/libc.so.6(__vsyslog_chk+0x3fe)[0x2b788a72bfce] /home/per/workspace/bulwark/bwsatd/../bwcommon.c:62(message)[0x402fd2] /home/per/workspace/bulwark/bwsatd/bwsatd_main2.c:387(main)[0x401b32] /lib64/libc.so.6(__libc_start_main+0xf4)[0x2b788a68bae4] ??:0(_start)[0x401919] Looks pretty much like what I got when running with gdb. Does catchsegv give me anything I wouldn't catch with gdb ? /Per Jessen, Zürich --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
On Tue, 26 Feb 2008 21:45:31 +0100, Per Jessen wrote:
Looks pretty much like what I got when running with gdb. Does catchsegv give me anything I wouldn't catch with gdb ?
Nope, it just makes it easier to get the traces. But as Marcus already told you in another mail, your error was to use the va_list twice. Philipp --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse-programming+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-programming+help@opensuse.org
participants (3)
-
Marcus Meissner
-
Per Jessen
-
Philipp Thomas