summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO3
-rw-r--r--init/udev-control.socket2
-rw-r--r--udev/udev-ctrl.c31
-rw-r--r--udev/udev.h6
-rw-r--r--udev/udevadm-control.c7
-rw-r--r--udev/udevadm-settle.c2
-rw-r--r--udev/udevd.c4
7 files changed, 26 insertions, 29 deletions
diff --git a/TODO b/TODO
index 3dcaf4ca85..1d26f451b0 100644
--- a/TODO
+++ b/TODO
@@ -1,8 +1,5 @@
- test (now fixed) /dev/tape/ links
- - /run/udev/control socket
- (add ConditionVirtualization=!pidns)
-
- move udevd -> --libexecdir
- have a $attrs{} ?
diff --git a/init/udev-control.socket b/init/udev-control.socket
index 8f3106130b..ea21803f77 100644
--- a/init/udev-control.socket
+++ b/init/udev-control.socket
@@ -5,4 +5,4 @@ ConditionVirtualization=!container
[Socket]
Service=udev.service
-ListenSequentialPacket=@/org/kernel/udev/udevd
+ListenSequentialPacket=/run/udev/control
diff --git a/udev/udev-ctrl.c b/udev/udev-ctrl.c
index 85e656248b..43484cc838 100644
--- a/udev/udev-ctrl.c
+++ b/udev/udev-ctrl.c
@@ -60,6 +60,7 @@ struct udev_ctrl {
struct sockaddr_un saddr;
socklen_t addrlen;
bool bound;
+ bool cleanup_socket;
bool connected;
};
@@ -69,7 +70,7 @@ struct udev_ctrl_connection {
int sock;
};
-static struct udev_ctrl *udev_ctrl_new(struct udev *udev)
+struct udev_ctrl *udev_ctrl_new_from_fd(struct udev *udev, int fd)
{
struct udev_ctrl *uctrl;
@@ -78,16 +79,6 @@ static struct udev_ctrl *udev_ctrl_new(struct udev *udev)
return NULL;
uctrl->refcount = 1;
uctrl->udev = udev;
- return uctrl;
-}
-
-struct udev_ctrl *udev_ctrl_new_from_socket_fd(struct udev *udev, const char *socket_path, int fd)
-{
- struct udev_ctrl *uctrl;
-
- uctrl = udev_ctrl_new(udev);
- if (uctrl == NULL)
- return NULL;
if (fd < 0) {
uctrl->sock = socket(AF_LOCAL, SOCK_SEQPACKET|SOCK_NONBLOCK|SOCK_CLOEXEC, 0);
@@ -102,17 +93,15 @@ struct udev_ctrl *udev_ctrl_new_from_socket_fd(struct udev *udev, const char *so
}
uctrl->saddr.sun_family = AF_LOCAL;
- strcpy(uctrl->saddr.sun_path, socket_path);
+ util_strscpyl(uctrl->saddr.sun_path, sizeof(uctrl->saddr.sun_path),
+ udev_get_run_path(udev), "/control", NULL);
uctrl->addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(uctrl->saddr.sun_path);
- /* translate leading '@' to abstract namespace */
- if (uctrl->saddr.sun_path[0] == '@')
- uctrl->saddr.sun_path[0] = '\0';
return uctrl;
}
-struct udev_ctrl *udev_ctrl_new_from_socket(struct udev *udev, const char *socket_path)
+struct udev_ctrl *udev_ctrl_new(struct udev *udev)
{
- return udev_ctrl_new_from_socket_fd(udev, socket_path, -1);
+ return udev_ctrl_new_from_fd(udev, -1);
}
int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl)
@@ -121,6 +110,11 @@ int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl)
if (!uctrl->bound) {
err = bind(uctrl->sock, (struct sockaddr *)&uctrl->saddr, uctrl->addrlen);
+ if (err < 0 && errno == EADDRINUSE) {
+ unlink(uctrl->saddr.sun_path);
+ err = bind(uctrl->sock, (struct sockaddr *)&uctrl->saddr, uctrl->addrlen);
+ }
+
if (err < 0) {
err = -errno;
err(uctrl->udev, "bind failed: %m\n");
@@ -135,6 +129,7 @@ int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl)
}
uctrl->bound = true;
+ uctrl->cleanup_socket = true;
}
return 0;
}
@@ -161,6 +156,8 @@ struct udev_ctrl *udev_ctrl_unref(struct udev_ctrl *uctrl)
return uctrl;
if (uctrl->sock >= 0)
close(uctrl->sock);
+ if (uctrl->cleanup_socket)
+ unlink(uctrl->saddr.sun_path);
free(uctrl);
return NULL;
}
diff --git a/udev/udev.h b/udev/udev.h
index 5aaf117a9c..402c738aee 100644
--- a/udev/udev.h
+++ b/udev/udev.h
@@ -26,8 +26,6 @@
#include "libudev.h"
#include "libudev-private.h"
-#define UDEV_CTRL_SOCK_PATH "@/org/kernel/udev/udevd"
-
struct udev_event {
struct udev *udev;
struct udev_device *dev;
@@ -99,8 +97,8 @@ void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev
/* udev-ctrl.c */
struct udev_ctrl;
-struct udev_ctrl *udev_ctrl_new_from_socket(struct udev *udev, const char *socket_path);
-struct udev_ctrl *udev_ctrl_new_from_socket_fd(struct udev *udev, const char *socket_path, int fd);
+struct udev_ctrl *udev_ctrl_new(struct udev *udev);
+struct udev_ctrl *udev_ctrl_new_from_fd(struct udev *udev, int fd);
int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl);
struct udev_ctrl *udev_ctrl_ref(struct udev_ctrl *uctrl);
struct udev_ctrl *udev_ctrl_unref(struct udev_ctrl *uctrl);
diff --git a/udev/udevadm-control.c b/udev/udevadm-control.c
index b500d75a4e..130a71b3d0 100644
--- a/udev/udevadm-control.c
+++ b/udev/udevadm-control.c
@@ -66,7 +66,7 @@ static int adm_control(struct udev *udev, int argc, char *argv[])
return 1;
}
- uctrl = udev_ctrl_new_from_socket(udev, UDEV_CTRL_SOCK_PATH);
+ uctrl = udev_ctrl_new(udev);
if (uctrl == NULL)
return 2;
@@ -157,6 +157,11 @@ static int adm_control(struct udev *udev, int argc, char *argv[])
break;
}
}
+
+ if (argv[optind] != NULL)
+ fprintf(stderr, "unknown option\n");
+ else if (optind == 1)
+ fprintf(stderr, "missing option\n");
out:
udev_ctrl_unref(uctrl);
return rc;
diff --git a/udev/udevadm-settle.c b/udev/udevadm-settle.c
index 9f409b61b8..a59d7c39e5 100644
--- a/udev/udevadm-settle.c
+++ b/udev/udevadm-settle.c
@@ -138,7 +138,7 @@ static int adm_settle(struct udev *udev, int argc, char *argv[])
if (getuid() == 0) {
struct udev_ctrl *uctrl;
- uctrl = udev_ctrl_new_from_socket(udev, UDEV_CTRL_SOCK_PATH);
+ uctrl = udev_ctrl_new(udev);
if (uctrl != NULL) {
if (udev_ctrl_send_ping(uctrl, timeout) < 0) {
info(udev, "no connection to daemon\n");
diff --git a/udev/udevd.c b/udev/udevd.c
index b65b53f7ed..fdb3e42002 100644
--- a/udev/udevd.c
+++ b/udev/udevd.c
@@ -1349,7 +1349,7 @@ int main(int argc, char *argv[])
if (systemd_fds(udev, &fd_ctrl, &fd_netlink) >= 0) {
/* get control and netlink socket from from systemd */
- udev_ctrl = udev_ctrl_new_from_socket_fd(udev, UDEV_CTRL_SOCK_PATH, fd_ctrl);
+ udev_ctrl = udev_ctrl_new_from_fd(udev, fd_ctrl);
if (udev_ctrl == NULL) {
err(udev, "error taking over udev control socket");
rc = 1;
@@ -1364,7 +1364,7 @@ int main(int argc, char *argv[])
}
} else {
/* open control and netlink socket */
- udev_ctrl = udev_ctrl_new_from_socket(udev, UDEV_CTRL_SOCK_PATH);
+ udev_ctrl = udev_ctrl_new(udev);
if (udev_ctrl == NULL) {
fprintf(stderr, "error initializing udev control socket");
err(udev, "error initializing udev control socket");