aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mds-base.c10
-rw-r--r--src/mds-server/mds-server.c59
-rw-r--r--src/mds-server/mds-server.h8
3 files changed, 51 insertions, 26 deletions
diff --git a/src/mds-base.c b/src/mds-base.c
index 433564e..ede29c3 100644
--- a/src/mds-base.c
+++ b/src/mds-base.c
@@ -49,6 +49,10 @@ int socket_fd = -1;
*/
static int parse_cmdline(void)
{
+#if (LIBEXEC_ARGC_EXTRA_LIMIT < 2)
+# error LIBEXEC_ARGC_EXTRA_LIMIT is too small, need at least 2.
+#endif
+
int i;
for (i = 1; i < argc; i++)
{
@@ -64,6 +68,8 @@ static int parse_cmdline(void)
}
else if (strequals(arg, "--re-exec")) /* Re-exec state-marshal. */
is_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. */
}
if (is_reexec)
{
@@ -117,10 +123,6 @@ int main(int argc_, char** argv_)
{
int r;
-#if (LIBEXEC_ARGC_EXTRA_LIMIT < 2)
-# error LIBEXEC_ARGC_EXTRA_LIMIT is too small, need at least 2.
-#endif
-
argc = argc_;
argv = argv_;
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