[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:
parent
bb051f6657
commit
eb10f97f28
23
Makefile
23
Makefile
|
@ -34,6 +34,7 @@ ROOT = udev
|
||||||
DAEMON = udevd
|
DAEMON = udevd
|
||||||
SENDER = udevsend
|
SENDER = udevsend
|
||||||
HELPER = udevinfo
|
HELPER = udevinfo
|
||||||
|
TESTER = udevtest
|
||||||
VERSION = 016_bk
|
VERSION = 016_bk
|
||||||
INSTALL_DIR = /usr/local/bin
|
INSTALL_DIR = /usr/local/bin
|
||||||
RELEASE_NAME = $(ROOT)-$(VERSION)
|
RELEASE_NAME = $(ROOT)-$(VERSION)
|
||||||
|
@ -168,7 +169,7 @@ endif
|
||||||
|
|
||||||
CFLAGS += -I$(PWD)/libsysfs
|
CFLAGS += -I$(PWD)/libsysfs
|
||||||
|
|
||||||
all: $(ROOT) $(SENDER) $(DAEMON) $(HELPER)
|
all: $(ROOT) $(SENDER) $(DAEMON) $(HELPER) $(TESTER)
|
||||||
@extras="$(EXTRAS)" ; for target in $$extras ; do \
|
@extras="$(EXTRAS)" ; for target in $$extras ; do \
|
||||||
echo $$target ; \
|
echo $$target ; \
|
||||||
$(MAKE) prefix=$(prefix) \
|
$(MAKE) prefix=$(prefix) \
|
||||||
|
@ -178,8 +179,6 @@ all: $(ROOT) $(SENDER) $(DAEMON) $(HELPER)
|
||||||
-C $$target $@ ; \
|
-C $$target $@ ; \
|
||||||
done ; \
|
done ; \
|
||||||
|
|
||||||
$(ROOT): $(LIBC)
|
|
||||||
|
|
||||||
$(ARCH_LIB_OBJS) : $(CRT0)
|
$(ARCH_LIB_OBJS) : $(CRT0)
|
||||||
|
|
||||||
$(CRT0):
|
$(CRT0):
|
||||||
|
@ -250,21 +249,29 @@ $(LOCAL_CFG_DIR)/udev.conf:
|
||||||
|
|
||||||
|
|
||||||
$(OBJS): $(GEN_HEADERS)
|
$(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)
|
$(LD) $(LDFLAGS) -o $@ $(CRT0) udev.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
|
||||||
$(STRIPCMD) $@
|
$(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)
|
$(LD) $(LDFLAGS) -o $@ $(CRT0) udevinfo.o udev_config.o udevdb.o $(SYSFS) $(TDB) $(LIB_OBJS) $(ARCH_LIB_OBJS)
|
||||||
$(STRIPCMD) $@
|
$(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)
|
$(LD) $(LDFLAGS) -o $@ $(CRT0) udevd.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
|
||||||
$(STRIPCMD) $@
|
$(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)
|
$(LD) $(LDFLAGS) -o $@ $(CRT0) udevsend.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
|
||||||
$(STRIPCMD) $@
|
$(STRIPCMD) $@
|
||||||
|
|
||||||
|
|
56
udev-add.c
56
udev-add.c
|
@ -99,7 +99,7 @@ static int create_path(char *file)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int create_node(struct udevice *dev)
|
static int create_node(struct udevice *dev, int fake)
|
||||||
{
|
{
|
||||||
struct stat stats;
|
struct stat stats;
|
||||||
char filename[255];
|
char filename[255];
|
||||||
|
@ -137,16 +137,20 @@ static int create_node(struct udevice *dev)
|
||||||
|
|
||||||
info("creating device node '%s'", filename);
|
info("creating device node '%s'", filename);
|
||||||
dbg("mknod(%s, %#o, %u, %u)", filename, dev->mode, dev->major, dev->minor);
|
dbg("mknod(%s, %#o, %u, %u)", filename, dev->mode, dev->major, dev->minor);
|
||||||
retval = mknod(filename, dev->mode, makedev(dev->major, dev->minor));
|
if (!fake) {
|
||||||
if (retval != 0)
|
retval = mknod(filename, dev->mode, makedev(dev->major, dev->minor));
|
||||||
dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",
|
if (retval != 0)
|
||||||
filename, dev->mode, dev->major, dev->minor, strerror(errno));
|
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);
|
dbg("chmod(%s, %#o)", filename, dev->mode);
|
||||||
retval = chmod(filename, dev->mode);
|
if (!fake) {
|
||||||
if (retval != 0)
|
retval = chmod(filename, dev->mode);
|
||||||
dbg("chmod(%s, %#o) failed with error '%s'",
|
if (retval != 0)
|
||||||
filename, dev->mode, strerror(errno));
|
dbg("chmod(%s, %#o) failed with error '%s'",
|
||||||
|
filename, dev->mode, strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
if (dev->owner[0] != '\0') {
|
if (dev->owner[0] != '\0') {
|
||||||
char *endptr;
|
char *endptr;
|
||||||
|
@ -195,8 +199,9 @@ static int create_node(struct udevice *dev)
|
||||||
strncpy(filename, udev_root, sizeof(filename));
|
strncpy(filename, udev_root, sizeof(filename));
|
||||||
strncat(filename, linkname, sizeof(filename));
|
strncat(filename, linkname, sizeof(filename));
|
||||||
dbg("symlink '%s' to node '%s' requested", filename, dev->name);
|
dbg("symlink '%s' to node '%s' requested", filename, dev->name);
|
||||||
if (strrchr(linkname, '/'))
|
if (!fake)
|
||||||
create_path(filename);
|
if (strrchr(linkname, '/'))
|
||||||
|
create_path(filename);
|
||||||
|
|
||||||
/* optimize relative link */
|
/* optimize relative link */
|
||||||
linktarget[0] = '\0';
|
linktarget[0] = '\0';
|
||||||
|
@ -219,7 +224,7 @@ static int create_node(struct udevice *dev)
|
||||||
|
|
||||||
/* unlink existing non-directories to ensure that our symlink
|
/* unlink existing non-directories to ensure that our symlink
|
||||||
* is created */
|
* is created */
|
||||||
if (lstat(filename, &stats) == 0) {
|
if (!fake && (lstat(filename, &stats) == 0)) {
|
||||||
if ((stats.st_mode & S_IFMT) != S_IFDIR) {
|
if ((stats.st_mode & S_IFMT) != S_IFDIR) {
|
||||||
if (unlink(filename))
|
if (unlink(filename))
|
||||||
dbg("unlink(%s) failed with error '%s'",
|
dbg("unlink(%s) failed with error '%s'",
|
||||||
|
@ -228,10 +233,12 @@ static int create_node(struct udevice *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
dbg("symlink(%s, %s)", linktarget, filename);
|
dbg("symlink(%s, %s)", linktarget, filename);
|
||||||
retval = symlink(linktarget, filename);
|
if (!fake) {
|
||||||
if (retval != 0)
|
retval = symlink(linktarget, filename);
|
||||||
dbg("symlink(%s, %s) failed with error '%s'",
|
if (retval != 0)
|
||||||
linktarget, filename, strerror(errno));
|
dbg("symlink(%s, %s) failed with error '%s'",
|
||||||
|
linktarget, filename, strerror(errno));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +296,7 @@ exit:
|
||||||
return retval;
|
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 sysfs_class_device *class_dev = NULL;
|
||||||
struct udevice dev;
|
struct udevice dev;
|
||||||
|
@ -321,15 +328,18 @@ int udev_add_device(char *path, char *subsystem)
|
||||||
if (retval != 0)
|
if (retval != 0)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
retval = udevdb_add_dev(path, &dev);
|
if (!fake) {
|
||||||
if (retval != 0)
|
retval = udevdb_add_dev(path, &dev);
|
||||||
dbg("udevdb_add_dev failed, but we are going to try to create the node anyway. "
|
if (retval != 0)
|
||||||
"But remove might not work properly for this device.");
|
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);
|
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);
|
sysbus_send_create(&dev, path);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|
2
udev.c
2
udev.c
|
@ -164,7 +164,7 @@ static int udev_hotplug(int argc, char **argv)
|
||||||
namedev_init();
|
namedev_init();
|
||||||
|
|
||||||
if (strcmp(action, "add") == 0)
|
if (strcmp(action, "add") == 0)
|
||||||
retval = udev_add_device(devpath, subsystem);
|
retval = udev_add_device(devpath, subsystem, 0);
|
||||||
|
|
||||||
else if (strcmp(action, "remove") == 0)
|
else if (strcmp(action, "remove") == 0)
|
||||||
retval = udev_remove_device(devpath, subsystem);
|
retval = udev_remove_device(devpath, subsystem);
|
||||||
|
|
2
udev.h
2
udev.h
|
@ -56,7 +56,7 @@ do { \
|
||||||
strncpy(to, from, sizeof(to)-1); \
|
strncpy(to, from, sizeof(to)-1); \
|
||||||
} while (0)
|
} 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 int udev_remove_device(char *path, char *subsystem);
|
||||||
extern void udev_init_config(void);
|
extern void udev_init_config(void);
|
||||||
extern int parse_get_pair(char **orig_string, char **left, char **right);
|
extern int parse_get_pair(char **orig_string, char **left, char **right);
|
||||||
|
|
51
udevtest.c
51
udevtest.c
|
@ -29,10 +29,8 @@
|
||||||
|
|
||||||
#include "udev.h"
|
#include "udev.h"
|
||||||
#include "udev_version.h"
|
#include "udev_version.h"
|
||||||
#include "udev_dbus.h"
|
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "namedev.h"
|
#include "namedev.h"
|
||||||
#include "udevdb.h"
|
|
||||||
#include "libsysfs/libsysfs.h"
|
#include "libsysfs/libsysfs.h"
|
||||||
|
|
||||||
/* global variables */
|
/* global variables */
|
||||||
|
@ -45,12 +43,15 @@ void log_message (int level, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
if (!udev_log)
|
// if (!udev_log)
|
||||||
return;
|
// return;
|
||||||
|
|
||||||
|
/* FIXME use level... */
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
vsyslog(level, format, args);
|
vprintf(format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
if (format[strlen(format)-1] != '\n')
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -59,8 +60,6 @@ static void sig_handler(int signum)
|
||||||
switch (signum) {
|
switch (signum) {
|
||||||
case SIGINT:
|
case SIGINT:
|
||||||
case SIGTERM:
|
case SIGTERM:
|
||||||
sysbus_disconnect();
|
|
||||||
udevdb_exit();
|
|
||||||
exit(20 + signum);
|
exit(20 + signum);
|
||||||
default:
|
default:
|
||||||
dbg("unhandled signal");
|
dbg("unhandled signal");
|
||||||
|
@ -102,22 +101,15 @@ static char *subsystem_blacklist[] = {
|
||||||
|
|
||||||
static int udev_hotplug(int argc, char **argv)
|
static int udev_hotplug(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *action;
|
|
||||||
char *devpath;
|
char *devpath;
|
||||||
char *subsystem;
|
char *subsystem;
|
||||||
int retval = -EINVAL;
|
int retval = -EINVAL;
|
||||||
int i;
|
int i;
|
||||||
struct sigaction act;
|
struct sigaction act;
|
||||||
|
|
||||||
action = get_action();
|
devpath = argv[1];
|
||||||
if (!action) {
|
|
||||||
dbg ("no action?");
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
devpath = get_devpath();
|
|
||||||
if (!devpath) {
|
if (!devpath) {
|
||||||
dbg ("no devpath?");
|
dbg("no devpath?");
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
dbg("looking at '%s'", devpath);
|
dbg("looking at '%s'", devpath);
|
||||||
|
@ -140,19 +132,9 @@ static int udev_hotplug(int argc, char **argv)
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* connect to the system message bus */
|
|
||||||
sysbus_connect();
|
|
||||||
|
|
||||||
/* initialize our configuration */
|
/* initialize our configuration */
|
||||||
udev_init_config();
|
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 */
|
/* set up a default signal handler for now */
|
||||||
act.sa_handler = sig_handler;
|
act.sa_handler = sig_handler;
|
||||||
sigemptyset (&act.sa_mask);
|
sigemptyset (&act.sa_mask);
|
||||||
|
@ -163,21 +145,7 @@ static int udev_hotplug(int argc, char **argv)
|
||||||
/* initialize the naming deamon */
|
/* initialize the naming deamon */
|
||||||
namedev_init();
|
namedev_init();
|
||||||
|
|
||||||
if (strcmp(action, "add") == 0)
|
retval = udev_add_device(devpath, subsystem, 1);
|
||||||
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();
|
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (retval > 0)
|
if (retval > 0)
|
||||||
|
@ -191,7 +159,6 @@ int main(int argc, char **argv, char **envp)
|
||||||
main_argv = argv;
|
main_argv = argv;
|
||||||
main_envp = envp;
|
main_envp = envp;
|
||||||
|
|
||||||
init_logging("udev");
|
|
||||||
dbg("version %s", UDEV_VERSION);
|
dbg("version %s", UDEV_VERSION);
|
||||||
|
|
||||||
return udev_hotplug(argc, argv);
|
return udev_hotplug(argc, argv);
|
||||||
|
|
Loading…
Reference in a new issue