LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-12-2012, 11:47 AM   #1
kenkahn
LQ Newbie
 
Registered: Nov 2012
Posts: 2

Rep: Reputation: Disabled
Calling backtrace_symbols_fd from signal handler fails


[FONT="Arial"][SIZE="2"]

I have a multi-threaded application which sets up a signal handler in thread 1. The signal handler consists of



void Signal_Handler(int signum, siginfo_t *sinfo, void *ucontxt) {

void *backtrace_buffer[100];
size_t backtrace_size;

/*----------------------------------------------------------------------------------*
! Determine if a backtrace exists (backtrace_size > 0). !
*----------------------------------------------------------------------------------*/
backtrace_size = backtrace(backtrace_buffer, 100);

int backtrace_hdl = open("/et3mach/configmgr_backtrace",O_APPEND,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
chmod("/et3mach/configmgr_backtrace",S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);

backtrace_symbols_fd(backtrace_buffer,backtrace_size,backtrace_hdl);

close(backtrace_hdl);



The backtrace call works fine; it returns a count of 11. The open works file and returns a valid file handle. The call to backtrace_symbols_fd results in the program terminating. Nothing is written to the file and the next instruction is not run.

Can anyone suggest what might be going on? According to my research both backtrace calls do no memory allocation and are valid in a signal handler.

I also tried backtrace_symbols with the same results.

I'm running RHEL5.0-2010-x86_64 with a 2.6.18-194.el5 kernel. compile used was gcc 4.1.2.

Last edited by kenkahn; 11-12-2012 at 11:51 AM.
 
Old 11-13-2012, 09:57 AM   #2
kenkahn
LQ Newbie
 
Registered: Nov 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Found my problem. I changed the open from O_APPEND to O_WRONLY|O_CREAT and backtrace_symbols_fd now works. My guess is it had to do with fact that under the covers O_APPEND forces an lseek which is invalid in a signal handler.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
delay in calling handler of SIGALRM ankitm Linux - Kernel 0 10-07-2011 06:12 AM
problem in Signal Handler amir_skh Programming 9 11-15-2010 04:38 AM
user-define signal handler & coredump for signal 11(SIGSEGV) Alexlun Linux - Software 2 05-24-2009 06:37 AM
How to reinstall a signal handler after exec ( Strange behaviour in signal handling ) lali.p Programming 0 09-20-2008 12:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration