📄 forking.c
字号:
}#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif /* Now, regardless of either method we did to fetch messages, check for errors */ if( error ) {#ifdef DEBUG printf( "new_pop3_get_message has returned an error of %d.\n", error ) ;#endif switch( error ) { case PARENTSKIP: if( msg ) free( msg ) ; snum = disassemble_long( (unsigned long)abs(PARENTSKIP) ) ; printf( "Got PARENTSKIP error back.\n" ) ; break ; case PARENTSTOP: if( msg ) free( msg ) ; snum = disassemble_long( (unsigned long)abs(PARENTSTOP) ) ; printf( "Got PARENTSTOP error back.\n" ) ; break ; default:#ifdef DEBUG printf( "default error hit in fork_receive_message1().\n" ) ;#endif break ; } /* Now, report the error to the parent. */ pipe_parent_stat_put( PIPEERROR, snum, 4 ) ; free( snum ) ; } else { /* We didn't have any errors, so process the message */ if( msg ) {#if DEBUG > 5 printf( "Posting a 'PMESSAGE' message.\n" ) ;#endif pipe_data_put( PMESSAGE, msg, strlen(msg) ) ;#if DEBUG > 5 printf( "Posted a 'PMESSAGE' message.\n" ) ;#endif#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif } } } /* * That is, we've looped through all of the messages, so I * think this means that were are no more messages */#if DEBUG > 4 printf( "no more messages on account %d, logging off account %d on pid %d\n", curpop -> id, popid, getpid() ) ;#endif } /* Now, log out!!! */#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif if( loggedIn ) { new_pop3_logout( curpop -> id, stream ) ; loggedIn = 0 ; } /* We'll use this to reset the curpid value since the parent is waiting on us. */#ifdef DEBUG printf( "****>ANNOUNCING CURPID %d from account #%d because we are done with it.\n", -1, curpop -> id ) ;#endif snum = disassemble_long( (unsigned long)curpop -> pid ) ; pipe_parent_stat_put( CURPID, snum, 4 ) ; free( snum ) ; /* Tell everyone that we're done */ if( announce ) {#if DEBUG > 5 printf( "ANNOUNCING 'DONE' on account #%d.\n", curpop -> id ) ;#endif pipe_parent_stat_put( DONE, "", 0 ) ; }#if DEBUG > 4 printf( "*************************Exiting...\n" ) ; printf( "Exiting pid fork_message1 %d.\n", getpid() ) ; if( !announce ) printf( "Expect to see another account follow...\n" ) ; printf( "*************************Exiting...\n" ) ;#endif#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif _exit( 0 ) ; } /* End of message processing */ } else { /* * He hit here because we are the parent process, noticed * that we said the pid of this child process so the the * parent can make sure he doesn't have any mutant zombie * kids running around. Must eat brains.....duooh! */#ifdef DEBUG printf( "****>Assigned account PID and returning control to monitor process on %d\n", pid ) ;#endif }return pid ;}#ifdef DEBUG#undef DEBUGFORK#define DEBUGFORK 0#endifvoid new_fork_send_message (PopAccount *pop, MailMessage *mmessage, char *recipline) { int pid, serror, i; char *snum; int recip_count=count_delimiters (recipline, ',')+1; char *recip[recip_count]; char *smtpsender, *domain, *tmp, *tmp2;#if DEBUGFORK > 0 int debugger ;#endif if (recip_count>1) { recip[0]=cut_string (recipline, ',', 1, 1); for (i=1;i<recip_count;i++) { tmp=cut_string (recipline, ',', 2, i); strip_lead_spaces( tmp ) ; if (i<(recip_count-1)) { tmp2=cut_string (tmp, ',', 1, 1); recip[i]=rm_crlf (tmp2); free (tmp2); } else { recip[i]=rm_crlf (tmp); } if (recip[i][0]==' ') recip[i]++;// bad bad, we cant free that byte now free (tmp); } } else recip[0]=rm_crlf (recipline);#ifdef DEBUG printf( "Forking send for background operation for %s\n", pop->emailaddr ) ;#endif tm_globs -> curaccount = pop ; if( ( pid = fork() ) == 0 ) {#if DEBUGFORK > 0 /* Here for debugging only - this requires the debugger to change the value!!!! */ debugger = 1 ; while( debugger ) { printf( "Waiting on the debugger to save me on pid #%d in new_fork_send_message().\n", getpid() ) ; sleep( 1 ) ; }#endif smtpsender=strdup(pop->emailaddr); serror=0; if (serror<0) {#ifdef DEBUG printf ("Child puts PIPEERROR\n");#endif snum=disassemble_long (abs(serror)); pipe_parent_stat_put (PIPEERROR, snum, 4); free (snum); goto sdone1; }#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif domain=cut_string (pop->emailaddr, '@', 2, 1);#ifdef DEBUG printf(" trying to send msg\n");#endif serror = new_sendmessage( mmessage ) ;#ifdef DEBUG printf(" sendmsg DONE\n");#endif for (i=0; i<recip_count; i++) { free (recip[i]); } if (serror<0) {#ifdef DEBUG printf ("Child puts PIPEERROR\n");#endif snum=disassemble_long (abs(serror)); pipe_parent_stat_put (PIPEERROR, snum, 4); free (snum); } sdone1: free (smtpsender);#ifdef DEBUG printf("Child is 'DONE'\n");#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif#endif pipe_parent_stat_put( DONE, "", 0 ) ;#ifdef DEBUG printf( "Child process %d is dying.\n", getpid() ) ;#endif /* * Here, we exit the child process in our own process (the child), so that * we can gracefully die. If we exit() as we should, GTK freaks out! */ _exit( 0 ) ; } else { pop -> spid = pid ; }#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif return ;}int get_message_timeout (gpointer data) { int type=0, error=0, hsize; unsigned long size; Message *msg=NULL; char *message; Folder *fl=NULL; Header_Info *hinfo; FilterAction *fact; int serror; unsigned long stype, ssize; char *stats = NULL ; Attachment *att; char *msgbody;#if DEBUG > 4 printf ("---> get_message_timeout() has been called! <---\n");#endif /* * See if the child process has finished. If so, it means all of the grand * kids have finished playing. At any rate, we need to check from time to * time to make sure they've done their thing. Notice that we're not waiting * around because we have better things to do. If it's done, we reset the * value of the global pid. */ message=pipe_data_get (&type, &size, &error);#if DEBUG > 6 printf( "pipe_data_get() has returned with type = %d, size = %d and error = %d.\n", type, size, error ) ;#endif switch (error) { case READERR:#ifdef DEBUG printf ("For some reason, the actual file descriptor is messed up and won't let me read\n");#endif break; case PACKETERR:#ifdef DEBUG printf ("Packet error is when uh, the different parts don't come in, in the right order\n");#endif break; default: switch( type ) { case OOOREAD:#if DEBUG > 4 printf( "'OOOREAD' message is being processed.\n" ) ;#endif status_pipe_timeout( NULL ) ; break ; case QUEUED: case PMESSAGE:#if DEBUG > 5 printf( "'QUEUED' or 'PMESSAGE' message is being processed.\n" ) ;#endif#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif hsize = message_hsize( message ) ;#if DEBUG > 7 printf( "got hsize.\n" ) ;#endif#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif hinfo = parse_header( message ) ; att=(Attachment *)calloc (1, sizeof (Attachment)); att->mtype=strdup ("dummyatt"); msgbody = mime_process( message, att, 0 ); free(att->mtype); free(att);#if DEBUG > 7 printf( "got hinfo.\n" ) ;#endif#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif stats = pipe_child_stat_get( &stype, &ssize, &serror ) ;#if DEBUG > 7 printf( "got child stat.\n" ) ;#endif#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif /* This way, we only increment the msg count that we have submitted on our queue!!! */ tm_globs -> msg_count++ ; if (tm_globs->curaccount) tm_globs -> curaccount -> popcmsg++ ; /* Now, process the message filters */ if (tm_globs->msg_count>tm_globs->msg_total) tm_globs->msg_count=tm_globs->msg_total; set_receiving (tm_globs->msg_count, tm_globs->msg_total); if ((hinfo->uidl)&&(index_find_uidl (hinfo->uidl, NULL))) {#if DEBUG > 4 printf("FOUND DUPLICATE UIDL (%s)\n",hinfo->uidl);#endif msg = NULL; fl = NULL; } else {/* XXX: trey: add message-id checking */ #if DEBUG > 6 printf( "applying filters to message...\n" ) ;#endif fact = filter_message( hinfo -> subject, hinfo -> from, hinfo -> to, hinfo->cc, hinfo->bcc, msgbody, hinfo->keywords, hinfo->replyto) ; if( fact ) { switch( fact -> action ) { case F_ACTION_DELETE: /* The filter says we are to delete it */#if DEBUG > 6 printf( "deleting message from: '%s' subject: '%s'\n", hinfo->from, hinfo->subject ) ;#endif msg = NULL ; fl = NULL ; break ; case F_ACTION_MOVE: /* The filter says we are to move it */#if DEBUG > 6 printf( "Moving message from: '%s' subject: '%s'\n", hinfo->from, hinfo->subject ) ;#endif fl = folder_seek( folder_seek_by_name( fact->folder ) ) ; msg = message_seek( fl, message_save( fl->name, message ) ) ; break ; default: /* The filter didn't say what to do with it, so file it! */ if( tm_globs -> curaccount != NULL ) { fl = folder_seek( folder_seek_by_name( ( (PopAccount *)tm_globs -> curaccount ) -> folder ) ) ; msg = message_seek( fl, message_save( ( (PopAccount *)tm_globs -> curaccount ) -> folder, message ) ) ; } else { fl = folder_first(); msg = message_seek( fl, message_save( fl->name, message ) ) ; } break ; } } /* Be sure to free the memory used on the message filter, if any! */ if( fact ) filter_action_destroy( fact ) ; } destroy_hinfo( hinfo ) ; free (message); if(msgbody) free (msgbody); if( msg ) { msg -> flags |= MESSAGE_UNREAD ; msg -> rfolder = strdup( fl -> name ) ; } if( fl ) fl -> unread++ ; if( fl && msg ) create_new_message( fl, msg ) ; break ; } } /* * Now, check the status of everything that's going on. * This was previously on it's own timer, but it doesn't really make sense to do * that since, to some extent they really need to be serialized. */ return status_pipe_timeout( NULL ) ;}int status_pipe_timeout(gpointer data) { unsigned long type=0, size=0; int forkStat ; int error=0; char *stat; unsigned long tmpl; int tmpi=0; GtkWidget *pwd_diag; PopAccount *acct=tm_globs->curaccount;#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif stat=pipe_parent_stat_get (&type, &size, &error);#if DEBUG > 6 if( stat ) printf( "pipe_parent_stat_get returned with %s and type = %ld, size=%ld, error=%d,\n", stat, type, size, error ) ; else printf( "stat = NULL, type = %ld, size=%ld, error=%d,\n", type, size, error ) ;#endif switch( type ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -