/* ******************************************************************************* * Copyright (c) 1996 Martin Poole * ******************************************************************************* ** ** WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! ** ** Any changes to be made to this file should first be checked with ** mplib1 source control for library integrity. ** ** mplib1 source control can be reached at mplib1@quatermass.co.uk ** * * System : * Subsystem : * Module : * $Source: /home/cvs/cvsroot/onelan/onelan/src/mplib1/libsrc/bpo_proc_cln.c,v $ * $Author: mpoole $ * $Date: 2002/10/07 09:37:37 $ * $Revision: 1.2 $ * ******************************************************************************* * * Change History * * $Log: bpo_proc_cln.c,v $ * Revision 1.2 2002/10/07 09:37:37 mpoole * Initial checkin of mplib1-3.1.0 * * Revision 1.1 2002/10/07 09:36:54 mpoole * Initial checkin of mplib1-3.1.0 * * ******************************************************************************* */ #ident "$Header: /home/cvs/cvsroot/onelan/onelan/src/mplib1/libsrc/bpo_proc_cln.c,v 1.2 2002/10/07 09:37:37 mpoole Exp $" /* ------------------------------------------------------------------ Include files ------------------------------------------------------------------ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* ------------------------------------------------------------------ defines ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Code starts here ------------------------------------------------------------------ */ static int check_pipe( char *name ) { /* Is this one a pipe, and is there a pid on the end, and is it alive */ char *cp; int rv = 0; struct stat tstat; pid_t pid; /* is it a pipe ? */ if ( stat(name, &tstat)==0 && S_ISFIFO(tstat.st_mode) ) { cp = name + Sstrlen(name) - 1; if (isdigit(*cp)) { /* looks like a pid, so scan backwards to beginning */ while (isdigit(*(cp-1))) cp--; pid = atoi(cp); if (pid && is_pid_dead(pid)!=0) { /* it is a pid and the pid is not there */ unlink( name ); rv = 1; } } } return(rv); } int scan_dead_pipes( const char *dir_name ) { DIR *dirp; struct dirent *direntp; char *olddir; int rv = 0; olddir = getcwd( NULL, 200 ); if (chdir(dir_name)==0) { dirp = opendir( dir_name ); while ((direntp=readdir(dirp))!=NULL) { check_pipe( direntp->d_name ); }; closedir(dirp); chdir(olddir); } free(olddir); return(rv); } /* -- End of File -- */