diff options
author | Christian Heim <phreak@gentoo.org> | 2005-12-02 10:56:06 +0000 |
---|---|---|
committer | Christian Heim <phreak@gentoo.org> | 2005-12-02 10:56:06 +0000 |
commit | a14ee4ab9b6b622475c9520fb3d08e6f78b08881 (patch) | |
tree | ff48cc3f5de2918ab569e3cb391db1ec883a35eb /src/core/librcscripts/debug.h | |
parent | Import the latest baselayout changes. Merging revision 1648. (diff) | |
download | baselayout-vserver-a14ee4ab9b6b622475c9520fb3d08e6f78b08881.tar.gz baselayout-vserver-a14ee4ab9b6b622475c9520fb3d08e6f78b08881.tar.bz2 baselayout-vserver-a14ee4ab9b6b622475c9520fb3d08e6f78b08881.zip |
Import the latest baselayout changes. Merging revision 1658.
svn path=/baselayout-vserver/trunk/; revision=127
Diffstat (limited to 'src/core/librcscripts/debug.h')
-rw-r--r-- | src/core/librcscripts/debug.h | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/core/librcscripts/debug.h b/src/core/librcscripts/debug.h new file mode 100644 index 0000000..997e92f --- /dev/null +++ b/src/core/librcscripts/debug.h @@ -0,0 +1,85 @@ +/* + * debug.h + * + * Simle debugging/logging macro's and functions. + * + * Copyright (C) 2004,2005 Martin Schlemmer <azarah@nosferatu.za.org> + * + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Header$ + */ + +#ifndef _DEBUG_H +#define _DEBUG_H + +#if defined(RC_DEBUG) +# define DBG_MSG(_format, _arg...) \ + do { \ + int old_errno = errno; \ + fprintf(stderr, "DEBUG(1): in %s, function %s(), line %i:\n", __FILE__, \ + __FUNCTION__, __LINE__); \ + fprintf(stderr, "DEBUG(2): " _format, ## _arg); \ + errno = old_errno; \ + if (0 != errno) { \ + perror("DEBUG(3)"); \ + /* perror() for some reason sets errno to ESPIPE */ \ + errno = old_errno; \ + } \ + } while (0) +#else +# define DBG_MSG(_format, _arg...) \ + do { \ + int old_errno = errno; \ + /* Bit of a hack, as how we do things tend to cause seek + * errors when reading the parent/child pipes */ \ + /* if ((0 != errno) && (ESPIPE != errno)) { */ \ + if (0 != errno) { \ + fprintf(stderr, "DEBUG(1): in %s, function %s(), line %i:\n", \ + __FILE__, __FUNCTION__, __LINE__); \ + fprintf(stderr, "DEBUG(2): " _format, ## _arg); \ + errno = old_errno; \ + perror("DEBUG(3)"); \ + /* perror() for some reason sets errno to ESPIPE */ \ + errno = old_errno; \ + } \ + } while (0) +#endif + +#define FATAL_ERROR() \ + do { \ + int old_errno = errno; \ + fprintf(stderr, "ERROR: file '%s', function '%s', line %i.\n", \ + __FILE__, __FUNCTION__, __LINE__); \ + errno = old_errno; \ + if (0 != errno) \ + perror("ERROR"); \ + exit(EXIT_FAILURE); \ + } while (0) + +#define NEG_FATAL_ERROR(_x) \ + do { \ + if (-1 == _x) \ + FATAL_ERROR(); \ + } while (0) + +#define NULL_FATAL_ERROR(_x) \ + do { \ + if (NULL == _x) \ + FATAL_ERROR(); \ + } while (0) + +#endif /* _DEBUG_H */ + |