udev-node.c revision 48a849ee17fb25e0001bfcc0f28a4aa633d016a1
/*
* Copyright (C) 2003-2010 Kay Sievers <kay@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"
{
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 */
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;
log_debug("'%s' claims priority %i for '%s'\n",
}
}
}
}
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];
} 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;
log_debug("update old name, '%s' no longer belonging to '%s'\n",
}
}
{
int err = 0;
else
goto out;
}
log_debug("found node '%s' with non-matching devnum %s, skip handling\n",
goto out;
}
/*
* Set permissions and selinux file context only on add events. We always
* set it on bootup (coldplug) with "trigger --action=add" for all devices
* and for any newly added devices (hotplug). We don't want to change it
* later, in case something else has applied custom settings in the meantime.
*/
} else {
}
}
/* always update timestamp when we re-use the node, like on media change events */
out:
return err;
}
{
char filename[UTIL_PATH_SIZE];
struct udev_list_entry *list_entry;
log_debug("handling device node '%s', devnum=%s, mode=%#o, uid=%d, gid=%d\n",
return;
/* always add /dev/{block,char}/$major:$minor */
}
{
struct udev_list_entry *list_entry;
char filename[UTIL_PATH_SIZE];
/* remove /dev/{block,char}/$major:$minor */
}