Commit 936ca49e authored by David Zeuthen's avatar David Zeuthen

move to using _pk_debug and respect $POLKIT_DEBUG

parent b18bb2d8
......@@ -43,7 +43,8 @@ libpolkit_la_SOURCES = \
libpolkit-privilege-file-entry.h libpolkit-privilege-file-entry.c \
libpolkit-privilege-file.h libpolkit-privilege-file.c \
libpolkit-privilege-cache.h libpolkit-privilege-cache.c \
libpolkit-privilege-default.h libpolkit-privilege-default.c
libpolkit-privilege-default.h libpolkit-privilege-default.c \
libpolkit-debug.h libpolkit-debug.c
libpolkit_la_LIBADD = @GLIB_LIBS@ @DBUS_LIBS@
......
......@@ -44,6 +44,7 @@
#include <errno.h>
#include <glib.h>
#include "libpolkit-debug.h"
#include "libpolkit-caller.h"
/**
......@@ -414,10 +415,10 @@ libpolkit_caller_new_from_dbus_name (DBusConnection *con, const char *dbus_name,
}
not_in_session:
g_debug ("uid %d", uid);
g_debug ("pid %d", pid);
g_debug ("selinux context '%s'", selinux_context != NULL ? selinux_context : "(not set)");
g_debug ("ck session '%s'", ck_session_objpath != NULL ? ck_session_objpath : "(not in a session)");
_pk_debug ("uid %d", uid);
_pk_debug ("pid %d", pid);
_pk_debug ("selinux context '%s'", selinux_context != NULL ? selinux_context : "(not set)");
_pk_debug ("ck session '%s'", ck_session_objpath != NULL ? ck_session_objpath : "(not in a session)");
caller = libpolkit_caller_new ();
libpolkit_caller_set_dbus_name (caller, dbus_name);
......@@ -445,8 +446,8 @@ void
libpolkit_caller_debug (PolKitCaller *caller)
{
g_return_if_fail (caller != NULL);
g_debug ("PolKitCaller: refcount=%d dbus_name=%s uid=%d pid=%d selinux_context=%s",
caller->refcount, caller->dbus_name, caller->uid, caller->pid, caller->selinux_context);
_pk_debug ("PolKitCaller: refcount=%d dbus_name=%s uid=%d pid=%d selinux_context=%s",
caller->refcount, caller->dbus_name, caller->uid, caller->pid, caller->selinux_context);
if (caller->session != NULL)
libpolkit_session_debug (caller->session);
}
......@@ -37,6 +37,7 @@
#include <errno.h>
#include <glib.h>
#include "libpolkit-debug.h"
#include "libpolkit-context.h"
#include "libpolkit-privilege-cache.h"
......@@ -65,7 +66,12 @@ struct PolKitContext
* libpolkit_context_new:
* @error: return location for error
*
* Create a new context.
* Create a new context; loads PolicyKit files from
* /etc/PolicyKit/privileges unless the environment variable
* $POLKIT_PRIVILEGE_DIR points to a location.
*
* If the environment $POLKIT_DEBUG is set, libpolkit will spew lots
* of debug.
*
* Returns: #NULL if @error was set, otherwise the #PolKitPrivilegeCache object
**/
......@@ -77,9 +83,9 @@ libpolkit_context_new (GError **error)
pk_context = g_new0 (PolKitContext, 1);
pk_context->refcount = 1;
dirname = getenv ("POLKIT_PRIV_DIR");
dirname = getenv ("POLKIT_PRIVILEGE_DIR");
if (dirname != NULL) {
g_debug ("Using directory %s", dirname);
_pk_debug ("Using directory %s", dirname);
} else {
dirname = PACKAGE_SYSCONF_DIR "/PolicyKit/privileges";
}
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/***************************************************************************
*
* libpolkit.c : library for querying system-wide policy
*
* Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
*
* Licensed under the Academic Free License version 2.1
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
**************************************************************************/
/**
* SECTION:libpolkit-debug
* @short_description: Debug functions.
*
* These functions are used for debug purposes
**/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include "libpolkit-debug.h"
/**
* pk_debug:
* @format: format
*
* Print debug message
**/
void
_pk_debug (const char *format, ...)
{
va_list args;
static gboolean show_debug = FALSE;
static gboolean init = FALSE;
if (!init) {
init = TRUE;
if (getenv ("POLKIT_DEBUG") != NULL) {
show_debug = TRUE;
}
}
if (show_debug) {
va_start (args, format);
vfprintf (stdout, format, args);
va_end (args);
fprintf (stdout, "\n");
}
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/***************************************************************************
*
* libpolkit-debug.h : debug infrastructure for libpolkit
*
* Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
*
* Licensed under the Academic Free License version 2.1
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
**************************************************************************/
#ifndef LIBPOLKIT_DEBUG_H
#define LIBPOLKIT_DEBUG_H
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <glib.h>
void _pk_debug (const char *format, ...) __attribute__((__format__ (__printf__, 1, 2)));
#endif /* LIBPOLKIT_DEBUG_H */
......@@ -37,6 +37,7 @@
#include <errno.h>
#include <glib.h>
#include "libpolkit-debug.h"
#include "libpolkit-privilege-file.h"
#include "libpolkit-privilege-cache.h"
......@@ -112,7 +113,7 @@ libpolkit_privilege_cache_new (const char *dirname, GError **error)
path = g_strdup_printf ("%s/%s", dirname, file);
g_debug ("Loading %s", path);
_pk_debug ("Loading %s", path);
pf = libpolkit_privilege_file_new (path, error);
g_free (path);
......@@ -188,9 +189,9 @@ libpolkit_privilege_cache_debug (PolKitPrivilegeCache *privilege_cache)
GSList *i;
g_return_if_fail (privilege_cache != NULL);
g_debug ("PolKitPrivilegeCache: refcount=%d num_entries=%d ...",
privilege_cache->refcount,
privilege_cache->priv_entries == NULL ? 0 : g_slist_length (privilege_cache->priv_entries));
_pk_debug ("PolKitPrivilegeCache: refcount=%d num_entries=%d ...",
privilege_cache->refcount,
privilege_cache->priv_entries == NULL ? 0 : g_slist_length (privilege_cache->priv_entries));
for (i = privilege_cache->priv_entries; i != NULL; i = g_slist_next (i)) {
PolKitPrivilegeFileEntry *pfe = i->data;
......@@ -221,6 +222,8 @@ libpolkit_privilege_cache_get_entry (PolKitPrivilegeCache *privilege_cache,
pfe = NULL;
/* I'm sure it would be easy to make this O(1)... */
g_return_val_if_fail (privilege_cache != NULL, NULL);
g_return_val_if_fail (privilege != NULL, NULL);
......
......@@ -37,6 +37,7 @@
#include <errno.h>
#include <glib.h>
#include "libpolkit-debug.h"
#include "libpolkit-error.h"
#include "libpolkit-privilege-default.h"
......@@ -199,16 +200,16 @@ void
libpolkit_privilege_default_debug (PolKitPrivilegeDefault *privilege_default)
{
g_return_if_fail (privilege_default != NULL);
g_debug ("PolKitPrivilegeDefault: refcount=%d\n"
" default_remote_inactive=%s\n"
" default_remote_active=%s\n"
" default_local_inactive=%s\n"
" default_local_active=%s",
privilege_default->refcount,
libpolkit_result_to_string_representation (privilege_default->default_remote_inactive),
libpolkit_result_to_string_representation (privilege_default->default_remote_active),
libpolkit_result_to_string_representation (privilege_default->default_local_inactive),
libpolkit_result_to_string_representation (privilege_default->default_local_active));
_pk_debug ("PolKitPrivilegeDefault: refcount=%d\n"
" default_remote_inactive=%s\n"
" default_remote_active=%s\n"
" default_local_inactive=%s\n"
" default_local_active=%s",
privilege_default->refcount,
libpolkit_result_to_string_representation (privilege_default->default_remote_inactive),
libpolkit_result_to_string_representation (privilege_default->default_remote_active),
libpolkit_result_to_string_representation (privilege_default->default_local_inactive),
libpolkit_result_to_string_representation (privilege_default->default_local_active));
}
......
......@@ -37,6 +37,7 @@
#include <errno.h>
#include <glib.h>
#include "libpolkit-debug.h"
#include "libpolkit-error.h"
#include "libpolkit-result.h"
#include "libpolkit-privilege-file-entry.h"
......@@ -140,9 +141,9 @@ void
libpolkit_privilege_file_entry_debug (PolKitPrivilegeFileEntry *privilege_file_entry)
{
g_return_if_fail (privilege_file_entry != NULL);
g_debug ("PolKitPrivilegeFileEntry: refcount=%d privilege=%s",
privilege_file_entry->refcount,
privilege_file_entry->privilege);
_pk_debug ("PolKitPrivilegeFileEntry: refcount=%d privilege=%s",
privilege_file_entry->refcount,
privilege_file_entry->privilege);
libpolkit_privilege_default_debug (privilege_file_entry->defaults);
}
......
......@@ -37,6 +37,7 @@
#include <errno.h>
#include <glib.h>
#include "libpolkit-debug.h"
#include "libpolkit-privilege.h"
/**
......@@ -155,5 +156,5 @@ void
libpolkit_privilege_debug (PolKitPrivilege *privilege)
{
g_return_if_fail (privilege != NULL);
g_debug ("PolKitPrivilege: refcount=%d id=%s", privilege->refcount, privilege->id);
_pk_debug ("PolKitPrivilege: refcount=%d id=%s", privilege->refcount, privilege->id);
}
......@@ -37,6 +37,7 @@
#include <errno.h>
#include <glib.h>
#include "libpolkit-debug.h"
#include "libpolkit-resource.h"
/**
......@@ -203,5 +204,5 @@ void
libpolkit_resource_debug (PolKitResource *resource)
{
g_return_if_fail (resource != NULL);
g_debug ("PolKitResource: refcount=%d type=%s id=%s", resource->refcount, resource->type, resource->id);
_pk_debug ("PolKitResource: refcount=%d type=%s id=%s", resource->refcount, resource->type, resource->id);
}
......@@ -37,6 +37,7 @@
#include <errno.h>
#include <glib.h>
#include "libpolkit-debug.h"
#include "libpolkit-seat.h"
/**
......@@ -153,5 +154,5 @@ void
libpolkit_seat_debug (PolKitSeat *seat)
{
g_return_if_fail (seat != NULL);
g_debug ("PolKitSeat: refcount=%d objpath=%s", seat->refcount, seat->ck_objref);
_pk_debug ("PolKitSeat: refcount=%d objpath=%s", seat->refcount, seat->ck_objref);
}
......@@ -37,6 +37,7 @@
#include <errno.h>
#include <glib.h>
#include "libpolkit-debug.h"
#include "libpolkit-session.h"
......@@ -476,13 +477,13 @@ libpolkit_session_new_from_objpath (DBusConnection *con, const char *objpath, ui
dbus_message_unref (reply);
}
g_debug ("is_active %d", is_active);
g_debug ("is_local %d", is_local);
g_debug ("uid %d", uid);
_pk_debug ("is_active %d", is_active);
_pk_debug ("is_local %d", is_local);
_pk_debug ("uid %d", uid);
if (!is_local) {
g_debug ("remote host '%s'", remote_host);
_pk_debug ("remote host '%s'", remote_host);
}
g_debug ("ck seat '%s'", seat_path);
_pk_debug ("ck seat '%s'", seat_path);
session = libpolkit_session_new ();
libpolkit_session_set_ck_is_active (session, is_active);
......@@ -573,8 +574,9 @@ void
libpolkit_session_debug (PolKitSession *session)
{
g_return_if_fail (session != NULL);
g_debug ("PolKitSession: refcount=%d objpath=%s is_active=%d is_local=%d remote_host=%s",
session->refcount, session->ck_objref, session->is_active, session->is_local, session->remote_host);
_pk_debug ("PolKitSession: refcount=%d uid=%d objpath=%s is_active=%d is_local=%d remote_host=%s",
session->refcount, session->uid,
session->ck_objref, session->is_active, session->is_local, session->remote_host);
if (session->seat != NULL)
libpolkit_seat_debug (session->seat);
}
......@@ -45,6 +45,7 @@
#include <glib.h>
#include "libpolkit.h"
#include "libpolkit-debug.h"
/**
* libpolkit_get_seat_resource_association:
......@@ -128,7 +129,7 @@ libpolkit_can_session_access_resource (PolKitContext *pk_context,
if (cache == NULL)
goto out;
g_debug ("entering libpolkit_can_session_access_resource()");
_pk_debug ("entering libpolkit_can_session_access_resource()");
libpolkit_privilege_debug (privilege);
libpolkit_resource_debug (resource);
libpolkit_session_debug (session);
......@@ -154,7 +155,7 @@ libpolkit_can_session_access_resource (PolKitContext *pk_context,
resource,
session);
out:
g_debug ("... result was %s", libpolkit_result_to_string_representation (result));
_pk_debug ("... result was %s", libpolkit_result_to_string_representation (result));
return result;
}
......@@ -186,7 +187,7 @@ libpolkit_can_caller_access_resource (PolKitContext *pk_context,
if (cache == NULL)
goto out;
g_debug ("entering libpolkit_can_caller_access_resource()");
_pk_debug ("entering libpolkit_can_caller_access_resource()");
libpolkit_privilege_debug (privilege);
libpolkit_resource_debug (resource);
libpolkit_caller_debug (caller);
......@@ -213,6 +214,6 @@ libpolkit_can_caller_access_resource (PolKitContext *pk_context,
caller);
out:
g_debug ("... result was %s", libpolkit_result_to_string_representation (result));
_pk_debug ("... result was %s", libpolkit_result_to_string_representation (result));
return result;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment