common.c revision 26fd77009b17f8c8fb32eb362584cfd635e87ad9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include "statcommon.h"
#include <stdarg.h>
#include <signal.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
extern char *cmdname;
extern int caught_cont;
/*PRINTFLIKE2*/
void
{
int save_errno = errno;
if (do_perror)
exit(2);
}
/*
* Sleep until *wakeup + interval, keeping cadence where desired
*
* *wakeup - The time we last wanted to wake up. Updated.
* interval - We want to sleep until *wakeup + interval
* forever - Running for infinite periods, so cadence not important
* *caught_cont - Global set by signal handler if we got a SIGCONT
*/
void
int *caught_cont)
{
int status;
if (forever || *caught_cont) {
/* Reset our cadence (see comment below) */
} else {
/*
* If we got here, then the time between the
* output we just did, and the scheduled time
* for the next output is < 1/4 of our requested
* interval AND the number of intervals has been
* requested AND we have never caught a SIGCONT
* (so we have never been suspended). In this
* case, we'll try to stay to the desired
* cadence, and we will pause for 1/2 the normal
* interval this time.
*/
}
else
if (pause < 1000)
/* Near enough */
return;
/* Now do the actual sleep */
pause_left = pause;
do {
if (status < 0)
if (pause_left < 1000)
/* Near enough */
return;
} else {
}
} while (status != 0);
}
/*
* Signal handler - so we can be aware of SIGCONT
*/
void
cont_handler(int sig_number)
{
/* Re-set the signal handler */
caught_cont = 1;
}