diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-05-19 19:48:55 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-05-19 19:48:55 +0200 |
commit | 92a217d0be3dd3f19eeb8dfd883d9ce4bfed7366 (patch) | |
tree | 26adbd8051d07fc7aed94b69465c13a64242b683 /src/mds-server | |
parent | begin on base for servers (diff) | |
download | mds-92a217d0be3dd3f19eeb8dfd883d9ce4bfed7366.tar.gz mds-92a217d0be3dd3f19eeb8dfd883d9ce4bfed7366.tar.bz2 mds-92a217d0be3dd3f19eeb8dfd883d9ce4bfed7366.tar.xz |
m + add --alarm= options
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/mds-server')
-rw-r--r-- | src/mds-server/mds-server.c | 59 | ||||
-rw-r--r-- | src/mds-server/mds-server.h | 8 |
2 files changed, 45 insertions, 22 deletions
diff --git a/src/mds-server/mds-server.c b/src/mds-server/mds-server.c index 0ad7736..55db770 100644 --- a/src/mds-server/mds-server.c +++ b/src/mds-server/mds-server.c @@ -63,7 +63,6 @@ int main(int argc_, char** argv_) int unparsed_args_ptr = 1; char* unparsed_args[ARGC_LIMIT + LIBEXEC_ARGC_EXTRA_LIMIT + 1]; int i; - pthread_t slave_thread; #if (LIBEXEC_ARGC_EXTRA_LIMIT < 3) # error LIBEXEC_ARGC_EXTRA_LIMIT is too small, need at least 3. @@ -104,6 +103,8 @@ int main(int argc_, char** argv_) } else if (strequals(arg, "--re-exec")) /* Re-exec state-marshal. */ reexec = 1; + else if (startswith(arg, "--alarm=")) /* Schedule an alarm signal for forced abort. */ + alarm((unsigned)min(atoi(arg + strlen("--alarm=")), 60)); /* At most 1 minute. */ else /* Not recognised, it is probably for another server. */ unparsed_args[unparsed_args_ptr++] = arg; @@ -183,28 +184,9 @@ int main(int argc_, char** argv_) /* Accepting incoming connections. */ while (running && (terminating == 0)) - { - /* Accept connection. */ - int client_fd = accept(socket_fd, NULL, NULL); - if (client_fd >= 0) - { - /* Increase number of running slaves. */ - with_mutex (slave_mutex, running_slaves++;); - - /* Start slave thread. */ - create_slave(&slave_thread, client_fd); - } - else - /* Handle errors and shutdown. */ - if ((errno == EINTR) && terminating) /* Interrupted for termination. */ - goto terminate; - else if ((errno == ECONNABORTED) || (errno == EINVAL)) /* Closing. */ - running = 0; - else if (errno != EINTR) /* Error. */ - perror(*argv); - } + if (accept_connection(socket_fd) == 1) + break; - terminate: if (reexecing) goto reexec; @@ -233,6 +215,39 @@ int main(int argc_, char** argv_) /** + * Accept an incoming and start a slave thread for it + * + * @param socket_fd The file descriptor of the server socket + * @return Zero normally, 1 if terminating + */ +int accept_connection(int socket_fd) +{ + pthread_t slave_thread; + int client_fd; + + /* Accept connection. */ + client_fd = accept(socket_fd, NULL, NULL); + if (client_fd >= 0) + { + /* Increase number of running slaves. */ + with_mutex (slave_mutex, running_slaves++;); + + /* Start slave thread. */ + create_slave(&slave_thread, client_fd); + } + else + /* Handle errors and shutdown. */ + if ((errno == EINTR) && terminating) /* Interrupted for termination. */ + return 1; + else if ((errno == ECONNABORTED) || (errno == EINVAL)) /* Closing. */ + running = 0; + else if (errno != EINTR) /* Error. */ + perror(*argv); + return 0; +} + + +/** * Master function for slave threads * * @param data Input data diff --git a/src/mds-server/mds-server.h b/src/mds-server/mds-server.h index 8154807..19f3044 100644 --- a/src/mds-server/mds-server.h +++ b/src/mds-server/mds-server.h @@ -25,6 +25,14 @@ /** + * Accept an incoming and start a slave thread for it + * + * @param socket_fd The file descriptor of the server socket + * @return Zero normally, 1 if terminating + */ +int accept_connection(int socket_fd); + +/** * Master function for slave threads * * @param data Input data |