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 <[email protected]> --- elflink.c | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-) diff --git a/elflink.c b/elflink.c index 159edae..e36b5e3 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. @@ -974,6 +982,7 @@ static int find_or_prepare_shared_file(struct seg_info *htlb_seg_info) int fdx, 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++; i < SHARED_TIMEOUT) { /* 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) { -- 1.7.1 ------------------------------------------------------------------------------ The Next 800 Companies to Lead America's Growth: New Video Whitepaper David G. Thomson, author of the best-selling book "Blueprint to a Billion" shares his insights and actions to help propel your business during the next growth cycle. Listen Now! http://p.sf.net/sfu/SAP-dev2dev _______________________________________________ Libhugetlbfs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel
