X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev%2Fudev_node.c;h=8971f9ff3fdacb35681546e55590f56634282479;hb=41b7a00922bdb1a501cbf2e39282fe64bb94cb6d;hp=079bb4e3b1092ffc5d5ec251268852ebb5e0bbcf;hpb=4f4b12c20388ff2cb158b040e3193f86cf7a3b96;p=elogind.git diff --git a/udev/udev_node.c b/udev/udev_node.c index 079bb4e3b..8971f9ff3 100644 --- a/udev/udev_node.c +++ b/udev/udev_node.c @@ -1,20 +1,18 @@ /* - * Copyright (C) 2003 Greg Kroah-Hartman - * Copyright (C) 2004-2006 Kay Sievers + * Copyright (C) 2004-2008 Kay Sievers * - * 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. + * 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, either version 2 of the License, or + * (at your option) any later version. * + * 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, see . */ #include @@ -36,7 +34,7 @@ int udev_node_mknod(struct udevice *udevice, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid) { - char file_tmp[PATH_SIZE + sizeof(TMP_FILE_EXT)]; + char file_tmp[UTIL_PATH_SIZE + sizeof(TMP_FILE_EXT)]; struct stat stats; int preserve = 0; int err = 0; @@ -53,8 +51,8 @@ int udev_node_mknod(struct udevice *udevice, const char *file, dev_t devt, mode_ udev_selinux_lsetfilecon(udevice->udev, file, mode); } else { info(udevice->udev, "atomically replace existing file '%s'\n", file); - strlcpy(file_tmp, file, sizeof(file_tmp)); - strlcat(file_tmp, TMP_FILE_EXT, sizeof(file_tmp)); + util_strlcpy(file_tmp, file, sizeof(file_tmp)); + util_strlcat(file_tmp, TMP_FILE_EXT, sizeof(file_tmp)); unlink(file_tmp); udev_selinux_setfscreatecon(udevice->udev, file_tmp, mode); err = mknod(file_tmp, mode, devt); @@ -106,8 +104,8 @@ exit: static int node_symlink(struct udevice *udevice, const char *node, const char *slink) { struct stat stats; - char target[PATH_SIZE] = ""; - char slink_tmp[PATH_SIZE + sizeof(TMP_FILE_EXT)]; + char target[UTIL_PATH_SIZE] = ""; + char slink_tmp[UTIL_PATH_SIZE + sizeof(TMP_FILE_EXT)]; int i = 0; int tail = 0; int len; @@ -121,10 +119,10 @@ static int node_symlink(struct udevice *udevice, const char *node, const char *s } while (slink[i] != '\0') { if (slink[i] == '/') - strlcat(target, "../", sizeof(target)); + util_strlcat(target, "../", sizeof(target)); i++; } - strlcat(target, &node[tail], sizeof(target)); + util_strlcat(target, &node[tail], sizeof(target)); /* preserve link with correct target, do not replace node of other device */ if (lstat(slink, &stats) == 0) { @@ -142,7 +140,7 @@ static int node_symlink(struct udevice *udevice, const char *node, const char *s } } } else if (S_ISLNK(stats.st_mode)) { - char buf[PATH_SIZE]; + char buf[UTIL_PATH_SIZE]; info(udevice->udev, "found existing symlink '%s'\n", slink); len = readlink(slink, buf, sizeof(buf)); @@ -165,8 +163,8 @@ static int node_symlink(struct udevice *udevice, const char *node, const char *s } info(udevice->udev, "atomically replace '%s'\n", slink); - strlcpy(slink_tmp, slink, sizeof(slink_tmp)); - strlcat(slink_tmp, TMP_FILE_EXT, sizeof(slink_tmp)); + util_strlcpy(slink_tmp, slink, sizeof(slink_tmp)); + util_strlcat(slink_tmp, TMP_FILE_EXT, sizeof(slink_tmp)); unlink(slink_tmp); udev_selinux_setfscreatecon(udevice->udev, slink, S_IFLNK); retval = symlink(target, slink_tmp); @@ -188,18 +186,18 @@ exit: static int update_link(struct udevice *udevice, const char *name) { LIST_HEAD(name_list); - char slink[PATH_SIZE]; - char node[PATH_SIZE]; + char slink[UTIL_PATH_SIZE]; + char node[UTIL_PATH_SIZE]; struct udevice *udevice_db; struct name_entry *device; - char target[PATH_MAX] = ""; + char target[UTIL_PATH_SIZE] = ""; int count; int priority = 0; int rc = 0; - strlcpy(slink, udev_get_dev_path(udevice->udev), sizeof(slink)); - strlcat(slink, "/", sizeof(slink)); - strlcat(slink, name, sizeof(slink)); + util_strlcpy(slink, udev_get_dev_path(udevice->udev), sizeof(slink)); + util_strlcat(slink, "/", sizeof(slink)); + util_strlcat(slink, name, sizeof(slink)); count = udev_db_get_devices_by_name(udevice->udev, name, &name_list); info(udevice->udev, "found %i devices with name '%s'\n", count, name); @@ -226,7 +224,7 @@ static int update_link(struct udevice *udevice, const char *name) info(udevice->udev, "'%s' is our device node, database inconsistent, skip link update\n", udevice->name); } else if (target[0] == '\0' || udevice->link_priority >= priority) { priority = udevice->link_priority; - strlcpy(target, udevice->name, sizeof(target)); + util_strlcpy(target, udevice->name, sizeof(target)); } continue; } @@ -243,7 +241,7 @@ static int update_link(struct udevice *udevice, const char *name) udevice_db->dev->devpath, udevice_db->link_priority, priority); if (target[0] == '\0' || udevice_db->link_priority > priority) { priority = udevice_db->link_priority; - strlcpy(target, udevice_db->name, sizeof(target)); + util_strlcpy(target, udevice_db->name, sizeof(target)); } } } @@ -258,9 +256,9 @@ static int update_link(struct udevice *udevice, const char *name) } /* create symlink to the target with the highest priority */ - strlcpy(node, udev_get_dev_path(udevice->udev), sizeof(node)); - strlcat(node, "/", sizeof(node)); - strlcat(node, target, sizeof(node)); + util_strlcpy(node, udev_get_dev_path(udevice->udev), sizeof(node)); + util_strlcat(node, "/", sizeof(node)); + util_strlcat(node, target, sizeof(node)); info(udevice->udev, "'%s' with target '%s' has the highest priority %i, create it\n", name, target, priority); if (!udevice->test_run) { create_path(udevice->udev, slink); @@ -273,19 +271,19 @@ out: void udev_node_update_symlinks(struct udevice *udevice, struct udevice *udevice_old) { struct name_entry *name_loop; - char symlinks[PATH_SIZE] = ""; + char symlinks[UTIL_PATH_SIZE] = ""; list_for_each_entry(name_loop, &udevice->symlink_list, node) { info(udevice->udev, "update symlink '%s' of '%s'\n", name_loop->name, udevice->dev->devpath); update_link(udevice, name_loop->name); - strlcat(symlinks, udev_get_dev_path(udevice->udev), sizeof(symlinks)); - strlcat(symlinks, "/", sizeof(symlinks)); - strlcat(symlinks, name_loop->name, sizeof(symlinks)); - strlcat(symlinks, " ", sizeof(symlinks)); + util_strlcat(symlinks, udev_get_dev_path(udevice->udev), sizeof(symlinks)); + util_strlcat(symlinks, "/", sizeof(symlinks)); + util_strlcat(symlinks, name_loop->name, sizeof(symlinks)); + util_strlcat(symlinks, " ", sizeof(symlinks)); } /* export symlinks to environment */ - remove_trailing_chars(symlinks, ' '); + util_remove_trailing_chars(symlinks, ' '); if (symlinks[0] != '\0') setenv("DEVLINKS", symlinks, 1); @@ -323,15 +321,15 @@ void udev_node_update_symlinks(struct udevice *udevice, struct udevice *udevice_ int udev_node_add(struct udevice *udevice) { - char filename[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; uid_t uid; gid_t gid; int i; int retval = 0; - strlcpy(filename, udev_get_dev_path(udevice->udev), sizeof(filename)); - strlcat(filename, "/", sizeof(filename)); - strlcat(filename, udevice->name, sizeof(filename)); + util_strlcpy(filename, udev_get_dev_path(udevice->udev), sizeof(filename)); + util_strlcat(filename, "/", sizeof(filename)); + util_strlcat(filename, udevice->name, sizeof(filename)); create_path(udevice->udev, filename); if (strcmp(udevice->owner, "root") == 0) @@ -373,7 +371,7 @@ int udev_node_add(struct udevice *udevice) /* create all_partitions if requested */ if (udevice->partitions) { - char partitionname[PATH_SIZE]; + char partitionname[UTIL_PATH_SIZE]; char *attr; int range; @@ -402,15 +400,15 @@ exit: int udev_node_remove(struct udevice *udevice) { - char filename[PATH_SIZE]; - char partitionname[PATH_SIZE]; + char filename[UTIL_PATH_SIZE]; + char partitionname[UTIL_PATH_SIZE]; struct stat stats; int retval = 0; int num; - strlcpy(filename, udev_get_dev_path(udevice->udev), sizeof(filename)); - strlcat(filename, "/", sizeof(filename)); - strlcat(filename, udevice->name, sizeof(filename)); + util_strlcpy(filename, udev_get_dev_path(udevice->udev), sizeof(filename)); + util_strlcat(filename, "/", sizeof(filename)); + util_strlcat(filename, udevice->name, sizeof(filename)); if (stat(filename, &stats) != 0) { info(udevice->udev, "device node '%s' not found\n", filename); return 0;