udev.c revision b1e95455d2683f43f47ea94a7b79af64f0738d36
/*
* udev.c
*
* Userspace devfs
*
* Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
* Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
*
* 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 <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
#include <signal.h>
#include <unistd.h>
#include "libsysfs/sysfs/libsysfs.h"
#include "udev.h"
#include "udev_utils.h"
#include "udev_sysfs.h"
#include "udev_version.h"
#include "namedev.h"
#include "logging.h"
#ifdef LOG
unsigned char logname[LOGNAME_SIZE];
{
if (!udev_log)
return;
}
#endif
/* (for now) true if udevsend is the helper */
static int manage_hotplug_event(void) {
char helper[256];
int fd;
int len;
if (fd < 0)
goto exit;
if (len < 0)
goto exit;
return 1;
exit:
return 0;
}
{
switch (signum) {
case SIGALRM:
exit(1);
case SIGINT:
case SIGTERM:
}
}
{
struct sysfs_class_device *class_dev;
struct sysfs_device *devices_dev;
char path[SYSFS_PATH_MAX];
const char *error;
logging_init("udev");
/* set signal handlers */
/* alarm must not restart syscalls*/
/* trigger timeout to interrupt blocking syscalls */
dbg("udevstart");
/* disable all logging, as it's much too slow on some facilities */
udev_log = 0;
namedev_init();
retval = udev_start();
goto exit;
}
if (!action) {
dbg("no action");
goto hotplug;
}
if (!subsystem) {
dbg("no subsystem");
goto hotplug;
}
if (!devpath) {
dbg("no devpath");
goto hotplug;
}
/* export logging flag, as called scripts may want to do the same as udev */
if (udev_log)
/* wait for sysfs and possibly add node */
dbg("udev add");
/* skip blacklisted subsystems */
goto hotplug;
};
dbg ("open class device failed");
goto hotplug;
}
/* init rules, permissions */
namedev_init();
/* name, create node, store in db */
/* run dev.d/ scripts if we created a node or changed a netif name */
}
/* possibly remove a node */
dbg("udev remove");
/* get node from db, remove db-entry, delete created node */
/* run dev.d/ scripts if we're not instructed to ignore the event */
}
}
/* wait for sysfs */
dbg("devices add");
if (!devices_dev) {
dbg("devices device unavailable (probably remove has beaten us)");
goto hotplug;
}
dbg("devices remove");
}
} else {
dbg("unhandled");
}
if (manage_hotplug_event())
exit:
return retval;
}