54 static void _log_free(
LogFile *log)
58 if (log->
fp && (log->
fp != stdout) && (log->
fp != stderr)) {
119 char time_string[32];
128 log_fp = (log->
fp) ? log->
fp : stdout;
138 if (proc_stats->
errstr[0] !=
'\0') {
140 nbytes = fprintf(log_fp,
141 "\n%s", proc_stats->
errstr);
148 nbytes = fprintf(log_fp,
150 "Executable File Name: %s\n"
151 "Process Image Size: %u Kbytes\n"
152 "Resident Set Size: %u Kbytes\n"
153 "Total CPU Time: %g seconds\n",
165 nbytes = fprintf(log_fp,
166 "Total read/write IO: %lu bytes\n",
175 run_time = (time_t)(proc_stats->
run_time + 0.5);
183 close_time = time(NULL);
189 nbytes = fprintf(log_fp,
190 "\nRun time: %d seconds\n"
202 if (log_fp != stdout &&
206 lockf(fileno(log_fp), F_ULOCK, 0);
209 if (fclose(log_fp) != 0) {
221 else if (log_fp == stdout) {
222 full_path =
"stdout";
224 else if (log_fp == stderr) {
225 full_path =
"stderr";
228 full_path =
"unknown";
231 snprintf(errstr, errlen,
232 "Could not write to log file: %s\n"
234 full_path, strerror(log_errno));
239 log->
fp = (FILE *)NULL;
243 return((log_errno) ? 0 : 1 );
269 if (log->
errstr[0] ==
'\0') {
270 return((
const char *)NULL);
273 return((
const char *)log->
errstr);
327 char time_string[32];
338 snprintf(errstr, errlen,
339 "Could not open log file: %s/%s\n"
340 " -> memory allocation error\n",
355 snprintf(errstr, errlen,
356 "Could not open log file: %s/%s\n"
357 " -> memory allocation error\n",
369 snprintf(errstr, errlen,
370 "Could not open log file: %s/%s\n"
372 path, name, strerror(errno));
379 if (lockf(fileno(log->
fp), F_TLOCK, 0) == -1) {
383 snprintf(errstr, errlen,
384 "Could not get lock on log file: %s/%s\n"
386 path, name, strerror(errno));
397 nbytes = fprintf(log->
fp,
405 snprintf(errstr, errlen,
406 "Could not write to log file: %s/%s\n"
408 path, name, strerror(errno));
449 const char *line_tag,
450 const char *format, ...)
455 va_start(args, format);
488 const char *line_tag,
501 log_fp = (log && log->
fp) ? log->
fp : stdout;
508 nbytes = fprintf(log_fp, line_tag);
516 if (strcmp(format,
"MSNGR_MESSAGE_BLOCK") == 0) {
518 va_copy(args_copy, args);
519 msg_block = va_arg(args_copy,
char **);
522 for (i = 0; msg_block[i] != (
char *)NULL; i++) {
524 length = strlen(msg_block[i]);
525 nbytes = fprintf(log_fp, msg_block[i]);
530 if ((length == 0) || (msg_block[i][length-1] !=
'\n')) {
531 fprintf(log_fp,
"\n");
537 length = strlen(format);
539 if ((length == 0) || (format[length-1] !=
'\n')) {
540 fprintf(log_fp,
"\n");
550 if (fflush(log_fp) != 0) {
558 if (log_fp == stdout) {
559 full_path =
"stdout";
561 else if (log_fp == stderr) {
562 full_path =
"stderr";
572 "Could not write to log file: %s\n"
574 full_path, strerror(log_errno));
583 return((log_errno) ? 0 : 1 );