chiark / gitweb /
pubkeys: Improve debug message for expected ENOENT
[secnet.git] / pubkeys.fl.pl
index b8cac624317de3307f7d61efd9e8903597740f2d..69cc3c925aee2ab249529d32d631c5cfb4f8f399 100755 (executable)
@@ -109,7 +109,7 @@ while (<DATA>) {
     if (m/^!FINAL \{\s*$/) {
        die unless $kw;
        die if @next_kw;
-       $co .= inst("FIN_$kwid")."\\n { BEGIN(0); c->lno++; }\n";
+       $co .= inst("FIN_$kwid")."\\n { BEGIN(0); c->loc.line++; }\n";
        $co .= inst("$in_s")."{L}/\\n {\n";
        $co .= "\tBEGIN(FIN_$kwid);\n";
        $co .= lineno(1,1);
@@ -158,13 +158,12 @@ BASE91S   []-~!#-&(-[]+
 
 struct pubkeyset_context {
     /* filled in during setup: */
-    const char *path;
+    struct cloc loc; /* line is runtime */
     struct log_if *log;
     struct buffer_if *data_buf;
     struct peer_keyset *building;
     /* runtime: */
     bool_t had_serial;
-    int lno;
     bool_t fallback_skip;
     const struct sigscheme_info *scheme;
     uint8_t grpid[GRPIDSZ];
@@ -186,11 +185,11 @@ static struct pubkeyset_context c[1];
         break;                                         \
     })
 #define DOSKIP(m) ({                                   \
-        slilog(LI,M_INFO,"%s:%d: " m, c->path, c->lno);        \
+        slilog(LI,M_INFO,"%s:%d: " m, c->loc.file, c->loc.line);       \
         DOSKIPQ;                                       \
     })
 #define FAIL(m) do{                                    \
-       slilog(LI,M_ERR,"%s:%d: " m, c->path, c->lno);  \
+       slilog(LI,M_ERR,"%s:%d: " m, c->loc.file, c->loc.line); \
        return -1;                                      \
     }while(0)
 
@@ -228,7 +227,7 @@ static struct pubkeyset_context c[1];
     if (c->building->nkeys >= MAX_SIG_KEYS) DOSKIP("too many public keys");
     struct sigpubkey_if *pubkey;
     bool_t ok=c->scheme->loadpub(c->scheme,c->data_buf,
-                                &pubkey,c->log);
+                                &pubkey,c->log,c->loc);
     if (!ok) break;
     memcpy(c->building->keys[c->building->nkeys].id.b,
           c->grpid,
@@ -258,11 +257,11 @@ static struct pubkeyset_context c[1];
     BEGIN(SKIPNL);
 }
 {L}\n {
-    c->lno++;
+    c->loc.line++;
 }
 
 <SKIPNL>.*\n {
-    c->lno++;
+    c->loc.line++;
     BEGIN(0);
 }
 
@@ -279,12 +278,13 @@ keyset_load(const char *path, struct buffer_if *data_buf,
            struct log_if *log, int logcl_enoent) {
     assert(!c->building);
     c->log=log;
-    c->path=path;
+    c->loc.file=path;
     pkyyin = fopen(path, "r");
     if (!pkyyin) {
        slilog(LI,
               errno==ENOENT ? logcl_enoent : M_ERR,
-              "could not open keyset file %s: %s",
+              "%scould not open keyset file %s: %s",
+              logcl_enoent==M_DEBUG && errno==ENOENT ? "expectedly " : "",
               path,strerror(errno));
        goto err;
     }
@@ -297,7 +297,7 @@ keyset_load(const char *path, struct buffer_if *data_buf,
     c->building->refcount=1;
     c->fallback_skip=0;
     c->had_serial=0;
-    c->lno=1;
+    c->loc.line=1;
     FILLZERO(c->grpid);
     FILLZERO(c->serial);
     int r=pkyylex();