From: Maxim Ostapenko <m.ostapenko@partner.samsung.com>
To: "Joseph S. Myers" <joseph@codesourcery.com>,
Jakub Jelinek <jakub@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>, Jeff Law <law@redhat.com>,
Yury Gribov <y.gribov@samsung.com>,
Slava Garbuzov <v.garbuzov@samsung.com>,
Maxim Ostapenko <chefmax7@gmail.com>,
ian@airs.com, dj@redhat.com
Subject: [PATCH 1/2] Extend libiberty to allow append stdout and stderr to existing files.
Date: Thu, 11 Sep 2014 16:18:00 -0000 [thread overview]
Message-ID: <5411CB3E.3000907@partner.samsung.com> (raw)
In-Reply-To: <Pine.LNX.4.64.1409101634020.12853@digraph.polyomino.org.uk>
[-- Attachment #1: Type: text/plain, Size: 274 bytes --]
Working on ICE debugging patch, I've noted that libiberty interface
doesn't allow to append stdout and stderr to existing files.
This small patch provides two new flags for pex_run and extends
open_write interface to handle the issue.
Does this patch look sane?
-Maxim
[-- Attachment #2: libiberty_allow_append-2.diff --]
[-- Type: text/x-patch, Size: 6171 bytes --]
libiberty/ChangeLog:
2014-09-11 Max Ostapenko <m.ostapenko@partner.samsung.com>
* pex-common.h (struct pex_funcs): Add new parameter for open_write field.
* pex-unix.c (pex_unix_open_write): Add support for new parameter.
* pex-djgpp.c (pex_djgpp_open_write): Likewise.
* pex-win32.c (pex_win32_open_write): Likewise.
* pex-common.c (pex_run_in_environment): Likewise.
include/ChangeLog:
2014-09-11 Max Ostapenko <m.ostapenko@partner.samsung.com>
* libiberty.h (PEX_STDOUT_APPEND): New flag.
(PEX_STDERR_APPEND): Likewise.
diff --git a/include/libiberty.h b/include/libiberty.h
index 56b8b43..bcc1f9a 100644
--- a/include/libiberty.h
+++ b/include/libiberty.h
@@ -445,6 +445,11 @@ extern struct pex_obj *pex_init (int flags, const char *pname,
on Unix. */
#define PEX_BINARY_ERROR 0x80
+/* Append stdout to existing file instead of truncating it. */
+#define PEX_STDOUT_APPEND 0x100
+
+/* Thes same as PEX_STDOUT_APPEND, but for STDERR. */
+#define PEX_STDERR_APPEND 0x200
/* Execute one program. Returns NULL on success. On error returns an
error string (typically just the name of a system call); the error
diff --git a/libiberty/pex-common.c b/libiberty/pex-common.c
index 6fd3fde..146010a 100644
--- a/libiberty/pex-common.c
+++ b/libiberty/pex-common.c
@@ -267,7 +267,8 @@ pex_run_in_environment (struct pex_obj *obj, int flags, const char *executable,
if (out < 0)
{
out = obj->funcs->open_write (obj, outname,
- (flags & PEX_BINARY_OUTPUT) != 0);
+ (flags & PEX_BINARY_OUTPUT) != 0,
+ (flags & PEX_STDOUT_APPEND) != 0);
if (out < 0)
{
*err = errno;
@@ -319,8 +320,9 @@ pex_run_in_environment (struct pex_obj *obj, int flags, const char *executable,
}
else
{
- errdes = obj->funcs->open_write (obj, errname,
- (flags & PEX_BINARY_ERROR) != 0);
+ errdes = obj->funcs->open_write (obj, errname,
+ (flags & PEX_BINARY_ERROR) != 0,
+ (flags & PEX_STDERR_APPEND) != 0);
if (errdes < 0)
{
*err = errno;
diff --git a/libiberty/pex-common.h b/libiberty/pex-common.h
index af338e6..b6db248 100644
--- a/libiberty/pex-common.h
+++ b/libiberty/pex-common.h
@@ -104,7 +104,7 @@ struct pex_funcs
/* Open file NAME for writing. If BINARY is non-zero, open in
binary mode. Return >= 0 on success, -1 on error. */
int (*open_write) (struct pex_obj *, const char */* name */,
- int /* binary */);
+ int /* binary */, int /* append */);
/* Execute a child process. FLAGS, EXECUTABLE, ARGV, ERR are from
pex_run. IN, OUT, ERRDES, TOCLOSE are all descriptors, from
open_read, open_write, or pipe, or they are one of STDIN_FILE_NO,
diff --git a/libiberty/pex-djgpp.c b/libiberty/pex-djgpp.c
index 0721139..b014ffa 100644
--- a/libiberty/pex-djgpp.c
+++ b/libiberty/pex-djgpp.c
@@ -43,7 +43,7 @@ extern int errno;
#endif
static int pex_djgpp_open_read (struct pex_obj *, const char *, int);
-static int pex_djgpp_open_write (struct pex_obj *, const char *, int);
+static int pex_djgpp_open_write (struct pex_obj *, const char *, int, int);
static pid_t pex_djgpp_exec_child (struct pex_obj *, int, const char *,
char * const *, char * const *,
int, int, int, int,
@@ -90,10 +90,12 @@ pex_djgpp_open_read (struct pex_obj *obj ATTRIBUTE_UNUSED,
static int
pex_djgpp_open_write (struct pex_obj *obj ATTRIBUTE_UNUSED,
- const char *name, int binary)
+ const char *name, int binary, int append)
{
/* Note that we can't use O_EXCL here because gcc may have already
created the temporary file via make_temp_file. */
+ if (append)
+ return -1;
return open (name,
(O_WRONLY | O_CREAT | O_TRUNC
| (binary ? O_BINARY : O_TEXT)),
diff --git a/libiberty/pex-unix.c b/libiberty/pex-unix.c
index addf8ee..0715115 100644
--- a/libiberty/pex-unix.c
+++ b/libiberty/pex-unix.c
@@ -301,7 +301,7 @@ pex_wait (struct pex_obj *obj, pid_t pid, int *status, struct pex_time *time)
static void pex_child_error (struct pex_obj *, const char *, const char *, int)
ATTRIBUTE_NORETURN;
static int pex_unix_open_read (struct pex_obj *, const char *, int);
-static int pex_unix_open_write (struct pex_obj *, const char *, int);
+static int pex_unix_open_write (struct pex_obj *, const char *, int, int);
static pid_t pex_unix_exec_child (struct pex_obj *, int, const char *,
char * const *, char * const *,
int, int, int, int,
@@ -350,11 +350,12 @@ pex_unix_open_read (struct pex_obj *obj ATTRIBUTE_UNUSED, const char *name,
static int
pex_unix_open_write (struct pex_obj *obj ATTRIBUTE_UNUSED, const char *name,
- int binary ATTRIBUTE_UNUSED)
+ int binary ATTRIBUTE_UNUSED, int append)
{
/* Note that we can't use O_EXCL here because gcc may have already
created the temporary file via make_temp_file. */
- return open (name, O_WRONLY | O_CREAT | O_TRUNC, PUBLIC_MODE);
+ return open (name, O_WRONLY | O_CREAT
+ | (append ? O_APPEND : O_TRUNC), PUBLIC_MODE);
}
/* Close a file. */
diff --git a/libiberty/pex-win32.c b/libiberty/pex-win32.c
index 8b9d4f0..66d2f11 100644
--- a/libiberty/pex-win32.c
+++ b/libiberty/pex-win32.c
@@ -78,7 +78,7 @@ backslashify (char *s)
}
static int pex_win32_open_read (struct pex_obj *, const char *, int);
-static int pex_win32_open_write (struct pex_obj *, const char *, int);
+static int pex_win32_open_write (struct pex_obj *, const char *, int, int);
static pid_t pex_win32_exec_child (struct pex_obj *, int, const char *,
char * const *, char * const *,
int, int, int, int,
@@ -126,10 +126,12 @@ pex_win32_open_read (struct pex_obj *obj ATTRIBUTE_UNUSED, const char *name,
static int
pex_win32_open_write (struct pex_obj *obj ATTRIBUTE_UNUSED, const char *name,
- int binary)
+ int binary, int append)
{
/* Note that we can't use O_EXCL here because gcc may have already
created the temporary file via make_temp_file. */
+ if (append)
+ return -1;
return _open (name,
(_O_WRONLY | _O_CREAT | _O_TRUNC
| (binary ? _O_BINARY : _O_TEXT)),
next prev parent reply other threads:[~2014-09-11 16:18 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-04 17:03 [PATCH] Add patch for debugging compiler ICEs Maxim Ostapenko
2014-08-12 16:14 ` [PING][PATCH] " Maxim Ostapenko
2014-08-19 13:58 ` Fwd: [PATCH] " Maxim Ostapenko
2014-08-28 7:31 ` [Ping v2][PATCH] " Maxim Ostapenko
2014-09-05 14:16 ` [Ping v3][PATCH] " Maxim Ostapenko
2014-09-09 22:51 ` [Ping v2][PATCH] " Joseph S. Myers
2014-09-10 4:57 ` Jakub Jelinek
2014-09-10 16:37 ` Joseph S. Myers
2014-09-11 16:18 ` Maxim Ostapenko [this message]
2014-09-11 16:33 ` [PATCH 1/2] Extend libiberty to allow append stdout and stderr to existing files Ian Lance Taylor
2014-09-11 16:20 ` [PATCH 2/2] Add patch for debugging compiler ICEs Maxim Ostapenko
2014-09-18 15:37 ` [PING] " Maxim Ostapenko
2014-09-18 22:17 ` Joseph S. Myers
2014-09-19 3:33 ` Yury Gribov
2014-09-23 7:15 ` Maxim Ostapenko
2014-09-25 19:05 ` Jeff Law
2014-09-26 8:04 ` Maxim Ostapenko
2014-09-26 13:11 ` Rainer Orth
2014-09-26 13:24 ` Thomas Schwinge
2014-09-26 13:32 ` Maxim Ostapenko
2014-09-26 16:18 ` Jeff Law
2014-09-26 16:31 ` Thomas Schwinge
2014-09-26 16:32 ` Jeff Law
2015-01-23 1:42 ` H.J. Lu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5411CB3E.3000907@partner.samsung.com \
--to=m.ostapenko@partner.samsung.com \
--cc=chefmax7@gmail.com \
--cc=dj@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=ian@airs.com \
--cc=jakub@redhat.com \
--cc=joseph@codesourcery.com \
--cc=law@redhat.com \
--cc=v.garbuzov@samsung.com \
--cc=y.gribov@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).