1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

[PATCH] add udevtest program to build

Also fix up some other dependancy issues in the Makefile.
Thanks to Olaf Hering <olh@suse.de> for pointing them out.
This commit is contained in:
greg@kroah.com 2004-02-12 20:19:21 -08:00 committed by Greg KH
parent bb051f6657
commit eb10f97f28
5 changed files with 59 additions and 75 deletions

View File

@ -34,6 +34,7 @@ ROOT = udev
DAEMON = udevd
SENDER = udevsend
HELPER = udevinfo
TESTER = udevtest
VERSION = 016_bk
INSTALL_DIR = /usr/local/bin
RELEASE_NAME = $(ROOT)-$(VERSION)
@ -168,7 +169,7 @@ endif
CFLAGS += -I$(PWD)/libsysfs
all: $(ROOT) $(SENDER) $(DAEMON) $(HELPER)
all: $(ROOT) $(SENDER) $(DAEMON) $(HELPER) $(TESTER)
@extras="$(EXTRAS)" ; for target in $$extras ; do \
echo $$target ; \
$(MAKE) prefix=$(prefix) \
@ -178,8 +179,6 @@ all: $(ROOT) $(SENDER) $(DAEMON) $(HELPER)
-C $$target $@ ; \
done ; \
$(ROOT): $(LIBC)
$(ARCH_LIB_OBJS) : $(CRT0)
$(CRT0):
@ -250,21 +249,29 @@ $(LOCAL_CFG_DIR)/udev.conf:
$(OBJS): $(GEN_HEADERS)
udev.o: $(GEN_HEADERS)
$(ROOT).o: $(GEN_HEADERS)
$(TESTER).o: $(GEN_HEADERS)
$(HELPER).o: $(GEN_HEADERS)
$(DAEMON).o: $(GEN_HEADERS)
$(SENDER).o: $(GEN_HEADERS)
$(ROOT): udev.o $(OBJS) $(HEADERS) $(GEN_HEADERS)
$(ROOT): $(ROOT).o $(OBJS) $(HEADERS) $(LIBC)
$(LD) $(LDFLAGS) -o $@ $(CRT0) udev.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
$(STRIPCMD) $@
$(HELPER): $(HEADERS) udevinfo.o $(OBJS)
$(TESTER): $(TESTER).o $(OBJS) $(HEADERS) $(LIBC)
$(LD) $(LDFLAGS) -o $@ $(CRT0) udevtest.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
$(STRIPCMD) $@
$(HELPER): $(HELPER).o $(OBJS) $(HEADERS) $(LIBC)
$(LD) $(LDFLAGS) -o $@ $(CRT0) udevinfo.o udev_config.o udevdb.o $(SYSFS) $(TDB) $(LIB_OBJS) $(ARCH_LIB_OBJS)
$(STRIPCMD) $@
$(DAEMON): udevd.h $(GEN_HEADERS) udevd.o
$(DAEMON): $(DAEMON).o udevd.h $(LIBC)
$(LD) $(LDFLAGS) -o $@ $(CRT0) udevd.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
$(STRIPCMD) $@
$(SENDER): udevd.h $(GEN_HEADERS) udevsend.o
$(SENDER): $(SENDER).o udevd.h $(LIBC)
$(LD) $(LDFLAGS) -o $@ $(CRT0) udevsend.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
$(STRIPCMD) $@

View File

