]> sourceware.org Git - lvm2.git/blame - daemons/common/daemon-client.c
Parse the incoming config tree in daemon-server.c, providing the
[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>
30896326 8#include <errno.h> // ENOMEM
92658f56
PR
9
10daemon_handle daemon_open(daemon_info i) {
11 daemon_handle h;
12 struct sockaddr_un sockaddr;
30896326 13 if ((h.socket_fd = socket(PF_UNIX, SOCK_STREAM /* | SOCK_NONBLOCK */, 0)) < 0) {
92658f56
PR
14 perror("socket");
15 goto error;
16 }
17 memset(&sockaddr, 0, sizeof(sockaddr));
55e30071 18 fprintf(stderr, "[C] connecting to %s\n", i.socket);
92658f56
PR
19 strcpy(sockaddr.sun_path, i.socket);
20 sockaddr.sun_family = AF_UNIX;
21 if (connect(h.socket_fd,(struct sockaddr *) &sockaddr, sizeof(sockaddr))) {
22 perror("connect");
23 goto error;
24 }
25 h.protocol = 0;
26 return h;
27error:
28 if (h.socket_fd >= 0)
29 close(h.socket_fd);
30 h.socket_fd = -1;
31 return h;
32}
33
34daemon_reply daemon_send(daemon_handle h, daemon_request rq)
35{
36 daemon_reply reply;
37 assert(h.socket_fd >= 0);
38
39 if (!rq.buffer) {
40 /* TODO: build the buffer from rq.cft */
41 }
42
43 assert(rq.buffer);
44 write_buffer(h.socket_fd, rq.buffer, strlen(rq.buffer));
45
46 if (read_buffer(h.socket_fd, &reply.buffer)) {
47 /* TODO: parse reply.buffer into reply.cft */
48 } else
49 reply.error = 1;
50
51 return reply;
52}
53
30896326
PR
54daemon_reply daemon_send_simple(daemon_handle h, char *id, ...)
55{
56 va_list ap;
57 va_start(ap, id);
58 daemon_request rq = { .buffer = format_buffer(id, ap) };
59
60 if (!rq.buffer) {
61 daemon_reply err = { .error = ENOMEM, .buffer = NULL, .cft = NULL };
62 return err;
63 }
64
65 daemon_reply repl = daemon_send(h, rq);
66 dm_free(rq.buffer);
67 return repl;
68}
69
70void daemon_close(daemon_handle h)
71{
92658f56 72}
This page took 0.028246 seconds and 5 git commands to generate.