#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
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;
}
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;
}
/* global variables*/
static int udevd_sock;
-static int uevent_nl_sock;
+static int uevent_netlink_sock;
static pid_t sid;
static int pipefds[2];
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();
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)
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;
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);
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");
}
}
/* 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;
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");
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, '@');
return 0;
}
-static int init_uevent_nl_sock(void)
+static int init_uevent_netlink_sock(void)
{
struct sockaddr_nl snl;
int retval;
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;
}
struct sigaction act;
fd_set readfds;
const char *value;
- int uevent_nl_active = 0;
+ int uevent_netlink_active = 0;
int daemonize = 0;
int i;
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;
}
}
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");
}
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) {
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;
}
}
- 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;
}
}
}