udev-ctrl.c revision 25568304d2cbe95720a336acfee2c7bc0e945a35
/*
* libudev - interface to udev device information
*
* Copyright (C) 2008 Kay Sievers <kay@vrfy.org>
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*/
#include <errno.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <poll.h>
#include "socket-util.h"
#include "formats-util.h"
#include "udev.h"
/* wire protocol magic must match */
#define UDEV_CTRL_MAGIC 0xdead1dea
enum udev_ctrl_msg_type {
};
struct udev_ctrl_msg_wire {
char version[16];
unsigned int magic;
enum udev_ctrl_msg_type type;
union {
int intval;
char buf[256];
};
};
struct udev_ctrl_msg {
int refcount;
struct udev_ctrl_connection *conn;
struct udev_ctrl_msg_wire ctrl_msg_wire;
};
struct udev_ctrl {
int refcount;
int sock;
union sockaddr_union saddr;
bool bound;
bool cleanup_socket;
bool connected;
};
struct udev_ctrl_connection {
int refcount;
int sock;
};
const int on = 1;
int r;
return NULL;
if (fd < 0) {
return NULL;
}
} else {
}
/*
* FIXME: remove it as soon as we can depend on this:
*/
if (r < 0)
return uctrl;
}
}
int err;
}
if (err < 0) {
return err;
}
if (err < 0) {
return err;
}
uctrl->cleanup_socket = true;
}
return 0;
}
}
if (uctrl)
return uctrl;
}
}
return NULL;
}
return 0;
if (uctrl->cleanup_socket)
return 0;
}
return -EINVAL;
}
struct udev_ctrl_connection *conn;
const int on = 1;
int r;
return NULL;
goto err;
}
/* check peer credential of connection */
if (r < 0) {
log_error_errno(r, "unable to receive credentials of ctrl connection: %m");
goto err;
}
goto err;
}
/* enable receiving of the sender credentials in the messages */
if (r < 0)
return conn;
err:
return NULL;
}
return NULL;
return conn;
}
}
return NULL;
}
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;
else
goto out;
}
}
goto out;
}
/* wait for peer message handling or disconnect */
for (;;) {
int r;
if (r < 0) {
continue;
break;
}
break;
}
if (r == 0)
break;
}
out:
return err;
}
}
}
}
}
}
}
}
}
struct udev_ctrl_msg *uctrl_msg;
.msg_iovlen = 1,
.msg_control = cred_msg,
.msg_controllen = sizeof(cred_msg),
};
return NULL;
/* wait for the incoming message */
for (;;) {
int r;
if (r < 0) {
continue;
goto err;
} else if (r == 0) {
log_error("timeout waiting for ctrl message");
goto err;
} else {
goto err;
}
}
break;
}
if (size < 0) {
goto err;
}
log_error("no sender credentials received, message ignored");
goto err;
}
goto err;
}
goto err;
}
return uctrl_msg;
err:
return NULL;
}
}
return NULL;
}
return -1;
}
return 1;
return -1;
}
return 1;
return -1;
}
return 1;
return -1;
}
return NULL;
}
return -1;
}
return 1;
return -1;
}
return 1;
return -1;
}