- struct writer_node_group *g = para_calloc(sizeof(struct writer_node_group));
- g->num_writers = num_writers;
- g->writer_nodes = para_calloc(num_writers
- * sizeof(struct writer_node));
- g->task.post_select = wng_post_select;
- g->task.pre_select = wng_pre_select;
- return g;
+ int ret, writer_num, argc;
+ char **argv = NULL, *errctx = NULL;
+ const struct lls_command *cmd;
+
+ if (!wa || !*wa) {
+ writer_num = default_writer_id();
+ cmd = WRITE_CMD(writer_num);
+ argv = para_malloc(2 * sizeof(char *));
+ argc = 1;
+ argv[0] = para_strdup(lls_command_name(cmd));
+ argv[1] = NULL;
+ goto parse;
+ }
+ ret = create_argv(wa, " \t\n", &argv);
+ if (ret < 0)
+ goto fail;
+ argc = ret;
+ ret = lls(lls_lookup_subcmd(argv[0], write_cmd_suite, &errctx));
+ if (ret < 0)
+ goto free_argv;
+ writer_num = ret;
+ cmd = WRITE_CMD(writer_num);
+ if (!writer_supported(writer_num)) {
+ ret = -ERRNO_TO_PARA_ERROR(EINVAL);
+ errctx = make_message("%s writer is not supported",
+ lls_command_name(cmd));
+ goto free_argv;
+ }
+parse:
+ ret = lls(lls_parse(argc, argv, cmd, lprp, &errctx));
+ if (ret >= 0)
+ ret = writer_num;
+free_argv:
+ free_argv(argv);
+ if (ret >= 0)
+ return ret;
+fail:
+ if (errctx)
+ PARA_ERROR_LOG("%s\n", errctx);
+ free(errctx);
+ PARA_EMERG_LOG("%s\n", para_strerror(-ret));
+ exit(EXIT_FAILURE);