diff -ruN vpopmail-5.4.18-factory/vpopmail.c vpopmail-5.4.18-updated/vpopmail.c --- vpopmail-5.4.18-factory/vpopmail.c 2006-12-30 04:46:13.000000000 -0500 +++ vpopmail-5.4.18-updated/vpopmail.c 2007-01-09 02:49:43.000000000 -0500 @@ -3884,6 +3884,9 @@ * John Simpson 2005-01-22 * * 2006-03-30 jms1 - added command line parameters for external program + * + * 2007-07-09 jms1 - cleanup, now returns onchange script exit code, + * error messages are now accurate. */ char onchange_buf[MAX_BUFF]; int allow_onchange=1; @@ -3891,40 +3894,42 @@ { char path[MAX_BUFF]; int pid; + int rv; - if( !allow_onchange ) { - return(0); - } + if( !allow_onchange ) return(0); /* build the name */ snprintf ( path, sizeof(path), "%s/etc/onchange", VPOPMAILDIR ); /* if it doesn't exist, we're done */ - if( access(path,F_OK) ) { - fprintf(stderr, "ONCHANGE script %s not found.\n", path); - return(0); - } + if( access(path,F_OK) ) + { + fprintf(stderr, "ONCHANGE script %s not found.\n", path); + return(ENOENT); + } /* it does exist, make sure we're allowed to run it */ - if( access(path,X_OK) ) { - fprintf(stderr, "ONCHANGE script %s not executable.\n", path); - return(EACCES); - } + if( access(path,X_OK) ) + { + fprintf(stderr, "ONCHANGE script %s not executable.\n", path); + return(EACCES); + } /* okay, let's do it */ pid = vfork(); if ( 0 == pid ) { execl ( path, "onchange", cmd, onchange_buf, NULL ); - fprintf(stderr, "ONCHANGE script %s unable to fork.\n", path); - return(0); + fprintf(stderr, "ONCHANGE script %s unable to exec.\n", path); + _exit(1); } else if ( pid > 0 ) - wait ( &pid ); - else - fprintf(stderr, "ONCHANGE script %s failed.\n", path); - return(0); + { + wait(&rv); + return(rv); + } - return(0); + fprintf(stderr, "ONCHANGE script %s unable to fork.\n", path); + return(-1); } #endif