aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-04-30 20:47:16 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-05-04 08:40:38 +0000
commita1b41bd186147f3f028030e9079821d0bfa7b3f6 (patch)
tree05796d4fbef7a5d8838f9331e52dd2b28dd5b508 /main.c
parentMerge branch 'beam-thickness' (diff)
foot/footclient: use a custom exit code when foot/footclient fail to run
Normally, foot and footclient uses the exit code from the client application (i.e. the shell). However, foot (or footclient) itself may fail to run; if run outside of a Wayland session, or no fonts are installed, or the client application/shell cannot be found (“foot lsdjfldsjf”) etc. Up until now, there has been no way to differentiate these kind of failures from the client application exiting with code 1. This patch changes foot’s failure exit code to -27/229, and footclient’s to -28/228. Note that footclient will exit with foot’s -27/229 if footclient ran successfully, but the foot server failed to instantiate a new window. Closes #466.
Diffstat (limited to 'main.c')
-rw-r--r--main.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/main.c b/main.c
index 19c1904b..573cb0a1 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 = -27;
+ 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);