chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
util: temporarily ignore SIGHUP while we are issuing TIOCSTTY
[elogind.git]
/
src
/
shared
/
util.c
diff --git
a/src/shared/util.c
b/src/shared/util.c
index 63471899fd111f8d21da5c74baecfcd464fb130d..845b4bf8241cf427678dc0d576bbc5bf97431c1c 100644
(file)
--- a/
src/shared/util.c
+++ b/
src/shared/util.c
@@
-1083,7
+1083,7
@@
int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char *
if (h < 0)
return h;
if (h < 0)
return h;
- r = join("[", t, "]", NULL);
+ r =
str
join("[", t, "]", NULL);
free(t);
if (!r)
free(t);
if (!r)
@@
-2387,6
+2387,7
@@
int acquire_terminal(
int fd = -1, notify = -1, r, wd = -1;
usec_t ts = 0;
int fd = -1, notify = -1, r, wd = -1;
usec_t ts = 0;
+ struct sigaction sa_old, sa_new;
assert(name);
assert(name);
@@
-2434,17
+2435,26
@@
int acquire_terminal(
if (fd < 0)
return fd;
if (fd < 0)
return fd;
+ /* Temporarily ignore SIGHUP, so that we don't get SIGHUP'ed
+ * if we already own the tty. */
+ zero(sa_new);
+ sa_new.sa_handler = SIG_IGN;
+ sa_new.sa_flags = SA_RESTART;
+ assert_se(sigaction(SIGHUP, &sa_new, &sa_old) == 0);
+
/* First, try to get the tty */
/* First, try to get the tty */
- r = ioctl(fd, TIOCSCTTY, force);
+ if (ioctl(fd, TIOCSCTTY, force) < 0)
+ r = -errno;
+
+ assert_se(sigaction(SIGHUP, &sa_old, NULL) == 0);
/* Sometimes it makes sense to ignore TIOCSCTTY
* returning EPERM, i.e. when very likely we already
* are have this controlling terminal. */
/* Sometimes it makes sense to ignore TIOCSCTTY
* returning EPERM, i.e. when very likely we already
* are have this controlling terminal. */
- if (r < 0 &&
errno ==
EPERM && ignore_tiocstty_eperm)
+ if (r < 0 &&
r == -
EPERM && ignore_tiocstty_eperm)
r = 0;
r = 0;
- if (r < 0 && (force || fail || errno != EPERM)) {
- r = -errno;
+ if (r < 0 && (force || fail || r != -EPERM)) {
goto fail;
}
goto fail;
}
@@
-5145,7
+5155,7
@@
finish:
return r;
}
return r;
}
-char *join(const char *x, ...) {
+char *
str
join(const char *x, ...) {
va_list ap;
size_t l;
char *r, *p;
va_list ap;
size_t l;
char *r, *p;