diff options
| author | Stephen Nothnagel <srnoth@users.noreply.github.com> | 2026-04-08 17:01:11 -0400 |
|---|---|---|
| committer | Stephen Nothnagel <srnoth@users.noreply.github.com> | 2026-04-08 17:01:11 -0400 |
| commit | 8f5934e9a7f75a18b7399b163fe8e898a63ce77c (patch) | |
| tree | 7b15b57acfc97cea1a1fa3d5fbe5719630d8be7e /src | |
| parent | 2509879017df77a0a7478df63d3e30c193c5ed7c (diff) | |
| download | vyos-1x-8f5934e9a7f75a18b7399b163fe8e898a63ce77c.tar.gz vyos-1x-8f5934e9a7f75a18b7399b163fe8e898a63ce77c.zip | |
serial: T8211: refactor rule to reduce duplication
Store the PROGRAM output in a temporary .BY_BUS ENV variable, then
reference it via %E{.BY_BUS} in the SYMLINK+= assignments. This
collapses the three duplicated PROGRAM pipelines into a single
invocation and removes the mixed usage of $result and %c.
No functional change: tested on MosChip MCS7840 (2x 4-port chips,
8 ports total), FTDI FT4232H, and Sierra EM7455 -- all symlinks
identical before and after, verified with udevadm test.
Reduces duplication; refactor suggested by
@copilot-pull-request-reviewer on PR #5113.
Diffstat (limited to 'src')
| -rw-r--r-- | src/etc/udev/rules.d/90-vyos-serial.rules | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/etc/udev/rules.d/90-vyos-serial.rules b/src/etc/udev/rules.d/90-vyos-serial.rules index 41cd7b381..3fb34d16a 100644 --- a/src/etc/udev/rules.d/90-vyos-serial.rules +++ b/src/etc/udev/rules.d/90-vyos-serial.rules @@ -22,8 +22,9 @@ IMPORT{builtin}="path_id", IMPORT{builtin}="usb_id" # (tr -d -) does the replacement # - Replace the first group after ":" to represent the bus relation (sed -e 0,/:/s//b/) indicated by "b" # - Replace the next group after ":" to represent the port relation (sed -e 0,/:/s//p/) indicated by "p" -ENV{ID_PATH}=="?*", ENV{.ID_PORT}=="", PROGRAM="/bin/sh -c 'echo $env{ID_PATH} | cut -d- -f3- | tr -d - | sed -e 0,/:/s//b/ | sed -e 0,/:/s//p/'", SYMLINK+="serial/by-bus/$result" -ENV{ID_PATH}=="?*", ENV{.ID_PORT}=="0", PROGRAM="/bin/sh -c 'echo $env{ID_PATH} | cut -d- -f3- | tr -d - | sed -e 0,/:/s//b/ | sed -e 0,/:/s//p/'", SYMLINK+="serial/by-bus/$result" -ENV{ID_PATH}=="?*", ENV{.ID_PORT}=="?*", ENV{.ID_PORT}!="0", PROGRAM="/bin/sh -c 'echo $env{ID_PATH} | cut -d- -f3- | tr -d - | sed -e 0,/:/s//b/ | sed -e 0,/:/s//p/'", SYMLINK+="serial/by-bus/%cp%E{.ID_PORT}" +ENV{ID_PATH}=="?*", PROGRAM="/bin/sh -c 'echo $env{ID_PATH} | cut -d- -f3- | tr -d - | sed -e 0,/:/s//b/ | sed -e 0,/:/s//p/'", ENV{.BY_BUS}="%c" +ENV{.BY_BUS}=="?*", ENV{.ID_PORT}=="", SYMLINK+="serial/by-bus/%E{.BY_BUS}" +ENV{.BY_BUS}=="?*", ENV{.ID_PORT}=="0", SYMLINK+="serial/by-bus/%E{.BY_BUS}" +ENV{.BY_BUS}=="?*", ENV{.ID_PORT}=="?*", ENV{.ID_PORT}!="0", SYMLINK+="serial/by-bus/%E{.BY_BUS}p%E{.ID_PORT}" LABEL="serial_end" |
