]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Unix: Refactor tracked files
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Tue, 13 Nov 2018 17:13:11 +0000 (18:13 +0100)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Sun, 18 Nov 2018 13:03:50 +0000 (14:03 +0100)
We need access to resource in order to free it.

sysdep/unix/config.Y
sysdep/unix/io.c
sysdep/unix/unix.h

index 1bffa322ae98405c9c4b8718fd0ef544e1cc80c8..b8572c907a73628553c9d34f13dfe0de52c190e4 100644 (file)
@@ -41,9 +41,9 @@ syslog_name:
 
 log_file:
    text {
-     FILE *f = tracked_fopen(new_config->pool, $1, "a");
-     if (!f) cf_error("Unable to open log file `%s': %m", $1);
-     $$ = f;
+     struct rfile *f = rf_open(new_config->pool, $1, "a");
+     if (!f) cf_error("Unable to open log file '%s': %m", $1);
+     $$ = rf_file(f);
    }
  | SYSLOG syslog_name { $$ = NULL; new_config->syslog_name = $2; }
  | STDERR { $$ = stderr; }
@@ -77,9 +77,9 @@ conf: mrtdump_base ;
 mrtdump_base:
    MRTDUMP PROTOCOLS mrtdump_mask ';' { new_config->proto_default_mrtdump = $3; }
  | MRTDUMP text ';' {
-     FILE *f = tracked_fopen(new_config->pool, $2, "a");
+     struct rfile *f = rf_open(new_config->pool, $2, "a");
      if (!f) cf_error("Unable to open MRTDump file '%s': %m", $2);
-     new_config->mrtdump_file = fileno(f);
+     new_config->mrtdump_file = rf_fileno(f);
    }
  ;
 
index 4455fc1991999dcdc7b387cf98e928ad913a7c1f..8c9052a3e57f79df6ee3ccf1735a751edad8e44a 100644 (file)
@@ -55,6 +55,7 @@
    this to gen small latencies */
 #define MAX_RX_STEPS 4
 
+
 /*
  *     Tracked Files
  */
@@ -89,17 +90,29 @@ static struct resclass rf_class = {
   NULL
 };
 
-void *
-tracked_fopen(pool *p, char *name, char *mode)
+struct rfile *
+rf_open(pool *p, char *name, char *mode)
 {
   FILE *f = fopen(name, mode);
 
-  if (f)
-    {
-      struct rfile *r = ralloc(p, &rf_class);
-      r->f = f;
-    }
-  return f;
+  if (!f)
+    return NULL;
+
+  struct rfile *r = ralloc(p, &rf_class);
+  r->f = f;
+  return r;
+}
+
+void *
+rf_file(struct rfile *f)
+{
+  return f->f;
+}
+
+int
+rf_fileno(struct rfile *f)
+{
+  return fileno(f->f);
 }
 
 
index cb12fad844bb65da77b3d95960e982e0452ca817..64b146ee6e501389fffdcb01bc71c66c4914096a 100644 (file)
@@ -14,6 +14,7 @@
 struct pool;
 struct iface;
 struct birdsock;
+struct rfile;
 
 /* main.c */
 
@@ -102,7 +103,9 @@ void io_init(void);
 void io_loop(void);
 void io_log_dump(void);
 int sk_open_unix(struct birdsock *s, char *name);
-void *tracked_fopen(struct pool *, char *name, char *mode);
+struct rfile *rf_open(struct pool *, char *name, char *mode);
+void *rf_file(struct rfile *f);
+int rf_fileno(struct rfile *f);
 void test_old_bird(char *path);
 
 /* krt.c bits */