mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-11 05:17:44 +03:00
udevadm: control - use /run/udev/control socket instead of abstract namespace one
This commit is contained in:
parent
7944a13a2b
commit
5cc4112e6d
3
TODO
3
TODO
@ -1,8 +1,5 @@
|
||||
- test (now fixed) /dev/tape/ links
|
||||
|
||||
- /run/udev/control socket
|
||||
(add ConditionVirtualization=!pidns)
|
||||
|
||||
- move udevd -> --libexecdir
|
||||
|
||||
- have a $attrs{} ?
|
||||
|
@ -5,4 +5,4 @@ ConditionVirtualization=!container
|
||||
|
||||
[Socket]
|
||||
Service=udev.service
|
||||
ListenSequentialPacket=@/org/kernel/udev/udevd
|
||||
ListenSequentialPacket=/run/udev/control
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user