From 887e75c4ee492c6a8635d8695455f23426183c58 Mon Sep 17 00:00:00 2001 From: Hong Xu Date: Wed, 7 Dec 2016 17:55:28 -0800 Subject: [PATCH] Child processes should be session leaders. If not, when the session of mu is killed, these child processes are also killed. This scenario shows up when using mu4e: a PDF attachment, for example, is opened by Evince, but as soon as Emacs exits, Evince is also killed. --- configure.ac | 2 +- lib/mu-util.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 70167605..a6a329ba 100644 --- a/configure.ac +++ b/configure.ac @@ -122,7 +122,7 @@ AS_IF([test "x$ac_cv_member_struct_dirent_d_ino" != "xyes"], # we need these -AC_CHECK_FUNCS([memset memcpy realpath setlocale strerror getpass]) +AC_CHECK_FUNCS([memset memcpy realpath setlocale strerror getpass setsid]) AC_CHECK_FUNC(timegm,[],[AC_MSG_ERROR([missing required function timegm])]) # require pkg-config diff --git a/lib/mu-util.c b/lib/mu-util.c index 37d0e936..367ad78d 100644 --- a/lib/mu-util.c +++ b/lib/mu-util.c @@ -1,7 +1,7 @@ /* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/ /* ** -** Copyright (C) 2008-2013 Dirk-Jan C. Binnema +** Copyright (C) 2008-2016 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -330,6 +330,17 @@ mu_util_program_in_path (const char *prog) } +/* + * Set the child to a group leader to avoid being killed when the + * parent group is killed. + */ +static void +maybe_setsid (G_GNUC_UNUSED gpointer user_data) +{ +#if HAVE_SETSID + setsid(); +#endif /*HAVE_SETSID*/ +} gboolean mu_util_play (const char *path, gboolean allow_local, gboolean allow_remote, @@ -366,8 +377,8 @@ mu_util_play (const char *path, gboolean allow_local, gboolean allow_remote, err = NULL; rv = g_spawn_async (NULL, (gchar**)&argv, NULL, - G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, - err); + G_SPAWN_SEARCH_PATH, maybe_setsid, + NULL, NULL, err); return rv; }