aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric B Munson <emunson@mgebm.net>2010-11-11 08:01:59 -0700
committerEric B Munson <emunson@mgebm.net>2010-11-15 13:51:26 -0700
commitc484ac48d4fdaa650bcd641b08b5a9dc310f3330 (patch)
treeb268a400b131aad03aff689bed198a7f73785d3b
parentaf4f3eb0210519c719f7bf5bf4f893c51d92dd14 (diff)
downloadlibhugetlbfs-c484ac48d4fdaa650bcd641b08b5a9dc310f3330.tar.gz
Add timeout to find_or_prepare_shared_file
find_or_prepare_shared_file has a message stating that it should have a timeout so that we don't spin forever waiting on a shared file. In practice this would be very unlikely but this patch adds a timeout check to protect from spinning. Signed-off-by: Eric B Munson <emunson@mgebm.net>
-rw-r--r--elflink.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/elflink.c b/elflink.c
index 159edae..7e0444b 100644
--- a/elflink.c
+++ b/elflink.c
@@ -59,6 +59,14 @@
#define ELF_ST_TYPE(x) ELF64_ST_TYPE(x)
#endif
+/*
+ * SHARED_TIMEOUT is used by find_or_prepare_shared_file for when it
+ * should timeout while waiting for other users to finish preparing
+ * the file it wants. The value is the number of tries before giving
+ * up with a 1 second wait between tries
+ */
+#define SHARED_TIMEOUT 10
+
/* This function prints an error message to stderr, then aborts. It
* is safe to call, even if the executable segments are presently
* unmapped.
@@ -971,9 +979,10 @@ static int fork_and_prepare_segment(struct seg_info *htlb_seg_info)
*/
static int find_or_prepare_shared_file(struct seg_info *htlb_seg_info)
{
- int fdx, fds;
+ int fdx = -1, fds;
int errnox, errnos;
int ret;
+ int i;
char final_path[PATH_MAX+1];
char tmp_path[PATH_MAX+1];
@@ -982,7 +991,7 @@ static int find_or_prepare_shared_file(struct seg_info *htlb_seg_info)
return -1;
assemble_path(tmp_path, "%s.tmp", final_path);
- do {
+ for (i = 0; i < SHARED_TIMEOUT; i++) {
/* NB: mode is modified by umask */
fdx = open(tmp_path, O_CREAT | O_EXCL | O_RDWR, 0666);
errnox = errno;
@@ -1038,8 +1047,7 @@ static int find_or_prepare_shared_file(struct seg_info *htlb_seg_info)
/* Both opens failed, somebody else is still preparing */
/* Wait and try again */
sleep(1);
- /* FIXME: should have a timeout */
- } while (1);
+ }
fail:
if (fdx > 0) {