Doxygen Source Code Documentation
afni_logger.c File Reference
#include "mrilib.h"#include <sys/file.h>Go to the source code of this file.
Defines | |
| #define | LOCK_file(fp) flock(fileno(fp),LOCK_EX|LOCK_NB) |
| #define | UNLOCK_file(fp) flock(fileno(fp),LOCK_UN) |
| #define | LOGFILE ".afni.log" |
Functions | |
| void | AFNI_sleep (int msec) |
| int | AFNI_logger (char *pname, int argc, char **argv) |
Define Documentation
|
|
Definition at line 11 of file afni_logger.c. Referenced by AFNI_logger(). |
|
|
Definition at line 22 of file afni_logger.c. Referenced by AFNI_logger(). |
|
|
Definition at line 12 of file afni_logger.c. Referenced by AFNI_logger(). |
Function Documentation
|
||||||||||||||||
|
Definition at line 40 of file afni_logger.c. References AFMALL, AFNI_sleep(), AFNI_yesenv(), argc, fll, free, getenv(), LOCK_file, LOGFILE, THD_filesize(), tross_commandline(), tross_datetime(), and UNLOCK_file. Referenced by F3D_initialize_user_data(), get_inputs(), get_line_opt(), get_options(), initialize_program(), and main().
00041 {
00042 char *cline, *cdate , *eh , *fn , *logfile=LOGFILE ;
00043 FILE *fp ;
00044 int ll ; unsigned long fll ;
00045
00046 if( pname == NULL || pname[0] == '\0' ) return -1 ;
00047 eh = getenv("HOME") ; if( eh == NULL ) return -1 ;
00048 if( AFNI_yesenv("AFNI_DONT_LOGFILE") ) return -1 ;
00049 if( argc > 1 ) cline = tross_commandline( pname , argc , argv ) ;
00050 else cline = strdup(pname) ;
00051 if( cline == NULL ) return -1 ;
00052 cdate = tross_datetime() ;
00053 fn = AFMALL(char, strlen(eh)+strlen(logfile)+8) ;
00054 strcpy(fn,eh) ; strcat(fn,"/") ; strcat(fn,logfile) ;
00055 if( (fll=THD_filesize(fn)) > 100000000 ) /* 01 Jun 2005: for Kevin */
00056 fprintf(stderr,"++ WARNING: file %s is now %lu bytes long!\n",fn,fll) ;
00057 fp = fopen(fn,"a") ;
00058 if( fp == NULL ){ free(fn); free(cdate); free(cline); return -1; }
00059 ll = LOCK_file(fp) ;
00060 if( ll ){
00061 #if 0
00062 fprintf(stderr,"%s: LOCKED\n",cline);
00063 #endif
00064 ll = strlen(pname) ; if( ll > 11 ) ll = 11 ;
00065 AFNI_sleep(ll) ; ll = LOCK_file(fp) ;
00066 if( ll ){ fclose(fp); free(fn); free(cdate); free(cline); return -1; }
00067 }
00068 fseek(fp,0,SEEK_END) ;
00069 fprintf(fp,"[%s] %s\n",cdate,cline) ;
00070 UNLOCK_file(fp) ; fclose(fp) ;
00071 free(fn); free(cdate); free(cline) ; return 0;
00072 }
|
|
|
Definition at line 26 of file afni_logger.c. Referenced by AFNI_logger(), and drive_MCW_grapher().
00027 {
00028 struct timeval tv ;
00029 if( msec <= 0 ) return ;
00030 tv.tv_sec = msec/1000 ;
00031 tv.tv_usec = (msec%1000)*1000 ;
00032 select( 1 , NULL,NULL,NULL , &tv ) ;
00033 return ;
00034 }
|