[request-sponsor] Adding status support to dd

2007-04-06 Thread Frank Van Der Linden
Matty wrote:
 Howdy,

 Most Linux and BSD distributions ship with a version of dd that
 displays the status of a copy operation when a SIGUSR1 signal is
 received. 
Just a correction. I know this is late in the game, and I don't want to 
prolong the discussion much, since this isn't the right list, but: *BSD 
uses SIGINFO, which is generated via the tty code when the user presses 
^T. Several tools implement a status handler that uses SIGINFO.

I think OpenSolaris doesn't have this functionality (it was a 
BSD-specific piece of functionality), hence another signal would have to 
be used, but that also makes it less useful (typing ^T to the tty where 
the command is running, vs. having to go to another window, doing a 
pgrep, and then a kill -USR1).

- Frank




[request-sponsor] Adding status support to dd

2007-04-06 Thread James Carlson
Frank Van Der Linden writes:
 Matty wrote:
  Howdy,
 
  Most Linux and BSD distributions ship with a version of dd that
  displays the status of a copy operation when a SIGUSR1 signal is
  received. 
 Just a correction. I know this is late in the game, and I don't want to 
 prolong the discussion much, since this isn't the right list, but: *BSD 
 uses SIGINFO, which is generated via the tty code when the user presses 
 ^T. Several tools implement a status handler that uses SIGINFO.

CR 6310532, now celebrating its first birthday.

-- 
James Carlson, Solaris Networking  james.d.carlson at sun.com
Sun Microsystems / 1 Network Drive 71.232W   Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757   42.496N   Fax +1 781 442 1677



[request-sponsor] Adding status support to dd

2007-04-06 Thread James Carlson
James Carlson writes:
 Frank Van Der Linden writes:
  Matty wrote:
   Howdy,
  
   Most Linux and BSD distributions ship with a version of dd that
   displays the status of a copy operation when a SIGUSR1 signal is
   received. 
  Just a correction. I know this is late in the game, and I don't want to 
  prolong the discussion much, since this isn't the right list, but: *BSD 
  uses SIGINFO, which is generated via the tty code when the user presses 
  ^T. Several tools implement a status handler that uses SIGINFO.
 
 CR 6310532, now celebrating its first birthday.

Ah, surprise.  I filed it even longer ago.  ;-}

-- 
James Carlson, Solaris Networking  james.d.carlson at sun.com
Sun Microsystems / 1 Network Drive 71.232W   Vox +1 781 442 2084
MS UBUR02-212 / Burlington MA 01803-2757   42.496N   Fax +1 781 442 1677



[request-sponsor] Adding status support to dd

2007-04-06 Thread Bart Smaalders
James Carlson wrote:
 James Carlson writes:
 Frank Van Der Linden writes:
 Matty wrote:
 Howdy,

 Most Linux and BSD distributions ship with a version of dd that
 displays the status of a copy operation when a SIGUSR1 signal is
 received. 
 Just a correction. I know this is late in the game, and I don't want to 
 prolong the discussion much, since this isn't the right list, but: *BSD 
 uses SIGINFO, which is generated via the tty code when the user presses 
 ^T. Several tools implement a status handler that uses SIGINFO.
 CR 6310532, now celebrating its first birthday.
 
 Ah, surprise.  I filed it even longer ago.  ;-}
 

Sounds like we could implement the Linux behavior wrt
SIGUSR1 and then add SIGINFO support trivially once
that appeared in the terminal handler...

- Bart


-- 
Bart Smaalders  Solaris Kernel Performance
barts at cyber.eng.sun.com  http://blogs.sun.com/barts



[request-sponsor] Adding status support to dd

2007-04-06 Thread david.co...@sun.com
 Just a correction. I know this is late in the game, and I don't want to 
 prolong the discussion much, since this isn't the right list, but: *BSD uses 
 SIGINFO, which is generated via the tty code when the user presses ^T. 
 Several tools implement a status handler that uses SIGINFO.

 I think OpenSolaris doesn't have this functionality (it was a BSD-specific 
 piece of functionality), hence another signal would have to be used, but that 
 also makes it less useful (typing ^T to the tty where the command is running, 
 vs. having to go to another window, doing a pgrep, and then a kill -USR1).

Note there is an outstanding RFE open on this

6310532 Solaris ldterm could support BSD's SIGINFO/VSTATUS once
again

dsc



[request-sponsor] Adding status support to dd

