int main(int argc, char *argv[]) { if (argc < 3) { sys_info("too few parameter, please input net-system-pid"); return -1; } net_system_pid = atoi(argv[1]); if (net_system_pid <= 0) { sys_info("invalid parameter, exit"); return -1; } SRC_ADDR = atoi(argv[2]); if (SRC_ADDR<=0 | SRC_ADDR>MAX_NODES) { sys_info("invalid parameter, exit"); return -1; } if (route_init() < 0) { sys_info("route_init failed, exit"); return -1; } switch(rt_cache->rp) { case FHR: fhr_main(); break; /* case DSR: dsr_main(); break; case PDQR: pdqr_main();*/ } route_exit(); }
int uname(struct utsname *uts) { struct kerninfo info; sys_info(INFO_KERNEL, &info); memcpy(uts, &info, sizeof(*uts)); return 0; }
int main(int argc, char *argv[]) { struct timerinfo info; task_t task; char stack[16]; u_long start, end; int i, pri, error; printf("Benchmark to create/terminate %d threads\n", NR_THREADS); sys_info(INFO_TIMER, &info); if (info.hz == 0) panic("can not get timer tick rate"); thread_getpri(thread_self(), &pri); thread_setpri(thread_self(), pri - 1); task = task_self(); error = vm_allocate(task, (void **)&thread, sizeof(thread_t) * NR_THREADS, 1); if (error) panic("vm_allocate is failed"); sys_time(&start); /* * Create threads */ for (i = 0; i < NR_THREADS; i++) { if (thread_create(task, &thread[i]) != 0) panic("thread_create is failed"); if (thread_load(thread[i], null_thread, &stack) != 0) panic("thread_load is failed"); if (thread_resume(thread[i]) != 0) panic("thread_resume is failed"); } /* * Teminate threads */ for (i = 0; i < NR_THREADS; i++) thread_terminate(thread[i]); sys_time(&end); vm_free(task, thread); printf("Complete. The score is %d msec (%d ticks).\n", (int)((end - start) * 1000 / info.hz), (int)(end - start)); return 0; }
static int cmd_mem(int argc, char *argv[]) { struct meminfo info; sys_info(INFO_MEMORY, &info); /* UNIX v7 style... */ printf("mem = %d\n", (u_int)info.total); return 0; }
static void cmd_ver(int argc, char **argv) { struct kerninfo info; sys_info(INFO_KERNEL, &info); printf("Kernel version:\n"); printf("%s version %s for %s\n", info.sysname, info.version, info.machine); }
/******open route-msg-q, route-table share-memory, init rt_cache and open net-system api*****/ static int route_init(void) { key_t msg_key, shm_key; void *shmaddr; msg_key = ftok(KEY_RT_PATH, 1); shm_key = ftok(KEY_RT_PATH, 2); if (msg_key<0 || shm_key<0) { sys_err("failed route ftok:"); return -1; } route_msgid = msgget(msg_key, SVMSG_MODE | IPC_CREAT); route_view_msgid = msgget(RT_VIEW_KEY, SVMSG_MODE | IPC_CREAT); route_shmid = shmget(shm_key, sizeof(route_table_cache)+1,SVMSG_MODE | IPC_CREAT); if (route_msgid<0 || route_shmid<0 || route_view_msgid<0) { sys_err("failed msgget or shmget:"); return -1; } shmaddr = shmat(route_shmid, NULL, 0); if (shmaddr == NULL) { sys_err("failed shmat:"); return -1; } rt_cache = (route_table_cache*)shmaddr; memset(rt_cache, 0, sizeof(rt_cache)); rt_cache->rp = FHR; rt_cache->src_addr = SRC_ADDR; if (fhr_init() < 0) { sys_info("fhr init failed"); return -1; } handle = ap_socket(RT_PORT); if (handle < 0) { sys_info("ap_socket failed"); return -1; } return 0; }
int uname(struct utsname *uts) { struct info_kernel info; sys_info(INFO_KERNEL, &info); strcpy(uts->sysname, info.sysname); strcpy(uts->release, info.version); strcpy(uts->version, info.blddate); strcpy(uts->machine, info.machine); strcpy(uts->nodename, info.hostname); return 0; }
static void cmd_mem(int argc, char **argv) { struct meminfo info; sys_info(INFO_MEMORY, &info); printf("Memory usage:\n"); printf(" Used : %8d KB\n", (u_int)((info.total - info.free) / 1024)); printf(" Free : %8d KB\n", (u_int)(info.free / 1024)); printf(" Total : %8d KB\n", (u_int)(info.total / 1024)); printf(" Bootdisk : %8d KB\n", (u_int)(info.bootdisk / 1024)); }
int bootxxx(void *readsector, void *disklabel, osdsc_t *od) { int fd; char *errmsg; extern char end[], edata[]; memset(edata, 0, end - edata); /* XXX: Limit should be 16MB */ setheap(end, (void*)0x1000000); printf("\033v\nNetBSD/Atari tertiary bootloader " "($Revision: 1.8 $)\n\n"); if (init_dskio(readsector, disklabel, od->rootfs)) return -1; sys_info(od); if (!(od->cputype & ATARI_ANYCPU)) { printf("Unknown CPU-type.\n"); return -2; } if ((fd = open(od->osname, 0)) < 0) { printf("Cannot open kernel '%s'\n", od->osname); return -3; } #ifndef __ELF__ /* a.out */ if (aout_load(fd, od, &errmsg, 1) != 0) #else if (elf_load(fd, od, &errmsg, 1) != 0) #endif return -4; boot_BSD(&od->kp); return -5; /* NOTREACHED */ }
int main(int argc, char *argv[]) { static const char stat[][2] = { "R", "Z", "S" }; static const char pol[][5] = { "FIFO", "RR " }; static struct threadinfo ti; static struct procinfo pi; int ch, rc, ps_flag = 0; pid_t last_pid = -2; while ((ch = getopt(argc, argv, "lx")) != -1) switch(ch) { case 'x': ps_flag |= PSFX; break; case 'l': ps_flag |= PSFL; break; case '?': default: fprintf(stderr, "usage: ps [-lx]\n"); exit(1); } argc -= optind; argv += optind; if (object_lookup("!proc", &procobj)) exit(1); if (ps_flag & PSFL) printf(" PID PPID PRI STAT POL TIME WCHAN CMD\n"); else printf(" PID TIME CMD\n"); rc = 0; ti.cookie = 0; do { /* * Get thread info from kernel. */ rc = sys_info(INFO_THREAD, &ti); if (!rc) { /* * Get process info from server. */ if (pstat(ti.task, &pi) && !(ps_flag & PSFX)) continue; if (ps_flag & PSFL) { if (pi.pid == -1) printf(" - -"); /* kernel */ else printf("%5d %5d", pi.pid, pi.ppid); printf(" %3d %s %s %8d " "%-11s %-11s\n", ti.priority, stat[pi.stat-1], pol[ti.policy], ti.time, ti.slpevt, ti.taskname); } else { if (!(ps_flag & PSFX) && (pi.pid == last_pid)) continue; if (pi.pid == -1) printf(" -"); /* kernel */ else printf("%5d", pi.pid); printf(" %8d %-11s\n", ti.time, ti.taskname); last_pid = pi.pid; } } } while (rc == 0); exit(0); }
static void crash_handler(const char *logfile) { const char *sigdesc = ""; int i; if(fread(&crash_info, sizeof(crash_info), 1, stdin) != 1) { fprintf(stderr, "!!! Failed to retrieve info from crashed process\n"); exit(1); } /* Get the signal description */ for(i = 0;signals[i].name;++i) { if(signals[i].signum == crash_info.signum) { sigdesc = signals[i].name; break; } } if(crash_info.has_siginfo) { switch(crash_info.signum) { case SIGSEGV: for(i = 0;sigsegv_codes[i].name;++i) { if(sigsegv_codes[i].code == crash_info.siginfo.si_code) { sigdesc = sigsegv_codes[i].name; break; } } break; case SIGFPE: for(i = 0;sigfpe_codes[i].name;++i) { if(sigfpe_codes[i].code == crash_info.siginfo.si_code) { sigdesc = sigfpe_codes[i].name; break; } } break; case SIGILL: for(i = 0;sigill_codes[i].name;++i) { if(sigill_codes[i].code == crash_info.siginfo.si_code) { sigdesc = sigill_codes[i].name; break; } } break; case SIGBUS: for(i = 0;sigbus_codes[i].name;++i) { if(sigbus_codes[i].code == crash_info.siginfo.si_code) { sigdesc = sigbus_codes[i].name; break; } } break; } } fprintf(stderr, "%s (signal %i)\n", sigdesc, crash_info.signum); if(crash_info.has_siginfo) fprintf(stderr, "Address: %p\n", crash_info.siginfo.si_addr); fputc('\n', stderr); if(logfile) { /* Create crash log file and redirect shell output to it */ if(freopen(logfile, "wa", stdout) != stdout) { fprintf(stderr, "!!! Could not create %s following signal\n", logfile); exit(1); } fprintf(stderr, "Generating %s and killing process %d, please wait... ", logfile, crash_info.pid); printf("*** Fatal Error ***\n" "%s (signal %i)\n", sigdesc, crash_info.signum); if(crash_info.has_siginfo) printf("Address: %p\n", crash_info.siginfo.si_addr); fputc('\n', stdout); fflush(stdout); } sys_info(); crash_info.buf[sizeof(crash_info.buf)-1] = '\0'; printf("%s\n", crash_info.buf); fflush(stdout); if(crash_info.pid > 0) { gdb_info(crash_info.pid); kill(crash_info.pid, SIGKILL); } if(logfile) { const char *str; char buf[512]; if((str=getenv("KDE_FULL_SESSION")) && strcmp(str, "true") == 0) snprintf(buf, sizeof(buf), "kdialog --title \"Very Fatal Error\" --textbox \"%s\" 800 600", logfile); else if((str=getenv("GNOME_DESKTOP_SESSION_ID")) && str[0] != '\0') snprintf(buf, sizeof(buf), "gxmessage -buttons \"Okay:0\" -geometry 800x600 -title \"Very Fatal Error\" -center -file \"%s\"", logfile); else snprintf(buf, sizeof(buf), "xmessage -buttons \"Okay:0\" -center -file \"%s\"", logfile); system(buf); } exit(0); }
static void crash_handler(const char *logfile) { const char *sigdesc = "Unknown signal"; const char *codedesc = "unknown code"; int showlog = 0; int i; if(fread(&crash_info, sizeof(crash_info), 1, stdin) != 1) { fputs("!!! Failed to retrieve info from crashed process\n", stderr); exit(1); } if(crash_info.version != CRASH_INFO_VERSION) { fputs("!!! Incompatible crash_info structure (library mismatch)\n", stderr); exit(1); } /* Get the signal description */ for(i = 0;signals[i].name;++i) { if(signals[i].signum == crash_info.signum) { sigdesc = signals[i].name; break; } } if(crash_info.has_siginfo) { for(i = 0;generic_codes[i].name;++i) { if(generic_codes[i].code == crash_info.siginfo.si_code) { codedesc = generic_codes[i].name; break; } } if(!generic_codes[i].name) { switch(crash_info.signum) { case SIGSEGV: for(i = 0;sigsegv_codes[i].name;++i) { if(sigsegv_codes[i].code == crash_info.siginfo.si_code) { codedesc = sigsegv_codes[i].name; break; } } break; case SIGFPE: for(i = 0;sigfpe_codes[i].name;++i) { if(sigfpe_codes[i].code == crash_info.siginfo.si_code) { codedesc = sigfpe_codes[i].name; break; } } break; case SIGILL: for(i = 0;sigill_codes[i].name;++i) { if(sigill_codes[i].code == crash_info.siginfo.si_code) { codedesc = sigill_codes[i].name; break; } } break; case SIGBUS: for(i = 0;sigbus_codes[i].name;++i) { if(sigbus_codes[i].code == crash_info.siginfo.si_code) { codedesc = sigbus_codes[i].name; break; } } break; } } fprintf(stderr, "%s, %s (signal %i, code 0x%02x)\n", sigdesc, codedesc, crash_info.signum, crash_info.siginfo.si_code); if(crash_info.signum != SIGABRT) fprintf(stderr, "Address: %p\n", crash_info.siginfo.si_addr); fputc('\n', stderr); } else fprintf(stderr, "%s (signal %i)\n\n", sigdesc, crash_info.signum); if(logfile && *logfile) { /* Create crash log file and redirect shell output to it */ if(freopen(logfile, "wa", stdout) != stdout) fprintf(stderr, "!!! Could not create %s following signal\n", logfile); else { fprintf(stderr, "Generating %s and killing process %d, please wait...\n", logfile, crash_info.pid); puts("*** Fatal Error ***"); if(!crash_info.has_siginfo) printf("%s (signal %i)\n\n", sigdesc, crash_info.signum); else { printf("%s, %s (signal %i, code 0x%02x)\n", sigdesc, codedesc, crash_info.signum, crash_info.siginfo.si_code); if(crash_info.signum != SIGABRT) printf("Address: %p\n", crash_info.siginfo.si_addr); putchar('\n'); } fflush(stdout); showlog = 1; } } sys_info(); if(crash_info.buf[0] != '\0') { crash_info.buf[sizeof(crash_info.buf)-1] = '\0'; puts(crash_info.buf); fflush(stdout); } if(crash_info.pid > 0) { gdb_info(crash_info.pid); kill(crash_info.pid, SIGKILL); } if(showlog) { const char *str; int ret = 0; if((str=getenv("KDE_FULL_SESSION")) && strcmp(str, "true") == 0) ret = show_kde(&crash_info, sigdesc, logfile); if(!ret) { ret = show_gtk(&crash_info, sigdesc, logfile); if(!ret) ret = show_x11(&crash_info, sigdesc, logfile); } } }
static void crash_handler(const char *logfile) { const char *sigdesc = ""; int i; if(fread(&crash_info, sizeof(crash_info), 1, stdin) != 1) { fprintf(stderr, "!!! Failed to retrieve info from crashed process\n"); exit(1); } /* Get the signal description */ for(i = 0;signals[i].name;++i) { if(signals[i].signum == crash_info.signum) { sigdesc = signals[i].name; break; } } if(crash_info.has_siginfo) { switch(crash_info.signum) { case SIGSEGV: for(i = 0;sigsegv_codes[i].name;++i) { if(sigsegv_codes[i].code == crash_info.siginfo.si_code) { sigdesc = sigsegv_codes[i].name; break; } } break; case SIGFPE: for(i = 0;sigfpe_codes[i].name;++i) { if(sigfpe_codes[i].code == crash_info.siginfo.si_code) { sigdesc = sigfpe_codes[i].name; break; } } break; case SIGILL: for(i = 0;sigill_codes[i].name;++i) { if(sigill_codes[i].code == crash_info.siginfo.si_code) { sigdesc = sigill_codes[i].name; break; } } break; case SIGBUS: for(i = 0;sigbus_codes[i].name;++i) { if(sigbus_codes[i].code == crash_info.siginfo.si_code) { sigdesc = sigbus_codes[i].name; break; } } break; } } fprintf(stderr, "%s (signal %i)\n", sigdesc, crash_info.signum); if(crash_info.has_siginfo) fprintf(stderr, "Address: %p\n", crash_info.siginfo.si_addr); fputc('\n', stderr); if(logfile) { // [EP/TP] Needed for the timestamp appending to crash log filename. char newLogfile[64]; time_t timestamp; time( ×tamp ); char *bufferEnd = newLogfile + sizeof( newLogfile ); snprintf( newLogfile, sizeof( newLogfile ), "%s", logfile ); char *appendPoint = strchr( newLogfile, '.' ); if ( appendPoint == NULL ) appendPoint = newLogfile + strlen( newLogfile ); appendPoint += strftime( appendPoint, bufferEnd - appendPoint, "-%m_%d_%Y-%H_%M_%S", localtime( ×tamp ) ); snprintf( appendPoint, bufferEnd - appendPoint, ".%d.log", (int)crash_info.pid ); logfile = (const char *)newLogfile; /* Create crash log file and redirect shell output to it */ if(freopen(logfile, "wa", stdout) != stdout) { fprintf(stderr, "!!! Could not create %s following signal\n", logfile); exit(1); } fprintf(stderr, "Generating %s and killing process %d, please wait... ", logfile, crash_info.pid); printf("*** Fatal Error ***\n" "%s (signal %i)\n", sigdesc, crash_info.signum); if(crash_info.has_siginfo) printf("Address: %p\n", crash_info.siginfo.si_addr); fputc('\n', stdout); fflush(stdout); } sys_info(); crash_info.buf[sizeof(crash_info.buf)-1] = '\0'; printf("%s\n", crash_info.buf); fflush(stdout); if(crash_info.pid > 0) { gdb_info(crash_info.pid); kill(crash_info.pid, SIGKILL); } #ifndef SERVER_ONLY // [BB] The Linux server doesn't have a GUI, so don't bother it with a window. if(logfile) { const char *str; char buf[512]; if((str=getenv("KDE_FULL_SESSION")) && strcmp(str, "true") == 0) snprintf(buf, sizeof(buf), "kdialog --title \"Very Fatal Error\" --textbox \"%s\" 800 600", logfile); else if((str=getenv("GNOME_DESKTOP_SESSION_ID")) && str[0] != '\0') snprintf(buf, sizeof(buf), "gxmessage -buttons \"Okay:0\" -geometry 800x600 -title \"Very Fatal Error\" -center -file \"%s\"", logfile); else snprintf(buf, sizeof(buf), "xmessage -buttons \"Okay:0\" -center -file \"%s\"", logfile); system(buf); } #endif exit(0); }
static void crash_handler(const char *logfile) { const char *sigdesc = ""; int i; if(fread(&crash_info, sizeof(crash_info), 1, stdin) != 1) { fprintf(stderr, "!!! Failed to retrieve info from crashed process\n"); exit(1); } /* Get the signal description */ for(i = 0;signals[i].name;++i) { if(signals[i].signum == crash_info.signum) { sigdesc = signals[i].name; break; } } if(crash_info.has_siginfo) { switch(crash_info.signum) { case SIGSEGV: for(i = 0;sigsegv_codes[i].name;++i) { if(sigsegv_codes[i].code == crash_info.siginfo.si_code) { sigdesc = sigsegv_codes[i].name; break; } } break; case SIGFPE: for(i = 0;sigfpe_codes[i].name;++i) { if(sigfpe_codes[i].code == crash_info.siginfo.si_code) { sigdesc = sigfpe_codes[i].name; break; } } break; case SIGILL: for(i = 0;sigill_codes[i].name;++i) { if(sigill_codes[i].code == crash_info.siginfo.si_code) { sigdesc = sigill_codes[i].name; break; } } break; case SIGBUS: for(i = 0;sigbus_codes[i].name;++i) { if(sigbus_codes[i].code == crash_info.siginfo.si_code) { sigdesc = sigbus_codes[i].name; break; } } break; } } fprintf(stderr, "%s (signal %i)\n", sigdesc, crash_info.signum); if(crash_info.has_siginfo) fprintf(stderr, "Address: %p\n", crash_info.siginfo.si_addr); fputc('\n', stderr); if(logfile) { /* Create crash log file and redirect shell output to it */ if(freopen(logfile, "wa", stdout) != stdout) { fprintf(stderr, "!!! Could not create %s following signal\n", logfile); exit(1); } fprintf(stderr, "Generating %s and killing process %d, please wait... ", logfile, crash_info.pid); printf("*** Fatal Error ***\n" "%s (signal %i)\n", sigdesc, crash_info.signum); if(crash_info.has_siginfo) printf("Address: %p\n", crash_info.siginfo.si_addr); fputc('\n', stdout); fflush(stdout); } sys_info(); crash_info.buf[sizeof(crash_info.buf)-1] = '\0'; printf("%s\n", crash_info.buf); fflush(stdout); if(crash_info.pid > 0) { gdb_info(crash_info.pid); kill(crash_info.pid, SIGKILL); } if(logfile) { char cwd[MAXPATHLEN]; getcwd(cwd, MAXPATHLEN); std::string message = "OpenMW has encountered a fatal error.\nCrash log saved to '" + std::string(cwd) + "/" + std::string(logfile) + "'.\n Please report this to https://bugs.openmw.org !"; SDL_ShowSimpleMessageBox(0, "Fatal Error", message.c_str(), NULL); } exit(0); }