📄 forking.c
字号:
case -1: break ; case DONE:#ifdef DEBUG printf( "'DONE' has been received, waiting on the child process to terminate.\n" ) ;#endif /* * Remember, we are waiting on our child!! In turn, our child is waiting * on it's children. So, once our child is done, all of the grandchildren are done. * In either case, we will not be hanging waiting for them to finish. We might need * to rethink this in the future, but for now, it seems a-okay! */ if((acct)&&(acct -> pid != -1 )) {#ifdef DEBUG printf( "Waiting on child process %d in DONE section on account #%d.\n", acct -> pid, acct -> id ) ;#endif waitpid( acct -> pid, &forkStat, 0 ) ;#ifdef DEBUG printf( "Waiting on child process %d in DONE has finished account #%d.\n", acct -> pid, acct -> id ) ;#endif /* Now, start timed background fetches again! *///TREY tm_globs -> getMsgTimeout = gtk_timeout_add( 950, (GtkFunction)message_event_loop, NULL ) ; /* * Since we are setup for deleting, we need to reset our values * after the transfer is completed. */ if( tm_globs -> curaccount -> flags & DELETEFROMSERVER ) { tm_globs -> curaccount -> popcmsg = 0 ; tm_globs -> curaccount -> poptmsg = 0 ;#if DEBUG > 4 printf( "Message counters have been reset because we are in delete mode for this account.\n" ) ;#endif } /* Okay, reset the pid values */ acct -> pid = -1 ; } /* No matter what, we need to see if the monitor process has finished on this DONE too. */ if( tm_globs -> pid != -1 ) { forkStat = 0 ; #ifdef DEBUG printf( "Waiting on child monitor process %d in DONE section.\n", tm_globs -> pid ) ;#endif if( tm_globs -> pid == waitpid( tm_globs -> pid, &forkStat, WNOHANG ) ) {#ifdef DEBUG printf( "Waiting on child monitor process %d in DONE section has completed.\n", tm_globs -> pid ) ;#endif//TREY tm_globs -> getMsgTimeout = gtk_timeout_add( 950, (GtkFunction)message_event_loop, NULL ) ; /* Now, start timed background fetches again! */ tm_globs -> pid = -1 ; } } /* Re-enable the GUI */#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif //TREYgtk_timeout_remove (tm_globs->getMsgTimeout); gtk_widget_set_sensitive (lookup_widget (tm_globs->main_window, "get_message"), TRUE); gtk_widget_set_sensitive (lookup_widget (tm_globs->status, "stopthat"), FALSE); gtk_widget_set_sensitive (lookup_widget (tm_globs->status, "skip"), FALSE); set_progress (1, 1); set_receiving (0, 0); folders_write_index (); set_account_name (_("Done")); insert_message (_("Finished.\n"));#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif if ((tm_globs->flags & HIDE_STATUS_WHEN_DONE)) { destroy_status (tm_globs->status, NULL); } if (stat) free (stat); return FALSE; break; case CURACCOUNT: tmpl=assemble_long (stat); acct=tm_globs->curaccount=seek_popaccount ((int)tmpl); set_account_name (acct->name); insert_message (_("Logging onto account %s.\n"), acct->name); set_receiving (0, 0); set_progress (0, 0); break; case CURPID: tmpl=assemble_long( stat ) ; tm_globs -> curaccount -> pid = tmpl ;#ifdef DEBUG printf( "Cur piD = %ld on account #%d.\n", tmpl, tm_globs -> curaccount -> id ) ;#endif break ; case TOTALMESSAGES: tmpl = assemble_long( stat ) ; tm_globs -> curaccount -> poptmsg = tmpl ; if( (tm_globs -> curaccount -> flags & FORCE_FETCH) || ((tm_globs -> curaccount -> popcmsg) > tmpl) ) { if( acct -> flags & FORCE_FETCH ) tm_globs -> curaccount -> flags ^= FORCE_FETCH ; tm_globs -> curaccount -> popcmsg = 0 ; } /* Reset the force bit if it's set */ if( tm_globs -> curaccount -> flags & FORCE_FETCH ) tm_globs -> curaccount -> flags ^= FORCE_FETCH ;#ifdef DEBUG printf( "Got a 'TOTALMESSAGES' message with %ld total messages.\n", tmpl ) ;#endif break ; case NEWMESSAGES: tmpl=assemble_long (stat); tm_globs->msg_count=1; tm_globs->msg_total=tmpl; set_receiving (tm_globs->msg_count, tm_globs->msg_total); insert_message (_("Connected, %ld new messages.\n"), tmpl);#ifdef DEBUG printf( "Got a 'NEWMESSAGES' message with %ld new messages.\n", tmpl ) ;#endif break; case MSGSIZE: tmpl=assemble_long (stat);#ifdef DEBUG printf ("Receiving message of size '%d'\n", (int)tmpl);#endif tm_globs->msgtotal=tmpl; tm_globs->msgblocks=0; set_progress (tm_globs->msg_count, tm_globs->msg_total); break; case PIPEERROR: tmpl = assemble_long( stat ) ; switch (tmpl) { case 0: break ; case NDEFACCOUNT: insert_error (_("Bug encountered. Tried to access undefined account\n")); break; case NDEFHOST: insert_error (_("Undefined host on account %s\n"), acct->name); break; case UNKNOWNHOST: insert_error (_("Unknown Host on account %s\n"), acct->name); pipe_child_stat_put (SKIP, "", 0); break; case NDEFUSER: insert_error (_("Undefined user on account %s\n"), acct->name); break; case NDEFPASSWORD: insert_error (_("Password Needed\n")); pwd_diag=create_enter_password (tm_globs->curaccount); gtk_widget_show (pwd_diag); break; case UNKNOWNUSER: insert_error (_("Server says: Unknown user '%s' on account %s\n"), acct->puser, acct->name); break; case INCORRECTPW: insert_error (_("Server said: Incorrect password\n")); pwd_diag=create_enter_password (tm_globs->curaccount); gtk_widget_show (pwd_diag); break; case PARENTSTOP: insert_warning (_("Stopping transaction\n")); insert_warning (_("Received %d messages successfully.\n"),tm_globs->msg_count-1); break; case PARENTSKIP: insert_warning (_("Skipping Account\n")); insert_warning (_("Received %d messages successfully.\n"),tm_globs->msg_count-1); break; default: insert_error (_("Unknown error type %d received\n"),tmpi); } break; case NEWPASSWORD:#if DEBUG > 4 printf( "New password message has been received and password is being set w/length = %ld...\n", size ) ;#endif if( acct -> ppasswd ) free( acct -> ppasswd ) ; acct -> ppasswd = malloc( size*sizeof(char)+2 ) ; strncpy( acct -> ppasswd, stat, size ) ; acct -> ppasswd[size] = 0x00 ; break ; }if (stat) free (stat);#ifdef DMALLOCdmalloc_verify( 0 ) ;#endifreturn TRUE;}int send_message_timeout (StupidFunc *func) { unsigned long type=0, size=0; int error=0; char *stat; unsigned long tmpl; int tmpi=0; PopAccount *pop ;#if DEBUG > 3 printf( "---*******=======>>>>>>>>send_message_timeout has been hit\n" ) ;#endif#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif pop = tm_globs -> curaccount ; if( !pop ) {#ifdef DEBUG printf( "There isn't a pop account assigned, so this isn't going to work...exit FALSE!!!\n" ) ;#endif return FALSE ; } stat=pipe_parent_stat_get (&type, &size, &error); if (error!=0) { switch (error) { case NODATA: break; case BADDATA:#ifdef DEBUG printf ("Something really messed up stat\n");#endif break; case READERR:#ifdef DEBUG printf ("For some reason, the actual file descriptor is messed up and won't let me read stat\n");#endif break; case PACKETERR:#ifdef DEBUG printf ("Packet error is when uh, the different parts don't come in, in the right order stato\n");#endif break; } } else { switch (type) { case -1: break; case DONE:#ifdef DEBUG printf( "Waiting for child to finish in 'DONE' logic...\n" ) ;#endif if( pop -> spid != -1 ) { if( waitpid( pop -> spid, NULL, WNOHANG ) ) { pop -> spid = -1 ; }#ifdef DEBUG printf( "Child is done, resetting GUI...\n" ) ;#endif gtk_timeout_remove( tm_globs -> send_timeout ) ; gtk_widget_set_sensitive (lookup_widget (tm_globs->main_window, "get_message"), TRUE); gtk_widget_set_sensitive (lookup_widget (tm_globs->status, "stopthat"), FALSE); gtk_widget_set_sensitive (lookup_widget (tm_globs->status, "skip"), FALSE); set_progress (1, 1); set_receiving (0, 0); folders_write_index (); set_account_name (_("Done")); insert_message (_("Finished.\n")); if ((tm_globs->flags & HIDE_STATUS_WHEN_DONE)) { destroy_status (tm_globs->status, NULL); } #ifdef DEBUG printf( "Doing status window junk...\n" ) ;#endif if (stat) free (stat); if (func) { if (func->func) func->func (func->messagebody, func->widget); } } return FALSE; break; case EMESSAGE:#ifdef DEBUG printf( "'EMESSAGE' error message is being processed.\n" ) ;#endif insert_message( _("The SMTP server reported:\n") ) ; insert_warning( "%s\n", stat ) ; if( pop -> spid != -1 ) { if( waitpid( pop -> spid, NULL, 0 ) ) { pop -> spid = -1 ; } }#ifdef DEBUG printf( "Child is done on error, resetting GUI...\n" ) ;#endif gtk_timeout_remove( tm_globs -> send_timeout ) ; gtk_widget_set_sensitive (lookup_widget (tm_globs->main_window, "get_message"), TRUE); gtk_widget_set_sensitive (lookup_widget (tm_globs->status, "stopthat"), FALSE); gtk_widget_set_sensitive (lookup_widget (tm_globs->status, "skip"), FALSE); set_progress (1, 1); set_receiving (0, 0); folders_write_index (); set_account_name (_("Done")); insert_message (_("Error reported.\n")); /* So we can properly report an error. */ if (func) {#ifdef DEBUG printf( "Firing failure function\n" ) ;#endif func->failure( func->widget ) ; } if ((tm_globs->flags & HIDE_STATUS_WHEN_DONE)) { destroy_status (tm_globs->status, NULL); } if (stat) free (stat); return FALSE ; break ; case PIPEERROR: tmpl=assemble_long (stat); tmpi=-(tmpl); switch (tmpi) { case NDEFACCOUNT: insert_error (_("Bug encountered. Tried to access undefined account\n")); break; case NDEFHOST: insert_error (_("Bug encountered. Undefined host on account %s\n"), pop->name); break; case UNKNOWNHOST: insert_error (_("Unknown Host on account %s\n"), pop->name); break; case CONNREF: insert_warning (_("Connection to the server was refused. Please contact your system's administrator\n")); break; case UNKNOWNERR: insert_warning (_("An unknown error occurred while connecting to the server\n")); break; case NORELAY: insert_error (_("Server says that it's not not configured for relaying. Use a different host.\n") ) ; break; default: insert_error (_("Unknown error type %d received\n"),tmpi); break; } if (func) {#ifdef DEBUG printf( "Firing failure function\n" ) ;#endif func->failure (func->widget); } if( pop -> spid != -1 ) {#ifdef DEBUG printf( "Waiting for child that reported 'DONE' to finished...\n" ) ;#endif if( waitpid( pop -> spid, NULL, WNOHANG ) ) { pop -> spid = -1 ;#ifdef DEBUG printf( "Child has finished.\n" ) ;#endif } }#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif return FALSE; } }#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif return TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -