summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>2004-02-02 17:00:07 +0100
committerGreg KH <gregkh@suse.de>2005-04-27 06:13:20 +0200
commit8e2229c439f4d0bcf5660457d5a2d6f9d4723e88 (patch)
tree4aa57059da530632dd0d71552cb7c1afbfd04215
parent[PATCH] udevd - cleanup and better timeout handling (diff)
downloadsystemd-8e2229c439f4d0bcf5660457d5a2d6f9d4723e88.tar.xz
systemd-8e2229c439f4d0bcf5660457d5a2d6f9d4723e88.zip
[PATCH] udevd - config cleanup
> Here is a small cleanup and better Makefile integration. > udevd and udevsender are now installed. Just switch HOTPLUG_EXEC from ROOT > to SENDER before install and udevsend will be called. > > We may add the location of the socket and lock file to the config, > if this is needed. Same patch with a fix for the stack size setting.
-rw-r--r--Makefile15
-rw-r--r--udevd.c26
-rw-r--r--udevd.h11
-rw-r--r--udevsend.c2
4 files changed, 28 insertions, 26 deletions
diff --git a/Makefile b/Makefile
index d953218f7b..05d5da5a33 100644
--- a/Makefile
+++ b/Makefile
@@ -38,6 +38,7 @@ VERSION = 015_bk
INSTALL_DIR = /usr/local/bin
RELEASE_NAME = $(ROOT)-$(VERSION)
LOCAL_CFG_DIR = etc/udev
+HOTPLUG_EXEC = $(ROOT)
DESTDIR =
# override this to make udev look in a different location for it's config files
@@ -232,8 +233,10 @@ udev_version.h:
@echo \#define UDEV_CONFIG_FILE \"$(configdir)\udev.conf\" >> $@
@echo \#define UDEV_RULES_FILE \"$(configdir)\udev.rules\" >> $@
@echo \#define UDEV_PERMISSION_FILE \"$(configdir)\udev.permissions\" >> $@
- @echo \#define UDEV_BIN \"$(PWD)/udev\" >> $@
- @echo \#define UDEVD_BIN \"$(PWD)/udevd\" >> $@
+ @echo \#define UDEV_BIN \"$(DESTDIR)$(sbindir)/udev\" >> $@
+ @echo \#define UDEVD_BIN \"$(DESTDIR)$(sbindir)/udevd\" >> $@
+ @echo \#define UDEVD_SOCK \"$(udevdir)/\.udevd.sock\" >> $@
+ @echo \#define UDEVD_LOCK \"$(udevdir)/\.udevd.lock\" >> $@
# config files automatically generated
GEN_CONFIGS = $(LOCAL_CFG_DIR)/udev.conf
@@ -338,6 +341,8 @@ install: install-config install-dbus-policy all
$(INSTALL) -d $(DESTDIR)$(udevdir)
$(INSTALL) -d $(DESTDIR)$(hotplugdir)
$(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT)
+ $(INSTALL_PROGRAM) -D $(DAEMON) $(DESTDIR)$(sbindir)/$(DAEMON)
+ $(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER)
$(INSTALL_PROGRAM) -D $(HELPER) $(DESTDIR)$(sbindir)/$(HELPER)
@if [ "x$(USE_LSB)" = "xtrue" ]; then \
$(INSTALL_PROGRAM) -D etc/init.d/udev.init.LSB $(DESTDIR)$(initdir)/udev; \
@@ -347,8 +352,8 @@ install: install-config install-dbus-policy all
fi
$(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
$(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
- - rm -f $(DESTDIR)$(hotplugdir)/udev.hotplug
- - ln -f -s $(sbindir)/$(ROOT) $(DESTDIR)$(hotplugdir)/udev.hotplug
+ - rm -f $(DESTDIR)$(hotplugdir)/$(HOTPLUG_EXEC).hotplug
+ - ln -f -s $(sbindir)/$(HOTPLUG_EXEC) $(DESTDIR)$(hotplugdir)/udev.hotplug
@extras="$(EXTRAS)" ; for target in $$extras ; do \
echo $$target ; \
$(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
@@ -364,6 +369,8 @@ uninstall: uninstall-dbus-policy
- rm $(mandir)/man8/udev.8
- rm $(mandir)/man8/udevinfo.8
- rm $(sbindir)/$(ROOT)
+ - rm $(sbindir)/$(DAEMON)
+ - rm $(sbindir)/$(SENDER)
- rm $(sbindir)/$(HELPER)
- rmdir $(hotplugdir)
- rmdir $(configdir)
diff --git a/udevd.c b/udevd.c
index 22fb4d33db..dc7d581c24 100644
--- a/udevd.c
+++ b/udevd.c
@@ -19,6 +19,7 @@
*
*/
+#include <pthread.h>
#include <stddef.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -33,7 +34,6 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
-#include <pthread.h>
#include "list.h"
#include "udev.h"
@@ -71,7 +71,6 @@ static void msg_dump(struct hotplug_msg *msg)
msg->seqnum, msg->action, msg->devpath, msg->subsystem);
}
-/* allocates a new message */
static struct hotplug_msg *msg_create(void)
{
struct hotplug_msg *new_msg;
@@ -81,10 +80,15 @@ static struct hotplug_msg *msg_create(void)
dbg("error malloc");
return NULL;
}
- memset(new_msg, 0x00, sizeof(struct hotplug_msg));
return new_msg;
}
+static void msg_delete(struct hotplug_msg *msg)
+{
+ if (msg != NULL)
+ free(msg);
+}
+
/* orders the message in the queue by sequence number */
static void msg_queue_insert(struct hotplug_msg *msg)
{
@@ -143,7 +147,7 @@ exit:
list_del_init(&msg->list);
pthread_mutex_unlock(&running_lock);
- free(msg);
+ msg_delete(msg);
/* signal queue activity to exec manager */
pthread_mutex_lock(&exec_active_lock);
@@ -289,6 +293,7 @@ static void *client_threads(void * parm)
if (strncmp(msg->magic, UDEV_MAGIC, sizeof(UDEV_MAGIC)) != 0 ) {
dbg("message magic '%s' doesn't match, ignore it", msg->magic);
+ msg_delete(msg);
goto exit;
}
@@ -307,7 +312,7 @@ static void sig_handler(int signum)
case SIGINT:
case SIGTERM:
unlink(UDEVD_LOCK);
- unlink(UDEVD_SOCKET);
+ unlink(UDEVD_SOCK);
exit(20 + signum);
break;
default:
@@ -320,7 +325,6 @@ static int one_and_only(void)
char string[50];
int lock_file;
- /* see if we can open */
lock_file = open(UDEVD_LOCK, O_RDWR | O_CREAT, 0x640);
if (lock_file < 0)
return -1;
@@ -359,9 +363,9 @@ int main(int argc, char *argv[])
memset(&saddr, 0x00, sizeof(saddr));
saddr.sun_family = AF_LOCAL;
- strcpy(saddr.sun_path, UDEVD_SOCKET);
+ strcpy(saddr.sun_path, UDEVD_SOCK);
- unlink(UDEVD_SOCKET);
+ unlink(UDEVD_SOCK);
ssock = socket(AF_LOCAL, SOCK_STREAM, 0);
if (ssock == -1) {
dbg("error getting socket");
@@ -389,6 +393,7 @@ int main(int argc, char *argv[])
/* set default attributes for created threads */
pthread_attr_init(&thr_attr);
pthread_attr_setdetachstate(&thr_attr, PTHREAD_CREATE_DETACHED);
+ pthread_attr_setstacksize(&thr_attr, 16 * 1024);
/* init queue management */
pthread_create(&mgr_msg_tid, &thr_attr, msg_queue_manager, NULL);
@@ -399,14 +404,13 @@ int main(int argc, char *argv[])
while (1) {
csock = accept(ssock, &caddr, &clen);
if (csock < 0) {
- if (errno == EINTR)
- continue;
dbg("client accept failed\n");
+ continue;
}
pthread_create(&cli_tid, &thr_attr, client_threads, (void *) csock);
}
exit:
close(ssock);
- unlink(UDEVD_SOCKET);
+ unlink(UDEVD_SOCK);
exit(1);
}
diff --git a/udevd.h b/udevd.h
index e24bc28a78..6dbee3a295 100644
--- a/udevd.h
+++ b/udevd.h
@@ -24,18 +24,9 @@
#include "list.h"
-/*
- * FIXME: udev_root is post compile configurable and may also be
- * mounted over at any time and /var/run/ and /tmp/ is unusable,
- * cause it's cleaned at system startup, long _after_ udevd is
- * already running. Should we use udev_init_config()?
- */
-
-#define UDEV_MAGIC "udev_" UDEV_VERSION
+#define UDEV_MAGIC "udevd_" UDEV_VERSION
#define EVENT_TIMEOUT_SEC 5
#define UDEVSEND_CONNECT_RETRY 20 /* x 100 millisec */
-#define UDEVD_SOCKET UDEV_ROOT ".udevd.socket"
-#define UDEVD_LOCK UDEV_ROOT ".udevd.pid"
struct hotplug_msg {
char magic[20];
diff --git a/udevsend.c b/udevsend.c
index 6ffd68c1b7..0ddc6839de 100644
--- a/udevsend.c
+++ b/udevsend.c
@@ -159,7 +159,7 @@ int main(int argc, char* argv[])
memset(&saddr, 0x00, sizeof(saddr));
saddr.sun_family = AF_LOCAL;
- strcpy(saddr.sun_path, UDEVD_SOCKET);
+ strcpy(saddr.sun_path, UDEVD_SOCK);
/* try to connect, if it fails start daemon */
retval = connect(sock, &saddr, sizeof(saddr));