mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
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.
This commit is contained in:
parent
29b697a9af
commit
a1b41bd186
4 changed files with 33 additions and 18 deletions
|
|
@ -51,6 +51,12 @@
|
||||||
* Point values in `line-height`, `letter-spacing`,
|
* Point values in `line-height`, `letter-spacing`,
|
||||||
`horizontal-letter-offset` and `vertical-letter-offset` are now
|
`horizontal-letter-offset` and `vertical-letter-offset` are now
|
||||||
rounded, not truncated, when translated to pixel values.
|
rounded, not truncated, when translated to pixel values.
|
||||||
|
* Foot’s exit code is now -27/229 when foot itself failed to launch
|
||||||
|
(due to invalid command line options, client application/shell not
|
||||||
|
found etc). Footclient’s exit code is -28/228 when it itself fails
|
||||||
|
to launch (e.g. bad command line option) and -27/229 when the foot
|
||||||
|
server failed to instantiate a new window
|
||||||
|
(https://codeberg.org/dnkl/foot/issues/466).
|
||||||
|
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
|
||||||
19
client.c
19
client.c
|
|
@ -69,7 +69,10 @@ print_usage(const char *prog_name)
|
||||||
int
|
int
|
||||||
main(int argc, char *const *argv)
|
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 = -28;
|
||||||
|
int ret = foot_exit_failure;
|
||||||
|
|
||||||
const char *const prog_name = argv[0];
|
const char *const prog_name = argv[0];
|
||||||
|
|
||||||
|
|
@ -135,7 +138,7 @@ main(int argc, char *const *argv)
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (stat(optarg, &st) < 0 || !(st.st_mode & S_IFDIR)) {
|
if (stat(optarg, &st) < 0 || !(st.st_mode & S_IFDIR)) {
|
||||||
fprintf(stderr, "error: %s: not a directory\n", optarg);
|
fprintf(stderr, "error: %s: not a directory\n", optarg);
|
||||||
return EXIT_FAILURE;
|
return ret;
|
||||||
}
|
}
|
||||||
custom_cwd = optarg;
|
custom_cwd = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
@ -144,7 +147,7 @@ main(int argc, char *const *argv)
|
||||||
case 'w':
|
case 'w':
|
||||||
if (sscanf(optarg, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
|
if (sscanf(optarg, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
|
||||||
fprintf(stderr, "error: invalid window-size-pixels: %s\n", optarg);
|
fprintf(stderr, "error: invalid window-size-pixels: %s\n", optarg);
|
||||||
return EXIT_FAILURE;
|
return ret;
|
||||||
}
|
}
|
||||||
size_type = 0; // CONF_SIZE_PX
|
size_type = 0; // CONF_SIZE_PX
|
||||||
break;
|
break;
|
||||||
|
|
@ -152,7 +155,7 @@ main(int argc, char *const *argv)
|
||||||
case 'W':
|
case 'W':
|
||||||
if (sscanf(optarg, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
|
if (sscanf(optarg, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
|
||||||
fprintf(stderr, "error: invalid window-size-chars: %s\n", optarg);
|
fprintf(stderr, "error: invalid window-size-chars: %s\n", optarg);
|
||||||
return EXIT_FAILURE;
|
return ret;
|
||||||
}
|
}
|
||||||
size_type = 1; // CONF_SIZE_CELLS
|
size_type = 1; // CONF_SIZE_CELLS
|
||||||
break;
|
break;
|
||||||
|
|
@ -187,7 +190,7 @@ main(int argc, char *const *argv)
|
||||||
"-d,--log-level: %s: argument must be one of %s\n",
|
"-d,--log-level: %s: argument must be one of %s\n",
|
||||||
optarg,
|
optarg,
|
||||||
log_level_string_hint());
|
log_level_string_hint());
|
||||||
return EXIT_FAILURE;
|
return ret;
|
||||||
}
|
}
|
||||||
log_level = lvl;
|
log_level = lvl;
|
||||||
break;
|
break;
|
||||||
|
|
@ -202,7 +205,7 @@ main(int argc, char *const *argv)
|
||||||
log_colorize = LOG_COLORIZE_ALWAYS;
|
log_colorize = LOG_COLORIZE_ALWAYS;
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "%s: argument must be one of 'never', 'always' or 'auto'\n", optarg);
|
fprintf(stderr, "%s: argument must be one of 'never', 'always' or 'auto'\n", optarg);
|
||||||
return EXIT_FAILURE;
|
return ret;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -215,7 +218,7 @@ main(int argc, char *const *argv)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
return EXIT_FAILURE;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -373,6 +376,8 @@ main(int argc, char *const *argv)
|
||||||
int exit_code;
|
int exit_code;
|
||||||
ssize_t rcvd = recv(fd, &exit_code, sizeof(exit_code), 0);
|
ssize_t rcvd = recv(fd, &exit_code, sizeof(exit_code), 0);
|
||||||
|
|
||||||
|
LOG_INFO("exit-code=%d", exit_code);
|
||||||
|
|
||||||
if (rcvd == -1 && errno == EINTR)
|
if (rcvd == -1 && errno == EINTR)
|
||||||
xassert(aborted);
|
xassert(aborted);
|
||||||
else if (rcvd != sizeof(exit_code))
|
else if (rcvd != sizeof(exit_code))
|
||||||
|
|
|
||||||
22
main.c
22
main.c
|
|
@ -151,7 +151,10 @@ print_pid(const char *pid_file, bool *unlink_at_exit)
|
||||||
int
|
int
|
||||||
main(int argc, char *const *argv)
|
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
|
/* Startup notifications; we don't support it, but must ensure we
|
||||||
* don't pass this on to programs launched by us */
|
* don't pass this on to programs launched by us */
|
||||||
|
|
@ -242,7 +245,7 @@ main(int argc, char *const *argv)
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (stat(optarg, &st) < 0 || !(st.st_mode & S_IFDIR)) {
|
if (stat(optarg, &st) < 0 || !(st.st_mode & S_IFDIR)) {
|
||||||
fprintf(stderr, "error: %s: not a directory\n", optarg);
|
fprintf(stderr, "error: %s: not a directory\n", optarg);
|
||||||
return EXIT_FAILURE;
|
return ret;
|
||||||
}
|
}
|
||||||
custom_cwd = optarg;
|
custom_cwd = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
@ -274,7 +277,7 @@ main(int argc, char *const *argv)
|
||||||
unsigned width, height;
|
unsigned width, height;
|
||||||
if (sscanf(optarg, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
|
if (sscanf(optarg, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
|
||||||
fprintf(stderr, "error: invalid window-size-pixels: %s\n", optarg);
|
fprintf(stderr, "error: invalid window-size-pixels: %s\n", optarg);
|
||||||
return EXIT_FAILURE;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
conf_size_type = CONF_SIZE_PX;
|
conf_size_type = CONF_SIZE_PX;
|
||||||
|
|
@ -287,7 +290,7 @@ main(int argc, char *const *argv)
|
||||||
unsigned width, height;
|
unsigned width, height;
|
||||||
if (sscanf(optarg, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
|
if (sscanf(optarg, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
|
||||||
fprintf(stderr, "error: invalid window-size-chars: %s\n", optarg);
|
fprintf(stderr, "error: invalid window-size-chars: %s\n", optarg);
|
||||||
return EXIT_FAILURE;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
conf_size_type = CONF_SIZE_CELLS;
|
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",
|
"-d,--log-level: %s: argument must be one of %s\n",
|
||||||
optarg,
|
optarg,
|
||||||
log_level_string_hint());
|
log_level_string_hint());
|
||||||
return EXIT_FAILURE;
|
return ret;
|
||||||
}
|
}
|
||||||
log_level = lvl;
|
log_level = lvl;
|
||||||
break;
|
break;
|
||||||
|
|
@ -347,7 +350,7 @@ main(int argc, char *const *argv)
|
||||||
log_colorize = LOG_COLORIZE_ALWAYS;
|
log_colorize = LOG_COLORIZE_ALWAYS;
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "%s: argument must be one of 'never', 'always' or 'auto'\n", optarg);
|
fprintf(stderr, "%s: argument must be one of 'never', 'always' or 'auto'\n", optarg);
|
||||||
return EXIT_FAILURE;
|
return ret;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -364,7 +367,7 @@ main(int argc, char *const *argv)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
return EXIT_FAILURE;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -464,7 +467,7 @@ main(int argc, char *const *argv)
|
||||||
struct renderer *renderer = NULL;
|
struct renderer *renderer = NULL;
|
||||||
struct terminal *term = NULL;
|
struct terminal *term = NULL;
|
||||||
struct server *server = 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;
|
const char *cwd = custom_cwd;
|
||||||
char *_cwd = NULL;
|
char *_cwd = NULL;
|
||||||
|
|
@ -533,7 +536,8 @@ main(int argc, char *const *argv)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = aborted || tll_length(wayl->terms) == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
if (aborted || tll_length(wayl->terms) == 0)
|
||||||
|
ret = EXIT_SUCCESS;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free(_cwd);
|
free(_cwd);
|
||||||
|
|
|
||||||
4
server.c
4
server.c
|
|
@ -312,7 +312,7 @@ fdm_client(struct fdm *fdm, int fd, int events, void *data)
|
||||||
|
|
||||||
if (instance->terminal == NULL) {
|
if (instance->terminal == NULL) {
|
||||||
LOG_ERR("failed to instantiate new terminal");
|
LOG_ERR("failed to instantiate new terminal");
|
||||||
client_send_exit_code(client, -1);
|
client_send_exit_code(client, -27);
|
||||||
instance_destroy(instance, -1);
|
instance_destroy(instance, -1);
|
||||||
goto shutdown;
|
goto shutdown;
|
||||||
}
|
}
|
||||||
|
|
@ -497,7 +497,7 @@ server_destroy(struct server *server)
|
||||||
tll_length(server->clients));
|
tll_length(server->clients));
|
||||||
|
|
||||||
tll_foreach(server->clients, it) {
|
tll_foreach(server->clients, it) {
|
||||||
client_send_exit_code(it->item, 1);
|
client_send_exit_code(it->item, -27);
|
||||||
client_destroy(it->item);
|
client_destroy(it->item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue