udev-node.c revision 4ec9c3e79771aa95586390cecff4218cc8938160
/*
* Copyright (C) 2003-2010 Kay Sievers <kay.sievers@vrfy.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stddef.h>
#include <stdbool.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <grp.h>
#include <dirent.h>
#include "udev.h"
#define TMP_FILE_EXT ".udev-tmp"
{
int err = 0;
else
} else {
}
/*
* Set initial selinux file context only on add events.
* We set the proper context on bootup (triger) or for newly
* added devices, but we don't change it later, in case
* something else has set a custom context in the meantime.
*/
/* always update timestamp when we re-use the node, like on media change events */
} else {
if (err != 0) {
goto exit;
}
if (err != 0) {
goto exit;
}
}
} else {
do {
break;
if (err != 0)
if (err != 0)
}
exit:
return err;
}
{
char target[UTIL_PATH_SIZE];
char *s;
size_t l;
int i = 0;
int tail = 0;
int err = 0;
/* use relative link */
target[0] = '\0';
if (node[i] == '/')
tail = i+1;
i++;
}
s = target;
l = sizeof(target);
while (slink[i] != '\0') {
if (slink[i] == '/')
l = util_strpcpy(&s, l, "../");
i++;
}
if (l == 0) {
goto exit;
}
/* preserve link with correct target, do not replace node of other device */
} else {
"link to '%s' will not overwrite it\n",
goto exit;
}
}
char buf[UTIL_PATH_SIZE];
int len;
goto exit;
}
}
}
} else {
do {
break;
if (err != 0)
if (err == 0)
goto exit;
}
do {
break;
if (err != 0)
if (err != 0) {
goto exit;
}
if (err != 0) {
}
exit:
return err;
}
/* find device node of device with highest priority */
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;
for (;;) {
struct udev_device *dev_db;
break;
continue;
/* did we find ourself? */
continue;
const char *devnode;
}
}
}
}
return target;
}
/* manage "stack of names" with possibly specified device priorities */
{
char name_enc[UTIL_PATH_SIZE];
char dirname[UTIL_PATH_SIZE];
const char *target;
char buf[UTIL_PATH_SIZE];
if (!add) {
}
} else {
}
if (add) {
int err;
do {
int fd;
break;
if (fd >= 0)
else
}
}
{
struct udev_list_entry *list_entry;
/* update possible left-over symlinks */
struct udev_list_entry *list_entry_current;
int found;
/* check if old link name still belongs to this device */
found = 0;
found = 1;
break;
}
}
if (found)
continue;
}
}
{
char filename[UTIL_PATH_SIZE];
struct udev_list_entry *list_entry;
int err = 0;
err = -1;
goto exit;
}
/* always add /dev/{block,char}/$major:$minor */
/* simple unmanaged link name */
else
}
exit:
return err;
}
{
struct udev_list_entry *list_entry;
const char *devnode;
struct udev_device *dev_check;
char filename[UTIL_PATH_SIZE];
int err = 0;
goto out;
goto out;
}
err = -1;
goto out;
}
/* do not remove device node if the same sys-device is re-created in the meantime */
goto out;
}
if (err == 0)
/* remove /dev/{block,char}/$major:$minor */
out:
return err;
}