From f6220a2d6e2c6ecb348541b28314d1fa7767f52b Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Fri, 27 Sep 2019 11:06:03 +0200 Subject: [PATCH] lib: do flatpak check only once Either we are in a flatpak or not, this doesn't change, so we can just remember the result. --- lib/client_impl.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/client_impl.c b/lib/client_impl.c index 2a47903..4c187f1 100644 --- a/lib/client_impl.c +++ b/lib/client_impl.c @@ -76,12 +76,17 @@ static char error_string[512] = { 0 }; // Helper to check if we are running inside a flatpak static int in_flatpak(void) { - struct stat sb; - int r; + static int status = -1; - r = lstat("/.flatpak-info", &sb); + if (status == -1) { + struct stat sb; + int r; - return r == 0 && sb.st_size > 0; + r = lstat("/.flatpak-info", &sb); + status = r == 0 && sb.st_size > 0; + } + + return status; } static int log_error(const char *fmt, ...)