static void dump_metadata_ptrs (MonoImage *meta) { printf ("\nMetadata pointers:\n"); dsh ("\tTables (#~)", meta, &meta->heap_tables); dsh ("\t Strings", meta, &meta->heap_strings); dsh ("\t Blob", meta, &meta->heap_blob); dsh ("\tUser string", meta, &meta->heap_us); dsh ("\t GUID", meta, &meta->heap_guid); }
/* * Prompt for dsh commands, then execute them, prompt again, ... * "quit", "exit", or ^D to get out. * opt (IN) program options struct */ static void _interactive_dsh(opt_t * opt) { pid_t pid; signal(SIGINT, SIG_IGN); while ((opt->cmd = _getcmd(opt->progname))) { if (*opt->cmd == '\0') { /* empty command */ Free((void **) &opt->cmd); continue; } if (*opt->cmd == '!') { /* shell escape */ _shell(opt->luid, opt->cmd + 1); Free((void **) &opt->cmd); continue; } if (strcmp(opt->cmd, "quit") == 0 /* user exit */ || strcmp(opt->cmd, "exit") == 0) { Free((void **) &opt->cmd); break; } /* must fork dsh so we can ignore SIGINT in prompt loop */ switch (pid = fork()) { case -1: errx("%p: fork: %m\n"); case 0: dsh(opt); /* run command */ exit(0); default: while (waitpid(pid, NULL, 0) < 0 && errno == EINTR); } Free((void **) &opt->cmd); } }
int main(int argc, char *argv[]) { opt_t opt; int retval = 0; const char *m; /* * Initialize. */ err_init(xbasename(argv[0])); /* init err package */ /* * If running setuid, fork a child to handle * all privileged operations and drop privs in this process. */ privsep_init(); /* * Seed options with default values: */ opt_default(&opt, argv[0]); /* * Override defaults with environment */ opt_env(&opt); /* * Process any options that need to be handled early: */ opt_args_early(&opt, argc, argv); /* * Load static or dynamic pdsh modules */ mod_init(); /* * Allow module directory to be overridden, but not when * running as root or setuid. (This is mainly for testing...) */ if (!(m = getenv ("PDSH_MODULE_DIR")) || getuid() == 0 || getuid() != geteuid()) m = pdsh_module_dir; if (mod_load_modules(m, &opt) < 0) errx("%p: Couldn't load any pdsh modules\n"); /* * Handle options. */ opt_args(&opt, argc, argv); /* override with command line */ if (opt_verify(&opt)) { /* verify options, print errors */ /* * Do the work. */ if (opt.info_only) /* display info only */ opt_list(&opt); else if (pdsh_personality() == PCP && opt.pcp_server) retval = (_pcp_remote_server (&opt) < 0); else if (pdsh_personality() == PCP && opt.pcp_client) retval = (_pcp_remote_client (&opt) < 0); else if (pdsh_personality() == PCP || opt.cmd != NULL) retval = dsh(&opt); /* single dsh/pcp command */ else /* prompt loop */ _interactive_dsh(&opt); } else { retval = 1; } mod_exit(); /* * Clean up. */ privsep_fini(); opt_free(&opt); /* free heap storage in opt struct */ err_cleanup(); return retval; }
/* Warning: May be running setuid root! */ static void _interactive_dsh(opt_t * opt) { pid_t pid; char prompt[64]; char history_filename[MAXPATHLEN]; char *cmd = NULL; int got_history_file = 1; int len; snprintf(prompt, sizeof(prompt), "%s> ", opt->progname); using_history (); len = sizeof (history_filename); if (_history_file_create (history_filename, len) < 0) { got_history_file = 0; } while ((cmd = readline(prompt)) != NULL) { int errnum; char *expansion; if ((errnum = history_expand (cmd, &expansion))) { err ("%p: %s\n", expansion); } free (cmd); if ((errnum < 0) || (errnum == 2)) { free (expansion); continue; } cmd = expansion; if (!strcmp(cmd, "history")) { _history_list (); continue; } add_history (cmd); if (strlen(cmd) == 0) { /* empty line */ free(cmd); continue; } if (!strcmp(cmd, "quit") || !strcmp(cmd, "exit")) { free(cmd); /* quit or exit */ break; } if ((strlen(cmd) != 0) && (got_history_file)) append_history (1, history_filename); /* * fork dsh so we can ignore SIGINT in prompt loop */ switch (pid = fork()) { case -1: /* error */ errx("%p: fork: %m\n"); case 0: /* child - run cmd */ opt->cmd = Strdup(cmd); dsh(opt); Free((void **) &opt->cmd); exit(0); default: /* parent - wait */ while (waitpid(pid, NULL, 0) < 0) { if (errno != EINTR) break; } break; } free (cmd); } }