Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve TTY path before opening #61

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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