summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>2005-01-16 04:08:54 +0100
committerGreg KH <gregkh@suse.de>2005-04-26 23:21:58 -0700
commitc2cf40123f836b0f24da2604aba177b86b93823d (patch)
tree4dd9ee47d6c353bfeecf029a73a0e904ec2d49dc
parentf15515b59ff373c3b9524a0842e96c1d105f5a62 (diff)
[PATCH] udevd: separate socket handling to prepare for other event sources
-rw-r--r--udevd.c73
1 files changed, 48 insertions, 25 deletions
diff --git a/udevd.c b/udevd.c
index f1e28d9ca3..7ae7a5b232 100644
--- a/udevd.c
+++ b/udevd.c
@@ -109,10 +109,16 @@ static void msg_queue_insert(struct hotplug_msg *msg)
}
/* sort message by sequence number into list */
- list_for_each_entry_reverse(loop_msg, &msg_list, list)
+ list_for_each_entry_reverse(loop_msg, &msg_list, list) {
if (loop_msg->seqnum < msg->seqnum)
break;
+ if (loop_msg->seqnum == msg->seqnum) {
+ dbg("ignoring duplicate message seq %llu", msg->seqnum);
+ return;
+ }
+ }
+
/* store timestamp of queuing */
sysinfo(&info);
msg->queue_time = info.uptime;
@@ -123,7 +129,7 @@ static void msg_queue_insert(struct hotplug_msg *msg)
/* run msg queue manager */
run_msg_q = 1;
- return ;
+ return;
}
/* forks event and removes event from run queue when finished */
@@ -453,14 +459,45 @@ static void user_sighandler(void)
}
}
-int main(int argc, char *argv[], char *envp[])
+static int init_udevsend_socket(void)
{
- struct sysinfo info;
- int maxsockplus;
struct sockaddr_un saddr;
socklen_t addrlen;
- int retval, fd;
const int feature_on = 1;
+ int retval;
+
+ memset(&saddr, 0x00, sizeof(saddr));
+ saddr.sun_family = AF_LOCAL;
+ /* use abstract namespace for socket path */
+ strcpy(&saddr.sun_path[1], UDEVD_SOCK_PATH);
+ addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1;
+
+ udevsendsock = socket(AF_LOCAL, SOCK_DGRAM, 0);
+ if (udevsendsock == -1) {
+ dbg("error getting socket, %s", strerror(errno));
+ return -1;
+ }
+
+ /* the bind takes care of ensuring only one copy running */
+ retval = bind(udevsendsock, (struct sockaddr *) &saddr, addrlen);
+ if (retval < 0) {
+ dbg("bind failed, %s", strerror(errno));
+ close(udevsendsock);
+ return -1;
+ }
+
+ /* enable receiving of the sender credentials */
+ setsockopt(udevsendsock, SOL_SOCKET, SO_PASSCRED, &feature_on, sizeof(feature_on));
+
+ return 0;
+}
+
+int main(int argc, char *argv[], char *envp[])
+{
+ struct sysinfo info;
+ int maxsockplus;
+ int retval;
+ int fd;
struct sigaction act;
fd_set readfds;
@@ -547,29 +584,15 @@ int main(int argc, char *argv[], char *envp[])
sigaction(SIGALRM, &act, NULL);
sigaction(SIGCHLD, &act, NULL);
- memset(&saddr, 0x00, sizeof(saddr));
- saddr.sun_family = AF_LOCAL;
- /* use abstract namespace for socket path */
- strcpy(&saddr.sun_path[1], UDEVD_SOCK_PATH);
- addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path+1) + 1;
+ if (init_udevsend_socket() < 0) {
+ if (errno == EADDRINUSE)
+ dbg("another udevd is running, exit");
+ else
+ dbg("error initialising udevsend socket: %s", strerror(errno));
- udevsendsock = socket(AF_LOCAL, SOCK_DGRAM, 0);
- if (udevsendsock == -1) {
- dbg("error getting socket, exit");
- goto exit;
- }
-
- /* the bind takes care of ensuring only one copy running */
- retval = bind(udevsendsock, (struct sockaddr *) &saddr, addrlen);
- if (retval < 0) {
- dbg("bind failed, exit");
- close(udevsendsock);
goto exit;
}
- /* enable receiving of the sender credentials */
- setsockopt(udevsendsock, SOL_SOCKET, SO_PASSCRED, &feature_on, sizeof(feature_on));
-
/* possible override of udev binary, used for testing */
udev_bin = getenv("UDEV_BIN");
if (udev_bin != NULL)