2007-04-05 Thread Bart Smaalders
Matty wrote:
 On 4/5/07, James Carlson james.d.carlson at sun.com wrote:
 Darren J Moffat writes:
  Matty wrote:
   Howdy,
  
   Most Linux and BSD distributions ship with a version of dd that
   displays the status of a copy operation when a SIGUSR1 signal is
   received. For some reason /usr/bin/dd on Solaris hosts doesn't 
 contain
   this capability, and I would like to add it. After reading through 
 the
   source code for dd.c, it looks like adding this support would be as
   simple as installing a signal handler for SIGUSR1, and having it call
   the function stats. I am attaching code (which I copied from the dd
   that ships with Fedora Core Linux)
 
  What license is that dd code you copied under ?
 
  You can't just copy code like that without considering the licenses.

 Indeed.  That's GPLv2 code, which would require OpenSolaris dd to
 become GPLv2 as well.

 That can't be done.  Either start provably from scratch or use
 software under a compatible license.
 
 Your absolutely right, and Stephen Hahn was nice enough to point this
 out in an email last night. Since the existing code uses signal to
 register the SIGINT signal handler (I reckon the issues Bart mentioned
 are minimized since it exit()'s after printing the statistics):
 
 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
 {
   (void) signal(SIGINT, term);
 }
 
 Do folks see any issue with using similar code to add a SIGUSR1 signal 
 handler?:
 
 if (signal(SIGUSR1, SIG_IGN) != SIG_IGN)
 {
(void) signal(SIGUSR1, stats);
 }
 
 This would minmize the amount of code that would need to be added to
 get stats functionality, and would address the license issues. If this
 solution isn't acceptable, could I get a sponsor assigned to help me
 work through a community approved solution?
 
 Thanks,
 - Ryan

Note that SA_RESTART must be set; otherwise dd from a pipe or other slow
device will return an error condition.  I also like Casper's suggestion 
to use sprintf and write to stderr, since sprintf is now
async-signal-safe.

I can help you get this into shape.

- Bart



-- 
Bart Smaalders  Solaris Kernel Performance
barts at cyber.eng.sun.com  http://blogs.sun.com/barts



[request-sponsor] Adding status support to dd

2007-04-05 Thread casper....@sun.com

Note that SA_RESTART must be set; otherwise dd from a pipe or other slow
device will return an error condition.  I also like Casper's suggestion 
to use sprintf and write to stderr, since sprintf is now
async-signal-safe.

Note also that there are three gettext()s of constant strings;
these should probably be cached at the beginning of the program
so that we completely avoid any unsafe pitfalls.

const char *instr = gettext(%llu+%llu records in\n;
const char *outstr = gettext(%llu+%llu records out\n;
const char *truncstr = gettext(%llu truncated record(s)\n;

Casper



[request-sponsor] Adding status support to dd

2007-04-05 Thread Bonnie Corwin
Hi Bart,

I assume your comment about helping to get this into shape means you 
will sponsor Ryan's work.  Can someone file a bug, if there isn't one 
already, so I can add this to the table?

Thanks.

Bonnie

Bart Smaalders wrote:
 Matty wrote:
 
 On 4/5/07, James Carlson james.d.carlson at sun.com wrote:

 Darren J Moffat writes:
  Matty wrote:
   Howdy,
  
   Most Linux and BSD distributions ship with a version of dd that
   displays the status of a copy operation when a SIGUSR1 signal is
   received. For some reason /usr/bin/dd on Solaris hosts doesn't 
 contain
   this capability, and I would like to add it. After reading 
 through the
   source code for dd.c, it looks like adding this support would be as
   simple as installing a signal handler for SIGUSR1, and having it 
 call
   the function stats. I am attaching code (which I copied from the dd
   that ships with Fedora Core Linux)
 
  What license is that dd code you copied under ?
 
  You can't just copy code like that without considering the licenses.

 Indeed.  That's GPLv2 code, which would require OpenSolaris dd to
 become GPLv2 as well.

 That can't be done.  Either start provably from scratch or use
 software under a compatible license.


 Your absolutely right, and Stephen Hahn was nice enough to point this
 out in an email last night. Since the existing code uses signal to
 register the SIGINT signal handler (I reckon the issues Bart mentioned
 are minimized since it exit()'s after printing the statistics):

 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
 {
   (void) signal(SIGINT, term);
 }

 Do folks see any issue with using similar code to add a SIGUSR1 signal 
 handler?:

 if (signal(SIGUSR1, SIG_IGN) != SIG_IGN)
 {
(void) signal(SIGUSR1, stats);
 }

 This would minmize the amount of code that would need to be added to
 get stats functionality, and would address the license issues. If this
 solution isn't acceptable, could I get a sponsor assigned to help me
 work through a community approved solution?

 Thanks,
 - Ryan
 
 
 Note that SA_RESTART must be set; otherwise dd from a pipe or other slow
 device will return an error condition.  I also like Casper's suggestion 
 to use sprintf and write to stderr, since sprintf is now
 async-signal-safe.
 
 I can help you get this into shape.
 
 - Bart
 
 
 



[request-sponsor] Adding status support to dd

2007-04-05 Thread Bart Smaalders
Bonnie Corwin wrote:
 Hi Bart,
 
 I assume your comment about helping to get this into shape means you 
 will sponsor Ryan's work.  Can someone file a bug, if there isn't one 
 already, so I can add this to the table?
 
 Thanks.
 
 Bonnie


6543165 dd should display incremental progress ala linux in response to 
sigusr1

- Bart


-- 
Bart Smaalders  Solaris Kernel Performance
barts at cyber.eng.sun.com  http://blogs.sun.com/barts



[request-sponsor] Adding status support to dd

2007-04-04 Thread Matty
Howdy,

Most Linux and BSD distributions ship with a version of dd that
displays the status of a copy operation when a SIGUSR1 signal is
received. For some reason /usr/bin/dd on Solaris hosts doesn't contain
this capability, and I would like to add it. After reading through the
source code for dd.c, it looks like adding this support would be as
simple as installing a signal handler for SIGUSR1, and having it call
the function stats. I am attaching code (which I copied from the dd
that ships with Fedora Core Linux) [1] to add this support to
/usr/bin/dd, and have tested it on my build 54 machine. Would it be
possible to integrate this or something similar to opensolaris
(assuming this doesn't break some rule defined by the SUS or POSIX)?

Thanks,
- Ryan
-- 
UNIX Administrator
http://prefetch.net

[1]

/* Create a signal handler for SIGUSR1 so dd can display stats on
active copies.*/
struct sigaction sa;
memset(sa, 0, sizeof(sa));
sa.sa_handler = stats;
sa.sa_flags = SA_RESTART;
sigemptyset(sa.sa_mask);
sigaction(SIGUSR1, sa, 0);



[request-sponsor] Adding status support to dd

2007-04-04 Thread Matty
Howdy,

Most Linux and BSD distributions ship with a version of dd that
displays the status of a copy operation when a SIGUSR1 signal is
received. For some reason /usr/bin/dd on Solaris hosts doesn't contain
this capability (it has a signal handler for SIGINT which causes stats
to be displayed, but the handler calls exit() after printing the
statistics), and I would like to add it. After reading through the
source code for dd.c, it looks like adding this support would be as
simple as installing a signal handler for SIGUSR1, and having it call
the function stats. I am attaching code (which I derived from the dd
source code that comes with Fedora Core Linux) [1] to add this support
to /usr/bin/dd, and have tested it on my build 54 machine. Would it be
possible to integrate this or something similar to opensolaris
(assuming this doesn't break some rule defined by the SUS or POSIX)?

Thanks,
- Ryan
--
UNIX Administrator
http://prefetch.net

[1]

/* Create a signal handler for SIGUSR1 so dd can display stats for
active copies.*/
struct sigaction sa;
memset(sa, 0, sizeof(sa));
sa.sa_handler = stats;
sa.sa_flags = SA_RESTART;
sigemptyset(sa.sa_mask);
sigaction(SIGUSR1, sa, 0);



[request-sponsor] Adding status support to dd

2007-04-04 Thread Bart Smaalders
Matty wrote:
 Howdy,
 
 Most Linux and BSD distributions ship with a version of dd that
 displays the status of a copy operation when a SIGUSR1 signal is
 received. For some reason /usr/bin/dd on Solaris hosts doesn't contain
 this capability (it has a signal handler for SIGINT which causes stats
 to be displayed, but the handler calls exit() after printing the
 statistics), and I would like to add it. After reading through the
 source code for dd.c, it looks like adding this support would be as
 simple as installing a signal handler for SIGUSR1, and having it call
 the function stats. I am attaching code (which I derived from the dd
 source code that comes with Fedora Core Linux) [1] to add this support
 to /usr/bin/dd, and have tested it on my build 54 machine. Would it be
 possible to integrate this or something similar to opensolaris
 (assuming this doesn't break some rule defined by the SUS or POSIX)?
 
 Thanks,
 - Ryan
 -- 
 UNIX Administrator
 http://prefetch.net
 
 [1]
 
 /* Create a signal handler for SIGUSR1 so dd can display stats for
 active copies.*/
 struct sigaction sa;
 memset(sa, 0, sizeof(sa));
 sa.sa_handler = stats;
 sa.sa_flags = SA_RESTART;
 sigemptyset(sa.sa_mask);
 sigaction(SIGUSR1, sa, 0);
 ___
 request-sponsor mailing list
 request-sponsor at opensolaris.org

The code changes are obvious enough.  However, there exists a small
possibility of deadlock if the process receives a signal as
it is encountering errors or exiting, as neither fprintf and
gettext are async signal safe. If either routine holds a
lock when it is interrupted and then gets called again in
the signal handler, things can go badly awry.  We don't actually
deadlock (although perhaps we should), but output, etc, can get
rather garbled.

In general, a cleaner way to handle this is to block sigusr1 in the main
thread, and create a thread to handle the sigusr1 and sigint
synchronously using sigwait(2).  If sigint is caught, the
thread calls stats() and exits.  If sigusr1 is caught, the
thread calls stats() and then calls sigwait(2) again.

This is prob. overkill in this situation... since the main loop
will only do stdio just before exiting, it could set
signal handlers to SIG_IGN before doing any IO which should
prevent any problems from arising.


- Bart




-- 
Bart Smaalders  Solaris Kernel Performance
barts at cyber.eng.sun.com  http://blogs.sun.com/barts