int getIPv6Addr(char *intf, char *ipv6addr) { L3Addr_t ips[10] = {0}; int cnt = 0; int i = 0; char buf[100] = {0}; kinfo("Enter"); if(!safe_strcmp(intf, "br0")) cnt = getL3LocalList(ips, 10, NULL); kinfo("ipaddr (totally %d)", cnt); for(i = 0; i < cnt; i++) { kinfo("%s, type(%d)", ips[i].ipAddrStr, ips[i].type); changeString(ips[i].ipAddrStr); sprintf(buf, "%d|%s||", ips[i].type, ips[i].ipAddrStr); strcat(ipv6addr, buf); } return 0; }
//void __test_assert(char *expr, char *file, int line, const char *func) //{ // kinfo("Test '%s' failed: file %s,", expr, file); // kinfo(" line %d, function '%s'\n", line, func); // while (1); //} // int __test_assert_eq_int(int actual, int expected, const char *file, int line, const char *func) { kinfo("Expected %d actual %d: file %s,", expected, actual, file); kinfo(" line %d, function '%s'\n", line, func); return 0; //while (1); }
int __test_assert_eq_ptr(void *actual, void *expected, const char *file, int line, const char *func) { kinfo("Expected %p actual %p: file %s,", expected, actual, file); kinfo(" line %d, function '%s'\n", line, func); return 0; //while (1); }
int Syscall::kcall_threadinfo(CoreData& core_data, Thread *currt) { /* * Get info on a thread * * KPARM1 : pid * KPARM2 : tid * KPARM3 : &thread_info * * KRETVAL : 0 or -ERRNO */ Thread *thread; struct thread_info thread_info; pid_t pid; int id_found; kinfo("kcall_threadinfo %d %d\n", KPARM1, KPARM2); if (KPARM1 == 0) { pid = currt->get_pid(); } else { pid = KPARM1; } Process *proc; if ((proc = proctable.getref(pid, true)) == NULL) { kinfo("kcall_threadinfo ret %d\n", -ESRCH); return -ESRCH; } if ((thread = proc->thread_getref_iter(KPARM2, id_found)) == NULL) { kinfo("kcall_threadinfo ret %d\n", -ESRCH); proc->unref(); return -ESRCH; } kinfo("kcall_threadinfo found %d\n", thread->get_id()); thread_info.pid = pid; thread_info.tid = thread->get_id(); thread_info.state = thread->get_state(); /* Subtract one because we hold a lock ;) */ thread_info.refs = thread->get_refcnt() - 1; currt->kcopy_touser((void *)KPARM3, (const char *)&thread_info, sizeof(thread_info)); proc->unref(); thread->unref(); kinfo("kcall_threadinfo found %d %d\n", pid, id_found); return id_found; }
void getStatusValue(char *type, char *retvalue) { if (!safe_strcmp(type, "ethmac")) { getMacByIntf("eth0", retvalue); } else if (!safe_strcmp(type, "wlan0")) { getMacByIntf("wlan0-va0", retvalue); } else if (!safe_strcmp(type, "wlan1")) { getMacByIntf("wlan1-va0", retvalue); } else if (!safe_strcmp(type, "mocamac")) { getMacByIntf("eth0", retvalue); } else if (!safe_strcmp(type, "version")) { strcpy(retvalue, "10.1.1"); } else if (!safe_strcmp(type, "ipv6addr")) { getIPv6Addr("br0", retvalue); } kinfo("%s -> %s", type, retvalue); }
int getMacByIntf(char *intf, char *macaddr) { int fd; struct ifreq ifr; kinfo("Enter, intf: %s", intf); fd = socket(AF_INET, SOCK_DGRAM, 0); ifr.ifr_addr.sa_family = AF_INET; strncpy(ifr.ifr_name, intf, IFNAMSIZ - 1); if(ioctl(fd, SIOCGIFHWADDR, &ifr)) { kerror("iotcl SIOCGIFHWADDR Error"); return 1; } if(fd) close(fd); if(ifr.ifr_hwaddr.sa_data != NULL) { /* display result */ sprintf(macaddr,"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", (unsigned char)ifr.ifr_hwaddr.sa_data[0], (unsigned char)ifr.ifr_hwaddr.sa_data[1], (unsigned char)ifr.ifr_hwaddr.sa_data[2], (unsigned char)ifr.ifr_hwaddr.sa_data[3], (unsigned char)ifr.ifr_hwaddr.sa_data[4], (unsigned char)ifr.ifr_hwaddr.sa_data[5]); } return 0; }
int Thread::asynch_handler() { if (asynch & THREAD_ASYNCH_CLEANING) { //kinfo("Cleaning process %d, %d\n", get_pid(), get_id()); if (get_proc()->complete_exit() == true) { // We are done sys.m_sched.block(THR_ST_ZOMBIE); die(); } else { // We will reschedule ourselves to finish later sys.m_sched.block(THR_ST_STOPPED); sys.m_sched.add(this, 0); } return 0; } /* The running thread must end */ else if (get_proc()->m_state == PROC_ST_EXITING) { //kinfo("Destroy process %d, %d\n", get_pid(), get_id()); sys.m_sched.block(THR_ST_ZOMBIE); die(); return 0; } else if (get_proc()->m_state == PROC_ST_STOPPED) { kinfo("Stop process %d, %d\n", get_pid(), get_id()); sys.m_sched.block(THR_ST_STOPPED); return 0; } if (asynch & THREAD_ASYNCH_DESTROY) { kinfo("Destroy thread %d, %d\n", get_pid(), get_id()); sys.m_sched.block(THR_ST_ZOMBIE); die(); return 0; } else if (asynch & THREAD_ASYNCH_SIGNAL) { handle_signal(); } return 0; }
static void * _pipeline_stage_tail(void *arg) { pipeline_t *pl = (pipeline_t *) arg; pipeline_stage_t *stage = pl->tail; if (pthread_mutex_lock(&stage->mutex) != 0) kerror("state_tail lock error"); while (KTRUE) { while (stage->data_ready == 0) { if (pthread_cond_wait(&stage->avail, &stage->mutex)) { pthread_mutex_unlock(&stage->mutex); kerror("stage_tail cond wait error"); } } if (stage->msg.exit == 1) { pthread_mutex_unlock(&stage->mutex); break; } if (stage->proc(stage->index, &stage->msg.data) != KSUCCESS) kinfo("stage proc error"); pthread_mutex_unlock(&stage->mutex); pthread_mutex_lock(&pl->mutex); if ((--pl->active) == 0) { pthread_cond_signal(&pl->finished); } pthread_mutex_unlock(&pl->mutex); pthread_mutex_lock(&stage->mutex); stage->data_ready = 0; pthread_cond_signal(&stage->ready); } pthread_mutex_lock(&pl->mutex); kinfo("the stage[thread-%d] exit", stage->index); --pl->active; pthread_cond_signal(&pl->finished); pthread_mutex_unlock(&pl->mutex); return (void *) KSUCCESS; }
void ktest() { karray_test1(); karray_test2(); karray_test3(); karray_test4(); kinfo("Test complete\n"); while (1); }
void kernel_init(struct multiboot *mboot_ptr) { //Reprogram PICs cli(); init_pics(0x20, 0x28); sti(); //Initialize Terminal terminal_initialize(); kinfo("Enable A20 Gate (if not already done)\n"); //Enable A20 Gate if it is not already enabled. if (checkA20() = 0) enableA20(); //Check if A20 is REALLY enabled if (checkA20() = 0) panic("Enabling A20 Gate"); //Enable the timer and setting it to 50hz kinfo("Enable Timer (50hz)"); init_timer(50); //Initiate the descriptor tables (gdt and idt) init_descriptor_tables(); //Enter the protected mode kinfo("Enter protected mode"); enterProtected(); //Spawning the init process with argument *mboot_ptr kinfo("Spawning Init process..."); init(*mboot_ptr); //The init process should NEVER die. //If it dies kerror("Init Process terminated... make a kernel panic..."); panic("Unendable Process ended."); }
int Syscall::kcall_threaddestroy(CoreData& core_data, Thread *currt) { /* * Destroy a thread * * KPARM1 : pid * KPARM2 : tid * * KRETVAL : 0 or -ERRNO */ Thread *thread; int id_found; int pid; kinfo("kcall_threaddestroy %d %d\n", KPARM1, KPARM2); if (KPARM1 == 0) { pid = currt->get_pid(); } else { pid = KPARM1; } if ((thread = get_thread_ref(pid, KPARM2)) == NULL) { kinfo("kcall_threaddestroy ret %d\n", -ESRCH); return -ESRCH; } thread->asynch |= THREAD_ASYNCH_DESTROY; thread->abort(); thread->unref(); return 0; }
static void * _pipeline_stage(void *arg) { pipeline_stage_t *stage = (pipeline_stage_t *) arg; kerrno_t ret = KSUCCESS; if (pthread_mutex_lock(&stage->mutex)) { kinfo("pipeline stage lock mutex error"); return (void *) KERROR; } while (KTRUE) { while (stage->data_ready == 0) { if (pthread_cond_wait(&stage->avail, &stage->mutex)) { kinfo("pipeline stage wait avail cond error"); ret = KERROR; goto DONE; } } /* force invoking the next stage */ if (stage->msg.exit == 1) { pthread_mutex_unlock(&stage->mutex); kinfo("stage[thread-%d] exited", stage->index); _pipeline_send(stage->next, NULL, 1); break; } if (stage->proc(stage->index, &stage->msg.data) != KSUCCESS) kinfo("stage proc error"); pthread_mutex_unlock(&stage->mutex); _pipeline_send(stage->next, stage->msg.data, 0); pthread_mutex_lock(&stage->mutex); stage->data_ready = 0; if (pthread_cond_signal(&stage->ready)) { kinfo("pipeline stage signal ready error"); ret = KERROR; break; } } DONE: if (pthread_mutex_unlock(&stage->mutex)) kinfo("pipeline stage unlock mutex error"); return (void *) (long) ret; }
int getStatusList(request *wp, char *status_type) { char buf[256] = {0}; char full_name[256] = {0}; int host_entries = 0; int i = 0; int nBytesSent = 0; char ip_address[20] = {0}; char mac_address[20] = {0}; char interface_type[20] = {0}; int active = 0; kinfo("status_type: %s", status_type); if(tr69GetUnfreshLeafData(buf, "Device.Hosts", "HostNumberOfEntries")) { strcpy(error_buf, "Get Device.Hosts.HostNumberOfEntries error"); return 0; } host_entries = atoi(buf); kinfo("host_entries: %d", host_entries); for(i = 1; i <= host_entries; i++) { sprintf(full_name, "Device.Hosts.Host.%d", i); if(tr69GetUnfreshLeafData(ip_address, full_name, "IPAddress")) { sprintf(error_buf, "Get %s.IPAddress error", full_name); break; } if(tr69GetUnfreshLeafData(mac_address, full_name, "PhysAddress")) { sprintf(error_buf, "Get %s.PhysAddress error", full_name); break; } if(tr69GetUnfreshLeafData(interface_type, full_name, "X_ACTIONTEC_COM_InterfaceType")) { sprintf(error_buf, "Get %s.X_ACTIONTEC_COM_InterfaceType error", full_name); break; } if(tr69GetUnfreshLeafData(buf, full_name, "Active")) { sprintf(error_buf, "Get %s.Active error", full_name); break; } active = atoi(buf); if(active) { nBytesSent += req_format_write(wp, "%s", "<table id=\"tbl_clients\" width=\"90%%%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"status_style\" style=\"margin:0px auto 0 auto;\">\n<tr>\n"); if(!safe_strcmp(interface_type, "Wireless")) nBytesSent += req_format_write(wp, "%s", "<td class=\"left_cell\" id=\"wrls_on\"></td>\n"); else nBytesSent += req_format_write(wp, "%s", "<td class=\"left_cell\" id=\"eth_on\"></td>\n"); nBytesSent += req_format_write(wp, "<td class=\"mid_cell\" id=\"client_name_on\">%s</td>\n", mac_address); nBytesSent += req_format_write(wp, "%s", "<td class=\"right_cell\" id=\"client_connected\">\n"); nBytesSent += req_format_write(wp, "%s", "<p class=\"client_ip\">Connected</p>\n"); nBytesSent += req_format_write(wp, "<p class=\"client_ip\">%s</p>\n", ip_address); nBytesSent += req_format_write(wp, "<p class=\"client_data\">Via %s</p>\n", interface_type); nBytesSent += req_format_write(wp, "%s", "</td>\n</tr>\n</table>\n"); } } if(nBytesSent==0) { req_format_write(wp, "%s", "NULL"); } return nBytesSent; }
int Thread::abort() { /* * This function can get a thread from anywhere in the system, rip it * out from its current state and runs it. The idea is that the thread * knows what to do when it wakes up. */ int unblocked = 0; //kinfo("Unblocking thread %d %d st=%d\n", get_pid(), get_id(), state); while (!unblocked) { switch (m_state) { case THR_ST_READY: case THR_ST_RUNNING: unblocked = 1; break; case THR_ST_SENDING: case THR_ST_RECEIVING: kinfo("Queued on %p\n", proc_queue); // if (proc_queue) // { // rwlock_wrlock(&proc_queue->msg_queue_lock); // if (state == THR_ST_SENDING) // { // proc_queue->smsg_queue.rem_item(this); // } // else if (state == THR_ST_RECEIVING) // { // proc_queue->rmsg_queue.rem_item(this); // } // proc_queue = NULL; // unref(); // rwlock_unlock(&proc_queue->msg_queue_lock); // } sys.m_sched.add(this, 1); break; case THR_ST_NANOSLEEP: if (timerqueue_remove(thread_timer)) { sys.m_sched.add(this, 1); } break; case THR_ST_STOPPED: sys.m_sched.add(this, 1); break; case THR_ST_WAITING: get_proc()->wait_list.rem_item(this); break; case THR_ST_ZOMBIE: //die(); unblocked = 1; break; case THR_ST_DEAD: case THR_ST_FUTEX: case THR_ST_JOINING: default: kinfo("UNHANDLED STATE %d\n", m_state); break; } } return 0; }
void method_delete(struct kreq *r) { struct state *st = r->arg; int rc; const char *digest; int64_t tag; char *ep; if (NULL == st->cfg) { kerrx("%s: DELETE from non-calendar " "collection", st->prncpl->name); http_error(r, KHTTP_403); return; } digest = NULL; if (NULL != r->reqmap[KREQU_IF_MATCH]) { digest = r->reqmap[KREQU_IF_MATCH]->val; tag = strtoll(digest, &ep, 10); if (digest == ep || '\0' != *ep) digest = NULL; else if (tag == LLONG_MIN && errno == ERANGE) digest = NULL; else if (tag == LLONG_MAX && errno == ERANGE) digest = NULL; if (NULL == digest) kerrx("%s: bad numeric digest", st->prncpl->name); } if (NULL != digest && '\0' != st->resource[0]) { rc = db_resource_delete (st->resource, tag, st->cfg->id); if (0 == rc) { kerrx("%s: cannot deleted: %s", st->prncpl->name, r->fullpath); http_error(r, KHTTP_403); } else { kinfo("%s: resource deleted: %s", st->prncpl->name, r->fullpath); http_error(r, KHTTP_204); } return; } else if (NULL == digest && '\0' != st->resource[0]) { rc = db_resource_remove (st->resource, st->cfg->id); if (0 == rc) { kerrx("%s: cannot deleted: %s", st->prncpl->name, r->fullpath); http_error(r, KHTTP_403); } else { kinfo("%s: resource (unsafe) deleted: %s", st->prncpl->name, r->fullpath); http_error(r, KHTTP_204); } return; } if (0 == db_collection_remove(st->cfg->id, st->prncpl)) { kinfo("%s: cannot delete: %s", st->prncpl->name, r->fullpath); http_error(r, KHTTP_505); } else { kinfo("%s: collection unlinked: %s", st->prncpl->name, r->fullpath); http_error(r, KHTTP_204); } }