Thread: Strange code in initdb

Strange code in initdb

From
Peter Eisentraut
Date:
What is this trying to tell us?
if (ret == -1)    fprintf(stderr,            _("The program \"postgres\" is needed by %s "           "but was not found
inthe same directory as \"%s\".\n"              "Check your installation.\n"),            progname, progname);else
fprintf(stderr,           _("The program \"postgres\" was found by %s "              "but was not the same version as
\"%s\".\n"             "Check your installation.\n"),            progname, progname);
 

Shouldn't the second progname be argv[0] or something else that contains 
the full path?

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/



Re: Strange code in initdb

From
Tom Lane
Date:
Peter Eisentraut <peter_e@gmx.net> writes:
> Shouldn't the second progname be argv[0] or something else that contains 
> the full path?

argv[0] doesn't necessarily contain the full path.  Is it worth calling
find_my_exec() here to produce an absolute path?  Possibly...
        regards, tom lane


Re: Strange code in initdb

From
Bruce Momjian
Date:
I have modified these reports so they print the full path used.

Typical pg_dumpall output is:

    The program "pg_dump" is needed by pg_dumpall but was not found in the
    same directory as "/usr/local/postgres/bin/pg_dumpall".
    Check your installation.


---------------------------------------------------------------------------

Peter Eisentraut wrote:
> What is this trying to tell us?
>
>     if (ret == -1)
>         fprintf(stderr,
>                 _("The program \"postgres\" is needed by %s "
>                "but was not found in the same directory as \"%s\".\n"
>                   "Check your installation.\n"),
>                 progname, progname);
>     else
>         fprintf(stderr,
>                 _("The program \"postgres\" was found by %s "
>                   "but was not the same version as \"%s\".\n"
>                   "Check your installation.\n"),
>                 progname, progname);
>
> Shouldn't the second progname be argv[0] or something else that contains
> the full path?
>
> --
> Peter Eisentraut
> http://developer.postgresql.org/~petere/
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
>       subscribe-nomail command to majordomo@postgresql.org so that your
>       message can get through to the mailing list cleanly
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: src/bin/initdb/initdb.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/initdb/initdb.c,v
retrieving revision 1.61
diff -c -c -r1.61 initdb.c
*** src/bin/initdb/initdb.c    12 Oct 2004 21:54:42 -0000    1.61
--- src/bin/initdb/initdb.c    15 Oct 2004 04:16:47 -0000
***************
*** 2268,2285 ****
      if ((ret = find_other_exec(argv[0], "postgres", PG_VERSIONSTR,
                                 backend_exec)) < 0)
      {
          if (ret == -1)
              fprintf(stderr,
                      _("The program \"postgres\" is needed by %s "
!                    "but was not found in the same directory as \"%s\".\n"
                        "Check your installation.\n"),
!                     progname, progname);
          else
              fprintf(stderr,
!                     _("The program \"postgres\" was found by %s "
!                       "but was not the same version as \"%s\".\n"
                        "Check your installation.\n"),
!                     progname, progname);
          exit(1);
      }

--- 2268,2291 ----
      if ((ret = find_other_exec(argv[0], "postgres", PG_VERSIONSTR,
                                 backend_exec)) < 0)
      {
+         char full_path[MAXPGPATH];
+
+         if (find_my_exec(argv[0], full_path) < 0)
+             StrNCpy(full_path, progname, MAXPGPATH);
+
          if (ret == -1)
              fprintf(stderr,
                      _("The program \"postgres\" is needed by %s "
!                       "but was not found in the\n"
!                       "same directory as \"%s\".\n"
                        "Check your installation.\n"),
!                     progname, full_path);
          else
              fprintf(stderr,
!                     _("The program \"postgres\" was found by \"%s\"\n"
!                       "but was not the same version as %s.\n"
                        "Check your installation.\n"),
!                     full_path, progname);
          exit(1);
      }

Index: src/bin/pg_ctl/pg_ctl.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/pg_ctl/pg_ctl.c,v
retrieving revision 1.35
diff -c -c -r1.35 pg_ctl.c
*** src/bin/pg_ctl/pg_ctl.c    13 Oct 2004 10:35:05 -0000    1.35
--- src/bin/pg_ctl/pg_ctl.c    15 Oct 2004 04:16:50 -0000
***************
*** 524,540 ****
          if ((ret = find_other_exec(argv0, "postmaster", PM_VERSIONSTR,
                                     postmaster_path)) < 0)
          {
              if (ret == -1)
                  write_stderr(_("The program \"postmaster\" is needed by %s "
!                             "but was not found in the same directory as "
!                                "\"%s\".\n"
                                 "Check your installation.\n"),
!                              progname, progname);
              else
!                 write_stderr(_("The program \"postmaster\" was found by %s "
!                                "but was not the same version as \"%s\".\n"
                                 "Check your installation.\n"),
!                              progname, progname);
              exit(1);
          }
          postgres_path = postmaster_path;
