summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd C. Miller <Todd.Miller@sudo.ws>2023-04-16 15:45:19 -0600
committerTodd C. Miller <Todd.Miller@sudo.ws>2023-04-16 15:45:19 -0600
commit8c9bdeb4ab003fe30e7a981412511997c02f75b5 (patch)
tree15cab213352de9d6c6504a6eec8d7de83331eb0a /lib
parenta96a7bb7d416bf5e2e42ae3089afae9569873b9c (diff)
downloadsudo-8c9bdeb4ab003fe30e7a981412511997c02f75b5.tar.gz
Add an fd argument to sudo_get_ttysize() instead of always using stderr.
For sudoreplay we open /dev/tty, so use that instead of stderr when determining the terminal size.
Diffstat (limited to 'lib')
-rw-r--r--lib/util/ttysize.c14
-rw-r--r--lib/util/util.exp.in1
2 files changed, 11 insertions, 4 deletions
diff --git a/lib/util/ttysize.c b/lib/util/ttysize.c
index c14e3a85d..d72f96eb9 100644
--- a/lib/util/ttysize.c
+++ b/lib/util/ttysize.c
@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: ISC
*
- * Copyright (c) 2010-2012, 2014-2015 Todd C. Miller <Todd.Miller@sudo.ws>
+ * Copyright (c) 2010-2012, 2014-2015, 2023 Todd C. Miller <Todd.Miller@sudo.ws>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -34,12 +34,12 @@
#include "sudo_util.h"
static int
-get_ttysize_ioctl(int *rowp, int *colp)
+get_ttysize_ioctl(int fd, int *rowp, int *colp)
{
struct winsize wsize;
debug_decl(get_ttysize_ioctl, SUDO_DEBUG_UTIL);
- if (isatty(STDERR_FILENO) && ioctl(STDERR_FILENO, TIOCGWINSZ, &wsize) == 0) {
+ if (isatty(fd) && ioctl(fd, TIOCGWINSZ, &wsize) == 0) {
if (wsize.ws_row != 0 && wsize.ws_col != 0) {
*rowp = wsize.ws_row;
*colp = wsize.ws_col;
@@ -52,9 +52,15 @@ get_ttysize_ioctl(int *rowp, int *colp)
void
sudo_get_ttysize_v1(int *rowp, int *colp)
{
+ sudo_get_ttysize_v2(STDERR_FILENO, rowp, colp);
+}
+
+void
+sudo_get_ttysize_v2(int fd, int *rowp, int *colp)
+{
debug_decl(sudo_get_ttysize, SUDO_DEBUG_UTIL);
- if (get_ttysize_ioctl(rowp, colp) == -1) {
+ if (get_ttysize_ioctl(fd, rowp, colp) == -1) {
char *p;
/* Fall back on $LINES and $COLUMNS. */
diff --git a/lib/util/util.exp.in b/lib/util/util.exp.in
index 484753ab0..47e776c0d 100644
--- a/lib/util/util.exp.in
+++ b/lib/util/util.exp.in
@@ -83,6 +83,7 @@ sudo_gai_vfatal_nodebug_v1
sudo_gai_vwarn_nodebug_v1
sudo_gai_warn_nodebug_v1
sudo_get_ttysize_v1
+sudo_get_ttysize_v2
sudo_getgrouplist2_v1
sudo_gethostname_v1
sudo_gettime_awake_v1