Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/crypto/dist/ipsec-tools/src/setkey Keep track of the filenam...



details:   https://anonhg.NetBSD.org/src/rev/e6269cf6b7aa
branches:  trunk
changeset: 932616:e6269cf6b7aa
user:      christos <christos%NetBSD.org@localhost>
date:      Tue May 12 14:29:06 2020 +0000

description:
Keep track of the filename to print in error messages.
Change quoting of error string from [] to `'.

diffstat:

 crypto/dist/ipsec-tools/src/setkey/extern.h |   5 +++--
 crypto/dist/ipsec-tools/src/setkey/setkey.c |  12 ++++++++----
 crypto/dist/ipsec-tools/src/setkey/token.l  |  16 ++++++++--------
 3 files changed, 19 insertions(+), 14 deletions(-)

diffs (130 lines):

diff -r 0d4d0294509f -r e6269cf6b7aa crypto/dist/ipsec-tools/src/setkey/extern.h
--- a/crypto/dist/ipsec-tools/src/setkey/extern.h       Tue May 12 14:04:50 2020 +0000
+++ b/crypto/dist/ipsec-tools/src/setkey/extern.h       Tue May 12 14:29:06 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.7 2018/10/14 08:27:39 maxv Exp $  */
+/*     $NetBSD: extern.h,v 1.8 2020/05/12 14:29:06 christos Exp $      */
 
 /*
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
 void parse_init(void);
 
 /* token.l */
-int parse(FILE **);
+int parse(const char *, FILE *);
 int parse_string(char *);
 
 /* setkey.c */
@@ -46,6 +46,7 @@
 #ifdef HAVE_POLICY_FWD
 extern int f_rfcmode;
 #endif
+extern const char *filename;
 extern int lineno;
 extern int exit_now;
 #ifdef HAVE_PFKEY_POLICY_PRIORITY
diff -r 0d4d0294509f -r e6269cf6b7aa crypto/dist/ipsec-tools/src/setkey/setkey.c
--- a/crypto/dist/ipsec-tools/src/setkey/setkey.c       Tue May 12 14:04:50 2020 +0000
+++ b/crypto/dist/ipsec-tools/src/setkey/setkey.c       Tue May 12 14:29:06 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: setkey.c,v 1.20 2019/02/03 10:23:42 mrg Exp $  */
+/*     $NetBSD: setkey.c,v 1.21 2020/05/12 14:29:06 christos Exp $     */
 /*     $KAME: setkey.c,v 1.36 2003/09/24 23:52:51 itojun Exp $ */
 
 /*
@@ -149,6 +149,7 @@
 #endif
 
 int lineno;
+const char *filename;
 int exit_now;
 static time_t thiszone;
 
@@ -172,6 +173,7 @@
 main(int argc, char **argv)
 {
        FILE *fp = stdin;
+       const char *fname = "<stdin>";
        int c;
 
        if (argc == 1) {
@@ -193,9 +195,11 @@
                        f_mode = MODE_SCRIPT;
                        if (strcmp(optarg, "-") == 0) {
                                fp = stdin;
+                               fname = "<stdin>";
                        } else if ((fp = fopen(optarg, "r")) == NULL) {
                                err(1, "Can't open `%s'", optarg);
                        }
+                       fname = optarg;
                        break;
                case 'D':
                        f_mode = MODE_CMDDUMP;
@@ -286,7 +290,7 @@
                if (get_supported() < 0) {
                        errx(1, "%s", ipsec_strerror());
                }
-               if (parse(&fp))
+               if (parse(fname, fp))
                        exit(1);
                break;
        case MODE_STDIN:
@@ -826,7 +830,7 @@
 #endif
 
 static int
-fileproc(const char *filename)
+fileproc(const char *fname)
 {
        int fd;
        ssize_t len, l;
@@ -834,7 +838,7 @@
        struct sadb_msg *msg;
        u_char rbuf[1024 * 32]; /* XXX: Enough ? Should I do MSG_PEEK ? */
 
-       fd = open(filename, O_RDONLY);
+       fd = open(fname, O_RDONLY);
        if (fd < 0)
                return -1;
 
diff -r 0d4d0294509f -r e6269cf6b7aa crypto/dist/ipsec-tools/src/setkey/token.l
--- a/crypto/dist/ipsec-tools/src/setkey/token.l        Tue May 12 14:04:50 2020 +0000
+++ b/crypto/dist/ipsec-tools/src/setkey/token.l        Tue May 12 14:29:06 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: token.l,v 1.24 2020/05/10 19:54:49 christos Exp $      */
+/*     $NetBSD: token.l,v 1.25 2020/05/12 14:29:06 christos Exp $      */
 /*     $KAME: token.l,v 1.44 2003/10/21 07:20:58 itojun Exp $  */
 
 /*
@@ -336,23 +336,23 @@
 void
 yyerror(const char *s)
 {
-       warnx("line %d: %s at [%s]", lineno, s, yytext);
+       warnx("%s,%d: %s at `%s'", filename, lineno, s, yytext);
 }
 
 int
-parse(FILE **fp)
+parse(const char *fname, FILE *fp)
 {
-       yyin = *fp;
-
+       yyin = fp;
+       filename = fname;
        lineno = 1;
        parse_init();
 
        if (yyparse()) {
-               warnx("line %d: parse failed", lineno);
-               return(-1);
+               warnx("%s,%d: parse failed", filename, lineno);
+               return -1;
        }
 
-       return(0);
+       return 0;
 }
 
 int



Home | Main Index | Thread Index | Old Index