Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VoEl8-0000mg-C3 for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Dec 2013 15:53:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VoEl7-0003tC-Qu for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Dec 2013 15:53:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VoEl6-0003re-5P for pgsql-bugs@postgresql.org; Wed, 04 Dec 2013 15:53:04 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VoEl2-0000un-TI for pgsql-bugs@postgresql.org; Wed, 04 Dec 2013 15:53:03 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1VoEkz-0000nH-F0; Wed, 04 Dec 2013 10:52:57 -0500 Date: Wed, 4 Dec 2013 10:52:57 -0500 From: Bruce Momjian To: Alvaro Herrera Cc: Tom Lane , nicolas@marchildon.net, pgsql-bugs@postgresql.org Subject: Re: BUG #8139: initdb: Misleading error message when current user not in /etc/passwd Message-ID: <20131204155257.GD17114@momjian.us> References: <296.1367950228@sss.pgh.pa.us> <20130507181904.GA26800@eldon.alvh.no-ip.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="gatW/ieO32f1wygP" Content-Disposition: inline In-Reply-To: <20130507181904.GA26800@eldon.alvh.no-ip.org> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --gatW/ieO32f1wygP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, May 7, 2013 at 02:19:05PM -0400, Alvaro Herrera wrote: > Tom Lane wrote: > > nicolas@marchildon.net writes: > > > > The man page says: > > > > > RETURN VALUE > > > The getpwnam() and getpwuid() functions return a pointer to a > > > passwd > > > structure, or NULL if the matching entry is not found or an > > > error > > > occurs. If an error occurs, errno is set appropriately. If one > > > wants > > > to check errno after the call, it should be set to zero before > > > the > > > call. > > > > AFAICS, getpwuid is not honoring its specification here: it failed to > > set errno. I don't see that suppressing the strerror result would add > > anything much. > > Well, in this case no error occured, but no matching entry was found. > The wording in the manpage is explicit that there not being an entry is > not an error. I have developed the attached patch to fix this and another instance I saw. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + Everyone has their own god. + --gatW/ieO32f1wygP Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="passwd.diff" diff --git a/contrib/pg_upgrade/util.c b/contrib/pg_upgrade/util.c new file mode 100644 index a67bd64..9ad4220 *** a/contrib/pg_upgrade/util.c --- b/contrib/pg_upgrade/util.c *************** get_user_info(char **user_name) *** 228,234 **** user_id = 1; #endif ! *user_name = pg_strdup(pw->pw_name); return user_id; } --- 228,237 ---- user_id = 1; #endif ! if (pw) ! *user_name = pg_strdup(pw->pw_name); ! else ! *user_name = NULL; return user_id; } diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c new file mode 100644 index 30e3701..8665595 *** a/src/bin/initdb/initdb.c --- b/src/bin/initdb/initdb.c *************** get_id(void) *** 795,801 **** { fprintf(stderr, _("%s: could not obtain information about current user: %s\n"), ! progname, strerror(errno)); exit(1); } #else /* the windows code */ --- 795,801 ---- { fprintf(stderr, _("%s: could not obtain information about current user: %s\n"), ! progname, errno ? strerror(errno) : "not an operating system user"); exit(1); } #else /* the windows code */ --gatW/ieO32f1wygP Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --gatW/ieO32f1wygP--