Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup the os_dirpath logic #2756

Merged
merged 3 commits into from
Jan 20, 2017
Merged

Cleanup the os_dirpath logic #2756

merged 3 commits into from
Jan 20, 2017

Conversation

rhc54
Copy link
Contributor

@rhc54 rhc54 commented Jan 18, 2017

Cleanup the os_dirpath logic so it doesn't error out if the directory actually gets created (regardless of what mkdir returns), and pretty-prints the error if it does error out.

Fixes #2754

Signed-off-by: Ralph Castain rhc@open-mpi.org
(cherry picked from commit b257c32)

… actually gets created (regardless of what mkdir returns), and pretty-prints the error if it does error out.

Signed-off-by: Ralph Castain <rhc@open-mpi.org>
(cherry picked from commit b257c32)
@rhc54 rhc54 added the bug label Jan 18, 2017
@rhc54 rhc54 added this to the v2.0.2 milestone Jan 18, 2017
@rhc54 rhc54 requested a review from jsquyres January 18, 2017 22:11
@tjb900
Copy link

tjb900 commented Jan 18, 2017

Awesome, thanks! You guys sure do respond quickly. One thing though - with the current patch, I think the stat() might destroy the errno from mkdir(), in which case the message from strerror will end up being wrong.

@rhc54
Copy link
Contributor Author

rhc54 commented Jan 18, 2017

crumby - you are quite correct. will fix. thanks!

…l likely overwrite it

Signed-off-by: Ralph Castain <rhc@open-mpi.org>
(cherry picked from commit 6da4dbb)
/* Now that we have the name, try to create it */
mkdir(tmp, mode);
ret = errno; // save the errno for an error msg, if needed
if (0 != stat(tmp, &buf)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the pointed commit was meant to solve a race condition (e.g. mkdir() after stat())

there still is a tricky race condition here ... someone else might have mkdir() but with the wrong permissions, so it will likely crash later.
so i guess we have to check the permissions at the end.

this is for master

diff --git a/opal/util/os_dirpath.c b/opal/util/os_dirpath.c
index 9ef9ebb..2328179 100644
--- a/opal/util/os_dirpath.c
+++ b/opal/util/os_dirpath.c
@@ -9,7 +9,7 @@
  *                         University of Stuttgart.  All rights reserved.
  * Copyright (c) 2004-2005 The Regents of the University of California.
  *                         All rights reserved.
- * Copyright (c) 2015-2016 Research Organization for Information Science
+ * Copyright (c) 2015-2017 Research Organization for Information Science
  *                         and Technology (RIST). All rights reserved.
  * Copyright (c) 2016-2017 Intel, Inc. All rights reserved.
  * $COPYRIGHT$
@@ -121,6 +121,12 @@ int opal_os_dirpath_create(const char *path, const mode_t mode)
             opal_argv_free(parts);
             free(tmp);
             return OPAL_ERROR;
+        } else if (i == (len-1) && (mode != (mode & buf.st_mode)) && (0 > chmod(tmp, (buf.st_mode | mode)))) {
+            opal_show_help("help-opal-util.txt", "dir-mode", true,
+                           tmp, mode, strerror(errno));
+            opal_argv_free(parts);
+            free(tmp);
+            return(OPAL_ERR_PERM); /* can't set correct mode */
         }
     }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds reasonable - if you want to commit to master, I'll cherry-pick it into this PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i made #2759
will merge when CI completes

always check the permissions of the created directory,
in case some one else created the very same directory but
with incompatible permissions

Signed-off-by: Gilles Gouaillardet <gilles@rist.or.jp>
(cherry picked from commit dffaad9)
@rhc54
Copy link
Contributor Author

rhc54 commented Jan 19, 2017

@ggouaillardet Thanks! Cherry-picked your update so it is included here

@jsquyres
Copy link
Member

@hppritcha This is good to go when CI finishes. It fixes an issue on Lustre.

@hppritcha hppritcha merged commit 854119e into open-mpi:v2.0.x Jan 20, 2017
@rhc54 rhc54 deleted the cmr20x/session branch February 13, 2017 23:15
@tjb900
Copy link

tjb900 commented Apr 13, 2017

Hi all,

Just a heads up, I hit this again on v2.1.0 - it appears to not have been cherrypicked into v2.x.

Cheers,
Tim

@ggouaillardet
Copy link
Contributor

@tjb900 that is correct, i just filled #3345 for this

@tjb900
Copy link

tjb900 commented Apr 13, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants