void main(void) { mq_t *mq; int r; int source, m_type, timerand, fd; u32_t tasknr; struct fssignon device; u8_t randbits[32]; struct timeval tv; #if DEBUG printk("Starting inet...\n"); printk("%s\n", version); #endif #if HZ_DYNAMIC system_hz = sys_hz(); #endif /* Read configuration. */ nw_conf(); /* Get a random number */ timerand= 1; fd= open(RANDOM_DEV_NAME, O_RDONLY | O_NONBLOCK); if (fd != -1) { r= read(fd, randbits, sizeof(randbits)); if (r == sizeof(randbits)) timerand= 0; else { printk("inet: unable to read random data from %s: %s\n", RANDOM_DEV_NAME, r == -1 ? strerror(errno) : r == 0 ? "EOF" : "not enough data"); } close(fd); } else { printk("inet: unable to open random device %s: %s\n", RANDOM_DEV_NAME, strerror(errno)); } if (timerand) { printk("inet: using current time for random-number seed\n"); r= gettimeofday(&tv, NULL); if (r == -1) { printk("sysutime failed: %s\n", strerror(errno)); exit(1); } memcpy(randbits, &tv, sizeof(tv)); } init_rand256(randbits); /* Our new identity as a server. */ r= ds_retrieve_u32("inet", &tasknr); if (r != 0) ip_panic(("inet: ds_retrieve_u32 failed for 'inet': %d", r)); this_proc= tasknr; /* Register the device group. */ device.dev= ip_dev; device.style= STYLE_CLONE; if (svrctl(FSSIGNON, (void *) &device) == -1) { printk("inet: error %d on registering ethernet devices\n", errno); pause(); } #ifdef BUF_CONSISTENCY_CHECK inet_buf_debug= (getenv("inetbufdebug") && (strcmp(getenv("inetbufdebug"), "on") == 0)); inet_buf_debug= 100; if (inet_buf_debug) { ip_warning(( "buffer consistency check enabled" )); } #endif if (getenv("killerinet")) { ip_warning(( "killer inet active" )); killer_inet= 1; } nw_init(); while (TRUE) { #ifdef BUF_CONSISTENCY_CHECK if (inet_buf_debug) { static int buf_debug_count= 0; if (++buf_debug_count >= inet_buf_debug) { buf_debug_count= 0; if (!bf_consistency_check()) break; } } #endif if (ev_head) { ev_process(); continue; } if (clck_call_expire) { clck_expire_timers(); continue; } mq= mq_get(); if (!mq) ip_panic(("out of messages")); r = kipc_module_call(KIPC_RECEIVE, 0, ENDPT_ANY, &mq->mq_mess); if (r<0) { ip_panic(("unable to receive: %d", r)); } reset_time(); source= mq->mq_mess.m_source; m_type= mq->mq_mess.m_type; if (source == VFS_PROC_NR) { sr_rec(mq); } else if (is_notify(m_type)) { if (_ENDPOINT_P(source) == CLOCK) { clck_tick(&mq->mq_mess); mq_free(mq); } else if (_ENDPOINT_P(source) == PM_PROC_NR) { /* signaled */ /* probably SIGTERM */ mq_free(mq); } else { /* A driver is (re)started. */ eth_check_drivers(&mq->mq_mess); mq_free(mq); } } else if (m_type == DL_CONF_REPLY || m_type == DL_TASK_REPLY || m_type == DL_NAME_REPLY || m_type == DL_STAT_REPLY) { eth_rec(&mq->mq_mess); mq_free(mq); } else { printk("inet: got bad message type 0x%x from %d\n", mq->mq_mess.m_type, mq->mq_mess.m_source); mq_free(mq); } } ip_panic(("task is not allowed to terminate")); }
PUBLIC void main() { mq_t *mq; int r; int source, timerand, fd; struct fssignon device; #ifdef __minix_vmd struct systaskinfo info; #endif u8_t randbits[32]; struct timeval tv; #if DEBUG printf("Starting inet...\n"); printf("%s\n", version); #endif /* Read configuration. */ nw_conf(); /* Get a random number */ timerand= 1; fd= open(RANDOM_DEV_NAME, O_RDONLY | O_NONBLOCK); if (fd != -1) { r= read(fd, randbits, sizeof(randbits)); if (r == sizeof(randbits)) timerand= 0; else { printf("unable to read random data from %s: %s\n", RANDOM_DEV_NAME, r == -1 ? strerror(errno) : r == 0 ? "EOF" : "not enough data"); } close(fd); } else { printf("unable to open random device %s: %s\n", RANDOM_DEV_NAME, strerror(errno)); } if (timerand) { printf("using current time for random-number seed\n"); #ifdef __minix_vmd r= sysutime(UTIME_TIMEOFDAY, &tv); #else /* Minix 3 */ r= gettimeofday(&tv, NULL); #endif if (r == -1) { printf("sysutime failed: %s\n", strerror(errno)); exit(1); } memcpy(randbits, &tv, sizeof(tv)); } init_rand256(randbits); #ifdef __minix_vmd if (svrctl(SYSSIGNON, (void *) &info) == -1) pause(); /* Our new identity as a server. */ this_proc = info.proc_nr; #else /* Minix 3 */ /* Our new identity as a server. */ if ((this_proc = getprocnr()) < 0) ip_panic(( "unable to get own process nr\n")); #endif /* Register the device group. */ device.dev= ip_dev; device.style= STYLE_CLONE; if (svrctl(FSSIGNON, (void *) &device) == -1) { printf("inet: error %d on registering ethernet devices\n", errno); pause(); } #ifdef BUF_CONSISTENCY_CHECK inet_buf_debug= (getenv("inetbufdebug") && (strcmp(getenv("inetbufdebug"), "on") == 0)); inet_buf_debug= 100; if (inet_buf_debug) { ip_warning(( "buffer consistency check enabled" )); } #endif if (getenv("killerinet")) { ip_warning(( "killer inet active" )); killer_inet= 1; } #ifdef __minix_vmd r= sys_findproc(SYN_AL_NAME, &synal_tasknr, 0); if (r != OK) ip_panic(( "unable to find synchronous alarm task: %d\n", r )); #endif nw_init(); while (TRUE) { #ifdef BUF_CONSISTENCY_CHECK if (inet_buf_debug) { static int buf_debug_count= 0; if (++buf_debug_count >= inet_buf_debug) { buf_debug_count= 0; if (!bf_consistency_check()) break; } } #endif if (ev_head) { ev_process(); continue; } if (clck_call_expire) { clck_expire_timers(); continue; } mq= mq_get(); if (!mq) ip_panic(("out of messages")); r= receive (ANY, &mq->mq_mess); if (r<0) { ip_panic(("unable to receive: %d", r)); } reset_time(); source= mq->mq_mess.m_source; if (source == FS_PROC_NR) { sr_rec(mq); } #ifdef __minix_vmd else if (source == synal_tasknr) { clck_tick (&mq->mq_mess); mq_free(mq); } #else /* Minix 3 */ else if (mq->mq_mess.m_type == SYN_ALARM) { clck_tick(&mq->mq_mess); mq_free(mq); } else if (mq->mq_mess.m_type == SYS_SIG) { /* signaled */ /* probably SIGTERM */ mq_free(mq); } else if (mq->mq_mess.m_type & NOTIFY_MESSAGE) { /* A driver is (re)started. */ eth_check_drivers(&mq->mq_mess); mq_free(mq); } #endif else { compare(mq->mq_mess.m_type, ==, DL_TASK_REPLY); eth_rec(&mq->mq_mess); mq_free(mq); } } ip_panic(("task is not allowed to terminate")); }
PUBLIC int main(int argc, char *argv[]) { mq_t *mq; int ipc_status; int r; endpoint_t source; int m_type; /* SEF local startup. */ sef_local_startup(); while (TRUE) { #ifdef BUF_CONSISTENCY_CHECK if (inet_buf_debug) { static int buf_debug_count= 0; if (++buf_debug_count >= inet_buf_debug) { buf_debug_count= 0; if (!bf_consistency_check()) break; } } #endif if (ev_head) { ev_process(); continue; } if (clck_call_expire) { clck_expire_timers(); continue; } mq= mq_get(); if (!mq) ip_panic(("out of messages")); r= sef_receive_status(ANY, &mq->mq_mess, &ipc_status); if (r<0) { ip_panic(("unable to receive: %d", r)); } reset_time(); source= mq->mq_mess.m_source; m_type= mq->mq_mess.m_type; if (source == VFS_PROC_NR) { sr_rec(mq); } else if (is_ipc_notify(ipc_status)) { if (source == CLOCK) { clck_tick(&mq->mq_mess); mq_free(mq); } else if (source == PM_PROC_NR) { /* signaled */ /* probably SIGTERM */ mq_free(mq); } else if (source == DS_PROC_NR) { /* DS notifies us of an event. */ ds_event(); mq_free(mq); } else { printf("inet: got unexpected notify from %d\n", mq->mq_mess.m_source); mq_free(mq); } } else if (m_type == DL_CONF_REPLY || m_type == DL_TASK_REPLY || m_type == DL_STAT_REPLY) { eth_rec(&mq->mq_mess); mq_free(mq); } else { printf("inet: got bad message type 0x%x from %d\n", mq->mq_mess.m_type, mq->mq_mess.m_source); mq_free(mq); } } ip_panic(("task is not allowed to terminate")); return 1; }