Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symlink support on Linux #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mechsin
Copy link

@mechsin mechsin commented Feb 11, 2021

Would like to add the ability for libserialport to recognize and use symlinks on Linux. This is primarily in support of the Arduino IDE which uses libserialport to enumerate and list serial ports however it seems like it would be beneficial to any libserialport users. Symlinks are created on Linux when udev rules are used to map a specific device or class of devices to a symlink. In order to accommodate this I have added code to find symlinks base on TTY devices found and then I removed a block of code that ensure a real path was passed to the serial port creator and moved this call in the Linux only portion of the code. Based on some research Mac OSX doesn't seem allow for symlink serial ports and there was a guard on the code already to stop it from running on Windows so that leaves BSD which I am unfamiliar with. I am sure BSD allows for symlinks but it doesn't look like it uses the same path searching method to determine port characteristics so I though moving that bit of code would be safe. I have another version of this feature where I added a realpath element to the sp_port struct. This would leave that realpath block in place but assign that real path to the struct there however that seemed more error prone. I was able to get all of the examples to run with my code modifications.

The only other note is that there is two commits here the first adds the code to allow the symlinks to be found. The second moves the realpath code to allow the symlink port names to pass through.

This is my first pull request to an open source project so any feed back is appreciated.

This code as commited allows the symlinks for a any device to
be found. I only need to add a few variables and reuse ones from
the device finder loop.
This is a slightly different approch to fixing the issue with the
way the port details are resovled on linux. Currently the symlink
is converted to a real path in the serialport.c however if I
remove this code and move it to the get_port_details in the
linux.c everything seems to work fine. I don't believe this
will effect Mac and there was a Windows guard on the code
any way so the only implementation this might cause problems
for is BSD. Otherwise this is less envasive because we aren't
updating the port struct.
@mechsin mechsin changed the title Symlink b Symlink support on Linux Feb 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants