Repository: llvm/llvm-project
Pull request #126112: Add sysexits.h header with BSD exit codes (total-18)
Author: login: ajayrajsaini
Labels: name: libc
name: llvm:support
Created: 2025-02-06T18:57:32Z | Merged: 2025-03-07T00:25:14Z

This pull request adds a new header file, SysExits.h, to the LLVM project. The header includes 18 BSD exit code.


Diff:
diff --git a/libc/config/linux/aarch64/headers.txt b/libc/config/linux/aarch64/headers.txt
index 54c65765abe4a..f4223ed8a225d 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -29,6 +29,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.sys_socket
     libc.include.sys_syscall
     libc.include.sys_time
+    libc.include.sysexits
     libc.include.sys_wait
     libc.include.threads
     libc.include.time
diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index bd2fc3df75964..01b0bf36498ce 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -50,6 +50,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.sys_types
     libc.include.sys_utsname
     libc.include.sys_wait
+    libc.include.sysexits
     libc.include.termios
     libc.include.threads
     libc.include.time
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 41f6d3b67c95b..34f7c78b9783e 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -168,6 +168,16 @@ add_header_macro(
     .llvm-libc-types.stdfix-types
 )
 
+
+add_header_macro(
+  sysexits
+  ../libc/include/sysexits.yaml
+  sysexits.h
+  DEPENDS
+    .llvm-libc-macros.sysexits_macros
+)
+
+
 # TODO: This should be conditional on POSIX networking being included.
 file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/arpa)
 
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index 7f10e773479a3..7aa549ddc75d9 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -343,3 +343,10 @@ add_macro_header(
   HDR
     EFIAPI-macros.h
 )
+
+add_macro_header(
+  sysexits_macros
+  HDR
+    sysexits-macros.h
+)
+
diff --git a/libc/include/llvm-libc-macros/sysexits-macros.h b/libc/include/llvm-libc-macros/sysexits-macros.h
new file mode 100644
index 0000000000000..52f838788632b
--- /dev/null
+++ b/libc/include/llvm-libc-macros/sysexits-macros.h
@@ -0,0 +1,29 @@
+//===-- Macros defined in sysexits.h header file --------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef SYSEXITS_MACROS_H
+#define SYSEXITS_MACROS_H
+
+#define EX_OK 0           // Successful termination
+#define EX_USAGE 64       // Command line usage error
+#define EX_DATAERR 65     // Data format error
+#define EX_NOINPUT 66     // Cannot open input
+#define EX_NOUSER 67      // Addressee unknown
+#define EX_NOHOST 68      // Host name unknown
+#define EX_UNAVAILABLE 69 // Service unavailable
+#define EX_SOFTWARE 70    // Internal software error
+#define EX_OSERR 71       // Operating system error
+#define EX_OSFILE 72      // System file error
+#define EX_CANTCREAT 73   // Cannot create (user) output file
+#define EX_IOERR 74       // Input/output error
+#define EX_TEMPFAIL 75    // Temporary failure, try again
+#define EX_PROTOCOL 76    // Remote protocol error
+#define EX_NOPERM 77      // Permission denied
+#define EX_CONFIG 78      // Configuration error
+
+#endif // SYSEXITS_MACROS_H
diff --git a/libc/include/sysexits.h.def b/libc/include/sysexits.h.def
new file mode 100644
index 0000000000000..58e65a62f4903
--- /dev/null
+++ b/libc/include/sysexits.h.def
@@ -0,0 +1,17 @@
+//===-- POSIX header sysexits.h -----------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIBC_SYSEXITS_H
+#define LLVM_LIBC_SYSEXITS_H
+
+#include "__llvm-libc-common.h"
+#include "llvm-libc-macros/sysexits-macros.h"
+
+%%public_api()
+
+#endif // LLVM_LIBC_SYSEXITS_H
+
diff --git a/libc/include/sysexits.yaml b/libc/include/sysexits.yaml
new file mode 100644
index 0000000000000..753d99205ec29
--- /dev/null
+++ b/libc/include/sysexits.yaml
@@ -0,0 +1,10 @@
+header: sysexits.h
+header_template: sysexits.h.def
+standards:
+  - BSDExtensions
+  - GNUExtensions
+macros: []
+types: []
+enums: []
+objects: []
+functions: []


Reviews:
user: login: nickdesaulniers
body: Ah, sorry, the intent of #124640 was to provide sysexits.h to llvm-libc, (lib/), not llvm itself.

