ras2.c revision 1.9
11.9Sdsl/* $NetBSD: ras2.c,v 1.9 2008/01/12 11:10:08 dsl 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 * 3. All advertising materials mentioning features or use of this software 161.2Sgmcgarry * must display the following acknowledgement: 171.2Sgmcgarry * This product includes software developed by the NetBSD 181.2Sgmcgarry * Foundation, Inc. and its contributors. 191.2Sgmcgarry * 4. Neither the name of The NetBSD Foundation nor the names of its 201.2Sgmcgarry * contributors may be used to endorse or promote products derived 211.2Sgmcgarry * from this software without specific prior written permission. 221.2Sgmcgarry * 231.2Sgmcgarry * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 241.2Sgmcgarry * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 251.2Sgmcgarry * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 261.2Sgmcgarry * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 271.2Sgmcgarry * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 281.2Sgmcgarry * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 291.2Sgmcgarry * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 301.2Sgmcgarry * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 311.2Sgmcgarry * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 321.2Sgmcgarry * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 331.2Sgmcgarry * POSSIBILITY OF SUCH DAMAGE. 341.2Sgmcgarry */ 351.2Sgmcgarry 361.5Smartin#include <errno.h> 371.6Sthorpej#include <inttypes.h> 381.1Sgmcgarry#include <stdio.h> 391.1Sgmcgarry#include <signal.h> 401.1Sgmcgarry#include <unistd.h> 411.1Sgmcgarry#include <sys/ras.h> 421.1Sgmcgarry#include <sys/time.h> 431.1Sgmcgarry#include <sys/wait.h> 441.1Sgmcgarry 451.1Sgmcgarry#define COUNT 10 461.1Sgmcgarry 471.7Sperryvolatile int handled = 0; 481.7Sperryvolatile int count = 0; 491.1Sgmcgarrystruct itimerval itv; 501.1Sgmcgarry 511.1Sgmcgarryvoid handler(int); 521.1Sgmcgarry 531.1Sgmcgarryvoid 541.1Sgmcgarryhandler(int sig) 551.1Sgmcgarry{ 561.1Sgmcgarry 571.1Sgmcgarry handled++; 581.1Sgmcgarry} 591.1Sgmcgarry 601.6SthorpejRAS_DECL(main); 611.6Sthorpej 621.1Sgmcgarryint 631.1Sgmcgarrymain(void) 641.1Sgmcgarry{ 651.1Sgmcgarry int rv; 661.1Sgmcgarry 671.1Sgmcgarry signal(SIGVTALRM, handler); 681.1Sgmcgarry 691.1Sgmcgarry itv.it_interval.tv_sec = 0; 701.1Sgmcgarry itv.it_interval.tv_usec = 0; 711.1Sgmcgarry itv.it_value.tv_sec = 10; 721.1Sgmcgarry itv.it_value.tv_usec = 0; 731.1Sgmcgarry 741.6Sthorpej if (rasctl(RAS_ADDR(main), RAS_SIZE(main), RAS_INSTALL) < 0) { 751.5Smartin if (errno == EOPNOTSUPP) { 761.5Smartin printf("RAS is not supported on this architecture\n"); 771.5Smartin return 0; 781.5Smartin } 791.1Sgmcgarry return (1); 801.5Smartin } 811.1Sgmcgarry 821.1Sgmcgarry if (fork() != 0) { 831.1Sgmcgarry wait(&rv); 841.8Smartin return WEXITSTATUS(rv); 851.1Sgmcgarry } 861.9Sdsl setitimer(ITIMER_VIRTUAL, &itv, NULL); 871.4Smartin 881.6Sthorpej RAS_START(main); 891.1Sgmcgarry count++; 901.1Sgmcgarry if (count > COUNT) 911.1Sgmcgarry goto end; 921.1Sgmcgarry 931.1Sgmcgarry while (!handled) { 941.1Sgmcgarry continue; 951.1Sgmcgarry } 961.1Sgmcgarryend: 971.6Sthorpej RAS_END(main); 981.1Sgmcgarry 991.1Sgmcgarry return (handled != 0); 1001.1Sgmcgarry} 101