[FFmpeg-devel] [PATCH] ffmpeg: check value of write syscall
gajjanag at mit.edu
Sat Jul 25 16:47:39 CEST 2015
On Sat, Jul 25, 2015 at 10:31 AM, Nicolas George <george at nsup.org> wrote:
> Le septidi 7 thermidor, an CCXXIII, Ganesh Ajjanagadde a écrit :
>> >> - write(2/*STDERR_FILENO*/, "Received > 3 system signals, hard exiting\n",
>> >> + num_write = write(2/*STDERR_FILENO*/, "Received > 3 system signals, hard exiting\n",
>> >> strlen("Received > 3 system signals, hard exiting\n"));
>> >> -
>> >> + if(num_write < 0)
>> >> + perror("write");
>> Ok. How about making this errno set by write (if any) become part of
>> the exit code, e.g by or'ing?
>> As it stands, the 123 in the exit status sounds quite arbitrary, so
>> this should be ok,
>> and gives the parent a chance to distinguish between the two cases.
> IMHO, you are wasting your time here: this error message is not important,
> it is only for people who did not notice they had the elbow on the Ctrl key
> while their cat was pawing the C key.
> More seriously: this message is for informing human users that the reason
> for stopping is three signals. The 123 return code is for informing the
> parent process of the same condition. They are entirely redundant
> (especially with a good shell that has an option to print the error code of
> a failed command), and the exit code can not fail. Therefore, we really do
> not care if writing the error message fails.
The reason I attempted a fix is because books on C/systems programming
are often full of advice like "always check the return value of a
syscall, as they can fail".
I guess this is part of GCC's rationale for -Wunused-result.
The explanation above makes sense, so above advice ought to be "almost always".
> Nicolas George
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
More information about the ffmpeg-devel