2005-04-27 10:59:47 +07:00
|
|
|
/*
|
|
|
|
* udev.c
|
|
|
|
*
|
|
|
|
* Userspace devfs
|
|
|
|
*
|
2004-01-27 10:23:11 +07:00
|
|
|
* Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
|
2004-11-23 13:34:56 +07:00
|
|
|
* Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
|
2005-04-27 10:59:47 +07:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-03-23 13:22:20 +07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stddef.h>
|
2005-04-27 10:59:47 +07:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2004-11-23 13:34:56 +07:00
|
|
|
#include <fcntl.h>
|
2003-12-03 16:08:46 +07:00
|
|
|
#include <ctype.h>
|
2004-03-23 13:22:20 +07:00
|
|
|
#include <errno.h>
|
2003-12-30 16:21:06 +07:00
|
|
|
#include <signal.h>
|
2004-10-19 13:14:20 +07:00
|
|
|
#include <unistd.h>
|
2003-04-11 00:53:46 +07:00
|
|
|
|
2004-02-24 10:07:25 +07:00
|
|
|
#include "libsysfs/sysfs/libsysfs.h"
|
2005-04-27 10:59:47 +07:00
|
|
|
#include "udev.h"
|
2004-03-23 13:22:20 +07:00
|
|
|
#include "udev_lib.h"
|
2004-10-19 18:37:22 +07:00
|
|
|
#include "udev_sysfs.h"
|
2005-04-27 10:59:47 +07:00
|
|
|
#include "udev_version.h"
|
2003-07-17 15:24:51 +07:00
|
|
|
#include "namedev.h"
|
2004-11-12 12:32:19 +07:00
|
|
|
#include "logging.h"
|
2005-04-27 10:59:47 +07:00
|
|
|
|
2004-10-14 13:13:26 +07:00
|
|
|
|
2004-02-13 09:57:06 +07:00
|
|
|
#ifdef LOG
|
2004-03-04 15:57:29 +07:00
|
|
|
unsigned char logname[LOGNAME_SIZE];
|
2004-02-27 10:40:40 +07:00
|
|
|
void log_message(int level, const char *format, ...)
|
2004-02-12 13:10:26 +07:00
|
|
|
{
|
2004-02-27 10:40:32 +07:00
|
|
|
va_list args;
|
2004-02-13 09:57:06 +07:00
|
|
|
|
|
|
|
if (!udev_log)
|
|
|
|
return;
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
vsyslog(level, format, args);
|
|
|
|
va_end(args);
|
2004-02-12 13:10:26 +07:00
|
|
|
}
|
2004-02-13 09:57:06 +07:00
|
|
|
#endif
|
2004-02-12 13:10:26 +07:00
|
|
|
|
2004-10-14 12:38:15 +07:00
|
|
|
static void asmlinkage sig_handler(int signum)
|
2003-12-30 16:21:06 +07:00
|
|
|
{
|
|
|
|
switch (signum) {
|
2004-10-14 13:13:26 +07:00
|
|
|
case SIGALRM:
|
2004-11-06 20:28:01 +07:00
|
|
|
exit(1);
|
2003-12-30 16:21:06 +07:00
|
|
|
case SIGINT:
|
|
|
|
case SIGTERM:
|
|
|
|
exit(20 + signum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[PATCH] Fix naming ethernet devices in udevstart
On Tue, Sep 07, 2004 at 12:46:43PM +0200, Kay Sievers wrote:
> On Mon, 2004-09-06 at 20:18 -0700, Tom Rini wrote:
> > I noticed somewhat recently that my enet devices weren't being renamed
> > on boot anymore. I don't quite know when this got broken (or rather, if
> > it was supposed to be working. I swear it worked for me once..), but
> > the following seems to do it.
>
> I think it never worked in the udevstart case. It worked only with the
> hotplug-event-udev, I expect.
>
> > In udev_scan_class(), look for not just
> > %s/%s/dev (which everything with a dev node has), but %s/%s/dev* (both
> > of my enet devices, sis900 & 3c59x only have device) and if that
> > exists, pass this along to udev.
>
> Yeah, network devices don't have a devnode and therefore no "dev", but
> they are all in /sys/class/net/. We may just test if we are there
> instead of the "device" match.
How about something like this. It adds all the net devices without
looking at the attributes and keeps the remaining logic like it is.
It also removes certain levels of indirection and much simplifies the
udevstart process. We surely don't need to open and close the udevdb
for every node while iterating over the list. (We are about 5% faster on
my box)
It's not well tested, so it would be nice if someone can have a look
at it, before a broken udevstart renders any system unbootable.
2004-09-11 11:09:25 +07:00
|
|
|
int main(int argc, char *argv[], char *envp[])
|
2003-12-31 13:31:37 +07:00
|
|
|
{
|
2004-02-12 13:29:15 +07:00
|
|
|
struct sigaction act;
|
2004-10-19 09:11:51 +07:00
|
|
|
struct sysfs_class_device *class_dev;
|
2004-11-23 13:34:56 +07:00
|
|
|
struct sysfs_device *devices_dev;
|
2004-10-19 09:11:51 +07:00
|
|
|
struct udevice udev;
|
|
|
|
char path[SYSFS_PATH_MAX];
|
[PATCH] Fix naming ethernet devices in udevstart
On Tue, Sep 07, 2004 at 12:46:43PM +0200, Kay Sievers wrote:
> On Mon, 2004-09-06 at 20:18 -0700, Tom Rini wrote:
> > I noticed somewhat recently that my enet devices weren't being renamed
> > on boot anymore. I don't quite know when this got broken (or rather, if
> > it was supposed to be working. I swear it worked for me once..), but
> > the following seems to do it.
>
> I think it never worked in the udevstart case. It worked only with the
> hotplug-event-udev, I expect.
>
> > In udev_scan_class(), look for not just
> > %s/%s/dev (which everything with a dev node has), but %s/%s/dev* (both
> > of my enet devices, sis900 & 3c59x only have device) and if that
> > exists, pass this along to udev.
>
> Yeah, network devices don't have a devnode and therefore no "dev", but
> they are all in /sys/class/net/. We may just test if we are there
> instead of the "device" match.
How about something like this. It adds all the net devices without
looking at the attributes and keeps the remaining logic like it is.
It also removes certain levels of indirection and much simplifies the
udevstart process. We surely don't need to open and close the udevdb
for every node while iterating over the list. (We are about 5% faster on
my box)
It's not well tested, so it would be nice if someone can have a look
at it, before a broken udevstart renders any system unbootable.
2004-09-11 11:09:25 +07:00
|
|
|
int retval = -EINVAL;
|
2004-11-23 13:34:56 +07:00
|
|
|
const char *error;
|
|
|
|
const char *action = getenv("ACTION");
|
|
|
|
const char *devpath = getenv("DEVPATH");
|
|
|
|
const char *subsystem = argv[1];
|
2003-12-31 13:31:37 +07:00
|
|
|
|
[PATCH] Fix naming ethernet devices in udevstart
On Tue, Sep 07, 2004 at 12:46:43PM +0200, Kay Sievers wrote:
> On Mon, 2004-09-06 at 20:18 -0700, Tom Rini wrote:
> > I noticed somewhat recently that my enet devices weren't being renamed
> > on boot anymore. I don't quite know when this got broken (or rather, if
> > it was supposed to be working. I swear it worked for me once..), but
> > the following seems to do it.
>
> I think it never worked in the udevstart case. It worked only with the
> hotplug-event-udev, I expect.
>
> > In udev_scan_class(), look for not just
> > %s/%s/dev (which everything with a dev node has), but %s/%s/dev* (both
> > of my enet devices, sis900 & 3c59x only have device) and if that
> > exists, pass this along to udev.
>
> Yeah, network devices don't have a devnode and therefore no "dev", but
> they are all in /sys/class/net/. We may just test if we are there
> instead of the "device" match.
How about something like this. It adds all the net devices without
looking at the attributes and keeps the remaining logic like it is.
It also removes certain levels of indirection and much simplifies the
udevstart process. We surely don't need to open and close the udevdb
for every node while iterating over the list. (We are about 5% faster on
my box)
It's not well tested, so it would be nice if someone can have a look
at it, before a broken udevstart renders any system unbootable.
2004-09-11 11:09:25 +07:00
|
|
|
dbg("version %s", UDEV_VERSION);
|
2004-10-19 08:15:10 +07:00
|
|
|
logging_init("udev");
|
[PATCH] Fix naming ethernet devices in udevstart
On Tue, Sep 07, 2004 at 12:46:43PM +0200, Kay Sievers wrote:
> On Mon, 2004-09-06 at 20:18 -0700, Tom Rini wrote:
> > I noticed somewhat recently that my enet devices weren't being renamed
> > on boot anymore. I don't quite know when this got broken (or rather, if
> > it was supposed to be working. I swear it worked for me once..), but
> > the following seems to do it.
>
> I think it never worked in the udevstart case. It worked only with the
> hotplug-event-udev, I expect.
>
> > In udev_scan_class(), look for not just
> > %s/%s/dev (which everything with a dev node has), but %s/%s/dev* (both
> > of my enet devices, sis900 & 3c59x only have device) and if that
> > exists, pass this along to udev.
>
> Yeah, network devices don't have a devnode and therefore no "dev", but
> they are all in /sys/class/net/. We may just test if we are there
> instead of the "device" match.
How about something like this. It adds all the net devices without
looking at the attributes and keeps the remaining logic like it is.
It also removes certain levels of indirection and much simplifies the
udevstart process. We surely don't need to open and close the udevdb
for every node while iterating over the list. (We are about 5% faster on
my box)
It's not well tested, so it would be nice if someone can have a look
at it, before a broken udevstart renders any system unbootable.
2004-09-11 11:09:25 +07:00
|
|
|
udev_init_config();
|
2003-07-17 10:18:06 +07:00
|
|
|
|
2004-06-07 16:56:47 +07:00
|
|
|
/* set signal handlers */
|
2004-10-14 12:37:59 +07:00
|
|
|
act.sa_handler = (void (*) (int))sig_handler;
|
2004-02-12 13:29:15 +07:00
|
|
|
sigemptyset (&act.sa_mask);
|
2004-11-05 19:16:32 +07:00
|
|
|
act.sa_flags = 0;
|
2004-10-15 10:36:07 +07:00
|
|
|
/* alarm must not restart syscalls*/
|
2004-10-14 13:13:26 +07:00
|
|
|
sigaction(SIGALRM, &act, NULL);
|
2004-02-12 13:29:15 +07:00
|
|
|
sigaction(SIGINT, &act, NULL);
|
|
|
|
sigaction(SIGTERM, &act, NULL);
|
2003-12-30 16:29:16 +07:00
|
|
|
|
2004-11-23 13:34:56 +07:00
|
|
|
/* trigger timeout to interrupt blocking syscalls */
|
2004-10-14 13:13:26 +07:00
|
|
|
alarm(ALARM_TIMEOUT);
|
|
|
|
|
2004-11-23 13:34:56 +07:00
|
|
|
udev_set_values(&udev, devpath, subsystem, action);
|
|
|
|
|
|
|
|
if (strstr(argv[0], "udevstart") || (argv[1] != NULL && strstr(argv[1], "udevstart"))) {
|
[PATCH] Fix naming ethernet devices in udevstart
On Tue, Sep 07, 2004 at 12:46:43PM +0200, Kay Sievers wrote:
> On Mon, 2004-09-06 at 20:18 -0700, Tom Rini wrote:
> > I noticed somewhat recently that my enet devices weren't being renamed
> > on boot anymore. I don't quite know when this got broken (or rather, if
> > it was supposed to be working. I swear it worked for me once..), but
> > the following seems to do it.
>
> I think it never worked in the udevstart case. It worked only with the
> hotplug-event-udev, I expect.
>
> > In udev_scan_class(), look for not just
> > %s/%s/dev (which everything with a dev node has), but %s/%s/dev* (both
> > of my enet devices, sis900 & 3c59x only have device) and if that
> > exists, pass this along to udev.
>
> Yeah, network devices don't have a devnode and therefore no "dev", but
> they are all in /sys/class/net/. We may just test if we are there
> instead of the "device" match.
How about something like this. It adds all the net devices without
looking at the attributes and keeps the remaining logic like it is.
It also removes certain levels of indirection and much simplifies the
udevstart process. We surely don't need to open and close the udevdb
for every node while iterating over the list. (We are about 5% faster on
my box)
It's not well tested, so it would be nice if someone can have a look
at it, before a broken udevstart renders any system unbootable.
2004-09-11 11:09:25 +07:00
|
|
|
dbg("udevstart");
|
2004-11-23 10:47:06 +07:00
|
|
|
|
2004-11-23 13:34:56 +07:00
|
|
|
/* disable all logging, as it's much too slow on some facilities */
|
2004-11-13 20:51:10 +07:00
|
|
|
udev_log = 0;
|
2004-11-23 10:47:06 +07:00
|
|
|
|
[PATCH] Fix naming ethernet devices in udevstart
On Tue, Sep 07, 2004 at 12:46:43PM +0200, Kay Sievers wrote:
> On Mon, 2004-09-06 at 20:18 -0700, Tom Rini wrote:
> > I noticed somewhat recently that my enet devices weren't being renamed
> > on boot anymore. I don't quite know when this got broken (or rather, if
> > it was supposed to be working. I swear it worked for me once..), but
> > the following seems to do it.
>
> I think it never worked in the udevstart case. It worked only with the
> hotplug-event-udev, I expect.
>
> > In udev_scan_class(), look for not just
> > %s/%s/dev (which everything with a dev node has), but %s/%s/dev* (both
> > of my enet devices, sis900 & 3c59x only have device) and if that
> > exists, pass this along to udev.
>
> Yeah, network devices don't have a devnode and therefore no "dev", but
> they are all in /sys/class/net/. We may just test if we are there
> instead of the "device" match.
How about something like this. It adds all the net devices without
looking at the attributes and keeps the remaining logic like it is.
It also removes certain levels of indirection and much simplifies the
udevstart process. We surely don't need to open and close the udevdb
for every node while iterating over the list. (We are about 5% faster on
my box)
It's not well tested, so it would be nice if someone can have a look
at it, before a broken udevstart renders any system unbootable.
2004-09-11 11:09:25 +07:00
|
|
|
namedev_init();
|
|
|
|
retval = udev_start();
|
2004-11-23 13:34:56 +07:00
|
|
|
goto exit;
|
|
|
|
}
|
2004-10-19 09:11:51 +07:00
|
|
|
|
2004-11-23 13:34:56 +07:00
|
|
|
if (!action) {
|
|
|
|
dbg("no action");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!subsystem) {
|
|
|
|
dbg("no subsystem");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!devpath) {
|
|
|
|
dbg("no devpath");
|
|
|
|
goto exit;
|
|
|
|
}
|
2004-10-19 18:37:22 +07:00
|
|
|
|
2004-11-23 13:34:56 +07:00
|
|
|
/* export logging flag, called scripts may want to do the same as udev */
|
|
|
|
if (udev_log)
|
|
|
|
setenv("UDEV_LOG", "1", 1);
|
|
|
|
|
|
|
|
if ((strncmp(devpath, "/block/", 7) == 0) || (strncmp(devpath, "/class/", 7) == 0)) {
|
|
|
|
if (strcmp(action, "add") == 0) {
|
|
|
|
/* wait for sysfs and possibly add node */
|
|
|
|
dbg("udev add");
|
|
|
|
|
|
|
|
/* skip blacklisted subsystems */
|
|
|
|
if (udev.type != 'n' && subsystem_expect_no_dev(udev.subsystem)) {
|
|
|
|
dbg("don't care about '%s' devices", udev.subsystem);
|
|
|
|
goto exit;
|
|
|
|
};
|
|
|
|
|
|
|
|
snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, udev.devpath);
|
|
|
|
class_dev = wait_class_device_open(path);
|
|
|
|
if (class_dev == NULL) {
|
|
|
|
dbg ("open class device failed");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
dbg("opened class_dev->name='%s'", class_dev->name);
|
|
|
|
|
|
|
|
wait_for_class_device(class_dev, &error);
|
|
|
|
|
|
|
|
/* init rules, permissions */
|
|
|
|
namedev_init();
|
|
|
|
|
|
|
|
/* name, create node, store in db */
|
|
|
|
retval = udev_add_device(&udev, class_dev);
|
|
|
|
|
|
|
|
/* run dev.d/ scripts if we created a node or changed a netif name */
|
|
|
|
if (udev.devname[0] != '\0') {
|
|
|
|
setenv("DEVNAME", udev.devname, 1);
|
|
|
|
dev_d_execute(&udev, DEVD_DIR, DEVD_SUFFIX);
|
|
|
|
}
|
|
|
|
|
|
|
|
sysfs_close_class_device(class_dev);
|
|
|
|
} else if (strcmp(action, "remove") == 0) {
|
|
|
|
/* possibly remove a node */
|
|
|
|
dbg("udev remove");
|
|
|
|
|
|
|
|
/* get node from db, delete it */
|
|
|
|
retval = udev_remove_device(&udev);
|
|
|
|
|
|
|
|
/* run dev.d/ scripts if we're not instructed to ignore the event */
|
|
|
|
if (udev.devname[0] != '\0') {
|
|
|
|
setenv("DEVNAME", udev.devname, 1);
|
|
|
|
dev_d_execute(&udev, DEVD_DIR, DEVD_SUFFIX);
|
|
|
|
}
|
2004-10-19 09:28:39 +07:00
|
|
|
|
2004-11-12 12:21:16 +07:00
|
|
|
}
|
2004-11-23 13:34:56 +07:00
|
|
|
} else if ((strncmp(devpath, "/devices/", 9) == 0)) {
|
|
|
|
if (strcmp(action, "add") == 0) {
|
|
|
|
/* wait for sysfs */
|
|
|
|
dbg("devices add");
|
2004-10-19 09:28:39 +07:00
|
|
|
|
2004-11-23 13:34:56 +07:00
|
|
|
snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, devpath);
|
|
|
|
devices_dev = wait_devices_device_open(path);
|
|
|
|
if (!devices_dev) {
|
|
|
|
dbg("devices device unavailable (probably remove has beaten us)");
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
dbg("devices device opened '%s'", path);
|
2004-10-19 09:28:39 +07:00
|
|
|
|
2004-11-23 13:34:56 +07:00
|
|
|
wait_for_devices_device(devices_dev, &error);
|
2004-10-19 09:28:39 +07:00
|
|
|
|
2004-11-23 13:34:56 +07:00
|
|
|
sysfs_close_device(devices_dev);
|
|
|
|
} else if (strcmp(action, "remove") == 0) {
|
|
|
|
dbg("devices remove");
|
2004-11-23 11:05:37 +07:00
|
|
|
}
|
2004-11-23 13:34:56 +07:00
|
|
|
} else {
|
|
|
|
dbg("unhandled");
|
2003-10-15 13:20:53 +07:00
|
|
|
}
|
2004-03-24 09:54:34 +07:00
|
|
|
|
2003-12-09 00:40:40 +07:00
|
|
|
exit:
|
2004-10-19 08:15:10 +07:00
|
|
|
logging_close();
|
[PATCH] hmm, handle net devices with udev?
Hmm, Arndt Bergmann sent a patch like this one a few weeks ago and
I want to bring the question back, if we want to handle net device
naming with udev.
With this patch it is actually possible to specify something like this
in udev.rules:
KERNEL="dummy*", SYSFS{address}="00:00:00:00:00:00", SYSFS{features}="0x0", NAME="blind%n"
KERNEL="eth*", SYSFS{address}="00:0d:60:77:30:91", NAME="private"
and you will get:
[root@pim udev.kay]# cat /proc/net/dev
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 1500 30 0 0 0 0 0 0 1500 30 0 0 0 0 0 0
private: 278393 1114 0 0 0 0 0 0 153204 1468 0 0 0 0 0 0
sit0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
blind0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The udevinfo program is also working:
[root@pim udev.kay]# ./udevinfo -a -p /sys/class/net/private
looking at class device '/sys/class/net/private':
SYSFS{addr_len}="6"
SYSFS{address}="00:0d:60:77:30:91"
SYSFS{broadcast}="ff:ff:ff:ff:ff:ff"
SYSFS{features}="0x3a9"
SYSFS{flags}="0x1003"
SYSFS{ifindex}="2"
SYSFS{iflink}="2"
SYSFS{mtu}="1500"
SYSFS{tx_queue_len}="1000"
SYSFS{type}="1"
follow the class device's "device"
looking at the device chain at '/sys/devices/pci0000:00/0000:00:1e.0/0000:02:01.0':
BUS="pci"
ID="0000:02:01.0"
SYSFS{class}="0x020000"
SYSFS{detach_state}="0"
SYSFS{device}="0x101e"
SYSFS{irq}="11"
SYSFS{subsystem_device}="0x0549"
SYSFS{subsystem_vendor}="0x1014"
SYSFS{vendor}="0x8086"
The matching device will be renamed to the given name. The device name
will not be put into the udev database, cause the kernel renames the
device and the sysfs name disappears.
I like it, cause it plugs in nicely. We have all the naming features
and sysfs queries and walks inside of udev. The sysfs timing races
are already solved and the management tools are working for net devices
too. nameif can only match the MAC address now. udev can match any sysfs
value of the device tree the net device is connected to.
But right, net devices do not have device nodes :)
2004-03-25 14:19:39 +07:00
|
|
|
return retval;
|
2005-04-27 10:59:47 +07:00
|
|
|
}
|