Browse Source

fl_wrapper: split log_append() out of handle_file_access_after()

user/amery/test/random-cleanup
Alejandro Mery 14 years ago
committed by Alejandro Mery
parent
commit
485035afa0
1 changed files with 29 additions and 18 deletions
  1. +29
    -18
      src/tools-source/fl_wrapper/fl_wrapper.c

+ 29
- 18
src/tools-source/fl_wrapper/fl_wrapper.c

@ -304,12 +304,38 @@ static void sort_of_realpath (const char *file, char *absfile)
*dst = 0; *dst = 0;
} }
static inline void log_append(const char *logfile, const char *fmt, ...)
{
va_list ap;
char buf[PATH_MAX];
int fd, l;
va_start(ap, fmt);
l = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
#ifdef __USE_LARGEFILE
fd=open64(logfile,O_APPEND|O_WRONLY|O_LARGEFILE,0);
#else
#warning "The wrapper library will not work properly for large logs!"
fd=open(logfile,O_APPEND|O_WRONLY,0);
#endif
if (fd == -1) return;
flock(fd, LOCK_EX);
lseek(fd, 0, SEEK_END);
write(fd,buf,l);
close(fd);
}
static void handle_file_access_after(const char * func, const char * file, static void handle_file_access_after(const char * func, const char * file,
struct status_t * status) struct status_t * status)
{ {
char buf[PATH_MAX], *logfile, filterdir2 [PATH_MAX], *tfilterdir;
char *logfile, filterdir2 [PATH_MAX], *tfilterdir;
char absfile [PATH_MAX]; char absfile [PATH_MAX];
int fd; struct stat st;
struct stat st;
LOG("begin of handle_file_access_after(\"%s\", \"%s\", xxx)\n", func, file); LOG("begin of handle_file_access_after(\"%s\", \"%s\", xxx)\n", func, file);
@ -338,21 +364,6 @@ static void handle_file_access_after(const char * func, const char * file,
return; return;
} }
} }
#ifdef __USE_LARGEFILE
fd=open64(logfile,O_APPEND|O_WRONLY|O_LARGEFILE,0);
#else
#warning "The wrapper library will not work properly for large logs!"
fd=open(logfile,O_APPEND|O_WRONLY,0);
#endif
if (fd == -1) return;
flock(fd, LOCK_EX);
lseek(fd, 0, SEEK_END);
sprintf(buf,"%s.%s:\t%s\n", cmdname, func, absfile);
write(fd,buf,strlen(buf));
close(fd);
log_append(logfile, "%s.%s:\t%s\n", cmdname, func, absfile);
LOG("end of handle_file_access_after(\"%s\", \"%s\", xxx)", func, file); LOG("end of handle_file_access_after(\"%s\", \"%s\", xxx)", func, file);
} }

Loading…
Cancel
Save