Signal trapping would be nice.

Have an idea or great plots for Egoboo? Post them here!

Moderator: Developers

Post Reply
ns89
Acid Blob (New member)
Acid Blob (New member)
Posts: 18
Joined: Sun Aug 15, 2010 2:05 am

Signal trapping would be nice.

Post by ns89 »

Some signal trapping on POSIX systems would be nice, it currently will only respond to kill. This would be really useful to use ^C (Control+C) to close it from a shell. And should allow the use SIGTERM to close it when it hangs.
User avatar
penguinflyer5234
Sheep (Developer)
Sheep (Developer)
Posts: 3025
Joined: Wed Jul 23, 2008 1:39 am
Location: Best Southwest

Post by penguinflyer5234 »

SIGINT (Control-C) is given to us as an SDL_QUIT event (maybe SIGTERM too).

Should be easy.
...
bgbirdsey
{]-[0{0|307 (Developer)
{]-[0{0|307 (Developer)
Posts: 1864
Joined: Wed Jul 23, 2008 4:22 am
Location: Minnesota, USA

Post by bgbirdsey »

Actually, whatever SDL interprets as a kill signal will stop the program if it ever detects it. To get that to work properly, it must be done in a multi-threaded environment where the master thread iterates quickly and the heavy lifting is done by the worker threads...

This is practically impossible with SDL because of the way that the video is controlled. In Linux, it might be possible to spawn the entire "game" in a fork, in which case, it might be possible to grab various terminal and system flags and force the program to quit...
User avatar
penguinflyer5234
Sheep (Developer)
Sheep (Developer)
Posts: 3025
Joined: Wed Jul 23, 2008 1:39 am
Location: Best Southwest

Post by penguinflyer5234 »

that's SIGKILL, not SIGTERM or SIGINT :?

also capturing SDL_QUIT events allows people to click the little X at the top :P (something I would also like)
...
bgbirdsey
{]-[0{0|307 (Developer)
{]-[0{0|307 (Developer)
Posts: 1864
Joined: Wed Jul 23, 2008 4:22 am
Location: Minnesota, USA

Post by bgbirdsey »

Yes, but SDL_QUIT is whatever the local system thinks a "quit event" is. I don't know what SDL does with different Linux event bits and am not really interested, as this is a cross-platform game.
User avatar
Zefz
Squirrel Knight (Administrator)
Squirrel Knight (Administrator)
Posts: 3820
Joined: Wed Jul 23, 2008 1:27 am
Location: Norway
Contact:

Post by Zefz »

Use CTRL+Q for a quick exit?
bgbirdsey
{]-[0{0|307 (Developer)
{]-[0{0|307 (Developer)
Posts: 1864
Joined: Wed Jul 23, 2008 4:22 am
Location: Minnesota, USA

Post by bgbirdsey »

I thought I had trapped the SDL_QUIT event, but apparently not...

In any case, this will not work if the program is trapped in an infinite loop somewhere. The best way to cure this is to have a multi-threaded system, but there are limits to the threading imposed by SDL (from the SDL documentation):
  • Don't call SDL video/event functions from separate
  • Don't use any library functions in separate threads
  • Don't perform any memory management in separate threads
  • Lock global variables which may be accessed by multiple threads
  • Never terminate threads, always set a flag and wait for them to quit
  • Think very carefully about all possible ways your code may interact
So, I can't think of a way of using SDL threads to do anything to fix the stated problem.
User avatar
penguinflyer5234
Sheep (Developer)
Sheep (Developer)
Posts: 3025
Joined: Wed Jul 23, 2008 1:39 am
Location: Best Southwest

Post by penguinflyer5234 »

hmm does it matter that we do anything when it hangs? I kinda doubt other games kill themselves when a quit-like event is sent
...
bgbirdsey
{]-[0{0|307 (Developer)
{]-[0{0|307 (Developer)
Posts: 1864
Joined: Wed Jul 23, 2008 4:22 am
Location: Minnesota, USA

Post by bgbirdsey »

I kinda doubt other games kill themselves when a quit-like event is sent
Internal messaging like this is the norm, but not necessarily due to a ctrl-c.
User avatar
penguinflyer5234
Sheep (Developer)
Sheep (Developer)
Posts: 3025
Joined: Wed Jul 23, 2008 1:39 am
Location: Best Southwest

Post by penguinflyer5234 »

I meant when they are hanged :\
...
Post Reply