Пример #1
0
static int DisplayLogFlux_valist(FILE * flux, char * function,
                                 log_components_t component, char *format,
                                 va_list arguments)
{
  char tampon[STR_LEN_TXT];

  DisplayLogString_valist(tampon, function, component, format, arguments);

  fprintf(flux, "%s", tampon);
  return fflush(flux);
}                               /* DisplayLogFlux_valist */
Пример #2
0
static int DisplayLogFlux_valist(FILE * flux, char * function, log_components_t component,
                                 int level, char *format, va_list arguments)
{
  char buffer[STR_LEN_TXT];

  DisplayLogString_valist(buffer, function, component, format, arguments);

  fprintf(flux, "%s", buffer);
  if (level <= LogComponents[LOG_MESSAGE_DEBUGINFO].comp_log_level
      && level != NIV_NULL)
    print_debug_info_file(flux);
  return fflush(flux);
}                               /* DisplayLogFlux_valist */
Пример #3
0
static int DisplayLogPath_valist(char *path, char * function,
                                 log_components_t component, int level,
                                 char *format, va_list arguments)
{
  char buffer[STR_LEN_TXT];
  int fd, my_status;

  DisplayLogString_valist(buffer, function, component, format, arguments);

  if(path[0] != '\0')
    {
#ifdef _LOCK_LOG
      if((fd = open(path, O_WRONLY | O_SYNC | O_APPEND | O_CREAT, log_mask)) != -1)
        {
          /* A lock on file */
          struct flock lock_file;
          int rc = 0;

          lock_file.l_type = F_WRLCK;
          lock_file.l_whence = SEEK_SET;
          lock_file.l_start = 0;
          lock_file.l_len = 0;

          if(fcntl(fd, F_SETLKW, (char *)&lock_file) != -1)
            {
              rc = write(fd, buffer, strlen(buffer));
              if (level <= LogComponents[LOG_MESSAGE_DEBUGINFO].comp_log_level
                  && level != NIV_NULL)
                print_debug_info_fd(fd);

              /* Release the lock */
              lock_file.l_type = F_UNLCK;

              fcntl(fd, F_SETLKW, (char *)&lock_file);

              close(fd);

              return SUCCES;
            }                   /* if fcntl */
          else
            {
              my_status = errno;
              close(fd);
            }
        }

#else
      if((fd = open(path, O_WRONLY | O_NONBLOCK | O_APPEND | O_CREAT, log_mask)) != -1)
        {
          if(write(fd, buffer, strlen(buffer)) < strlen(buffer))
          {
            fprintf(stderr, "Error: couldn't complete write to the log file, "
                    "ensure disk has not filled up");
            close(fd);

            return ERR_FILE_LOG;
          }
          if (level <= LogComponents[LOG_MESSAGE_DEBUGINFO].comp_log_level
              && level != NIV_NULL)
            print_debug_info_fd(fd);

          close(fd);

          return SUCCES;
        }
#endif
      else
        {
          my_status = errno;
        }
      fprintf(stderr, "Error %s : %s : status %d on file %s message was:\n%s\n",
              tab_system_err[ERR_FILE_LOG].label,
              tab_system_err[ERR_FILE_LOG].msg, my_status, path, buffer);

      return ERR_FILE_LOG;
    }
  /* if path */
  return SUCCES;
}                               /* DisplayLogPath_valist */
Пример #4
0
static int DisplayLogPath_valist(char *path, char * function,
                                 log_components_t component, char *format,
                                 va_list arguments)
{
  char tampon[STR_LEN_TXT];
  int fd, my_status;

  DisplayLogString_valist(tampon, function, component, format, arguments);

  if(path[0] != '\0')
    {
#ifdef _LOCK_LOG
      if((fd = open(path, O_WRONLY | O_SYNC | O_APPEND | O_CREAT, masque_log)) != -1)
        {
          /* un verrou sur fichier */
          struct flock lock_file;

          /* mise en place de la structure de verrou sur fichier */
          lock_file.l_type = F_WRLCK;
          lock_file.l_whence = SEEK_SET;
          lock_file.l_start = 0;
          lock_file.l_len = 0;

          if(fcntl(fd, F_SETLKW, (char *)&lock_file) != -1)
            {
              /* Si la prise du verrou est OK */
              write(fd, tampon, strlen(tampon));

              /* Relache du verrou sur fichier */
              lock_file.l_type = F_UNLCK;

              fcntl(fd, F_SETLKW, (char *)&lock_file);

              /* fermeture du fichier */
              close(fd);
              return SUCCES;
            }                   /* if fcntl */
          else
            {
              /* Si la prise du verrou a fait un probleme */
              my_status = errno;
              close(fd);
            }
        }

#else
      if((fd = open(path, O_WRONLY | O_NONBLOCK | O_APPEND | O_CREAT, masque_log)) != -1)
        {
          if(write(fd, tampon, strlen(tampon)) < strlen(tampon))
          {
            fprintf(stderr, "Error: couldn't complete write to the log file, ensure disk has not filled up");
            close(fd);
            return ERR_FICHIER_LOG;
          }

          /* fermeture du fichier */
          close(fd);
          return SUCCES;
        }
#endif
      else
        {
          /* Si l'ouverture du fichier s'est mal passee */
          my_status = errno;
        }
      fprintf(stderr, "Error %s : %s : status %d on file %s message was:\n%s\n",
              tab_systeme_err[ERR_FICHIER_LOG].label,
              tab_systeme_err[ERR_FICHIER_LOG].msg, my_status, path, tampon);

      return ERR_FICHIER_LOG;
    }
  /* if path */
  return SUCCES;
}                               /* DisplayLogPath_valist */