-/*
- * Create a lock file for the named lock device
- */
-void lock()
- {
- int fd, pid;
-# ifdef PIDSTRING
- char hdb_lock_buffer[12];
-# endif
-
- lock_file = strcat(strcat(strcpy(malloc(strlen(LOCK_DIR)
- + 1 + strlen(lock_file) + 1),
- LOCK_DIR), "/"), lock_file);
-
- if ((fd = open(lock_file, O_EXCL | O_CREAT | O_RDWR, 0644)) < 0)
- {
- char *s = lock_file;
- lock_file = (char *)0; /* Don't remove someone else's lock file! */
- syslog(LOG_ERR, "Can't get lock file '%s': %m", s);
- die();
- }
-
-# ifdef PIDSTRING
- sprintf(hdb_lock_buffer, "%10d\n", getpid());
- write(fd, hdb_lock_buffer, 11);
-# else
- pid = getpid();
- write(fd, &pid, sizeof pid);
-# endif
-
- close(fd);
- }
-
-/*
- * Remove our lockfile
- */
-void unlock()
- {
- if (lock_file)
- {
- unlink(lock_file);
- lock_file = (char *)0;
- }
- }
-