int update_binary_main(int argc, char *argv[]) { // Make stdout unbuffered setvbuf(stdout, nullptr, _IONBF, 0); int opt; static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; int long_index = 0; while ((opt = getopt_long(argc, argv, "h", long_options, &long_index)) != -1) { switch (opt) { case 'h': update_binary_usage(0); return EXIT_SUCCESS; default: update_binary_usage(1); return EXIT_FAILURE; } } if (argc - optind != 3) { update_binary_usage(1); return EXIT_FAILURE; } int interface; int output_fd; const char *zip_file; char *ptr; interface = strtol(argv[1], &ptr, 10); if (*ptr != '\0' || interface < 0) { fprintf(stderr, "Invalid interface"); return EXIT_FAILURE; } output_fd = strtol(argv[2], &ptr, 10); if (*ptr != '\0' || output_fd < 0) { fprintf(stderr, "Invalid output fd"); return EXIT_FAILURE; } zip_file = argv[3]; // stdout is messed up when it's appended to /tmp/recovery.log util::log_set_logger(std::make_shared<util::StdioLogger>(stderr, false)); mbp::setLogCallback(mbp_log_cb); RecoveryInstaller ri(zip_file, interface, output_fd); return ri.start_installation() ? EXIT_SUCCESS : EXIT_FAILURE; }
int update_binary_main(int argc, char *argv[]) { if (unshare(CLONE_NEWNS) < 0) { fprintf(stderr, "unshare() failed: %s\n", strerror(errno)); return EXIT_FAILURE; } if (mount("", "/", "", MS_PRIVATE | MS_REC, "") < 0) { fprintf(stderr, "Failed to set private mount propagation: %s\n", strerror(errno)); return false; } // Make stdout unbuffered setvbuf(stdout, nullptr, _IONBF, 0); int opt; static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; int long_index = 0; while ((opt = getopt_long(argc, argv, "h", long_options, &long_index)) != -1) { switch (opt) { case 'h': update_binary_usage(0); return EXIT_SUCCESS; default: update_binary_usage(1); return EXIT_FAILURE; } } if (argc - optind != 3) { update_binary_usage(1); return EXIT_FAILURE; } int interface; int output_fd; const char *zip_file; char *ptr; interface = strtol(argv[1], &ptr, 10); if (*ptr != '\0' || interface < 0) { fprintf(stderr, "Invalid interface"); return EXIT_FAILURE; } output_fd = strtol(argv[2], &ptr, 10); if (*ptr != '\0' || output_fd < 0) { fprintf(stderr, "Invalid output fd"); return EXIT_FAILURE; } zip_file = argv[3]; // stdout is messed up when it's appended to /tmp/recovery.log log::log_set_logger(std::make_shared<log::StdioLogger>(stderr, false)); RecoveryInstaller ri(zip_file, interface, output_fd); return ri.start_installation() ? EXIT_SUCCESS : EXIT_FAILURE; }