Added wofi_exit(). This allows correct handling of custom exit status codes on non-glibc systems. This function should always be used for exiting wofi as libc exit() will no longer correctly handle error situations.

This commit is contained in:
Scoopta
2024-02-07 18:16:11 -08:00
parent 32795acb20
commit a6e66d7cb7
7 changed files with 45 additions and 31 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2020 Scoopta
* Copyright (C) 2019-2024 Scoopta
* This file is part of Wofi
* Wofi is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -156,7 +156,7 @@ void wofi_dmenu_exec(const gchar* cmd) {
}
printf("%s\n", action);
free(action);
exit(0);
wofi_exit(0);
}
const char** wofi_dmenu_get_arg_names(void) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2023 Scoopta
* Copyright (C) 2019-2024 Scoopta
* This file is part of Wofi
* Wofi is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -398,7 +398,7 @@ struct widget* wofi_drun_get_widget(void) {
static void launch_done(GObject* obj, GAsyncResult* result, gpointer data) {
GError* err = NULL;
if(g_app_info_launch_uris_finish(G_APP_INFO(obj), result, &err)) {
exit(0);
wofi_exit(0);
} else if(err != NULL) {
char* cmd = data;
fprintf(stderr, "%s cannot be executed: %s\n", cmd, err->message);
@@ -407,7 +407,7 @@ static void launch_done(GObject* obj, GAsyncResult* result, gpointer data) {
char* cmd = data;
fprintf(stderr, "%s cannot be executed\n", cmd);
}
exit(1);
wofi_exit(1);
}
static void set_dri_prime(GDesktopAppInfo* info) {
@@ -449,17 +449,17 @@ void wofi_drun_exec(const gchar* cmd) {
char* cmd = get_cmd(G_APP_INFO(info));
printf("%s\n", cmd);
free(cmd);
exit(0);
wofi_exit(0);
} else if(print_desktop_file) {
printf("%s\n", cmd);
exit(0);
wofi_exit(0);
} else {
set_dri_prime(info);
if(uses_dbus(info)) {
g_app_info_launch_uris_async(G_APP_INFO(info), NULL, NULL, NULL, launch_done, (gchar*) cmd);
} else {
g_app_info_launch_uris(G_APP_INFO(info), NULL, NULL, NULL);
exit(0);
wofi_exit(0);
}
}
} else if(strrchr(cmd, ' ') != NULL) {
@@ -475,15 +475,15 @@ void wofi_drun_exec(const gchar* cmd) {
fprintf(stderr, "Printing the command line for an action is not supported\n");
} else if(print_desktop_file) {
printf("%s %s\n", cmd, action);
exit(0);
wofi_exit(0);
} else {
set_dri_prime(info);
g_desktop_app_info_launch_action(info, action, NULL);
}
exit(0);
wofi_exit(0);
} else {
fprintf(stderr, "%s cannot be executed\n", cmd);
exit(1);
wofi_exit(1);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2020 Scoopta
* Copyright (C) 2019-2024 Scoopta
* This file is part of Wofi
* Wofi is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -192,7 +192,7 @@ void wofi_run_exec(const char* cmd) {
}
if(print_command) {
printf("%s\n", cmd);
exit(0);
wofi_exit(0);
}
if(arg_run) {
size_t space_count = 2;
@@ -215,7 +215,7 @@ void wofi_run_exec(const char* cmd) {
execl(cmd, cmd, NULL);
}
fprintf(stderr, "%s cannot be executed %s\n", cmd, strerror(errno));
exit(errno);
wofi_exit(errno);
}
const char** wofi_run_get_arg_names(void) {