Specifically, that build failure isn't llvm's fault, it's only when building llvm on top of the nascent llvm-libc is the deficiency in llvm-libc exposed.
state: CHANGES_REQUESTED
author_association: MEMBER
submitted_at: 2025-02-07T18:26:34Z
user: login: jhuber6
body: This doesn't seem to define the header, it just adds this file in the `lib/` directory? Look at how we handle the other headers in `include/`. Specifically you'll want to understand the `hdrgen` utility and the `config/<os>/headers.txt` files.
state: CHANGES_REQUESTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-09T16:04:53Z
user: login: nickdesaulniers
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-02-11T17:41:38Z
user: login: nickdesaulniers
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-02-11T22:10:25Z
user: login: nickdesaulniers
state: APPROVED
author_association: MEMBER
submitted_at: 2025-02-11T22:10:43Z
user: login: michaelrj-google
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-04T17:38:50Z
user: login: ajayrajsaini
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-05T05:14:34Z
user: login: michaelrj-google
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-05T18:22:36Z
user: login: michaelrj-google
body: LGTM, @lntue do you want to merge it or should I?
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-06T21:38:49Z

Review comments:
diff_hunk: @@ -32,6 +32,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.unistd
     libc.include.wchar
     libc.include.uchar
+    libc.include.sysexits
path: libc/config/linux/aarch64/headers.txt
user: login: nickdesaulniers
body: Mind keeping this list sorted?
created_at: 2025-02-11T17:35:57Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,9 @@
+header: sysexits.h
+header_template: sysexits.h.def
+standards:
+  - POSIX
path: libc/include/sysexits.yaml
user: login: nickdesaulniers
body: sysexits.h is not in POSIX. (https://pubs.opengroup.org/onlinepubs/9799919799/ click Headers in bottom left).

I think you can just put `BSDExtensions` and `GNUExtensions`.

```suggestion
  - BSDExtensions
  - GNUExtensions
```
created_at: 2025-02-11T17:40:06Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,23 @@
+#ifndef SYSEXITS_MACROS_H
+#define SYSEXITS_MACROS_H
+
+#define EX_OK         0    // Successful termination
+#define EX_USAGE      64   // Command line usage error
+#define EX_DATAERR    65   // Data format error
+#define EX_NOINPUT    66   // Cannot open input
+#define EX_NOUSER     67   // Addressee unknown
+#define EX_NOHOST     68   // Host name unknown
+#define EX_UNAVAILABLE 69  // Service unavailable
+#define EX_SOFTWARE   70   // Internal software error
+#define EX_OSERR      71   // Operating system error
+#define EX_OSFILE     72   // System file error
+#define EX_CANTCREAT  73   // Cannot create (user) output file
+#define EX_IOERR      74   // Input/output error
+#define EX_TEMPFAIL   75   // Temporary failure, try again
+#define EX_PROTOCOL   76   // Remote protocol error
+#define EX_NOPERM     77   // Permission denied
+#define EX_CONFIG     78   // Configuration error
+#define EX_INTERNAL   80   // Internal error
+#define EX_INVALIDARG 81   // Invalid argument
path: libc/include/llvm-libc-macros/sysexits-macros.h
user: login: nickdesaulniers
body: Where did you find `EX_INTERNAL` and `EX_INVALIDARG`?  glibc, bionic, and musl only have up to `EX_CONFIG`.
created_at: 2025-02-11T17:41:30Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,23 @@
+#ifndef SYSEXITS_MACROS_H
+#define SYSEXITS_MACROS_H
+
+#define EX_OK         0    // Successful termination
+#define EX_USAGE      64   // Command line usage error
+#define EX_DATAERR    65   // Data format error
+#define EX_NOINPUT    66   // Cannot open input
+#define EX_NOUSER     67   // Addressee unknown
+#define EX_NOHOST     68   // Host name unknown
+#define EX_UNAVAILABLE 69  // Service unavailable
+#define EX_SOFTWARE   70   // Internal software error
+#define EX_OSERR      71   // Operating system error
+#define EX_OSFILE     72   // System file error
+#define EX_CANTCREAT  73   // Cannot create (user) output file
+#define EX_IOERR      74   // Input/output error
+#define EX_TEMPFAIL   75   // Temporary failure, try again
+#define EX_PROTOCOL   76   // Remote protocol error
+#define EX_NOPERM     77   // Permission denied
+#define EX_CONFIG     78   // Configuration error
+#define EX_INTERNAL   80   // Internal error
+#define EX_INVALIDARG 81   // Invalid argument
path: libc/include/llvm-libc-macros/sysexits-macros.h
user: login: nickdesaulniers
body: Question still stands; if these are from a BSD, it would be good to know which BSD adds these two new symbolic constants.
created_at: 2025-02-11T22:10:25Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,21 @@
+#ifndef SYSEXITS_MACROS_H
path: libc/include/llvm-libc-macros/sysexits-macros.h
user: login: michaelrj-google
body: this file needs a license header
created_at: 2025-03-04T17:38:00Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,21 @@
+#ifndef SYSEXITS_MACROS_H
path: libc/include/llvm-libc-macros/sysexits-macros.h
user: login: ajayrajsaini
body: //===-- Macros defined in sysexits.h header file --------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//


is it correct license header @michaelrj-google ?
created_at: 2025-03-05T05:14:34Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,21 @@
+#ifndef SYSEXITS_MACROS_H
path: libc/include/llvm-libc-macros/sysexits-macros.h
user: login: michaelrj-google
body: yes
created_at: 2025-03-05T18:22:36Z
author_association: CONTRIBUTOR

PR comments:
user: login: github-actions[bot]
created_at: 2025-02-06T18:57:50Z
body: <!--LLVM NEW CONTRIBUTOR COMMENT-->

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/).
author_association: NONE
user: login: llvmbot
created_at: 2025-02-06T18:58:27Z
body: 
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc

