How to prevent DTR on open for cdc_acm?

When a userland process is opening a serial device like /dev/ttyS0 or /dev/ttyACM0, linux will raise the DTR/RTS lines by default, and will drop them when closing it.

It does that by calling a dtr_rts callback defined by the driver.

Unfortunately, there isn't yet any sysctl or similar which allows to disable this annoying behavior (of very little use nowadays), so the only thing that works is to remove that callback from the driver's tty_port_operations structure, and recompile the driver module.

You can do that for the cdc-acm driver by commenting out this line:

--- drivers/usb/class/cdc-acm.c~
+++ drivers/usb/class/cdc-acm.c
@@ -1063,7 +1063,7 @@
 }

 static const struct tty_port_operations acm_port_ops = {
-       .dtr_rts = acm_port_dtr_rts,
+       /* .dtr_rts = acm_port_dtr_rts, */
        .shutdown = acm_port_shutdown,
        .activate = acm_port_activate,
        .destruct = acm_port_destruct,

This will not prevent you from using the DTR/RTS lines via serial ioctls like TIOCMSET, TIOCMBIC, TIOCMBIS, which will be handled by the acm_tty_tiocmset(), etc callbacks from the acm_ops structure, as usual.

Similar hacks could be used with other drivers; I personally have used this with the PL2303 usb -> serial driver.

[The diff is informative; it will not apply directly because this site mangles tabs and whitespaces]