diff options
Diffstat (limited to 'catgets')
-rw-r--r-- | catgets/catgets.c | 6 | ||||
-rw-r--r-- | catgets/catgetsinfo.h | 7 | ||||
-rw-r--r-- | catgets/gencat.c | 4 | ||||
-rw-r--r-- | catgets/open_catalog.c | 28 |
4 files changed, 32 insertions, 13 deletions
diff --git a/catgets/catgets.c b/catgets/catgets.c index 4c6997e..d5eefc9 100644 --- a/catgets/catgets.c +++ b/catgets/catgets.c @@ -87,7 +87,7 @@ catopen (const char *cat_name, int flag) if (nlspath != NULL && *nlspath != '\0') { /* Append the system dependent directory. */ - size_t len = strlen (nlspath + 1 + sizeof NLSPATH); + size_t len = strlen (nlspath) + 1 + sizeof NLSPATH; char *tmp = alloca (len); __stpcpy (__stpcpy (__stpcpy (tmp, nlspath), ":"), NLSPATH); @@ -111,6 +111,8 @@ catopen (const char *cat_name, int flag) result->nlspath = NULL; } + __libc_lock_init (result->lock); + return (nl_catd) result; } @@ -130,7 +132,7 @@ catgets (nl_catd catalog_desc, int set, int message, const char *string) catalog = (__nl_catd) catalog_desc; if (catalog->status == closed) - __open_catalog (catalog, 1); + __open_catalog (catalog); if (catalog->status == nonexisting) { diff --git a/catgets/catgetsinfo.h b/catgets/catgetsinfo.h index 292572d..edb1099 100644 --- a/catgets/catgetsinfo.h +++ b/catgets/catgetsinfo.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1996 Free Software Foundation, Inc. +/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>. @@ -18,6 +18,7 @@ Boston, MA 02111-1307, USA. */ #include <sys/types.h> +#include <bits/libc-lock.h> struct catalog_obj @@ -47,6 +48,8 @@ typedef struct catalog_info struct catalog_obj *file_ptr; size_t file_size; + + __libc_lock_define (,lock); } *__nl_catd; @@ -56,4 +59,4 @@ typedef struct catalog_info /* Prototypes for helper functions. */ -void __open_catalog (__nl_catd __catalog, int __with_path); +void __open_catalog (__nl_catd __catalog); diff --git a/catgets/gencat.c b/catgets/gencat.c index 9ce962c..8d310d8 100644 --- a/catgets/gencat.c +++ b/catgets/gencat.c @@ -988,9 +988,11 @@ read_old (struct catalog *catalog, const char *file_name) old_cat_obj.status = closed; old_cat_obj.cat_name = file_name; + old_cat_obj.nlspath = NULL; + __libc_lock_init (old_cat_obj.lock); /* Try to open catalog, but don't look through the NLSPATH. */ - __open_catalog (&old_cat_obj, 0); + __open_catalog (&old_cat_obj); if (old_cat_obj.status != mmapped && old_cat_obj.status != malloced) if (errno == ENOENT) diff --git a/catgets/open_catalog.c b/catgets/open_catalog.c index 2c1cbb4..62fb111 100644 --- a/catgets/open_catalog.c +++ b/catgets/open_catalog.c @@ -33,14 +33,22 @@ void -__open_catalog (__nl_catd catalog, int with_path) +__open_catalog (__nl_catd catalog) { int fd; struct stat st; int swapping; - if (strchr (catalog->cat_name, '/') != NULL || !with_path) - fd = open (catalog->cat_name, O_RDONLY); + /* Make sure we are alone. */ + __libc_lock_lock (catalog->lock); + + /* Check whether there was no other thread faster. */ + if (catalog->status != closed) + /* While we waited some other thread tried to open the catalog. */ + goto unlock_return; + + if (strchr (catalog->cat_name, '/') != NULL || catalog->nlspath == NULL) + fd = __open (catalog->cat_name, O_RDONLY); else { const char *run_nlspath = catalog->nlspath; @@ -164,7 +172,7 @@ __open_catalog (__nl_catd catalog, int with_path) if (fd < 0 || __fstat (fd, &st) < 0) { catalog->status = nonexisting; - return; + goto unlock_return; } #ifndef MAP_COPY @@ -195,7 +203,7 @@ __open_catalog (__nl_catd catalog, int with_path) if (catalog->file_ptr == NULL) { catalog->status = nonexisting; - return; + goto unlock_return; } todo = st.st_size; /* Save read, handle partial reads. */ @@ -207,7 +215,7 @@ __open_catalog (__nl_catd catalog, int with_path) { free ((void *) catalog->file_ptr); catalog->status = nonexisting; - return; + goto unlock_return; } todo -= now; } @@ -227,14 +235,14 @@ __open_catalog (__nl_catd catalog, int with_path) swapping = 1; else { - /* Illegal file. Free he resources and mark catalog as not + /* Illegal file. Free the resources and mark catalog as not usable. */ if (catalog->status == mmapped) __munmap ((void *) catalog->file_ptr, catalog->file_size); else free (catalog->file_ptr); catalog->status = nonexisting; - return; + goto unlock_return; } #define SWAP(x) (swapping ? SWAPU32 (x) : (x)) @@ -260,4 +268,8 @@ __open_catalog (__nl_catd catalog, int with_path) catalog->strings = (const char *) &catalog->file_ptr->name_ptr[catalog->plane_size * catalog->plane_depth * 3 * 2]; + + /* Release the lock again. */ + unlock_return: + __libc_lock_unlock (catalog->lock); } |