# 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"
#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
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");