udev-node.c revision 6c29f2b942358d4dd9d3e7c65c13c3612dded3cc
144d4893ba5a3815bd1639d498ee4a20ed13a211Till Mossakowski * Copyright (C) 2003-2009 Kay Sievers <kay.sievers@vrfy.org>
cc9279b89cc62b80199696ac7e87b6d2bdd08e7aTill Mossakowski * This program is free software: you can redistribute it and/or modify
5f40e8aa2c372040ab519c6401627d64812922ffKlaus Luettich * it under the terms of the GNU General Public License as published by
c1015e823b467ffb3e58fe3eacb0db58937063baTill Mossakowski * the Free Software Foundation, either version 2 of the License, or
baac12e7dd41b6e250e753c88ee0d40505509104Klaus Luettich * (at your option) any later version.
baac12e7dd41b6e250e753c88ee0d40505509104Klaus Luettich * This program is distributed in the hope that it will be useful,
aa6f6fa09091e92016598584162b9ba909af48ccTill Mossakowski * but WITHOUT ANY WARRANTY; without even the implied warranty of
ed6873e3c28f11208f6873e04a65c3c3aa012ed9Klaus Luettich * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ed6873e3c28f11208f6873e04a65c3c3aa012ed9Klaus Luettich * GNU General Public License for more details.
ed6873e3c28f11208f6873e04a65c3c3aa012ed9Klaus Luettich * You should have received a copy of the GNU General Public License
ed6873e3c28f11208f6873e04a65c3c3aa012ed9Klaus Luettich * along with this program. If not, see <http://www.gnu.org/licenses/>.
144d4893ba5a3815bd1639d498ee4a20ed13a211Till Mossakowskiint udev_node_mknod(struct udev_device *dev, const char *file, dev_t devnum, mode_t mode, uid_t uid, gid_t gid)
144d4893ba5a3815bd1639d498ee4a20ed13a211Till Mossakowski struct udev *udev = udev_device_get_udev(dev);
7c610eb832a4575b209fc6e6c674b99975135012Till Mossakowski if (strcmp(udev_device_get_subsystem(dev), "block") == 0)
183e25edd6aaf48da3cfcf6e5a5300bed5a941dfTill Mossakowski if (((stats.st_mode & S_IFMT) == (mode & S_IFMT)) && (stats.st_rdev == devnum)) {
7c610eb832a4575b209fc6e6c674b99975135012Till Mossakowski info(udev, "preserve file '%s', because it has correct dev_t\n", file);
183e25edd6aaf48da3cfcf6e5a5300bed5a941dfTill Mossakowski udev_selinux_lsetfilecon(udev, file, mode);
183e25edd6aaf48da3cfcf6e5a5300bed5a941dfTill Mossakowski char file_tmp[UTIL_PATH_SIZE + sizeof(TMP_FILE_EXT)];
183e25edd6aaf48da3cfcf6e5a5300bed5a941dfTill Mossakowski info(udev, "atomically replace existing file '%s'\n", file);
183e25edd6aaf48da3cfcf6e5a5300bed5a941dfTill Mossakowski util_strscpyl(file_tmp, sizeof(file_tmp), file, TMP_FILE_EXT, NULL);
183e25edd6aaf48da3cfcf6e5a5300bed5a941dfTill Mossakowski udev_selinux_setfscreatecon(udev, file_tmp, mode);
183e25edd6aaf48da3cfcf6e5a5300bed5a941dfTill Mossakowski err(udev, "mknod(%s, %#o, %u, %u) failed: %m\n",
183e25edd6aaf48da3cfcf6e5a5300bed5a941dfTill Mossakowski file_tmp, mode, major(devnum), minor(devnum));
7c610eb832a4575b209fc6e6c674b99975135012Till Mossakowski err(udev, "rename(%s, %s) failed: %m\n", file_tmp, file);
7c610eb832a4575b209fc6e6c674b99975135012Till Mossakowski info(udev, "mknod(%s, %#o, (%u,%u))\n", file, mode, major(devnum), minor(devnum));
7c610eb832a4575b209fc6e6c674b99975135012Till Mossakowski udev_selinux_setfscreatecon(udev, file, mode);
7c610eb832a4575b209fc6e6c674b99975135012Till Mossakowski err(udev, "mknod(%s, %#o, (%u,%u) failed: %m\n", file, mode, major(devnum), minor(devnum));
7c610eb832a4575b209fc6e6c674b99975135012Till Mossakowski info(udev, "chmod(%s, %#o)\n", file, mode);
7c610eb832a4575b209fc6e6c674b99975135012Till Mossakowski err(udev, "chmod(%s, %#o) failed: %m\n", file, mode);
7c610eb832a4575b209fc6e6c674b99975135012Till Mossakowski if (!preserve || stats.st_uid != uid || stats.st_gid != gid) {
7c610eb832a4575b209fc6e6c674b99975135012Till Mossakowski info(udev, "chown(%s, %u, %u)\n", file, uid, gid);
7c610eb832a4575b209fc6e6c674b99975135012Till Mossakowski err(udev, "chown(%s, %u, %u) failed: %m\n", file, uid, gid);
183e25edd6aaf48da3cfcf6e5a5300bed5a941dfTill Mossakowskistatic int node_symlink(struct udev *udev, const char *node, const char *slink)
183e25edd6aaf48da3cfcf6e5a5300bed5a941dfTill Mossakowski char slink_tmp[UTIL_PATH_SIZE + sizeof(TMP_FILE_EXT)];
int tail = 0;
int err = 0;
s = target;
l = sizeof(target);
goto exit;
goto exit;
int len;
if (len > 0) {
goto exit;
if (err == 0)
goto exit;
if (err != 0) {
goto exit;
if (err != 0) {
exit:
return err;
static const char *link_find_prioritized(struct udev_device *dev, bool add, const char *stackdir, char *buf, size_t bufsize)
int priority = 0;
if (add) {
return target;
const char *devnode;
return target;
const char *target;
if (!add) {
if (add) {
int found;
found = 0;
if (found)
int num;
int err = 0;
goto exit;
if (num > 0) {
exit:
return err;
const char *devnode;
int err = 0;
int num;
if (err)
return err;
if (num > 0) {
return err;