]> sourceware.org Git - lvm2.git/blame - daemons/common/daemon-client.c
Call daemon_close before exit in the testclient.
[lvm2.git] / daemons / common / daemon-client.c
CommitLineData
92658f56
PR
1#include "daemon-client.h"
2#include "daemon-shared.h"
3#include <sys/un.h>
4#include <sys/socket.h>
5#include <string.h>
6#include <stdio.h>
7#include <assert.h>
8
9daemon_handle daemon_open(daemon_info i) {
10 daemon_handle h;
11 struct sockaddr_un sockaddr;
12 if ((h.socket_fd = socket(PF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0)) < 0) {
13 perror("socket");
14 goto error;
15 }
16 memset(&sockaddr, 0, sizeof(sockaddr));
17 fprintf(stderr, "connecting to %s\n", i.socket);
18 strcpy(sockaddr.sun_path, i.socket);
19 sockaddr.sun_family = AF_UNIX;
20 if (connect(h.socket_fd,(struct sockaddr *) &sockaddr, sizeof(sockaddr))) {
21 perror("connect");
22 goto error;
23 }
24 h.protocol = 0;
25 return h;
26error:
27 if (h.socket_fd >= 0)
28 close(h.socket_fd);
29 h.socket_fd = -1;
30 return h;
31}
32
33daemon_reply daemon_send(daemon_handle h, daemon_request rq)
34{
35 daemon_reply reply;
36 assert(h.socket_fd >= 0);
37
38 if (!rq.buffer) {
39 /* TODO: build the buffer from rq.cft */
40 }
41
42 assert(rq.buffer);
43 write_buffer(h.socket_fd, rq.buffer, strlen(rq.buffer));
44
45 if (read_buffer(h.socket_fd, &reply.buffer)) {
46 /* TODO: parse reply.buffer into reply.cft */
47 } else
48 reply.error = 1;
49
50 return reply;
51}
52
53void daemon_close(daemon_handle h) {
54}
This page took 0.028135 seconds and 5 git commands to generate.