From c6989ed912b4fecec208c3e986f446afa87d85b2 Mon Sep 17 00:00:00 2001 From: Philippe Houdoin Date: Wed, 23 Sep 2009 20:55:08 +0000 Subject: [PATCH] * check if the device path is already known first. * check the path is NOT a directory or a symlink to a directory. regular or char/block device are considered both valid path to read from and write to. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33257 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/midi/DeviceWatcher.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/servers/midi/DeviceWatcher.cpp b/src/servers/midi/DeviceWatcher.cpp index 7c3280d744..926ad4eb18 100644 --- a/src/servers/midi/DeviceWatcher.cpp +++ b/src/servers/midi/DeviceWatcher.cpp @@ -181,19 +181,25 @@ DeviceWatcher::_AddDevice(const char* path) { // printf("DeviceWatcher::_AddDevice(\"%s\");\n", path); - BEntry entry(path); - if (! entry.IsFile()) - // Invalid path ! - return; - if ( fDeviceEndpointsMap.ContainsKey(path) ) // Already known return; - int fd = open(path, O_RDWR | O_EXCL); - if (fd < 0) + BEntry entry(path); + if (entry.IsDirectory()) + // Invalid path ! return; + if (entry.IsSymLink()) { + BEntry symlink(path, true); + if (symlink.IsDirectory()) + // Invalid path! + return; + } + + int fd = open(path, O_RDWR | O_EXCL); + if (fd < 0) + return; MidiPortConsumer* consumer = new MidiPortConsumer(fd, path); _SetIcons(consumer);