Re: dd: exit nonzero on receipt of SIGINT

2017-10-24 Thread Theo Buehler
> So when calling _exit() explicitly, we have to pass a status
> of 128 + signo indeed.

I agree with your analysis. ok



Re: dd: exit nonzero on receipt of SIGINT

2017-10-24 Thread Ingo Schwarze
Hi,

Scott Cheloha wrote on Mon, Oct 23, 2017 at 09:01:04PM -0500:

> Per this bit from POSIX on dd(1):

>> For SIGINT, the dd utility shall interrupt its current processing,
>> write status information to standard error, and exit as though
>> terminated by SIGINT.  It shall take the standard action for all
>> other signals; see [...].

> I think we ought to exit nonzero when SIGINT'd.

I think that is the correct interpretation, because

  http://pubs.opengroup.org/onlinepubs/9699919799/utilities/dd.html

does not describe SIGINT in more detail,

  http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html

clearly says that SIGINT causes *abnormal* termination by default, and

  
http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04_03

says

  If the default action is to terminate the process abnormally, the
  process is terminated as if by a call to _exit(), except that the
  status made available to wait(), waitid(), and waitpid() indicates
  abnormal termination by the signal.

So when calling _exit() explicitly, we have to pass a status
of 128 + signo indeed.


Of course, this can cause a change of behaviour in scripts, but
it seems more likely to me to fix bugs than introduce any.
A script that relied on dd(1) to succeed on SIGINT would seem
quite badly broken to me.

OK to commit?
  Ingo


> Index: bin/dd/misc.c
> ===
> RCS file: /cvs/src/bin/dd/misc.c,v
> retrieving revision 1.21
> diff -u -p -r1.21 misc.c
> --- bin/dd/misc.c 13 Aug 2017 02:06:42 -  1.21
> +++ bin/dd/misc.c 24 Oct 2017 01:38:10 -
> @@ -111,9 +111,8 @@ summaryx(int notused)
>  }
>  
>  void
> -terminate(int notused)
> +terminate(int signo)
>  {
> -
>   summary();
> - _exit(0);
> + _exit(128 + signo);
>  }



dd: exit nonzero on receipt of SIGINT

2017-10-23 Thread Scott Cheloha
Hi,

Per this bit from POSIX on dd(1):

> For SIGINT, the dd utility shall interrupt its current processing,
> write status information to standard error, and exit as though
> terminated by SIGINT.  It shall take the standard action for all
> other signals; see [...].

I think we ought to exit nonzero when SIGINT'd.  FreeBSD, NetBSD,
Solaris, AIX, etc., all do, though they all have chosen their own
exit codes.

NetBSD actually goes so far as to restore the original signal handler
for SIGINT and then raises SIGINT again:

http://cvsweb.netbsd.org/bsdweb.cgi/src/bin/dd/misc.c.diff?r1=1.19=1.20_with_tag=MAIN=h

This is the most unique interpretation I found.  But my gut says that
this is a misreading of "exit as though terminated by SIGINT," and that
exiting with 128 + signo is closer to what was meant.

Thoughts?

--
Scott Cheloha

Index: bin/dd/misc.c
===
RCS file: /cvs/src/bin/dd/misc.c,v
retrieving revision 1.21
diff -u -p -r1.21 misc.c
--- bin/dd/misc.c   13 Aug 2017 02:06:42 -  1.21
+++ bin/dd/misc.c   24 Oct 2017 01:38:10 -
@@ -111,9 +111,8 @@ summaryx(int notused)
 }
 
 void
-terminate(int notused)
+terminate(int signo)
 {
-
summary();
-   _exit(0);
+   _exit(128 + signo);
 }