- register int i;
- register FILE *cf;
- register struct filed *f;
- register char *p;
- char cline[BUFSIZ];
- struct hostent *hp;
- int pmask, flags;
- long now;
- char *getpmask();
-
- dprintf("init\n");
-
- /* flush any pending output */
- flushmsg();
-
- /*
- * Close all open log files.
- */
- for (f = Files; f < &Files[NLOGS]; f++) {
- if (f->f_file >= 0)
- (void) close(f->f_file);
- f->f_file = -1;
- }
-
- /* open the configuration file */
- if ((cf = fopen(ConfFile, "r")) == NULL) {
- dprintf("cannot open %s\n", ConfFile);
- f = Files;
- if ((f->f_file = open(ctty, O_WRONLY)) >= 0) {
- strncpy(f->f_name, ctty, sizeof(f->f_name)-1);
- f->f_pmask = mask(LOG_CRIT);
- f->f_flags = F_TTY|F_MARK|F_CONS;
- untty();
- }
- return;
- }
-
- /*
- * Foreach line in the conf table, open that file.
- */
- f = Files;
- while (fgets(cline, sizeof cline, cf) != NULL) {
- /* check for end-of-section */
- if (cline[0] == '\n')
- break;
-
- /* strip off newline character */
- p = index(cline, '\n');
- if (p)
- *p = '\0';
-
- dprintf("F: got line '%s'\n", cline);
-
- /* extract priority mask and mark flag */
- p = cline;
- flags = 0;
- p = getpmask(p, &pmask);
- if (*p == '*') {
- p++;
- flags |= F_MARK;
- }
-
- if (f >= &Files[NLOGS])
- continue;
-
- /* mark entry as used and update flags */
- if (*p == '@') {
- if (!inet)
- continue;
- hp = gethostbyname(++p);
- if (hp == NULL) {
- char buf[100];
-
- sprintf(buf, "unknown host %s", p);
- errno = 0;
- logerror(buf);
- continue;
- }
- bzero(&f->f_addr, sizeof f->f_addr);
- f->f_addr.sin_family = AF_INET;
- f->f_addr.sin_port = port;
- bcopy(hp->h_addr, (char *) &f->f_addr.sin_addr, hp->h_length);
- f->f_file = socket(AF_INET, SOCK_DGRAM, 0);
- if (f->f_file < 0) {
- logerror("socket");
- continue;
- }
- flags |= F_FORW;
- f->f_pmask = pmask;
- f->f_flags = flags;
- dprintf("Host %s pmask %#x flags %#x\n", p, pmask, flags);
- f++;
- continue;
- }
- strncpy(f->f_name, p, sizeof(f->f_name)-1);
- if ((f->f_file = open(p, O_WRONLY|O_APPEND)) < 0) {
- logerror(p);
- continue;
- }
- if (isatty(f->f_file)) {
- flags |= F_TTY;
- untty();
- }
- if (strcmp(p, ctty) == 0)
- flags |= F_CONS;
- f->f_pmask = pmask;
- f->f_flags = flags;
- dprintf("File %s pmask %#x flags %#x\n", p, pmask, flags);
- f++;
- }
-
- /*
- * Read the list of users.
- *
- * Anyone in this list is informed directly if s/he
- * is logged in when a high priority message comes through.
- */
- Sumask = mask(KERN_EMERG)|mask(LOG_EMERG);
- for (i = 0; i < NSUSERS && fgets(cline, sizeof cline, cf) != NULL; i++) {
- /* strip off newline */
- p = index(cline, '\n');
- if (p)
- *p = '\0';
- dprintf("U: got line '%s'\n", cline);
- p = cline;
- if (isdigit(*p))
- p = getpmask(p, &pmask);
- else
- pmask = mask(LOG_SALERT);
- Susers[i].s_pmask = pmask;
- Sumask |= pmask;
- strncpy(Susers[i].s_name, p, UNAMESZ);
- dprintf("Suser %s pmask %#x\n", p, pmask);
- }
-
- /* zero the rest of the old superusers */
- while (i < NSUSERS)
- Susers[i++].s_name[0] = '\0';
-
- /* close the configuration file */
- (void) fclose(cf);
-
- dprintf("syslogd: restarted\n");