1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#! /bin/sh -e
# DP: Don't ignore write failures on standard streams.
dir=
if [ $# -eq 3 -a "$2" = '-d' ]; then
pdir="-d $3"
dir="$3/"
elif [ $# -ne 1 ]; then
echo >&2 "usage: `basename $0`: -patch|-unpatch [-d <srcdir>]"
exit 1
fi
case "$1" in
-patch)
patch $pdir -f --no-backup-if-mismatch -p0 < $0
#cd ${dir}gcc && autoconf
;;
-unpatch)
patch $pdir -f --no-backup-if-mismatch -R -p0 < $0
#rm ${dir}gcc/configure
;;
*)
echo >&2 "usage: `basename $0`: -patch|-unpatch [-d <srcdir>]"
exit 1
esac
exit 0
From: Ben Hutchings <ben@decadentplace.org.uk>
To: 283108@bugs.debian.org, control@bugs.debian.org
Subject: Bug#283108: python2.3: ignores write failure
Date: Mon, 29 Nov 2004 10:40:14 +0000
tags 283108 + patch
thanks
Each Python file object has a pointer to the function to be called on
the C stream when close is called on the file object. Normally this is
fclose, but Python doesn't want the standard streams closed so their
file objects are created with the function pointer set to NULL, making
close a no-op on the underlying files. This patch changes the function
for stdout and stderr to be fflush, so that the streams stay open but
write errors are detected at the time of an explicit close. I don't see
the relevance of the exitfuncs.
--- Python/sysmodule.c.~2.126.~ 2004-08-12 20:19:17.000000000 +0200
+++ Python/sysmodule.c 2004-12-02 09:59:09.058953816 +0100
@@ -927,6 +927,13 @@ settrace() -- set the global debug traci
)
/* end of sys_doc */ ;
+static int
+_check_and_flush (FILE *stream)
+{
+ int prev_fail = ferror (stream);
+ return fflush (stream) || prev_fail ? EOF : 0;
+}
+
PyObject *
_PySys_Init(void)
{
@@ -941,8 +948,8 @@ _PySys_Init(void)
sysdict = PyModule_GetDict(m);
sysin = PyFile_FromFile(stdin, "<stdin>", "r", NULL);
- sysout = PyFile_FromFile(stdout, "<stdout>", "w", NULL);
- syserr = PyFile_FromFile(stderr, "<stderr>", "w", NULL);
+ sysout = PyFile_FromFile(stdout, "<stdout>", "w", _check_and_flush);
+ syserr = PyFile_FromFile(stderr, "<stderr>", "w", _check_and_flush);
if (PyErr_Occurred())
return NULL;
#ifdef MS_WINDOWS
|