Home | History | Annotate | Download | only in utils

Lines Matching full:lock

55  **     lock  - a lock file  (file + '.lock')
60 ** attemp to link 'lock' to 'temp'
61 ** if the link succeeds, we obtain the lock
65 ** unlink 'lock'
68 ** 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 strcpy( lock->temp, lock->file );
227 strcat( lock->temp, TEMP_NAME );
228 temp_fd = mkstemp( lock->temp );
231 D("cannot create locking temp file '%s'", lock->temp );
238 D( "cannot write to locking temp file '%s'", lock->temp);
244 CHECKED(rc, lstat( lock->temp, &st_temp ));
246 D( "can't properly stat our locking temp file '%s'", lock->temp );
250 /* now attempt to link the temp file to the lock file */
259 D( "cannot acquire lock file '%s'", lock->lock );
267 CHECKED(rc, link( lock->temp, lock->lock ));
269 CHECKED(rc, lstat( lock->lock, &st_lock ));
275 lock->locked = 1;
276 CHECKED(rc, unlink( lock->temp ));
293 CHECKED(lockfd, open( lock->lock,O_RDONLY ));
322 D( "removing stale lockfile '%s'", lock->lock );
323 CHECKED(rc, unlink( lock->lock ));
329 D("file '%s' is already in use by another process", lock->file );
343 unlink( lock->lock );
344 unlink( lock->temp );
350 filelock_release( FileLock* lock )
352 if (lock->locked) {
354 path_delete_file( (char*)lock->temp );
355 rmdir( (char*)lock->lock );
357 unlink( (char*)lock->lock );
359 lock->locked = 0;
366 FileLock* lock;
368 for (lock = _all_filelocks; lock != NULL; lock = lock->next)
369 filelock_release( lock );
372 /* create a file lock */
385 FileLock* lock = malloc(total_len);
387 lock->file = (const char*)(lock + 1);
388 memcpy( (char*)lock->file, file, file_len+1 );
390 lock->lock = lock->file + file_len + 1;
391 memcpy( (char*)lock->lock, file, file_len+1 );
392 strcat( (char*)lock->lock, LOCK_NAME );
394 lock->temp = (char*)lock->lock + lock_len + 1;
396 snprintf( (char*)lock->temp, temp_len, "%s\\" PIDFILE_NAME, lock->lock );
398 lock->temp[0] = 0;
400 lock->locked = 0;
402 if (filelock_lock(lock) < 0) {
403 free(lock);
407 lock->next = _all_filelocks;
408 _all_filelocks = lock;
410 if (lock->next == NULL)
413 return lock;