Lines Matching refs:lock

54  **     lock  - a lock file  (file + '.lock')
59 ** attemp to link 'lock' to 'temp'
60 ** if the link succeeds, we obtain the lock
64 ** unlink 'lock'
67 ** On Windows, 'lock' is a directory name. locking is equivalent to
76 const char* lock;
86 #define LOCK_NAME ".lock"
95 filelock_lock( FileLock* lock )
101 ret = mkdir( lock->lock );
104 D( "could not access directory '%s', check path elements", lock->lock );
107 D( "mkdir(%s): %s", lock->lock, strerror(errno) );
111 /* if we get here, it's because the .lock directory already exists */
113 D("directory '%s' already exist, waiting a bit to ensure that no other emulator instance is starting", lock->lock );
120 pidfile_fd = open( lock->temp, O_RDONLY );
131 D( "no pid file in '%s', assuming stale directory", lock->lock );
144 D( "could not read pid file '%s'", lock->temp );
183 D( "the file '%s' is locked by process ID %d\n", lock->file, lockpid );
190 pidfile_fd = open( lock->temp, O_WRONLY | O_CREAT | O_TRUNC );
193 if ( path_delete_file( lock->temp ) < 0 ) {
194 D( "could not remove '%s': %s\n", lock->temp, strerror(errno) );
197 pidfile_fd = open( lock->temp, O_WRONLY | O_CREAT | O_TRUNC );
200 D( "could not create '%s': %s\n", lock->temp, strerror(errno) );
211 D( "could not write PID to '%s'\n", lock->temp );
216 lock->locked = 1;
226 temp_fd = mkstemp(lock->temp);
229 D("Cannot create locking temp file '%s'", lock->temp);
236 D("Cannot write to locking temp file '%s'", lock->temp);
242 rc = HANDLE_EINTR(lstat(lock->temp, &st_temp));
244 D("Can't properly stat our locking temp file '%s'", lock->temp);
248 /* now attempt to link the temp file to the lock file */
257 D("Cannot acquire lock file '%s'", lock->lock);
266 rc = HANDLE_EINTR(link(lock->temp, lock->lock));
269 rc = HANDLE_EINTR(lstat(lock->lock, &st_lock));
278 lock->locked = 1;
279 rc = HANDLE_EINTR(unlink(lock->temp));
284 // The .lock file is a directory. This can only happen
288 "Stale Win32 lock file detected: %s\n",
289 lock->lock);
309 int lockfd = HANDLE_EINTR(open(lock->lock,O_RDONLY));
342 D("Removing stale lockfile '%s'", lock->lock);
343 rc = HANDLE_EINTR(unlink(lock->lock));
348 D("file '%s' is already in use by another process", lock->file);
363 HANDLE_EINTR(unlink(lock->lock));
364 HANDLE_EINTR(unlink(lock->temp));
370 filelock_release( FileLock* lock )
372 if (lock->locked) {
374 path_delete_file( (char*)lock->temp );
375 rmdir( (char*)lock->lock );
377 unlink( (char*)lock->lock );
379 lock->locked = 0;
386 FileLock* lock;
388 for (lock = _all_filelocks; lock != NULL; lock = lock->next)
389 filelock_release( lock );
392 /* create a file lock */
405 FileLock* lock = malloc(total_len);
407 lock->file = (const char*)(lock + 1);
408 memcpy( (char*)lock->file, file, file_len+1 );
410 lock->lock = lock->file + file_len + 1;
411 memcpy( (char*)lock->lock, file, file_len+1 );
412 strcat( (char*)lock->lock, LOCK_NAME );
414 lock->temp = (char*)lock->lock + lock_len + 1;
416 snprintf( (char*)lock->temp, temp_len, "%s\\" PIDFILE_NAME, lock->lock );
418 snprintf((char*)lock->temp, temp_len, "%s%s", lock->file, TEMP_NAME);
420 lock->locked = 0;
422 if (filelock_lock(lock) < 0) {
423 free(lock);
427 lock->next = _all_filelocks;
428 _all_filelocks = lock;
430 if (lock->next == NULL)
433 return lock;