[BACK]Return to log.c CVS log [TXT][DIR] Up to [local] / blind

Diff for /blind/log.c between version 1.6 and 1.11

version 1.6, 2022/03/18 20:54:01 version 1.11, 2022/04/03 13:52:00
Line 1 
Line 1 
 /*  /*
 1;95;0c * Copyright (c) 2022 Daniel Kroczynski <d@kroczynski.net>   * Copyright (c) 2022 Daniel Kroczynski <d@kroczynski.net>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above   * purpose with or without fee is hereby granted, provided that the above
Line 14 
Line 14 
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */   */
   
   #include <errno.h>
   #include <stdarg.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <stdarg.h>  
 #include <syslog.h>  
 #include <string.h>  #include <string.h>
 #include <errno.h>  #include <syslog.h>
 #include <time.h>  #include <time.h>
   
 static int  log_background;  static int      log_bgnd;
 static int  log_verbose;  static int      log_verb;
 const char *log_procname;  const char     *log_name;
   
 void    log_initialize(int, int);  void    log_init(int, int);
 void    log_setverbose(int);  void    log_set(int);
 int     log_getverbose(void);  int     log_get(void);
 void    log_send(const char *, va_list)  void    log_send(const char *, va_list)
         __attribute__((__format__ (printf, 1, 0)));          __attribute__((__format__ (printf, 1, 0)));
 void    log_info(const char *, ...)  void    log_info(const char *, ...)
Line 39  __dead void log_fatal(const char *, ...)
Line 39  __dead void log_fatal(const char *, ...)
         __attribute__((__format__ (printf, 1, 2)));          __attribute__((__format__ (printf, 1, 2)));
   
 void  void
 log_initialize(int background, int facility)  log_init(int background, int facility)
 {  {
         extern char *__progname;          extern char *__progname;
   
         if (__progname != NULL)          if (__progname != NULL)
                 log_procname = __progname;                  log_name = __progname;
   
         log_background = background;          log_bgnd = background;
         if (log_background)          if (log_bgnd)
                 openlog(log_procname, LOG_PID | LOG_NDELAY, facility);                  openlog(log_name, LOG_PID | LOG_NDELAY, facility);
   
         tzset();          tzset();
 }  }
   
 void  void
 log_setverbose(int verb)  log_set(int verb)
 {  {
         log_verbose = verb;          log_verb = verb;
 }  }
   
 int  int
 log_getverbose(void)  log_get(void)
 {  {
         return (log_verbose);          return (log_verb);
 }  }
   
 void  void
 log_send(const char *info, va_list ap)  log_send(const char *info, va_list ap)
 {  {
           char   *ninf;
   
         if (info != NULL) {          if (info != NULL) {
                 if (log_background)                  if (log_bgnd)
                         vsyslog(LOG_INFO, info, ap);                          vsyslog(LOG_INFO, info, ap);
                 else {                  else {
                         vfprintf(stderr, info, ap);                          if (asprintf(&ninf, "%s\n", info) == -1) {
                         fprintf(stderr, "\n");                                  vfprintf(stderr, info, ap);
                                   fprintf(stderr, "\n");
                           } else {
                                   vfprintf(stderr, ninf, ap);
                                   free(ninf);
                           }
                           fflush(stderr);
                 }                  }
         }          }
 }  }
Line 93  log_debug(const char *info, ...)
Line 101  log_debug(const char *info, ...)
 {  {
         va_list ap;          va_list ap;
   
         if (log_verbose) {          if (log_verb) {
                 va_start(ap, info);                  va_start(ap, info);
                 log_send(info, ap);                  log_send(info, ap);
                 va_end(ap);                  va_end(ap);
Line 103  log_debug(const char *info, ...)
Line 111  log_debug(const char *info, ...)
 void  void
 log_fatal(const char *info, ...)  log_fatal(const char *info, ...)
 {  {
           extern struct blind *bl;
           static char s[BUFSIZ];
         va_list ap;          va_list ap;
   
         va_start(ap, info);          va_start(ap, info);
         log_send(info, ap);          if (info != NULL)
                   (void)vsnprintf(s, sizeof(s), info, ap);
           else
                   s[0] = '\0';
   
         va_end(ap);          va_end(ap);
         log_info("%s", strerror(errno));          if (errno)
                   log_info("%s: %s", strerror(errno), s);
           else
                   log_info("Unknown error: %s", s);
   
           if (bl != NULL)
                   free(bl);
   
         exit(1);          exit(1);
 }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.11

https://cvs.kroczynski.net