home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / libcnews / rerror.c < prev    next >
C/C++ Source or Header  |  1994-09-18  |  2KB  |  116 lines

  1. /*
  2.  * relaynews error handling (also used by some other bits)
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <errno.h>
  9. #include "fixerrno.h"
  10. #include <sys/types.h>
  11. #include <sys/timeb.h>        /* solely for getindate call */
  12.  
  13. #include "libc.h"
  14. #include "news.h"
  15. #include "active.h"
  16. #include "headers.h"
  17. #include "relay.h"
  18. #include "msgs.h"
  19.  
  20. /* common log reporting */
  21. static
  22. log(stream, art, code, fmt, arg, sverrno)
  23. register FILE *stream;
  24. register struct article *art;
  25. int code;
  26. char *fmt, *arg;
  27. register int sverrno;
  28. {
  29.     time_t now;
  30.  
  31.     if (code != '\0') {
  32.         timestamp(stream, &now);
  33.         (void) putc(' ', stream);
  34.         if (art != NULL)
  35.             (void) fputs(sendersite(nullify(art->h.h_path)),
  36.                 stream);
  37.         (void) putc(' ', stream);
  38.         (void) putc(code, stream);
  39.         (void) putc(' ', stream);
  40.         if (art != NULL && art->h.h_msgid != NULL)
  41.             (void) fputs(art->h.h_msgid, stream);
  42.         else
  43.             (void) putc('-', stream);
  44.         (void) putc(' ', stream);
  45.         (void) fprintf(stream, fmt, arg);
  46.         if (sverrno != 0)
  47.             (void) fprintf(stream, " (%s)", strerror(sverrno));
  48.         (void) putc('\n', stream);
  49.         if (ferror(stream))
  50.             fulldisk(art, "a log file");
  51.     }
  52. }
  53.  
  54. /*
  55.  * log an audit report and continue
  56.  * article status unaffected
  57.  */
  58. logaudit(art, code, fmt, arg)
  59. struct article *art;
  60. int code;
  61. char *fmt, *arg;
  62. {
  63.     log(stdout, art, code, fmt, arg, 0);
  64. }
  65.  
  66. /*
  67.  * log a complaint about bad input and continue
  68.  * set ST_REFUSED in article status
  69.  */
  70. transient(art, code, fmt, arg)
  71. register struct article *art;
  72. int code;
  73. char *fmt, *arg;
  74. {
  75.     log(stdout, art, code, fmt, arg, 0);
  76.     if (art != NULL)
  77.         art->a_status |= ST_REFUSED;
  78. }
  79.  
  80. /*
  81.  * the news system needs attention; complain and shut down gracefully
  82.  * sets ST_NEEDATTN and ST_DROPPED in article status
  83.  */
  84. persistent(art, code, fmt, arg)
  85. register struct article *art;
  86. int code;
  87. char *fmt, *arg;
  88. {
  89.     log(stderr, art, code, fmt, arg, errno);
  90.     if (art != NULL)
  91.         art->a_status |= ST_NEEDATTN|ST_DROPPED;
  92. }
  93.  
  94. /*
  95.  * something impossible has happened; complain and shut down ASAP
  96.  * either quits or sets ST_NEEDATTN and ST_DROPPED in article status
  97.  */
  98. /* ARGSUSED art code */
  99. canthappen(art, code, fmt, arg)
  100. struct article *art;
  101. int code;
  102. char *fmt, *arg;
  103. {
  104.     errunlock(fmt, arg);
  105.     /* NOTREACHED */
  106. }
  107.  
  108. void
  109. fulldisk(art, file)            /* complain once & set status bits */
  110. register struct article *art;
  111. char *file;
  112. {
  113.     if (!(art->a_status&ST_DISKFULL))
  114.         art->a_status |= prfulldisk(file);
  115. }
  116.