int main(int argc, char *argv[]) { struct opal_prd_ctx _ctx; enum action action; int rc; ctx = &_ctx; memset(ctx, 0, sizeof(*ctx)); ctx->vlog = pr_log_stdio; ctx->use_syslog = true; /* Parse options */ for (;;) { int c; c = getopt_long(argc, argv, "f:p:dhs", opal_diag_options, NULL); if (c == -1) break; switch (c) { case 'f': ctx->hbrt_file_name = optarg; break; case 'd': ctx->debug = true; break; case 'p': ctx->pnor.path = strndup(optarg, PATH_MAX); break; case 's': ctx->use_syslog = false; break; case 'h': usage(argv[0]); return EXIT_SUCCESS; case 'v': print_version(); return EXIT_SUCCESS; case '?': default: usage(argv[0]); return EXIT_FAILURE; } } if (optind < argc) { rc = parse_action(argv[optind], &action); if (rc) return EXIT_FAILURE; } else { action = ACTION_RUN_DAEMON; } if (action == ACTION_RUN_DAEMON) { rc = run_prd_daemon(ctx); } else if (action == ACTION_OCC_CONTROL) { if (optind + 1 >= argc) { pr_log(LOG_ERR, "CTRL: occ command requires " "an argument"); return EXIT_FAILURE; } rc = send_occ_control(ctx, argv[optind + 1]); } return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE; }
int main(int argc, char *argv[]) { struct opal_prd_ctx _ctx; enum action action; int rc; check_abi(); ctx = &_ctx; memset(ctx, 0, sizeof(*ctx)); ctx->vlog = pr_log_stdio; ctx->use_syslog = true; /* Parse options */ for (;;) { int c; c = getopt_long(argc, argv, "f:p:dhse", opal_diag_options, NULL); if (c == -1) break; switch (c) { case 'f': ctx->hbrt_file_name = optarg; break; case 'd': ctx->debug = true; break; case 'p': ctx->pnor.path = strndup(optarg, PATH_MAX); break; case 's': ctx->use_syslog = false; break; case 'h': usage(argv[0]); return EXIT_SUCCESS; case 'e': ctx->expert_mode = true; break; case 'v': print_version(); return EXIT_SUCCESS; case '?': default: usage(argv[0]); return EXIT_FAILURE; } } if (optind < argc) { rc = parse_action(argv[optind], &action); if (rc) return EXIT_FAILURE; } else { action = ACTION_RUN_DAEMON; } if (is_prd_supported() < 0) { pr_log(LOG_ERR, "CTRL: PowerNV OPAL runtime diagnostic " "is not supported on this system"); return -1; } switch (action) { case ACTION_RUN_DAEMON: rc = run_prd_daemon(ctx); break; case ACTION_OCC_CONTROL: if (optind + 1 >= argc) { pr_log(LOG_ERR, "CTRL: occ command requires " "an argument"); return EXIT_FAILURE; } rc = send_occ_control(ctx, argv[optind + 1]); break; case ACTION_ATTR_OVERRIDE: if (optind + 1 >= argc) { pr_log(LOG_ERR, "CTRL: attribute override command " "requires an argument"); return EXIT_FAILURE; } rc = send_attr_override(ctx, argc - optind - 1, &argv[optind + 1]); break; case ACTION_HTMGT_PASSTHRU: if (optind + 1 >= argc) { pr_log(LOG_ERR, "CTRL: htmgt passthru requires at least " "one argument"); return EXIT_FAILURE; } rc = send_htmgt_passthru(ctx, argc - optind - 1, &argv[optind + 1]); break; case ACTION_RUN_COMMAND: if (optind + 1 >= argc) { pr_log(LOG_ERR, "CTRL: run command requires " "argument(s)"); return EXIT_FAILURE; } rc = send_run_command(ctx, argc - optind - 1, &argv[optind + 1]); break; default: break; } return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE; }