--- 524,545 ----
          if ((ret = find_other_exec(argv0, "postmaster", PM_VERSIONSTR,
                                     postmaster_path)) < 0)
          {
+             char full_path[MAXPGPATH];
+
+             if (find_my_exec(argv0, full_path) < 0)
+                 StrNCpy(full_path, progname, MAXPGPATH);
+
              if (ret == -1)
                  write_stderr(_("The program \"postmaster\" is needed by %s "
!                                "but was not found in the\n"
!                                "same directory as \"%s\".\n"
                                 "Check your installation.\n"),
!                              progname, full_path);
              else
!                 write_stderr(_("The program \"postmaster\" was found by \"%s\"\n"
!                                "but was not the same version as %s.\n"
                                 "Check your installation.\n"),
!                              full_path, progname);
              exit(1);
          }
          postgres_path = postmaster_path;
Index: src/bin/pg_dump/pg_dumpall.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v
retrieving revision 1.52
diff -c -c -r1.52 pg_dumpall.c
*** src/bin/pg_dump/pg_dumpall.c    6 Oct 2004 17:02:02 -0000    1.52
--- src/bin/pg_dump/pg_dumpall.c    15 Oct 2004 04:16:51 -0000
***************
*** 139,156 ****
      if ((ret = find_other_exec(argv[0], "pg_dump", PG_VERSIONSTR,
                                 pg_dump_bin)) < 0)
      {
          if (ret == -1)
              fprintf(stderr,
                      _("The program \"pg_dump\" is needed by %s "
!                    "but was not found in the same directory as \"%s\".\n"
                        "Check your installation.\n"),
!                     progname, progname);
          else
              fprintf(stderr,
!                     _("The program \"pg_dump\" was found by %s "
!                       "but was not the same version as \"%s\".\n"
                        "Check your installation.\n"),
!                     progname, progname);
          exit(1);
      }

--- 139,162 ----
      if ((ret = find_other_exec(argv[0], "pg_dump", PG_VERSIONSTR,
                                 pg_dump_bin)) < 0)
      {
+         char full_path[MAXPGPATH];
+
+         if (find_my_exec(argv[0], full_path) < 0)
+             StrNCpy(full_path, progname, MAXPGPATH);
+
          if (ret == -1)
              fprintf(stderr,
                      _("The program \"pg_dump\" is needed by %s "
!                       "but was not found in the\n"
!                       "same directory as \"%s\".\n"
                        "Check your installation.\n"),
!                     progname, full_path);
          else
              fprintf(stderr,
!                     _("The program \"pg_dump\" was found by \"%s\"\n"
!                       "but was not the same version as %s.\n"
                        "Check your installation.\n"),
!                     full_path, progname);
          exit(1);
      }


Re: Strange code in initdb

From
Peter Eisentraut
Date:
Am Freitag, 15. Oktober 2004 06:24 schrieb Bruce Momjian:
> I have modified these reports so they print the full path used.
>
> Typical pg_dumpall output is:
>
>  The program "pg_dump" is needed by pg_dumpall but was not found in the
>  same directory as "/usr/local/postgres/bin/pg_dumpall".
>  Check your installation.

Yes, that is what I thought it should have been.  There are similar pieces of 
code in pg_dumpall, initdb, pg_ctl, and maybe elsewhere.  Did you get them 
all?

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/


Re: Strange code in initdb

From
Bruce Momjian
Date:
Peter Eisentraut wrote:
> Am Freitag, 15. Oktober 2004 06:24 schrieb Bruce Momjian:
> > I have modified these reports so they print the full path used.
> >
> > Typical pg_dumpall output is:
> >
> >  The program "pg_dump" is needed by pg_dumpall but was not found in the
> >  same directory as "/usr/local/postgres/bin/pg_dumpall".
> >  Check your installation.
> 
> Yes, that is what I thought it should have been.  There are similar pieces of 
> code in pg_dumpall, initdb, pg_ctl, and maybe elsewhere.  Did you get them 
> all?

Yes.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073