summaryrefslogtreecommitdiff
path: root/src/udev/udev-ctrl.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-12-21 13:36:26 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-12-21 13:36:26 +0100
commitb9da6a098b08d4eafec239fc05e0fd2073115504 (patch)
treef3eca7305463efa9b49fb87a59a13cc04db87a56 /src/udev/udev-ctrl.c
parenta67c318df8800ba98d7361308937ed276dc73982 (diff)
downloadsystemd-b9da6a098b08d4eafec239fc05e0fd2073115504.tar.gz
udev: modernize ctrl_send and use PROJECT_VERSION
PROJECT_VERSION is used in preparation for future changes. Let's simplify the code by using structured initialization. If the string written to .version ever became to long, the compiler will truncate it and tell us: ../src/udev/udev-ctrl.c: In function ‘ctrl_send’: ../src/udev/udev-ctrl.c:221:28: warning: initializer-string for array of chars is too long .version = "udev-" STRINGIFY(R_VERSION), ^~~~~~~ ../src/udev/udev-ctrl.c:221:28: note: (near initialization for ‘ctrl_msg_wire.version’) No functional change.
Diffstat (limited to 'src/udev/udev-ctrl.c')
-rw-r--r--src/udev/udev-ctrl.c50
1 files changed, 19 insertions, 31 deletions
diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c
index d90ebb7259..cb36c7e537 100644
--- a/src/udev/udev-ctrl.c
+++ b/src/udev/udev-ctrl.c
@@ -214,13 +214,11 @@ static struct udev_ctrl_connection *udev_ctrl_connection_free(struct udev_ctrl_c
DEFINE_TRIVIAL_REF_UNREF_FUNC(struct udev_ctrl_connection, udev_ctrl_connection, udev_ctrl_connection_free);
static int ctrl_send(struct udev_ctrl *uctrl, enum udev_ctrl_msg_type type, int intval, const char *buf, int timeout) {
- struct udev_ctrl_msg_wire ctrl_msg_wire;
- int err = 0;
-
- memzero(&ctrl_msg_wire, sizeof(struct udev_ctrl_msg_wire));
- strcpy(ctrl_msg_wire.version, "udev-" PACKAGE_VERSION);
- ctrl_msg_wire.magic = UDEV_CTRL_MAGIC;
- ctrl_msg_wire.type = type;
+ struct udev_ctrl_msg_wire ctrl_msg_wire = {
+ .version = "udev-" STRINGIFY(PROJECT_VERSION),
+ .magic = UDEV_CTRL_MAGIC,
+ .type = type,
+ };
if (buf)
strscpy(ctrl_msg_wire.buf, sizeof(ctrl_msg_wire.buf), buf);
@@ -228,43 +226,33 @@ static int ctrl_send(struct udev_ctrl *uctrl, enum udev_ctrl_msg_type type, int
ctrl_msg_wire.intval = intval;
if (!uctrl->connected) {
- if (connect(uctrl->sock, &uctrl->saddr.sa, uctrl->addrlen) < 0) {
- err = -errno;
- goto out;
- }
+ if (connect(uctrl->sock, &uctrl->saddr.sa, uctrl->addrlen) < 0)
+ return -errno;
uctrl->connected = true;
}
- if (send(uctrl->sock, &ctrl_msg_wire, sizeof(ctrl_msg_wire), 0) < 0) {
- err = -errno;
- goto out;
- }
+ if (send(uctrl->sock, &ctrl_msg_wire, sizeof(ctrl_msg_wire), 0) < 0)
+ return -errno;
/* wait for peer message handling or disconnect */
for (;;) {
- struct pollfd pfd[1];
+ struct pollfd pfd = {
+ .fd = uctrl->sock,
+ .events = POLLIN,
+ };
int r;
- pfd[0].fd = uctrl->sock;
- pfd[0].events = POLLIN;
- r = poll(pfd, 1, timeout * MSEC_PER_SEC);
+ r = poll(&pfd, 1, timeout * MSEC_PER_SEC);
if (r < 0) {
if (errno == EINTR)
continue;
- err = -errno;
- break;
- }
-
- if (r > 0 && pfd[0].revents & POLLERR) {
- err = -EIO;
- break;
+ return -errno;
}
-
if (r == 0)
- err = -ETIMEDOUT;
- break;
+ return -ETIMEDOUT;
+ if (pfd.revents & POLLERR)
+ return -EIO;
+ return 0;
}
-out:
- return err;
}
int udev_ctrl_send_set_log_level(struct udev_ctrl *uctrl, int priority, int timeout) {