udev.c revision e5e322bc627a07d29a07e08f7c96bd644a3ae057
/*
* 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_libc_wrapper.h"
#include "udev.h"
#include "udev_utils.h"
#include "udev_sysfs.h"
#include "udev_version.h"
#include "udev_rules.h"
#include "logging.h"
#ifdef USE_LOG
{
if (!udev_log)
return;
}
#endif
/* decide if we should manage the whole hotplug event
*/
static int manage_hotplug_event(void) {
char helper[256];
int fd;
int len;
/* don't handle hotplug.d if we are called directly */
if (!getenv("UDEVD_EVENT"))
return 0;
if (fd < 0)
return 0;
if (len < 0)
return 0;
return 1;
return 0;
}
{
switch (signum) {
case SIGALRM:
exit(1);
case SIGINT:
case SIGTERM:
}
}
{
struct sysfs_class_device *class_dev;
struct sysfs_device *devices_dev;
const char *error;
const char *action;
const char *devpath;
const char *subsystem;
int managed_event;
exit(0);
}
logging_init("udev");
/* set signal handlers */
/* trigger timeout to prevent hanging processes */
/* let the executed programs know if we handle the whole hotplug event */
if (managed_event)
/* older kernels passed the SUBSYSTEM only as argument */
dbg("action, subsystem or devpath missing");
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 */
/* 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 && managed_event)
return retval;
}