From 6e5618407061cc9d0f547be94f4f98ac57a5ca7a Mon Sep 17 00:00:00 2001 From: Martin Castillo Date: Sun, 15 Mar 2020 14:37:46 +0059 Subject: [PATCH] Wait for lockcommand to exit. (Bug #10089) This should prevent cases where the systems suspends/hibernates before the screen is completely locked. --- xfce4-session/xfce-screensaver.c | 41 ++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/xfce4-session/xfce-screensaver.c b/xfce4-session/xfce-screensaver.c index 947c486..a6696ca 100644 --- a/xfce4-session/xfce-screensaver.c +++ b/xfce4-session/xfce-screensaver.c @@ -531,30 +531,51 @@ xfce_screensaver_lock (XfceScreenSaver *saver) case SCREENSAVER_TYPE_OTHER: { gboolean ret = FALSE; + gint exit_status = 255; - if (saver->priv->lock_command != NULL) + if (saver->priv->lock_command == NULL) + { + g_warning ("Screensaver lock command not set when attempting to lock the screen.\n" + "Please set the xfconf property %s%s in xfce4-session to the desired lock command", + XFSM_PROPERTIES_PREFIX, LOCK_COMMAND); + } + else { DBG ("running lock command: %s", saver->priv->lock_command); - ret = g_spawn_command_line_async (saver->priv->lock_command, NULL); + ret = g_spawn_command_line_sync (saver->priv->lock_command, NULL, NULL, &exit_status, NULL); + /* 'ret' tells us, whether the command could be executed, but 'exit_status' says, whether the + * command was succesful. Both need to be true. Otherwise we try other commands. */ + if (exit_status != 0) + { + ret = FALSE; + } } if (!ret) { - g_warning ("Screensaver lock command not set when attempting to lock the screen.\n" - "Please set the xfconf property %s%s in xfce4-session to the desired lock command", - XFSM_PROPERTIES_PREFIX, LOCK_COMMAND); - - ret = g_spawn_command_line_async ("xflock4", NULL); + ret = g_spawn_command_line_sync ("xflock4", NULL, NULL, &exit_status, NULL); + if (exit_status != 0) + { + ret = FALSE; + } } if (!ret) { - ret = g_spawn_command_line_async ("xdg-screensaver lock", NULL); + ret = g_spawn_command_line_sync ("xdg-screensaver lock", NULL, NULL, &exit_status, NULL); + if (exit_status != 0) + { + ret = FALSE; + } } - + if (!ret) { - ret = g_spawn_command_line_async ("xscreensaver-command -lock", NULL); + ret = g_spawn_command_line_sync ("xscreensaver-command -lock", NULL, NULL, &exit_status, NULL); + if (exit_status != 0) + { + ret = FALSE; + } } return ret; -- 2.25.1