Skip to content

Fix core file not generating on OSX - #6190

Merged
0xdaryl merged 1 commit into
eclipse-omr:masterfrom
mikezhang1234567890:osx-ddr
Oct 7, 2021
Merged

0xdaryl merged 1 commit into
eclipse-omr:masterfrom
mikezhang1234567890:osx-ddr

Conversation

@mikezhang1234567890

Copy link
Copy Markdown
Contributor

The return value kr is set to an error value that is non-fatal and should be
reset so that the generated file is not deleted at the end if the last memory
segment throws an error when being read.

Also make sure final return value is correct when there is an error.

Signed-off-by: Mike Zhang mike.h.zhang@ibm.com

Fixes the test issues on 10.11 Macs in eclipse-openj9/openj9#13509

fyi: @pshipton @keithc-ca

Comment thread port/osx/omrosdump.c Outdated

return kr;
/* check the core file has actually been created */
return access(filename, F_OK);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We don't want to ignore the value of kr here, and the return type of access() is incompatible with the return type of this function (actually, so is kern_return_t); suggest:

    return ((KERN_SUCCESS == kr) && (0 == access(filename, F_OK))) ? 0 : 1;

Other return statements above should either set kr appropriately and goto here, or properly map kern_return_t to uintptr_t.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed it to what you suggested. For the child process though, an error will just cause it to not write the core file and thus fail the access() check at the end, since the value of kr is harder to propagate to the parent.

@keithc-ca keithc-ca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, a failure near line 86 will inappropriately return KERN_SUCCESS.
Either initialize kr = KERN_FAILURE or assign it in the if body.

Comment thread port/osx/omrosdump.c Outdated
if (0 != chdir(filename)) {
perror("failed to change directories for dump");
return KERN_FAILURE;
goto done_child_proc;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it's better to just ignore this failure and attempt to write the dump in the current directory.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed it as you suggested, if chdir fails it will attempt to create a core dump in the current working directory.

Comment thread port/osx/omrosdump.c Outdated
if (KERN_SUCCESS != kr) {
mach_error("failed get special port:\n", kr);
return kr;
goto done_child_proc;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest an else block is preferable to the use of goto here.

Comment thread port/osx/omrosdump.c
Comment on lines +472 to +483
if (KERN_SUCCESS == kr) {
return ((0 == access(filename, F_OK)) || (0 == access(corefile_name, F_OK))) ? 0 : 1;
} else {
return 1;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the logic here needs to change. I don't think filename is allowed to be NULL, so the test on line 416 should change.

If filename is empty, the generated name should be written to that buffer.

So this should be something like:

	if (KERN_SUCCESS == kr) {
		/* check that the core file has been created */
		if (0 == access(filename, F_OK)) {
			return 0;
		}
		/* check for the core file in the current directory */
		if ((NULL != lastSep) && (0 == access(lastSep + 1, F_OK))) {
			return 0;
		}
	}
	return 1;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For the second check here, why does (NULL != lastSep) need to be true?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If the caller specified a (possibly empty) file name without a slash, then lastSep would be NULL in which case lastSep + 1 would not be a reasonable address to pass to access().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed so that omrdump_create fails if filename is NULL. It wasn't immediately obvious to me looking at the Unix version, but it occurs in L208 there.

I restructured the access checks as you suggested but kept (0 == access(corefile_name, F_OK)) for the 2nd check in the current working directory, since we already have the file name without any directories stored there.

Comment thread port/osx/omrosdump.c Outdated
strncpy(corefile_name, filename, PATH_MAX);
}


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove this extra blank line.

Comment thread port/osx/omrosdump.c Outdated
return 0;
}
/* check for corefile in current working directory */
if (0 == access(corefile_name, F_OK)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If NULL == lastSep, this is a repeat of the call to access() above (and just a waste of time).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right, added the check.

When reading memory segments, reset the return value kr so that the
generated file is not deleted at the end if the last memory segment
throws an error when being read, since mach_vm_read errors are not
fatal.

Also make sure final return value is correct when there is an error.

Signed-off-by: Mike Zhang <mike.h.zhang@ibm.com>
@0xdaryl

0xdaryl commented Oct 7, 2021

Copy link
Copy Markdown
Contributor

Jenkins build osx

@0xdaryl 0xdaryl self-assigned this Oct 7, 2021
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.

3 participants