Menu

#26 Can't interrupt when blocked on network

open
nobody
None
5
2003-06-13
2003-06-13
No

It's not possible to gracefully exit mpg321 on BSD systems when it
gets blocked on network input. This happens because
read_from_fd calls read(), which by default gets restarted after a
signal. This may be a BSD specific phenomenon - I think that Linux
signals default to non-restarting.

The fix for this on systems with sigaction() is to unset
SA_RESTART to prevent auto-restarting of the read system call.

Replacing the calls to
signal(SIGINT, handler)
with

sigemptyset (&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = handle_signals;
if (sigaction(SIGINT, &sa, NULL) == -1) {
perror("sigaction");
}

(and a declaration at the start of struct sigaction sa, of course).

corrects the problem and makes it possible to do graceful cleanup
when killed during a network hang.

Not submitted as a patch since it's so tiny (only three spots to fix -
one at the start of main, and the two calls to signal(sigint)) and since
it needs to be tested on Linux before I'd call it happy.

Discussion


Log in to post a comment.