postfix-users May 2012 archive
Main Archive Page > Month Archives  > postfix-users archives
postfix-users: PATCH: Syntax error in main.cf

PATCH: Syntax error in main.cf

From: Wietse Venema <wietse_at_nospam>
Date: Sun May 13 2012 - 19:28:33 GMT
To: Postfix users <postfix-users@postfix.org>

Wietse Venema:
> postconf reports the last line number of multi-line text, for
> example:
>
> % cat -n /tmp/main.cf
> 1 some random free text
> 2 other free text
> 3 name = value
>
> % postconf -c /tmp
> postconf: fatal: /tmp/main.cf, line 2: missing '=' after attribute
> name: "some random free text other free text"
>
> The fix is easy: report both the first and last line number.
>
> % postconf -c /tmp
> postconf: fatal: /tmp/main.cf, line 1:2: missing '=' after
> attribute name: "some random free text"

See the patch below.

        Wietse

20120513

        Cleanup: report "first:last" line number for syntax errors
        in main.cf-like files, instead of reporting the last line
        number only. File: util.dict.c.

*** /var/tmp/postfix-2.10-20120426/src/util/dict.c Tue Jan 24 19:41:08 2012
--- src/util/dict.c Sun May 13 10:07:44 2012
***************
*** 424,429 ****
--- 424,430 ----
      VSTRING *buf;
      char *member;
      char *val;
+ int old_lineno;
      int lineno;
      const char *err;
      struct stat st;
***************
*** 434,447 ****
       */
      DICT_FIND_FOR_UPDATE(dict, dict_name);
      buf = vstring_alloc(100);
! lineno = 0;
  
      if (fstat(vstream_fileno(fp), &st) < 0)
          msg_fatal("fstat %s: %m", VSTREAM_PATH(fp));
! while (readlline(buf, fp, &lineno)) {
          if ((err = split_nameval(STR(buf), &member, &val)) != 0)
! msg_fatal("%s, line %d: %s: \"%s\"",
! VSTREAM_PATH(fp), lineno, err, STR(buf));
          if (msg_verbose > 1)
              msg_info("%s: %s = %s", myname, member, val);
          if (dict->update(dict, member, val) != 0)
--- 435,448 ----
       */
      DICT_FIND_FOR_UPDATE(dict, dict_name);
      buf = vstring_alloc(100);
! old_lineno = lineno = 0;
  
      if (fstat(vstream_fileno(fp), &st) < 0)
          msg_fatal("fstat %s: %m", VSTREAM_PATH(fp));
! for (/* void */; readlline(buf, fp, &lineno); old_lineno = lineno) {
          if ((err = split_nameval(STR(buf), &member, &val)) != 0)
! msg_fatal("%s, line %d:%d: %s: \"%s\"",
! VSTREAM_PATH(fp), old_lineno + 1, lineno, err, STR(buf));
          if (msg_verbose > 1)
              msg_info("%s: %s = %s", myname, member, val);
          if (dict->update(dict, member, val) != 0)