pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Kunshchikov Vladimir <Vladimir.Kunshchikov@infotecs.ru>
To: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Subject: Re: [patch] pg_dump/pg_restore zerror() and strerror() mishap
Date: Thu, 27 Jul 2017 07:34:22 +0000
Message-ID: <26f687922d9f44ad98c2638e8a8a13de@infotecs.ru> (raw )
In-Reply-To: <20170726164020.zavdyr4en3eheqrr@alvherre.pgsql >
References: <1501082204231.82652@infotecs.ru >
<20170726164020.zavdyr4en3eheqrr@alvherre.pgsql >
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
Hello, Alvaro,
thanks for the suggestions, attached version #3 with all of your requirements met.
--
С уважением,
Владимир Кунщиков
Ведущий программист
Отдел разработки систем обнаружения и предотвращения компьютерных атак
Компания "ИнфоТеКС"
<http://portal.infotecs.int/company/structure/Pages/detailsDepartment.aspx?idDepartment=235&idCom... ;
________________________________
From: Alvaro Herrera <alvherre@2ndquadrant.com>
Sent: Wednesday, July 26, 2017 7:40:20 PM
To: Kunshchikov Vladimir
Cc: pgsql-hackers@postgresql.org
Subject: Re: [HACKERS] [patch] pg_dump/pg_restore zerror() and strerror() mishap
Kunshchikov Vladimir wrote:
> Hello Alvaro, thanks for the feedback, fixed all of your points.
> Attached new version of patch.
Looks great -- it's a lot smaller than the original even. One final
touch -- see cfread(), where we have an #ifdef where we test for
fp->compressedfp; the "#else" branch uses the same code as the
!fp->compressedfp. I think your get_cfp_error can be written more
simply using that form. (Also, your version probably errors or warns
about "code before declaration" in that routine, which is not allowed in
C89.)
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Attachments:
[text/x-patch] strerror-gzerror-zlib-v3.patch (3.1K, ../26f687922d9f44ad98c2638e8a8a13de@infotecs.ru/3-strerror-gzerror-zlib-v3.patch)
download | inline diff:
diff --git a/src/bin/pg_dump/compress_io.c b/src/bin/pg_dump/compress_io.c
index 991fe11e8a..28e5b417c2 100644
--- a/src/bin/pg_dump/compress_io.c
+++ b/src/bin/pg_dump/compress_io.c
@@ -709,5 +709,22 @@ hasSuffix(const char *filename, const char *suffix)
suffix,
suffixlen) == 0;
}
+#endif
+const char *
+get_cfp_error(cfp* fp)
+{
+#ifdef HAVE_LIBZ
+ if(fp->compressedfp){
+ int errnum;
+ static const char fallback[] = "Zlib error";
+ const int maxlen = 255;
+ const char *errmsg = gzerror(fp->compressedfp, &errnum);
+ if(!errmsg || !memchr(errmsg, 0, maxlen))
+ errmsg = fallback;
+
+ return errnum == Z_ERRNO ? strerror(errno) : errmsg;
+ }
#endif
+ return strerror(errno);
+}
diff --git a/src/bin/pg_dump/compress_io.h b/src/bin/pg_dump/compress_io.h
index 8f2e752cba..06b3762233 100644
--- a/src/bin/pg_dump/compress_io.h
+++ b/src/bin/pg_dump/compress_io.h
@@ -65,5 +65,6 @@ extern int cfgetc(cfp *fp);
extern char *cfgets(cfp *fp, char *buf, int len);
extern int cfclose(cfp *fp);
extern int cfeof(cfp *fp);
+extern const char * get_cfp_error(cfp *fp);
#endif
diff --git a/src/bin/pg_dump/pg_backup_directory.c b/src/bin/pg_dump/pg_backup_directory.c
index 79922da8ba..e9c26bc571 100644
--- a/src/bin/pg_dump/pg_backup_directory.c
+++ b/src/bin/pg_dump/pg_backup_directory.c
@@ -352,7 +352,7 @@ _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
lclContext *ctx = (lclContext *) AH->formatData;
if (dLen > 0 && cfwrite(data, dLen, ctx->dataFH) != dLen)
- WRITE_ERROR_EXIT;
+ exit_horribly(modulename, "could not write to output file: %s\n", get_cfp_error(ctx->dataFH));
return;
}
@@ -490,7 +490,7 @@ _WriteByte(ArchiveHandle *AH, const int i)
lclContext *ctx = (lclContext *) AH->formatData;
if (cfwrite(&c, 1, ctx->dataFH) != 1)
- WRITE_ERROR_EXIT;
+ exit_horribly(modulename, "could not write to output file: %s\n", get_cfp_error(ctx->dataFH));
return 1;
}
@@ -519,7 +519,7 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
lclContext *ctx = (lclContext *) AH->formatData;
if (cfwrite(buf, len, ctx->dataFH) != len)
- WRITE_ERROR_EXIT;
+ exit_horribly(modulename, "could not write to output file: %s\n", get_cfp_error(ctx->dataFH));
return;
}
diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c
index f839712945..f17ce78aca 100644
--- a/src/bin/pg_dump/pg_backup_tar.c
+++ b/src/bin/pg_dump/pg_backup_tar.c
@@ -35,6 +35,7 @@
#include "pgtar.h"
#include "common/file_utils.h"
#include "fe_utils/string_utils.h"
+#include "compress_io.h"
#include <sys/stat.h>
#include <ctype.h>
@@ -555,8 +556,12 @@ _tarReadRaw(ArchiveHandle *AH, void *buf, size_t len, TAR_MEMBER *th, FILE *fh)
{
res = GZREAD(&((char *) buf)[used], 1, len, th->zFH);
if (res != len && !GZEOF(th->zFH))
+ {
+ int errnum;
+ const char *errmsg = gzerror(th->zFH, &errnum);
exit_horribly(modulename,
- "could not read from input file: %s\n", strerror(errno));
+ "could not read from input file: %s\n", errnum == Z_ERRNO? strerror(errno) : errmsg);
+ }
}
else
{
view thread (12+ messages) latest in thread
Message-ID: <26f687922d9f44ad98c2638e8a8a13de@infotecs.ru>
Permalink: ../26f687922d9f44ad98c2638e8a8a13de@infotecs.ru/
Also on: postgresql.org/message-id/26f687922d9f44ad98c2638e8a8a13de@infotecs.ru
copy link · copy postgr.es · copy git am
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: Vladimir.Kunshchikov@infotecs.ru, alvherre@2ndquadrant.com
Subject: Re: [patch] pg_dump/pg_restore zerror() and strerror() mishap
In-Reply-To: <26f687922d9f44ad98c2638e8a8a13de@infotecs.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox