Re: cu: loop over cua00-09+cuaU0-U9

2018-01-09 Thread Theo de Raadt
You want to connect to the next available port?

yeah, and I'll work up a diff so that newfs without any arguements
initializes the next partition.

The concept is ridiculous.

> On Tue, Jan 09, 2018 at 01:44:04PM -0700, Theo de Raadt wrote:
> > No way.
> > 
> > No justification provided for anyone to want this feature.
> > 
> 
> Np, this is just what i want this for:
> 
> ucom0 at uchcom0
> ucom1 at uplcom0
> ucom2 at uslcom0 portno 0
> ucom3 at uftdi0 portno 1
> ucom4 at uftdi1 portno 1
> ucom5 at uftdi2 portno 1
> ucom6 at uftdi3 portno 1
> ucom7 at uftdi4 portno 1
> ucom8 at umodem0
> 
> $ usbdevs   
> addr 1: xHCI root hub, NEC
>  addr 2: Cypress USB Keyboard / PS2 Mouse, Cypress
>  addr 3: Razer Naga Hex, Razer
> addr 1: EHCI root hub, NEC
> addr 1: OHCI root hub, NEC
>  addr 2: USB Hub 2.0, ALCOR
>   addr 3: USB Hub 2.0, ALCOR
>addr 4: CH340 serial/parallel, QinHeng Electronics
>addr 5: USB-Serial Controller, Prolific Technology Inc.
>addr 6: CP2104 USB to UART Bridge Controller, Silicon Labs
>   addr 7: FT232R USB UART, FTDI
>  addr 8: USB Hub 2.0, ALCOR
>   addr 9: USB Hub 2.0, ALCOR
>addr 10: FT232R USB UART, FTDI
>addr 11: FT232R USB UART, FTDI
>addr 12: FT232R USB UART, FTDI
>   addr 13: FT232R USB UART, FTDI
>   addr 14: STM32 STLink, STMicroelectronics
> 
> 
> and here's how it looks when working:
> 
> $ ./cu -115200
> cu: open("/dev/cua00"): Device busy
> cu: open("/dev/cua00"): Device busy
> cu: open("/dev/cua01"): Device not configured
> cu: open("/dev/cua02"): Device not configured
> cu: open("/dev/cua03"): Device not configured
> cu: open("/dev/cua04"): Device not configured
> cu: open("/dev/cua05"): Device not configured
> cu: open("/dev/cua06"): Device not configured
> cu: open("/dev/cua07"): Device not configured
> cu: open("/dev/cua08"): Device not configured
> cu: open("/dev/cua09"): Device not configured
> cu: open("/dev/cuaU0"): Device busy
> Connected to /dev/cuaU1 (speed 115200)
> 
> av7bbb#
> av7bbb#
> [EOT]
> 
>  $
>  $ ./cu -115200 -l cua00
> cu: open("/dev/cua00"): Device busy
>  $ cu -115200 -l cuaU2
> cu: open("/dev/cuaU2"): Device busy
>  $
> 



Re: cu: loop over cua00-09+cuaU0-U9

2018-01-09 Thread Artturi Alm
On Tue, Jan 09, 2018 at 01:44:04PM -0700, Theo de Raadt wrote:
> No way.
> 
> No justification provided for anyone to want this feature.
> 

Np, this is just what i want this for:

ucom0 at uchcom0
ucom1 at uplcom0
ucom2 at uslcom0 portno 0
ucom3 at uftdi0 portno 1
ucom4 at uftdi1 portno 1
ucom5 at uftdi2 portno 1
ucom6 at uftdi3 portno 1
ucom7 at uftdi4 portno 1
ucom8 at umodem0

$ usbdevs   
addr 1: xHCI root hub, NEC
 addr 2: Cypress USB Keyboard / PS2 Mouse, Cypress
 addr 3: Razer Naga Hex, Razer
addr 1: EHCI root hub, NEC
addr 1: OHCI root hub, NEC
 addr 2: USB Hub 2.0, ALCOR
  addr 3: USB Hub 2.0, ALCOR
   addr 4: CH340 serial/parallel, QinHeng Electronics
   addr 5: USB-Serial Controller, Prolific Technology Inc.
   addr 6: CP2104 USB to UART Bridge Controller, Silicon Labs
  addr 7: FT232R USB UART, FTDI
 addr 8: USB Hub 2.0, ALCOR
  addr 9: USB Hub 2.0, ALCOR
   addr 10: FT232R USB UART, FTDI
   addr 11: FT232R USB UART, FTDI
   addr 12: FT232R USB UART, FTDI
  addr 13: FT232R USB UART, FTDI
  addr 14: STM32 STLink, STMicroelectronics


and here's how it looks when working:

$ ./cu -115200
cu: open("/dev/cua00"): Device busy
cu: open("/dev/cua00"): Device busy
cu: open("/dev/cua01"): Device not configured
cu: open("/dev/cua02"): Device not configured
cu: open("/dev/cua03"): Device not configured
cu: open("/dev/cua04"): Device not configured
cu: open("/dev/cua05"): Device not configured
cu: open("/dev/cua06"): Device not configured
cu: open("/dev/cua07"): Device not configured
cu: open("/dev/cua08"): Device not configured
cu: open("/dev/cua09"): Device not configured
cu: open("/dev/cuaU0"): Device busy
Connected to /dev/cuaU1 (speed 115200)

av7bbb#
av7bbb#
[EOT]

 $
 $ ./cu -115200 -l cua00
cu: open("/dev/cua00"): Device busy
 $ cu -115200 -l cuaU2
cu: open("/dev/cuaU2"): Device busy
 $



Re: cu: loop over cua00-09+cuaU0-U9

2018-01-09 Thread Theo de Raadt
No way.

No justification provided for anyone to want this feature.

> 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 termiosline_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)
> 



cu: loop over cua00-09+cuaU0-U9

2018-01-09 Thread Artturi Alm
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)