[PVFS2-CVS]
commit by slang in pvfs2/src/common/gossip: gossip.c gossip.h
CVS commit program
cvs at parl.clemson.edu
Thu Aug 25 17:38:16 EDT 2005
Update of /projects/cvsroot/pvfs2/src/common/gossip
In directory parlweb:/tmp/cvs-serv7520/src/common/gossip
Modified Files:
Tag: slang-event-changes-branch
gossip.c gossip.h
Log Message:
updates to my event changes to bring them inline with trunk
Index: gossip.c
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/common/gossip/gossip.c,v
diff -p -u -r1.15 -r1.15.4.1
--- gossip.c 4 Mar 2005 16:50:11 -0000 1.15
+++ gossip.c 25 Aug 2005 20:38:16 -0000 1.15.4.1
@@ -39,11 +39,6 @@ enum
GOSSIP_SYSLOG = 4
};
-enum
-{
- GOSSIP_BUF_SIZE = 1024
-};
-
/** determines which logging facility to use. Default to stderr to begin
* with.
*/
@@ -64,9 +59,10 @@ static enum gossip_logstamp internal_log
static int gossip_disable_stderr(void);
static int gossip_disable_file(void);
-static int gossip_debug_fp(FILE *fp, const char *format, va_list ap, enum
+static int gossip_debug_fp(FILE *fp, char prefix, const char *format, va_list ap, enum
gossip_logstamp ts);
static int gossip_debug_syslog(
+ char prefix,
const char *format,
va_list ap);
static int gossip_err_syslog(
@@ -250,6 +246,7 @@ int gossip_set_logstamp(
*/
int __gossip_debug_stub(
uint64_t mask,
+ char prefix,
const char *format,
...)
{
@@ -267,6 +264,7 @@ int __gossip_debug_stub(
*/
int __gossip_debug(
uint64_t mask,
+ char prefix,
const char *format,
...)
{
@@ -285,19 +283,25 @@ int __gossip_debug(
}
#endif
+ if(prefix == '?')
+ {
+ /* automatic prefix assignment */
+ prefix = 'D';
+ }
+
/* rip out the variable arguments */
va_start(ap, format);
switch (gossip_facility)
{
case GOSSIP_STDERR:
- ret = gossip_debug_fp(stderr, format, ap, internal_logstamp);
+ ret = gossip_debug_fp(stderr, prefix, format, ap, internal_logstamp);
break;
case GOSSIP_FILE:
- ret = gossip_debug_fp(internal_log_file, format, ap, internal_logstamp);
+ ret = gossip_debug_fp(internal_log_file, prefix, format, ap, internal_logstamp);
break;
case GOSSIP_SYSLOG:
- ret = gossip_debug_syslog(format, ap);
+ ret = gossip_debug_syslog(prefix, format, ap);
break;
default:
break;
@@ -332,10 +336,10 @@ int gossip_err(
switch (gossip_facility)
{
case GOSSIP_STDERR:
- ret = gossip_debug_fp(stderr, format, ap, internal_logstamp);
+ ret = gossip_debug_fp(stderr, 'E', format, ap, internal_logstamp);
break;
case GOSSIP_FILE:
- ret = gossip_debug_fp(internal_log_file, format, ap, internal_logstamp);
+ ret = gossip_debug_fp(internal_log_file, 'E', format, ap, internal_logstamp);
break;
case GOSSIP_SYSLOG:
ret = gossip_err_syslog(format, ap);
@@ -384,13 +388,20 @@ void gossip_backtrace(void)
* returns 0 on success, -errno on failure
*/
static int gossip_debug_syslog(
+ char prefix,
const char *format,
va_list ap)
{
char buffer[GOSSIP_BUF_SIZE];
+ char *bptr = buffer;
+ int bsize = sizeof(buffer);
int ret = -EINVAL;
- ret = vsnprintf(buffer, GOSSIP_BUF_SIZE, format, ap);
+ sprintf(bptr, "[%c] ", prefix);
+ bptr += 4;
+ bsize -= 4;
+
+ ret = vsnprintf(bptr, bsize, format, ap);
if (ret < 0)
{
return -errno;
@@ -408,8 +419,8 @@ static int gossip_debug_syslog(
*
* returns 0 on success, -errno on failure
*/
-static int gossip_debug_fp(FILE *fp, const char *format, va_list ap, enum
-gossip_logstamp ts)
+static int gossip_debug_fp(FILE *fp, char prefix,
+ const char *format, va_list ap, enum gossip_logstamp ts)
{
char buffer[GOSSIP_BUF_SIZE], *bptr = buffer;
int bsize = sizeof(buffer);
@@ -417,24 +428,32 @@ gossip_logstamp ts)
struct timeval tv;
time_t tp;
+ sprintf(bptr, "[%c ", prefix);
+ bptr += 3;
+ bsize -= 3;
+
switch(ts)
{
case GOSSIP_LOGSTAMP_USEC:
gettimeofday(&tv, 0);
tp = tv.tv_sec;
- strftime(bptr, 10, "[%H:%M:%S", localtime(&tp));
- sprintf(bptr+9, ".%06ld] ", tv.tv_usec);
- bptr += 18;
- bsize -= 18;
+ strftime(bptr, 9, "%H:%M:%S", localtime(&tp));
+ sprintf(bptr+8, ".%06ld] ", tv.tv_usec);
+ bptr += 17;
+ bsize -= 17;
break;
case GOSSIP_LOGSTAMP_DATETIME:
gettimeofday(&tv, 0);
tp = tv.tv_sec;
- strftime(bptr, 15, "[%m/%d %H:%M] ", localtime(&tp));
- bptr += 14;
- bsize -= 14;
+ strftime(bptr, 14, "%m/%d %H:%M] ", localtime(&tp));
+ bptr += 13;
+ bsize -= 13;
break;
case GOSSIP_LOGSTAMP_NONE:
+ bptr--;
+ sprintf(bptr, "] ");
+ bptr += 2;
+ bsize++;
break;
default:
break;
@@ -472,7 +491,7 @@ static int gossip_err_syslog(
int tmp_priority = internal_syslog_priority;
internal_syslog_priority = LOG_ERR;
- gossip_debug_syslog(format, ap);
+ gossip_debug_syslog('E', format, ap);
internal_syslog_priority = tmp_priority;
Index: gossip.h
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/common/gossip/gossip.h,v
diff -p -u -r1.12 -r1.12.4.1
--- gossip.h 28 Mar 2005 18:31:38 -0000 1.12
+++ gossip.h 25 Aug 2005 20:38:16 -0000 1.12.4.1
@@ -28,6 +28,8 @@
* Visible interface
*/
+#define GOSSIP_BUF_SIZE 1024
+
/* what type of timestamp to place in msgs */
enum gossip_logstamp
{
@@ -64,8 +66,9 @@ void gossip_backtrace(void);
/* do printf style type checking if built with gcc */
int __gossip_debug(
uint64_t mask,
+ char prefix,
const char *format,
- ...) __attribute__ ((format(printf, 2, 3)));
+ ...) __attribute__ ((format(printf, 3, 4)));
int gossip_err(
const char *format,
...) __attribute__ ((format(printf, 1, 2)));
@@ -83,7 +86,7 @@ do {
if ((gossip_debug_on) && (gossip_debug_mask & mask) &&\
(gossip_facility)) \
{ \
- __gossip_debug(mask, format, ##f); \
+ __gossip_debug(mask, '?', format, ##f); \
} \
} while(0)
#endif /* GOSSIP_DISABLE_DEBUG */
@@ -91,29 +94,31 @@ do {
/* do file and line number printouts w/ the GNU preprocessor */
#define gossip_ldebug(mask, format, f...) \
do { \
- gossip_debug(mask, "%s: " format, __func__, ##f); \
+ gossip_debug(mask, "%s: " format, __func__ , ##f); \
} while(0)
#ifdef GOSSIP_ENABLE_BACKTRACE
#define gossip_lerr(format, f...) \
do { \
- gossip_err("%s line %d: " format, __FILE__, __LINE__, ##f); \
+ gossip_err("%s line %d: " format, __FILE__ , __LINE__ , ##f); \
gossip_backtrace(); \
} while(0)
#else
#define gossip_lerr(format, f...) \
do { \
- gossip_err("%s line %d: " format, __FILE__, __LINE__, ##f); \
+ gossip_err("%s line %d: " format, __FILE__ , __LINE__ , ##f); \
} while(0)
#endif
#else /* ! __GNUC__ */
int __gossip_debug(
uint64_t mask,
+ char prefix,
const char *format,
...);
int __gossip_debug_stub(
uint64_t mask,
+ char prefix,
const char *format,
...);
int gossip_err(
@@ -121,11 +126,11 @@ int gossip_err(
...);
#ifdef GOSSIP_DISABLE_DEBUG
-#define gossip_debug __gossip_debug_stub
-#define gossip_ldebug __gossip_debug_stub
+#define gossip_debug(__m, __f, f...) __gossip_debug_stub(__m, '?', __f, ##f);
+#define gossip_ldebug(__m, __f, f...) __gossip_debug_stub(__m, '?', __f, ##f);
#else
-#define gossip_debug __gossip_debug
-#define gossip_ldebug __gossip_debug
+#define gossip_debug(__m, __f, f...) __gossip_debug(__m, '?', __f, ##f);
+#define gossip_ldebug(__m, __f, f...) __gossip_debug(__m, '?', __f, ##f);
#endif /* GOSSIP_DISABLE_DEBUG */
#define gossip_lerr gossip_err
More information about the PVFS2-CVS
mailing list