mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
Parse the incoming config tree in daemon-server.c, providing the
daemon-specific handler with a struct config_tree pointer to look things up in.
This commit is contained in:
parent
9925977b07
commit
55e300716f
@ -15,7 +15,7 @@ daemon_handle daemon_open(daemon_info i) {
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
memset(&sockaddr, 0, sizeof(sockaddr));
|
memset(&sockaddr, 0, sizeof(sockaddr));
|
||||||
fprintf(stderr, "connecting to %s\n", i.socket);
|
fprintf(stderr, "[C] connecting to %s\n", i.socket);
|
||||||
strcpy(sockaddr.sun_path, i.socket);
|
strcpy(sockaddr.sun_path, i.socket);
|
||||||
sockaddr.sun_family = AF_UNIX;
|
sockaddr.sun_family = AF_UNIX;
|
||||||
if (connect(h.socket_fd,(struct sockaddr *) &sockaddr, sizeof(sockaddr))) {
|
if (connect(h.socket_fd,(struct sockaddr *) &sockaddr, sizeof(sockaddr))) {
|
||||||
|
@ -107,7 +107,7 @@ static int _open_socket(daemon_state s)
|
|||||||
fprintf(stderr, "setting CLOEXEC on socket fd %d failed: %s\n", fd, strerror(errno));
|
fprintf(stderr, "setting CLOEXEC on socket fd %d failed: %s\n", fd, strerror(errno));
|
||||||
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
|
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
|
||||||
|
|
||||||
fprintf(stderr, "creating %s\n", s.socket_path);
|
fprintf(stderr, "[D] creating %s\n", s.socket_path);
|
||||||
memset(&sockaddr, 0, sizeof(sockaddr));
|
memset(&sockaddr, 0, sizeof(sockaddr));
|
||||||
strcpy(sockaddr.sun_path, s.socket_path);
|
strcpy(sockaddr.sun_path, s.socket_path);
|
||||||
sockaddr.sun_family = AF_UNIX;
|
sockaddr.sun_family = AF_UNIX;
|
||||||
@ -213,8 +213,10 @@ void *client_thread(void *baton)
|
|||||||
if (!read_buffer(b->client.socket_fd, &req.buffer))
|
if (!read_buffer(b->client.socket_fd, &req.buffer))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
/* TODO parse the buffer into req.cft */
|
req.cft = create_config_tree_from_string(req.buffer);
|
||||||
response res = b->s.handler(b->s, b->client, req);
|
response res = b->s.handler(b->s, b->client, req);
|
||||||
|
destroy_config_tree(req.cft);
|
||||||
|
dm_free(req.buffer);
|
||||||
|
|
||||||
if (!res.buffer) {
|
if (!res.buffer) {
|
||||||
/* TODO fill in the buffer from res.cft */
|
/* TODO fill in the buffer from res.cft */
|
||||||
@ -223,7 +225,6 @@ void *client_thread(void *baton)
|
|||||||
write_buffer(b->client.socket_fd, res.buffer, strlen(res.buffer));
|
write_buffer(b->client.socket_fd, res.buffer, strlen(res.buffer));
|
||||||
|
|
||||||
free(res.buffer);
|
free(res.buffer);
|
||||||
free(req.buffer);
|
|
||||||
}
|
}
|
||||||
fail:
|
fail:
|
||||||
/* TODO what should we really do here? */
|
/* TODO what should we really do here? */
|
||||||
|
@ -26,13 +26,13 @@ typedef struct {
|
|||||||
} client_handle;
|
} client_handle;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct config_node *cft;
|
struct config_tree *cft;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
} request;
|
} request;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int error;
|
int error;
|
||||||
struct config_node *cft;
|
struct config_tree *cft;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
} response;
|
} response;
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ typedef struct {
|
|||||||
static response handler(daemon_state s, client_handle h, request r)
|
static response handler(daemon_state s, client_handle h, request r)
|
||||||
{
|
{
|
||||||
response res;
|
response res;
|
||||||
fprintf(stderr, "---- server obtained:\n%s\n----------------------\n", r.buffer);
|
fprintf(stderr, "[D] REQUEST: %s\n", find_config_str(r.cft->root, "request", "NONE"));
|
||||||
res.error = 1;
|
res.error = 1;
|
||||||
res.buffer = strdup("hey hey.\n\n");
|
res.buffer = strdup("hey hey.\n\n");
|
||||||
return res;
|
return res;
|
||||||
|
@ -5,7 +5,7 @@ int main() {
|
|||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 5; ++i ) {
|
for (i = 0; i < 5; ++i ) {
|
||||||
daemon_reply reply = daemon_send_simple(h, "hello world", "param = %d", 3, NULL);
|
daemon_reply reply = daemon_send_simple(h, "hello world", "param = %d", 3, NULL);
|
||||||
fprintf(stderr, "daemon says: %s\n", reply.buffer);
|
fprintf(stderr, "[C] obtained: %s\n", reply.buffer);
|
||||||
}
|
}
|
||||||
daemon_close(h);
|
daemon_close(h);
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user