1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +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:
Petr Rockai 2011-06-27 13:46:45 +00:00
parent 9925977b07
commit 55e300716f
5 changed files with 9 additions and 8 deletions

View File

@ -15,7 +15,7 @@ daemon_handle daemon_open(daemon_info i) {
goto error;
}
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);
sockaddr.sun_family = AF_UNIX;
if (connect(h.socket_fd,(struct sockaddr *) &sockaddr, sizeof(sockaddr))) {

View File

@ -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));
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));
strcpy(sockaddr.sun_path, s.socket_path);
sockaddr.sun_family = AF_UNIX;
@ -213,8 +213,10 @@ void *client_thread(void *baton)
if (!read_buffer(b->client.socket_fd, &req.buffer))
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);
destroy_config_tree(req.cft);
dm_free(req.buffer);
if (!res.buffer) {
/* 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));
free(res.buffer);
free(req.buffer);
}
fail:
/* TODO what should we really do here? */

View File

@ -26,13 +26,13 @@ typedef struct {
} client_handle;
typedef struct {
struct config_node *cft;
struct config_tree *cft;
char *buffer;
} request;
typedef struct {
int error;
struct config_node *cft;
struct config_tree *cft;
char *buffer;
} response;

View File

@ -7,7 +7,7 @@ typedef struct {
static response handler(daemon_state s, client_handle h, request r)
{
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.buffer = strdup("hey hey.\n\n");
return res;

View File

@ -5,7 +5,7 @@ int main() {
int i;
for (i = 0; i < 5; ++i ) {
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);
return 0;