I have an application (using
QIODevice::write (QSerialPort): device not open
crw-rw---T 1 root dialout ......
$> echo "foo bar baz" >> /dev/ttyS0
$> echo $?
Update: this is a bug in Qt, and will be fixed in version 5.6.2, which is due for release later this month.
On Linux and Mac,
QSerialPort creates a lock file in
/var/lock/ when opening a serial port. The lockfile has permissions
0644, i.e. only the creator of the file can write to it.
If the process that opened the serial port dies or if the serial port is somehow improperly closed by any other means, the lock file will not be deleted. The lockfile contains the PID of the process that opened the serial port; if the process is no longer running, Qt will attempt to simply take possession of the lock, changing the PID in the file.
However, since the lockfile has
0644 permissions, if the improperly-closing process was run by
root, the new process will be unable to delete or overwrite the lockfile, resulting in a permissions error.
This is fixed for version 5.6.2.
Note that QSerialPort does clean up after itself: when its destructor is called, the port is closed and the lockfile is deleted. However, by default, Qt does not call object destructors when
SIGINT causes the program to exit. (Personally, I think this is also a bug, but I recognize that this is more a matter of opinion.)
Also see the suggested dupe question. As can be seen from this question, the current behavior is actually an improvement--previously, the application would simply hang!