leafnode  1.12.0
About: Leafnode is a store & forward NNTP proxy for small (dialup) sites.
  Fossies Dox: leafnode-1.12.0.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

checkgroups.c
Go to the documentation of this file.
1/*
2 * Checkgroups: script that updates the description of newsgroups
3 * Input file : a checkgroups script that contains the name of
4 * the newsgroup and its description in one line
5 *
6 * Written and copyrighted by Cornelius Krasel, April 1997
7 * Source code borrows a lot from fetch(1).
8 *
9 * Modified and Copyright of modifications 2001 - 2005 Matthias Andree
10 *
11 * See file COPYING for restrictions on the use of this software.
12 */
13
14#include "leafnode.h"
15#include "ln_log.h"
16
17#include <sys/types.h>
18#include <ctype.h>
19#include "system.h"
20#include <fcntl.h>
21#include <stdlib.h>
22#include <signal.h>
23#include <stdio.h>
24#include <string.h>
25#include <sys/stat.h>
26#include <sys/resource.h>
27#include <unistd.h>
28
29int debug = 0;
30int verbose = 0;
31
32static void
34{
35 FILE *f;
36 char *l;
37 static time_t now;
38
39 if (!now) now = time(NULL);
40
41 f = fopen(s, "r");
42 if (!f) {
43 fprintf(stderr, "cannot open %s: %s\n", s, strerror(errno));
44 return;
45 }
46
47 while ((l = getaline(f))) {
48 char *p;
49 struct newsgroup *g;
50
51 p = l;
52 if (isalnum((unsigned char)*p)) {
53 while (*p && !isspace((unsigned char)*p))
54 p++;
55 if (*p)
56 *p++ = '\0';
57 if ((g = findgroup(l)) != NULL) {
58 fprintf(stderr, "%s\n", l);
59 if (strlen(p) > 0) {
60 if (g->desc)
61 free(g->desc);
62 g->desc = critstrdup(p, "process_input");
63 }
64 } else {
65 fprintf(stderr, "%s NEW\n", l);
66 insertgroup(l, 1, 0, now);
67 if (*p)
68 newgroupdesc(l, p);
69 }
70 }
71 }
72
73 fclose(f);
75}
76
77int
78main(int argc, char *argv[])
79{
80 int fd;
81 myopenlog("checkgroups");
82
83 fd = open(".", O_RDONLY);
84 if (fd < 0) {
85 perror("checkgroups: cannot store cwd");
86 exit(EXIT_FAILURE);
87 }
88
89 if (!initvars(argv[0]))
90 exit(EXIT_FAILURE);
91
92 if (fchdir(fd)) {
93 perror("checkgroups: cannot restore cwd");
94 exit(EXIT_FAILURE);
95 }
96 (void)close(fd);
97
98 if (argc != 2) {
99 fprintf(stderr, "Usage: %s checkgroupsfile\n", argv[0]);
100 exit(1);
101 }
102
103 umask(2);
104
105 if (readconfig(0)) {
106 fprintf(stderr, "cannot read configuration.\n");
107 exit(EXIT_FAILURE);
108 }
109
110 if (try_lock(timeout_lock)) {
111 fprintf(stderr, "could not obtain lock.\n");
112 exit(EXIT_FAILURE);
113 }
114
115 readactive(); /* read groupinfo file */
116 if (!active)
117 fakeactive(); /* make sure we have up to date water marks for existing groups */
118 process_input(argv[1]);
119 if (writeactive()) ln_log(LNLOG_SERR, LNLOG_CTOP, "Error writing groupinfo.");
120 unlink(lockfile);
122 freegetaline();
123 exit(0);
124}
void readactive(void)
Definition: activutil.c:373
void fakeactive(void)
Definition: activutil.c:515
void freeactive(struct newsgroup *act)
Definition: activutil.c:351
void mergegroups(void)
Definition: activutil.c:162
struct newsgroup * findgroup(const char *name)
Definition: activutil.c:260
void insertgroup(const char *name, long unsigned first, long unsigned last, time_t age)
Definition: activutil.c:77
int writeactive(void)
Definition: activutil.c:269
struct newsgroup * active
Definition: activutil.c:40
void newgroupdesc(const char *groupname, const char *description)
Definition: activutil.c:124
int verbose
Definition: checkgroups.c:30
int main(int argc, char *argv[])
Definition: checkgroups.c:78
static void process_input(char *s)
Definition: checkgroups.c:33
int debug
Definition: checkgroups.c:29
unsigned long timeout_lock
Definition: configutil.c:92
int readconfig(int logtostderr)
Definition: configutil.c:208
char * critstrdup(const char *source, const char *message)
Definition: critmem.c:92
static time_t now
Definition: fetchnews.c:58
char * getaline(FILE *f)
Definition: getaline.c:84
void freegetaline(void)
Definition: getaline.c:89
void myopenlog(const char *ident)
Definition: syslog.c:24
int initvars(char *progname)
Definition: miscutil.c:143
const char * lockfile
int try_lock(unsigned long)
Definition: lockfile.c:200
void ln_log(int sev, int ctx, const char *format,...)
Definition: ln_log.c:103
#define LNLOG_SERR
Definition: ln_log.h:13
#define LNLOG_CTOP
Definition: ln_log.h:22
char * desc
Definition: leafnode.h:125