xref: /openbsd-src/lib/libfuse/debug.c (revision c839d22f400af536a5e6b6a85044549c984c0d01)
1*c839d22fShelg /*	$OpenBSD: debug.c,v 1.2 2017/12/13 12:30:18 helg Exp $	*/
275af46c2Stedu /*
375af46c2Stedu  * Copyright (c) 2011 Alexandre Ratchov <alex@caoua.org>
475af46c2Stedu  *
575af46c2Stedu  * Permission to use, copy, modify, and distribute this software for any
675af46c2Stedu  * purpose with or without fee is hereby granted, provided that the above
775af46c2Stedu  * copyright notice and this permission notice appear in all copies.
875af46c2Stedu  *
975af46c2Stedu  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1075af46c2Stedu  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1175af46c2Stedu  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1275af46c2Stedu  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1375af46c2Stedu  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1475af46c2Stedu  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1575af46c2Stedu  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1675af46c2Stedu  */
1775af46c2Stedu 
1875af46c2Stedu #include <stdlib.h>
1975af46c2Stedu #include <unistd.h>
2075af46c2Stedu 
2175af46c2Stedu #include "debug.h"
2275af46c2Stedu 
2375af46c2Stedu /*
2475af46c2Stedu  * debug level, -1 means uninitialized
2575af46c2Stedu  */
2675af46c2Stedu int ifuse_debug = -1;
2775af46c2Stedu 
2875af46c2Stedu void
ifuse_debug_init(void)2975af46c2Stedu ifuse_debug_init(void)
3075af46c2Stedu {
3175af46c2Stedu 	char *dbg;
3275af46c2Stedu 
33*c839d22fShelg 	/* Default to level 1 unless FUSE_DEBUG environment variable is set. */
3475af46c2Stedu 	if (ifuse_debug < 0) {
3575af46c2Stedu 		dbg = issetugid() ? NULL : getenv("FUSE_DEBUG");
3675af46c2Stedu 		if (!dbg || sscanf(dbg, "%u", &ifuse_debug) != 1)
37*c839d22fShelg 			ifuse_debug = 1;
3875af46c2Stedu 	}
3975af46c2Stedu }
40