9512fe850e98fdd448c638ca63fdd92a8a510255ahl/*
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * CDDL HEADER START
9512fe850e98fdd448c638ca63fdd92a8a510255ahl *
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * The contents of this file are subject to the terms of the
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * Common Development and Distribution License (the "License").
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * You may not use this file except in compliance with the License.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl *
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * or http://www.opensolaris.org/os/licensing.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * See the License for the specific language governing permissions
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * and limitations under the License.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl *
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * When distributing Covered Code, include this CDDL HEADER in each
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * If applicable, add the following below this CDDL HEADER, with the
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * fields enclosed by brackets "[]" replaced with your own identifying
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * information: Portions Copyright [yyyy] [name of copyright owner]
9512fe850e98fdd448c638ca63fdd92a8a510255ahl *
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * CDDL HEADER END
9512fe850e98fdd448c638ca63fdd92a8a510255ahl */
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl/*
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * Use is subject to license terms.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl */
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#pragma ident "%Z%%M% %I% %E% SMI"
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#include <signal.h>
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#include <time.h>
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#include <stdlib.h>
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#include <stdio.h>
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#include <errno.h>
9512fe850e98fdd448c638ca63fdd92a8a510255ahl#include <string.h>
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
73427c57f824c3ec3b396181b163f37d50c5b3b1ahlint
9512fe850e98fdd448c638ca63fdd92a8a510255ahlmain(int argc, char **argv)
9512fe850e98fdd448c638ca63fdd92a8a510255ahl{
9512fe850e98fdd448c638ca63fdd92a8a510255ahl struct sigevent ev;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl struct itimerspec ts;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl sigset_t set;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl timer_t tid;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl char *cmd = argv[0];
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl ev.sigev_notify = SIGEV_SIGNAL;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl ev.sigev_signo = SIGUSR1;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl if (timer_create(CLOCK_REALTIME, &ev, &tid) == -1) {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl (void) fprintf(stderr, "%s: cannot create CLOCK_HIGHRES "
9512fe850e98fdd448c638ca63fdd92a8a510255ahl "timer: %s\n", cmd, strerror(errno));
9512fe850e98fdd448c638ca63fdd92a8a510255ahl exit(EXIT_FAILURE);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl }
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl (void) sigemptyset(&set);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl (void) sigaddset(&set, SIGUSR1);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl (void) sigprocmask(SIG_BLOCK, &set, NULL);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl ts.it_value.tv_sec = 1;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl ts.it_value.tv_nsec = 0;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl ts.it_interval.tv_sec = 0;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl ts.it_interval.tv_nsec = NANOSEC / 2;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl if (timer_settime(tid, TIMER_RELTIME, &ts, NULL) == -1) {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl (void) fprintf(stderr, "%s: timer_settime() failed: %s\n",
9512fe850e98fdd448c638ca63fdd92a8a510255ahl cmd, strerror(errno));
9512fe850e98fdd448c638ca63fdd92a8a510255ahl exit(EXIT_FAILURE);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl }
9512fe850e98fdd448c638ca63fdd92a8a510255ahl
9512fe850e98fdd448c638ca63fdd92a8a510255ahl for (;;) {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl (void) sigwait(&set);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl }
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl /*NOTREACHED*/
73427c57f824c3ec3b396181b163f37d50c5b3b1ahl return (0);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl}