- int lockfd;
- char *filen = "/tmp/conftest.lock";
- char *resn = "test";
- int fd;
-
- for(fd = 3; fd < FD_SETSIZE; fd++) {
- /*
- * Make sure nobody spoofs us with a lot of extra open files
- * that would cause an open we do to get a very high file
- * descriptor, which in turn might be used as an index into
- * an array (e.g. an fd_set).
- */
- close(fd);
- }
-
- unlink(filen);
- if ((lockfd = open(filen, O_RDONLY|O_CREAT|O_EXCL, 0600)) == -1) {
- perror (filen);
- exit(10);
- }
-
- if (amroflock(lockfd, resn) != 0) {
- perror ("amroflock");
- exit(1);
- }
- if (amfunlock(lockfd, resn) != 0) {
- perror ("amfunlock/2");
- exit(2);
- }
-
- /*
- * Do not use aclose() here. During configure we do not have
- * areads_relbuf() available and it makes configure think all
- * the tests have failed.
- */
- close(lockfd);
-
- unlink(filen);
- if ((lockfd = open(filen, O_WRONLY|O_CREAT|O_EXCL, 0600)) == -1) {
- perror (filen);
- exit(20);
- }
-
- if (amflock(lockfd, resn) != 0) {
- perror ("amflock");
- exit(3);
- }
- if (amfunlock(lockfd, resn) != 0) {
- perror ("amfunlock/4");
- exit(4);
- }