-
Notifications
You must be signed in to change notification settings - Fork 149
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
MacOS support, basic os abstraction layer, README example syntax #24
Open
d4tocchini
wants to merge
2
commits into
NationalSecurityAgency:master
Choose a base branch
from
d4tocchini:macos
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* https://en.wikipedia.org/wiki/Operating_system_abstraction_layer*/ | ||
|
||
#include <unistd.h> | ||
|
||
#if defined(__linux__) | ||
#include <prctl.h> | ||
#endif | ||
|
||
#include"osal.h" | ||
|
||
int | ||
osal_fdatasync(HANDLE fd) | ||
{ | ||
#if defined(__linux__) | ||
return fdatasync(fd); | ||
#else | ||
return fsync(fd); | ||
#endif | ||
} | ||
|
||
void | ||
osal_set_pdeathsig(int sig) | ||
{ | ||
#if defined(__linux__) | ||
prctl(PR_SET_PDEATHSIG, sig); | ||
#else | ||
// TODO: | ||
#endif | ||
} | ||
|
||
char * | ||
_readdir(DIR *dirp){ | ||
struct dirent *de = readdir(dirp); | ||
return de ? de->d_name : NULL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* https://en.wikipedia.org/wiki/Operating_system_abstraction_layer */ | ||
|
||
// Inspired by MDBX's abstraction setup, this is just a first step towards platform-specific encapsulation with enough needed to extend support to MacOS. With a bit of copy-paste, LMDB source provides necessary details to add Windows, but current linux binary should run atop WSL. | ||
|
||
#ifndef _OSAL_H | ||
#define _OSAL_H | ||
|
||
#ifndef _BSD_SOURCE | ||
#define _BSD_SOURCE | ||
#endif | ||
|
||
#include<dirent.h> | ||
|
||
/* HANDLE | ||
An abstraction for a file handle. | ||
On POSIX systems file handles are small integers. On Windows | ||
they're opaque pointers. | ||
*/ | ||
#define HANDLE int | ||
|
||
int osal_fdatasync(HANDLE fd); | ||
void osal_set_pdeathsig(int sig); | ||
char *_readdir(DIR *dirp); | ||
|
||
#endif |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
mac xargs !== gnu xargs
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'll take a look at these - I'm in the middle of overhauling some fdatasync-related stuff, and should be able to make that more portable while I'm at it.
I have a couple of ideas to replace the prctl(PR_SET_PDEATHSIG, sig) business as well, but for normal usage I think you can safely comment that out. Right now if the master process catches a SIGTERM or SIGINT, children will gracefully terminate. SIGQUIT kills everything right away. A SIGKILL or other uncaught signals on the master process will leave orphan children though - that's what I'll try to fix more portably.
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.
good to hear you're barking up the same tree!
What are your thoughts on that "osal", or something for sane cross-platform encapsulation, a keeper? I found it quite frustrating that the lmdb source has all the cross-platform details we'd need but b/c its sprinkled inline throughout lib-specific implementation it's not reusable without surgical copy-paste, but hey, at least it's cross-platform.
This PR is working for me on mac (10.14), let me know if any tweaks are needed...
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.
Just pushed a bunch of stuff - should be in better shape now with regards to portability.