~ubuntu-branches/ubuntu/precise/gnupg2/precise-proposed

« back to all changes in this revision

Viewing changes to jnlib/dotlock.c

  • Committer: Bazaar Package Importer
  • Author(s): Eric Dorland
  • Date: 2009-03-08 22:46:47 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090308224647-gq17gatcl71lrc2k
Tags: 2.0.11-1
* New upstream release. (Closes: #496663)
* debian/control: Make the description a little more distinctive than
  gnupg v1's. Thanks Jari Aalto. (Closes: #496323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* dotlock.c - dotfile locking
2
2
 * Copyright (C) 1998, 2000, 2001, 2003, 2004, 
3
 
 *               2005, 2006 Free Software Foundation, Inc.
 
3
 *               2005, 2006, 2008 Free Software Foundation, Inc.
4
4
 *
5
5
 * This file is part of JNLIB.
6
6
 *
25
25
#include <ctype.h>
26
26
#include <errno.h>
27
27
#include <unistd.h>
28
 
#ifndef  HAVE_DOSISH_SYSTEM
29
 
#include <sys/utsname.h>
 
28
#ifdef  HAVE_DOSISH_SYSTEM
 
29
# define WIN32_LEAN_AND_MEAN
 
30
# include <windows.h>
 
31
#else
 
32
# include <sys/utsname.h>
30
33
#endif
31
34
#include <sys/types.h>
32
35
#include <sys/time.h>
54
57
#endif
55
58
 
56
59
 
 
60
/* The object describing a lock.  */
57
61
struct dotlock_handle 
58
62
{
59
63
  struct dotlock_handle *next;
60
 
  char *tname;    /* Name of lockfile template.  */
 
64
  char *lockname;      /* Name of the actual lockfile.          */
 
65
  int locked;          /* Lock status.                          */
 
66
  int disable;         /* If true, locking is disabled.         */
 
67
 
 
68
#ifdef HAVE_DOSISH_SYSTEM
 
69
  HANDLE lockhd;       /* The W32 handle of the lock file.      */
 
70
#else
 
71
  char *tname;         /* Name of the lockfile template.        */
61
72
  size_t nodename_off; /* Offset in TNAME of the nodename part. */
62
 
  size_t nodename_len; /* Length of the nodename part. */
63
 
  char *lockname; /* Name of the real lockfile.  */
64
 
  int locked;     /* Lock status.  */
65
 
  int disable;    /* When true, locking is disabled.  */
 
73
  size_t nodename_len; /* Length of the nodename part.          */
 
74
#endif /* HAVE_DOSISH_SYSTEM */
66
75
};
67
76
 
68
77
 
 
78
/* A list of of all lock handles. */
69
79
static volatile DOTLOCK all_lockfiles;
 
80
 
 
81
/* If this has the value true all locking is disabled.  */
70
82
static int never_lock;
71
83
 
 
84
 
 
85
/* Local protototypes.  */
 
86
#ifndef HAVE_DOSISH_SYSTEM
72
87
static int read_lockfile (DOTLOCK h, int *same_node);
73
 
 
 
88
#endif /*!HAVE_DOSISH_SYSTEM*/
 
89
 
 
90
 
 
91
 
 
92
 
 
93
/* Entirely disable all locking.  This function should be called
 
94
   before any locking is done.  It may be called right at startup of
 
95
   the process as it only sets a global value.  */
74
96
void
75
97
disable_dotlock(void)
76
98
{
77
99
  never_lock = 1;
78
100
}
79
101
 
80
 
/****************
81
 
 * Create a lockfile with the given name and return an object of
82
 
 * type DOTLOCK which may be used later to actually do the lock.
83
 
 * A cleanup routine gets installed to cleanup left over locks
84
 
 * or other files used together with the lock mechanism.
85
 
 * Although the function is called dotlock, this does not necessarily
86
 
 * mean that real lockfiles are used - the function may decide to
87
 
 * use fcntl locking.  Calling the function with NULL only install
88
 
 * the atexit handler and maybe used to assure that the cleanup
89
 
 * is called after all other atexit handlers.
90
 
 *
91
 
 * Notes: This function creates a lock file in the same directory
92
 
 *        as file_to_lock with the name "file_to_lock.lock"
93
 
 *        A temporary file ".#lk.<hostname>.pid[.threadid] is used.
94
 
 *        This function does nothing for Windoze.
 
102
 
 
103
 
 
104
/* Create a lockfile for a file name FILE_TO_LOCK and returns an
 
105
   object of type DOTLOCK which may be used later to actually acquire
 
106
   the lock.  A cleanup routine gets installed to cleanup left over
 
107
   locks or other files used internally by the lock mechanism.
 
108
 
 
109
   Calling this function with NULL does only install the atexit
 
110
   handler and may thus be used to assure that the cleanup is called
 
111
   after all other atexit handlers.
 
112
  
 
113
   This function creates a lock file in the same directory as
 
114
   FILE_TO_LOCK using that name and a suffix of ".lock".  Note that on
 
115
   POSIX systems a temporary file ".#lk.<hostname>.pid[.threadid] is
 
116
   used.
 
117
 
 
118
   The function returns an new handle which needs to be released using
 
119
   destroy_dotlock but gets also released at the termination of the
 
120
   process.  On error NULL is returned.
95
121
 */
96
122
DOTLOCK
97
 
create_dotlock( const char *file_to_lock )
 
123
create_dotlock (const char *file_to_lock)
98
124
{
99
125
  static int initialized;
100
126
  DOTLOCK h;
 
127
#ifndef  HAVE_DOSISH_SYSTEM
101
128
  int  fd = -1;
102
129
  char pidstr[16];
103
130
  const char *nodename;
104
131
  const char *dirpart;
105
132
  int dirpartlen;
106
 
#ifndef  HAVE_DOSISH_SYSTEM
107
133
  struct utsname utsbuf;
 
134
  size_t tnamelen;
108
135
#endif
109
136
 
110
137
  if ( !initialized )
111
138
    {
112
 
      atexit( dotlock_remove_lockfiles );
 
139
      atexit (dotlock_remove_lockfiles);
113
140
      initialized = 1;
114
141
    }
 
142
 
115
143
  if ( !file_to_lock )
116
144
    return NULL;  /* Only initialization was requested.  */
117
145
 
118
 
  h = jnlib_xcalloc ( 1, sizeof *h );
119
 
  if( never_lock )
 
146
  h = jnlib_calloc (1, sizeof *h);
 
147
  if (!h)
 
148
    return NULL;
 
149
 
 
150
  if (never_lock)
120
151
    {
121
152
      h->disable = 1;
122
153
#ifdef _REENTRANT
128
159
    }
129
160
 
130
161
#ifndef HAVE_DOSISH_SYSTEM
131
 
  sprintf (pidstr, "%10d\n", (int)getpid() );
 
162
  /*
 
163
     This is the POSIX version which uses a temporary file and the
 
164
     link system call to make locking an atomic operation.
 
165
   */
 
166
 
 
167
  snprintf (pidstr, sizeof pidstr, "%10d\n", (int)getpid() );
132
168
  /* fixme: add the hostname to the second line (FQDN or IP addr?) */
133
169
 
134
170
  /* Create a temporary file. */
146
182
  }
147
183
#endif /* __riscos__ */
148
184
 
149
 
  if ( !(dirpart = strrchr ( file_to_lock, DIRSEP_C )) )
 
185
  if ( !(dirpart = strrchr (file_to_lock, DIRSEP_C)) )
150
186
    {
151
187
      dirpart = EXTSEP_S;
152
188
      dirpartlen = 1;
163
199
  h->next = all_lockfiles;
164
200
  all_lockfiles = h;
165
201
 
166
 
  h->tname = jnlib_xmalloc ( dirpartlen + 6+30+ strlen(nodename) + 11 );
 
202
  tnamelen = dirpartlen + 6 + 30 + strlen(nodename) + 10;
 
203
  h->tname = jnlib_malloc (tnamelen + 1);
 
204
  if (!h->tname)
 
205
    {
 
206
      all_lockfiles = h->next;
 
207
      jnlib_free (h);
 
208
      return NULL;
 
209
    }
167
210
  h->nodename_len = strlen (nodename);
 
211
 
168
212
#ifndef __riscos__
169
 
  sprintf (h->tname, "%.*s/.#lk%p.", dirpartlen, dirpart, h );
 
213
  snprintf (h->tname, tnamelen, "%.*s/.#lk%p.", dirpartlen, dirpart, h );
170
214
  h->nodename_off = strlen (h->tname);
171
 
  sprintf (h->tname+h->nodename_off, "%s.%d", nodename, (int)getpid ());
 
215
  snprintf (h->tname+h->nodename_off, tnamelen - h->nodename_off,
 
216
           "%s.%d", nodename, (int)getpid ());
172
217
#else /* __riscos__ */
173
 
  sprintf (h->tname, "%.*s.lk%p/", dirpartlen, dirpart, h );
 
218
  snprintf (h->tname, tnamelen, "%.*s.lk%p/", dirpartlen, dirpart, h );
174
219
  h->nodename_off = strlen (h->tname);
175
 
  sprintf (h->tname+h->nodename_off, "%s/%d", nodename, (int)getpid () );
 
220
  snprintf (h->tname+h->nodename_off, tnamelen - h->modename_off,
 
221
            "%s/%d", nodename, (int)getpid () );
176
222
#endif /* __riscos__ */
177
223
 
178
224
  do 
186
232
  if ( fd == -1 ) 
187
233
    {
188
234
      all_lockfiles = h->next;
189
 
      log_error ( "failed to create temporary file `%s': %s\n",
 
235
      log_error (_("failed to create temporary file `%s': %s\n"),
190
236
                  h->tname, strerror(errno));
191
 
      jnlib_free(h->tname);
192
 
      jnlib_free(h);
 
237
      jnlib_free (h->tname);
 
238
      jnlib_free (h);
193
239
      return NULL;
194
240
    }
195
241
  if ( write (fd, pidstr, 11 ) != 11 )
204
250
# ifdef _REENTRANT
205
251
  /* release mutex */
206
252
# endif
207
 
#endif /* !HAVE_DOSISH_SYSTEM */
208
 
  h->lockname = jnlib_xmalloc ( strlen (file_to_lock) + 6 );
209
 
  strcpy (stpcpy(h->lockname, file_to_lock), EXTSEP_S "lock");
 
253
  h->lockname = jnlib_malloc ( strlen (file_to_lock) + 6 );
 
254
  if (!h->lockname)
 
255
    {
 
256
      all_lockfiles = h->next;
 
257
      unlink (h->tname);
 
258
      jnlib_free (h->tname);
 
259
      jnlib_free (h);
 
260
      return NULL;
 
261
    }
 
262
  strcpy (stpcpy (h->lockname, file_to_lock), EXTSEP_S "lock");
210
263
  return h;
 
264
 
211
265
 write_failed:
212
266
  all_lockfiles = h->next;
213
267
# ifdef _REENTRANT
214
268
  /* fixme: release mutex */
215
269
# endif
216
 
  log_error ( "error writing to `%s': %s\n", h->tname, strerror(errno) );
217
 
  close(fd);
218
 
  unlink(h->tname);
219
 
  jnlib_free(h->tname);
220
 
  jnlib_free(h);
 
270
  log_error ( _("error writing to `%s': %s\n"), h->tname, strerror(errno) );
 
271
  close (fd);
 
272
  unlink (h->tname);
 
273
  jnlib_free (h->tname);
 
274
  jnlib_free (h);
221
275
  return NULL;
 
276
 
 
277
#else /* HAVE_DOSISH_SYSTEM */
 
278
 
 
279
  /* The Windows version does not need a temporary file but uses the
 
280
     plain lock file along with record locking.  We create this file
 
281
     here so that we later do only need to do the file locking.  For
 
282
     error reporting it is useful to keep the name of the file in the
 
283
     handle.  */
 
284
  h->next = all_lockfiles;
 
285
  all_lockfiles = h;
 
286
 
 
287
  h->lockname = jnlib_malloc ( strlen (file_to_lock) + 6 );
 
288
  if (!h->lockname)
 
289
    {
 
290
      all_lockfiles = h->next;
 
291
      jnlib_free (h);
 
292
      return NULL;
 
293
    }
 
294
  strcpy (stpcpy(h->lockname, file_to_lock), EXTSEP_S "lock");
 
295
 
 
296
  /* If would be nice if we would use the FILE_FLAG_DELETE_ON_CLOSE
 
297
     along with FILE_SHARE_DELETE but that does not work due to a race
 
298
     condition: Despite the OPEN_ALWAYS flag CreateFile may return an
 
299
     error and we can't reliable create/open the lock file unless we
 
300
     would wait here until it works - however there are other valid
 
301
     reasons why a lock file can't be created and thus the process
 
302
     would not stop as expected but spin til until Windows crashes.
 
303
     Our solution is to keep the lock file open; that does not
 
304
     harm. */ 
 
305
  h->lockhd = CreateFile (h->lockname,
 
306
                          GENERIC_READ|GENERIC_WRITE,
 
307
                          FILE_SHARE_READ|FILE_SHARE_WRITE,
 
308
                          NULL, OPEN_ALWAYS, 0, NULL);
 
309
  if (h->lockhd == INVALID_HANDLE_VALUE)
 
310
    {
 
311
      log_error (_("can't create `%s': %s\n"), h->lockname, w32_strerror (-1));
 
312
      all_lockfiles = h->next;
 
313
      jnlib_free (h->lockname);
 
314
      jnlib_free (h);
 
315
      return NULL;
 
316
    }
 
317
  return h;
 
318
 
 
319
#endif /* HAVE_DOSISH_SYSTEM */
222
320
}
223
321
 
224
322
 
 
323
/* Destroy the local handle H and release the lock. */
225
324
void
226
325
destroy_dotlock ( DOTLOCK h )
227
326
{
228
 
#ifndef HAVE_DOSISH_SYSTEM
229
 
  if ( h )
 
327
  DOTLOCK hprev, htmp;
 
328
 
 
329
  if ( !h )
 
330
    return;
 
331
 
 
332
  /* First remove the handle from our global list of all locks. */
 
333
  for (hprev=NULL, htmp=all_lockfiles; htmp; hprev=htmp, htmp=htmp->next)
 
334
    if (htmp == h)
 
335
      {
 
336
        if (hprev)
 
337
          hprev->next = htmp->next;
 
338
        else
 
339
          all_lockfiles = htmp->next;
 
340
        h->next = NULL;
 
341
        break;
 
342
      }
 
343
  
 
344
  /* Then destroy the lock. */
 
345
  if (!h->disable)
230
346
    {
231
 
      DOTLOCK hprev, htmp;
232
 
      
233
 
      /* First remove the handle from our global list of all locks. */
234
 
      for (hprev=NULL, htmp=all_lockfiles; htmp; hprev=htmp, htmp=htmp->next)
235
 
        if (htmp == h)
236
 
          {
237
 
            if (hprev)
238
 
              hprev->next = htmp->next;
239
 
            else
240
 
              all_lockfiles = htmp->next;
241
 
            h->next = NULL;
242
 
            break;
243
 
          }
244
 
      
245
 
      /* Second destroy the lock. */
246
 
      if (!h->disable)
 
347
#ifdef HAVE_DOSISH_SYSTEM
 
348
      if (h->locked)
247
349
        {
248
 
          if (h->locked && h->lockname)
249
 
            unlink (h->lockname);
250
 
          if (h->tname)
251
 
              unlink (h->tname);
252
 
          jnlib_free (h->tname);
253
 
          jnlib_free (h->lockname);
 
350
          UnlockFile (h->lockhd, 0, 0, 1, 0);
254
351
        }
255
 
      jnlib_free(h);
 
352
      CloseHandle (h->lockhd);
 
353
#else /* !HAVE_DOSISH_SYSTEM */
 
354
      if (h->locked && h->lockname)
 
355
        unlink (h->lockname);
 
356
      if (h->tname)
 
357
        unlink (h->tname);
 
358
      jnlib_free (h->tname);
 
359
#endif /* HAVE_DOSISH_SYSTEM */
 
360
      jnlib_free (h->lockname);
256
361
    }
257
 
#endif /*!HAVE_DOSISH_SYSTEM*/
 
362
  jnlib_free(h);
258
363
}
259
364
 
260
365
 
261
 
 
 
366
#ifndef HAVE_DOSISH_SYSTEM
262
367
static int
263
368
maybe_deadlock( DOTLOCK h )
264
369
{
271
376
    }
272
377
  return 0;
273
378
}
274
 
 
275
 
/****************
276
 
 * Do a lock on H. A TIMEOUT of 0 returns immediately, -1 waits
277
 
 * forever (hopefully not), other values are reserved (should then be
278
 
 * timeouts in milliseconds).  Returns: 0 on success
279
 
 */
 
379
#endif /*!HAVE_DOSISH_SYSTEM*/
 
380
 
 
381
 
 
382
 
 
383
/* Do a lock on H. A TIMEOUT of 0 returns immediately, -1 waits
 
384
   forever (hopefully not), other values are reserved (should then be
 
385
   timeouts in milliseconds).  Returns: 0 on success  */
280
386
int
281
 
make_dotlock( DOTLOCK h, long timeout )
 
387
make_dotlock ( DOTLOCK h, long timeout )
282
388
{
283
 
#ifdef HAVE_DOSISH_SYSTEM
284
 
  return 0;
285
 
#else
 
389
  int backoff = 0;
 
390
#ifndef HAVE_DOSISH_SYSTEM
286
391
  int  pid;
287
392
  const char *maybe_dead="";
288
 
  int backoff=0;
289
393
  int same_node;
 
394
#endif /*!HAVE_DOSISH_SYSTEM*/
290
395
 
291
396
  if ( h->disable )
292
397
    return 0; /* Locks are completely disabled.  Return success. */
294
399
  if ( h->locked ) 
295
400
    {
296
401
#ifndef __riscos__
297
 
      log_debug("oops, `%s' is already locked\n", h->lockname );
 
402
      log_debug ("Oops, `%s' is already locked\n", h->lockname);
298
403
#endif /* !__riscos__ */
299
404
      return 0;
300
405
    }
301
406
 
302
 
  for(;;)
 
407
  for (;;)
303
408
    {
304
 
#ifndef __riscos__
 
409
#ifndef HAVE_DOSISH_SYSTEM
 
410
# ifndef __riscos__
305
411
      if ( !link(h->tname, h->lockname) )
306
412
        {
307
413
          /* fixme: better use stat to check the link count */
310
416
        }
311
417
      if ( errno != EEXIST )
312
418
        {
313
 
          log_error( "lock not made: link() failed: %s\n", strerror(errno) );
 
419
          log_error ( "lock not made: link() failed: %s\n", strerror(errno) );
314
420
          return -1;
315
421
        }
316
 
#else /* __riscos__ */
 
422
# else /* __riscos__ */
317
423
      if ( !renamefile(h->tname, h->lockname) ) 
318
424
        {
319
425
          h->locked = 1;
324
430
          log_error( "lock not made: rename() failed: %s\n", strerror(errno) );
325
431
          return -1;
326
432
        }
327
 
#endif /* __riscos__ */
 
433
# endif /* __riscos__ */
328
434
 
329
435
      if ( (pid = read_lockfile (h, &same_node)) == -1 ) 
330
436
        {
344
450
        }
345
451
      else if ( same_node && kill (pid, 0) && errno == ESRCH )
346
452
        {
347
 
#ifndef __riscos__
348
 
          log_info ("removing stale lockfile (created by %d)", pid );
 
453
# ifndef __riscos__
 
454
          log_info (_("removing stale lockfile (created by %d)\n"), pid );
349
455
          unlink (h->lockname);
350
456
          continue;
351
 
#else /* __riscos__ */
 
457
# else /* __riscos__ */
352
458
          /* Under RISCOS we are *pretty* sure that the other task
353
459
             is dead and therefore we remove the stale lock file. */
354
 
          maybe_dead = " - probably dead - removing lock";
 
460
          maybe_dead = _(" - probably dead - removing lock");
355
461
          unlink(h->lockname);
356
 
#endif /* __riscos__ */
 
462
# endif /* __riscos__ */
357
463
        }
358
464
 
359
465
      if ( timeout == -1 ) 
361
467
          /* Wait until lock has been released. */
362
468
          struct timeval tv;
363
469
          
364
 
          log_info ("waiting for lock (held by %d%s) %s...\n",
365
 
                    pid, maybe_dead, maybe_deadlock(h)? "(deadlock?) ":"");
 
470
          log_info (_("waiting for lock (held by %d%s) %s...\n"),
 
471
                    pid, maybe_dead, maybe_deadlock(h)? _("(deadlock?) "):"");
366
472
 
367
473
 
368
474
          /* We can't use sleep, cause signals may be blocked. */
374
480
        }
375
481
      else
376
482
        return -1;
 
483
#else /*HAVE_DOSISH_SYSTEM*/
 
484
      int w32err;
 
485
 
 
486
      if (LockFile (h->lockhd, 0, 0, 1, 0))
 
487
        {
 
488
          h->locked = 1;
 
489
          return 0; /* okay */
 
490
        }
 
491
      w32err = GetLastError ();
 
492
      if (w32err != ERROR_LOCK_VIOLATION)
 
493
        {
 
494
          log_error (_("lock `%s' not made: %s\n"),
 
495
                     h->lockname, w32_strerror (w32err));
 
496
          return -1;
 
497
        }
 
498
 
 
499
      if ( timeout == -1 ) 
 
500
        {
 
501
          /* Wait until lock has been released. */
 
502
          log_info (_("waiting for lock %s...\n"), h->lockname);
 
503
          Sleep ((1 + backoff)*1000);
 
504
          if ( backoff < 10 )
 
505
            backoff++ ;
 
506
        }
 
507
      else
 
508
        return -1;
 
509
#endif /*HAVE_DOSISH_SYSTEM*/
377
510
    }
378
 
    /*NOTREACHED*/
379
 
#endif /* !HAVE_DOSISH_SYSTEM */
 
511
  /*NOTREACHED*/
380
512
}
381
513
 
