summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-04-24 02:32:07 +0200
committerLennart Poettering <lennart@poettering.net>2010-04-24 02:32:07 +0200
commit57cd2192d0085737bbc745756b97a40a20711b80 (patch)
tree242104d229f2b96675f3c3a26f51aacd4fb63515 /util.c
parentb29a8e58fa7c30dfcc4e4b1ccf9f409dc2935f8a (diff)
util: when releasing terminal, temporarily disable SIGHUP
Diffstat (limited to 'util.c')
-rw-r--r--util.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/util.c b/util.c
index 9d99fefe78..8556ea12cd 100644
--- a/util.c
+++ b/util.c
@@ -1677,13 +1677,24 @@ fail:
int release_terminal(void) {
int r = 0, fd;
+ struct sigaction sa_old, sa_new;
- if ((fd = open("/dev/tty", O_RDWR)) < 0)
+ if ((fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_NDELAY)) < 0)
return -errno;
+ /* Temporarily ignore SIGHUP, so that we don't get SIGHUP'ed
+ * by our own TIOCNOTTY */
+
+ zero(sa_new);
+ sa_new.sa_handler = SIG_IGN;
+ sa_new.sa_flags = SA_RESTART;
+ assert_se(sigaction(SIGHUP, &sa_new, &sa_old) == 0);
+
if (ioctl(fd, TIOCNOTTY) < 0)
r = -errno;
+ assert_se(sigaction(SIGHUP, &sa_old, NULL) == 0);
+
close_nointr_nofail(fd);
return r;
}