slang-users mailing list

[2007 Date Index] [2007 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: [slang-users] Re: need to send signals two times


=?UTF-8?Q?J=C3=B6rg?= Sommer <joerg@xxxxxxxxxxxx> wrote:
>Does jed (and jed-script) suffer from the same problem? This explains,
>why my process doesn't read and quit. I think the return from fopen() and
>the SIGHUP happen nearly at the same time or the return from fopen() a
>little bit before. So the fopen() is suspended again, but nobody ever
>does open the pipe.

I also think that it is useful to point out that the slang stdio
functions (fopen, fputs, fgets, ...) are wrappers around the
corresponding C library functions.  Unfortunately, the behavior of the
C library stdio functions in the presence of signals is poorly defined.

For example, consider the C library fputs function.  This function
writes a string to a file descriptor.  It returns EOF upon error, and
a non-negative integer upon sucess.  In particular, it may not may not
return the number of characters sucessfully written, and the
non-negative value 0 is a perfectly acceptable return value from this
function.  What happens if the underlying low-level write function was
interrupted by a signal whose disposition was set to not to restart
system calls?  The fputs function may have written out some of the
bytes but not all of them but the ambiguity of the return value does
not permit the exact number written to be determined in a portable
manner.   As a result, a file may become corrupted because information
has been lost and there is no portable way to recover from this
situation.

For reasons such as this, I do not trust nor would use the stdio
functions for mission-critical operations.  Instead, use the
lower-level read/write functions since they have well defined
behaviors in the presence of signals.

--John



[2007 date index] [2007 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]