int main(int argc, char* argv[]) { char *procd_address = NULL; myDistro->Init(argc, argv); if (argc < 2) { fprintf(stderr, "Usage: %s <options w/arguments> <command> [<arg> ...]\n", argv[0]); list_commands(); return 1; } config(); Termlog = 1; dprintf_config("TOOL", get_param_functions()); int cmd_argc = argc - 1; char** cmd_argv = argv + 1; // Process the first set of options. while(cmd_argv[0] != NULL && cmd_argv[0][0] == '-') { if (strcmp(cmd_argv[0], "-A") == MATCH) { cmd_argc--; cmd_argv++; if (cmd_argc == 0) { fprintf(stderr, "error: -A needs an argument\n"); list_commands(); return 1; } // store the argument to -A as the file we'll use. procd_address = cmd_argv[0]; cmd_argc--; cmd_argv++; continue; } else if (strcmp(cmd_argv[0], "-h") == MATCH) { cmd_argc--; cmd_argv++; fprintf(stderr, "Usage: %s <options w/arguments> <command> [<arg> ...]\n", argv[0]); list_commands(); return 1; continue; } // This is the failure case if we manage to pass all checks above. fprintf(stderr, "error: Don't understand option %s\n", cmd_argv[0]); list_commands(); return 1; } // If there are no command line arguments left, then there is no // command specified after the options, which is a failure. if (cmd_argc == 0) { fprintf(stderr, "Please specify a command.\n" "Usage: %s <options w/arguments> <command> [<arg> ...]\n", argv[0]); list_commands(); return 1; } // If a procd address wasn't specified on the command line, see if we // have an entry in a config file to use. if (procd_address == NULL) { procd_address = param("PROCD_ADDRESS"); if (procd_address == NULL) { fprintf(stderr, "error: PROCD_ADDRESS not defined\n"); return 1; } } ProcFamilyClient pfc; if (!pfc.initialize(procd_address)) { fprintf(stderr, "error: failed to initialize ProcD client\n"); return 1; } // Process this single command we should be performing if (strcasecmp(cmd_argv[0], "REGISTER_FAMILY") == 0) { return register_family(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "TRACK_BY_ASSOCIATED_GID") == 0) { return track_by_associated_gid(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "TRACK_BY_ASSOCIATED_CGROUP") == 0) { return track_by_associated_cgroup(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "GET_USAGE") == 0) { return get_usage(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "DUMP") == 0) { return dump(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "LIST") == 0) { return list(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "SIGNAL_PROCESS") == 0) { return signal_process(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "SUSPEND_FAMILY") == 0) { return suspend_family(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "CONTINUE_FAMILY") == 0) { return continue_family(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "KILL_FAMILY") == 0) { return kill_family(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "UNREGISTER_FAMILY") == 0) { return unregister_family(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "SNAPSHOT") == 0) { return snapshot(pfc, cmd_argc, cmd_argv); } else if (strcasecmp(cmd_argv[0], "QUIT") == 0) { return quit(pfc, cmd_argc, cmd_argv); } else { fprintf(stderr, "error: invalid command: %s\n", cmd_argv[0]); list_commands(); return 1; } }
int nlhandler_init(void) { error_pool_init(); return register_family(); }