(open_archive): Replace using label 'again' with a loop to work around gcc 3.2 bug.

This commit is contained in:
Ulrich Drepper 2002-08-28 12:00:53 +00:00
parent 9cce206e72
commit 1099624912
2 changed files with 53 additions and 48 deletions

View File

@ -1 +1 @@
linuxthreads-0.9 by Xavier Leroy linuxthreads-0.10 by Xavier Leroy

View File

@ -417,69 +417,74 @@ open_archive (struct locarhandle *ah, bool readonly)
memcpy (archivefname, output_prefix, prefix_len); memcpy (archivefname, output_prefix, prefix_len);
strcpy (archivefname + prefix_len, ARCHIVE_NAME); strcpy (archivefname + prefix_len, ARCHIVE_NAME);
again: while (1)
/* Open the archive. We must have exclusive write access. */
fd = open64 (archivefname, readonly ? O_RDONLY : O_RDWR);
if (fd == -1)
{ {
/* Maybe the file does not yet exist. */ /* Open the archive. We must have exclusive write access. */
if (errno == ENOENT) fd = open64 (archivefname, readonly ? O_RDONLY : O_RDWR);
if (fd == -1)
{ {
if (readonly) /* Maybe the file does not yet exist. */
if (errno == ENOENT)
{ {
static const struct locarhead nullhead = if (readonly)
{ {
.namehash_used = 0, static const struct locarhead nullhead =
.namehash_offset = 0, {
.namehash_size = 0 .namehash_used = 0,
}; .namehash_offset = 0,
.namehash_size = 0
};
ah->addr = (void *) &nullhead; ah->addr = (void *) &nullhead;
ah->fd = -1; ah->fd = -1;
}
else
create_archive (archivefname, ah);
return;
} }
else else
create_archive (archivefname, ah); error (EXIT_FAILURE, errno, _("cannot open locale archive \"%s\""),
archivefname);
return;
} }
else
error (EXIT_FAILURE, errno, _("cannot open locale archive \"%s\""), if (fstat64 (fd, &st) < 0)
error (EXIT_FAILURE, errno, _("cannot stat locale archive \"%s\""),
archivefname); archivefname);
}
if (fstat64 (fd, &st) < 0) if (!readonly && lockf64 (fd, F_LOCK, sizeof (struct locarhead)) == -1)
error (EXIT_FAILURE, errno, _("cannot stat locale archive \"%s\""),
archivefname);
if (!readonly && lockf64 (fd, F_LOCK, sizeof (struct locarhead)) == -1)
{
close (fd);
if (retry++ < max_locarchive_open_retry)
{ {
struct timespec req; close (fd);
/* Wait for a bit. */ if (retry++ < max_locarchive_open_retry)
req.tv_sec = 0; {
req.tv_nsec = 1000000 * (random () % 500 + 1); struct timespec req;
(void) nanosleep (&req, NULL);
goto again; /* Wait for a bit. */
req.tv_sec = 0;
req.tv_nsec = 1000000 * (random () % 500 + 1);
(void) nanosleep (&req, NULL);
continue;
}
error (EXIT_FAILURE, errno, _("cannot lock locale archive \"%s\""),
archivefname);
} }
error (EXIT_FAILURE, errno, _("cannot lock locale archive \"%s\""), /* One more check. Maybe another process replaced the archive file
archivefname); with a new, larger one since we opened the file. */
} if (stat64 (archivefname, &st2) == -1
|| st.st_dev != st2.st_dev
|| st.st_ino != st2.st_ino)
{
(void) lockf64 (fd, F_ULOCK, sizeof (struct locarhead));
close (fd);
continue;
}
/* One more check. Maybe another process replaced the archive file /* Leave the loop. */
with a new, larger one since we opened the file. */ break;
if (stat64 (archivefname, &st2) == -1
|| st.st_dev != st2.st_dev
|| st.st_ino != st2.st_ino)
{
(void) lockf64 (fd, F_ULOCK, sizeof (struct locarhead));
close (fd);
goto again;
} }
/* Read the header. */ /* Read the header. */