Skip to content

constants: add support for sysexits.h exit codes #48418

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cheezedoodle2
Copy link

These exit codes are still in use by process managers which inherited behavior expectations of child processes from the early days of BSD.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. typings labels Jun 11, 2023
@mscdex
Copy link
Contributor

mscdex commented Jun 11, 2023

I'm not sure it makes sense to add legacy exit code constants like this to node core.

@cheezedoodle2
Copy link
Author

I'm not sure it makes sense to add legacy exit code constants like this to node core.

You're right that it doesn't make a lot of sense on its face, and my first thought was to create a module. However, this doesn't work because the situation is:

  1. Within a particular environment which is mostly legacy, but also includes modern systems which must be compatible with systems derived from that environment, there are at least three different families of these constants. Two of them are in the same OS, one major semver apart.
  2. Because of this, the canonical source for the constant->number mapping is the header files, which in this environment are treated more like config files, because...
  3. Getting a native code compiler in the environment that will be running node is effectively impossible if you want to keep using your very expensive support contract to get free(ish) hardware replacements.

I considered building a C preprocessor in a module to extract the constants, but this was 1) significantly more difficult than I thought, because in one case <sysexits.h> pulls in a bunch of other stuff with compiler-specific conditional statements, partly to select the correct family of sysexit codes as mentioned above, and 2) in a case that isn't in production, but I'm told will be in the future, even the header files won't be available at runtime. Due to government SBOM regulations, only the package builder will have access to headers, and the runtime environment will be very stripped down.

@mscdex
Copy link
Contributor

mscdex commented Jun 13, 2023

If we are providing explicit values for typings then I don't see why you would need a compiler or sysexits.h?

Even if it varied depending on platform, surely you can just check the platform and make adjustments as needed?

@cheezedoodle2
Copy link
Author

Oh, you're right, the typings should be pulling from the symbolic constants in the C header. I'm not sure how to do that, I can't find anything in the tree as a precedent where the .d.ts files are run through the C preprocessor to replace tokens.

I did do some tests where some test applications would try to ask the node interpreter to figure out what environment it's in, then use hard-coded tables to set the constants correctly. This wasn't reliable for a bunch of reasons, mainly because application security restrictions (100% normal for this platform) prevent the application from directly getting that information from the executive (like a kernel syscall). I can try to infer it by probing another peer image and examining edge cases to drive a heuristic to figure out what the environment probably is, but it's a fragile and only mostly reliable solution at best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. typings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants