Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 12th, 2006, 1:20 AM   #1
a1g0rithm
Newbie
 
Join Date: Mar 2006
Posts: 2
Rep Power: 0 a1g0rithm is on a distinguished road
segfault using sigaction with gnu history

i am writing a shell program with a history feature. i am reassigning sigint (ctrl-c) to print the history list. i am trying to use the gnu history library to manage the history, but it now segfaults on ctrl-c. here is the code:

setup signal handler;
struct sigaction handler;
sigfillset(&handler.sa_mask);
handler.sa_handler = handle_SIGINT;
sigaction(SIGINT, &handler, NULL);
signal handling function:
void handle_SIGINT(int signo)
{
	printf("sig\n");
}
now if the following line is in main, ctrl-c segfaults, if it is commented out, it works fine..
add_history(*args);
i think that some other sig handling stuff is getting setup with gnu history, but i dont know what..
any help would be appreciated, if more info is needed, let me know.
a1g0rithm is offline   Reply With Quote
Old Mar 12th, 2006, 1:36 AM   #2
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5 grumpy is on a distinguished road
Well, if the problem goes away when you comment out a call to add_history(), a fairly strong possibility is that the call of add_history() is the cause of the problem ...... which would mean the problem has nothing to the signal handling (the signal handling works incorrectly as a side-effect of an error by add_history()).

You haven't really provided enough information, but my guess is that add_history() assumes something about "args" that you are not honouring in main().
grumpy is offline   Reply With Quote
Old Mar 12th, 2006, 2:44 AM   #3
a1g0rithm
Newbie
 
Join Date: Mar 2006
Posts: 2
Rep Power: 0 a1g0rithm is on a distinguished road
thanks for the response.. i tracked down the problem...

the add_history function did not work well with the *args pointer.. it would complile and execute once fine, but segfault.. fixed by assigning *args contents to buffer var and passing this in to add_history.
a1g0rithm is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:26 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC