udev.c revision 18ebc4305034401648e343b27981ef1badafef1c
/*
* 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;
/* false, if we are called directly */
if (!getenv("MANAGED_EVENT"))
goto exit;
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;
const char *action;
const char *devpath;
const char *subsystem;
exit(0);
}
logging_init("udev");
/* set signal handlers */
/* trigger timeout to prevent hanging processes */
dbg("udevstart");
/* disable all logging, as it's much too slow on some facilities */
udev_log = 0;
namedev_init();
retval = udev_start();
goto exit;
}
/* older kernels passed the SUBSYSTEM only as argument */
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 subsystems without "dev", but handle net devices */
goto hotplug;
}
dbg ("open class device failed");
goto hotplug;
}
/* init rules, permissions */
namedev_init();
/* name, create node, store in db */
/* possibly remove a node */
dbg("udev remove");
/* skip subsystems without "dev" */
goto hotplug;
}
/* get node from db, remove db-entry, delete created node */
}
if (udev_dev_d)
}
/* 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 (udev_hotplug_d && manage_hotplug_event())
exit:
return retval;
}