static int command_more(int argc, char *argv[]) { int i; int res; char line[80]; res=0; pager_open(); for (i = 1; (i < argc) && (res == 0); i++) { sprintf(line, "*** FILE %s BEGIN ***\n", argv[i]); if (pager_output(line)) break; res = page_file(argv[i]); if (!res) { sprintf(line, "*** FILE %s END ***\n", argv[i]); res = pager_output(line); } } pager_close(); if (res == 0) return CMD_OK; else return CMD_ERROR; }
static int command_show(int argc, char *argv[]) { struct env_var *ev; char *cp; if (argc < 2) { /* * With no arguments, print everything. */ pager_open(); for (ev = environ; ev != NULL; ev = ev->ev_next) { pager_output(ev->ev_name); cp = getenv(ev->ev_name); if (cp != NULL) { pager_output("="); pager_output(cp); } if (pager_output("\n")) break; } pager_close(); } else { if ((cp = getenv(argv[1])) != NULL) { printf("%s\n", cp); } else { sprintf(command_errbuf, "variable '%s' not found", argv[1]); return(CMD_ERROR); } } return(CMD_OK); }
int command_lskern(int argc, char *argv[]) { struct preloaded_file *fp; char lbuf[80]; int ch, verbose; verbose = 0; optind = 1; optreset = 1; pager_open(); for (fp = preloaded_files; fp; fp = fp->f_next) { snprintf(lbuf, sizeof(lbuf), " %p: %s (%s, 0x%lx)\n", (void *) fp->f_addr, fp->f_name, fp->f_type, (long) fp->f_size); pager_output(lbuf); if (fp->f_args != NULL) { pager_output(" args: "); pager_output(fp->f_args); pager_output("\n"); } } pager_close(); return(CMD_OK); }
static int list_timezones(int argc, char **argv, void *userdata) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; sd_bus *bus = userdata; _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; int r; char** zones; r = sd_bus_call_method(bus, "org.freedesktop.timedate1", "/org/freedesktop/timedate1", "org.freedesktop.timedate1", "ListTimezones", &error, &reply, NULL); if (r < 0) return log_error_errno(r, "Failed to request list of time zones: %s", bus_error_message(&error, r)); r = sd_bus_message_read_strv(reply, &zones); if (r < 0) return bus_log_parse_error(r); (void) pager_open(arg_pager_flags); strv_print(zones); return 0; }
static void efipart_print(int verbose) { char line[80]; EFI_BLOCK_IO *blkio; EFI_HANDLE h; EFI_STATUS status; u_int unit; pager_open(); for (unit = 0, h = efi_find_handle(&efipart_dev, 0); h != NULL; h = efi_find_handle(&efipart_dev, ++unit)) { sprintf(line, " %s%d:", efipart_dev.dv_name, unit); if (pager_output(line)) break; status = BS->HandleProtocol(h, &blkio_guid, (void **)&blkio); if (!EFI_ERROR(status)) { sprintf(line, " %llu blocks", (unsigned long long)(blkio->Media->LastBlock + 1)); if (pager_output(line)) break; if (blkio->Media->RemovableMedia) if (pager_output(" (removable)")) break; } if (pager_output("\n")) break; } pager_close(); }
int command_commandlist(int argc, char *argv[]) { struct bootblk_command *cmdp; int res; char name[20]; int i; res = 0; pager_open(); res = pager_output("Available commands:\n"); for (i = 0, cmdp = commands; (cmdp->c_name != NULL) && (cmdp->c_desc != NULL ); i++, cmdp = commands + i) { if (res) break; if ((cmdp->c_name != NULL) && (cmdp->c_desc != NULL)) { sprintf(name, " %s ", cmdp->c_name); pager_output(name); pager_output(cmdp->c_desc); res = pager_output("\n"); } } pager_close(); return(CMD_OK); }
static void pager_open_if_enabled(void) { if (arg_no_pager) return; pager_open(false); }
static void pager_open_if_enabled(void) { /* Cache result before we open the pager */ if (arg_no_pager) return; pager_open(false); }
static int list_timezones(int argc, char **argv, void *userdata) { _cleanup_strv_free_ char **zones = NULL; int r; r = get_timezones(&zones); if (r < 0) return log_error_errno(r, "Failed to read list of time zones: %m"); (void) pager_open(arg_no_pager, false); strv_print(zones); return 0; }
static int list_vconsole_keymaps(int argc, char **argv, void *userdata) { _cleanup_strv_free_ char **l = NULL; int r; r = get_keymaps(&l); if (r < 0) return log_error_errno(r, "Failed to read list of keymaps: %m"); (void) pager_open(arg_no_pager, false); strv_print(l); return 0; }
int main(int argc, char *argv[]) { int r, k; r = parse_argv(argc, argv); if (r <= 0) return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); umask(0022); r = 0; if (argc > optind) { int i; for (i = optind; i < argc; i++) { k = apply_file(argv[i], false); if (k < 0 && r == 0) r = k; } } else { _cleanup_strv_free_ char **files = NULL; char **f; r = conf_files_list_strv(&files, ".conf", NULL, 0, (const char**) CONF_PATHS_STRV("binfmt.d")); if (r < 0) { log_error_errno(r, "Failed to enumerate binfmt.d files: %m"); goto finish; } if (arg_cat_config) { (void) pager_open(arg_no_pager, false); r = cat_files(NULL, files, 0); goto finish; } /* Flush out all rules */ write_string_file("/proc/sys/fs/binfmt_misc/status", "-1", 0); STRV_FOREACH(f, files) { k = apply_file(*f, true); if (k < 0 && r == 0) r = k; } }
static int command_configuration(int argc, char *argv[]) { char line[80]; UINTN i; snprintf(line, sizeof(line), "NumberOfTableEntries=%lu\n", (unsigned long)ST->NumberOfTableEntries); pager_open(); if (pager_output(line)) { pager_close(); return (CMD_OK); } for (i = 0; i < ST->NumberOfTableEntries; i++) { EFI_GUID *guid; printf(" "); guid = &ST->ConfigurationTable[i].VendorGuid; if (!memcmp(guid, &mps, sizeof(EFI_GUID))) printf("MPS Table"); else if (!memcmp(guid, &acpi, sizeof(EFI_GUID))) printf("ACPI Table"); else if (!memcmp(guid, &acpi20, sizeof(EFI_GUID))) printf("ACPI 2.0 Table"); else if (!memcmp(guid, &smbios, sizeof(EFI_GUID))) printf("SMBIOS Table %p", ST->ConfigurationTable[i].VendorTable); else if (!memcmp(guid, &dxe, sizeof(EFI_GUID))) printf("DXE Table"); else if (!memcmp(guid, &hoblist, sizeof(EFI_GUID))) printf("HOB List Table"); else if (!memcmp(guid, &memtype, sizeof(EFI_GUID))) printf("Memory Type Information Table"); else if (!memcmp(guid, &debugimg, sizeof(EFI_GUID))) printf("Debug Image Info Table"); else if (!memcmp(guid, &fdtdtb, sizeof(EFI_GUID))) printf("FDT Table"); else printf("Unknown Table (%s)", guid_to_string(guid)); snprintf(line, sizeof(line), " at %p\n", ST->ConfigurationTable[i].VendorTable); if (pager_output(line)) break; } pager_close(); return (CMD_OK); }
static void efinet_dev_print(int verbose) { char line[80]; EFI_HANDLE h; int unit; pager_open(); for (unit = 0, h = efi_find_handle(&efinet_dev, 0); h != NULL; h = efi_find_handle(&efinet_dev, ++unit)) { sprintf(line, " %s%d:\n", efinet_dev.dv_name, unit); if (pager_output(line)) break; } pager_close(); }
static int list_timezones(sd_bus *bus, char **args, unsigned n) { _cleanup_strv_free_ char **zones = NULL; int r; assert(args); assert(n == 1); r = get_timezones(&zones); if (r < 0) return log_error_errno(r, "Failed to read list of time zones: %m"); pager_open(arg_no_pager, false); strv_print(zones); return 0; }
static int command_commandlist(int argc, char *argv[]) { struct bootblk_command **cmdp; char str[81]; pager_open(); printf("Available commands:\n"); SET_FOREACH(cmdp, Xcommand_set) { if (((*cmdp)->c_name != NULL) && ((*cmdp)->c_desc != NULL)) { snprintf(str, sizeof(str), " %-15s %s\n", (*cmdp)->c_name, (*cmdp)->c_desc); pager_output(str); } } pager_close(); return(CMD_OK); }
static int command_lsmod(int argc, char *argv[]) { struct loaded_module *am; struct module_metadata *md; char lbuf[80]; int ch, verbose; verbose = 0; optind = 1; optreset = 1; while ((ch = getopt(argc, argv, "v")) != -1) { switch(ch) { case 'v': verbose = 1; break; case '?': default: /* getopt has already reported an error */ return(CMD_OK); } } pager_open(); for (am = loaded_modules; (am != NULL); am = am->m_next) { sprintf(lbuf, " %p: %s (%s, 0x%lx)\n", (void *) am->m_addr, am->m_name, am->m_type, (long) am->m_size); pager_output(lbuf); if (am->m_args != NULL) { pager_output(" args: "); pager_output(am->m_args); pager_output("\n"); } if (verbose) /* XXX could add some formatting smarts here to display some better */ for (md = am->m_metadata; md != NULL; md = md->md_next) { sprintf(lbuf, " 0x%04x, 0x%lx\n", md->md_type, (long) md->md_size); pager_output(lbuf); } } pager_close(); return(CMD_OK); }
static void efinet_dev_print(int verbose) { CHAR16 *text; EFI_HANDLE h; int unit; pager_open(); for (unit = 0, h = efi_find_handle(&efinet_dev, 0); h != NULL; h = efi_find_handle(&efinet_dev, ++unit)) { printf(" %s%d:", efinet_dev.dv_name, unit); text = efi_devpath_name(efi_lookup_devpath(h)); if (text != NULL) { printf(" %S", text); efi_free_devpath_name(text); } if (pager_output("\n")) break; } pager_close(); }
static int command_lsdev(int argc, char *argv[]) { int verbose, ch, i; char line[80]; verbose = 0; optind = 1; optreset = 1; while ((ch = getopt(argc, argv, "v")) != -1) { switch(ch) { case 'v': verbose = 1; break; case '?': default: /* getopt has already reported an error */ return(CMD_OK); } } argv += (optind); argc -= (optind); pager_open(); for (i = 0; devsw[i] != NULL; i++) { if (devsw[i]->dv_print != NULL){ sprintf(line, "%s devices:\n", devsw[i]->dv_name); if (pager_output(line)) break; devsw[i]->dv_print(verbose); } else { sprintf(line, "%s: (unknown)\n", devsw[i]->dv_name); if (pager_output(line)) break; } } pager_close(); return(CMD_OK); }
/* * Please note: although we use the pager for the list of commands, * this routine is called from the ? FORTH function which then * unconditionally prints some commands. This will lead to anomalous * behavior. There's no 'pager_output' binding to FORTH to allow * things to work right, so I'm documenting the bug rather than * fixing it. */ static int command_commandlist(int argc, char *argv[]) { struct bootblk_command **cmdp; int res; char name[20]; res = 0; pager_open(); res = pager_output("Available commands:\n"); SET_FOREACH(cmdp, Xcommand_set) { if (res) break; if (((*cmdp)->c_name != NULL) && ((*cmdp)->c_desc != NULL)) { sprintf(name, " %-15s ", (*cmdp)->c_name); pager_output(name); pager_output((*cmdp)->c_desc); res = pager_output("\n"); } } pager_close(); return(CMD_OK); }
int command_lsdev(int argc, char *argv[]) { int verbose, ch, i; char line[80]; verbose = 0; optind = 1; optreset = 1; while ((ch = getopt(argc, argv, "v")) != -1) { switch(ch) { case 'v': verbose = 1; break; case '?': default: /* getopt has already reported an error */ return(CMD_OK); } } argv += (optind); argc -= (optind); pager_open(); sprintf(line, "Device Enumeration:\n"); pager_output(line); for (i = 0; i < ndevs; i++) { sprintf(line, "%s\n", devsw[i].dv_name); if (pager_output(line)) break; } pager_close(); return(CMD_OK); }
/* * Display a region in traditional hexdump format. */ void hexdump(caddr_t region, size_t len) { caddr_t line; int x, c; char lbuf[80]; #define emit(fmt, args...) {sprintf(lbuf, fmt , ## args); pager_output(lbuf);} pager_open(); for (line = region; line < (region + len); line += 16) { emit("%08lx ", (long) line); for (x = 0; x < 16; x++) { if ((line + x) < (region + len)) { emit("%02x ", *(u_int8_t *)(line + x)); } else { emit("-- "); } if (x == 7) emit(" "); } emit(" |"); for (x = 0; x < 16; x++) { if ((line + x) < (region + len)) { c = *(u_int8_t *)(line + x); if ((c < ' ') || (c > '~')) /* !isprint(c) */ c = '.'; emit("%c", c); } else { emit(" "); } } emit("|\n"); } pager_close(); }
int main(int argc, char *argv[]) { const char prefixes[] = "/etc\0" "/run\0" "/usr/local/lib\0" "/usr/local/share\0" "/usr/lib\0" "/usr/share\0" #ifdef HAVE_SPLIT_USR "/lib\0" #endif ; const char suffixes[] = "sysctl.d\0" "tmpfiles.d\0" "modules-load.d\0" "binfmt.d\0" "systemd/system\0" "systemd/user\0" "systemd/system-preset\0" "systemd/user-preset\0" "udev/rules.d\0" "modprobe.d\0"; int r = 0, k; int n_found = 0; log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) goto finish; if (arg_flags == 0) arg_flags = SHOW_DEFAULTS; if (arg_diff < 0) arg_diff = !!(arg_flags & SHOW_OVERRIDDEN); else if (arg_diff) arg_flags |= SHOW_OVERRIDDEN; if (!arg_no_pager) pager_open(); if (optind < argc) { int i; for (i = optind; i < argc; i++) { k = process_suffix_chop(prefixes, argv[i]); if (k < 0) r = k; else n_found += k; } } else { const char *n; NULSTR_FOREACH(n, suffixes) { k = process_suffix(prefixes, n); if (k < 0) r = k; else n_found += k; } }
static int command_ls(int argc, char *argv[]) { int fd; struct stat sb; struct dirent *d; char *buf, *path; char lbuf[128]; /* one line */ int result, ch; int verbose; result = CMD_OK; fd = -1; verbose = 0; optind = 1; optreset = 1; while ((ch = getopt(argc, argv, "l")) != -1) { switch(ch) { case 'l': verbose = 1; break; case '?': default: /* getopt has already reported an error */ return(CMD_OK); } } argv += (optind - 1); argc -= (optind - 1); if (argc < 2) { path = ""; } else { path = argv[1]; } fd = ls_getdir(&path); if (fd == -1) { result = CMD_ERROR; goto out; } pager_open(); pager_output(path); pager_output("\n"); while ((d = readdirfd(fd)) != NULL) { if (strcmp(d->d_name, ".") && strcmp(d->d_name, "..")) { if (verbose) { /* stat the file, if possible */ sb.st_size = 0; buf = malloc(strlen(path) + strlen(d->d_name) + 2); sprintf(buf, "%s/%s", path, d->d_name); /* ignore return, could be symlink, etc. */ if (stat(buf, &sb)) sb.st_size = 0; free(buf); sprintf(lbuf, " %c %8d %s\n", typestr[d->d_type], (int)sb.st_size, d->d_name); } else { sprintf(lbuf, " %c %s\n", typestr[d->d_type], d->d_name); } if (pager_output(lbuf)) goto out; } } out: pager_close(); if (fd != -1) close(fd); if (path != NULL) free(path); return(result); }
int main(int argc, char *argv[]) { int r, output_flags; log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) goto finish; if (!arg_no_pager) { r = pager_open(false); if (r > 0 && arg_full < 0) arg_full = true; } output_flags = arg_all * OUTPUT_SHOW_ALL | (arg_full > 0) * OUTPUT_FULL_WIDTH; if (optind < argc) { _cleanup_free_ char *root = NULL; int i; r = get_cgroup_root(&root); if (r < 0) goto finish; for (i = optind; i < argc; i++) { int q; if (path_startswith(argv[i], "/sys/fs/cgroup")) { printf("Directory %s:\n", argv[i]); fflush(stdout); q = show_cgroup_by_path(argv[i], NULL, 0, arg_kernel_threads, output_flags); } else { _cleanup_free_ char *c = NULL, *p = NULL, *j = NULL; const char *controller, *path; r = cg_split_spec(argv[i], &c, &p); if (r < 0) { log_error_errno(r, "Failed to split argument %s: %m", argv[i]); goto finish; } controller = c ?: SYSTEMD_CGROUP_CONTROLLER; if (p) { j = strjoin(root, "/", p, NULL); if (!j) { r = log_oom(); goto finish; } path_kill_slashes(j); path = j; } else path = root; show_cg_info(controller, path); q = show_cgroup(controller, path, NULL, 0, arg_kernel_threads, output_flags); } if (q < 0) r = q; } } else {
int main(int argc, char *argv[]) { int r = 0, retval = EXIT_FAILURE; int output_flags; log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r < 0) goto finish; else if (r == 0) { retval = EXIT_SUCCESS; goto finish; } if (!arg_no_pager) { r = pager_open(false); if (r > 0) { if (arg_full == -1) arg_full = true; } } output_flags = arg_all * OUTPUT_SHOW_ALL | (arg_full > 0) * OUTPUT_FULL_WIDTH; if (optind < argc) { unsigned i; for (i = (unsigned) optind; i < (unsigned) argc; i++) { int q; printf("%s:\n", argv[i]); q = show_cgroup_by_path(argv[i], NULL, 0, arg_kernel_threads, output_flags); if (q < 0) r = q; } } else { char _cleanup_free_ *p; p = get_current_dir_name(); if (!p) { log_error("Cannot determine current working directory: %m"); goto finish; } if (path_startswith(p, "/sys/fs/cgroup")) { printf("Working Directory %s:\n", p); r = show_cgroup_by_path(p, NULL, 0, arg_kernel_threads, output_flags); } else { char _cleanup_free_ *root = NULL; const char *t = NULL; r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, 1, &root); if (r < 0) t = "/"; else { if (endswith(root, "/system")) root[strlen(root)-7] = 0; t = root[0] ? root : "/"; } r = show_cgroup(SYSTEMD_CGROUP_CONTROLLER, t, NULL, 0, arg_kernel_threads, output_flags); } } if (r < 0) log_error("Failed to list cgroup tree: %s", strerror(-r)); retval = EXIT_SUCCESS; finish: pager_close(); return retval; }
static int inspect_image(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL; _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; _cleanup_strv_free_ char **matches = NULL; _cleanup_free_ char *image = NULL; bool nl = false, header = false; const void *data; const char *path; size_t sz; int r; r = determine_image(argv[1], false, &image); if (r < 0) return r; r = determine_matches(argv[1], argv + 2, true, &matches); if (r < 0) return r; r = acquire_bus(&bus); if (r < 0) return r; r = sd_bus_message_new_method_call( bus, &m, "org.freedesktop.portable1", "/org/freedesktop/portable1", "org.freedesktop.portable1.Manager", "GetImageMetadata"); if (r < 0) return bus_log_create_error(r); r = sd_bus_message_append(m, "s", image); if (r < 0) return bus_log_create_error(r); r = sd_bus_message_append_strv(m, matches); if (r < 0) return bus_log_create_error(r); r = sd_bus_call(bus, m, 0, &error, &reply); if (r < 0) return log_error_errno(r, "Failed to inspect image metadata: %s", bus_error_message(&error, r)); r = sd_bus_message_read(reply, "s", &path); if (r < 0) return bus_log_parse_error(r); r = sd_bus_message_read_array(reply, 'y', &data, &sz); if (r < 0) return bus_log_parse_error(r); (void) pager_open(arg_pager_flags); if (arg_cat) { printf("%s-- OS Release: --%s\n", ansi_highlight(), ansi_normal()); fwrite(data, sz, 1, stdout); fflush(stdout); nl = true; } else { _cleanup_free_ char *pretty_portable = NULL, *pretty_os = NULL; _cleanup_fclose_ FILE *f; f = fmemopen_unlocked((void*) data, sz, "re"); if (!f) return log_error_errno(errno, "Failed to open /etc/os-release buffer: %m"); r = parse_env_file(f, "/etc/os-release", "PORTABLE_PRETTY_NAME", &pretty_portable, "PRETTY_NAME", &pretty_os); if (r < 0) return log_error_errno(r, "Failed to parse /etc/os-release: %m"); printf("Image:\n\t%s\n" "Portable Service:\n\t%s\n" "Operating System:\n\t%s\n", path, strna(pretty_portable), strna(pretty_os)); } r = sd_bus_message_enter_container(reply, 'a', "{say}"); if (r < 0) return bus_log_parse_error(r); for (;;) { const char *name; r = sd_bus_message_enter_container(reply, 'e', "say"); if (r < 0) return bus_log_parse_error(r); if (r == 0) break; r = sd_bus_message_read(reply, "s", &name); if (r < 0) return bus_log_parse_error(r); r = sd_bus_message_read_array(reply, 'y', &data, &sz); if (r < 0) return bus_log_parse_error(r); if (arg_cat) { if (nl) fputc('\n', stdout); printf("%s-- Unit file: %s --%s\n", ansi_highlight(), name, ansi_normal()); fwrite(data, sz, 1, stdout); fflush(stdout); nl = true; } else { if (!header) { fputs("Unit files:\n", stdout); header = true; } fputc('\t', stdout); fputs(name, stdout); fputc('\n', stdout); } r = sd_bus_message_exit_container(reply); if (r < 0) return bus_log_parse_error(r); } r = sd_bus_message_exit_container(reply); if (r < 0) return bus_log_parse_error(r); return 0; }
int main(int argc, char *argv[]) { int r = 0, retval = EXIT_FAILURE; int output_flags; _cleanup_free_ char *root = NULL; _cleanup_bus_close_unref_ sd_bus *bus = NULL; log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r < 0) goto finish; else if (r == 0) { retval = EXIT_SUCCESS; goto finish; } if (!arg_no_pager) { r = pager_open(false); if (r > 0) { if (arg_full == -1) arg_full = true; } } output_flags = arg_all * OUTPUT_SHOW_ALL | (arg_full > 0) * OUTPUT_FULL_WIDTH; r = bus_open_transport(BUS_TRANSPORT_LOCAL, NULL, false, &bus); if (r < 0) { log_error_errno(r, "Failed to create bus connection: %m"); goto finish; } if (optind < argc) { int i; for (i = optind; i < argc; i++) { int q; fprintf(stdout, "%s:\n", argv[i]); fflush(stdout); if (arg_machine) root = strjoin("machine/", arg_machine, "/", argv[i], NULL); else root = strdup(argv[i]); if (!root) return log_oom(); q = show_cgroup_by_path(root, NULL, 0, arg_kernel_threads, output_flags); if (q < 0) r = q; } } else { _cleanup_free_ char *p; p = get_current_dir_name(); if (!p) { log_error_errno(errno, "Cannot determine current working directory: %m"); goto finish; } if (path_startswith(p, "/sys/fs/cgroup") && !arg_machine) { printf("Working Directory %s:\n", p); r = show_cgroup_by_path(p, NULL, 0, arg_kernel_threads, output_flags); } else { if (arg_machine) { char *m; const char *cgroup; _cleanup_free_ char *scope = NULL; _cleanup_free_ char *path = NULL; _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; m = strjoina("/run/systemd/machines/", arg_machine); r = parse_env_file(m, NEWLINE, "SCOPE", &scope, NULL); if (r < 0) { log_error_errno(r, "Failed to get machine path: %m"); goto finish; } path = unit_dbus_path_from_name(scope); if (!path) { log_oom(); goto finish; } r = sd_bus_get_property( bus, "org.freedesktop.systemd1", path, "org.freedesktop.systemd1.Scope", "ControlGroup", &error, &reply, "s"); if (r < 0) { log_error("Failed to query ControlGroup: %s", bus_error_message(&error, -r)); goto finish; } r = sd_bus_message_read(reply, "s", &cgroup); if (r < 0) { bus_log_parse_error(r); goto finish; } root = strdup(cgroup); if (!root) { log_oom(); goto finish; } } else r = cg_get_root_path(&root); if (r < 0) { log_error_errno(r, "Failed to get %s path: %m", arg_machine ? "machine" : "root"); goto finish; } r = show_cgroup(SYSTEMD_CGROUP_CONTROLLER, root, NULL, 0, arg_kernel_threads, output_flags); } } if (r < 0) { log_error_errno(r, "Failed to list cgroup tree %s: %m", root); retval = EXIT_FAILURE; } else retval = EXIT_SUCCESS; finish: pager_close(); return retval; }
static int list_x11_keymaps(int argc, char **argv, void *userdata) { _cleanup_fclose_ FILE *f = NULL; _cleanup_strv_free_ char **list = NULL; char line[LINE_MAX]; enum { NONE, MODELS, LAYOUTS, VARIANTS, OPTIONS } state = NONE, look_for; int r; f = fopen("/usr/share/X11/xkb/rules/base.lst", "re"); if (!f) return log_error_errno(errno, "Failed to open keyboard mapping list. %m"); if (streq(argv[0], "list-x11-keymap-models")) look_for = MODELS; else if (streq(argv[0], "list-x11-keymap-layouts")) look_for = LAYOUTS; else if (streq(argv[0], "list-x11-keymap-variants")) look_for = VARIANTS; else if (streq(argv[0], "list-x11-keymap-options")) look_for = OPTIONS; else assert_not_reached("Wrong parameter"); FOREACH_LINE(line, f, break) { char *l, *w; l = strstrip(line); if (isempty(l)) continue; if (l[0] == '!') { if (startswith(l, "! model")) state = MODELS; else if (startswith(l, "! layout")) state = LAYOUTS; else if (startswith(l, "! variant")) state = VARIANTS; else if (startswith(l, "! option")) state = OPTIONS; else state = NONE; continue; } if (state != look_for) continue; w = l + strcspn(l, WHITESPACE); if (argc > 1) { char *e; if (*w == 0) continue; *w = 0; w++; w += strspn(w, WHITESPACE); e = strchr(w, ':'); if (!e) continue; *e = 0; if (!streq(w, argv[1])) continue; } else *w = 0; r = strv_extend(&list, l); if (r < 0) return log_oom(); } if (strv_isempty(list)) { log_error("Couldn't find any entries."); return -ENOENT; } strv_sort(list); strv_uniq(list); (void) pager_open(arg_no_pager, false); strv_print(list); return 0; }
void ofw_memmap(int acells) { struct ofw_mapping *mapptr; struct ofw_mapping2 *mapptr2; phandle_t mmup; int nmapping, i; u_char mappings[256 * sizeof(struct ofw_mapping2)]; char lbuf[80]; mmup = OF_instance_to_package(mmu); bzero(mappings, sizeof(mappings)); nmapping = OF_getprop(mmup, "translations", mappings, sizeof(mappings)); if (nmapping == -1) { printf("Could not get memory map (%d)\n", nmapping); return; } pager_open(); if (acells == 1) { nmapping /= sizeof(struct ofw_mapping); mapptr = (struct ofw_mapping *) mappings; printf("%17s\t%17s\t%8s\t%6s\n", "Virtual Range", "Physical Range", "#Pages", "Mode"); for (i = 0; i < nmapping; i++) { sprintf(lbuf, "%08x-%08x\t%08x-%08x\t%8d\t%6x\n", mapptr[i].va, mapptr[i].va + mapptr[i].len, mapptr[i].pa, mapptr[i].pa + mapptr[i].len, mapptr[i].len / 0x1000, mapptr[i].mode); if (pager_output(lbuf)) break; } } else { nmapping /= sizeof(struct ofw_mapping2); mapptr2 = (struct ofw_mapping2 *) mappings; printf("%17s\t%17s\t%8s\t%6s\n", "Virtual Range", "Physical Range", "#Pages", "Mode"); for (i = 0; i < nmapping; i++) { sprintf(lbuf, "%08x-%08x\t%08x-%08x\t%8d\t%6x\n", mapptr2[i].va, mapptr2[i].va + mapptr2[i].len, mapptr2[i].pa_lo, mapptr2[i].pa_lo + mapptr2[i].len, mapptr2[i].len / 0x1000, mapptr2[i].mode); if (pager_output(lbuf)) break; } } pager_close(); }
static int command_help(int argc, char *argv[]) { char buf[81]; /* XXX buffer size? */ int hfd, matched, doindex; char *topic, *subtopic, *t, *s, *d; /* page the help text from our load path */ /* sprintf(buf, "%s/boot/loader.help", getenv("loaddev")); */ /* page the help text from our base path */ snprintf(buf, sizeof(buf), "%sloader.help", getenv("base")); if ((hfd = open(buf, O_RDONLY)) < 0) { if ((hfd = rel_open("loader.help", NULL, O_RDONLY)) < 0) { printf("Verbose help not available, use '?' to list commands\n"); return(CMD_OK); } } /* pick up request from arguments */ topic = subtopic = NULL; switch(argc) { case 3: subtopic = strdup(argv[2]); case 2: topic = strdup(argv[1]); break; case 1: topic = strdup("help"); break; default: command_errmsg = "usage is 'help <topic> [<subtopic>]"; return(CMD_ERROR); } /* magic "index" keyword */ doindex = !strcmp(topic, "index"); matched = doindex; /* Scan the helpfile looking for help matching the request */ pager_open(); while(help_getnext(hfd, &t, &s, &d)) { if (doindex) { /* dink around formatting */ help_emitsummary(t, s, d); } else if (strcmp(topic, t)) { /* topic mismatch */ if(matched) /* nothing more on this topic, stop scanning */ break; } else { /* topic matched */ matched = 1; if (((subtopic == NULL) && (s == NULL)) || ((subtopic != NULL) && (s != NULL) && !strcmp(subtopic, s))) { /* exact match, print text */ while((fgetstr(buf, 80, hfd) >= 0) && (buf[0] != '#')) { if (pager_output(buf)) break; if (pager_output("\n")) break; } } else if ((subtopic == NULL) && (s != NULL)) { /* topic match, list subtopics */ help_emitsummary(t, s, d); } } free(t); free(s); free(d); } pager_close(); close(hfd); if (!matched) { sprintf(command_errbuf, "no help available for '%s'", topic); free(topic); if (subtopic) free(subtopic); return(CMD_ERROR); } free(topic); if (subtopic) free(subtopic); return(CMD_OK); }