Skip to content

Commit

Permalink
4493 want siginfo
Browse files Browse the repository at this point in the history
4494 Make dd show progress when you send INFO/USR1 signals
4495 dd could support O_SYNC and O_DSYNC
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Joshua M. Clulow <josh@sysmgr.org>
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Reviewed by: Garrett D'Amore <garrett@damore.org>
Approved by: Garrett D'Amore <garrett@damore.org>
  • Loading branch information
rmustacc committed Jan 22, 2014
1 parent 4f364e7 commit 19d32b9
Show file tree
Hide file tree
Showing 35 changed files with 311 additions and 157 deletions.
105 changes: 94 additions & 11 deletions usr/src/cmd/dd/dd.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright 2012, Josef 'Jeff' Sipek <jeffpc@31bits.net>. All rights reserved.
* Copyright (c) 2014, Joyent, Inc. All rights reserved.
*/

/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
Expand All @@ -44,6 +45,9 @@
#include <stdlib.h>
#include <locale.h>
#include <string.h>
#include <sys/time.h>
#include <errno.h>
#include <strings.h>

/* The BIG parameter is machine dependent. It should be a long integer */
/* constant that can be used by the number parser to check the validity */
Expand Down Expand Up @@ -102,7 +106,8 @@
" [iseek=n] [oseek=n] [seek=n] [count=n] [conv=[ascii]\n"\
" [,ebcdic][,ibm][,asciib][,ebcdicb][,ibmb]\n"\
" [,block|unblock][,lcase|ucase][,swab]\n"\
" [,noerror][,notrunc][,sync]]\n"
" [,noerror][,notrunc][,sync]]\n"\
" [oflag=[dsync][sync]]\n"

/* Global references */

Expand All @@ -127,6 +132,7 @@ static unsigned cbc; /* number of bytes in the conversion buffer */
static int ibf; /* input file descriptor */
static int obf; /* output file descriptor */
static int cflag; /* conversion option flags */
static int oflag; /* output flag options */
static int skipf; /* if skipf == 1, skip rest of input line */
static unsigned long long nifr; /* count of full input records */
static unsigned long long nipr; /* count of partial input records */
Expand All @@ -149,6 +155,10 @@ static char *ofile; /* output file name pointer */
static unsigned char *ibuf; /* input buffer pointer */
static unsigned char *obuf; /* output buffer pointer */

static hrtime_t startt; /* hrtime copy started */
static unsigned long long obytes; /* output bytes */
static sig_atomic_t nstats; /* do we need to output stats */

/* This is an EBCDIC to ASCII conversion table */
/* from a proposed BTL standard April 16, 1979 */

Expand Down Expand Up @@ -461,6 +471,12 @@ static unsigned char *atoe = svr4_atoe;
static unsigned char *etoa = svr4_etoa;
static unsigned char *atoibm = svr4_atoibm;

/*ARGSUSED*/
static void
siginfo_handler(int sig, siginfo_t *sip, void *ucp)
{
nstats = 1;
}

int
main(int argc, char **argv)
Expand All @@ -471,6 +487,7 @@ main(int argc, char **argv)
int conv; /* conversion option code */
int trunc; /* whether output file is truncated */
struct stat file_stat;
struct sigaction sact;

/* Set option defaults */

Expand Down Expand Up @@ -657,6 +674,32 @@ main(int argc, char **argv)
}
continue;
}
if (match("oflag="))
{
for (;;)
{
if (match(","))
{
continue;
}
if (*string == '\0')
{
break;
}
if (match("dsync"))
{
oflag |= O_DSYNC;
continue;
}
if (match("sync"))
{
oflag |= O_SYNC;
continue;
}
goto badarg;
}
continue;
}
badarg:
(void) fprintf(stderr, "dd: %s \"%s\"\n",
gettext("bad argument:"), string);
Expand Down Expand Up @@ -787,13 +830,12 @@ main(int argc, char **argv)
{
ibf = open(ifile, 0);
}
#ifndef STANDALONE
else
{
ifile = "";
ibf = dup(0);
}
#endif

if (ibf == -1)
{
(void) fprintf(stderr, "dd: %s: ", ifile);
Expand All @@ -807,11 +849,11 @@ main(int argc, char **argv)
if (ofile)
{
if (trunc == 0) /* do not truncate output file */
obf = open(ofile, (O_WRONLY|O_CREAT),
obf = open(ofile, (O_WRONLY|O_CREAT|oflag),
(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH));
else if (oseekn && (trunc == 1))
{
obf = open(ofile, O_WRONLY|O_CREAT,
obf = open(ofile, O_WRONLY|O_CREAT|oflag,
(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH));
if (obf == -1)
{
Expand All @@ -829,16 +871,15 @@ main(int argc, char **argv)
}
}
else
obf = creat(ofile,
obf = open(ofile, O_WRONLY|O_CREAT|O_TRUNC|oflag,
(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH));
}
#ifndef STANDALONE
else
{
ofile = "";
obf = dup(1);
}
#endif

if (obf == -1)
{
(void) fprintf(stderr, "dd: %s: ", ofile);
Expand Down Expand Up @@ -871,14 +912,33 @@ main(int argc, char **argv)
exit(2);
}

/* Enable a statistics message on SIGINT */
/*
* Enable a statistics message when we terminate on SIGINT
* Also enable it to be queried via SIGINFO and SIGUSR1
*/

#ifndef STANDALONE
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
{
(void) signal(SIGINT, term);
}
#endif

bzero(&sact, sizeof (struct sigaction));
sact.sa_flags = SA_SIGINFO;
sact.sa_sigaction = siginfo_handler;
(void) sigemptyset(&sact.sa_mask);
if (sigaction(SIGINFO, &sact, NULL) != 0) {
(void) fprintf(stderr, "dd: %s: %s\n",
gettext("failed to enable siginfo handler"),
gettext(strerror(errno)));
exit(2);
}
if (sigaction(SIGUSR1, &sact, NULL) != 0) {
(void) fprintf(stderr, "dd: %s: %s\n",
gettext("failed to enable sigusr1 handler"),
gettext(strerror(errno)));
exit(2);
}

/* Skip input blocks */

while (skip)
Expand Down Expand Up @@ -939,8 +999,16 @@ main(int argc, char **argv)

/* Read and convert input blocks until end of file(s) */

/* Grab our start time for siginfo purposes */
startt = gethrtime();

for (;;)
{
if (nstats != 0) {
stats();
nstats = 0;
}

if ((count == 0) || (nifr+nipr < count))
{
/* If proceed on error is enabled, zero the input buffer */
Expand Down Expand Up @@ -1772,6 +1840,7 @@ static unsigned char
}
obc -= oc;
op = obuf;
obytes += bc;

/* If any data in the conversion buffer, move it into */
/* the output buffer */
Expand Down Expand Up @@ -1820,10 +1889,24 @@ int c;
static void
stats()
{
hrtime_t delta = gethrtime() - startt;
double secs = delta * 1e-9;

(void) fprintf(stderr, gettext("%llu+%llu records in\n"), nifr, nipr);
(void) fprintf(stderr, gettext("%llu+%llu records out\n"), nofr, nopr);
if (ntrunc) {
(void) fprintf(stderr,
gettext("%llu truncated record(s)\n"), ntrunc);
}

/*
* If we got here before we started copying somehow, don't bother
* printing the rest.
*/
if (startt == 0)
return;

(void) fprintf(stderr,
gettext("%llu bytes transferred in %.6f secs (%.0f bytes/sec)\n"),
obytes, secs, obytes / secs);
}
4 changes: 1 addition & 3 deletions usr/src/cmd/lp/cmd/lpsched/alerts.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
/* All Rights Reserved */


#pragma ident "%Z%%M% %I% %E% SMI"

#include "lpsched.h"
#include "stdarg.h"

Expand Down Expand Up @@ -294,7 +292,7 @@ cancel_alert(int type, ...)
static int
dest_equivalent_printer(char *dest, char *printer)
{
CSTATUS * pc;
CLSTATUS * pc;

return (
STREQU(dest, printer)
Expand Down
10 changes: 4 additions & 6 deletions usr/src/cmd/lp/cmd/lpsched/disp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
/* All Rights Reserved */


#pragma ident "%Z%%M% %I% %E% SMI"

#include "dispatch.h"
#include <syslog.h>
#include <time.h>
Expand Down Expand Up @@ -371,7 +369,7 @@ s_load_class(char *m, MESG *md)
char *class;
ushort status;
register CLASS *pc;
register CSTATUS *pcs;
register CLSTATUS *pcs;

(void) getmessage(m, S_LOAD_CLASS, &class);
syslog(LOG_DEBUG, "s_load_class(%s)", (class ? class : "NULL"));
Expand Down Expand Up @@ -449,7 +447,7 @@ s_load_class(char *m, MESG *md)
*/

static void
_unload_class(CSTATUS *pcs)
_unload_class(CLSTATUS *pcs)
{
freeclass (pcs->class);
if (pcs->rej_reason != NULL)
Expand All @@ -465,7 +463,7 @@ s_unload_class(char *m, MESG *md)
char *class;
ushort status;
RSTATUS *prs;
register CSTATUS *pcs;
register CLSTATUS *pcs;

(void) getmessage(m, S_UNLOAD_CLASS, &class);
syslog(LOG_DEBUG, "s_unload_class(%s)", (class ? class : "NULL"));
Expand Down Expand Up @@ -535,7 +533,7 @@ void
s_inquire_class(char *m, MESG *md)
{
char *class;
register CSTATUS *pcs;
register CLSTATUS *pcs;

(void) getmessage(m, S_INQUIRE_CLASS, &class);
syslog(LOG_DEBUG, "s_inquire_class(%s)", (class ? class : "NULL"));
Expand Down
6 changes: 2 additions & 4 deletions usr/src/cmd/lp/cmd/lpsched/disp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
/* All Rights Reserved */


#pragma ident "%Z%%M% %I% %E% SMI"

#include "time.h"
#include "dispatch.h"
#include <syslog.h>
Expand All @@ -44,7 +42,7 @@ s_accept_dest(char *m, MESG *md)
char *destination;
ushort status;
register PSTATUS *pps;
register CSTATUS *pcs;
register CLSTATUS *pcs;

getmessage (m, S_ACCEPT_DEST, &destination);
syslog(LOG_DEBUG, "s_accept_dest(%s)",
Expand Down Expand Up @@ -94,7 +92,7 @@ s_reject_dest(char *m, MESG *md)
*reason;
ushort status;
register PSTATUS *pps;
register CSTATUS *pcs;
register CLSTATUS *pcs;


getmessage (m, S_REJECT_DEST, &destination, &reason);
Expand Down
12 changes: 5 additions & 7 deletions usr/src/cmd/lp/cmd/lpsched/fncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */

#pragma ident "%Z%%M% %I% %E% SMI"

/* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */

#include "unistd.h"
Expand Down Expand Up @@ -271,7 +269,7 @@ new_pstatus(PRINTER *p)
}

void
free_cstatus(CSTATUS *csp)
free_cstatus(CLSTATUS *csp)
{
if (csp != NULL) {
if (csp->rej_reason != NULL)
Expand All @@ -282,10 +280,10 @@ free_cstatus(CSTATUS *csp)
}
}

CSTATUS *
CLSTATUS *
new_cstatus(CLASS *c)
{
CSTATUS *result = calloc(1, sizeof (*result));
CLSTATUS *result = calloc(1, sizeof (*result));

if (result != NULL) {
if (c != NULL)
Expand Down Expand Up @@ -502,10 +500,10 @@ search_fptable(register char *paper)
return (ps);
}

CSTATUS *
CLSTATUS *
search_cstatus(register char *name)
{
CSTATUS *ps = NULL;
CLSTATUS *ps = NULL;

if (name != NULL) {
if (CStatus != NULL) {
Expand Down
4 changes: 1 addition & 3 deletions usr/src/cmd/lp/cmd/lpsched/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@
/* All Rights Reserved */


#pragma ident "%Z%%M% %I% %E% SMI"

#include "lpsched.h"
#include <syslog.h>

CSTATUS **CStatus = NULL; /* Status of same */
CLSTATUS **CStatus = NULL; /* Status of same */
PSTATUS **PStatus = NULL; /* Status of same */
FSTATUS **FStatus = NULL; /* status of same */
PWSTATUS **PWStatus = NULL; /* Status of same */
Expand Down
Loading

0 comments on commit 19d32b9

Please sign in to comment.