ras2.c revision 1.11
11.11Schs/* $NetBSD: ras2.c,v 1.11 2012/11/02 14:53:03 chs Exp $ */
21.2Sgmcgarry
31.2Sgmcgarry/*-
41.2Sgmcgarry * Copyright (c) 2002 The NetBSD Foundation, Inc.
51.2Sgmcgarry * All rights reserved.
61.2Sgmcgarry *
71.2Sgmcgarry * Redistribution and use in source and binary forms, with or without
81.2Sgmcgarry * modification, are permitted provided that the following conditions
91.2Sgmcgarry * are met:
101.2Sgmcgarry * 1. Redistributions of source code must retain the above copyright
111.2Sgmcgarry *    notice, this list of conditions and the following disclaimer.
121.2Sgmcgarry * 2. Redistributions in binary form must reproduce the above copyright
131.2Sgmcgarry *    notice, this list of conditions and the following disclaimer in the
141.2Sgmcgarry *    documentation and/or other materials provided with the distribution.
151.2Sgmcgarry *
161.2Sgmcgarry * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
171.2Sgmcgarry * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
181.2Sgmcgarry * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
191.2Sgmcgarry * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
201.2Sgmcgarry * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
211.2Sgmcgarry * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
221.2Sgmcgarry * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
231.2Sgmcgarry * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
241.2Sgmcgarry * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
251.2Sgmcgarry * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
261.2Sgmcgarry * POSSIBILITY OF SUCH DAMAGE.
271.2Sgmcgarry */
281.2Sgmcgarry
291.11Schs#include <stdlib.h>
301.5Smartin#include <errno.h>
311.6Sthorpej#include <inttypes.h>
321.1Sgmcgarry#include <stdio.h>
331.1Sgmcgarry#include <signal.h>
341.1Sgmcgarry#include <unistd.h>
351.1Sgmcgarry#include <sys/ras.h>
361.1Sgmcgarry#include <sys/time.h>
371.1Sgmcgarry#include <sys/wait.h>
381.1Sgmcgarry
391.1Sgmcgarry#define COUNT	10
401.1Sgmcgarry
411.7Sperryvolatile int handled = 0;
421.7Sperryvolatile int count = 0;
431.1Sgmcgarrystruct itimerval itv;
441.1Sgmcgarry
451.1Sgmcgarryvoid handler(int);
461.1Sgmcgarry
471.1Sgmcgarryvoid
481.1Sgmcgarryhandler(int sig)
491.1Sgmcgarry{
501.1Sgmcgarry
511.1Sgmcgarry	handled++;
521.1Sgmcgarry}
531.1Sgmcgarry
541.6SthorpejRAS_DECL(main);
551.6Sthorpej
561.1Sgmcgarryint
571.1Sgmcgarrymain(void)
581.1Sgmcgarry{
591.1Sgmcgarry	int rv;
601.1Sgmcgarry
611.1Sgmcgarry        signal(SIGVTALRM, handler);
621.1Sgmcgarry
631.1Sgmcgarry        itv.it_interval.tv_sec = 0;
641.1Sgmcgarry        itv.it_interval.tv_usec = 0;
651.1Sgmcgarry        itv.it_value.tv_sec = 10;
661.1Sgmcgarry        itv.it_value.tv_usec = 0;
671.1Sgmcgarry
681.6Sthorpej	if (rasctl(RAS_ADDR(main), RAS_SIZE(main), RAS_INSTALL) < 0) {
691.5Smartin		if (errno == EOPNOTSUPP) {
701.5Smartin			printf("RAS is not supported on this architecture\n");
711.5Smartin			return 0;
721.5Smartin		}
731.1Sgmcgarry		return (1);
741.5Smartin	}
751.1Sgmcgarry
761.1Sgmcgarry	if (fork() != 0) {
771.1Sgmcgarry		wait(&rv);
781.8Smartin		return WEXITSTATUS(rv);
791.1Sgmcgarry	}
801.9Sdsl	setitimer(ITIMER_VIRTUAL, &itv, NULL);
811.4Smartin
821.6Sthorpej	RAS_START(main);
831.1Sgmcgarry	count++;
841.1Sgmcgarry	if (count > COUNT)
851.11Schs		exit(handled != 0);
861.1Sgmcgarry
871.1Sgmcgarry	while (!handled) {
881.1Sgmcgarry		continue;
891.1Sgmcgarry	}
901.6Sthorpej	RAS_END(main);
911.1Sgmcgarry
921.1Sgmcgarry	return (handled != 0);
931.1Sgmcgarry}
94