get_tty_fd: only print fd on success

This commit is contained in:
nick black 2021-11-01 20:32:04 -04:00 committed by nick black
parent a9fd1542e4
commit 5fe3a30580
2 changed files with 8 additions and 6 deletions

View File

@ -457,12 +457,12 @@ int get_tty_fd(FILE* ttyfp){
int fd = -1;
if(ttyfp){
if((fd = fileno(ttyfp)) < 0){
logwarn("No file descriptor was available in outfp %p\n", ttyfp);
logwarn("no file descriptor was available in outfp %p\n", ttyfp);
}else{
if(tty_check(fd)){
fd = dup(fd);
}else{
loginfo("fd %d not a TTY\n", fd);
loginfo("fd %d is not a TTY\n", fd);
fd = -1;
}
}
@ -470,15 +470,17 @@ int get_tty_fd(FILE* ttyfp){
if(fd < 0){
fd = open("/dev/tty", O_RDWR | O_CLOEXEC | O_NOCTTY);
if(fd < 0){
loginfo("Error opening /dev/tty (%s)\n", strerror(errno));
loginfo("couldn't open /dev/tty (%s)\n", strerror(errno));
}else{
if(!tty_check(fd)){
loginfo("File descriptor for /dev/tty (%d) is not actually a TTY\n", fd);
loginfo("file descriptor for /dev/tty (%d) is not actually a TTY\n", fd);
close(fd);
fd = -1;
}
}
}
loginfo("Returning TTY fd %d\n", fd);
if(fd >= 0){
loginfo("returning TTY fd %d\n", fd);
}
return fd;
}

View File

@ -38,7 +38,7 @@ static void
get_default_geometry(tinfo* ti){
ti->default_rows = get_default_dimension("LINES", "lines", 24);
ti->default_cols = get_default_dimension("COLUMNS", "cols", 80);
loginfo("Default geometry: %d row%s, %d column%s\n",
loginfo("default geometry: %d row%s, %d column%s\n",
ti->default_rows, ti->default_rows != 1 ? "s" : "",
ti->default_cols, ti->default_cols != 1 ? "s" : "");
ti->dimy = ti->default_rows;