summaryrefslogtreecommitdiffstats
path: root/term-utils/write.c
diff options
context:
space:
mode:
authorSami Kerola2016-05-14 20:50:41 +0200
committerSami Kerola2016-07-04 00:35:10 +0200
commit285c1f3a3eda762897d45f698e94c461d68e8d68 (patch)
treee2b99cdb523a2f4341e68da397310925df91f402 /term-utils/write.c
parentwrite: stop removing and adding /dev/ in front of tty string (diff)
downloadkernel-qcow2-util-linux-285c1f3a3eda762897d45f698e94c461d68e8d68.tar.gz
kernel-qcow2-util-linux-285c1f3a3eda762897d45f698e94c461d68e8d68.tar.xz
kernel-qcow2-util-linux-285c1f3a3eda762897d45f698e94c461d68e8d68.zip
lib: try to find tty in get_terminal_name()
Try all standard terminal input/output file descriptors when finding tty name in get_germinal_name(). This should make all invocations of the function as robust as they can get. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'term-utils/write.c')
-rw-r--r--term-utils/write.c16
1 files changed, 3 insertions, 13 deletions
diff --git a/term-utils/write.c b/term-utils/write.c
index be91218cf..6bd393441 100644
--- a/term-utils/write.c
+++ b/term-utils/write.c
@@ -296,7 +296,7 @@ static void do_write(const struct write_control *ctl)
int main(int argc, char **argv)
{
- int tty_writeable = 0, src_fd, c;
+ int tty_writeable = 0, c;
struct write_control ctl = { 0 };
static const struct option longopts[] = {
@@ -321,18 +321,8 @@ int main(int argc, char **argv)
usage(stderr);
}
- /* check that sender has write enabled */
- if (isatty(STDIN_FILENO))
- src_fd = STDIN_FILENO;
- else if (isatty(STDOUT_FILENO))
- src_fd = STDOUT_FILENO;
- else if (isatty(STDERR_FILENO))
- src_fd = STDERR_FILENO;
- else
- src_fd = -1;
-
- if (src_fd != -1 &&
- get_terminal_name(src_fd, &ctl.src_tty_path, &ctl.src_tty_name, NULL) == 0) {
+ if (get_terminal_name(&ctl.src_tty_path, &ctl.src_tty_name, NULL) == 0) {
+ /* check that sender has write enabled */
if (check_tty(ctl.src_tty_path, &tty_writeable, NULL, 1))
exit(EXIT_FAILURE);
if (!tty_writeable)