X-Git-Url: https://git.archive.openwrt.org/?a=blobdiff_plain;f=udevtrigger.c;h=af620c24db0ac00f63113d6443a2a459a129ba88;hb=e6021a8a34e39328ffc867141da03c19da9b2aec;hp=be611c7385488a27e39c6beb715a309163c7dd0e;hpb=1dc968d494c86e4a48335428b7c5cb99ca12e106;p=project%2Fprocd.git diff --git a/udevtrigger.c b/udevtrigger.c index be611c7..af620c2 100644 --- a/udevtrigger.c +++ b/udevtrigger.c @@ -5,12 +5,12 @@ * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation version 2 of the License. - * + * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -135,21 +136,34 @@ static int sysfs_resolve_link(char *devpath, size_t size) return 0; } +static bool device_has_attribute(const char *path, const char *attr, + mode_t mode) +{ + char filename[PATH_SIZE]; + struct stat statbuf; + + strlcpy(filename, path, sizeof(filename)); + strlcat(filename, attr, sizeof(filename)); + + if (stat(filename, &statbuf) < 0) + return false; + + if (!(statbuf.st_mode & mode)) + return false; + + return true; +} static int device_list_insert(const char *path) { - char filename[PATH_SIZE]; char devpath[PATH_SIZE]; struct stat statbuf; dbg("add '%s'" , path); - /* we only have a device, if we have an uevent file */ - strlcpy(filename, path, sizeof(filename)); - strlcat(filename, "/uevent", sizeof(filename)); - if (stat(filename, &statbuf) < 0) - return -1; - if (!(statbuf.st_mode & S_IWUSR)) + /* we only have a device, if we have a dev and an uevent file */ + if (!device_has_attribute(path, "/dev", S_IRUSR) || + !device_has_attribute(path, "/uevent", S_IWUSR)) return -1; strlcpy(devpath, &path[4], sizeof(devpath));