resetting manifest requested domain to floor
[platform/upstream/libpipeline.git] / lib / debug.c
1 /*
2  * debug.c: debugging messages
3  * Copyright (C) 2007, 2010 Colin Watson.
4  *
5  * This file is part of libpipeline.
6  *
7  * libpipeline is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or (at
10  * your option) any later version.
11  *
12  * libpipeline is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with libpipeline; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
20  * USA
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <stdarg.h>
30 #include <string.h>
31 #include <errno.h>
32
33 #include "pipeline-private.h"
34
35 int debug_level = 0;
36
37 void init_debug (void)
38 {
39         static int inited = 0;
40         const char *pipeline_debug;
41
42         if (inited)
43                 return;
44         inited = 1;
45
46         pipeline_debug = getenv ("PIPELINE_DEBUG");
47         if (pipeline_debug && !strcmp (pipeline_debug, "1"))
48                 debug_level = 1;
49 }
50
51 static void vdebug (const char *message, va_list args)
52 {
53         if (debug_level)
54                 vfprintf (stderr, message, args);
55 }
56
57 void debug (const char *message, ...)
58 {
59         init_debug ();
60
61         if (debug_level) {
62                 va_list args;
63
64                 va_start (args, message);
65                 vdebug (message, args);
66                 va_end (args);
67         }
68 }