+static int read_command(int fd, char **result)
+{
+ int ret;
+ char buf[4096];
+ char *command = NULL;
+
+ for (;;) {
+ size_t numbytes;
+ char *p;
+
+ ret = recv_buffer(fd, buf, sizeof(buf));
+ if (ret < 0)
+ goto out;
+ if (!ret)
+ break;
+ numbytes = ret;
+ ret = -E_COMMAND_SYNTAX;
+ if (command && numbytes + strlen(command) > MAX_COMMAND_LEN) /* DOS */
+ goto out;
+ command = para_strcat(command, buf);
+ p = strstr(command, EOC_MSG);
+ if (p) {
+ *p = '\0';
+ break;
+ }
+ }
+ ret = command? 1 : -E_COMMAND_SYNTAX;
+out:
+ if (ret < 0)
+ free(command);
+ else
+ *result = command;
+ return ret;
+
+}
+
+static void reset_signals(void)
+{
+ para_sigaction(SIGCHLD, SIG_IGN);
+ para_sigaction(SIGINT, SIG_DFL);
+ para_sigaction(SIGTERM, SIG_DFL);
+ para_sigaction(SIGHUP, SIG_DFL);
+}
+