int main (int argc, char * const argv[]) { PROG = "aa-reset"; const char *path_repo = "/run/services"; intptr_t mode = MODE_NONE; int i; int r; for (;;) { struct option longopts[] = { { "auto", no_argument, NULL, 'A' }, { "started", no_argument, NULL, 'a' }, { "double-output", no_argument, NULL, 'D' }, { "help", no_argument, NULL, 'h' }, { "stopped", no_argument, NULL, 'o' }, { "repodir", required_argument, NULL, 'r' }, { "version", no_argument, NULL, 'V' }, { NULL, 0, 0, 0 } }; int c; c = getopt_long (argc, argv, "AaDhor:V", longopts, NULL); if (c == -1) break; switch (c) { case 'A': mode = MODE_AUTO; break; case 'a': mode = MODE_STARTED; break; case 'D': aa_set_double_output (1); break; case 'h': dieusage (0); case 'o': mode = MODE_STOPPED; break; case 'r': unslash (optarg); path_repo = optarg; break; case 'V': aa_die_version (); default: dieusage (1); } } argc -= optind; argv += optind; if (argc < 1 || mode == MODE_NONE) dieusage (1); r = aa_init_repo (path_repo, AA_REPO_READ); if (r < 0) aa_strerr_diefu2sys (2, "init repository ", path_repo); for (i = 0; i < argc; ++i) if (str_equal (argv[i], "-")) { if (process_names_from_stdin ((names_cb) reset_service, (void *) mode) < 0) aa_strerr_diefu1sys (ERR_IO, "process names from stdin"); } else reset_service (argv[i], mode); return 0; }
int main (int argc, char * const argv[]) { PROG = "aa-start"; const char *path_repo = "/run/services"; const char *path_list = NULL; int i; aa_secs_timeout = DEFAULT_TIMEOUT_SECS; for (;;) { struct option longopts[] = { { "double-output", no_argument, NULL, 'D' }, { "help", no_argument, NULL, 'h' }, { "listdir", required_argument, NULL, 'l' }, { "dry-list", no_argument, NULL, 'n' }, { "repodir", required_argument, NULL, 'r' }, { "timeout", required_argument, NULL, 't' }, { "version", no_argument, NULL, 'V' }, { "verbose", no_argument, NULL, 'v' }, { "no-wants", no_argument, NULL, 'W' }, { NULL, 0, 0, 0 } }; int c; c = getopt_long (argc, argv, "Dhl:nr:t:VvW", longopts, NULL); if (c == -1) break; switch (c) { case 'D': aa_set_double_output (1); break; case 'h': dieusage (0); case 'l': unslash (optarg); path_list = optarg; break; case 'n': if (mode & AA_MODE_IS_DRY) mode |= AA_MODE_IS_DRY_FULL; else mode |= AA_MODE_IS_DRY; break; case 'r': unslash (optarg); path_repo = optarg; break; case 't': if (!uint0_scan (optarg, &aa_secs_timeout)) aa_strerr_diefu2sys (ERR_IO, "set default timeout to ", optarg); break; case 'V': aa_die_version (); case 'v': verbose = 1; break; case 'W': no_wants = 1; break; default: dieusage (1); } } argc -= optind; argv += optind; cols = get_cols (1); is_utf8 = is_locale_utf8 (); if (!path_list && argc < 1) dieusage (1); if (aa_init_repo (path_repo, (mode & AA_MODE_IS_DRY) ? AA_REPO_READ : AA_REPO_WRITE) < 0) aa_strerr_diefu2sys (ERR_IO, "init repository ", path_repo); if (path_list) { stralloc sa = STRALLOC_ZERO; int r; if (*path_list != '/' && *path_list != '.') stralloc_cats (&sa, LISTDIR_PREFIX); stralloc_catb (&sa, path_list, strlen (path_list) + 1); r = aa_scan_dir (&sa, 1, it_start, NULL); stralloc_free (&sa); if (r < 0) aa_strerr_diefu3sys (-r, "read list directory ", (*path_list != '/' && *path_list != '.') ? LISTDIR_PREFIX : path_list, (*path_list != '/' && *path_list != '.') ? path_list : ""); } tain_now_g (); for (i = 0; i < argc; ++i) if (str_equal (argv[i], "-")) { if (process_names_from_stdin ((names_cb) add_service, NULL) < 0) aa_strerr_diefu1sys (ERR_IO, "process names from stdin"); } else add_service (argv[i], NULL); mainloop (mode, scan_cb); if (!(mode & AA_MODE_IS_DRY)) { aa_bs_noflush (AA_OUT, "\n"); put_title (1, PROG, "Completed.", 1); aa_show_stat_nb (nb_already, "Already up", ANSI_HIGHLIGHT_GREEN_ON); aa_show_stat_nb (nb_done, "Started", ANSI_HIGHLIGHT_GREEN_ON); show_stat_service_names (&ga_timedout, "Timed out", ANSI_HIGHLIGHT_RED_ON); show_stat_service_names (&ga_failed, "Failed", ANSI_HIGHLIGHT_RED_ON); show_stat_service_names (&ga_depend, "Dependency failed", ANSI_HIGHLIGHT_RED_ON); aa_show_stat_names (aa_names.s, &ga_io, "I/O error", ANSI_HIGHLIGHT_RED_ON); aa_show_stat_names (aa_names.s, &ga_unknown, "Unknown", ANSI_HIGHLIGHT_RED_ON); aa_show_stat_names (aa_names.s, &ga_skipped, "Skipped", ANSI_HIGHLIGHT_YELLOW_ON); } genalloc_free (int, &ga_timedout); genalloc_free (int, &ga_failed); genalloc_free (int, &ga_depend); genalloc_free (size_t, &ga_io); genalloc_free (size_t, &ga_unknown); genalloc_free (size_t, &ga_skipped); genalloc_free (pid_t, &ga_pid); genalloc_free (int, &aa_tmp_list); genalloc_free (int, &aa_main_list); stralloc_free (&aa_names); genalloc_deepfree (struct progress, &ga_progress, free_progress); aa_free_services (close_fd); genalloc_free (iopause_fd, &ga_iop); return rc; }