From: Fabian Keil <fk@fabiankeil.de>
Date: Thu, 17 Dec 2020 09:32:55 +0000 (+0100)
Subject: Check the chdir() return code
X-Git-Tag: v_3_0_30~201
X-Git-Url: http://www.privoxy.org/gitweb/@default-cgi@/faq/@proxy-info-url@?a=commitdiff_plain;h=0fe40b4677a954bc7b4c843479f216bf1e2e9b3f;p=privoxy.git

Check the chdir() return code

... to fix the compiler warning:
   jcc.c: In function ‘main’:
   jcc.c:5185:7: warning: ignoring return value of ‘chdir’, declared with attribute warn_unused_result [-Wunused-result]
          chdir("/");
          ^~~~~~~~~~
---

diff --git a/jcc.c b/jcc.c
index 8d99b1f9..d8e25d5b 100644
--- a/jcc.c
+++ b/jcc.c
@@ -5182,7 +5182,10 @@ int main(int argc, char **argv)
       }
 #endif
 
-      chdir("/");
+      if (chdir("/") != 0)
+      {
+         log_error(LOG_LEVEL_FATAL, "Failed to cd into '/': %E");
+      }
 
    } /* -END- if (daemon_mode) */