summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--etc/udev/udev.conf.in1
-rw-r--r--udev.c2
-rw-r--r--udev_utils.c4
-rw-r--r--udevcontrol.c33
-rw-r--r--udevd.c70
-rw-r--r--udevd.h8
-rw-r--r--udevinitsend.c2
-rw-r--r--udevsend.c2
9 files changed, 78 insertions, 46 deletions
diff --git a/Makefile b/Makefile
index 9ad6ee103b..bdb87e5651 100644
--- a/Makefile
+++ b/Makefile
@@ -388,7 +388,7 @@ install: install-config install-man install-dev.d all
- ln -f -s $(sbindir)/$(SENDER) $(DESTDIR)$(hotplugdir)/10-udev.hotplug
ifndef DESTDIR
- killall $(DAEMON)
- - $(sbindir)/$(DAEMON) -d
+ - $(sbindir)/$(DAEMON) --daemon
- rm -rf $(udevdb)
endif
@extras="$(EXTRAS)" ; for target in $$extras ; do \
diff --git a/etc/udev/udev.conf.in b/etc/udev/udev.conf.in
index 9d5300a861..efdb1d1808 100644
--- a/etc/udev/udev.conf.in
+++ b/etc/udev/udev.conf.in
@@ -1,5 +1,4 @@
# udev.conf
-#
# Where in the filesystem to place the device nodes
udev_root="@udevdir@"
diff --git a/udev.c b/udev.c
index 3eb788f4c1..f7b9bf3573 100644
--- a/udev.c
+++ b/udev.c
@@ -109,7 +109,7 @@ int main(int argc, char *argv[], char *envp[])
goto exit;
}
- /* export log_level , as called programs may want to do the same as udev */
+ /* export log_priority , as called programs may want to do the same as udev */
if (udev_log_priority) {
char priority[32];
diff --git a/udev_utils.c b/udev_utils.c
index d605631088..64a7ba9caa 100644
--- a/udev_utils.c
+++ b/udev_utils.c
@@ -409,10 +409,10 @@ int execute_command(const char *command, const char *subsystem)
close(devnull);
}
retval = execv(arg, argv);
- err("exec of child failed");
+ err("exec of child '%s' failed", command);
_exit(1);
case -1:
- dbg("fork of child failed");
+ dbg("fork of child '%s' failed", command);
break;
return -1;
default:
diff --git a/udevcontrol.c b/udevcontrol.c
index 4a54af805e..98776ccefd 100644
--- a/udevcontrol.c
+++ b/udevcontrol.c
@@ -37,18 +37,23 @@
#include "udev.h"
#include "udev_version.h"
#include "udevd.h"
+#include "udev_utils.h"
#include "logging.h"
/* global variables */
static int sock = -1;
+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
@@ -59,25 +64,37 @@ int main(int argc, char *argv[], char *envp[])
static struct udevd_msg usend_msg;
struct sockaddr_un saddr;
socklen_t addrlen;
+ const char *env;
int retval = 1;
+ env = getenv("UDEV_LOG");
+ if (env)
+ log = log_priority(env);
+
logging_init("udevcontrol");
dbg("version %s", UDEV_VERSION);
if (argc != 2) {
- info("usage: udevcontrol <cmd>\n");
+ info("usage: udevcontrol <cmd>");
goto exit;
}
memset(&usend_msg, 0x00, sizeof(struct udevd_msg));
strcpy(usend_msg.magic, UDEV_MAGIC);
- if (strstr(argv[1], "stop_exec_queue"))
+ if (!strcmp(argv[1], "stop_exec_queue"))
usend_msg.type = UDEVD_STOP_EXEC_QUEUE;
- else if (strstr(argv[1], "start_exec_queue"))
+ else if (!strcmp(argv[1], "start_exec_queue"))
usend_msg.type = UDEVD_START_EXEC_QUEUE;
- else {
- info("unknown command\n");
+ else if (!strncmp(argv[1], "log_priority=", strlen("log_priority="))) {
+ int *level = (int *) usend_msg.envbuf;
+ char *prio = &argv[1][strlen("log_priority=")];
+
+ usend_msg.type = UDEVD_SET_LOG_LEVEL;
+ *level = log_priority(prio);
+ dbg("send log_priority=%i", *level);
+ } else {
+ err("unknown command\n");
goto exit;
}
@@ -99,7 +116,7 @@ int main(int argc, char *argv[], char *envp[])
info("error sending message (%s)", strerror(errno));
retval = 1;
} else {
- dbg("sent message '%x' (%u bytes sent)\n", usend_msg.type, retval);
+ dbg("sent message '%x' (%u bytes sent)", usend_msg.type, retval);
retval = 0;
}
diff --git a/udevd.c b/udevd.c
index f4c986b870..209b9fcd87 100644
--- a/udevd.c
+++ b/udevd.c
@@ -50,7 +50,7 @@
/* global variables*/
static int udevd_sock;
-static int uevent_nl_sock;
+static int uevent_netlink_sock;
static pid_t sid;
static int pipefds[2];
@@ -173,8 +173,8 @@ static void execute_udev(struct uevent_msg *msg)
switch (pid) {
case 0:
/* child */
- if (uevent_nl_sock != -1)
- close(uevent_nl_sock);
+ if (uevent_netlink_sock != -1)
+ close(uevent_netlink_sock);
close(udevd_sock);
logging_close();
@@ -362,6 +362,9 @@ static void exec_queue_manager(void)
struct uevent_msg *tmp_msg;
int running;
+ if (list_empty(&exec_list))
+ return;
+
running = running_processes();
dbg("%d processes runnning on system", running);
if (running < 0)
@@ -506,6 +509,7 @@ static struct uevent_msg *get_udevd_msg(void)
struct ucred *cred;
char cred_msg[CMSG_SPACE(sizeof(struct ucred))];
int envbuf_size;
+ int *intval;
memset(&usend_msg, 0x00, sizeof(struct udevd_msg));
iov.iov_base = &usend_msg;
@@ -541,10 +545,10 @@ static struct uevent_msg *get_udevd_msg(void)
return NULL;
}
-switch (usend_msg.type) {
- case UDEVD_UDEVSEND:
- case UDEVD_INITSEND:
- dbg("udevd event message received");
+ switch (usend_msg.type) {
+ case UDEVD_UEVENT_UDEVSEND:
+ case UDEVD_UEVENT_INITSEND:
+ info("udevd event message received");
envbuf_size = size - offsetof(struct udevd_msg, envbuf);
dbg("envbuf_size=%i", envbuf_size);
msg = get_msg_from_envbuf(usend_msg.envbuf, envbuf_size);
@@ -553,14 +557,24 @@ switch (usend_msg.type) {
msg->type = usend_msg.type;
return msg;
case UDEVD_STOP_EXEC_QUEUE:
- dbg("udevd message (STOP_EXEC_QUEUE) received");
+ info("udevd message (STOP_EXEC_QUEUE) received");
stop_exec_q = 1;
break;
case UDEVD_START_EXEC_QUEUE:
- dbg("udevd message (START_EXEC_QUEUE) received");
+ info("udevd message (START_EXEC_QUEUE) received");
stop_exec_q = 0;
exec_queue_manager();
break;
+ case UDEVD_SET_LOG_LEVEL:
+ intval = (int *) usend_msg.envbuf;
+ info("udevd message (SET_LOG_PRIORITY) received, udev_log_priority=%i", *intval);
+ udev_log_priority = *intval;
+ break;
+ case UDEVD_SET_MAX_CHILDS:
+ intval = (int *) usend_msg.envbuf;
+ info("udevd message (UDEVD_SET_MAX_CHILDS) received, max_childs=%i", *intval);
+ max_childs = *intval;
+ break;
default:
dbg("unknown message type");
}
@@ -568,7 +582,7 @@ switch (usend_msg.type) {
}
/* receive the kernel user event message and do some sanity checks */
-static struct uevent_msg *get_nl_msg(void)
+static struct uevent_msg *get_netlink_msg(void)
{
struct uevent_msg *msg;
int bufpos;
@@ -576,7 +590,7 @@ static struct uevent_msg *get_nl_msg(void)
static char buffer[UEVENT_BUFFER_SIZE + 512];
char *pos;
- size = recv(uevent_nl_sock, &buffer, sizeof(buffer), 0);
+ size = recv(uevent_netlink_sock, &buffer, sizeof(buffer), 0);
if (size < 0) {
if (errno != EINTR)
dbg("unable to receive udevd message");
@@ -593,7 +607,7 @@ static struct uevent_msg *get_nl_msg(void)
msg = get_msg_from_envbuf(&buffer[bufpos], size-bufpos);
if (msg == NULL)
return NULL;
- msg->type = UDEVD_NL;
+ msg->type = UDEVD_UEVENT_NETLINK;
/* validate message */
pos = strchr(buffer, '@');
@@ -732,7 +746,7 @@ static int init_udevd_socket(void)
return 0;
}
-static int init_uevent_nl_sock(void)
+static int init_uevent_netlink_sock(void)
{
struct sockaddr_nl snl;
int retval;
@@ -742,18 +756,18 @@ static int init_uevent_nl_sock(void)
snl.nl_pid = getpid();
snl.nl_groups = 0xffffffff;
- uevent_nl_sock = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
- if (uevent_nl_sock == -1) {
+ uevent_netlink_sock = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
+ if (uevent_netlink_sock == -1) {
dbg("error getting socket, %s", strerror(errno));
return -1;
}
- retval = bind(uevent_nl_sock, (struct sockaddr *) &snl,
+ retval = bind(uevent_netlink_sock, (struct sockaddr *) &snl,
sizeof(struct sockaddr_nl));
if (retval < 0) {
dbg("bind failed, %s", strerror(errno));
- close(uevent_nl_sock);
- uevent_nl_sock = -1;
+ close(uevent_netlink_sock);
+ uevent_netlink_sock = -1;
return -1;
}
@@ -768,7 +782,7 @@ int main(int argc, char *argv[], char *envp[])
struct sigaction act;
fd_set readfds;
const char *value;
- int uevent_nl_active = 0;
+ int uevent_netlink_active = 0;
int daemonize = 0;
int i;
@@ -788,7 +802,7 @@ int main(int argc, char *argv[], char *envp[])
daemonize = 1;
}
if (strcmp(arg, "--stop-exec-queue") == 0) {
- info("will not execute event until START_EXEC_QUEUE is received");
+ info("will not execute events until START_EXEC_QUEUE is received");
stop_exec_q = 1;
}
}
@@ -865,7 +879,7 @@ int main(int argc, char *argv[], char *envp[])
sigaction(SIGALRM, &act, NULL);
sigaction(SIGCHLD, &act, NULL);
- if (init_uevent_nl_sock() < 0) {
+ if (init_uevent_netlink_sock() < 0) {
dbg("uevent socket not available");
}
@@ -918,8 +932,8 @@ int main(int argc, char *argv[], char *envp[])
FD_ZERO(&readfds);
FD_SET(udevd_sock, &readfds);
- if (uevent_nl_sock != -1)
- FD_SET(uevent_nl_sock, &readfds);
+ if (uevent_netlink_sock != -1)
+ FD_SET(uevent_netlink_sock, &readfds);
FD_SET(pipefds[0], &readfds);
maxsockplus = udevd_sock+1;
while (1) {
@@ -938,7 +952,7 @@ int main(int argc, char *argv[], char *envp[])
msg = get_udevd_msg();
if (msg) {
/* discard kernel messages if netlink is active */
- if (uevent_nl_active && msg->type == UDEVD_UDEVSEND && msg->seqnum != 0) {
+ if (uevent_netlink_active && msg->type == UDEVD_UEVENT_UDEVSEND && msg->seqnum != 0) {
dbg("skip uevent_helper message, netlink is active");
free(msg);
continue;
@@ -947,14 +961,14 @@ int main(int argc, char *argv[], char *envp[])
}
}
- if (FD_ISSET(uevent_nl_sock, &workreadfds)) {
- msg = get_nl_msg();
+ if (FD_ISSET(uevent_netlink_sock, &workreadfds)) {
+ msg = get_netlink_msg();
if (msg) {
msg_queue_insert(msg);
/* disable udevsend with first netlink message */
- if (!uevent_nl_active) {
+ if (!uevent_netlink_active) {
info("uevent_nl message received, disable udevsend messages");
- uevent_nl_active = 1;
+ uevent_netlink_active = 1;
}
}
}
diff --git a/udevd.h b/udevd.h
index b8fb6913c9..34bfe931ba 100644
--- a/udevd.h
+++ b/udevd.h
@@ -50,11 +50,13 @@
enum udevd_msg_type {
UDEVD_UNKNOWN,
- UDEVD_UDEVSEND,
- UDEVD_INITSEND,
- UDEVD_NL,
+ UDEVD_UEVENT_UDEVSEND,
+ UDEVD_UEVENT_INITSEND,
+ UDEVD_UEVENT_NETLINK,
UDEVD_STOP_EXEC_QUEUE,
UDEVD_START_EXEC_QUEUE,
+ UDEVD_SET_LOG_LEVEL,
+ UDEVD_SET_MAX_CHILDS,
};
diff --git a/udevinitsend.c b/udevinitsend.c
index 31a7109d1b..26ae5c8418 100644
--- a/udevinitsend.c
+++ b/udevinitsend.c
@@ -100,7 +100,7 @@ static int udevsend(char *filename, int sock, int disable_loop_detection)
memset(&usend_msg, 0x00, sizeof(struct udevd_msg));
strcpy(usend_msg.magic, UDEV_MAGIC);
- usend_msg.type = UDEVD_INITSEND;
+ usend_msg.type = UDEVD_UEVENT_INITSEND;
ls = fdmap;
ch = le = ls;
diff --git a/udevsend.c b/udevsend.c
index 42ef0271dd..bdc69d0508 100644
--- a/udevsend.c
+++ b/udevsend.c
@@ -146,7 +146,7 @@ int main(int argc, char *argv[], char *envp[])
memset(&usend_msg, 0x00, sizeof(struct udevd_msg));
strcpy(usend_msg.magic, UDEV_MAGIC);
- usend_msg.type = UDEVD_UDEVSEND;
+ usend_msg.type = UDEVD_UEVENT_UDEVSEND;
/* copy all keys to send buffer */
for (i = 0; envp[i]; i++) {