tst.sigwait.c revision 259065
1139749Simp/*
284059Swpaul * CDDL HEADER START
384059Swpaul *
484059Swpaul * The contents of this file are subject to the terms of the
584059Swpaul * Common Development and Distribution License (the "License").
684059Swpaul * You may not use this file except in compliance with the License.
784059Swpaul *
884059Swpaul * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
984059Swpaul * or http://www.opensolaris.org/os/licensing.
1084059Swpaul * See the License for the specific language governing permissions
1184059Swpaul * and limitations under the License.
1284059Swpaul *
1384059Swpaul * When distributing Covered Code, include this CDDL HEADER in each
1484059Swpaul * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1584059Swpaul * If applicable, add the following below this CDDL HEADER, with the
1684059Swpaul * fields enclosed by brackets "[]" replaced with your own identifying
1784059Swpaul * information: Portions Copyright [yyyy] [name of copyright owner]
1884059Swpaul *
1984059Swpaul * CDDL HEADER END
2084059Swpaul */
2184059Swpaul
2284059Swpaul/*
2384059Swpaul * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
2484059Swpaul * Use is subject to license terms.
2584059Swpaul */
2684059Swpaul
2784059Swpaul#pragma ident	"%Z%%M%	%I%	%E% SMI"
2884059Swpaul
2984059Swpaul#include <signal.h>
3084059Swpaul#include <time.h>
3184059Swpaul#include <stdlib.h>
3284059Swpaul#include <stdio.h>
3384059Swpaul#include <errno.h>
3484059Swpaul#include <string.h>
3584059Swpaul
3684059Swpaul#define NANOSEC	1000000000
3784059Swpaul
3884059Swpaulint
3984059Swpaulmain(int argc, char **argv)
4084059Swpaul{
4184059Swpaul	struct sigevent ev;
4284059Swpaul	struct itimerspec ts;
4384059Swpaul	sigset_t set;
4484059Swpaul	timer_t tid;
4584059Swpaul	char *cmd = argv[0];
4684059Swpaul	int sig;
4784059Swpaul
4884059Swpaul	ev.sigev_notify = SIGEV_SIGNAL;
4984059Swpaul	ev.sigev_signo = SIGUSR1;
5084059Swpaul
5184059Swpaul	if (timer_create(CLOCK_REALTIME, &ev, &tid) == -1) {
5284059Swpaul		(void) fprintf(stderr, "%s: cannot create CLOCK_HIGHRES "
5384059Swpaul		    "timer: %s\n", cmd, strerror(errno));
5484059Swpaul		exit(EXIT_FAILURE);
5584059Swpaul	}
5684059Swpaul
5784059Swpaul	(void) sigemptyset(&set);
5884059Swpaul	(void) sigaddset(&set, SIGUSR1);
5984059Swpaul	(void) sigprocmask(SIG_BLOCK, &set, NULL);
6084059Swpaul
6184059Swpaul	ts.it_value.tv_sec = 1;
6284059Swpaul	ts.it_value.tv_nsec = 0;
6384059Swpaul	ts.it_interval.tv_sec = 0;
64166676Sjkim	ts.it_interval.tv_nsec = NANOSEC / 2;
65166676Sjkim
66166676Sjkim	if (timer_settime(tid, TIMER_RELTIME, &ts, NULL) == -1) {
67166676Sjkim		(void) fprintf(stderr, "%s: timer_settime() failed: %s\n",
68166676Sjkim		    cmd, strerror(errno));
69166676Sjkim		exit(EXIT_FAILURE);
70166676Sjkim	}
71166676Sjkim
72166676Sjkim	do {
73166676Sjkim		(void) sigwait(&set, &sig);
74166676Sjkim	} while(sig != SIGUSR1);
75166676Sjkim
76166676Sjkim	/*NOTREACHED*/
77166676Sjkim	return (0);
78166676Sjkim}
79166676Sjkim