udev-ctrl.c revision ad29a9f14fa8b1932c0e418bfcf1c10ce6a35a33
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson/*
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson * libudev - interface to udev device information
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson *
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson * Copyright (C) 2008 Kay Sievers <kay.sievers@vrfy.org>
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson *
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson * This library is free software; you can redistribute it and/or
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson * modify it under the terms of the GNU Lesser General Public
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson * License as published by the Free Software Foundation; either
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac * version 2.1 of the License, or (at your option) any later version.
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac */
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson#include <errno.h>
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson#include <stdio.h>
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson#include <stdlib.h>
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac#include <stddef.h>
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac#include <string.h>
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac#include <unistd.h>
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac#include <sys/types.h>
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson#include <sys/poll.h>
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson#include <sys/socket.h>
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson#include <sys/un.h>
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson#include "udev.h"
df1eaa96329d5ad15516c5045e1972d6e1baeda1jvergara
7c6d2cd054f573532aa1a421840937c100490ce1JnRouvignac/* wire protocol magic must match */
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson#define UDEV_CTRL_MAGIC 0xdead1dea
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonenum udev_ctrl_msg_type {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson UDEV_CTRL_UNKNOWN,
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson UDEV_CTRL_SET_LOG_LEVEL,
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson UDEV_CTRL_STOP_EXEC_QUEUE,
7c6d2cd054f573532aa1a421840937c100490ce1JnRouvignac UDEV_CTRL_START_EXEC_QUEUE,
7c6d2cd054f573532aa1a421840937c100490ce1JnRouvignac UDEV_CTRL_RELOAD,
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson UDEV_CTRL_SET_ENV,
82e58c0435a15201b1208d46c295337542638d9adugan UDEV_CTRL_SET_CHILDREN_MAX,
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson UDEV_CTRL_PING,
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson UDEV_CTRL_EXIT,
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson};
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonstruct udev_ctrl_msg_wire {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson char version[16];
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson unsigned int magic;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson enum udev_ctrl_msg_type type;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson union {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson int intval;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson char buf[256];
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson };
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson};
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonstruct udev_ctrl_msg {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson int refcount;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson struct udev_ctrl_connection *conn;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson struct udev_ctrl_msg_wire ctrl_msg_wire;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson};
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonstruct udev_ctrl {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson int refcount;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson struct udev *udev;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson int sock;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson struct sockaddr_un saddr;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson socklen_t addrlen;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson bool bound;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson bool cleanup_socket;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson bool connected;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson};
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonstruct udev_ctrl_connection {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson int refcount;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson struct udev_ctrl *uctrl;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson int sock;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson};
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonstruct udev_ctrl *udev_ctrl_new_from_fd(struct udev *udev, int fd)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson struct udev_ctrl *uctrl;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
df1eaa96329d5ad15516c5045e1972d6e1baeda1jvergara uctrl = calloc(1, sizeof(struct udev_ctrl));
82e58c0435a15201b1208d46c295337542638d9adugan if (uctrl == NULL)
82e58c0435a15201b1208d46c295337542638d9adugan return NULL;
82e58c0435a15201b1208d46c295337542638d9adugan uctrl->refcount = 1;
82e58c0435a15201b1208d46c295337542638d9adugan uctrl->udev = udev;
df1eaa96329d5ad15516c5045e1972d6e1baeda1jvergara
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (fd < 0) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson uctrl->sock = socket(AF_LOCAL, SOCK_SEQPACKET|SOCK_NONBLOCK|SOCK_CLOEXEC, 0);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (uctrl->sock < 0) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson err(udev, "error getting socket: %m\n");
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson udev_ctrl_unref(uctrl);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return NULL;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson }
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson } else {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson uctrl->bound = true;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson uctrl->sock = fd;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson }
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson uctrl->saddr.sun_family = AF_LOCAL;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson util_strscpyl(uctrl->saddr.sun_path, sizeof(uctrl->saddr.sun_path),
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson udev_get_run_path(udev), "/control", NULL);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson uctrl->addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(uctrl->saddr.sun_path);
82e58c0435a15201b1208d46c295337542638d9adugan return uctrl;
82e58c0435a15201b1208d46c295337542638d9adugan}
df1eaa96329d5ad15516c5045e1972d6e1baeda1jvergara
82e58c0435a15201b1208d46c295337542638d9aduganstruct udev_ctrl *udev_ctrl_new(struct udev *udev)
82e58c0435a15201b1208d46c295337542638d9adugan{
82e58c0435a15201b1208d46c295337542638d9adugan return udev_ctrl_new_from_fd(udev, -1);
82e58c0435a15201b1208d46c295337542638d9adugan}
82e58c0435a15201b1208d46c295337542638d9adugan
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonint udev_ctrl_enable_receiving(struct udev_ctrl *uctrl)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson int err;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (!uctrl->bound) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson err = bind(uctrl->sock, (struct sockaddr *)&uctrl->saddr, uctrl->addrlen);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (err < 0 && errno == EADDRINUSE) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson unlink(uctrl->saddr.sun_path);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson err = bind(uctrl->sock, (struct sockaddr *)&uctrl->saddr, uctrl->addrlen);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson }
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson if (err < 0) {
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson err = -errno;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson err(uctrl->udev, "bind failed: %m\n");
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson return err;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson }
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson err = listen(uctrl->sock, 0);
7c6d2cd054f573532aa1a421840937c100490ce1JnRouvignac if (err < 0) {
7c6d2cd054f573532aa1a421840937c100490ce1JnRouvignac err = -errno;
7c6d2cd054f573532aa1a421840937c100490ce1JnRouvignac err(uctrl->udev, "listen failed: %m\n");
7c6d2cd054f573532aa1a421840937c100490ce1JnRouvignac return err;
7c6d2cd054f573532aa1a421840937c100490ce1JnRouvignac }
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
7c6d2cd054f573532aa1a421840937c100490ce1JnRouvignac uctrl->bound = true;
7c6d2cd054f573532aa1a421840937c100490ce1JnRouvignac uctrl->cleanup_socket = true;
7c6d2cd054f573532aa1a421840937c100490ce1JnRouvignac }
7c6d2cd054f573532aa1a421840937c100490ce1JnRouvignac return 0;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson}
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonstruct udev *udev_ctrl_get_udev(struct udev_ctrl *uctrl)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return uctrl->udev;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson}
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonstruct udev_ctrl *udev_ctrl_ref(struct udev_ctrl *uctrl)
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (uctrl == NULL)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return NULL;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson uctrl->refcount++;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return uctrl;
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson}
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilsonstruct udev_ctrl *udev_ctrl_unref(struct udev_ctrl *uctrl)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (uctrl == NULL)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return NULL;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson uctrl->refcount--;
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson if (uctrl->refcount > 0)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return uctrl;
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson if (uctrl->sock >= 0)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson close(uctrl->sock);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson free(uctrl);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return NULL;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson}
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonint udev_ctrl_cleanup(struct udev_ctrl *uctrl)
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (uctrl == NULL)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return 0;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (uctrl->cleanup_socket)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson unlink(uctrl->saddr.sun_path);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return 0;
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson}
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilsonint udev_ctrl_get_fd(struct udev_ctrl *uctrl)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (uctrl == NULL)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return -EINVAL;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return uctrl->sock;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson}
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilsonstruct udev_ctrl_connection *udev_ctrl_get_connection(struct udev_ctrl *uctrl)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson{
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson struct udev_ctrl_connection *conn;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson struct ucred ucred;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson socklen_t slen;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson const int on = 1;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson conn = calloc(1, sizeof(struct udev_ctrl_connection));
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (conn == NULL)
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson return NULL;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson conn->refcount = 1;
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson conn->uctrl = uctrl;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson conn->sock = accept4(uctrl->sock, NULL, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (conn->sock < 0) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (errno != EINTR)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson err(uctrl->udev, "unable to receive ctrl connection: %m\n");
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson goto err;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson }
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson /* check peer credential of connection */
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson slen = sizeof(ucred);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (getsockopt(conn->sock, SOL_SOCKET, SO_PEERCRED, &ucred, &slen) < 0) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson err(uctrl->udev, "unable to receive credentials of ctrl connection: %m\n");
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson goto err;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson }
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (ucred.uid > 0) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson err(uctrl->udev, "sender uid=%i, message ignored\n", ucred.uid);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson goto err;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson }
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson /* enable receiving of the sender credentials in the messages */
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson setsockopt(conn->sock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson udev_ctrl_ref(uctrl);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return conn;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonerr:
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (conn->sock >= 0)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson close(conn->sock);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson free(conn);
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson return NULL;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson}
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonstruct udev_ctrl_connection *udev_ctrl_connection_ref(struct udev_ctrl_connection *conn)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (conn == NULL)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return NULL;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson conn->refcount++;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return conn;
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson}
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilsonstruct udev_ctrl_connection *udev_ctrl_connection_unref(struct udev_ctrl_connection *conn)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (conn == NULL)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return NULL;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson conn->refcount--;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (conn->refcount > 0)
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson return conn;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (conn->sock >= 0)
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson close(conn->sock);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson udev_ctrl_unref(conn->uctrl);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson free(conn);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return NULL;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson}
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonstatic int ctrl_send(struct udev_ctrl *uctrl, enum udev_ctrl_msg_type type, int intval, const char *buf, int timeout)
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson struct udev_ctrl_msg_wire ctrl_msg_wire;
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson int err = 0;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson memset(&ctrl_msg_wire, 0x00, sizeof(struct udev_ctrl_msg_wire));
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson strcpy(ctrl_msg_wire.version, "udev-" VERSION);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson ctrl_msg_wire.magic = UDEV_CTRL_MAGIC;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson ctrl_msg_wire.type = type;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson if (buf != NULL)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson util_strscpy(ctrl_msg_wire.buf, sizeof(ctrl_msg_wire.buf), buf);
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson else
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson ctrl_msg_wire.intval = intval;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (!uctrl->connected) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (connect(uctrl->sock, (struct sockaddr *)&uctrl->saddr, uctrl->addrlen) < 0) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson err = -errno;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson goto out;
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson }
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson uctrl->connected = true;
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson }
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (send(uctrl->sock, &ctrl_msg_wire, sizeof(ctrl_msg_wire), 0) < 0) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson err = -errno;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson goto out;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson }
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson /* wait for peer message handling or disconnect */
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson for (;;) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson struct pollfd pfd[1];
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson int r;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson pfd[0].fd = uctrl->sock;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson pfd[0].events = POLLIN;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson r = poll(pfd, 1, timeout * 1000);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (r < 0) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (errno == EINTR)
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson continue;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson err = -errno;
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson break;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson }
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (r > 0 && pfd[0].revents & POLLERR) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson err = -EIO;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson break;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson }
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (r == 0)
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson err = -ETIMEDOUT;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson break;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson }
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonout:
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return err;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson}
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilsonint udev_ctrl_send_set_log_level(struct udev_ctrl *uctrl, int priority, int timeout)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson{
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson return ctrl_send(uctrl, UDEV_CTRL_SET_LOG_LEVEL, priority, NULL, timeout);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson}
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonint udev_ctrl_send_stop_exec_queue(struct udev_ctrl *uctrl, int timeout)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return ctrl_send(uctrl, UDEV_CTRL_STOP_EXEC_QUEUE, 0, NULL, timeout);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson}
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonint udev_ctrl_send_start_exec_queue(struct udev_ctrl *uctrl, int timeout)
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return ctrl_send(uctrl, UDEV_CTRL_START_EXEC_QUEUE, 0, NULL, timeout);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson}
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonint udev_ctrl_send_reload(struct udev_ctrl *uctrl, int timeout)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return ctrl_send(uctrl, UDEV_CTRL_RELOAD, 0, NULL, timeout);
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson}
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilsonint udev_ctrl_send_set_env(struct udev_ctrl *uctrl, const char *key, int timeout)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return ctrl_send(uctrl, UDEV_CTRL_SET_ENV, 0, key, timeout);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson}
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonint udev_ctrl_send_set_children_max(struct udev_ctrl *uctrl, int count, int timeout)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson{
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson return ctrl_send(uctrl, UDEV_CTRL_SET_CHILDREN_MAX, count, NULL, timeout);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson}
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonint udev_ctrl_send_ping(struct udev_ctrl *uctrl, int timeout)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return ctrl_send(uctrl, UDEV_CTRL_PING, 0, NULL, timeout);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson}
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonint udev_ctrl_send_exit(struct udev_ctrl *uctrl, int timeout)
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return ctrl_send(uctrl, UDEV_CTRL_EXIT, 0, NULL, timeout);
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson}
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonstruct udev_ctrl_msg *udev_ctrl_receive_msg(struct udev_ctrl_connection *conn)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson struct udev *udev = conn->uctrl->udev;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson struct udev_ctrl_msg *uctrl_msg;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson ssize_t size;
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson struct msghdr smsg;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson struct cmsghdr *cmsg;
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson struct iovec iov;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson struct ucred *cred;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson char cred_msg[CMSG_SPACE(sizeof(struct ucred))];
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson uctrl_msg = calloc(1, sizeof(struct udev_ctrl_msg));
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (uctrl_msg == NULL)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return NULL;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson uctrl_msg->refcount = 1;
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson uctrl_msg->conn = conn;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson udev_ctrl_connection_ref(conn);
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson /* wait for the incoming message */
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson for(;;) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson struct pollfd pfd[1];
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson int r;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson pfd[0].fd = conn->sock;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson pfd[0].events = POLLIN;
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson r = poll(pfd, 1, 10000);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (r < 0) {
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson if (errno == EINTR)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson continue;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson goto err;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson } else if (r == 0) {
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson err(udev, "timeout waiting for ctrl message\n");
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson goto err;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson } else {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (!(pfd[0].revents & POLLIN)) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson err(udev, "ctrl connection error: %m\n");
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson goto err;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson }
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson }
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson break;
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson }
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson iov.iov_base = &uctrl_msg->ctrl_msg_wire;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson iov.iov_len = sizeof(struct udev_ctrl_msg_wire);
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson memset(&smsg, 0x00, sizeof(struct msghdr));
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson smsg.msg_iov = &iov;
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson smsg.msg_iovlen = 1;
1a086715b3a300cb87695667ab6bc0ec72dded0eneil_a_wilson smsg.msg_control = cred_msg;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson smsg.msg_controllen = sizeof(cred_msg);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson size = recvmsg(conn->sock, &smsg, 0);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (size < 0) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson err(udev, "unable to receive ctrl message: %m\n");
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson goto err;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson }
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson cmsg = CMSG_FIRSTHDR(&smsg);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson cred = (struct ucred *) CMSG_DATA(cmsg);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (cmsg == NULL || cmsg->cmsg_type != SCM_CREDENTIALS) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson err(udev, "no sender credentials received, message ignored\n");
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson goto err;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson }
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (cred->uid != 0) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson err(udev, "sender uid=%i, message ignored\n", cred->uid);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson goto err;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson }
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
520c31a362826a22ded10aecc31dc9d75e07fbf2lutoff if (uctrl_msg->ctrl_msg_wire.magic != UDEV_CTRL_MAGIC) {
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson err(udev, "message magic 0x%08x doesn't match, ignore it\n", uctrl_msg->ctrl_msg_wire.magic);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson goto err;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson }
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson dbg(udev, "created ctrl_msg %p (%i)\n", uctrl_msg, uctrl_msg->ctrl_msg_wire.type);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return uctrl_msg;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonerr:
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson udev_ctrl_msg_unref(uctrl_msg);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return NULL;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson}
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonstruct udev_ctrl_msg *udev_ctrl_msg_ref(struct udev_ctrl_msg *ctrl_msg)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (ctrl_msg == NULL)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return NULL;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson ctrl_msg->refcount++;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return ctrl_msg;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson}
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
414c37b64ad781961cde03441c436051cf56d441neil_a_wilsonstruct udev_ctrl_msg *udev_ctrl_msg_unref(struct udev_ctrl_msg *ctrl_msg)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson{
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (ctrl_msg == NULL)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return NULL;
520c31a362826a22ded10aecc31dc9d75e07fbf2lutoff ctrl_msg->refcount--;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson if (ctrl_msg->refcount > 0)
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return ctrl_msg;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson dbg(ctrl_msg->conn->uctrl->udev, "release ctrl_msg %p\n", ctrl_msg);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson udev_ctrl_connection_unref(ctrl_msg->conn);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson free(ctrl_msg);
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson return NULL;
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson}
414c37b64ad781961cde03441c436051cf56d441neil_a_wilson
480256311ff1597d92043303772f072d8d67fb3ccoulbeckint udev_ctrl_get_set_log_level(struct udev_ctrl_msg *ctrl_msg)
480256311ff1597d92043303772f072d8d67fb3ccoulbeck{
480256311ff1597d92043303772f072d8d67fb3ccoulbeck if (ctrl_msg->ctrl_msg_wire.type == UDEV_CTRL_SET_LOG_LEVEL)
480256311ff1597d92043303772f072d8d67fb3ccoulbeck return ctrl_msg->ctrl_msg_wire.intval;
480256311ff1597d92043303772f072d8d67fb3ccoulbeck return -1;
480256311ff1597d92043303772f072d8d67fb3ccoulbeck}
480256311ff1597d92043303772f072d8d67fb3ccoulbeck
480256311ff1597d92043303772f072d8d67fb3ccoulbeckint udev_ctrl_get_stop_exec_queue(struct udev_ctrl_msg *ctrl_msg)
480256311ff1597d92043303772f072d8d67fb3ccoulbeck{
480256311ff1597d92043303772f072d8d67fb3ccoulbeck if (ctrl_msg->ctrl_msg_wire.type == UDEV_CTRL_STOP_EXEC_QUEUE)
480256311ff1597d92043303772f072d8d67fb3ccoulbeck return 1;
480256311ff1597d92043303772f072d8d67fb3ccoulbeck return -1;
480256311ff1597d92043303772f072d8d67fb3ccoulbeck}
480256311ff1597d92043303772f072d8d67fb3ccoulbeck
480256311ff1597d92043303772f072d8d67fb3ccoulbeckint udev_ctrl_get_start_exec_queue(struct udev_ctrl_msg *ctrl_msg)
520c31a362826a22ded10aecc31dc9d75e07fbf2lutoff{
480256311ff1597d92043303772f072d8d67fb3ccoulbeck if (ctrl_msg->ctrl_msg_wire.type == UDEV_CTRL_START_EXEC_QUEUE)
480256311ff1597d92043303772f072d8d67fb3ccoulbeck return 1;
480256311ff1597d92043303772f072d8d67fb3ccoulbeck return -1;
480256311ff1597d92043303772f072d8d67fb3ccoulbeck}
480256311ff1597d92043303772f072d8d67fb3ccoulbeck
480256311ff1597d92043303772f072d8d67fb3ccoulbeckint udev_ctrl_get_reload(struct udev_ctrl_msg *ctrl_msg)
480256311ff1597d92043303772f072d8d67fb3ccoulbeck{
480256311ff1597d92043303772f072d8d67fb3ccoulbeck if (ctrl_msg->ctrl_msg_wire.type == UDEV_CTRL_RELOAD)
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson return 1;
49026dcadd8edca32a2628f768a9e0d92a07996elutoff return -1;
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson}
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilsonconst char *udev_ctrl_get_set_env(struct udev_ctrl_msg *ctrl_msg)
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson{
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson if (ctrl_msg->ctrl_msg_wire.type == UDEV_CTRL_SET_ENV)
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson return ctrl_msg->ctrl_msg_wire.buf;
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson return NULL;
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson}
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilsonint udev_ctrl_get_set_children_max(struct udev_ctrl_msg *ctrl_msg)
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson{
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson if (ctrl_msg->ctrl_msg_wire.type == UDEV_CTRL_SET_CHILDREN_MAX)
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson return ctrl_msg->ctrl_msg_wire.intval;
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson return -1;
49026dcadd8edca32a2628f768a9e0d92a07996elutoff}
520c31a362826a22ded10aecc31dc9d75e07fbf2lutoff
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilsonint udev_ctrl_get_ping(struct udev_ctrl_msg *ctrl_msg)
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson{
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson if (ctrl_msg->ctrl_msg_wire.type == UDEV_CTRL_PING)
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson return 1;
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson return -1;
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson}
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilsonint udev_ctrl_get_exit(struct udev_ctrl_msg *ctrl_msg)
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson{
49026dcadd8edca32a2628f768a9e0d92a07996elutoff if (ctrl_msg->ctrl_msg_wire.type == UDEV_CTRL_EXIT)
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson return 1;
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson return -1;
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson}
1acdbf024a6066d97bbd1ef07094be83f649239fneil_a_wilson