udev-ctrl.c revision eff05270986a13e7de93ae16311f654d3f7c166f
/*
* 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 <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <unistd.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;
struct sockaddr_un saddr;
bool bound;
bool cleanup_socket;
bool connected;
};
struct udev_ctrl_connection {
int refcount;
int sock;
};
{
const int on = 1;
return NULL;
if (fd < 0) {
log_error("error getting socket: %m\n");
return NULL;
}
} else {
}
return uctrl;
}
{
}
{
int err;
}
if (err < 0) {
log_error("bind failed: %m\n");
return err;
}
if (err < 0) {
log_error("listen failed: %m\n");
return err;
}
uctrl->cleanup_socket = true;
}
return 0;
}
{
}
{
return NULL;
return uctrl;
}
{
return NULL;
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;
log_error("unable to receive ctrl connection: %m\n");
goto err;
}
/* check peer credential of connection */
if (r < 0) {
goto err;
}
goto err;
}
/* enable receiving of the sender credentials in the messages */
return conn;
err:
return NULL;
}
{
return NULL;
return conn;
}
{
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\n");
goto err;
} else {
log_error("ctrl connection error: %m\n");
goto err;
}
}
break;
}
if (size < 0) {
log_error("unable to receive ctrl message: %m\n");
goto err;
}
log_error("no sender credentials received, message ignored\n");
goto err;
}
goto err;
}
goto err;
}
return uctrl_msg;
err:
return NULL;
}
{
return NULL;
return ctrl_msg;
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;
}