int plooptool_grow(int argc, char **argv) { int i, f; off_t new_size = 0; /* in sectors */ int raw = 0, sparse = 0; char *device = NULL; static struct option long_opts[] = { { "sparse", no_argument, 0, 'S' }, {}, }; while ((i = getopt_long(argc, argv, "f:d:s:S", long_opts, NULL)) != EOF) { switch (i) { case 'f': f = parse_format_opt(optarg); if (f < 0) { usage(); return SYSEXIT_PARAM; } raw = (f == PLOOP_RAW_MODE); break; case 'd': device = optarg; break; case 'S': sparse = 1; break; case 's': if (parse_size(optarg, &new_size, "-s")) { usage(); return SYSEXIT_PARAM; } break; default: usage(); return SYSEXIT_PARAM; } } argc -= optind; argv += optind; if (((argc != 0 || !device) && (argc != 1 || device)) || (raw && device) || (new_size == 0)) { usage(); return SYSEXIT_PARAM; } if (argc == 1 && is_xml_fname(argv[0])) { int ret; struct ploop_disk_images_data *di; ret = ploop_open_dd(&di, argv[0]); if (ret) return ret; ret = ploop_grow_image(di, new_size, sparse); ploop_close_dd(di); return ret; } else if (device) return ploop_grow_device(device, new_size); else if (raw) return ploop_grow_raw_delta_offline(argv[0], new_size, sparse); else return ploop_grow_delta_offline(argv[0], new_size); }
/* main desktop management function */ void manage_desktop( WCHAR *arg ) { static const WCHAR messageW[] = {'M','e','s','s','a','g','e',0}; HDESK desktop = 0; GUID guid; MSG msg; HWND hwnd, msg_hwnd; HMODULE graphics_driver; unsigned int width, height; WCHAR *cmdline = NULL, *driver = NULL; WCHAR *p = arg; const WCHAR *name = NULL; BOOL enable_shell = FALSE; /* get the rest of the command line (if any) */ while (*p && !isspace(*p)) p++; if (*p) { *p++ = 0; while (*p && isspace(*p)) p++; if (*p) cmdline = p; } /* parse the desktop option */ /* the option is of the form /desktop=name[,widthxheight[,driver]] */ if (*arg == '=' || *arg == ',') { arg++; name = arg; if ((p = strchrW( arg, ',' ))) { *p++ = 0; if ((driver = strchrW( p, ',' ))) *driver++ = 0; } if (!p || !parse_size( p, &width, &height )) get_default_desktop_size( name, &width, &height ); } else if ((name = get_default_desktop_name())) { if (!get_default_desktop_size( name, &width, &height )) width = height = 0; } if (name) enable_shell = get_default_enable_shell( name ); if (name && width && height) { if (!(desktop = CreateDesktopW( name, NULL, NULL, 0, DESKTOP_ALL_ACCESS, NULL ))) { WINE_ERR( "failed to create desktop %s error %d\n", wine_dbgstr_w(name), GetLastError() ); ExitProcess( 1 ); } SetThreadDesktop( desktop ); } UuidCreate( &guid ); TRACE( "display guid %s\n", debugstr_guid(&guid) ); graphics_driver = load_graphics_driver( driver, &guid ); /* create the desktop window */ hwnd = CreateWindowExW( 0, DESKTOP_CLASS_ATOM, NULL, WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 0, 0, 0, 0, 0, &guid ); /* create the HWND_MESSAGE parent */ msg_hwnd = CreateWindowExW( 0, messageW, NULL, WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100, 0, 0, 0, NULL ); if (hwnd == GetDesktopWindow()) { using_root = !desktop || !create_desktop( graphics_driver, name, width, height ); SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)desktop_wnd_proc ); SendMessageW( hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIconW( 0, MAKEINTRESOURCEW(OIC_WINLOGO))); if (name) set_desktop_window_title( hwnd, name ); SetWindowPos( hwnd, 0, GetSystemMetrics(SM_XVIRTUALSCREEN), GetSystemMetrics(SM_YVIRTUALSCREEN), GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN), SWP_SHOWWINDOW ); SystemParametersInfoW( SPI_SETDESKWALLPAPER, 0, NULL, FALSE ); ClipCursor( NULL ); initialize_display_settings(); initialize_appbar(); if (graphics_driver) { HMODULE shell32; void (WINAPI *pShellDDEInit)( BOOL ); if (using_root) enable_shell = FALSE; initialize_systray( graphics_driver, using_root, enable_shell ); if (!using_root) initialize_launchers( hwnd ); if ((shell32 = LoadLibraryA( "shell32.dll" )) && (pShellDDEInit = (void *)GetProcAddress( shell32, (LPCSTR)188))) { pShellDDEInit( TRUE ); } } } else { DestroyWindow( hwnd ); /* someone beat us to it */ hwnd = 0; } if (GetAncestor( msg_hwnd, GA_PARENT )) DestroyWindow( msg_hwnd ); /* someone beat us to it */ /* if we have a command line, execute it */ if (cmdline) { STARTUPINFOW si; PROCESS_INFORMATION pi; memset( &si, 0, sizeof(si) ); si.cb = sizeof(si); WINE_TRACE( "starting %s\n", wine_dbgstr_w(cmdline) ); if (CreateProcessW( NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi )) { CloseHandle( pi.hThread ); CloseHandle( pi.hProcess ); } } /* run the desktop message loop */ if (hwnd) { WINE_TRACE( "desktop message loop starting on hwnd %p\n", hwnd ); while (GetMessageW( &msg, 0, 0, 0 )) DispatchMessageW( &msg ); WINE_TRACE( "desktop message loop exiting for hwnd %p\n", hwnd ); } ExitProcess( 0 ); }
static int handle_options(const unsigned char *opt) { const unsigned char *n = NULL, *p; if (!strcmp("--version", opt)) { report_version(); } else if (!strcmp("--help", opt)) { report_help(); } else if ((p = check_option("--stdin", opt))) { stdin_file = p; } else if ((p = check_option("--stdout", opt))) { stdout_file = p; } else if ((p = check_option("--stderr", opt))) { stderr_file = p; } else if ((p = check_option("--workdir", opt))) { working_dir = p; } else if ((p = check_option("--test-file", opt))) { test_file = p; } else if ((p = check_option("--corr-file", opt))) { corr_file = p; } else if ((p = check_option("--info-file", opt))) { info_file = p; } else if ((p = check_option("--input-file", opt))) { input_file = p; } else if ((p = check_option("--output-file", opt))) { output_file = p; } else if (!strcmp("--clear-env", opt)) { clear_env_flag = 1; } else if ((p = check_option("--env", opt))) { xexpand(&env_vars); env_vars.v[env_vars.u++] = xstrdup(p); } else if ((p = check_option((n = "--time-limit"), opt))) { parse_int(n, p, &time_limit, 1, 99999); } else if ((p = check_option((n = "--time-limit-millis"), opt))) { parse_int(n, p, &time_limit_millis, 1, 999999999); } else if ((p = check_option((n = "--real-time-limit"), opt))) { parse_int(n, p, &real_time_limit, 1, 99999); } else if (!strcmp("--no-core-dump", opt)) { no_core_dump = 1; } else if ((p = check_option("--kill-signal", opt))) { kill_signal = p; } else if (!strcmp("--memory-limit", opt)) { memory_limit = 1; } else if (!strcmp("--secure-exec", opt)) { secure_exec = 1; } else if (!strcmp("--security-violation", opt)) { security_violation = 1; } else if (!strcmp("--use-stdin", opt)) { use_stdin = 1; } else if (!strcmp("--use-stdout", opt)) { use_stdout = 1; } else if ((p = check_option((n = "--max-vm-size"), opt))) { parse_size(n, p, &max_vm_size, 4096); } else if ((p = check_option((n = "--max-stack-size"), opt))) { parse_size(n, p, &max_stack_size, 4096); } else if ((p = check_option((n = "--max-data-size"), opt))) { parse_size(n, p, &max_data_size, 4096); } else if ((p = check_option((n = "--mode"), opt))) { parse_mode(n, p, &mode); } else if ((p = check_option((n = "--group"), opt))) { parse_group(n, p, &group); } else if ((p = check_option((n = "--test-num"), opt))) { parse_int(n, p, &test_num, 1, 99999); } else if ((p = check_option("--test-pattern", opt))) { test_pattern = p; } else if ((p = check_option("--corr-pattern", opt))) { corr_pattern = p; } else if ((p = check_option("--info-pattern", opt))) { info_pattern = p; } else if ((p = check_option("--tgzdir-pattern", opt))) { tgzdir_pattern = p; } else if (!strcmp("--update-corr", opt)) { update_corr = 1; } else if ((p = check_option("--test-dir", opt))) { test_dir = p; } else if (!strcmp("--all-tests", opt)) { all_tests = 1; } else if (!strcmp("--quiet", opt)) { quiet_flag = 1; } else if (!strcmp("--", opt)) { return 1; } else if (!strncmp("--", opt, 2)) { fatal("invalid option %s"); } else { return 2; } return 0; }
int command_create(args_t * args) { assert(args != NULL); uint32_t block = 0; uint32_t size = 0; uint32_t pad = 0xff; if (parse_size(args->block, &block) < 0) return -1; if (parse_size(args->size, &size) < 0) return -1; if (args->pad != NULL) if (parse_size(args->pad, &pad) < 0) return -1; struct stat st; if (stat(args->target, &st) < 0) { if (errno == ENOENT) { create_regular_file(args->target, size, (uint8_t)pad); } else { ERRNO(errno); return -1; } } else { if (st.st_size != size) { create_regular_file(args->target, size, (uint8_t)pad); } else { if (args->force != f_FORCE && st.st_size != size) { UNEXPECTED("--size '%d' differs from actual " "size '%lld', use --force to " "override", size, (long long)st.st_size); return -1; } } } /* ========================= */ int create(args_t * args, off_t poffset) { if (args->verbose == f_VERBOSE) printf("%llx: create partition table\n", (long long)poffset); const char * target = args->target; int debug = args->debug; RAII(FILE*, file, fopen_generic(target, "r+", debug), fclose); if (file == NULL) return -1; RAII(ffs_t*, ffs, __ffs_fcreate(file, poffset, block, size / block), __ffs_fclose); if (ffs == NULL) return -1; return 0; } /* ========================= */ return command(args, create); }
/* This is the underlying allocation function. It's called from * a few other places in guestfish. */ int alloc_disk (const char *filename, const char *size_str, int add, int sparse) { off_t size; int fd; char c = 0; if (parse_size (size_str, &size) == -1) return -1; if (!guestfs_is_config (g)) { fprintf (stderr, _("can't allocate or add disks after launching\n")); return -1; } fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_TRUNC, 0666); if (fd == -1) { perror (filename); return -1; } if (!sparse) { /* Not sparse */ #ifdef HAVE_POSIX_FALLOCATE int err = posix_fallocate (fd, 0, size); if (err != 0) { errno = err; perror ("fallocate"); close (fd); unlink (filename); return -1; } #else /* Slow emulation of posix_fallocate on platforms which don't have it. */ char buffer[BUFSIZ]; memset (buffer, 0, sizeof buffer); size_t remaining = size; while (remaining > 0) { size_t n = remaining > sizeof buffer ? sizeof buffer : remaining; ssize_t r = write (fd, buffer, n); if (r == -1) { perror ("write"); close (fd); unlink (filename); return -1; } remaining -= r; } #endif } else { /* Sparse */ if (lseek (fd, size-1, SEEK_SET) == (off_t) -1) { perror ("lseek"); close (fd); unlink (filename); return -1; } if (write (fd, &c, 1) != 1) { perror ("write"); close (fd); unlink (filename); return -1; } } if (close (fd) == -1) { perror (filename); unlink (filename); return -1; } if (add) { if (guestfs_add_drive_opts (g, filename, GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw", -1) == -1) { unlink (filename); return -1; } } return 0; }
void parse_vm_arguments1(JavaVMInitArgs *vm_args, size_t *p_string_pool_size, jboolean *p_is_class_data_shared, apr_pool_t* pool) { LogFormat logger_header = LOG_EMPTY; *p_string_pool_size = DEFAULT_STRING_TABLE_SIZE; // initialize logging system as soon as possible log_init(pool); for (int i = 0; i < vm_args->nOptions; i++) { const char* option = vm_args->options[i].optionString; if (begins_with(option, STRING_POOL_SIZE_OPTION)) { const char* arg = option + strlen(STRING_POOL_SIZE_OPTION); *p_string_pool_size = parse_size(arg); if (0 == *p_string_pool_size) { LECHO(34, "Negative or invalid string pool size. A default value is used, " << DEFAULT_STRING_TABLE_SIZE << " bytes."); *p_string_pool_size = DEFAULT_STRING_TABLE_SIZE; } TRACE("string_pool_size = " << *p_string_pool_size); } else if (!strcmp(option, CLASS_DATA_SHARING_OFF_OPTION)) { *p_is_class_data_shared = JNI_FALSE; } else if (!strcmp(option, CLASS_DATA_SHARING_ON_OPTION)) { *p_is_class_data_shared = JNI_TRUE; } else if (!strcmp(option, PORTLIB_OPTION)) { log_set_portlib((HyPortLibrary*) vm_args->options[i].extraInfo); } else if (!strcmp(option, "vfprintf")) { log_set_vfprintf(vm_args->options[i].extraInfo); } else if (!strcmp(option, "exit")) { log_set_exit(vm_args->options[i].extraInfo); } else if (!strcmp(option, "abort")) { log_set_abort(vm_args->options[i].extraInfo); } else if (!strcmp(option, "-Xfileline")) { logger_header |= LOG_FILELINE; } else if (!strcmp(option, "-Xthread")) { logger_header |= LOG_THREAD_ID; } else if (!strcmp(option, "-Xcategory")) { logger_header |= LOG_CATEGORY; } else if (!strcmp(option, "-Xtimestamp")) { logger_header |= LOG_TIMESTAMP; } else if (!strcmp(option, "-Xfunction")) { logger_header |= LOG_FUNCTION; } else if (!strcmp(option, "-Xwarn")) { logger_header |= LOG_WARN; /* * -verbose[:class|:gc|:jni] set specification log filters. */ } else if (!strcmp(option, "-verbose")) { log_enable_info_category(LOG_CLASS_INFO, 0); log_enable_info_category(LOG_GC_INFO, 0); log_enable_info_category(LOG_JNI_INFO, 0); } else if (!strcmp(option, "-verbose:class")) { log_enable_info_category(LOG_CLASS_INFO, 0); } else if (!strcmp(option, "-verbose:gc")) { log_enable_info_category(LOG_GC_INFO, 0); } else if (!strcmp(option, "-verbose:jni")) { log_enable_info_category(LOG_JNI_INFO, 0); } else if (begins_with(option, "-Xverboselog:")) { const char* file_name = option + strlen("-Xverboselog:"); FILE *f = fopen(file_name, "w"); if (NULL != f) { log_set_out(f); } else { WARN(("Cannot open: %s", file_name)); } } else if (begins_with(option, "-Xverbose:")) { log_enable_info_category(option + strlen("-Xverbose:"), 1); } else if (begins_with(option, "-Xnoverbose:")) { log_disable_info_category(option + strlen("-Xnoverbose:"), 1); #ifdef _DEBUG } else if (begins_with(option, "-Xtrace:")) { log_enable_trace_category(option + strlen("-Xtrace:"), 1); } else if (begins_with(option, "-Xnotrace:")) { log_disable_trace_category(option + strlen("-Xnotrace:"), 1); #endif //_DEBUG } } log_set_header_format(logger_header); } // parse_vm_arguments1
static void test_parse_size(void) { uint64_t bytes; assert_se(parse_size("111", 1024, &bytes) == 0); assert_se(bytes == 111); assert_se(parse_size("111.4", 1024, &bytes) == 0); assert_se(bytes == 111); assert_se(parse_size(" 112 B", 1024, &bytes) == 0); assert_se(bytes == 112); assert_se(parse_size(" 112.6 B", 1024, &bytes) == 0); assert_se(bytes == 112); assert_se(parse_size("3.5 K", 1024, &bytes) == 0); assert_se(bytes == 3*1024 + 512); assert_se(parse_size("3. K", 1024, &bytes) == 0); assert_se(bytes == 3*1024); assert_se(parse_size("3.0 K", 1024, &bytes) == 0); assert_se(bytes == 3*1024); assert_se(parse_size("3. 0 K", 1024, &bytes) == -EINVAL); assert_se(parse_size(" 4 M 11.5K", 1024, &bytes) == 0); assert_se(bytes == 4*1024*1024 + 11 * 1024 + 512); assert_se(parse_size("3B3.5G", 1024, &bytes) == -EINVAL); assert_se(parse_size("3.5G3B", 1024, &bytes) == 0); assert_se(bytes == 3ULL*1024*1024*1024 + 512*1024*1024 + 3); assert_se(parse_size("3.5G 4B", 1024, &bytes) == 0); assert_se(bytes == 3ULL*1024*1024*1024 + 512*1024*1024 + 4); assert_se(parse_size("3B3G4T", 1024, &bytes) == -EINVAL); assert_se(parse_size("4T3G3B", 1024, &bytes) == 0); assert_se(bytes == (4ULL*1024 + 3)*1024*1024*1024 + 3); assert_se(parse_size(" 4 T 3 G 3 B", 1024, &bytes) == 0); assert_se(bytes == (4ULL*1024 + 3)*1024*1024*1024 + 3); assert_se(parse_size("12P", 1024, &bytes) == 0); assert_se(bytes == 12ULL * 1024*1024*1024*1024*1024); assert_se(parse_size("12P12P", 1024, &bytes) == -EINVAL); assert_se(parse_size("3E 2P", 1024, &bytes) == 0); assert_se(bytes == (3 * 1024 + 2ULL) * 1024*1024*1024*1024*1024); assert_se(parse_size("12X", 1024, &bytes) == -EINVAL); assert_se(parse_size("12.5X", 1024, &bytes) == -EINVAL); assert_se(parse_size("12.5e3", 1024, &bytes) == -EINVAL); assert_se(parse_size("1024E", 1024, &bytes) == -ERANGE); assert_se(parse_size("-1", 1024, &bytes) == -ERANGE); assert_se(parse_size("-1024E", 1024, &bytes) == -ERANGE); assert_se(parse_size("-1024P", 1024, &bytes) == -ERANGE); assert_se(parse_size("-10B 20K", 1024, &bytes) == -ERANGE); }
void init_SIB2SF(BlinkParams *params, char *typ) { SIB2SF = parse_size(typ); }
void init_cmdFifoQueueSizeTX(BlinkParams *params, char *typ) { cmd_fifo_queue_size = (int)parse_size(typ); }
void init_dnlinkNRB(BlinkParams *params, char *typ) { dnlinkNRB = parse_size(typ); }
void init_dnlinkMCS(BlinkParams *params, char *typ) { dnlinkMCS = parse_size(typ); }
void init_LTEBand(BlinkParams *params, char *typ) { LTEBand = parse_size(typ); }
void init_debugLevel(BlinkParams *params, char *typ) { debug_level = parse_size(typ); }
void init_energyDetThr(BlinkParams *params, char *typ) { energyDetectionThreshold = parse_size(typ); }
void init_LatencySamplingRX(BlinkParams *params, char *siz) { params[1].latencySampling = parse_size(siz); }
void init_noTxBufsTX(BlinkParams *params, char *typ) { no_tx_bufs = (int)parse_size(typ); }
void init_LatencyCDFSizeRX(BlinkParams *params, char *siz) { params[1].latencyCDFSize = parse_size(siz); }
void init_inMemorySizeTX(BlinkParams *params, char *size) { params[0].inMemorySize = parse_size(size); }
static SIM_RC memory_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt, char *arg, int is_command) { switch (opt) { case OPTION_MEMORY_DELETE: if (strcasecmp (arg, "all") == 0) { while (STATE_MEMOPT (sd) != NULL) do_memopt_delete (sd, STATE_MEMOPT (sd)->level, STATE_MEMOPT (sd)->space, STATE_MEMOPT (sd)->addr); return SIM_RC_OK; } else { int level = 0; int space = 0; address_word addr = 0; parse_addr (arg, &level, &space, &addr); return do_memopt_delete (sd, level, space, addr); } case OPTION_MEMORY_REGION: { char *chp = arg; int level = 0; int space = 0; address_word addr = 0; address_word nr_bytes = 0; unsigned modulo = 0; /* parse the arguments */ chp = parse_addr (chp, &level, &space, &addr); if (*chp != ',') { sim_io_eprintf (sd, "Missing size for memory-region\n"); return SIM_RC_FAIL; } chp = parse_size (chp + 1, &nr_bytes, &modulo); /* old style */ if (*chp == ',') modulo = strtoul (chp + 1, &chp, 0); /* try to attach/insert it */ do_memopt_add (sd, level, space, addr, nr_bytes, modulo, &STATE_MEMOPT (sd), NULL); return SIM_RC_OK; } case OPTION_MEMORY_ALIAS: { char *chp = arg; int level = 0; int space = 0; address_word addr = 0; address_word nr_bytes = 0; unsigned modulo = 0; sim_memopt *entry; /* parse the arguments */ chp = parse_addr (chp, &level, &space, &addr); if (*chp != ',') { sim_io_eprintf (sd, "Missing size for memory-region\n"); return SIM_RC_FAIL; } chp = parse_size (chp + 1, &nr_bytes, &modulo); /* try to attach/insert the main record */ entry = do_memopt_add (sd, level, space, addr, nr_bytes, modulo, &STATE_MEMOPT (sd), NULL); /* now attach all the aliases */ while (*chp == ',') { int a_level = level; int a_space = space; address_word a_addr = addr; chp = parse_addr (chp + 1, &a_level, &a_space, &a_addr); do_memopt_add (sd, a_level, a_space, a_addr, nr_bytes, modulo, &entry->alias, entry->buffer); } return SIM_RC_OK; } case OPTION_MEMORY_SIZE: { int level = 0; int space = 0; address_word addr = 0; address_word nr_bytes = 0; unsigned modulo = 0; /* parse the arguments */ parse_size (arg, &nr_bytes, &modulo); /* try to attach/insert it */ do_memopt_add (sd, level, space, addr, nr_bytes, modulo, &STATE_MEMOPT (sd), NULL); return SIM_RC_OK; } case OPTION_MEMORY_CLEAR: { fill_byte_value = (unsigned8) 0; fill_byte_flag = 1; return SIM_RC_OK; break; } case OPTION_MEMORY_FILL: { unsigned long fill_value; parse_ulong_value (arg, &fill_value); if (fill_value > 255) { sim_io_eprintf (sd, "Missing fill value between 0 and 255\n"); return SIM_RC_FAIL; } fill_byte_value = (unsigned8) fill_value; fill_byte_flag = 1; return SIM_RC_OK; break; } case OPTION_MEMORY_INFO: { sim_memopt *entry; sim_io_printf (sd, "Memory maps:\n"); for (entry = STATE_MEMOPT (sd); entry != NULL; entry = entry->next) { sim_memopt *alias; sim_io_printf (sd, " memory"); if (entry->alias == NULL) sim_io_printf (sd, " region "); else sim_io_printf (sd, " alias "); if (entry->space != 0) sim_io_printf (sd, "0x%lx:", (long) entry->space); sim_io_printf (sd, "0x%08lx", (long) entry->addr); if (entry->level != 0) sim_io_printf (sd, "@0x%lx", (long) entry->level); sim_io_printf (sd, ",0x%lx", (long) entry->nr_bytes); if (entry->modulo != 0) sim_io_printf (sd, "%%0x%lx", (long) entry->modulo); for (alias = entry->alias; alias != NULL; alias = alias->next) { if (alias->space != 0) sim_io_printf (sd, "0x%lx:", (long) alias->space); sim_io_printf (sd, ",0x%08lx", (long) alias->addr); if (alias->level != 0) sim_io_printf (sd, "@0x%lx", (long) alias->level); } sim_io_printf (sd, "\n"); } return SIM_RC_OK; break; } default: sim_io_eprintf (sd, "Unknown memory option %d\n", opt); return SIM_RC_FAIL; } return SIM_RC_FAIL; }
void init_OffCycle(BlinkParams *params, char *siz) { lteu_context.offCycle = parse_size(siz); }
int main(int argc, char *argv[]) { int res; int src; int opt; int i; char *size_suf = NULL; int size_in_lines = -1; off_t size_base1000 = 0; off_t size_base1024 = 0; off_t user_defined_size = 0; off_t user_defined_size_lines = 0; struct copy_options copy_options; copy_options_init(©_options); copy_options.lines_mode = 0; copy_options.read_only = 0; copy_options.bar = &PROGRESS; while((opt = getopt(argc, argv, "rlhs:")) != -1) { switch(opt) { case 'r': copy_options.read_only = 1; break; case 'l': copy_options.lines_mode = 1; if(size_in_lines < 0) size_in_lines = 1; break; case 's': size_base1000 = parse_size(optarg, 1000, &size_suf); size_base1024 = parse_size(optarg, 1024, &size_suf); if(size_base1000 == -1) { fprintf(stderr, "Invalid argument: %s\n", optarg); exit(255); } if(strcasecmp(size_suf, "b") == 0) { size_in_lines = 0; } else if(strcasecmp(size_suf, "ln") == 0 || strcasecmp(size_suf, "l") == 0) { size_in_lines = 1; } else if(*size_suf != 0) { fprintf(stderr, "Invalid argument: %s\n", optarg); exit(255); } break; case 'h': case '?': default: usage(); exit(255); } } if(size_base1000 || size_base1024) { if(size_in_lines > 0) { if(!copy_options.lines_mode) { fprintf(stderr, "Error: size in lines has no effect without -l option!\n"); exit(255); } user_defined_size_lines = size_base1000; } else { user_defined_size = size_base1024; } } signal(SIGALRM, draw_progress); alarm(1); if(argc > optind) { for(i = optind; i < argc; i++) { if(argc - optind > 1) fprintf(stderr, "File %s:\n", argv[i]); while((src = open(argv[i], O_RDONLY)) < 1) { if(errno != EINTR) { perror(argv[i]); exit(errno); } } progress_init(&PROGRESS, STDERR_FILENO); PROGRESS.lines_mode = copy_options.lines_mode; PROGRESS.size = user_defined_size ? user_defined_size : filesize(src); PROGRESS.size_lines = user_defined_size_lines; DRAW_PROGRESS = 1; progress_draw(&PROGRESS); res = copy(src, STDOUT_FILENO, ©_options); if(res >= 0) PROGRESS.force_done = 1; progress_draw(&PROGRESS); DRAW_PROGRESS = 0; fputs("\n", stderr); if(res < 0) { perror("copy"); exit(errno); } close(src); } } else { progress_init(&PROGRESS, STDERR_FILENO); PROGRESS.lines_mode = copy_options.lines_mode; /* if used `pp < file` form */ PROGRESS.size = user_defined_size ? user_defined_size : filesize(STDIN_FILENO); PROGRESS.size_lines = user_defined_size_lines; DRAW_PROGRESS = 1; progress_draw(&PROGRESS); res = copy(STDIN_FILENO, STDOUT_FILENO, ©_options); if(res >= 0) PROGRESS.force_done = 1; progress_draw(&PROGRESS); DRAW_PROGRESS = 0; fputs("\n", stderr); } return EXIT_SUCCESS; }
void init_CTS_Subframes(BlinkParams *params, char *siz) { lteu_context.ctssubframes = parse_size(siz); }
static int ask_offset(struct fdisk_context *cxt, struct fdisk_ask *ask, char *buf, size_t bufsz) { char prompt[128] = { '\0' }; const char *q = fdisk_ask_get_query(ask); const char *range = fdisk_ask_number_get_range(ask); uint64_t dflt = fdisk_ask_number_get_default(ask), low = fdisk_ask_number_get_low(ask), high = fdisk_ask_number_get_high(ask), base = fdisk_ask_number_get_base(ask); assert(q); DBG(ASK, ul_debug("asking for offset ['%s', <%ju,%ju>, base=%ju, default=%ju, range: %s]", q, low, high, base, dflt, range)); if (range && dflt >= low && dflt <= high) snprintf(prompt, sizeof(prompt), _("%s (%s, default %ju): "), q, range, dflt); else if (dflt >= low && dflt <= high) snprintf(prompt, sizeof(prompt), _("%s (%ju-%ju, default %ju): "), q, low, high, dflt); else snprintf(prompt, sizeof(prompt), _("%s (%ju-%ju): "), q, low, high); do { uint64_t num = 0; char sig = 0, *p; int pwr = 0; int rc = get_user_reply(cxt, prompt, buf, bufsz); if (rc) return rc; if (!*buf && dflt >= low && dflt <= high) return fdisk_ask_number_set_result(ask, dflt); p = buf; if (*p == '+' || *p == '-') { sig = *buf; p++; } rc = parse_size(p, &num, &pwr); if (rc) continue; DBG(ASK, ul_debug("parsed size: %ju", num)); if (sig && pwr) { /* +{size}{K,M,...} specified, the "num" is in bytes */ uint64_t unit = fdisk_ask_number_get_unit(ask); num += unit/2; /* round */ num /= unit; } if (sig == '+') num += base; else if (sig == '-') num = base - num; DBG(ASK, ul_debug("final offset: %ju [sig: %c, power: %d, %s]", num, sig, pwr, sig ? "relative" : "absolute")); if (num >= low && num <= high) { if (sig && pwr) fdisk_ask_number_set_relative(ask, 1); return fdisk_ask_number_set_result(ask, num); } fdisk_warnx(cxt, _("Value out of range.")); } while (1); return -1; }
void init_outBufRX(BlinkParams *params, char *siz) { params[1].outBufSize = parse_size(siz); }
int run_hexedit (const char *cmd, size_t argc, char *argv[]) { if (argc < 1 || argc > 3) { fprintf (stderr, _("hexedit (device|filename) [max | start max]\n")); return -1; } const char *filename = argv[0]; off_t size = get_size (filename); if (size == -1) return -1; if (size == 0) { fprintf (stderr, _("hexedit: %s is a zero length file or device\n"), filename); return -1; } off_t start; off_t max; if (argc == 1) { /* hexedit device */ /* Check we're not going to download a huge file. */ if (size > MAX_DOWNLOAD_SIZE) { fprintf (stderr, _("hexedit: %s is larger than %s. You must supply a limit using\n" " 'hexedit %s <max>' (eg. 'hexedit %s 1M') or a range using\n" " 'hexedit %s <start> <max>'.\n"), filename, MAX_DOWNLOAD_SIZE_TEXT, filename, filename, filename); return -1; } start = 0; max = size; } else { if (argc == 3) { /* hexedit device start max */ if (parse_size (argv[1], &start) == -1) return -1; if (parse_size (argv[2], &max) == -1) return -1; } else { /* hexedit device max */ start = 0; if (parse_size (argv[1], &max) == -1) return -1; } if (start + max > size) max = size - start; } if (max <= 0) { fprintf (stderr, _("hexedit: invalid range\n")); return -1; } /* Download the requested range from the remote file|device into a * local temporary file. */ const char *editor; int r; struct stat oldstat, newstat; char tmpfd[sizeof "/dev/fd/" + 3 * sizeof (int)]; CLEANUP_FREE char *editcmd = NULL; CLEANUP_FREE char *tmpdir = guestfs_get_tmpdir (g), *tmp = NULL; if (asprintf (&tmp, "%s/guestfishXXXXXX", tmpdir) == -1) { perror ("asprintf"); return -1; } int fd = mkstemp (tmp); if (fd == -1) { perror ("mkstemp"); return -1; } /* Choose an editor. */ editor = getenv ("HEXEDITOR"); if (editor == NULL) editor = "hexedit"; snprintf (tmpfd, sizeof tmpfd, "/dev/fd/%d", fd); if (guestfs_download_offset (g, filename, tmpfd, start, max) == -1) { unlink (tmp); close (fd); return -1; } if (close (fd) == -1) { unlink (tmp); return -1; } /* Get the old stat. */ if (stat (tmp, &oldstat) == -1) { perror (tmp); unlink (tmp); return -1; } /* Edit it. */ if (asprintf (&editcmd, "%s %s", editor, tmp) == -1) { perror ("asprintf"); return -1; } r = system (editcmd); if (r != 0) { perror (editcmd); unlink (tmp); return -1; } /* Get the new stat. */ if (stat (tmp, &newstat) == -1) { perror (tmp); unlink (tmp); return -1; } /* Changed? */ if (oldstat.st_ctime == newstat.st_ctime && oldstat.st_size == newstat.st_size) { unlink (tmp); return 0; } /* Write new content. */ if (guestfs_upload_offset (g, tmp, filename, start) == -1) { unlink (tmp); return -1; } unlink (tmp); return 0; }
void init_outMemorySizeRX(BlinkParams *params, char *size) { params[1].outMemorySize = parse_size(size); }
static int opus_packet_parse_impl(const unsigned char *data, int len, int self_delimited, unsigned char *out_toc, const unsigned char *frames[48], short size[48], int *payload_offset) { int i, bytes; int count; int cbr; unsigned char ch, toc; int framesize; int last_size; const unsigned char *data0 = data; if (size==NULL) return OPUS_BAD_ARG; framesize = opus_packet_get_samples_per_frame(data, 48000); cbr = 0; toc = *data++; len--; last_size = len; switch (toc&0x3) { /* One frame */ case 0: count=1; break; /* Two CBR frames */ case 1: count=2; cbr = 1; if (!self_delimited) { if (len&0x1) return OPUS_INVALID_PACKET; size[0] = last_size = len/2; } break; /* Two VBR frames */ case 2: count = 2; bytes = parse_size(data, len, size); len -= bytes; if (size[0]<0 || size[0] > len) return OPUS_INVALID_PACKET; data += bytes; last_size = len-size[0]; break; /* Multiple CBR/VBR frames (from 0 to 120 ms) */ case 3: if (len<1) return OPUS_INVALID_PACKET; /* Number of frames encoded in bits 0 to 5 */ ch = *data++; count = ch&0x3F; if (count <= 0 || framesize*count > 5760) return OPUS_INVALID_PACKET; len--; /* Padding flag is bit 6 */ if (ch&0x40) { int padding=0; int p; do { if (len<=0) return OPUS_INVALID_PACKET; p = *data++; len--; padding += p==255 ? 254: p; } while (p==255); len -= padding; } if (len<0) return OPUS_INVALID_PACKET; /* VBR flag is bit 7 */ cbr = !(ch&0x80); if (!cbr) { /* VBR case */ last_size = len; for (i=0;i<count-1;i++) { bytes = parse_size(data, len, size+i); len -= bytes; if (size[i]<0 || size[i] > len) return OPUS_INVALID_PACKET; data += bytes; last_size -= bytes+size[i]; } if (last_size<0) return OPUS_INVALID_PACKET; } else if (!self_delimited) { /* CBR case */ last_size = len/count; if (last_size*count!=len) return OPUS_INVALID_PACKET; for (i=0;i<count-1;i++) size[i] = last_size; } break; } /* Self-delimited framing has an extra size for the last frame. */ if (self_delimited) { bytes = parse_size(data, len, size+count-1); len -= bytes; if (size[count-1]<0 || size[count-1] > len) return OPUS_INVALID_PACKET; data += bytes; /* For CBR packets, apply the size to all the frames. */ if (cbr) { if (size[count-1]*count > len) return OPUS_INVALID_PACKET; for (i=0;i<count-1;i++) size[i] = size[count-1]; } else if(size[count-1] > last_size) return OPUS_INVALID_PACKET; } else { /* Because it's not encoded explicitly, it's possible the size of the last packet (or all the packets, for the CBR case) is larger than 1275. Reject them here.*/ if (last_size > 1275) return OPUS_INVALID_PACKET; size[count-1] = last_size; } if (frames) { for (i=0;i<count;i++) { frames[i] = data; data += size[i]; } } if (out_toc) *out_toc = toc; if (payload_offset) *payload_offset = data-data0; return count; }
void init_heapSizeRX(BlinkParams *params, char *siz) { params[1].heapSize = parse_size(siz); }
int main(int argc, char *argv[], char *envp[]) { pid_t pid = 0, tree_id = 0; int ret = -1; bool usage_error = true; bool has_exec_cmd = false; int opt, idx; int log_level = LOG_UNSET; char *imgs_dir = "."; char *work_dir = NULL; static const char short_opts[] = "dSsRf:F:t:p:hcD:o:n:v::x::Vr:jlW:L:M:"; static struct option long_opts[] = { { "tree", required_argument, 0, 't' }, { "pid", required_argument, 0, 'p' }, { "leave-stopped", no_argument, 0, 's' }, { "leave-running", no_argument, 0, 'R' }, { "restore-detached", no_argument, 0, 'd' }, { "restore-sibling", no_argument, 0, 'S' }, { "daemon", no_argument, 0, 'd' }, { "contents", no_argument, 0, 'c' }, { "file", required_argument, 0, 'f' }, { "fields", required_argument, 0, 'F' }, { "images-dir", required_argument, 0, 'D' }, { "work-dir", required_argument, 0, 'W' }, { "log-file", required_argument, 0, 'o' }, { "namespaces", required_argument, 0, 'n' }, { "root", required_argument, 0, 'r' }, { USK_EXT_PARAM, optional_argument, 0, 'x' }, { "help", no_argument, 0, 'h' }, { SK_EST_PARAM, no_argument, 0, 1042 }, { "close", required_argument, 0, 1043 }, { "log-pid", no_argument, 0, 1044 }, { "version", no_argument, 0, 'V' }, { "evasive-devices", no_argument, 0, 1045 }, { "pidfile", required_argument, 0, 1046 }, { "veth-pair", required_argument, 0, 1047 }, { "action-script", required_argument, 0, 1049 }, { LREMAP_PARAM, no_argument, 0, 1041 }, { OPT_SHELL_JOB, no_argument, 0, 'j' }, { OPT_FILE_LOCKS, no_argument, 0, 'l' }, { "page-server", no_argument, 0, 1050 }, { "address", required_argument, 0, 1051 }, { "port", required_argument, 0, 1052 }, { "prev-images-dir", required_argument, 0, 1053 }, { "ms", no_argument, 0, 1054 }, { "track-mem", no_argument, 0, 1055 }, { "auto-dedup", no_argument, 0, 1056 }, { "libdir", required_argument, 0, 'L' }, { "cpu-cap", optional_argument, 0, 1057 }, { "force-irmap", no_argument, 0, 1058 }, { "ext-mount-map", required_argument, 0, 'M' }, { "exec-cmd", no_argument, 0, 1059 }, { "manage-cgroups", optional_argument, 0, 1060 }, { "cgroup-root", required_argument, 0, 1061 }, { "inherit-fd", required_argument, 0, 1062 }, { "feature", required_argument, 0, 1063 }, { "skip-mnt", required_argument, 0, 1064 }, { "enable-fs", required_argument, 0, 1065 }, { "enable-external-sharing", no_argument, 0, 1066 }, { "enable-external-masters", no_argument, 0, 1067 }, { "freeze-cgroup", required_argument, 0, 1068 }, { "ghost-limit", required_argument, 0, 1069 }, { "irmap-scan-path", required_argument, 0, 1070 }, { "lsm-profile", required_argument, 0, 1071 }, { "timeout", required_argument, 0, 1072 }, { "external", required_argument, 0, 1073 }, { }, }; BUILD_BUG_ON(PAGE_SIZE != PAGE_IMAGE_SIZE); if (fault_injection_init()) return 1; cr_pb_init(); setproctitle_init(argc, argv, envp); if (argc < 2) goto usage; init_opts(); if (init_service_fd()) return 1; if (!strcmp(argv[1], "swrk")) { if (argc < 3) goto usage; /* * This is to start criu service worker from libcriu calls. * The usage is "criu swrk <fd>" and is not for CLI/scripts. * The arguments semantics can change at any tyme with the * corresponding lib call change. */ opts.swrk_restore = true; return cr_service_work(atoi(argv[2])); } while (1) { idx = -1; opt = getopt_long(argc, argv, short_opts, long_opts, &idx); if (opt == -1) break; switch (opt) { case 's': opts.final_state = TASK_STOPPED; break; case 'R': opts.final_state = TASK_ALIVE; break; case 'x': if (optarg && unix_sk_ids_parse(optarg) < 0) return 1; opts.ext_unix_sk = true; break; case 'p': pid = atoi(optarg); if (pid <= 0) goto bad_arg; break; case 't': tree_id = atoi(optarg); if (tree_id <= 0) goto bad_arg; break; case 'c': opts.show_pages_content = true; break; case 'f': opts.show_dump_file = optarg; break; case 'F': opts.show_fmt = optarg; break; case 'r': opts.root = optarg; break; case 'd': opts.restore_detach = true; break; case 'S': opts.restore_sibling = true; break; case 'D': imgs_dir = optarg; break; case 'W': work_dir = optarg; break; case 'o': opts.output = optarg; break; case 'n': if (parse_ns_string(optarg)) goto bad_arg; break; case 'v': if (log_level == LOG_UNSET) log_level = 0; if (optarg) { if (optarg[0] == 'v') /* handle -vvvvv */ log_level += strlen(optarg) + 1; else log_level = atoi(optarg); } else log_level++; break; case 1041: pr_info("Will allow link remaps on FS\n"); opts.link_remap_ok = true; break; case 1042: pr_info("Will dump TCP connections\n"); opts.tcp_established_ok = true; break; case 1043: { int fd; fd = atoi(optarg); pr_info("Closing fd %d\n", fd); close(fd); break; } case 1044: opts.log_file_per_pid = 1; break; case 1045: opts.evasive_devices = true; break; case 1046: opts.pidfile = optarg; break; case 1047: { char *aux; aux = strchr(optarg, '='); if (aux == NULL) goto bad_arg; *aux = '\0'; if (veth_pair_add(optarg, aux + 1)) return 1; } break; case 1049: if (add_script(optarg, 0)) return 1; break; case 1050: opts.use_page_server = true; break; case 1051: opts.addr = optarg; break; case 1052: opts.port = htons(atoi(optarg)); if (!opts.port) goto bad_arg; break; case 'j': opts.shell_job = true; break; case 'l': opts.handle_file_locks = true; break; case 1053: opts.img_parent = optarg; break; case 1055: opts.track_mem = true; break; case 1056: opts.auto_dedup = true; break; case 1057: if (parse_cpu_cap(&opts, optarg)) goto usage; break; case 1058: opts.force_irmap = true; break; case 1054: opts.check_ms_kernel = true; break; case 'L': opts.libdir = optarg; break; case 1059: has_exec_cmd = true; break; case 1060: if (parse_manage_cgroups(&opts, optarg)) goto usage; break; case 1061: { char *path, *ctl; path = strchr(optarg, ':'); if (path) { *path = '\0'; path++; ctl = optarg; } else { path = optarg; ctl = NULL; } if (new_cg_root_add(ctl, path)) return -1; } break; case 1062: if (inherit_fd_parse(optarg) < 0) return 1; break; case 1063: if (check_add_feature(optarg) < 0) return 1; break; case 1064: if (!add_skip_mount(optarg)) return 1; break; case 1065: if (!add_fsname_auto(optarg)) return 1; break; case 1066: opts.enable_external_sharing = true; break; case 1067: opts.enable_external_masters = true; break; case 1068: opts.freeze_cgroup = optarg; break; case 1069: opts.ghost_limit = parse_size(optarg); break; case 1070: if (irmap_scan_path_add(optarg)) return -1; break; case 1071: if (parse_lsm_arg(optarg) < 0) return -1; case 1072: opts.timeout = atoi(optarg); break; case 'M': { char *aux; if (strcmp(optarg, "auto") == 0) { opts.autodetect_ext_mounts = true; break; } aux = strchr(optarg, ':'); if (aux == NULL) goto bad_arg; *aux = '\0'; if (ext_mount_add(optarg, aux + 1)) return 1; } break; case 1073: if (add_external(optarg)) return 1; break; case 'V': pr_msg("Version: %s\n", CRIU_VERSION); if (strcmp(CRIU_GITID, "0")) pr_msg("GitID: %s\n", CRIU_GITID); return 0; case 'h': usage_error = false; goto usage; default: goto usage; } } if (!opts.restore_detach && opts.restore_sibling) { pr_msg("--restore-sibling only makes sense with --restore-detach\n"); return 1; } if (!opts.autodetect_ext_mounts && (opts.enable_external_masters || opts.enable_external_sharing)) { pr_msg("must specify --ext-mount-map auto with --enable-external-{sharing|masters}"); return 1; } if (work_dir == NULL) work_dir = imgs_dir; if (optind >= argc) { pr_msg("Error: command is required\n"); goto usage; } if (has_exec_cmd) { if (argc - optind <= 1) { pr_msg("Error: --exec-cmd requires a command\n"); goto usage; } if (strcmp(argv[optind], "restore")) { pr_msg("Error: --exec-cmd is available for the restore command only\n"); goto usage; } if (opts.restore_detach) { pr_msg("Error: --restore-detached and --exec-cmd cannot be used together\n"); goto usage; } opts.exec_cmd = xmalloc((argc - optind) * sizeof(char *)); if (!opts.exec_cmd) return 1; memcpy(opts.exec_cmd, &argv[optind + 1], (argc - optind - 1) * sizeof(char *)); opts.exec_cmd[argc - optind - 1] = NULL; } /* We must not open imgs dir, if service is called */ if (strcmp(argv[optind], "service")) { ret = open_image_dir(imgs_dir); if (ret < 0) return 1; } if (chdir(work_dir)) { pr_perror("Can't change directory to %s", work_dir); return 1; } log_set_loglevel(log_level); if (log_init(opts.output)) return 1; if (!list_empty(&opts.external) && strcmp(argv[optind], "dump")) { pr_err("--external is dump-only option\n"); return 1; } if (!list_empty(&opts.inherit_fds)) { if (strcmp(argv[optind], "restore")) { pr_err("--inherit-fd is restore-only option\n"); return 1; } /* now that log file is set up, print inherit fd list */ inherit_fd_log(); } if (opts.img_parent) pr_info("Will do snapshot from %s\n", opts.img_parent); if (!strcmp(argv[optind], "dump")) { preload_socket_modules(); if (!tree_id) goto opt_pid_missing; return cr_dump_tasks(tree_id); } if (!strcmp(argv[optind], "pre-dump")) { if (!tree_id) goto opt_pid_missing; return cr_pre_dump_tasks(tree_id) != 0; } if (!strcmp(argv[optind], "restore")) { if (tree_id) pr_warn("Using -t with criu restore is obsoleted\n"); ret = cr_restore_tasks(); if (ret == 0 && opts.exec_cmd) { close_pid_proc(); execvp(opts.exec_cmd[0], opts.exec_cmd); pr_perror("Failed to exec command %s", opts.exec_cmd[0]); ret = 1; } return ret != 0; } if (!strcmp(argv[optind], "show")) return cr_show(pid) != 0; if (!strcmp(argv[optind], "check")) return cr_check() != 0; if (!strcmp(argv[optind], "exec")) { if (!pid) pid = tree_id; /* old usage */ if (!pid) goto opt_pid_missing; return cr_exec(pid, argv + optind + 1) != 0; } if (!strcmp(argv[optind], "page-server")) return cr_page_server(opts.daemon_mode, -1) > 0 ? 0 : 1; if (!strcmp(argv[optind], "service")) return cr_service(opts.daemon_mode); if (!strcmp(argv[optind], "dedup")) return cr_dedup() != 0; if (!strcmp(argv[optind], "cpuinfo")) { if (!argv[optind + 1]) goto usage; if (!strcmp(argv[optind + 1], "dump")) return cpuinfo_dump(); else if (!strcmp(argv[optind + 1], "check")) return cpuinfo_check(); } pr_msg("Error: unknown command: %s\n", argv[optind]); usage: pr_msg("\n" "Usage:\n" " criu dump|pre-dump -t PID [<options>]\n" " criu restore [<options>]\n" " criu check [--ms]\n" " criu exec -p PID <syscall-string>\n" " criu page-server\n" " criu service [<options>]\n" " criu dedup\n" "\n" "Commands:\n" " dump checkpoint a process/tree identified by pid\n" " pre-dump pre-dump task(s) minimizing their frozen time\n" " restore restore a process/tree\n" " check checks whether the kernel support is up-to-date\n" " exec execute a system call by other task\n" " page-server launch page server\n" " service launch service\n" " dedup remove duplicates in memory dump\n" " cpuinfo dump writes cpu information into image file\n" " cpuinfo check validates cpu information read from image file\n" ); if (usage_error) { pr_msg("\nTry -h|--help for more info\n"); return 1; } pr_msg("\n" "Dump/Restore options:\n" "\n" "* Generic:\n" " -t|--tree PID checkpoint a process tree identified by PID\n" " -d|--restore-detached detach after restore\n" " -S|--restore-sibling restore root task as sibling\n" " -s|--leave-stopped leave tasks in stopped state after checkpoint\n" " -R|--leave-running leave tasks in running state after checkpoint\n" " -D|--images-dir DIR directory for image files\n" " --pidfile FILE write root task, service or page-server pid to FILE\n" " -W|--work-dir DIR directory to cd and write logs/pidfiles/stats to\n" " (if not specified, value of --images-dir is used)\n" " --cpu-cap [CAP] require certain cpu capability. CAP: may be one of:\n" " 'cpu','fpu','all','ins','none'. To disable capability, prefix it with '^'.\n" " --exec-cmd execute the command specified after '--' on successful\n" " restore making it the parent of the restored process\n" " --freeze-cgroup\n" " use cgroup freezer to collect processes\n" "\n" "* Special resources support:\n" " -x|--" USK_EXT_PARAM "inode,.." " allow external unix connections (optionally can be assign socket's inode that allows one-sided dump)\n" " --" SK_EST_PARAM " checkpoint/restore established TCP connections\n" " -r|--root PATH change the root filesystem (when run in mount namespace)\n" " --evasive-devices use any path to a device file if the original one\n" " is inaccessible\n" " --veth-pair IN=OUT map inside veth device name to outside one\n" " can optionally append @<bridge-name> to OUT for moving\n" " the outside veth to the named bridge\n" " --link-remap allow one to link unlinked files back when possible\n" " --ghost-limit size specify maximum size of deleted file contents to be carried inside an image file\n" " --action-script FILE add an external action script\n" " -j|--" OPT_SHELL_JOB " allow one to dump and restore shell jobs\n" " -l|--" OPT_FILE_LOCKS " handle file locks, for safety, only used for container\n" " -L|--libdir path to a plugin directory (by default " CR_PLUGIN_DEFAULT ")\n" " --force-irmap force resolving names for inotify/fsnotify watches\n" " --irmap-scan-path FILE\n" " add a path the irmap hints to scan\n" " -M|--ext-mount-map KEY:VALUE\n" " add external mount mapping\n" " -M|--ext-mount-map auto\n" " attempt to autodetect external mount mapings\n" " --enable-external-sharing\n" " allow autoresolving mounts with external sharing\n" " --enable-external-masters\n" " allow autoresolving mounts with external masters\n" " --manage-cgroups [m] dump or restore cgroups the process is in usig mode:\n" " 'none', 'props', 'soft' (default), 'full' and 'strict'.\n" " --cgroup-root [controller:]/newroot\n" " change the root cgroup the controller will be\n" " installed into. No controller means that root is the\n" " default for all controllers not specified.\n" " --skip-mnt PATH ignore this mountpoint when dumping the mount namespace.\n" " --enable-fs FSNAMES a comma separated list of filesystem names or \"all\".\n" " force criu to (try to) dump/restore these filesystem's\n" " mountpoints even if fs is not supported.\n" " --external RES dump objects from this list as external resources:\n" " Formats of RES:\n" " tty[rdev:dev]\n" "\n" "* Logging:\n" " -o|--log-file FILE log file name\n" " --log-pid enable per-process logging to separate FILE.pid files\n" " -v[NUM] set logging level (higher level means more output):\n" " -v1|-v - only errors and messages\n" " -v2|-vv - also warnings (default level)\n" " -v3|-vvv - also information messages and timestamps\n" " -v4|-vvvv - lots of debug\n" "\n" "* Memory dumping options:\n" " --track-mem turn on memory changes tracker in kernel\n" " --prev-images-dir DIR path to images from previous dump (relative to -D)\n" " --page-server send pages to page server (see options below as well)\n" " --auto-dedup when used on dump it will deduplicate \"old\" data in\n" " pages images of previous dump\n" " when used on restore, as soon as page is restored, it\n" " will be punched from the image.\n" "\n" "Page/Service server options:\n" " --address ADDR address of server or service\n" " --port PORT port of page server\n" " -d|--daemon run in the background after creating socket\n" "\n" "Other options:\n" " -h|--help show this text\n" " -V|--version show version\n" " --ms don't check not yet merged kernel features\n" ); return 0; opt_pid_missing: pr_msg("Error: pid not specified\n"); return 1; bad_arg: if (idx < 0) /* short option */ pr_msg("Error: invalid argument for -%c: %s\n", opt, optarg); else /* long option */ pr_msg("Error: invalid argument for --%s: %s\n", long_opts[idx].name, optarg); return 1; }
static status_t read_sys_info( struct SYSInfo * sysinfo ) { char buff[BUFFLEN], buff1[BUFFLEN], str[BUFFLEN]; char *new_line, *find_str; int i, j, k, net_num, rval, fd; int kernel_26 = 0; /*************************** Initialization ****************************/ bzero(buff, BUFFLEN); bzero(buff1, BUFFLEN); bzero(str, BUFFLEN); init_sysinfo_data(sysinfo); /* Copy the network interface names from predefined CONSTNETNAME in * util.h if user has not specified a nic name */ if ( ! Defined_Nic_Name ) for ( i = 0; i < NETTYPE; i++ ) strcpy(NETNAME[i], CONSTNETNAME[i]); /************** Fill in loopback "interface" as the first NIC **********/ /* Loopback "interface" has no records in /proc/interrupts. We are still * interested in some statistics about this "interface", whose info be * found in /proc/net/dev. */ for ( i = 0; i < NETTYPE; i++ ) { if ( strncmp(NETNAME[i], "loop", strlen(NETNAME[i])) == 0 ) { sysinfo->net_num = 1; strcpy(sysinfo->net[0].name, "loop"); } } /*** Interrupt information is stored in /proc/interrupts in Linux ******/ if ( (fd = open("/proc/interrupts", O_RDONLY)) < 0 || (rval=read(fd, buff, BUFFLEN-1)) <= 0) { perror("Fail to get interrupt information from /proc/interrupts"); return NOTOK; } close(fd); /**** Frist line of /proc/interrupts indicates the number of CPUs ******/ for ( i = 0; buff[i] != '\n' && i < BUFFLEN-1; i++) // copy the first line to buff1 buff1[i] = buff[i]; if ( strlen(buff) == 0 || ( sysinfo->cpu_num = sscanf(buff1, "%s %s %s %s %s %s %s %s", str, str, str, str, str, str, str, str)) < 1 ) { perror("Failed to parse /proc/interrupts"); return NOTOK; } if ( sysinfo->cpu_num > 8 ) { fprintf(stderr, "Exceed the maximum CPU number: %d.\n",sysinfo->cpu_num); return NOTOK; } /********** Parse the interrupt information line by line ***************/ new_line = buff; net_num = sysinfo->net_num; while ( net_num < MAXNETWORK ) { /******************* Copy next line to buff1 for parsing ***********/ if ( (new_line = strstr(new_line, "\n")) == NULL ) break; new_line++; if ( strlen(new_line) == 0 ) break; strncpy(buff1, new_line, BUFFLEN-1); for ( i = 0; buff1[i] != '\n' && i < BUFFLEN-1; i++ ); buff1[i] = '\0'; /****************** Search the network interface entry *************/ for ( i = 0; i < NETTYPE; i++ ) { if ( (find_str = strstr(buff1, NETNAME[i])) != NULL ) { // got one /******************* First number is IRQ *******************/ sysinfo->net[net_num].irq = atoi(strtok(buff1, " :\t().,")); /******** Following are interrupts for each CPU ************/ for ( j = 0; j < sysinfo->cpu_num; j++ ) { sysinfo->cpu[j].net_int[net_num] = atol(strtok(NULL, " :\t().")); sysinfo->net[net_num].interrupt += sysinfo->cpu[j].net_int[net_num]; } /** The last part is device name such as keyboard and eth0 */ while ( (find_str = (char *)strtok(NULL, " :\t().,")) != NULL ) { if ( (find_str = strstr(find_str, NETNAME[i])) != NULL ) { strncpy(sysinfo->net[net_num].name, find_str, NETNAMELEN-1); break; } } net_num++; break; } // end of if find_str } // end of for loop } // end of while loop sysinfo->net_num = net_num; #ifdef DEBUG fprintf(stderr, " DEBUG: Parse /proc/interrupts (%d bytes read). CPU: %d Network-card: %d (%s %s %s)\n", rval, sysinfo->cpu_num, net_num, sysinfo->net[0].name, sysinfo->net[1].name, sysinfo->net[2].name); #endif /* FILE *fd1; if ( (fd1 = open("/proc/stat", "r")) == NULLf || fscanf(fp1, "%s %d %d %d %d", &str, &sysinfo->cpu_user, &sysinfo->cpu_nice, &sysinfo->cpu_system, &sysinfo->cpu_idle) != 5 ) { perror("Failed to get cpu information from /proc/stat."); return NOTOK; } fclose(fp1); */ /************************* Read CPU usage ******************************/ /* CPU information is stored in /proc/stat in Linux. Format: * cpu-name user-jiffies nice-jiffies system-jiffies idle-jiffies. For example, * cpu 123456 123 12345 1234567 * The number of jiffies that the system spent in user/nice/system/idle mode are * 123456, 123, 12345, and 1234567, respectively. Jiffy is defined by kernel (HZ). */ bzero(buff, BUFFLEN); if ( (fd = open("/proc/stat", O_RDONLY)) < 0 || (rval=read(fd, buff, BUFFLEN-1)) <= 0) { perror("Failed to get cpu information from /proc/stat."); return NOTOK; } close(fd); /************* First line shows the summary of CPU statistics **********/ if ( strlen(buff) == 0 || sscanf(buff, "%s %lld %lld %lld %lld", str, &sysinfo->cpu_user, &sysinfo->cpu_nice, &sysinfo->cpu_system, &sysinfo->cpu_idle) != 5 ) { perror("Failed to get cpu information from /proc/stat."); return NOTOK; } #ifdef DEBUG fprintf(stderr, " DEBUG: Parse /proc/stat (%d byt read): %lld[user] %lld[nice] %lld[system] %lld[idle]\n", rval, sysinfo->cpu_user, sysinfo->cpu_nice, sysinfo->cpu_system, sysinfo->cpu_idle); #endif /************************ Get each CPU's usage *************************/ new_line = buff; for( i = 0; i < sysinfo->cpu_num; i++){ if ( (new_line = strstr(new_line, "\n")) == NULL ) break; new_line++; if ( strlen(new_line) == 0 || sscanf(new_line, "%s %lld %lld %lld %lld", str, &sysinfo->cpu[i].user_mode, &sysinfo->cpu[i].nice_mode, &sysinfo->cpu[i].system_mode, &sysinfo->cpu[i].idle_mode) != 5 ) { perror("Failed to get cpu information from /proc/stat."); return NOTOK; } } if ( (new_line = strstr(buff, "page")) == NULL ) { kernel_26 = 1; } else { if ( sscanf(new_line, "%s %lld %lld", str, &sysinfo->page_in, &sysinfo->page_out) != 3 ) { perror("Fail to parse page info from /proc/stat."); return NOTOK; } if ( (new_line = strstr(buff, "swap")) == NULL || sscanf(new_line, "%s %lld %lld", str, &sysinfo->swap_in, &sysinfo->swap_out) != 3 ) { perror("Fail to parse swap info."); return NOTOK; } } if ( (new_line = strstr(buff, "intr")) == NULL || sscanf(new_line, "%s %lld", str, &sysinfo->interrupts) != 2 ) { perror("Fail to parse interrupt info from /proc/stat."); return NOTOK; } if ( (new_line = strstr(buff, "ctxt")) == NULL || sscanf(new_line, "%s %lld", str, &sysinfo->context_switch) != 2 ) { perror("Fail to parse context switch info from /proc/stat."); return NOTOK; } if ( kernel_26 ) { read_from_vmstat(sysinfo); read_memory_info(sysinfo); } else { /*************** Read memory information Kernel 2.4 ****************/ bzero(buff, BUFFLEN); if ( (fd = open("/proc/meminfo", O_RDONLY)) < 0 || (rval=read(fd, buff, BUFFLEN-1)) <= 0) { perror("Failed to open /proc/meminfo."); return NOTOK; } close(fd); /********* Ignore the first comment line of /proc/meminfo ************/ if ( (new_line = strstr(buff, "\n")) == NULL ) { perror("Fail to parse /proc/meminfo (No newline?)."); return NOTOK; } new_line++; /************* Parse the second line of /proc/meminfo ****************/ if ( strlen(new_line) == 0 || sscanf(new_line, "%s %lld %lld", str, &sysinfo->mem_total, &sysinfo->mem_used) != 3 ) { perror("Fail to parse /proc/meminfo (Wrong format)."); return NOTOK; } } #ifdef DEBUG fprintf(stderr, " DEBUG: Parse /proc/meminfo (%d byt read): %lld[mem-total] %lld[mem-used]\n", rval, sysinfo->mem_total, sysinfo->mem_used); #endif /*************** Read network device information ***********************/ bzero(buff, BUFFLEN); if ( (fd = open("/proc/net/dev", O_RDONLY)) < 0 || (rval=read(fd, buff, BUFFLEN-1)) <= 0) { perror("Failed to open /proc/net/dev."); return NOTOK; } close(fd); /******* Ignore the first two comment lines of /proc/net/dev ***********/ if ( (new_line = strstr(buff, "\n")) == NULL ) { perror("Fail to parse /proc/net/dev (No newline?)."); return NOTOK; } new_line++; for ( i = 0; i < MAXNETWORK; ) { /******************* Copy next line to buff1 for parsing ***********/ if ( (new_line = strstr(new_line, "\n")) == NULL ) break; new_line++; if ( strlen(new_line) == 0 ) break; strncpy(buff1, new_line, BUFFLEN-1); for ( j = 0; buff1[j] != '\n' && j < BUFFLEN-1; j++); buff1[j] = '\0'; strcpy(str, strtok(buff1, " :\t().")); for ( j = 0; j < sysinfo->net_num; j++ ) { if ( strncmp(str, sysinfo->net[j].name, strlen(str)) == 0 ) { sysinfo->net[j].recv_byte = parse_size( strtok(NULL, " :\t().")); sysinfo->net[j].recv_packet = parse_size(strtok(NULL, " :\t().")); for ( k = 0; k < 6; k++) // We don't use those middle six fields strtok(NULL, " :\t()."); sysinfo->net[j].send_byte = parse_size(strtok(NULL, " :\t().")); sysinfo->net[j].send_packet = parse_size(strtok(NULL, " :\t().")); #ifdef DEBUG fprintf(stderr, " DEBUG: %s: recv-bytes: %lld recv-packets: %lld send-bytes: %lld send-packets: %lld\n", sysinfo->net[j].name, sysinfo->net[j].recv_byte, sysinfo->net[j].recv_packet, sysinfo->net[j].send_byte, sysinfo->net[j].send_packet); #endif i++; break; } // end of if strncmp } // end of for loop of j } // end of for loop of i return OK; }