int info_main(int UNUSED_PARAM argc, char UNUSED_PARAM **argv) { int current_version; copyright_header("info"); if (!init_globals()) { return EINIT_GLOBALS; } current_version = get_current_version(path_prefix); printf("Installed version: %d\n", current_version); printf("Version URL: %s\n", version_url); printf("Content URL: %s\n", content_url); free_globals(); return 0; }
int update_main(int argc, char **argv) { int ret = 0; copyright_header("software update"); if (!parse_options(argc, argv)) { free_globals(); return EXIT_FAILURE; } if (cmd_line_status) { print_versions(); } else { ret = main_update(); } free_globals(); return ret; }
int bundle_remove_main(int argc, char **argv) { int ret = 0; int total = 0; int bad = 0; copyright_header("bundle remover"); if (!parse_options(argc, argv)) { return EINVALID_OPTION; } for (; *bundles; ++bundles, total++) { fprintf(stderr, "Removing bundle: %s\n", *bundles); if (remove_bundle(*bundles) != 0) { /* At least one bundle failed to be removed * then for consistency return an error * indicating that */ ret = EBUNDLE_REMOVE; bad++; } /* if we have more than one bundle to process then * make sure to reload the parsed options since all * globals are cleaned up at swupd_deinit() */ if (*bundles) { reload_parsed_opts(); } } /* print some statistics */ if (ret) { fprintf(stderr, "%i bundle(s) of %i failed to remove\n", bad, total); } else { fprintf(stderr, "%i bundle(s) were removed successfully\n", total); } /* free any parsed opt saved for reloading */ free_saved_opts(); return ret; }
static int parse_options(int argc, char **argv, int *index) { int opt; int ret; /* The leading "-" in the optstring is required to preserve option parsing order */ while ((opt = getopt_long(argc, argv, "-hv", prog_opts, NULL)) != -1) { switch (opt) { case 'h': print_help(argv[0]); exit(EXIT_SUCCESS); case 'v': copyright_header("swupd"); printf("Compile-time options: %s\n", BUILD_OPTS); exit(EXIT_SUCCESS); case '\01': /* found a subcommand, or a random non-option argument */ ret = subcmd_index(optarg); if (ret < 0) { fprintf(stderr, "error: unrecognized subcommand `%s'\n\n", optarg); goto error; } else { *index = ret; return 0; } case '?': /* for unknown options, an error message is printed automatically */ printf("\n"); goto error; default: /* should be unreachable */ break; } } /* no subcommands implies -h/--help */ print_help(argv[0]); exit(EXIT_SUCCESS); error: print_help(argv[0]); return -1; }
static void usage(char *s, struct xmp_options *opt) { struct xmp_fmt_info *f, *fmt; struct xmp_drv_info *d, *drv; char **hlp, buf[80]; int i; copyright_header (); printf ("%s\n", xmp_build); printf ("Usage: %s [options] [modules]\n", s); printf ("\nSupported module formats:\n"); xmp_get_fmt_info(&fmt); list_wrap (NULL, 3, 78, 1); for (i = 0, f = fmt; f; i++, f = f->next) { snprintf(buf, 80, "%s (%s)", f->id, f->tracker); list_wrap(buf, 3, 0, 1); } snprintf(buf, 80, "[%d known formats]", i); list_wrap(buf, 3, 0, 0); printf ("\n"); printf("\nAvailable drivers:\n"); xmp_get_drv_info(&drv); list_wrap (NULL, 3, 78, 1); for (d = drv; d; d = d->next) { snprintf(buf, 80, "%s (%s)", d->id, d->description); list_wrap(buf, 3, 0, 1); } printf("\n"); for (d = drv; d; d = d->next) { if (d->help) printf ("\n%s options:\n", d->description); for (hlp = d->help; hlp && *hlp; hlp += 2) printf (" -D%-20.20s %s\n", hlp[0], hlp[1]); } printf ( "\nPlayer control options:\n" " -D parameter[=val] Pass configuration parameter to the output driver\n" " -d --driver name Force output to the specified device\n" " --fix-sample-loops Use sample loop start /2 in MOD/UNIC/NP3\n" " --offset-bug-emulation Emulate Protracker 2.x bug in effect 9\n" " -l --loop Enable module looping\n" " -M --mute ch-list Mute the specified channels\n" " --modrange Limit the octave range to 3 octaves in MOD files\n" " --nocmd Disable interactive commands\n" " --norc Don't read configuration files\n" " -R --random Random order playing\n" #ifdef HAVE_SYS_RTPRIO_H " --realtime Run in real-time priority\n" #endif " -S --solo ch-list Set channels to solo mode\n" " -s --start num Start from the specified order\n" " -T --tempo num Initial tempo (default 6)\n" " -t --time num Maximum playing time in seconds\n" "\nPlayer sound options:\n" " -8 --8bit Convert 16 bit samples to 8 bit\n" " --chorus num Chorus depth (if supported)\n" " -m --mono Mono output\n" " --nofilter Disable IT filter\n" " --nopan Disable dynamic panning\n" " -P --pan pan Percentual pan amplitude (default %d%%)\n" " -r --reverse Reverse left/right stereo channels\n" " --reverb num Reverb depth (if supported)\n" " --stereo Stereo output\n" "\nSoftware mixer options:\n" " -b --bits {8|16} Software mixer resolution (8 or 16 bits)\n" " -c --stdout Mix the module to stdout\n" " -f --frequency rate Sampling rate in hertz (default %d Hz)\n" " -i --interpolate Use linear interpolation (default %s)\n" " -n --nearest Use nearest neighbor interpolation\n" " -o --output-file name Mix the module to file ('-' for stdout)\n" " -u --unsigned Set the mixer to use unsigned samples\n" "\nInformation options:\n" " -h --help Print a summary of the command line options\n" " --load-only Load module and exit\n" " --probe-only Probe audio device and exit\n" " -q --quiet Quiet mode (verbosity level = 0)\n" " -V --version Print version information\n" " -v --verbose Verbose mode (incremental)\n" ,opt->mix, opt->freq, opt->flags & XMP_CTL_ITPT ? "enabled" : "disabled" ); }
/* This function does a simple verification of files listed in the * subscribed bundle manifests. If the optional "fix" or "install" parameter * is specified, the disk will be modified at each point during the * sequential comparison of manifest files to disk files, where the disk is * found to not match the manifest. This is notably different from update, * which attempts to atomically (or nearly atomically) activate a set of * pre-computed and validated staged changes as a group. */ int verify_main(int argc, char **argv) { struct manifest *official_manifest = NULL; int ret; int lock_fd; struct list *subs = NULL; copyright_header("software verify"); if (!parse_options(argc, argv)) { return EINVALID_OPTION; } /* parse command line options */ assert(argc >= 0); assert(argv != NULL); ret = swupd_init(&lock_fd); if (ret != 0) { printf("Failed verify initialization, exiting now.\n"); return ret; } /* Gather current manifests */ if (!version) { version = get_current_version(path_prefix); if (version < 0) { printf("Error: Unable to determine current OS version\n"); ret = ECURRENT_VERSION; goto clean_and_exit; } } if (version == -1) { version = get_latest_version(); if (version < 0) { printf("Unable to get latest version for install\n"); ret = EXIT_FAILURE; goto clean_and_exit; } } printf("Verifying version %i\n", version); if (!check_network()) { printf("Error: Network issue, unable to download manifest\n"); ret = ENOSWUPDSERVER; goto clean_and_exit; } read_subscriptions_alt(&subs); /* * FIXME: We need a command line option to override this in case the * certificate is hosed and the admin knows it and wants to recover. */ ret = rm_staging_dir_contents("download"); if (ret != 0) { printf("Failed to remove prior downloads, carrying on anyway\n"); } official_manifest = load_mom(version); if (!official_manifest) { /* This is hit when or if an OS version is specified for --fix which * is not available, or if there is a server error and a manifest is * not provided. */ printf("Unable to download/verify %d Manifest.MoM\n", version); ret = EMOM_NOTFOUND; /* No repair is possible without a manifest, nor is accurate reporting * of the state of the system. Therefore cleanup, report failure and exit */ goto clean_and_exit; } ret = add_included_manifests(official_manifest, &subs); if (ret) { ret = EMANIFEST_LOAD; goto clean_and_exit; } set_subscription_versions(official_manifest, NULL, &subs); official_manifest->submanifests = recurse_manifest(official_manifest, subs, NULL); if (!official_manifest->submanifests) { printf("Error: Cannot load MoM sub-manifests\n"); ret = ERECURSE_MANIFEST; goto clean_and_exit; } official_manifest->files = files_from_bundles(official_manifest->submanifests); official_manifest->files = consolidate_files(official_manifest->files); /* when fixing or installing we need input files. */ if (cmdline_option_fix || cmdline_option_install) { ret = get_required_files(official_manifest, subs); if (ret != 0) { ret = -ret; goto clean_and_exit; } } /* preparation work complete. */ /* * NOTHING ELSE IS ALLOWED TO FAIL/ABORT after this line. * This tool is there to recover a nearly-bricked system. Aborting * from this point forward, for any reason, will result in a bricked system. * * I don't care what your static analysis tools says * I don't care what valgrind tells you * * There shall be no "goto fail;" from this point on. * * *** THE SHOW MUST GO ON *** */ if (cmdline_option_fix || cmdline_option_install) { /* * Next put the files in place that are missing completely. * This is to avoid updating a symlink to a library before the new full file * is already there. It's also the most safe operation, adding files rarely * has unintended side effect. So lets do the safest thing first. */ printf("Adding any missing files\n"); add_missing_files(official_manifest); } if (cmdline_option_quick) { /* quick only replaces missing files, so it is done here */ goto brick_the_system_and_clean_curl; } if (cmdline_option_fix) { bool repair = true; printf("Fixing modified files\n"); deal_with_hash_mismatches(official_manifest, repair); /* removing files could be risky, so only do it if the * prior phases had no problems */ if ((file_not_fixed_count == 0) && (file_not_replaced_count == 0)) { remove_orphaned_files(official_manifest); } } else { bool repair = false; printf("Verifying files\n"); deal_with_hash_mismatches(official_manifest, repair); } free_manifest(official_manifest); brick_the_system_and_clean_curl: /* clean up */ /* * naming convention: All exit goto labels must follow the "brick_the_system_and_FOO:" pattern */ /* report a summary of what we managed to do and not do */ printf("Inspected %i files\n", file_checked_count); if (cmdline_option_fix || cmdline_option_install) { printf(" %i files were missing\n", file_missing_count); if (file_missing_count) { printf(" %i of %i missing files were replaced\n", file_replaced_count, file_missing_count); printf(" %i of %i missing files were not replaced\n", file_not_replaced_count, file_missing_count); } } if (!cmdline_option_quick && file_mismatch_count > 0) { printf(" %i files did not match\n", file_mismatch_count); if (cmdline_option_fix) { printf(" %i of %i files were fixed\n", file_fixed_count, file_mismatch_count); printf(" %i of %i files were not fixed\n", file_not_fixed_count, file_mismatch_count); } } if ((file_not_fixed_count == 0) && (file_not_replaced_count == 0) && cmdline_option_fix && !cmdline_option_quick) { printf(" %i files found which should be deleted\n", file_extraneous_count); if (file_extraneous_count) { printf(" %i of %i files were deleted\n", file_deleted_count, file_extraneous_count); printf(" %i of %i files were not deleted\n", file_not_deleted_count, file_extraneous_count); } } if (cmdline_option_fix || cmdline_option_install) { // always run in a fix or install case need_update_boot = true; need_update_bootloader = true; run_scripts(); } sync(); if ((file_not_fixed_count == 0) && (file_not_replaced_count == 0) && (file_not_deleted_count == 0)) { ret = EXIT_SUCCESS; } else { ret = EXIT_FAILURE; } /* this concludes the critical section, after this point it's clean up time, the disk content is finished and final */ clean_and_exit: telemetry(ret ? TELEMETRY_CRIT : TELEMETRY_INFO, "verify", "fix=%d\nret=%d\n" "current_version=%d\n" "file_replaced_count=%d\n" "file_not_replaced_count=%d\n" "file_missing_count=%d\n" "file_fixed_count=%d\n" "file_not_fixed_count=%d\n" "file_deleted_count=%d\n" "file_not_deleted_count=%d\n" "file_mismatch_count=%d\n" "file_extraneous_count=%d\n", cmdline_option_fix || cmdline_option_install, ret, version, file_replaced_count, file_not_replaced_count, file_missing_count, file_fixed_count, file_not_fixed_count, file_deleted_count, file_not_deleted_count, file_mismatch_count, file_extraneous_count); if (ret == EXIT_SUCCESS) { if (cmdline_option_fix || cmdline_option_install) { printf("Fix successful\n"); } else { /* This is just a verification */ printf("Verify successful\n"); } } else { if (cmdline_option_fix || cmdline_option_install) { printf("Error: Fix did not fully succeed\n"); } else { /* This is just a verification */ printf("Error: Verify did not fully succeed\n"); } } swupd_deinit(lock_fd, &subs); return ret; }