/* * 返回父目录 */ void excute_return_parent_directory(){ if(strcmp(currentDisk,"home")==0) { } else if(strcmp(currentDirectory,"unknown")==0) { memset(currentDisk, 0, sizeof(char)*MAX_BUF_SIZE); memcpy(currentDisk, "home",sizeof(char)*4); } else { currentDirId = get_parent_id(currentDirId); if(strcmp(currentDirId,"0")==0) { memset(currentDirectory, 0, sizeof(char)*MAX_BUF_SIZE); memcpy(currentDirectory, "unknown", sizeof(char)*7); //当前ID? } else { currentDirectory = get_directory_name(currentDirId); } } }
void realloc(const Functor &new_ptr) { if (get_parent()) { set_parentid(new_ptr(get_parent()), get_parent_id()); set_xlinktag(0, new_ptr(get_xlink(0)), get_xtag(0)); set_xlinktag(1, new_ptr(get_xlink(1)), get_xtag(1)); } else // if root set_xlinktag(0, new_ptr(get_xlink(0)), get_xtag(0)); }
void do_stuff(msg *received_message){ if(received_message->msg_type==1){ //Broadcast message. if(check_history(received_message->message_id)) return; insert_into_history_table(received_message->message_id); int *neighbours=get_neighbours(ROUTER_ID); int size=neighbours[0]; int i; printf("received by router id:%d from %d.\nSending to others.\n", ROUTER_ID,received_message->coming_from); received_message->coming_from=ROUTER_BASE_PORT+ROUTER_ID; for(i=1;i<=size;i++){ write_to_socket(ROUTER_BASE_PORT+neighbours[i],code_message(received_message)); } } //unicast message else if(received_message->msg_type==2) if(received_message->receiver_id!=check_node_list(ROUTER_ID,received_message->receiver_id)) { int *path=find_shorest_path_between_routers(ROUTER_ID,get_parent_id(received_message->receiver_id)); int next_node_to_send_to=path[1]; if(next_node_to_send_to==-1){ printf("Next node not found.Exiting...\n"); exit(0); } received_message->coming_from=ROUTER_BASE_PORT+ROUTER_ID; printf("Passing from router %d to router %d\n",ROUTER_ID,next_node_to_send_to); write_to_socket(ROUTER_BASE_PORT+next_node_to_send_to,code_message(received_message)); } else{ received_message->coming_from=ROUTER_BASE_PORT+ROUTER_ID; printf("Passing from router %d to end node %d\n",ROUTER_ID,received_message->receiver_id ); write_to_socket(NODE_BASE_PORT+received_message->receiver_id,code_message(received_message)); } //Control message else if(received_message->msg_type==3){ //operations supported==> print the count of the messages received and forwarded on each link. if(check_history(received_message->message_id)) //node is already visited. return; insert_into_history_table(received_message->message_id); int *neighbours=get_neighbours(ROUTER_ID); int size=neighbours[0]; int i; // printf("received by router id:%d.\nSending to others.\n", ROUTER_ID); received_message->coming_from=ROUTER_BASE_PORT+ROUTER_ID; printf("Message received by Router # %d are %llu (including the current one!)\n",ROUTER_ID,message_count+1 ); for(i=1;i<=size;i++){ write_to_socket(ROUTER_BASE_PORT+neighbours[i],code_message(received_message)); } } message_count++; }
/// for debug only const char *visualize(const node_type *id0) const { static char buf[256]; sprintf(buf, "%d skip: %d pt: %d ptId: %d lnk0: %d tag0: %d lnk1: %d tag1: %d\n", this - id0, get_skip(), get_parent() - id0, get_parent_id(), get_xlink(0) - id0, get_xtag(0), get_xlink(1) - id0, get_xtag(1)); return buf; }
/// for debug only bool integrity() const { const word_t skip = get_skip(), tag0 = get_xtag(0), tag1 = get_xtag(1); const node_type *p0 = get_xlink(0), *p1 = get_xlink(1); return skip == ~word_t(0) && p1 == 0 && get_parent() == 0 && get_parent_id() == 0 || !tag0 && p0->get_parent() == this && !p0->get_parent_id() && skip < p0->get_skip() || !tag1 && p1->get_parent() == this && p1->get_parent_id() && skip < p1->get_skip() || tag0 && tag1; }
/* * ui_handle_keycode - handle ui keycode * @key : key except to be HANG, BACK, 1~6 * @return : status */ int ui_handle_keycode(int key) { int cur_id, item_num; int next_id, parent_id; ACTION handler; cur_id = get_cur_frame_id(); if (key == BACK) { parent_id = get_parent_id(cur_id); if (cur_id == parent_id) return SUCCESS; pop_ui_statck(); set_cur_frame_id(parent_id); show_current_ui(parent_id); return SUCCESS; } if (key == HANG) { cmd_resume_transact(); set_cur_frame_id(cur_id); show_current_ui(cur_id); return SUCCESS; } item_num = get_item_num(cur_id); if (key > (item_num - 1)) return FAIL; next_id = get_next_id(cur_id, key); handler = get_next_action(cur_id, key); if (handler == NULL) { push_ui_statck(cur_id); set_cur_frame_id(next_id); show_current_ui(next_id); return SUCCESS; } else { handler(); push_ui_statck(cur_id); if (next_id == CLEAN_UI) { /* * just for log out and shutdown */ clear_screen(); } else { set_cur_frame_id(next_id); show_current_ui(next_id); } return SUCCESS; } }
void stackdump(void) { int pid, core_pid; /* get name now -- will be same for children */ char *exec_name = get_application_name(); char core_name[128]; char tmp_name[128]; snprintf(tmp_name, 128, "%s.%d", TEMPORARY_FILENAME, get_process_id()); #ifdef VMX86_SERVER if (os_in_vmkernel_userworld()) { return; /* no local gdb, no multithreaded fork */ } #endif #if VERBOSE SYSLOG_INTERNAL_ERROR("about to fork parent %d to dump core", get_process_id()); #endif /* Fork a child to dump core */ pid = fork_syscall(); if (pid == 0) { /* child */ #if VERBOSE SYSLOG_INTERNAL_ERROR("about to dump core in process %d parent %d thread " TIDFMT "", get_process_id(), get_parent_id(), get_thread_id()); #endif /* We used to use abort here, but that had lots of complications with * pthreads and libc, so now we just dereference NULL. */ if (!set_default_signal_action(SIGSEGV)) { SYSLOG_INTERNAL_ERROR("ERROR in setting handler"); exit_process_syscall(1); } *(volatile int *)NULL = 0; #if VERBOSE SYSLOG_INTERNAL_ERROR("about to exit process %d", get_process_id()); #endif exit_process_syscall(0); } else if (pid == -1) { SYSLOG_INTERNAL_ERROR("ERROR: could not fork to dump core"); exit_process_syscall(1); } #if VERBOSE SYSLOG_INTERNAL_ERROR("parent %d %d waiting for child %d", get_process_id(), get_thread_id(), pid); #endif /* Parent continues */ core_pid = pid; while (wait_syscall(NULL) != pid) { /* wait for core to be dumped */ } #if VERBOSE SYSLOG_INTERNAL_ERROR("about to fork 2nd child to run gdb"); #endif /* Fork a 2nd child to run gdb */ pid = fork_syscall(); if (pid == 0) { /* child */ file_t fp; int fd; const char *argv[16]; int i; int execve_errno; /* Open a temporary file for the input: the "where" command */ fp = os_open(tmp_name, OS_OPEN_REQUIRE_NEW | OS_OPEN_WRITE); os_write(fp, DEBUGGER_COMMAND, strlen(DEBUGGER_COMMAND)); os_close(fp); fd = open_syscall(tmp_name, O_RDONLY, 0); if (fd < 0) { SYSLOG_INTERNAL_ERROR("ERROR: open failed on temporary file"); exit_process_syscall(1); } #if !BATCH_MODE /* Redirect stdin from the temporary file */ close_syscall(0); /* close stdin */ dup_syscall(fd); /* replace file descriptor 0 with reference to temp file */ #endif close_syscall(fd); /* close the other reference to temporary file */ /* Find the core file */ strncpy(core_name, CORE_NAME, 127); core_name[127] = '\0'; /* if max no null */ fd = open_syscall(core_name, O_RDONLY, 0); if (fd < 0) { snprintf(core_name, 128, "%s.%d", CORE_NAME, core_pid); SYSLOG_INTERNAL_ERROR("core not found, trying %s", core_name); fd = open_syscall(core_name, O_RDONLY, 0); if (fd < 0) { SYSLOG_INTERNAL_ERROR("ERROR: no core file found!"); exit_process_syscall(1); } } close_syscall(fd); /* avoid running the debugger under us! * FIXME: just remove our libraries, instead of entire env var? */ unsetenv("LD_PRELOAD"); SYSLOG_INTERNAL_ERROR("-------------------------------------------"); SYSLOG_INTERNAL_ERROR("stackdump: --- now running the debugger ---"); SYSLOG_INTERNAL_ERROR("%s %s %s %s", DEBUGGER, QUIET_MODE, exec_name, core_name); SYSLOG_INTERNAL_ERROR("-------------------------------------------"); i = 0; /* We rely on /usr/bin/env to do the PATH search for gdb on our behalf. */ argv[i++] = "/usr/bin/env"; argv[i++] = DEBUGGER; argv[i++] = QUIET_MODE; #if BATCH_MODE argv[i++] = "-x"; argv[i++] = tmp_name; argv[i++] = "-batch"; #endif argv[i++] = exec_name; argv[i++] = core_name; argv[i++] = NULL; execve_errno = execve_syscall("/usr/bin/env", argv, our_environ); SYSLOG_INTERNAL_ERROR("ERROR: execve failed for debugger: %d", -execve_errno); exit_process_syscall(1); } else if (pid == -1) { SYSLOG_INTERNAL_ERROR("ERROR: could not fork to run debugger"); exit_process_syscall(1); } /* Parent continues */ /* while(wait(NULL)>0) waits for all children, and could hang, so: */ while (wait_syscall(NULL) != pid) { /* empty loop */ } /* Wait for these children to complete before returning */ while (wait_syscall(NULL) > 0) { /* empty loop */ } os_delete_file(tmp_name); /* clean up the temporary file */ SYSLOG_INTERNAL_ERROR("-------------------------------------------"); }