aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-05-04 08:44:34 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-05-04 08:44:34 +0000
commitc7a149a7ea1338aa956140230915b8a617f49069 (patch)
treef55b4ea4973aa2e05e97bc742e7518a40aa5e57e
parentMerge branch 'beam-thickness' (diff)
parentdoc: foot.1 footclient.1: document exit status (diff)
Merge branch 'custom-exit-code'
Closes #466
-rw-r--r--CHANGELOG.md6
-rw-r--r--client.c19
-rw-r--r--doc/foot.1.scd9
-rw-r--r--doc/footclient.1.scd18
-rw-r--r--main.c22
-rw-r--r--server.c4
6 files changed, 57 insertions, 21 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2fce1af5..7ec26157 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -51,6 +51,12 @@
* Point values in `line-height`, `letter-spacing`,
`horizontal-letter-offset` and `vertical-letter-offset` are now
rounded, not truncated, when translated to pixel values.
+* Foot’s exit code is now -26/230 when foot itself failed to launch
+ (due to invalid command line options, client application/shell not
+ found etc). Footclient’s exit code is -36/220 when it itself fails
+ to launch (e.g. bad command line option) and -26/230 when the foot
+ server failed to instantiate a new window
+ (https://codeberg.org/dnkl/foot/issues/466).
### Deprecated
diff --git a/client.c b/client.c
index 93dcc666..1445146c 100644
--- a/client.c
+++ b/client.c
@@ -69,7 +69,10 @@ print_usage(const char *prog_name)
int
main(int argc, char *const *argv)
{
- int ret = EXIT_FAILURE;
+ /* Custom exit code, to enable users to differentiate between foot
+ * itself failing, and the client application failiing */
+ static const int foot_exit_failure = -36;
+ int ret = foot_exit_failure;
const char *const prog_name = argv[0];
@@ -135,7 +138,7 @@ main(int argc, char *const *argv)
struct stat st;
if (stat(optarg, &st) < 0 || !(st.st_mode & S_IFDIR)) {
fprintf(stderr, "error: %s: not a directory\n", optarg);
- return EXIT_FAILURE;
+ return ret;
}
custom_cwd = optarg;
break;
@@ -144,7 +147,7 @@ main(int argc, char *const *argv)
case 'w':
if (sscanf(optarg, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
fprintf(stderr, "error: invalid window-size-pixels: %s\n", optarg);
- return EXIT_FAILURE;
+ return ret;
}
size_type = 0; // CONF_SIZE_PX
break;
@@ -152,7 +155,7 @@ main(int argc, char *const *argv)
case 'W':
if (sscanf(optarg, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
fprintf(stderr, "error: invalid window-size-chars: %s\n", optarg);
- return EXIT_FAILURE;
+ return ret;
}
size_type = 1; // CONF_SIZE_CELLS
break;
@@ -187,7 +190,7 @@ main(int argc, char *const *argv)
"-d,--log-level: %s: argument must be one of %s\n",
optarg,
log_level_string_hint());
- return EXIT_FAILURE;
+ return ret;
}
log_level = lvl;
break;
@@ -202,7 +205,7 @@ main(int argc, char *const *argv)
log_colorize = LOG_COLORIZE_ALWAYS;
else {
fprintf(stderr, "%s: argument must be one of 'never', 'always' or 'auto'\n", optarg);
- return EXIT_FAILURE;
+ return ret;
}
break;
@@ -215,7 +218,7 @@ main(int argc, char *const *argv)
return EXIT_SUCCESS;
case '?':
- return EXIT_FAILURE;
+ return ret;
}
}
@@ -373,6 +376,8 @@ main(int argc, char *const *argv)
int exit_code;
ssize_t rcvd = recv(fd, &exit_code, sizeof(exit_code), 0);
+ LOG_INFO("exit-code=%d", exit_code);
+
if (rcvd == -1 && errno == EINTR)
xassert(aborted);
else if (rcvd != sizeof(exit_code))
diff --git a/doc/foot.1.scd b/doc/foot.1.scd
index 9b5079b8..8c7bf901 100644
--- a/doc/foot.1.scd
+++ b/doc/foot.1.scd
@@ -28,7 +28,7 @@ the foot command line
*-C*,*--check-config*
Verify configuration and then exit with 0 if ok, otherwise exit
- with 1.
+ with 230 (see *EXIT STATUS*).
*-f*,*--font*=_FONT_
Comma separated list of fonts to use, in fontconfig format (see
@@ -136,6 +136,13 @@ the foot command line
*-v*,*--version*
Show the version number and quit.
+# EXIT STATUS
+
+Foot will exit with code 230 if there is a failure in foot itself.
+
+In all other cases, the exit code is that of the client application
+(i.e. the shell).
+
# KEYBOARD SHORTCUTS
The following keyboard shortcuts are available.
diff --git a/doc/footclient.1.scd b/doc/footclient.1.scd
index 900668a2..fcd2f5d1 100644
--- a/doc/footclient.1.scd
+++ b/doc/footclient.1.scd
@@ -17,8 +17,8 @@ mode.
Running it without arguments will open a new terminal window (hosted
in the foot server), with your default shell. The exit code will be
-that of the terminal (thus, *footclient* does not exit until the
-terminal has terminated).
+that of the terminal. I.e *footclient* does not exit until the
+terminal has terminated.
# OPTIONS
@@ -74,6 +74,20 @@ terminal has terminated).
*-v*,*--version*
Show the version number and quit
+# EXIT STATUS
+
+Footlient will exit with code 220 if there is a failure in footclient
+itself (for example, the server socket does not exist).
+
+If *-N*,*--no-wait* is used, footclient exits with code 0 as soon as
+the foot server has been instructed to open a new window.
+
+If not, footclient may also exit with code 230. This indicates a
+failure in the foot server.
+
+In all other cases the exit code is that of the client application
+(i.e. the shell).
+
# SEE ALSO
*foot*(1)
diff --git a/main.c b/main.c
index 19c1904b..82795424 100644
--- a/main.c
+++ b/main.c
@@ -151,7 +151,10 @@ print_pid(const char *pid_file, bool *unlink_at_exit)
int
main(int argc, char *const *argv)
{
- int ret = EXIT_FAILURE;
+ /* Custom exit code, to enable users to differentiate between foot
+ * itself failing, and the client application failiing */
+ static const int foot_exit_failure = -26;
+ int ret = foot_exit_failure;
/* Startup notifications; we don't support it, but must ensure we
* don't pass this on to programs launched by us */
@@ -242,7 +245,7 @@ main(int argc, char *const *argv)
struct stat st;
if (stat(optarg, &st) < 0 || !(st.st_mode & S_IFDIR)) {
fprintf(stderr, "error: %s: not a directory\n", optarg);
- return EXIT_FAILURE;
+ return ret;
}
custom_cwd = optarg;
break;
@@ -274,7 +277,7 @@ main(int argc, char *const *argv)
unsigned width, height;
if (sscanf(optarg, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
fprintf(stderr, "error: invalid window-size-pixels: %s\n", optarg);
- return EXIT_FAILURE;
+ return ret;
}
conf_size_type = CONF_SIZE_PX;
@@ -287,7 +290,7 @@ main(int argc, char *const *argv)
unsigned width, height;
if (sscanf(optarg, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
fprintf(stderr, "error: invalid window-size-chars: %s\n", optarg);
- return EXIT_FAILURE;
+ return ret;
}
conf_size_type = CONF_SIZE_CELLS;
@@ -332,7 +335,7 @@ main(int argc, char *const *argv)
"-d,--log-level: %s: argument must be one of %s\n",
optarg,
log_level_string_hint());
- return EXIT_FAILURE;
+ return ret;
}
log_level = lvl;
break;
@@ -347,7 +350,7 @@ main(int argc, char *const *argv)
log_colorize = LOG_COLORIZE_ALWAYS;
else {
fprintf(stderr, "%s: argument must be one of 'never', 'always' or 'auto'\n", optarg);
- return EXIT_FAILURE;
+ return ret;
}
break;
@@ -364,7 +367,7 @@ main(int argc, char *const *argv)
return EXIT_SUCCESS;
case '?':
- return EXIT_FAILURE;
+ return ret;
}
}
@@ -464,7 +467,7 @@ main(int argc, char *const *argv)
struct renderer *renderer = NULL;
struct terminal *term = NULL;
struct server *server = NULL;
- struct shutdown_context shutdown_ctx = {.term = &term, .exit_code = EXIT_FAILURE};
+ struct shutdown_context shutdown_ctx = {.term = &term, .exit_code = foot_exit_failure};
const char *cwd = custom_cwd;
char *_cwd = NULL;
@@ -533,7 +536,8 @@ main(int argc, char *const *argv)
break;
}
- ret = aborted || tll_length(wayl->terms) == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+ if (aborted || tll_length(wayl->terms) == 0)
+ ret = EXIT_SUCCESS;
out:
free(_cwd);
diff --git a/server.c b/server.c
index 2d813ab2..1b33ee23 100644
--- a/server.c
+++ b/server.c
@@ -312,7 +312,7 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data)
if (instance->terminal == NULL) {
LOG_ERR("failed to instantiate new terminal");
- client_send_exit_code(client, -1);
+ client_send_exit_code(client, -26);
instance_destroy(instance, -1);
goto shutdown;
}
@@ -497,7 +497,7 @@ server_destroy(struct server *server)
tll_length(server->clients));
tll_foreach(server->clients, it) {
- client_send_exit_code(it->item, 1);
+ client_send_exit_code(it->item, -26);
client_destroy(it->item);
}