chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
volume_id: split raid and filesystem detection
[elogind.git]
/
udev_add.c
diff --git
a/udev_add.c
b/udev_add.c
index bf2d59d1989900c7e05f62d339d7a949233dac56..398dcb58fa0deb08589c8ed66c1bc8bb6c5e25a4 100644
(file)
--- a/
udev_add.c
+++ b/
udev_add.c
@@
-22,23
+22,19
@@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <stddef.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
+#include <grp.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <grp.h>
-#include <net/if.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+#include <net/if.h>
#include <linux/sockios.h>
#include <linux/sockios.h>
-#include "libsysfs/sysfs/libsysfs.h"
-#include "udev_libc_wrapper.h"
#include "udev.h"
#include "udev.h"
-#include "udev_utils.h"
-#include "udev_version.h"
-#include "logging.h"
#include "udev_rules.h"
#include "udev_selinux.h"
#include "udev_rules.h"
#include "udev_selinux.h"
@@
-48,25
+44,18
@@
int udev_make_node(struct udevice *udev, const char *file, dev_t devt, mode_t mo
struct stat stats;
int retval = 0;
struct stat stats;
int retval = 0;
- switch (udev->type) {
- case DEV_BLOCK:
+ if (major(devt) != 0 && strcmp(udev->dev->subsystem, "block") == 0)
mode |= S_IFBLK;
mode |= S_IFBLK;
- break;
- case DEV_CLASS:
+ else
mode |= S_IFCHR;
mode |= S_IFCHR;
- break;
- default:
- dbg("unknown node type %c\n", udev->type);
- return -EINVAL;
- }
if (stat(file, &stats) != 0)
goto create;
if (stat(file, &stats) != 0)
goto create;
- /* preserve node with already correct numbers, to
not change
the inode number */
+ /* preserve node with already correct numbers, to
prevent changing
the inode number */
if ((stats.st_mode & S_IFMT) == (mode & S_IFMT) && (stats.st_rdev == devt)) {
info("preserve file '%s', cause it has correct dev_t", file);
if ((stats.st_mode & S_IFMT) == (mode & S_IFMT) && (stats.st_rdev == devt)) {
info("preserve file '%s', cause it has correct dev_t", file);
- selinux_setfilecon(file, udev->kernel_name, stats.st_mode);
+ selinux_setfilecon(file, udev->
dev->
kernel_name, stats.st_mode);
goto perms;
}
goto perms;
}
@@
-76,7
+65,7
@@
int udev_make_node(struct udevice *udev, const char *file, dev_t devt, mode_t mo
dbg("already present file '%s' unlinked", file);
create:
dbg("already present file '%s' unlinked", file);
create:
- selinux_setfscreatecon(file, udev->kernel_name, mode);
+ selinux_setfscreatecon(file, udev->
dev->
kernel_name, mode);
retval = mknod(file, mode, devt);
selinux_resetfscreatecon();
if (retval != 0) {
retval = mknod(file, mode, devt);
selinux_resetfscreatecon();
if (retval != 0) {
@@
-105,7
+94,7
@@
exit:
return retval;
}
return retval;
}
-static int create_node(struct udevice *udev
, struct sysfs_class_device *class_dev
)
+static int create_node(struct udevice *udev)
{
char filename[PATH_SIZE];
struct name_entry *name_loop;
{
char filename[PATH_SIZE];
struct name_entry *name_loop;
@@
-147,27
+136,25
@@
static int create_node(struct udevice *udev, struct sysfs_class_device *class_de
gid = lookup_group(udev->group);
}
gid = lookup_group(udev->group);
}
- if (!udev->test_run) {
- info("creating device node '%s'", filename);
+ info("creating device node '%s', major = '%d', minor = '%d', " "mode = '%#o', uid = '%d', gid = '%d'",
+ filename, major(udev->devt), minor(udev->devt), udev->mode, uid, gid);
+
+ if (!udev->test_run)
if (udev_make_node(udev, filename, udev->devt, udev->mode, uid, gid) != 0)
goto error;
if (udev_make_node(udev, filename, udev->devt, udev->mode, uid, gid) != 0)
goto error;
- setenv("DEVNAME", filename, 1);
- } else {
- info("creating device node '%s', major = '%d', minor = '%d', "
- "mode = '%#o', uid = '%d', gid = '%d'", filename,
- major(udev->devt), minor(udev->devt), udev->mode, uid, gid);
- }
+
+ setenv("DEVNAME", filename, 1);
/* create all_partitions if requested */
if (udev->partitions) {
char partitionname[PATH_SIZE];
/* create all_partitions if requested */
if (udev->partitions) {
char partitionname[PATH_SIZE];
-
struct sysfs_attribute
*attr;
+
char
*attr;
int range;
/* take the maximum registered minor range */
int range;
/* take the maximum registered minor range */
- attr = sysfs_
get_classdev_attr(class_dev
, "range");
+ attr = sysfs_
attr_get_value(udev->dev->devpath
, "range");
if (attr) {
if (attr) {
- range = atoi(attr
->value
);
+ range = atoi(attr);
if (range > 1)
udev->partitions = range-1;
}
if (range > 1)
udev->partitions = range-1;
}
@@
-247,7
+234,7
@@
static int rename_net_if(struct udevice *udev)
struct ifreq ifr;
int retval;
struct ifreq ifr;
int retval;
- info("changing net interface name from '%s' to '%s'", udev->kernel_name, udev->name);
+ info("changing net interface name from '%s' to '%s'", udev->
dev->
kernel_name, udev->name);
if (udev->test_run)
return 0;
if (udev->test_run)
return 0;
@@
-258,7
+245,7
@@
static int rename_net_if(struct udevice *udev)
}
memset(&ifr, 0x00, sizeof(struct ifreq));
}
memset(&ifr, 0x00, sizeof(struct ifreq));
- strlcpy(ifr.ifr_name, udev->kernel_name, IFNAMSIZ);
+ strlcpy(ifr.ifr_name, udev->
dev->
kernel_name, IFNAMSIZ);
strlcpy(ifr.ifr_newname, udev->name, IFNAMSIZ);
retval = ioctl(sk, SIOCSIFNAME, &ifr);
strlcpy(ifr.ifr_newname, udev->name, IFNAMSIZ);
retval = ioctl(sk, SIOCSIFNAME, &ifr);
@@
-269,7
+256,7
@@
static int rename_net_if(struct udevice *udev)
return retval;
}
return retval;
}
-int udev_add_device(struct udevice *udev
, struct sysfs_class_device *class_dev
)
+int udev_add_device(struct udevice *udev)
{
char *pos;
int retval = 0;
{
char *pos;
int retval = 0;
@@
-277,16
+264,16
@@
int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev)
dbg("adding name='%s'", udev->name);
selinux_init();
dbg("adding name='%s'", udev->name);
selinux_init();
- if (
udev->type == DEV_BLOCK || udev->type == DEV_CLASS
) {
- retval = create_node(udev
, class_dev
);
+ if (
major(udev->devt)
) {
+ retval = create_node(udev);
if (retval != 0)
goto exit;
if (udev_db_add_device(udev) != 0)
dbg("udev_db_add_dev failed, remove might not work for custom names");
if (retval != 0)
goto exit;
if (udev_db_add_device(udev) != 0)
dbg("udev_db_add_dev failed, remove might not work for custom names");
- } else if (
udev->type == DEV_NET
) {
+ } else if (
strcmp(udev->dev->subsystem, "net") == 0
) {
/* look if we want to change the name of the netif */
/* look if we want to change the name of the netif */
- if (strcmp(udev->name, udev->kernel_name) != 0) {
+ if (strcmp(udev->name, udev->
dev->
kernel_name) != 0) {
retval = rename_net_if(udev);
if (retval != 0)
goto exit;
retval = rename_net_if(udev);
if (retval != 0)
goto exit;
@@
-296,12
+283,12
@@
int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev)
* original kernel name sleeps with the fishes and we don't
* get an event from the kernel with the new name
*/
* original kernel name sleeps with the fishes and we don't
* get an event from the kernel with the new name
*/
- pos = strrchr(udev->devpath, '/');
+ pos = strrchr(udev->dev
->dev
path, '/');
if (pos != NULL) {
pos[1] = '\0';
if (pos != NULL) {
pos[1] = '\0';
- strlcat(udev->dev
path, udev->name, sizeof(u
dev->devpath));
- strlcpy(udev->
kernel_name, udev->name, sizeof(u
dev->kernel_name));
- setenv("DEVPATH", udev->devpath, 1);
+ strlcat(udev->dev
->devpath, udev->name, sizeof(udev->
dev->devpath));
+ strlcpy(udev->
dev->kernel_name, udev->name, sizeof(udev->
dev->kernel_name));
+ setenv("DEVPATH", udev->dev
->dev
path, 1);
setenv("INTERFACE", udev->name, 1);
}
}
setenv("INTERFACE", udev->name, 1);
}
}