]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
tweak bsnapshot.c to use a fd instead of FILE* for debugging
authorAlain Spineux <alain@baculasystems.com>
Wed, 31 Aug 2022 14:25:51 +0000 (16:25 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:59 +0000 (13:56 +0200)
- see last change in message.c

bacula/src/tools/bsnapshot.c

index f203f2a8cab98fc1a986fdb742ff235b1bf2d7d2..2bdd90b2a7305cc451dc21230730df8d12fe4792 100644 (file)
 #include <sys/sysmacros.h>
 #endif
 
-#define Dmsg(level,  ...) do { \
-   if (level <= debug_level) { \
-      fprintf(debug, "%s:%d ", __FILE__ , __LINE__);    \
-      fprintf(debug, __VA_ARGS__ );                          \
-   }  \
+/* HERE I HAVE TO convert the fprintf into something in message.c */
+#define Dmsg(level, ...) do { \
+   d_msg(__FILE__ , __LINE__, level, __VA_ARGS__); \
  } while (0)
 
 #define Pmsg(level,  ...) do { \
@@ -76,7 +74,7 @@
 
 #define BSNAPSHOT_CONF SYSCONFDIR "/bsnapshot.conf"
 
-static FILE *debug = NULL;
+static int debug_fd = -1; /* file descriptor for the debugging */
 
 static void usage(const char *msg=NULL)
 {
@@ -167,18 +165,18 @@ void strip_quotes(char *str)
 static void set_trace_file(const char *path)
 {
    char dt[MAX_TIME_LENGTH];
-   if (debug && debug != stderr) {
-      fclose(debug);
+   if (debug_fd != -1) {
+      close(debug_fd);
    }
-   debug = fopen(path, "a");
-   if (!debug) {
-      debug = stderr;
-   } else {
+   debug_fd = open(path, O_RDWR | O_CREAT | O_APPEND, 0600);
+   if (debug_fd != -1) {
       Dmsg(10, "Starting bsnapshot %s\n",  
            bstrftime(dt, MAX_TIME_LENGTH, time(NULL)));
+      // redirect Dmsg() emitted by Bacula's libraries code
+      set_trace_for_tools(debug_fd);
+   } else {
+      perror(path); /* report the error to stderr */
    }
-   // redirect Dmsg() emitted by Bacula's libraries code
-   set_trace_for_tools(debug);
 }
 
 /* Small function to avoid double // in path name */