int main(int argc, char** argv) { int c, i, mypid; int opt_depth = 1; int opt_mknod = 0; static struct option long_opt[] = { {"depth", 1, 0, 'd' }, {"help", 0, 0, 'h' }, {"mknod", 0, 0, 'm' }, {"output", 1, 0, 'o' }, {"trace", 1, 0, 't' }, {"verbose", 0, 0, 'v' }, {0,0,0,0} }; char *outputfilename = NULL; char *base_pathname; char pathname[PATH_MAX]; char mark_buf[PATH_MAX + 50]; char mycwd[PATH_MAX]; char *pname = argv[0]; while ((c = getopt_long(argc, argv, "d:mhvo:", long_opt, NULL)) != -1) { switch (c) { case 'd': opt_depth = atoi(optarg); if ((opt_depth == 0) || (opt_depth > 1100)) usage(pname); break; case 'm': opt_mknod = 1; break; case 't': opt_trace = 1; break; case 'v': opt_verbose = 1; break; case 'o': outputfilename = optarg; break; case 'h': case '?': case ':': default: usage(pname); break; } } if (optind != (argc - 1)) usage(pname); base_pathname = argv[optind]; mypid = getpid(); if (!getcwd(&mycwd[0], sizeof(mycwd))) { fprintf(stderr, "%s: unable to getcwd()\n", pname); exit(1); } printf("%s(pid=%d) depth=%d mknod=%d, basepathname=%s, trace=%d\n", pname, mypid, opt_depth, opt_mknod, base_pathname, opt_trace); if (outputfilename) printf("outputfilename=%s\n", outputfilename); if (opt_trace) { ltrace_start(); ltrace_clear(); snprintf(mark_buf, PATH_MAX, "Initialize - mkdir %s; chdir %s", base_pathname, base_pathname); ltrace_mark(2, mark_buf); } if (do_mkdir(base_pathname)!=0) exit(1); if (do_chdir(base_pathname)!=0) exit(1); /* Create directory tree with depth level of subdirectories */ if (opt_trace) { snprintf(mark_buf, PATH_MAX, "Create Directory Tree (depth %d)", opt_depth); ltrace_mark(2, mark_buf); } for (i = 0; i < opt_depth; i++) { snprintf(pathname, sizeof(pathname), "%d", i + 1); if (i == (opt_depth - 1)) { /* Last Iteration */ if (opt_trace) { snprintf(mark_buf, PATH_MAX, "Tree Leaf (%d) %s/stat", i, (opt_mknod ? "mknod" : "mkdir")); ltrace_mark(3, mark_buf); } if (opt_mknod) do_mknod(pathname); else do_mkdir(pathname); /* Now stat it */ do_stat(pathname); } else { /* Not Leaf */ if (opt_trace) { snprintf(mark_buf, sizeof(mark_buf), "Tree Level (%d) mkdir/stat/chdir", i); ltrace_mark(3, mark_buf); } do_mkdir(pathname); do_stat(pathname); do_chdir(pathname); } } /* Stat through directory tree with fullpaths */ if (opt_trace) { snprintf(mark_buf, PATH_MAX, "Walk Directory Tree"); ltrace_mark(2, mark_buf); } do_chdir(base_pathname); strncpy(pathname, base_pathname, sizeof(pathname)); c = strlen(base_pathname); for (i = 0; i < opt_depth; i++) { c += snprintf(pathname + c, sizeof(pathname) - c, "/%d", i+1); if (opt_trace) { snprintf(mark_buf, PATH_MAX, "stat %s", pathname); ltrace_mark(2, mark_buf); } do_stat(pathname); } if (opt_trace && outputfilename) { ltrace_write_file(outputfilename); ltrace_add_processnames(outputfilename); ltrace_stop(); } do_chdir(base_pathname); printf("%s (pid=%d) done.\n", pname, mypid); return 0; }
/* * Trigger the debugger. */ void mainbus_debugger(void) { ltrace_stop(0); }
void panic(const char *fmt, ...) { va_list ap; /* * When we reach panic, the system is usually fairly screwed up. * It's not entirely uncommon for anything else we try to do * here to trigger more panics. * * This variable makes sure that if we try to do something here, * and it causes another panic, *that* panic doesn't try again; * trying again almost inevitably causes infinite recursion. * * This is not excessively paranoid - these things DO happen! */ static volatile int evil; if (evil == 0) { evil = 1; /* * Not only do we not want to be interrupted while * panicking, but we also want the console to be * printing in polling mode so as not to do context * switches. So turn interrupts off on this CPU. */ splhigh(); } if (evil == 1) { evil = 2; /* Kill off other threads and halt other CPUs. */ thread_panic(); } if (evil == 2) { evil = 3; /* Print the message. */ kprintf("panic: "); va_start(ap, fmt); __vprintf(console_send, NULL, fmt, ap); va_end(ap); } if (evil == 3) { evil = 4; /* Drop to the debugger. */ ltrace_stop(0); } if (evil == 4) { evil = 5; /* Try to sync the disks. */ vfs_sync(); } if (evil == 5) { evil = 6; /* Shut down or reboot the system. */ mainbus_panic(); } /* * Last resort, just in case. */ for (;;); }