- if ((af = fopen(aliasfile, "r+")) == NULL)
- {
- if (init)
- syserr("Can't open %s", aliasfile);
- else if (tTd(27, 1))
- printf("Can't open %s\n", aliasfile);
- errno = 0;
- NoAlias++;
- return;
- }
-
-# if defined(NDBM) || defined(NEWDB)
- /* see if someone else is rebuilding the alias file already */
-# ifdef LOCKF
- fld.l_type = F_WRLCK;
- fld.l_whence = fld.l_start = fld.l_len = 0;
- if (fcntl(fileno(af), F_SETLK, &fld) < 0)
-# else
- if (flock(fileno(af), LOCK_EX | LOCK_NB) < 0 && errno == EWOULDBLOCK)
-# endif
- {
- /* yes, they are -- wait until done and then return */
- message(Arpa_Info, "Alias file is already being rebuilt");
- if (OpMode != MD_INITALIAS)
- {
- /* wait for other rebuild to complete */
-# ifdef LOCKF
- (void) fcntl(fileno(af), F_SETLKW, &fld);
-# else
- (void) flock(fileno(af), LOCK_EX);
-# endif
- }
- (void) fclose(af);
- errno = 0;
- return;
- }
-# endif /* NDBM */
-
- /*
- ** If initializing, create the new DBM files.
- */
-
- if (init)
- {
- oldsigint = signal(SIGINT, SIG_IGN);
-# ifdef NEWDB
- (void) strcpy(line, aliasfile);
- (void) strcat(line, ".db");
- dbp = dbopen(line,
- O_RDWR|O_CREAT|O_TRUNC, DBMMODE, DB_HASH, NULL);
- if (dbp == NULL)
- {
- syserr("readaliases: cannot create %s", line);
- (void) signal(SIGINT, oldsigint);
- return;
- }
-# endif
-# ifdef IF_MAKEDBMFILES
-# ifdef NEWDB
- makedbmfiles = access("/var/yp/Makefile", R_OK) == 0;
-# endif
- IF_MAKEDBMFILES
- {
- dbmp = dbm_open(aliasfile,
- O_RDWR|O_CREAT|O_TRUNC, DBMMODE);
- if (dbmp == NULL)
- {
- syserr("readaliases: cannot create %s.{dir,pag}",
- aliasfile);
- (void) signal(SIGINT, oldsigint);
- return;
- }
- }
-# endif
- }
-