Closed s-hemer closed 1 year ago
looking good. I did a little testing:
linux-serial-test -p /dev/ttyUSB0
And then Ctrl-C
Linux serial test app
^Cpoll(): Interrupted system call
Terminating ...
/dev/ttyUSB0: count for this session: rx=12400, tx=13824, rx err=0
/dev/ttyUSB0: TIOCGICOUNT: ret=0, rx=150412, tx=152064, frame = 0, overrun = 0, parity = 0, brk = 0, buf_overrun = 0
Exit handler: Cleaning up ...
But with kill
Linux serial test app
Terminated
Which matches your comment.
What do you think of adding the following:
https://github.com/cbrake/linux-serial-test/pull/52/commits/7d71c474d970fd69a0084e4699083de451acc057
./linux-serial-test -p /dev/ttyUSB0 -o 2 -r
seems to call cleanup handlers OK.
I had the way of stopping via kill in mind, yet you are right that defaults to SIGTERM not SIGINT. Will test this variant and your addition. Only question: what about all the others in between like SIGKILL? With -o and -r set, it already worked before, would be also a solution to only allow option combinations that will definitively terminate (-o + -i set, -o+ -r, -i + -t, ...) and deny others. Yet, I am not sure if that makes sense and is intuitive.
Only question: what about all the others in between like SIGKILL?
SIGKILL can't be overridden (101 in Unix :-)
I am satisfied supporting just SIGTERM and SIGINT -- if other requirements come up in the future, we can add them then.
I think the exit handler is still useful if the program exits in the middle due to an error, not a signal.
It is not always obvious what should go in the program end vs exit handler, but let's take our best guess and get something working for you, and then we can iterate from there.
I think the exit handler is still useful if the program exits in the middle due to an error, not a signal.
I think this is out of question.
Looks good to me! You ready to merge this?
Yes, I set it from draft to ready (to review, but if review is ok that means also merge, I guess).
@s-hemer thanks for the thoughtful contributions! Amazing how such a simple tool can keep getting better.
This ensures correctly resetting i.e. RTS lines on RS485. Furthermore, moved the tcflush to exit_handler. Should solve the second part of #48. There are some comments that mark yet undecided/not finally tested changes. Feedback welcome, will remove them for final PR.