1 /* Debugging routines for the control program. */
2
3 /*
4 * Copyright (C) 2003-2006 IBM
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22 #include <unistd.h>
23 #include <stdlib.h>
24 #include <time.h>
25 #include <stdarg.h>
26 #include <sys/types.h>
27 #include <sys/time.h>
28
29 #include "debug.h"
30
31 #define BUF_LEN 256
32
pounder_fprintf(FILE * stream,const char * format,...)33 int pounder_fprintf(FILE * stream, const char *format, ...)
34 {
35 struct timeval tv;
36 struct tm *time;
37 char buf[BUF_LEN];
38 int ret;
39 va_list args;
40 FILE *logfile;
41
42 snprintf(buf, BUF_LEN, "%s/POUNDERLOG", getenv("POUNDER_LOGDIR"));
43 logfile = fopen(buf, "a");
44 if (logfile == NULL) {
45 perror(buf);
46 }
47
48 gettimeofday(&tv, NULL);
49 time = localtime(&tv.tv_sec);
50 strftime(buf, BUF_LEN, "[%Y-%m-%d %H:%M:%S]", time);
51
52 fprintf(stream, "%s (%d) ", buf, getpid());
53
54 va_start(args, format);
55 ret = vfprintf(stream, format, args);
56 va_end(args);
57
58 if (logfile != NULL) {
59 fprintf(logfile, "%s (%d) ", buf, getpid());
60 va_start(args, format);
61 vfprintf(logfile, format, args);
62 va_end(args);
63 fclose(logfile);
64 }
65
66 fflush(stream);
67
68 return ret;
69 }
70
71 const char *fail_msg = "\e[33;1mFAIL\e[0m";
72 const char *pass_msg = "\e[32;1mPASS\e[0m";
73 const char *abort_msg = "\e[31;1mABORT\e[0m";
74 const char *start_msg = "\e[36;1mSTART\e[0m";
75