|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T m
Length: 4108 (0x100c) Types: TextFile Names: »misc.c«
└─⟦9ae75bfbd⟧ Bits:30007242 EUUGD3: Starter Kit └─⟦f91e15335⟧ »EurOpenD3/news/nntp/nntplink2.0.0.tar.Z« └─⟦2c70c5e6b⟧ └─⟦this⟧ »misc.c«
#include "global.h" /* ** Signal stuff ** ** There's probably too much stuff to do in this signal ** handler, but we're going to exit anyway... */ interrupted(sig) int sig; { char buf[BUFSIZ]; #ifndef RELSIG catchsig(SIG_IGN); /* for System V - hope we're quick enough */ #endif RELSIG sprintf(buf, "%s signal %d", Host, sig); log(L_NOTICE, buf); if (Qfp != (FILE *)NULL) requeue(Article, (char *)NULL); if (!In_Log_File) cleanup(); if (Use_Log_File) create_nntp_spoolfile(); if (Report_Stats) logstats(); goodbye(DONT_WAIT); exit(EX_TEMPFAIL); } struct { int signo; ifunp state; } SigList[] = { {SIGHUP}, {SIGINT}, {SIGQUIT}, {SIGTERM}, {NULL} }; void catchsig(handler) ifunp handler; { register int i; if (handler != (ifunp)SIG_IGN) { for(i = 0; SigList[i].signo != NULL; i++) { #ifdef sun SigList[i].state = (int (*)())signal(SigList[i].signo, handler); #else SigList[i].state = signal(SigList[i].signo, handler); #endif sun } } else { for(i = 0; SigList[i].signo != NULL; i++) { (void) signal(SigList[i].signo, handler); } } } /* ** log stuff */ void log(importance, error) int importance; char *error; { dprintf(stderr, "log %s: %s\n", Pname, error); fflush(stderr); #ifdef SYSLOG switch(importance) { case L_INFO: importance = LOG_INFO; break; case L_DEBUG: importance = LOG_DEBUG; break; case L_NOTICE: importance = LOG_NOTICE; break; case L_WARNING: importance = LOG_WARNING; break; default: importance = LOG_DEBUG; break; } syslog(importance, error); #endif SYSLOG } /* ** Lock a file descriptor ** ** NOTE: if the appropriate system calls are unavailable, ** this subroutine is a no-op. */ lockfd(fd, file, non_blocking) int fd, non_blocking; char *file; /* just for error reporting */ { char buf[BUFSIZ]; #ifdef USG #ifdef F_TLOCK if (lockf(fd, (non_blocking ? F_TLOCK : F_LOCK), 0) < 0) { if (errno != EACCES) { sprintf(buf, "lockf(%s): %s\n", file, errmsg(errno)); log(L_WARNING, buf); } return(FALSE); } #endif F_TLOCK #else #ifdef LOCK_EX if (flock(fd, LOCK_EX|(non_blocking ? LOCK_NB : 0)) < 0) { if (errno != EWOULDBLOCK) { sprintf(buf, "flock(%s): %s\n", file, errmsg(errno)); log(L_WARNING, buf); } return(FALSE); } #endif LOCK_EX #endif USG return(TRUE); } void create_nntp_spoolfile() { int i, spool_dir_length; char *mode = "a", *p, mesgid[255], spool_entry[255], buf[BUFSIZ]; FILE *spoolfile; if (!In_Log_File) { if (Qfp != (FILE *)NULL) { FCLOSE(Qfp); if ((Qfp = fopen(LOG_FILE, "r")) == (FILE *)NULL) { sprintf(buf, E_fopen, orig_nntpfile, mode, errmsg(errno)); log(L_WARNING, buf); FCLOSE(Qfp); return; } } else { if ((Qfp = fopen(LOG_FILE, "r")) == (FILE *)NULL) { sprintf(buf, E_fopen, orig_nntpfile, mode, errmsg(errno)); log(L_WARNING, buf); FCLOSE(Qfp); return; } if(!skip_to_pos(LOG_FILE)) { sprintf(buf, "Fatal error in create_nntp_file\n"); log(L_WARNING, buf); FCLOSE(Qfp); return; } } In_Log_File = TRUE; } if ((spoolfile = fopen(orig_nntpfile, mode)) == (FILE *)NULL) { sprintf(buf, E_fopen, orig_nntpfile, mode, errmsg(errno)); log(L_WARNING, buf); FCLOSE(Qfp); return; } spool_dir_length = strlen(SPOOL_DIR); while( fgets( logline, MAXLOGLENGTH, Qfp) != NULL) { strcpy(old_logline, logline); for (p = logline; *p && *p != '<'; p++) ; if( !*p || (*(p-2) != '-') && (strnindex(p, sysname, 0) != -1)) { for (i = 0; *p && *p != '>'; mesgid[i++] = *p, p++) ; mesgid[i++] = *p; /* put the '>' back on the end */ mesgid[i] = '\0'; strcpy(spool_entry, SPOOL_DIR); strcat(spool_entry, "/"); for (p += 2, i = spool_dir_length; *p && (*p != ' '); spool_entry[i++] = *p, p++); spool_entry[i++] = ' '; spool_entry[i] = '\0'; strcat(spool_entry, mesgid); fprintf(spoolfile, "%s\n", spool_entry); } } FCLOSE(spoolfile); FCLOSE(Qfp); }