From bd9a0b0fbed2da4788363d9ce701302a2a021803 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 6 May 2014 17:58:31 +0200 Subject: misc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-server.c | 63 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 23 deletions(-) (limited to 'src/mds-server.c') diff --git a/src/mds-server.c b/src/mds-server.c index e0ef547..6f0764d 100644 --- a/src/mds-server.c +++ b/src/mds-server.c @@ -99,6 +99,11 @@ static fd_table_t client_map; */ static linked_list_t client_list; +/** + * The next free ID for a client + */ +static uint64_t next_id = 1; + /** @@ -476,6 +481,7 @@ void* slave_loop(void* data) information->list_entry = entry; information->socket_fd = socket_fd; information->open = 1; + information->id = 0; if (mds_message_initialise(&(information->message))) { perror(*argv); @@ -489,21 +495,11 @@ void* slave_loop(void* data) /* Make the server update without all slaves dying on SIGUSR1. */ - { - struct sigaction action; - sigset_t sigset; - - sigemptyset(&sigset); - action.sa_handler = sigusr1_trap; - action.sa_mask = sigset; - action.sa_flags = 0; - - if (sigaction(SIGUSR1, &action, NULL) < 0) - { - perror(*argv); - goto fail; - } - } + if (xsigaction(SIGUSR1, sigusr1_trap) < 0) + { + perror(*argv); + goto fail; + } /* Fetch messages from the slave. */ @@ -512,9 +508,7 @@ void* slave_loop(void* data) { r = mds_message_read(&(information->message), socket_fd); if (r == 0) - { - /* TODO */ - } + message_received(information); else if (r == -2) { @@ -526,9 +520,7 @@ void* slave_loop(void* data) r = mds_message_read(&(information->message), socket_fd); information->open = 0; if (r == 0) - { - /* TODO */ - } + message_received(information); /* Connection closed. */ break; } @@ -582,6 +574,25 @@ void* slave_loop(void* data) } +/** + * Perform actions that should be taken when + * a message has been received from a client + * + * @param client The client has sent a message + */ +void message_received(client_t* client) +{ + mds_message_t message = client->message; + size_t i; + + for (i = 0; i < message.header_count; i++) + { + char* header = message.headers[i]; + /* TODO */ + } +} + + /** * Exec into the mdsinitrc script * @@ -729,8 +740,9 @@ int marshal_server(int fd) /* Tell the new version of the program what version of the program it is marshalling. */ buf_set_next(state_buf_, int, MDS_SERVER_VARS_VERSION); - /* Marshal the program's running–exit state. */ + /* Marshal the miscellaneous state data. */ buf_set_next(state_buf_, sig_atomic_t, running); + buf_set_next(state_buf_, uint64_t, next_id); /* Tell the program how large the marshalled client list is and how any clients are marshalled. */ buf_set_next(state_buf_, size_t, list_size); @@ -755,6 +767,7 @@ int marshal_server(int fd) buf_set_next(state_buf_, ssize_t, value->list_entry); buf_set_next(state_buf_, int, value->socket_fd); buf_set_next(state_buf_, int, value->open); + buf_set_next(state_buf_, uint64_t, value->id); /* Marshal the message. */ mds_message_marshal(&(value->message), state_buf_, 1); state_buf_ += msg_size / sizeof(char); @@ -903,8 +916,9 @@ int unmarshal_server(int fd) /* buf_get(state_buf_, int, 0, MDS_SERVER_VARS_VERSION); */ buf_next(state_buf_, int, 1); - /* Unmarshal the program's running–exit state. */ + /* Unmarshal the miscellaneous state data. */ buf_get_next(state_buf_, sig_atomic_t, running); + buf_get_next(state_buf_, uint64_t, next_id); /* Get the marshalled size of the client list and how any clients that are marshalled. */ buf_get_next(state_buf_, size_t, list_size); @@ -932,12 +946,14 @@ int unmarshal_server(int fd) buf_get_next(state_buf_, ssize_t, value->list_entry); buf_get_next(state_buf_, int, value->socket_fd); buf_get_next(state_buf_, int, value->open); + buf_set_next(state_buf_, uint64_t, value->id); /* Unmarshal the message. */ if (mds_message_unmarshal(&(value->message), state_buf_)) { perror(*argv); mds_message_destroy(&(value->message)); free(value); + buf_prev(state_buf_, uint64_t, 1); buf_prev(state_buf_, int, 2); buf_prev(state_buf_, size_t, 3); goto clients_fail; @@ -960,6 +976,7 @@ int unmarshal_server(int fd) msg_size = ((size_t*)state_buf_)[1]; buf_next(state_buf_, size_t, 3); buf_next(state_buf_, int, 2); + buf_next(state_buf_, uint64_t, 1); state_buf_ += msg_size / sizeof(char); } break; -- cgit v1.2.3-70-g09d2