Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   segfault using sigaction with gnu history (http://www.programmingforums.org/showthread.php?t=8819)

a1g0rithm Mar 12th, 2006 2:20 AM

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.

grumpy Mar 12th, 2006 2:36 AM

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().

a1g0rithm Mar 12th, 2006 3:44 AM

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.


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

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