Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Commit

Permalink
idoutils: replace direct write with vfprintf with gnu vasprint/fprint…
Browse files Browse the repository at this point in the history
…f, which take care about null pointer arguments causing SEGV in Solaris #2271

refs #2271
  • Loading branch information
Tommi2Day committed Feb 3, 2012
1 parent 44111b7 commit 2256b95
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions module/idoutils/src/logging.c
Expand Up @@ -68,11 +68,13 @@ int ido2db_close_debug_log(void) {
int ido2db_log_debug_info(int level, int verbosity, const char *fmt, ...) {
va_list ap;
char *temp_path = NULL;
char *buf=NULL;
time_t t;
struct tm *tm;
char temp_time[80];
struct timeval current_time;
unsigned long tid;
unsigned long pid;

if (!(ido2db_debug_level == IDO2DB_DEBUGL_ALL || (level & ido2db_debug_level)))
return IDO_OK;
Expand All @@ -89,16 +91,22 @@ int ido2db_log_debug_info(int level, int verbosity, const char *fmt, ...) {
time(&t);
tm=localtime(&t);
strftime(temp_time, 80, "%c", tm);
tid=(unsigned long)pthread_self();
tid=pthread_self();
pid=getpid();
if (ido2db_debug_readable_timestamp)
fprintf(ido2db_debug_file_fp, "%s .%06lu [%03d.%d] [pid=%lu] [tid=%lu] ", temp_time, current_time.tv_usec, level, verbosity, (unsigned long)getpid(), tid);
fprintf(ido2db_debug_file_fp, "%s .%06lu [%03d.%d] [pid=%lu] [tid=%lu] ", temp_time, current_time.tv_usec, level, verbosity, pid, tid);
else
fprintf(ido2db_debug_file_fp, "[%lu.%06lu] [%03d.%d] [pid=%lu] [tid=%lu] ", current_time.tv_sec, current_time.tv_usec, level, verbosity, (unsigned long)getpid(), tid);
fprintf(ido2db_debug_file_fp, "[%lu.%06lu] [%03d.%d] [pid=%lu] [tid=%lu] ", current_time.tv_sec, current_time.tv_usec, level, verbosity, pid, tid);

/* write the data */
va_start(ap, fmt);
vfprintf(ido2db_debug_file_fp, fmt, ap);
/* use gnu asprintf to take care about null pointer data*/
vasprintf(&buf, fmt, ap);
va_end(ap);
if (buf) {
fprintf(ido2db_debug_file_fp, "%s", buf);
my_free(buf);
}

/* flush, so we don't have problems tailing or when fork()ing */
fflush(ido2db_debug_file_fp);
Expand Down

0 comments on commit 2256b95

Please sign in to comment.