diff options
author | Kay Sievers <kay.sievers@suse.de> | 2005-06-15 03:07:14 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@suse.de> | 2005-06-15 03:07:14 +0200 |
commit | 3632a3685883d3270145c59d5764de6246547943 (patch) | |
tree | 6b2a5d22d47f354f708df8f7fc733a4d20499942 | |
parent | e5b7f7b83428cb50f165b49408c2f7559dcfefef (diff) |
udeveventrecorder: add small program that writes an event to disk
Used for debugging and event replay from initramfs.
Signed-off-by: Kay Sievers <kay.sievers@suse.de>
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | udevd.c | 6 | ||||
-rw-r--r-- | udeveventrecorder.c | 127 | ||||
-rw-r--r-- | udevinitsend.c | 15 |
4 files changed, 153 insertions, 7 deletions
@@ -45,6 +45,7 @@ ROOT = udev DAEMON = udevd SENDER = udevsend INITSENDER = udevinitsend +RECORDER = udeveventrecorder CONTROL = udevcontrol INFO = udevinfo TESTER = udevtest @@ -204,7 +205,7 @@ endif # config files automatically generated GEN_CONFIGS = $(LOCAL_CFG_DIR)/udev.conf -all: $(ROOT) $(SENDER) $(INITSENDER) $(CONTROL) $(DAEMON) $(INFO) $(TESTER) $(STARTER) $(GEN_CONFIGS) $(KLCC) +all: $(ROOT) $(SENDER) $(INITSENDER) $(RECORDER) $(CONTROL) $(DAEMON) $(INFO) $(TESTER) $(STARTER) $(GEN_CONFIGS) $(KLCC) @extras="$(EXTRAS)" ; for target in $$extras ; do \ echo $$target ; \ $(MAKE) prefix=$(prefix) \ @@ -271,6 +272,7 @@ $(INFO).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC) $(DAEMON).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC) $(SENDER).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC) $(INITSENDER).o: $(GEN_HEADERS) $(HOST_PROGS) $(KLCC) +$(RECORDER).o: $(GEN_HEADERS) $(HOST_PROGS) $(KLCC) $(CONTROL).o: $(HEADERS) $( $(HEADERS)GEN_HEADERS) $(HOST_PROGS) $(KLCC) $(STARTER).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC) @@ -298,6 +300,10 @@ $(INITSENDER): $(KLCC) $(INITSENDER).o $(OBJS) udevd.h $(QUIET) $(LD) $(LDFLAGS) -o $@ $(INITSENDER).o $(OBJS) $(LIB_OBJS) $(QUIET) $(STRIPCMD) $@ +$(RECORDER): $(KLCC) $(RECORDER).o $(OBJS) udevd.h + $(QUIET) $(LD) $(LDFLAGS) -o $@ $(RECORDER).o $(OBJS) $(LIB_OBJS) + $(QUIET) $(STRIPCMD) $@ + $(CONTROL): $(KLCC) $(CONTROL).o $(OBJS) udevd.h $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CONTROL).o $(OBJS) $(LIB_OBJS) $(QUIET) $(STRIPCMD) $@ @@ -313,7 +319,7 @@ clean: -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \ | xargs rm -f -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(GEN_MANPAGES) $(INFO) $(DAEMON) \ - $(SENDER) $(INITSENDER) $(CONTROL) $(TESTER) $(STARTER) + $(SENDER) $(INITSENDER) $(RECORDER) $(CONTROL) $(TESTER) $(STARTER) -rm -f ccdv $(MAKE) -C klibc SUBDIRS=klibc clean @extras="$(EXTRAS)" ; for target in $$extras ; do \ @@ -374,6 +380,7 @@ install: install-config install-man install-dev.d all $(INSTALL_PROGRAM) -D $(DAEMON) $(DESTDIR)$(sbindir)/$(DAEMON) $(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER) $(INSTALL_PROGRAM) -D $(INITSENDER) $(DESTDIR)$(sbindir)/$(INITSENDER) + $(INSTALL_PROGRAM) -D $(RECORDER) $(DESTDIR)$(sbindir)/$(RECORDER) $(INSTALL_PROGRAM) -D $(CONTROL) $(DESTDIR)$(sbindir)/$(CONTROL) $(INSTALL_PROGRAM) -D $(INFO) $(DESTDIR)$(usrbindir)/$(INFO) $(INSTALL_PROGRAM) -D $(TESTER) $(DESTDIR)$(usrbindir)/$(TESTER) @@ -400,6 +407,7 @@ uninstall: uninstall-man uninstall-dev.d - rm $(sbindir)/$(DAEMON) - rm $(sbindir)/$(SENDER) - rm $(sbindir)/$(INITSENDER) + - rm $(sbindir)/$(RECORDER) - rm $(sbindir)/$(CONTROL) - rm $(sbindir)/$(STARTER) - rm $(usrbindir)/$(INFO) @@ -660,7 +660,7 @@ static void udev_done(int pid) list_for_each_entry(msg, &running_list, node) { if (msg->pid == pid) { sysinfo(&info); - info("seq %llu exit, %ld sec old", msg->seqnum, info.uptime - msg->queue_time); + info("seq %llu exit, %ld seconds old", msg->seqnum, info.uptime - msg->queue_time); run_queue_delete(msg); /* we want to run the exec queue manager since there may @@ -951,9 +951,9 @@ int main(int argc, char *argv[], char *envp[]) msg = get_nl_msg(); if (msg) { msg_queue_insert(msg); - /* disable kernel uevent_helper with first netlink message */ + /* disable udevsend with first netlink message */ if (!uevent_nl_active) { - info("uevent_nl message received, disable uevent_helper messages"); + info("uevent_nl message received, disable udevsend messages"); uevent_nl_active = 1; } } diff --git a/udeveventrecorder.c b/udeveventrecorder.c new file mode 100644 index 0000000000..af7ea7c15c --- /dev/null +++ b/udeveventrecorder.c @@ -0,0 +1,127 @@ +/* + * udeveventrecorder.c + * + * Userspace devfs + * + * Copyright (C) 2004, 2005 Olaf Hering <olh@suse.de> + * + * This program is free software; you can redistribute it and/or modify it + * 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 <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + +#include "udev.h" +#include "udev_version.h" +#include "udev_utils.h" +#include "logging.h" + +#define BUFSIZE 12345 +#define FNSIZE 123 + +static int log = 0; + +#ifdef USE_LOG +void log_message (int priority, const char *format, ...) +{ + va_list args; + + if (priority > log) + return; + + va_start(args, format); + vsyslog(priority, format, args); + va_end(args); +} +#endif + +int main(int argc, char **argv, char **envp) +{ + int fd, i; + unsigned long seq; + char **ep = envp; + char *buf, *p, *a; + struct stat sb; + const char *env; + + if (stat("/events", &sb) || !(S_ISDIR(sb.st_mode))) + return 1; + + env = getenv("UDEV_LOG"); + if (env) + log = log_priority(env); + + logging_init("udeveventrecorder"); + dbg("version %s", UDEV_VERSION); + + p = getenv("SEQNUM"); + a = getenv("ACTION"); + buf = malloc(FNSIZE); + if (!(buf && a && argv[1])) + goto error; + if (p) + seq = strtoul(p, NULL, 0); + else + seq = 0; + + snprintf(buf, FNSIZE, "/events/debug.%05lu.%s.%s.%u", seq, argv[1], a ? a : "", getpid()); + if ((fd = open(buf, O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 0) { + err("error creating '%s'", buf); + goto error; + } + free(buf); + p = malloc(BUFSIZE); + buf = p; + buf += snprintf(buf, p + BUFSIZE - buf, "set --"); + for (i = 1; i < argc; ++i) { + buf += snprintf(buf, p + BUFSIZE - buf, " %s", argv[i]); + if (buf > p + BUFSIZE) + goto full; + } + buf += snprintf(buf, p + BUFSIZE - buf, "\n"); + if (buf > p + BUFSIZE) + goto full; + while (*ep) { + unsigned char *t; + t = memchr(*ep, '=', strlen(*ep)); + if (t) { + *t = '\0'; + t++; + buf += snprintf(buf, p + BUFSIZE - buf, "%s='%s'\n", *ep, t); + --t; + *t = '='; + } + ep++; + if (buf > p + BUFSIZE) + break; + } + +full: + buf = p; + write(fd, buf, strlen(buf)); + close(fd); + free(buf); + return 0; + +error: + fprintf(stderr, "record enviroment to /events, to be called from udev context\n"); + return 1; +} diff --git a/udevinitsend.c b/udevinitsend.c index c7d56fc259..31a7109d1b 100644 --- a/udevinitsend.c +++ b/udevinitsend.c @@ -23,6 +23,7 @@ #include <stdio.h> #include <stddef.h> #include <stdio.h> +#include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> @@ -38,16 +39,21 @@ #include "udev.h" #include "udev_version.h" #include "udevd.h" +#include "udev_utils.h" #include "logging.h" +static int log = 0; #ifdef USE_LOG -void log_message (int level, const char *format, ...) +void log_message (int priority, const char *format, ...) { va_list args; + if (priority > log) + return; + va_start(args, format); - vsyslog(level, format, args); + vsyslog(priority, format, args); va_end(args); } #endif @@ -164,6 +170,11 @@ int main(int argc, char *argv[], char *envp[]) int retval = 1; int disable_loop_detection = 0; int sock; + const char *env; + + env = getenv("UDEV_LOG"); + if (env) + log = log_priority(env); logging_init("udevinitsend"); dbg("version %s", UDEV_VERSION); |