[14047] in Athena Bugs

home help back first fref pref prev next nref lref last post

cleanup locking is somewhat broken

daemon@ATHENA.MIT.EDU (Greg Hudson)
Sun Dec 10 16:22:56 1995

Date: Sun, 10 Dec 1995 16:22:47 -0500
From: Greg Hudson <ghudson@MIT.EDU>
To: bugs@MIT.EDU

Here is the function in cleanup.c for locking /etc/ptmp or /etc/gtmp:

	int
	lock_file(fn)
	char *fn;
	{
	    int i, fd;

	    for (i = 0; i < 10; i++)
	      if ((fd = open(fn, O_RDWR | O_CREAT | O_EXCL, 0644)) == -1 &&
		  errno == EEXIST)
		sleep(1);
	      else
		break;
	    if (fd == -1) {
		if (i < 10)
		  fprintf(stderr, "cleanup: unable to lock passwd file: %s\n",
			  sys_errlist[errno]);
		else
		  (void) unlink(fn);
	    }
	    close(fd);
	}

There are two problems with this, neither of them extremely serious:

	1. In the case where the loop exits with fd == -1 and i == 10,
	   it unlinks the lock file and doesn't acquire it again;
	   thus, it exits without the file locked.  Since /etc/nologin
	   exists at this point, this isn't critical.

	2. In the case where the loop exits with fd == -1, it runs
	   close(-1).


home help back first fref pref prev next nref lref last post