Skip to content

Commit

Permalink
Resolve TTY path before opening
Browse files Browse the repository at this point in the history
  • Loading branch information
YaSuenag committed Oct 15, 2024
1 parent 6d1a7eb commit c547c56
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tty-resizer/tty-resizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <bpf/libbpf.h>
#include "tty-resizer.skel.h"
#include "common.h"


static const char *ttypath;
static char ttypath[PATH_MAX];
static ino_t tty_ino;
static struct tty_resizer_bpf *skel = NULL;
static struct ring_buffer *rb = NULL;
Expand Down Expand Up @@ -119,16 +121,21 @@ static int setup_bpf(){
int main(int argc, char *argv[]){
if((argc == 3) && (strcmp(argv[1], "-v") == 0)){
libbpf_set_print(libbpf_print);
ttypath = argv[2];
realpath(argv[2], ttypath);
}
else if(argc == 2){
ttypath = argv[1];
realpath(argv[1], ttypath);
}
else{
printf("Usage: %s <-v> [TTY device file]\n", argv[0]);
return -100;
}

if(strncmp(ttypath, "/dev/tty", 8) != 0){
fprintf(stderr, "Not a valid TTY device: %s\n", ttypath);
return -150;
}

if((setup_tty() == 0) && (setup_bpf() == 0)){
while(true){
int ret = ring_buffer__poll(rb, -1);
Expand Down

0 comments on commit c547c56

Please sign in to comment.