@llvm/pr-subscribers-llvm-support

Author: None (ajayrajsaini)

<details>
<summary>Changes</summary>

This pull request adds a new header file, SysExits.h, to the LLVM project. The header includes 18 BSD exit code.

---
Full diff: https://github.com/llvm/llvm-project/pull/126112.diff


1 Files Affected:

- (added) llvm/include/llvm/Support/SysExits.h (+24) 


``````````diff
diff --git a/llvm/include/llvm/Support/SysExits.h b/llvm/include/llvm/Support/SysExits.h
new file mode 100644
index 000000000000000..06b3ada101756e7
--- /dev/null
+++ b/llvm/include/llvm/Support/SysExits.h
@@ -0,0 +1,24 @@
+#ifndef SYSEXITS_H
+#define SYSEXITS_H
+
+// BSD Exit Codes (18 total) — These are the commonly used exit codes without POSIX dependencies
+#define EX_OK         0    // Successful termination
+#define EX_USAGE      64   // Command line usage error
+#define EX_DATAERR    65   // Data format error
+#define EX_NOINPUT    66   // Cannot open input
+#define EX_NOUSER     67   // Addressee unknown
+#define EX_NOHOST     68   // Host name unknown
+#define EX_UNAVAILABLE 69  // Service unavailable
+#define EX_SOFTWARE   70   // Internal software error
+#define EX_OSERR      71   // Operating system error
+#define EX_OSFILE     72   // System file error
+#define EX_CANTCREAT  73   // Cannot create (user) output file
+#define EX_IOERR      74   // Input/output error
+#define EX_TEMPFAIL   75   // Temporary failure, try again
+#define EX_PROTOCOL   76   // Remote protocol error
+#define EX_NOPERM     77   // Permission denied
+#define EX_CONFIG     78   // Configuration error
+#define EX_INTERNAL   80   // Internal error
+#define EX_INVALIDARG 81   // Invalid argument
+
+#endif // SYSEXITS_H

``````````

</details>

author_association: MEMBER
user: login: ajayrajsaini
created_at: 2025-02-09T14:43:58Z
body: Hi @nickdesaulniers  please review the PR and let me know if there is any changes needed
author_association: CONTRIBUTOR
user: login: nickdesaulniers
created_at: 2025-02-10T17:06:46Z
body: 6807164500e9920638e2ab0cdb4bf8321d24f8eb is a good reference example on what adding a new header entails.

 The headers.txt files are what roots the generation of the headers into the build system.

You can for now skip additions to libc/docs/, since I don't think I properly handle in docgen what to do for BSD extensions (docgen will error IIRC if you add things that aren't std C or POSIX).
author_association: MEMBER
user: login: ajayrajsaini
created_at: 2025-02-11T10:45:37Z
body: Hey @nickdesaulniers  , @jhuber6  i had made the requested changes will you review it once
author_association: CONTRIBUTOR
user: login: ajayrajsaini
created_at: 2025-02-12T05:30:32Z
body: Hey @nickdesaulniers  and @jhuber6 ,
Thank you so much for your guidance on my first contribution to LLVM. I really enjoyed working on it and learned a lot during the process. I would love to work on more issues if any are available and promise to avoid the mistakes I made this time. Please assign me any tasks where I can contribute further. Thanks again!"
author_association: CONTRIBUTOR
user: login: lntue
created_at: 2025-02-28T16:00:10Z
body: @ajayrajsaini Do you mind resolving the conflict so that we can merge this PR?  Thanks!
author_association: CONTRIBUTOR
user: login: github-actions[bot]
created_at: 2025-03-03T17:57:24Z
body: <!--LLVM CODE FORMAT COMMENT: {clang-format}-->

:white_check_mark: With the latest revision this PR passed the C/C++ code formatter.
author_association: NONE
user: login: lntue
created_at: 2025-03-06T22:53:41Z
body: > LGTM, @lntue do you want to merge it or should I?

You can go ahead, I'm away from the computer right now.
author_association: CONTRIBUTOR
user: login: github-actions[bot]
created_at: 2025-03-07T00:25:32Z
body: <!--LLVM BUILDBOT INFORMATION COMMENT-->

@ajayrajsaini Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail [here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of [LLVM development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

author_association: NONE