Hi,
maybe someone else does find this usable :)
will loop to find the first available cua line unless -r or line_path
chosen before open(), so this does not really change the mostly
expected behaviour i can think of; only does make cua00 little less special.
-Artturi
diff --git a/usr.bin/cu/cu.c b/usr.bin/cu/cu.c
index 03a2df4181f..b4b07a924c6 100644
--- a/usr.bin/cu/cu.c
+++ b/usr.bin/cu/cu.c
@@ -44,6 +44,7 @@ struct bufferevent *output_ev;
int is_direct = -1;
int restricted = 0;
const char *line_path = NULL;
+int line_loop = 0;
int line_speed = -1;
int line_fd;
struct termios line_tio;
@@ -149,8 +150,10 @@ main(int argc, char **argv)
}
}
- if (line_path == NULL)
- line_path = "/dev/cua00";
+ if (line_path == NULL) {
+ line_path = "cua00";
+ line_loop = restricted ? 0 : 1;
+ }
if (line_speed == -1)
line_speed = 9600;
if (is_direct == -1)
@@ -165,7 +168,18 @@ main(int argc, char **argv)
flags = O_RDWR;
if (is_direct)
flags |= O_NONBLOCK;
- line_fd = open(line_path, flags);
+ for (;;) {
+ line_fd = open(line_path, flags);
+ if (!(line_fd < 0) || line_loop == 0 || line_loop > 20)
+ break;
+ warn("open(\"%s\")", line_path);
+ free(line_path);
+ if (asprintf(&line_path, "%s%s%d", _PATH_DEV,
+ line_loop < 11 ? "cua0" : "cuaU",
+ line_loop - (line_loop < 11 ? 1 : 11)) == -1)
+ err(1, "asprintf");
+ line_loop++;
+ }
if (line_fd < 0)
err(1, "open(\"%s\")", line_path);
if (restricted && pledge("stdio tty", NULL) == -1)