wtarreau / bootterm

The terminal written for its users by its users
MIT License
215 stars 11 forks source link

Cannot use relative paths (as symlinks to devices) #10

Open ydirson opened 2 years ago

ydirson commented 2 years ago

I have created symlinks into /dev/serial/by-id/ to help working with several usb/serial adapters. I cannot refer to them using a relative path:

$ strace -efile bt ./ttyA35 
...
openat(AT_FDCWD, "/dev/./ttyA35", O_RDWR|O_NOCTTY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
Trying port ./ttyA35... Failed! (No such file or directory)
Failed to open port: No such file or directory
+++ exited with 2 +++

A workaround is to use bt $PWD/ttyA35 but it's pretty ugly :)

Probably the argument should be considered a usual relative pass when it contains a / ?

Is it really that much of a gain to spare the user from typing /dev/ when he likely has to enter tty anyway ? I'd think a string without a / would make more sense to use as bt USB0, but I guess it can be a matter of taste...

wtarreau commented 2 years ago

Hello,

sorry I seem to have missed your report. I agree that considering all '/' entries as absolute would be the best option. I considered it a while ago but abandoned the idea thinking that there was little use for devices outside of /dev. Right now this part is split not because we try to make it relative, but because that's actually how device names appear in /sys and at other places so we need to keep consistent names. Also regarding the use of "USB0" instead of "ttyUSB0", we can't realistically do that because not all devices start with "tty" (e.g. "cua0" or "serial/ttyUSB0").

I'll have a look, thanks for your report.

wtarreau commented 2 years ago

Hmm now I remember regarding the string containing a "/", it's precisely for stuff like "serial/ttyUSB0" or "modem/cua0" that are annoying.

We could maybe also consider that "./" and "../" are special prefixes. Just an idea.

wtarreau commented 2 years ago

After some thingking, I believe the best solution would be to consider that if the device number/name starts with "/", "./" or "../", then it designates an absolute device to be used, and in this case we ought to totally bypass discovery and try to use it as-is. Right now this is not the case because when you pass a name it can for example wait for that device to appear. And that name may also be a number designating a device in a list; thus all of these cases currently rely on discovery. Or we could have an option to enforce a direct device like -D path/to/dev.