1219820Sjeff/*
2219820Sjeff * Copyright (c) 2006-2007 The Regents of the University of California.
3219820Sjeff * Copyright (c) 2004-2006 Voltaire, Inc. All rights reserved.
4219820Sjeff *
5219820Sjeff * This software is available to you under a choice of one of two
6219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
7219820Sjeff * General Public License (GPL) Version 2, available from the file
8219820Sjeff * COPYING in the main directory of this source tree, or the
9219820Sjeff * OpenIB.org BSD license below:
10219820Sjeff *
11219820Sjeff *     Redistribution and use in source and binary forms, with or
12219820Sjeff *     without modification, are permitted provided that the following
13219820Sjeff *     conditions are met:
14219820Sjeff *
15219820Sjeff *      - Redistributions of source code must retain the above
16219820Sjeff *        copyright notice, this list of conditions and the following
17219820Sjeff *        disclaimer.
18219820Sjeff *
19219820Sjeff *      - Redistributions in binary form must reproduce the above
20219820Sjeff *        copyright notice, this list of conditions and the following
21219820Sjeff *        disclaimer in the documentation and/or other materials
22219820Sjeff *        provided with the distribution.
23219820Sjeff *
24219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31219820Sjeff * SOFTWARE.
32219820Sjeff *
33219820Sjeff */
34219820Sjeff
35219820Sjeff/**
36219820Sjeff * Define common functions which can be included in the various C based diags.
37219820Sjeff */
38219820Sjeff
39219820Sjeff#define _GNU_SOURCE
40219820Sjeff#include <stdio.h>
41219820Sjeff#include <errno.h>
42219820Sjeff#include <string.h>
43219820Sjeff#include <stdlib.h>
44219820Sjeff#include <stdarg.h>
45219820Sjeff#include <sys/types.h>
46219820Sjeff#include <unistd.h>
47219820Sjeff#include <ctype.h>
48219820Sjeff#ifdef HAVE_CONFIG_H
49219820Sjeff#include <config.h>
50219820Sjeff#endif
51219820Sjeff
52219820Sjeff#include "ibdiag_common.h"
53219820Sjeff
54219820Sjeffint ibdebug;
55219820Sjeff
56219820Sjeffvoid
57219820Sjeffiberror(const char *fn, char *msg, ...)
58219820Sjeff{
59219820Sjeff	char buf[512], *s;
60219820Sjeff	va_list va;
61219820Sjeff	int n;
62219820Sjeff
63219820Sjeff	va_start(va, msg);
64219820Sjeff	n = vsprintf(buf, msg, va);
65219820Sjeff	va_end(va);
66219820Sjeff	buf[n] = 0;
67219820Sjeff
68219820Sjeff	if ((s = strrchr(argv0, '/')))
69219820Sjeff		argv0 = s + 1;
70219820Sjeff
71219820Sjeff	if (ibdebug)
72219820Sjeff		printf("%s: iberror: [pid %d] %s: failed: %s\n", argv0, getpid(), fn, buf);
73219820Sjeff	else
74219820Sjeff		printf("%s: iberror: failed: %s\n", argv0, buf);
75219820Sjeff
76219820Sjeff	exit(-1);
77219820Sjeff}
78219820Sjeff
79