Exemple #1
0
int flog_set_file(const char *filename) {
   int          status = FL_ERR_SUCCESS;
   const char   me[] = "flog_set_file";
   int          rc;
   char         prefix[3][STG_PREFIX_LEN];
   char         msg[128];

   /* lock mutex */
   rc = pthread_mutex_lock(&flog_mutex);
   if ( rc != 0 ) {
      (void) flog_prefix(FLOG_FATAL, FL_ERR_LOG_MUTEX, me, prefix);
      (void) sprintf(msg,
         "pthread_mutex_lock failed, rc = %d, errno = %d", rc, errno);
      (void) flog_print(FLOG_FATAL, prefix, msg);
      if ( status == FL_ERR_SUCCESS ) status = FL_ERR_LOG_MUTEX;
   }

   (void) strncpy(flog_file.name, filename, STG_FILE_PATH_MAX);
   flog_file.name[STG_FILE_PATH_MAX] = '\0';

   /* unlock mutex */
   rc = pthread_mutex_unlock(&flog_mutex);
   if ( rc != 0 ) {
      (void) flog_prefix(FLOG_FATAL, FL_ERR_LOG_MUTEX, me, prefix);
      (void) sprintf(msg,
         "pthread_mutex_unlock failed, rc = %d, errno = %d", rc, errno);
      (void) flog_print(FLOG_FATAL, prefix, msg);
      if ( status == FL_ERR_SUCCESS ) status = FL_ERR_LOG_MUTEX;
   }


   return(status);
}
Exemple #2
0
int flog_msg(const int16_t severity, const int ec, const char *routine,
                const char *message) {
   int          status = FL_ERR_SUCCESS;
   const char   me[] = "flog_msg";
   int16_t      level;
   char         prefix[3][STG_PREFIX_LEN];
   int          rc;
   char         msg[128];


   /* limit level to valid range */
   if (( severity > FLOG_NOLOG ) || ( severity < FLOG_CL4BUG )) {
      level = 0;
   } else {
      level = severity;
   }

   if (( abs(level) <= flog_report[0] ) ||
       ( abs(level) <= flog_report[1] ) ||
       ( abs(level) <= flog_report[2] )) {

      /* get message prefixes */
      status = flog_prefix(level, ec, routine, prefix);


      /* lock mutex */
      rc = pthread_mutex_lock(&flog_mutex);


      status = flog_print(level, prefix, message);

      if ( rc != 0 ) {
         (void) flog_prefix(FLOG_FATAL, FL_ERR_LOG_MUTEX, me, prefix);
         (void) snprintf(msg, 127,
            "pthread_mutex_lock failed, rc = %d, errno = %d", rc, errno);
         msg[127] = '\0';
         (void) flog_print(FLOG_FATAL, prefix, msg);
         if ( status == FL_ERR_SUCCESS ) status = FL_ERR_LOG_MUTEX;
      }


      /* unlock mutex */
      rc = pthread_mutex_unlock(&flog_mutex);
      if ( rc != 0 ) {
         (void) flog_prefix(FLOG_FATAL, FL_ERR_LOG_MUTEX, me, prefix);
         (void) snprintf(msg, 127,
            "pthread_mutex_unlock failed, rc = %d, errno = %d", rc, errno);
         msg[127] = '\0';
         (void) flog_print(FLOG_FATAL, prefix, msg);
         if ( status == FL_ERR_SUCCESS ) status = FL_ERR_LOG_MUTEX;
      }
   }


   return(status);
}
Exemple #3
0
int flog_get_report(int16_t *report_std, int16_t *report_sys,
                       int16_t *report_file) {
   int          status = FL_ERR_SUCCESS;
   const char   me[] = "flog_get_report";
   int          rc;
   char         prefix[3][STG_PREFIX_LEN];
   char         msg[128];


   /* lock mutex */
   rc = pthread_mutex_lock(&flog_mutex);
   if ( rc != 0 ) {
      (void) flog_prefix(FLOG_FATAL, FL_ERR_LOG_MUTEX, me, prefix);
      (void) sprintf(msg,
		     "pthread_mutex_lock failed, rc = %d, errno = %d", rc, errno);
      (void) flog_print(FLOG_FATAL, prefix, msg);
      if ( status == FL_ERR_SUCCESS ) status = FL_ERR_LOG_MUTEX;
   }

   *report_std = flog_report[0];
   *report_sys = flog_report[1];
   *report_file = flog_report[2];

   /* unlock mutex */
   rc = pthread_mutex_unlock(&flog_mutex);
   if ( rc != 0 ) {
      (void) flog_prefix(FLOG_FATAL, FL_ERR_LOG_MUTEX, me, prefix);
      (void) sprintf(msg,
		     "pthread_mutex_unlock failed, rc = %d, errno = %d", rc, errno);
      (void) flog_print(FLOG_FATAL, prefix, msg);
      if ( status == FL_ERR_SUCCESS ) status = FL_ERR_LOG_MUTEX;
   }


   return(status);
}
Exemple #4
0
int flog_set_style(const uint32_t style_std, const uint32_t style_sys,
                      const uint32_t style_file) {
   int          status = FL_ERR_SUCCESS;
   const char   me[] = "flog_set_style";
   int          rc;
   char         prefix[3][STG_PREFIX_LEN];
   char         msg[128];


   /* lock mutex */
   rc = pthread_mutex_lock(&flog_mutex);
   if ( rc != 0 ) {
      (void) flog_prefix(FLOG_FATAL, FL_ERR_LOG_MUTEX, me, prefix);
      (void) sprintf(msg,
         "pthread_mutex_lock failed, rc = %d, errno = %d", rc, errno);
      (void) flog_print(FLOG_FATAL, prefix, msg);
      if ( status == FL_ERR_SUCCESS ) status = FL_ERR_LOG_MUTEX;
   }

   flog_style[0] = style_std;
   flog_style[1] = style_sys;
   flog_style[2] = style_file;

   /* unlock mutex */
   rc = pthread_mutex_unlock(&flog_mutex);
   if ( rc != 0 ) {
      (void) flog_prefix(FLOG_FATAL, FL_ERR_LOG_MUTEX, me, prefix);
      (void) sprintf(msg,
         "pthread_mutex_unlock failed, rc = %d, errno = %d", rc, errno);
      (void) flog_print(FLOG_FATAL, prefix, msg);
      if ( status == FL_ERR_SUCCESS ) status = FL_ERR_LOG_MUTEX;
   }


   return(status);
}
Exemple #5
0
//! @param[in,out] *p target log
//! @param[in] *sublog log to add
//! @retval 0 success
int flog_append_sublog(FLOG_T *p,FLOG_T *sublog)
{
	if(!p)
		return(1);
	if(p==sublog) {
		flog_print(p->error_log,NULL,FLOG_ERROR,0,"cannot append log to itself (causes circular dependency)");
		return(1);
	}
	FLOG_T **new_sublog;
	if((new_sublog=realloc(p->sublog,(p->sublog_amount+1)*sizeof(FLOG_T *)))==NULL)
		return(1);
	p->sublog=new_sublog;
	p->sublog[p->sublog_amount]=sublog;
	p->sublog_amount++;
	return(0);
}
Exemple #6
0
int flog_set_report(const int16_t report_std, const int16_t report_sys,
                       const int16_t report_file) {
   int             status = FL_ERR_SUCCESS;
   const char      me[] = "flog_set_report";
   int             rc;
   char            prefix[3][STG_PREFIX_LEN];
   char            msg[128];


   /* lock mutex */
   rc = pthread_mutex_lock(&flog_mutex);
   if ( rc != 0 ) {
      (void) flog_prefix(FLOG_FATAL, FL_ERR_LOG_MUTEX, me, prefix);
      (void) sprintf(msg,
		     "pthread_mutex_lock failed, rc = %d, errno = %d",
         rc, errno);
      (void) flog_print(FLOG_FATAL, prefix, msg);
      if ( status == FL_ERR_SUCCESS ) status = FL_ERR_LOG_MUTEX;
   }


   flog_report[0] = report_std;


   if (( report_sys > FLOG_QUIET ) &&
       ( flog_report[1] <= FLOG_QUIET )) {
      (void) openlog("stager", LOG_CONS | LOG_NOWAIT, LOG_DAEMON);
   }
   else if (( report_sys <= FLOG_QUIET ) &&
            ( flog_report[1] > FLOG_QUIET )) {
      (void) closelog();
   }
   flog_report[1] = report_sys;


   if (( report_file > FLOG_QUIET ) &&
       ( flog_report[2] <= FLOG_QUIET )) {
      if ( flog_file.name[0] == '\0' ) {
         rc = snprintf(flog_file.name, STG_FILE_PATH_MAX, "stg_%lu.log",
            (unsigned long int) time(NULL));
         flog_file.name[STG_FILE_PATH_MAX] = '\0';
      }

      flog_file.fp = fopen(flog_file.name, "a");
      if ( flog_file.fp == NULL ) {
         (void) flog_prefix(FLOG_ERROR, FL_ERR_LOG_FILE, me, prefix);
         (void) sprintf(msg, "fopen failed, rc = %d, errno = %d", rc, errno);
         (void) flog_print(FLOG_ERROR, prefix, msg);
         if ( status == FL_ERR_SUCCESS ) status = FL_ERR_LOG_FILE;
      }
      else {
         flog_report[2] = report_file;
      }
   }
   else if (( report_file <= FLOG_QUIET ) &&
            ( flog_report[2] > FLOG_QUIET )) {
      rc = fclose(flog_file.fp);
      if ( rc != 0 ) {
         (void) flog_prefix(FLOG_ERROR, FL_ERR_LOG_FILE, me, prefix);
         (void) sprintf(msg, "fclose failed, rc = %d, errno = %d", rc, errno);
         (void) flog_print(FLOG_ERROR, prefix, msg);
         if ( status == FL_ERR_SUCCESS ) status = FL_ERR_LOG_FILE;
      }
      flog_file.fp = NULL;
      flog_report[2] = FLOG_QUIET;
   }
   else {
      flog_report[2] = report_file;
   }


   /* unlock mutex */
   rc = pthread_mutex_unlock(&flog_mutex);
   if ( rc != 0 ) {
      (void) flog_prefix(FLOG_FATAL, FL_ERR_LOG_MUTEX, me, prefix);
      (void) sprintf(msg,
         "pthread_mutex_unlock failed, rc = %d, errno = %d", rc, errno);
      (void) flog_print(FLOG_FATAL, prefix, msg);
      if ( status == FL_ERR_SUCCESS ) status = FL_ERR_LOG_MUTEX;
   }


   return(status);
}