Use g_spawn_async() instead of fork()/exec()

This commit is contained in:
Pierre Pronchery 2014-09-26 11:45:16 +03:00
parent 1fe8510cf8
commit ae69039c28

View File

@ -480,23 +480,28 @@ static int _error_text(char const * message, int ret)
/* view_open_with */ /* view_open_with */
static void _view_open_with(View * view, char const * program) static void _view_open_with(View * view, char const * program)
{ {
pid_t pid; char * argv[] = { NULL, NULL, NULL };
const unsigned int flags = 0;
GError * error = NULL;
if(program == NULL) if(program == NULL)
{ {
_view_open_with_dialog(view); _view_open_with_dialog(view);
return; return;
} }
if((pid = fork()) == -1) if((argv[0] = strdup(program)) == NULL)
_view_error(view, "fork", 0);
else if(pid == 0)
{ {
if(close(0) != 0) _view_error(view, strerror(errno), 1);
_view_error(NULL, "stdin", 0); return;
execlp(program, program, view->pathname, NULL);
_view_error(NULL, program, 0);
exit(2);
} }
argv[1] = view->pathname;
if(g_spawn_async(NULL, argv, NULL, flags, NULL, NULL, NULL, &error)
!= TRUE)
{
_view_error(view, error->message, 1);
g_error_free(error);
}
free(argv[0]);
} }