Mercurial > hg > xemacs-beta
comparison src/lstream.c @ 5588:2dbefd79b3d3
Prevent SIGPIPEs in deactivate_process().
* process.c (deactivate_process):
Use Lstream_close_noflush on output pipe instead of Lstream_close.
* lstream.c (Lstream_close_noflush):
New. Factored out of Lstream_close.
(Lstream_close): Use Lstream_close_noflush.
* lstream.h (Lstream_close_noflush): Declare it.
author | Stephen J. Turnbull <stephen@xemacs.org> |
---|---|
date | Sat, 29 Oct 2011 01:10:32 +0900 |
parents | 56144c8593a8 |
children | 65d65b52d608 |
comparison
equal
deleted
inserted
replaced
5587:3fde0e346ad7 | 5588:2dbefd79b3d3 |
---|---|
789 | 789 |
790 /* don't check errors here -- best not to risk file descriptor loss */ | 790 /* don't check errors here -- best not to risk file descriptor loss */ |
791 return Lstream_flush (lstr); | 791 return Lstream_flush (lstr); |
792 } | 792 } |
793 | 793 |
794 /* Close the stream without flushing buffers. | |
795 In current practice, this is only useful when a subprocess terminates | |
796 unexpectedly, and the OS closes its pipes without warning. In that case, | |
797 we do not want to flush our output buffers, as there is no longer a pipe | |
798 to write to. | |
799 This nomenclature may deserve review if XEmacs starts getting called as | |
800 a subprocess. */ | |
801 | |
802 int | |
803 Lstream_close_noflush (Lstream *lstr) | |
804 { | |
805 lstr->flags &= ~LSTREAM_FL_IS_OPEN; | |
806 lstr->byte_count = 0; | |
807 /* Note that Lstream_flush() reset all the buffer indices. That way, | |
808 the next call to Lstream_putc(), Lstream_getc(), or Lstream_ungetc() | |
809 on a closed stream will call into the function equivalents, which will | |
810 cause an error. */ | |
811 | |
812 /* We set the pointers to 0 so that we don't lose when this function | |
813 is called more than once on the same object */ | |
814 if (lstr->out_buffer) | |
815 { | |
816 xfree (lstr->out_buffer); | |
817 lstr->out_buffer = 0; | |
818 } | |
819 if (lstr->in_buffer) | |
820 { | |
821 xfree (lstr->in_buffer); | |
822 lstr->in_buffer = 0; | |
823 } | |
824 if (lstr->unget_buffer) | |
825 { | |
826 xfree (lstr->unget_buffer); | |
827 lstr->unget_buffer = 0; | |
828 } | |
829 | |
830 return 0; | |
831 } | |
832 | |
794 /* Close the stream. All data will be flushed out. If the stream is | 833 /* Close the stream. All data will be flushed out. If the stream is |
795 already closed, nothing happens. Note that, even if all data has | 834 already closed, nothing happens. Note that, even if all data has |
796 already been flushed out, the act of closing a stream may generate more | 835 already been flushed out, the act of closing a stream may generate more |
797 data -- for example, if the stream implements some sort of conversion, | 836 data -- for example, if the stream implements some sort of conversion, |
798 such as gzip, there may be special "end-data" that need to be written | 837 such as gzip, there may be special "end-data" that need to be written |
836 if (lstr->imp->closer) | 875 if (lstr->imp->closer) |
837 if ((lstr->imp->closer) (lstr) < 0) | 876 if ((lstr->imp->closer) (lstr) < 0) |
838 rc = -1; | 877 rc = -1; |
839 } | 878 } |
840 | 879 |
841 lstr->flags &= ~LSTREAM_FL_IS_OPEN; | 880 Lstream_close_noflush (lstr); |
842 lstr->byte_count = 0; | |
843 /* Note that Lstream_flush() reset all the buffer indices. That way, | |
844 the next call to Lstream_putc(), Lstream_getc(), or Lstream_ungetc() | |
845 on a closed stream will call into the function equivalents, which will | |
846 cause an error. */ | |
847 | |
848 /* We set the pointers to 0 so that we don't lose when this function | |
849 is called more than once on the same object */ | |
850 if (lstr->out_buffer) | |
851 { | |
852 xfree (lstr->out_buffer); | |
853 lstr->out_buffer = 0; | |
854 } | |
855 if (lstr->in_buffer) | |
856 { | |
857 xfree (lstr->in_buffer); | |
858 lstr->in_buffer = 0; | |
859 } | |
860 if (lstr->unget_buffer) | |
861 { | |
862 xfree (lstr->unget_buffer); | |
863 lstr->unget_buffer = 0; | |
864 } | |
865 | 881 |
866 return rc; | 882 return rc; |
867 } | 883 } |
868 | 884 |
869 | 885 |