int cmd_loopdev(int argc, char* argv[]) { if(argc == 0 || run_argv(commands, ARRAY_SIZE(commands), argc, argv)) { // No command supplied or invalid command, print usage. print_usage(); return 1; } return 0; }
int cmd_main(int argc, const char **argv) { const char *cmd; int done_help = 0; cmd = argv[0]; if (!cmd) cmd = "git-help"; else { const char *slash = find_last_dir_sep(cmd); if (slash) cmd = slash + 1; } /* * wait_for_pager_atexit will close stdout/stderr so it needs to be * registered first so that it will execute last and not close the * handles until all other atexit handlers have finished */ atexit(wait_for_pager_atexit); trace_command_performance(argv); atexit(post_command_hook_atexit); /* * "git-xxxx" is the same as "git xxxx", but we obviously: * * - cannot take flags in between the "git" and the "xxxx". * - cannot execute it externally (since it would just do * the same thing over again) * * So we just directly call the builtin handler, and die if * that one cannot handle it. */ if (skip_prefix(cmd, "git-", &cmd)) { argv[0] = cmd; handle_builtin(argc, argv); die("cannot handle %s as a builtin", cmd); } /* Look for flags.. */ argv++; argc--; handle_options(&argv, &argc, NULL); if (argc > 0) { /* translate --help and --version into commands */ skip_prefix(argv[0], "--", &argv[0]); } else { /* The user didn't specify a command; give them help */ commit_pager_choice(); if (run_pre_command_hook(argv)) die("pre-command hook aborted command"); printf("usage: %s\n\n", git_usage_string); list_common_cmds_help(); printf("\n%s\n", _(git_more_info_string)); exit_code = 1; run_post_command_hook(); exit(exit_code); } cmd = argv[0]; /* * We use PATH to find git commands, but we prepend some higher * precedence paths: the "--exec-path" option, the GIT_EXEC_PATH * environment, and the $(gitexecdir) from the Makefile at build * time. */ setup_path(); while (1) { int was_alias = run_argv(&argc, &argv); if (errno != ENOENT) break; if (was_alias) { fprintf(stderr, _("expansion of alias '%s' failed; " "'%s' is not a git command\n"), cmd, argv[0]); exit(1); } if (!done_help) { cmd = argv[0] = help_unknown_cmd(cmd); done_help = 1; } else break; } fprintf(stderr, _("failed to run command '%s': %s\n"), cmd, strerror(errno)); return 1; }
int main(int argc, const char **argv) { const char *cmd; cmd = perf_extract_argv0_path(argv[0]); if (!cmd) cmd = "perf-help"; debugfs_mount(NULL); if (!prefixcmp(cmd, "perf-")) { cmd += 5; argv[0] = cmd; handle_internal_command(argc, argv); die("cannot handle %s internally", cmd); } argv++; argc--; handle_options(&argv, &argc, NULL); commit_pager_choice(); set_buildid_dir(); if (argc > 0) { if (!prefixcmp(argv[0], "--")) argv[0] += 2; } else { printf("\n usage: %s\n\n", perf_usage_string); list_common_cmds_help(); printf("\n %s\n\n", perf_more_info_string); exit(1); } cmd = argv[0]; setup_path(); pthread__block_sigwinch(); while (1) { static int done_help; static int was_alias; was_alias = run_argv(&argc, &argv); if (errno != ENOENT) break; if (was_alias) { fprintf(stderr, "Expansion of alias '%s' failed; " "'%s' is not a perf-command\n", cmd, argv[0]); exit(1); } if (!done_help) { cmd = argv[0] = help_unknown_cmd(cmd); done_help = 1; } else break; } fprintf(stderr, "Failed to run command '%s': %s\n", cmd, strerror(errno)); return 1; }
int main(int argc, const char **argv) { const char *cmd; startup_info = &git_startup_info; cmd = git_extract_argv0_path(argv[0]); if (!cmd) cmd = "git-help"; /* * "git-xxxx" is the same as "git xxxx", but we obviously: * * - cannot take flags in between the "git" and the "xxxx". * - cannot execute it externally (since it would just do * the same thing over again) * * So we just directly call the internal command handler, and * die if that one cannot handle it. */ if (!prefixcmp(cmd, "git-")) { cmd += 4; argv[0] = cmd; handle_internal_command(argc, argv); die("cannot handle %s internally", cmd); } /* Look for flags.. */ argv++; argc--; handle_options(&argv, &argc, NULL); if (argc > 0) { if (!prefixcmp(argv[0], "--")) argv[0] += 2; } else { /* The user didn't specify a command; give them help */ commit_pager_choice(); printf("usage: %s\n\n", git_usage_string); list_common_cmds_help(); printf("\n%s\n", git_more_info_string); exit(1); } cmd = argv[0]; /* * We use PATH to find git commands, but we prepend some higher * precedence paths: the "--exec-path" option, the GIT_EXEC_PATH * environment, and the $(gitexecdir) from the Makefile at build * time. */ setup_path(); while (1) { static int done_help = 0; static int was_alias = 0; was_alias = run_argv(&argc, &argv); if (errno != ENOENT) break; if (was_alias) { fprintf(stderr, "Expansion of alias '%s' failed; " "'%s' is not a git command\n", cmd, argv[0]); exit(1); } if (!done_help) { cmd = argv[0] = help_unknown_cmd(cmd); done_help = 1; } else break; } fprintf(stderr, "Failed to run command '%s': %s\n", cmd, strerror(errno)); return 1; }
int main(int argc, const char **argv) { const char *cmd; cmd = perf_extract_argv0_path(argv[0]); if (!cmd) cmd = "perf-help"; if(adj_oom_score()) die("Cannot adjust my oom_adj, pls make sure you are root \ or have CAP_SYS_RESOURCE"); /* get debugfs mount point from /proc/mounts */ debugfs_mount(NULL); /* * "perf-xxxx" is the same as "perf xxxx", but we obviously: * * - cannot take flags in between the "perf" and the "xxxx". * - cannot execute it externally (since it would just do * the same thing over again) * * So we just directly call the internal command handler, and * die if that one cannot handle it. */ if (!prefixcmp(cmd, "perf-")) { cmd += 5; argv[0] = cmd; handle_internal_command(argc, argv); die("cannot handle %s internally", cmd); } /* Look for flags.. */ argv++; argc--; handle_options(&argv, &argc, NULL); commit_pager_choice(); set_buildid_dir(); if (argc > 0) { if (!prefixcmp(argv[0], "--")) argv[0] += 2; } else { /* The user didn't specify a command; give them help */ printf("\n usage: %s\n\n", perf_usage_string); list_common_cmds_help(); printf("\n %s\n\n", perf_more_info_string); exit(1); } cmd = argv[0]; /* * We use PATH to find perf commands, but we prepend some higher * precedence paths: the "--exec-path" option, the PERF_EXEC_PATH * environment, and the $(perfexecdir) from the Makefile at build * time. */ setup_path(); /* * Block SIGWINCH notifications so that the thread that wants it can * unblock and get syscalls like select interrupted instead of waiting * forever while the signal goes to some other non interested thread. */ pthread__block_sigwinch(); while (1) { static int done_help; static int was_alias; was_alias = run_argv(&argc, &argv); if (errno != ENOENT) break; if (was_alias) { fprintf(stderr, "Expansion of alias '%s' failed; " "'%s' is not a perf-command\n", cmd, argv[0]); exit(1); } if (!done_help) { cmd = argv[0] = help_unknown_cmd(cmd); done_help = 1; } else break; } fprintf(stderr, "Failed to run command '%s': %s\n", cmd, strerror(errno)); return 1; }
int main(int argc, const char **argv) { const char *cmd; /* The page_size is placed in util object. */ page_size = sysconf(_SC_PAGE_SIZE); cmd = perf_extract_argv0_path(argv[0]); if (!cmd) cmd = "perf-help"; /* get debugfs mount point from /proc/mounts */ perf_debugfs_mount(NULL); /* * "perf-xxxx" is the same as "perf xxxx", but we obviously: * * - cannot take flags in between the "perf" and the "xxxx". * - cannot execute it externally (since it would just do * the same thing over again) * * So we just directly call the internal command handler, and * die if that one cannot handle it. */ if (!prefixcmp(cmd, "perf-")) { cmd += 5; argv[0] = cmd; handle_internal_command(argc, argv); fprintf(stderr, "cannot handle %s internally", cmd); goto out; } if (!prefixcmp(cmd, "trace")) { #ifdef HAVE_LIBAUDIT_SUPPORT set_buildid_dir(); setup_path(); argv[0] = "trace"; return cmd_trace(argc, argv, NULL); #else fprintf(stderr, "trace command not available: missing audit-libs devel package at build time.\n"); goto out; #endif } /* Look for flags.. */ argv++; argc--; handle_options(&argv, &argc, NULL); commit_pager_choice(); set_buildid_dir(); if (argc > 0) { if (!prefixcmp(argv[0], "--")) argv[0] += 2; } else { /* The user didn't specify a command; give them help */ printf("\n usage: %s\n\n", perf_usage_string); list_common_cmds_help(); printf("\n %s\n\n", perf_more_info_string); goto out; } cmd = argv[0]; test_attr__init(); /* * We use PATH to find perf commands, but we prepend some higher * precedence paths: the "--exec-path" option, the PERF_EXEC_PATH * environment, and the $(perfexecdir) from the Makefile at build * time. */ setup_path(); /* * Block SIGWINCH notifications so that the thread that wants it can * unblock and get syscalls like select interrupted instead of waiting * forever while the signal goes to some other non interested thread. */ pthread__block_sigwinch(); while (1) { static int done_help; int was_alias = run_argv(&argc, &argv); if (errno != ENOENT) break; if (was_alias) { fprintf(stderr, "Expansion of alias '%s' failed; " "'%s' is not a perf-command\n", cmd, argv[0]); goto out; } if (!done_help) { cmd = argv[0] = help_unknown_cmd(cmd); done_help = 1; } else break; } fprintf(stderr, "Failed to run command '%s': %s\n", cmd, strerror(errno)); out: return 1; }
int main(int argc, const char **argv) { int err; const char *cmd; char sbuf[STRERR_BUFSIZE]; int value; /* libsubcmd init */ exec_cmd_init("perf", PREFIX, PERF_EXEC_PATH, EXEC_PATH_ENVIRONMENT); pager_init(PERF_PAGER_ENVIRONMENT); /* The page_size is placed in util object. */ page_size = sysconf(_SC_PAGE_SIZE); cache_line_size(&cacheline_size); if (sysctl__read_int("kernel/perf_event_max_stack", &value) == 0) sysctl_perf_event_max_stack = value; if (sysctl__read_int("kernel/perf_event_max_contexts_per_stack", &value) == 0) sysctl_perf_event_max_contexts_per_stack = value; cmd = extract_argv0_path(argv[0]); if (!cmd) cmd = "perf-help"; srandom(time(NULL)); perf_config__init(); err = perf_config(perf_default_config, NULL); if (err) return err; set_buildid_dir(NULL); /* get debugfs/tracefs mount point from /proc/mounts */ tracing_path_mount(); /* * "perf-xxxx" is the same as "perf xxxx", but we obviously: * * - cannot take flags in between the "perf" and the "xxxx". * - cannot execute it externally (since it would just do * the same thing over again) * * So we just directly call the internal command handler. If that one * fails to handle this, then maybe we just run a renamed perf binary * that contains a dash in its name. To handle this scenario, we just * fall through and ignore the "xxxx" part of the command string. */ if (strstarts(cmd, "perf-")) { cmd += 5; argv[0] = cmd; handle_internal_command(argc, argv); /* * If the command is handled, the above function does not * return undo changes and fall through in such a case. */ cmd -= 5; argv[0] = cmd; } if (strstarts(cmd, "trace")) { #if defined(HAVE_LIBAUDIT_SUPPORT) || defined(HAVE_SYSCALL_TABLE_SUPPORT) setup_path(); argv[0] = "trace"; return cmd_trace(argc, argv); #else fprintf(stderr, "trace command not available: missing audit-libs devel package at build time.\n"); goto out; #endif } /* Look for flags.. */ argv++; argc--; handle_options(&argv, &argc, NULL); commit_pager_choice(); if (argc > 0) { if (strstarts(argv[0], "--")) argv[0] += 2; } else { /* The user didn't specify a command; give them help */ printf("\n usage: %s\n\n", perf_usage_string); list_common_cmds_help(); printf("\n %s\n\n", perf_more_info_string); goto out; } cmd = argv[0]; test_attr__init(); /* * We use PATH to find perf commands, but we prepend some higher * precedence paths: the "--exec-path" option, the PERF_EXEC_PATH * environment, and the $(perfexecdir) from the Makefile at build * time. */ setup_path(); /* * Block SIGWINCH notifications so that the thread that wants it can * unblock and get syscalls like select interrupted instead of waiting * forever while the signal goes to some other non interested thread. */ pthread__block_sigwinch(); perf_debug_setup(); while (1) { static int done_help; run_argv(&argc, &argv); if (errno != ENOENT) break; if (!done_help) { cmd = argv[0] = help_unknown_cmd(cmd); done_help = 1; } else break; } fprintf(stderr, "Failed to run command '%s': %s\n", cmd, str_error_r(errno, sbuf, sizeof(sbuf))); out: return 1; }
int main(int argc, char **av) { const char **argv = (const char **) av; const char *cmd; startup_info = &git_startup_info; cmd = git_extract_argv0_path(argv[0]); if (!cmd) cmd = "git-help"; /* * Always open file descriptors 0/1/2 to avoid clobbering files * in die(). It also avoids messing up when the pipes are dup'ed * onto stdin/stdout/stderr in the child processes we spawn. */ sanitize_stdfds(); git_setup_gettext(); /* * "git-xxxx" is the same as "git xxxx", but we obviously: * * - cannot take flags in between the "git" and the "xxxx". * - cannot execute it externally (since it would just do * the same thing over again) * * So we just directly call the builtin handler, and die if * that one cannot handle it. */ if (starts_with(cmd, "git-")) { cmd += 4; argv[0] = cmd; handle_builtin(argc, argv); die("cannot handle %s as a builtin", cmd); } /* Look for flags.. */ argv++; argc--; handle_options(&argv, &argc, NULL); if (argc > 0) { if (starts_with(argv[0], "--")) argv[0] += 2; } else { /* The user didn't specify a command; give them help */ commit_pager_choice(); printf("usage: %s\n\n", git_usage_string); list_common_cmds_help(); printf("\n%s\n", _(git_more_info_string)); exit(1); } cmd = argv[0]; /* * We use PATH to find git commands, but we prepend some higher * precedence paths: the "--exec-path" option, the GIT_EXEC_PATH * environment, and the $(gitexecdir) from the Makefile at build * time. */ setup_path(); while (1) { static int done_help = 0; static int was_alias = 0; was_alias = run_argv(&argc, &argv); if (errno != ENOENT) break; if (was_alias) { fprintf(stderr, "Expansion of alias '%s' failed; " "'%s' is not a git command\n", cmd, argv[0]); exit(1); } if (!done_help) { cmd = argv[0] = help_unknown_cmd(cmd); done_help = 1; } else break; } fprintf(stderr, "Failed to run command '%s': %s\n", cmd, strerror(errno)); return 1; }