1181643Skmacy/* 2199959Skmacy * Copyright (c) 2006-2007 The Regents of the University of California. 3199959Skmacy * Copyright (c) 2004-2006 Voltaire, Inc. All rights reserved. 4251195Sgibbs * 5199960Skmacy * This software is available to you under a choice of one of two 6199959Skmacy * licenses. You may choose to be licensed under the terms of the GNU 7199959Skmacy * General Public License (GPL) Version 2, available from the file 8199959Skmacy * COPYING in the main directory of this source tree, or the 9199959Skmacy * OpenIB.org BSD license below: 10199959Skmacy * 11199959Skmacy * Redistribution and use in source and binary forms, with or 12199959Skmacy * without modification, are permitted provided that the following 13199959Skmacy * conditions are met: 14199959Skmacy * 15199959Skmacy * - Redistributions of source code must retain the above 16199959Skmacy * copyright notice, this list of conditions and the following 17199959Skmacy * disclaimer. 18199959Skmacy * 19199959Skmacy * - Redistributions in binary form must reproduce the above 20199959Skmacy * copyright notice, this list of conditions and the following 21199959Skmacy * disclaimer in the documentation and/or other materials 22181643Skmacy * provided with the distribution. 23181643Skmacy * 24181643Skmacy * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25181643Skmacy * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26181643Skmacy * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27199960Skmacy * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 28199960Skmacy * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 29181643Skmacy * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 30181643Skmacy * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31181643Skmacy * SOFTWARE. 32181643Skmacy * 33251195Sgibbs */ 34251195Sgibbs 35214077Sgibbs/** 36181643Skmacy * Define common functions which can be included in the various C based diags. 37214077Sgibbs */ 38231839Sgibbs 39231839Sgibbs#define _GNU_SOURCE 40231839Sgibbs#include <stdio.h> 41231839Sgibbs#include <errno.h> 42231839Sgibbs#include <string.h> 43231839Sgibbs#include <stdlib.h> 44231839Sgibbs#include <stdarg.h> 45231839Sgibbs#include <sys/types.h> 46231839Sgibbs#include <unistd.h> 47251195Sgibbs#include <ctype.h> 48231839Sgibbs#ifdef HAVE_CONFIG_H 49231839Sgibbs#include <config.h> 50231839Sgibbs#endif 51231839Sgibbs 52231839Sgibbs#include "ibdiag_common.h" 53231839Sgibbs 54231839Sgibbsint ibdebug; 55231839Sgibbs 56231839Sgibbsvoid 57231839Sgibbsiberror(const char *fn, char *msg, ...) 58231839Sgibbs{ 59231839Sgibbs char buf[512], *s; 60251195Sgibbs va_list va; 61231839Sgibbs int n; 62231839Sgibbs 63231839Sgibbs va_start(va, msg); 64285738Sroyger n = vsprintf(buf, msg, va); 65285738Sroyger va_end(va); 66285738Sroyger buf[n] = 0; 67285738Sroyger 68285738Sroyger if ((s = strrchr(argv0, '/'))) 69285738Sroyger argv0 = s + 1; 70285738Sroyger 71287801Scperciva if (ibdebug) 72287801Scperciva printf("%s: iberror: [pid %d] %s: failed: %s\n", argv0, getpid(), fn, buf); 73214077Sgibbs else 74285738Sroyger printf("%s: iberror: failed: %s\n", argv0, buf); 75285738Sroyger 76214077Sgibbs exit(-1); 77214077Sgibbs} 78287802Scperciva 79287802Scperciva