udev_add.c revision 821d0ec803a72841f173739f5b713fe847edab75
/*
*
* Userspace devfs
*
* Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
*
*
* 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.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <grp.h>
#include "libsysfs/sysfs/libsysfs.h"
#include "udev_libc_wrapper.h"
#include "udev.h"
#include "udev_utils.h"
#include "udev_sysfs.h"
#include "udev_version.h"
#include "logging.h"
#include "udev_rules.h"
#include "udev_db.h"
#include "udev_selinux.h"
int udev_make_node(struct udevice *udev, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid)
{
int retval = 0;
goto create;
/* preserve node with already correct numbers, to not change the inode number */
goto perms;
}
else
case DEV_BLOCK:
break;
case DEV_CLASS:
break;
default:
return -EINVAL;
}
if (retval != 0) {
err("mknod(%s, %#o, %u, %u) failed with error '%s'",
goto exit;
}
goto exit;
}
dbg("chown(%s, %u, %u) failed with error '%s'",
goto exit;
}
}
exit:
return retval;
}
{
char partitionname[PATH_SIZE];
struct name_entry *name_loop;
int tail;
int i;
/* create parent directories if needed */
uid = 0;
else {
char *endptr;
unsigned long id;
if (endptr[0] == '\0')
else
}
gid = 0;
else {
char *endptr;
unsigned long id;
if (endptr[0] == '\0')
else
}
goto error;
} else {
info("creating device node '%s', major = '%d', minor = '%d', "
"mode = '%#o', uid = '%d', gid = '%d'", filename,
}
/* create all_partitions if requested */
if (udev->partitions) {
struct sysfs_attribute *attr;
int range;
/* take the maximum registered minor range */
if (attr) {
if (range > 1)
}
}
}
}
/* create symlink(s) if requested */
int retval;
char linktarget[PATH_SIZE];
/* optimize relative link */
linktarget[0] = '\0';
i = 0;
tail = 0;
tail = i+1;
i++;
}
i++;
}
if (retval != 0)
dbg("symlink(%s, %s) failed with error '%s'",
}
}
return 0;
return -1;
}
{
int sk;
int retval;
return 0;
if (sk < 0) {
dbg("error opening socket");
return -1;
}
if (retval != 0)
dbg("error changing net interface name");
return retval;
}
{
char *pos;
int retval = 0;
dbg("no dev-file found, do nothing");
return 0;
}
}
if (udev->ignore_device) {
dbg("device event will be ignored");
return 0;
}
selinux_init();
if (retval != 0)
goto exit;
if (udev_db_add_device(udev) != 0)
dbg("udev_db_add_dev failed, but we create the node anyway, "
"remove might not work for custom names");
/* use full path to the environment */
/* look if we want to change the name of the netif */
if (retval != 0)
goto exit;
/* we've changed the name, now fake the devpath, cause the
* original kernel name sleeps with the fishes and we don't
* get an event from the kernel with the new name
*/
}
/* use netif name for the environment */
}
}
exit:
selinux_exit();
return retval;
}