int kexit(long exit_code) { struct process *init = find_init(); struct process *curr = NULL; int i = 0; if(!init) { printk("kexit:: warning could not find init task\n"); return 0; } for(i = 0; i < Nr_PRIORITY; ++i) { curr = process_tab[i]; do { if(curr) { if(curr->p_parent == current_process->p_pid) { curr->p_parent = 1; if(curr->p_state == P_ZOMBIE) { dispatch_signal(SIGCHLD, init, curr); } } curr = curr->p_next; } else { break; } } while(curr != process_tab[i]); } // TODO:= Sessions are not currently implemented. if(current_process->p_leader) { terminate_session(); } current_process->p_exit_code = exit_code; signal_parent(current_process->p_parent); schedule(); return -1; }// kexit
/** Similar to `read_from()`, but in case of socket error, `terminate_session()` is called using `BAD_READ_QUIT_MSG` as a quit message. @param client The client to read from. @param buf Buffer to store the message read. @param len Maximum length of the message. This is usually bounded by the size of `buf`. This parameter avoids buffer overflow. @return A positive integer denoting the number of characters read. */ inline ssize_t read_from_noerr(struct irc_client *client, char *buf, size_t len) { ssize_t msg_size; if ((msg_size = read_from(client, buf, len)) <= 0) { terminate_session(client, BAD_READ_QUIT_MSG); } return msg_size; }
/** Similar to `write_to()`, but in case of socket error, `terminate_session()` is called using `BAD_WRITE_QUIT_MSG` as a quit message. @param client The client to read from. @param buf Buffer to store the message read. @param len Maximum length of the message. This is usually bounded by the size of `buf`. This parameter avoids buffer overflow. */ inline void write_to_noerr(struct irc_client *client, char *buf, size_t len) { if (write_to(client, buf, len) == -1) { terminate_session(client, BAD_WRITE_QUIT_MSG); } }