-
Notifications
You must be signed in to change notification settings - Fork 931
ompi/opal/orte/oshmem/test: max hostname length cleanup #1552
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
Conversation
|
@kmroz would you mind rebasing this down to a smaller set of commits? it helps in tracking when we/if we want to merge in to other branches. Squashing down to one isn't necessary, more like 2 or 3 would be fine. |
|
@hppritcha - Will do. |
ompi/runtime/ompi_mpi_abort.c
Outdated
| host = ompi_process_info.nodename; | ||
| } else { | ||
| gethostname(hostname, sizeof(hostname)); | ||
| gethostname(hostname, MAXHOSTNAMELEN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to make changes like this? I somewhat like the defensive coding style of using sizeof(foo) to indicate the length of an array. In this case, it's obviously MAXHOSTNAME, but using sizeof protects you in case the array changes size someday (i.e., there's only 1 place to update instead of 2).
Indeed, I wouldn't mind seeing:
- Changing the size of all hostname-like arrays to
MAXHOSTNAMELEN(which you do already in this PR) - Changing all references to the length of the array (e.g., passing as the 2nd arg to
gethostname()) usesizeof(array_name).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a serious moral dilemma here ;) I agree we should go the sizeof() route.
|
@jsquyres Ah, cool! I didn't know this. We can test the "PR" hypothesis with this PR... provided I can get it into the right shape :) |
| /* local host name */ | ||
| gethostname(val, MPI_MAX_INFO_VAL); | ||
| gethostname(val, MAXHOSTNAMELEN); | ||
| ompi_info_set(&ompi_mpi_info_env.info, "host", val); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is limited by MPI_MAX_INFO_KEY.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I will look into changing this occurrence.
|
So the plan is to change [where possible] to use sizeof instead of hardcoding the MAXHOSTNAMELEN ? |
|
@bosilca I was specifically referring to using |
|
That's exactly what I was referring to. I was wondering if the plan was to change all the instances where sizeof(array[]) can be used (and thus provide a consistent usage) or just the one where it has been specifically mentioned ? |
|
I will rework this PR to pass sizeof() to all invocations of gethostname(). |
|
This PR was just about |
|
Yes of course, I meant using sizeof() in the context of this PR 😄 |
|
Rebased on top of current master, and s/MAXHOSTNAMELEN/sizeof()/ when invoking gethostname(). Some additional things:
@jsquyres - If you feel it would be better to drop libevent/pmix modifications from this PR, I'm happy to rebase things without those changes. I could try to go straight upstream, but would need a pointer where upstream is. Thanks again for all the reviews! |
|
@kmroz Please do a "git diff opal/mca/pmix" and send me the results - I'll upstream them to the pmix master. You can leave them here as well for now and I'll update them with the next PMIx release. |
|
@rhc54 - The diff you asked for is here: https://gist.github.com/kmroz/e786d5ea9e5dfd90ccc342d97792b997 I'd appreciate your feedback on |
|
@rhc54 - I think I narrowed it down. In pmix code, Above gist updated with most recent pmix diffset. |
|
Thanks - that indeed looks correct. I'll update this upstream, but let you include it in your commit here to avoid conflicts. |
|
@rhc54 - Great, thanks! |
|
@kmroz Sorry for the delay. Some (very minor) nits:
|
|
@jsquyres - No problem. I've removed the sizeof(char) instances and updated the PR. |
|
@jsquyres - Hmmm, did you have something like this in mind for both #ifndef MAXHOSTNAMELEN
/* From limits.h. Since we're using gethostname(), we add 1 to the max to allow
* for null termination.
*/
#ifdef HOST_NAME_MAX
#define OPAL_MAXHOSTNAMELEN HOST_NAME_MAX + 1
#else
/* SUSv2 guarantees that "Host names are limited to 255 bytes". */
#define OPAL_MAXHOSTNAMELEN 255 + 1
#endif
#else
#define OPAL_MAXHOSTNAMELEN MAXHOSTNAMELEN + 1
#endif |
|
Yes, that is what he is proposing. I would second it as it will avoid future confusion, if you wouldn't mind. |
|
@jsquyres / @rhc54 - Hi gents! OK - I think this should do it. Please have a look and let me know if you think I've missed something. I've also modified @rhc54 - I've updated the pmix diff (https://gist.github.com/kmroz/e786d5ea9e5dfd90ccc342d97792b997) with the latest. |
|
@kmroz Perhaps a little simpler, without the negative logic (pro tip: put a "c" after the triple-single-tick markdown for verbatim, and it syntax highlights for C): #if defined(MAXHOSTNAMELEN)
#define OPAL_MAXHOSTNAMELEN (MAXHOSTNAMELEN + 1)
#elif defined(HOST_NAME_MAX)
#define OPAL_MAXHOSTNAMELEN (HOST_NAME_MAX + 1)
#else
/* SUSv2 guarantees that "Host names are limited to 255 bytes". */
#define OPAL_MAXHOSTNAMELEN (255 + 1)
#endifThanks for your patience! Otherwise, I think it looks great. |
|
@jsquyres - On it... will fix it up shortly. |
|
Ummm...not quite right. The changes in the pmix code base should be PMIX_MAXHOSTNAMELEN, not OPAL_... Sorry to be a pain. |
Define OPAL_MAXHOSTNAMELEN to be either: (MAXHOSTNAMELEN + 1) or (limits.h:HOST_NAME_MAX + 1) or (255 + 1) For pmix code, define above using PMIX_MAXHOSTNAMELEN. Fixup opal layer to use the new max. Signed-off-by: Karol Mroz <mroz.karol@gmail.com>
|
👍 |
Signed-off-by: Karol Mroz <mroz.karol@gmail.com>
Also removes orte specific max hostname value. Signed-off-by: Karol Mroz <mroz.karol@gmail.com>
Signed-off-by: Karol Mroz <mroz.karol@gmail.com>
Signed-off-by: Karol Mroz <mroz.karol@gmail.com>
|
@jsquyres - Is there anything else you see that's needed to improve upon this one? |
|
Works for me. 👍 |
|
This is probably work PR'ing to the v2.x branch -- probably for v2.0.1. It's not critical functionality, by any means, but it will help reduce drift between master and the v2.x branch. |
|
@jsquyres - Will do, thanks. |
Trying to standardize from where max hostname length is derived and how gethostname() called. This is low priority/cleanup, but touches a fair number of files.
I've left MPI_Get_processor_name() to continue using MPI_MAX_PROCESSOR_NAME, as the variable to which it writes the hostname is passed into the function. If for some reason hostname max lengths ever exceed MPI_MAX_PROCESSOR_NAME, we could segfault.
Also, programs in orte/test/ are not configured to build, and further, they have various build failures. I've added the hostname max len fixups to these files as well, knowing they don't build. Perhaps a future TODO :)
Fixes: #1551