- para_sigaction(SIGCHLD, SIG_IGN);
- para_sigaction(SIGINT, SIG_DFL);
- para_sigaction(SIGTERM, SIG_DFL);
- para_sigaction(SIGHUP, SIG_DFL);
+ int ret, i;
+ char *p, *end;
+ struct server_command *cmd = NULL;
+ const struct lls_command *lcmd = NULL;
+ unsigned perms;
+ struct lls_parse_result *lpr;
+ char *errctx;
+
+ if (iov->iov_base == NULL || iov->iov_len == 0)
+ return -ERRNO_TO_PARA_ERROR(EINVAL);
+ p = iov->iov_base;
+ p[iov->iov_len - 1] = '\0'; /* just to be sure */
+
+ ret = lls(lls_lookup_subcmd(p, server_cmd_suite, &errctx));
+ if (ret >= 0) {
+ perms = server_command_perms[ret];
+ if ((perms & cc->u->perms) != perms)
+ return -E_PERM;
+ lcmd = lls_cmd(ret, server_cmd_suite);
+ } else {
+ cmd = get_cmd_ptr(p, NULL);
+ if (!cmd) {
+ send_errctx(cc, errctx);
+ return ret;
+ }
+ perms = cmd->perms;
+ ret = check_perms(cc->u->perms, cmd);
+ if (ret < 0)
+ return ret;
+ }
+ end = iov->iov_base + iov->iov_len;
+ for (i = 0; p < end; i++)
+ p += strlen(p) + 1;
+ cc->argc = i;
+ cc->argv = para_malloc((cc->argc + 1) * sizeof(char *));
+ for (i = 0, p = iov->iov_base; p < end; i++) {
+ cc->argv[i] = para_strdup(p);
+ p += strlen(p) + 1;
+ }
+ cc->argv[cc->argc] = NULL;
+ PARA_NOTICE_LOG("calling com_%s() for %s@%s\n", lcmd?
+ lls_command_name(lcmd) : cmd->name, cc->u->name, peername);
+ if (lcmd) {
+ ret = lls(lls_parse(cc->argc, cc->argv, lcmd, &lpr, &errctx));
+ if (ret >= 0) {
+ const struct server_cmd_user_data *ud = lls_user_data(lcmd);
+ ret = ud->handler(cc, lpr);
+ lls_free_parse_result(lpr, lcmd);
+ } else
+ send_errctx(cc, errctx);
+ } else {
+ ret = cmd->handler(cc);
+ }
+ free_argv(cc->argv);
+ mutex_lock(mmd_mutex);
+ mmd->num_commands++;
+ if (ret >= 0 && (perms & AFS_WRITE))
+ mmd->events++;
+ mutex_unlock(mmd_mutex);
+ return ret;