Use g_spawn_sync

This commit is contained in:
Sebastian Ramacher 2019-11-30 14:35:10 +01:00
parent 0fa26487fc
commit 9a4b7ebbde

View file

@ -123,25 +123,28 @@ guess_type_magic(zathura_content_type_context_t* UNUSED(context),
static char* static char*
guess_type_file(const char* path) guess_type_file(const char* path)
{ {
GString* command = g_string_new("file -b --mime-type "); /* g_spawn_async expects char** */
char* tmp = g_shell_quote(path); static char cmd_file[] = "file";
static char opt_b[] = "-b";
g_string_append(command, tmp); static char opt_mime_type = "--mime-type";
g_free(tmp); char* argv[] = { cmd_file, opt_b, opt_mime_type, g_strdup(path), NULL };
GError* error = NULL; GError* error = NULL;
char* out = NULL; char* out = NULL;
int ret = 0; int ret = 0;
g_spawn_command_line_sync(command->str, &out, NULL, &ret, &error); const bool r = g_spawn_sync(NULL, argv, NULL,
g_string_free(command, TRUE); G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL,
if (error != NULL) { NULL, NULL, &out, NULL, &ret, &error);
girara_warning("failed to execute command: %s", error->message); g_free(argv[3]);
if (r == false || error != NULL) {
girara_warning("failed to execute command: %s", error ? error->message : "unknown");
g_error_free(error); g_error_free(error);
g_free(out); g_free(out);
return NULL; return NULL;
} }
if (WEXITSTATUS(ret) != 0) { if (g_spawn_check_exit_status(ret, &error) == false) {
girara_warning("file failed with error code: %d", WEXITSTATUS(ret)); girara_warning("file failed: %s", error->message);
g_error_free(error);
g_free(out); g_free(out);
return NULL; return NULL;
} }