1
0
mirror of git://sigrok.org/libserialport synced 2023-08-10 21:13:24 +03:00

Canonicalize symlinks in portnames

This allows users to supply symlinks created e.g. by udev rules instead
of the actual device names.
This commit is contained in:
Stefan Tauner 2017-05-21 23:42:06 +02:00 committed by Uwe Hermann
parent 2a6c24be33
commit 95bad38c5b
3 changed files with 18 additions and 1 deletions

View File

@ -126,6 +126,9 @@ AC_CHECK_DECLS([BOTHER],,, [[#include <linux/termios.h>]])
# Check for serial_struct.
AC_CHECK_TYPES([struct serial_struct],,, [[#include <linux/serial.h>]])
# Check for realpath().
AC_CHECK_FUNC([realpath], [AC_DEFINE(HAVE_REALPATH, 1, [realpath is available.])], [])
AC_CACHE_CHECK([for visibility control], [sp_cv_visibility_control], [
sp_saved_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS -Werror"

View File

@ -23,7 +23,7 @@
#ifdef __linux__
/* For timeradd, timersub, timercmp. */
/* For timeradd, timersub, timercmp, realpath. */
#define _BSD_SOURCE 1 /* for glibc < 2.19 */
#define _DEFAULT_SOURCE 1 /* for glibc >= 2.20 */
#endif

View File

@ -75,6 +75,20 @@ SP_API enum sp_return sp_get_port_by_name(const char *portname, struct sp_port *
DEBUG_FMT("Building structure for port %s", portname);
#if !defined(_WIN32) && defined(HAVE_REALPATH)
/*
* get_port_details() below tries to be too smart and figure out
* some transport properties from the port name which breaks with
* symlinks. Therefore we canonicalize the portname first.
*/
char pathbuf[PATH_MAX + 1];
char *res = realpath(portname, pathbuf);
if (!res)
RETURN_ERROR(SP_ERR_ARG, "Could not retrieve realpath behind port name");
portname = pathbuf;
#endif
if (!(port = malloc(sizeof(struct sp_port))))
RETURN_ERROR(SP_ERR_MEM, "Port structure malloc failed");