@ -99,7 +99,7 @@ static int create_path(char *file)
return 0;
}
static int create_node(struct udevice *dev)
static int create_node(struct udevice *dev, int fake)
{
struct stat stats;
char filename[255];
@ -137,16 +137,20 @@ static int create_node(struct udevice *dev)
info("creating device node '%s'", filename);
dbg("mknod(%s, %#o, %u, %u)", filename, dev->mode, dev->major, dev->minor);
retval = mknod(filename, dev->mode, makedev(dev->major, dev->minor));
if (retval != 0)
dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",
filename, dev->mode, dev->major, dev->minor, strerror(errno));
if (!fake) {
retval = mknod(filename, dev->mode, makedev(dev->major, dev->minor));
if (retval != 0)
dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",
filename, dev->mode, dev->major, dev->minor, strerror(errno));
}
dbg("chmod(%s, %#o)", filename, dev->mode);
retval = chmod(filename, dev->mode);
if (retval != 0)
dbg("chmod(%s, %#o) failed with error '%s'",
filename, dev->mode, strerror(errno));
if (!fake) {
retval = chmod(filename, dev->mode);
if (retval != 0)
dbg("chmod(%s, %#o) failed with error '%s'",
filename, dev->mode, strerror(errno));
}
if (dev->owner[0] != '\0') {
char *endptr;
@ -195,8 +199,9 @@ static int create_node(struct udevice *dev)
strncpy(filename, udev_root, sizeof(filename));
strncat(filename, linkname, sizeof(filename));
dbg("symlink '%s' to node '%s' requested", filename, dev->name);
if (strrchr(linkname, '/'))
create_path(filename);
if (!fake)
if (strrchr(linkname, '/'))
create_path(filename);
/* optimize relative link */
linktarget[0] = '\0';
@ -219,7 +224,7 @@ static int create_node(struct udevice *dev)
/* unlink existing non-directories to ensure that our symlink
* is created */
if (lstat(filename, &stats) == 0) {
if (!fake && (lstat(filename, &stats) == 0)) {
if ((stats.st_mode & S_IFMT) != S_IFDIR) {
if (unlink(filename))
dbg("unlink(%s) failed with error '%s'",
@ -228,10 +233,12 @@ static int create_node(struct udevice *dev)
}
dbg("symlink(%s, %s)", linktarget, filename);
retval = symlink(linktarget, filename);
if (retval != 0)
dbg("symlink(%s, %s) failed with error '%s'",
linktarget, filename, strerror(errno));
if (!fake) {
retval = symlink(linktarget, filename);
if (retval != 0)
dbg("symlink(%s, %s) failed with error '%s'",
linktarget, filename, strerror(errno));
}
}
}
@ -289,7 +296,7 @@ exit:
return retval;
}
int udev_add_device(char *path, char *subsystem)
int udev_add_device(char *path, char *subsystem, int fake)
{
struct sysfs_class_device *class_dev = NULL;
struct udevice dev;
@ -321,15 +328,18 @@ int udev_add_device(char *path, char *subsystem)
if (retval != 0)
goto exit;
retval = udevdb_add_dev(path, &dev);
if (retval != 0)
dbg("udevdb_add_dev failed, but we are going to try to create the node anyway. "
"But remove might not work properly for this device.");
if (!fake) {
retval = udevdb_add_dev(path, &dev);
if (retval != 0)
dbg("udevdb_add_dev failed, but we are going to try "
"to create the node anyway. But remove might not "
"work properly for this device.");
}
dbg("name='%s'", dev.name);
retval = create_node(&dev);
retval = create_node(&dev, fake);
if (retval == 0)
if ((retval == 0) && (!fake))
sysbus_send_create(&dev, path);
exit:

2
udev.c
View File

@ -164,7 +164,7 @@ static int udev_hotplug(int argc, char **argv)
namedev_init();
if (strcmp(action, "add") == 0)
retval = udev_add_device(devpath, subsystem);
retval = udev_add_device(devpath, subsystem, 0);
else if (strcmp(action, "remove") == 0)
retval = udev_remove_device(devpath, subsystem);

2
udev.h
View File

@ -56,7 +56,7 @@ do { \
strncpy(to, from, sizeof(to)-1); \
} while (0)
extern int udev_add_device(char *path, char *subsystem);
extern int udev_add_device(char *path, char *subsystem, int fake);
extern int udev_remove_device(char *path, char *subsystem);
extern void udev_init_config(void);
extern int parse_get_pair(char **orig_string, char **left, char **right);

View File

@ -29,10 +29,8 @@
#include "udev.h"
#include "udev_version.h"
#include "udev_dbus.h"
#include "logging.h"
#include "namedev.h"
#include "udevdb.h"
#include "libsysfs/libsysfs.h"
/* global variables */
@ -45,12 +43,15 @@ void log_message (int level, const char *format, ...)
{
va_list args;
if (!udev_log)
return;
// if (!udev_log)
// return;
/* FIXME use level... */
va_start(args, format);
vsyslog(level, format, args);
vprintf(format, args);
va_end(args);
if (format[strlen(format)-1] != '\n')
printf("\n");
}
#endif
@ -59,8 +60,6 @@ static void sig_handler(int signum)
switch (signum) {
case SIGINT:
case SIGTERM:
sysbus_disconnect();
udevdb_exit();
exit(20 + signum);
default:
dbg("unhandled signal");
@ -102,22 +101,15 @@ static char *subsystem_blacklist[] = {
static int udev_hotplug(int argc, char **argv)
{
char *action;
char *devpath;
char *subsystem;
int retval = -EINVAL;
int i;
struct sigaction act;
action = get_action();
if (!action) {
dbg ("no action?");
goto exit;
}
devpath = get_devpath();
devpath = argv[1];
if (!devpath) {
dbg ("no devpath?");
dbg("no devpath?");
goto exit;
}
dbg("looking at '%s'", devpath);
@ -140,19 +132,9 @@ static int udev_hotplug(int argc, char **argv)
i++;
}
/* connect to the system message bus */
sysbus_connect();
/* initialize our configuration */
udev_init_config();
/* initialize udev database */
retval = udevdb_init(UDEVDB_DEFAULT);
if (retval != 0) {
dbg("unable to initialize database");
goto exit_sysbus;
}
/* set up a default signal handler for now */
act.sa_handler = sig_handler;
sigemptyset (&act.sa_mask);
@ -163,21 +145,7 @@ static int udev_hotplug(int argc, char **argv)
/* initialize the naming deamon */
namedev_init();
if (strcmp(action, "add") == 0)
retval = udev_add_device(devpath, subsystem);
else if (strcmp(action, "remove") == 0)
retval = udev_remove_device(devpath, subsystem);
else {
dbg("unknown action '%s'", action);
retval = -EINVAL;
}
udevdb_exit();
exit_sysbus:
/* disconnect from the system message bus */
sysbus_disconnect();
retval = udev_add_device(devpath, subsystem, 1);
exit:
if (retval > 0)
@ -191,7 +159,6 @@ int main(int argc, char **argv, char **envp)
main_argv = argv;
main_envp = envp;
init_logging("udev");
dbg("version %s", UDEV_VERSION);
return udev_hotplug(argc, argv);