Download | Plain Text | No Line Numbers


  1. /*
  2.   This program is free software; you can redistribute it and/or
  3.   modify it under the terms of the GNU General Public License as
  4.   published by the Free Software Foundation; either version 2, or (at
  5.   your option) any later version.
  6.  
  7.   This program is distributed in the hope that it will be useful, but
  8.   WITHOUT ANY WARRANTY; without even the implied warranty of
  9.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10.   General Public License for more details.
  11.  
  12.   Derived from checkpassword-pam by Alexey Mahotkin <alexm@hsys.msk.ru> 2002-2004
  13.   Modified and enhanced by Manuel Mausz 2017
  14. */
  15.  
  16. #define _DEFAULT_SOURCE 1
  17.  
  18. #include <stdio.h>
  19. #include <stdarg.h>
  20. #include <syslog.h>
  21.  
  22. #include "logging.h"
  23.  
  24. extern int opt_debug;
  25. extern int opt_use_syslog;
  26.  
  27. inline void log_init(const char *ident)
  28. {
  29. if (opt_use_syslog)
  30. openlog(ident, LOG_PID, LOG_AUTH);
  31. }
  32.  
  33. inline void log_close()
  34. {
  35. closelog();
  36. }
  37.  
  38. void log_error(const char *format, ...)
  39. {
  40. va_list args;
  41. va_start(args, format);
  42.  
  43. if (opt_use_syslog)
  44. (void)vsyslog(LOG_ERR, format, args);
  45. else {
  46. (void)vfprintf(stderr, format, args);
  47. (void)fputc('\n', stderr);
  48. }
  49. }
  50.  
  51. void log_debug(const char *format, ...)
  52. {
  53. if (!opt_debug)
  54. return;
  55.  
  56. va_list args;
  57. va_start(args, format);
  58. if (opt_use_syslog)
  59. (void)vsyslog(LOG_DEBUG, format, args);
  60. else {
  61. (void)vfprintf(stderr, format, args);
  62. (void)fputc('\n', stderr);
  63. }
  64. }
  65.  
  66.