382
514
 
383
 
/****************
384
 
 * release a lock
385
 
 * Returns: 0 := success
386
 
 */
 
515
/* Release a lock.  Returns 0 on success.  */
387
516
int
388
517
release_dotlock( DOTLOCK h )
389
518
{
390
 
#ifdef HAVE_DOSISH_SYSTEM
391
 
  return 0;
392
 
#else
 
519
#ifndef HAVE_DOSISH_SYSTEM
393
520
  int pid, same_node;
 
521
#endif
394
522
 
395
523
  /* To avoid atexit race conditions we first check whether there are
396
524
     any locks left.  It might happen that another atexit handler
404
532
 
405
533
  if ( !h->locked )
406
534
    {
407
 
      log_debug("oops, `%s' is not locked\n", h->lockname );
 
535
      log_debug("Oops, `%s' is not locked\n", h->lockname);
408
536
      return 0;
409
537
    }
410
538
 
 
539
#ifdef HAVE_DOSISH_SYSTEM
 
540
  if (!UnlockFile (h->lockhd, 0, 0, 1, 0))
 
541
    {
 
542
      log_error ("release_dotlock: error removing lockfile `%s': %s\n",
 
543
                 h->lockname, w32_strerror (-1));
 
544
      return -1;
 
545
    }
 
546
#else
 
547
 
411
548
  pid = read_lockfile (h, &same_node);
412
549
  if ( pid == -1 ) 
413
550
    {
419
556
      log_error( "release_dotlock: not our lock (pid=%d)\n", pid);
420
557
      return -1;
421
558
    }
 
559
 
422
560
#ifndef __riscos__
423
561
  if ( unlink( h->lockname ) )
424
562
    {
425
 
      log_error( "release_dotlock: error removing lockfile `%s'",
 
563
      log_error ("release_dotlock: error removing lockfile `%s'\n",
426
564
                 h->lockname);
427
565
      return -1;
428
566
    }
 
567
  /* Fixme: As an extra check we could check whether the link count is
 
568
     now really at 1. */
429
569
#else /* __riscos__ */
430
 
  if ( renamefile(h->lockname, h->tname) ) 
 
570
  if ( renamefile (h->lockname, h->tname) ) 
431
571
    {
432
 
      log_error( "release_dotlock: error renaming lockfile `%s' to `%s'",
 
572
      log_error ("release_dotlock: error renaming lockfile `%s' to `%s'\n",
433
573
                 h->lockname, h->tname);
434
574
      return -1;
435
575
    }
436
576
#endif /* __riscos__ */
437
 
  /* fixme: check that the link count is now 1 */
 
577
 
 
578
#endif /* !HAVE_DOSISH_SYSTEM */
438
579
  h->locked = 0;
439
580
  return 0;
440
 
#endif /* !HAVE_DOSISH_SYSTEM */
441
581
}
442
582
 
443
583
 
444
 
/*
445
 
   Read the lock file and return the pid, returns -1 on error.  True
446
 
   will be stored at SAME_NODE if the lock file has been created on
447
 
   the same node.
448
 
 */
 
584
/* Read the lock file and return the pid, returns -1 on error.  True
 
585
   will be stored in the integer at address SAME_NODE if the lock file
 
586
   has been created on the same node. */
 
587
#ifndef HAVE_DOSISH_SYSTEM
449
588
static int
450
589
read_lockfile (DOTLOCK h, int *same_node )
451
590
{
452
 
#ifdef HAVE_DOSISH_SYSTEM
453
 
  return 0;
454
 
#else
455
591
  char buffer_space[10+1+70+1]; /* 70 is just an estimated value; node
456
592
                                   name are usually shorter. */
457
593
  int fd;
505
641
      log_info ("invalid size of lockfile `%s'", h->lockname );
506
642
      if (buffer != buffer_space)
507
643
        jnlib_free (buffer);
508
 
      errno = 0; /* Do not return an inappropriate ERRNO. */
 
644
      errno = 0; /* Better don't return an inappropriate ERRNO. */
509
645
      return -1;
510
646
    }
511
647
 
533
669
  if (buffer != buffer_space)
534
670
    jnlib_free (buffer);
535
671
  return pid;
536
 
#endif
537
672
}
538
 
 
539
 
 
 
673
#endif /* !HAVE_DOSISH_SYSTEM */
 
674
 
 
675
 
 
676
/* Remove all lockfiles.  This is usually called by the atexit handler
 
677
   installed by this module but may also be called by other
 
678
   termination handlers.  */
540
679
void
541
680
dotlock_remove_lockfiles()
542
681
{
543
 
#ifndef HAVE_DOSISH_SYSTEM
544
682
  DOTLOCK h, h2;
545
683
  
546
684
  h = all_lockfiles;
552
690
      destroy_dotlock (h);
553
691
      h = h2;
554
692
    }
555
 
#endif
556
693
}
557
694