The following commit has been merged in the master branch:
commit 5e7235bf69f016a1ade715c4a6be3a40d2cde4b5
Author: Guillem Jover <[email protected]>
Date: Fri Feb 4 04:26:37 2011 +0100
Move and generalize debug API from dpkg to libdpkg
diff --git a/lib/dpkg/Makefile.am b/lib/dpkg/Makefile.am
index f43e25c..60a9435 100644
--- a/lib/dpkg/Makefile.am
+++ b/lib/dpkg/Makefile.am
@@ -30,6 +30,7 @@ libdpkg_a_SOURCES = \
compress.c \
database.c \
dbmodify.c \
+ debug.c \
dir.c \
dump.c \
ehandle.c \
@@ -69,6 +70,7 @@ pkginclude_HEADERS = \
buffer.h \
command.h \
compress.h \
+ debug.h \
dir.h \
dpkg.h \
dpkg-db.h \
diff --git a/lib/dpkg/debug.c b/lib/dpkg/debug.c
new file mode 100644
index 0000000..7ff12b3
--- /dev/null
+++ b/lib/dpkg/debug.c
@@ -0,0 +1,84 @@
+/*
+ * libdpkg - Debian packaging suite library routines
+ * debug.c - debugging support
+ *
+ * Copyright © 1995 Ian Jackson <[email protected]>
+ * Copyright © 2011 Guillem Jover <[email protected]>
+ *
+ * This 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 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <compat.h>
+
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <dpkg/debug.h>
+
+static int debug_mask = 0;
+static FILE *debug_output = NULL;
+
+/**
+ * Set the debugging output file.
+ */
+void
+debug_set_output(FILE *output)
+{
+ debug_output = output;
+}
+
+/**
+ * Set the debugging mask.
+ *
+ * The mask determines what debugging flags are going to take effect at
+ * run-time. The output will be set to stderr if it has not been set before.
+ */
+void
+debug_set_mask(int mask)
+{
+ debug_mask = mask;
+ if (!debug_output)
+ debug_output = stderr;
+}
+
+/**
+ * Check if a debugging flag is currently set on the debugging mask.
+ */
+bool
+debug_has_flag(int flag)
+{
+ return debug_mask & flag;
+}
+
+/**
+ * Output a debugging message.
+ *
+ * The message will be printed to the previously specified output if the
+ * specified flag is present in the current debugging mask.
+ */
+void
+debug(int flag, const char *fmt, ...)
+{
+ va_list args;
+
+ if (!debug_has_flag(flag))
+ return;
+
+ fprintf(debug_output, "D0%05o: ", flag);
+ va_start(args, fmt);
+ vfprintf(debug_output, fmt, args);
+ va_end(args);
+ putc('\n', debug_output);
+}
diff --git a/lib/dpkg/file.h b/lib/dpkg/debug.h
similarity index 53%
copy from lib/dpkg/file.h
copy to lib/dpkg/debug.h
index 5ea0849..291bc83 100644
--- a/lib/dpkg/file.h
+++ b/lib/dpkg/debug.h
@@ -1,8 +1,8 @@
/*
* libdpkg - Debian packaging suite library routines
- * file.h - file handling routines
+ * debug.h - debugging support
*
- * Copyright © 2008-2010 Guillem Jover <[email protected]>
+ * Copyright © 2011 Guillem Jover <[email protected]>
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,36 +18,37 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef LIBDPKG_FILE_H
-#define LIBDPKG_FILE_H
+#ifndef LIBDPKG_DEBUG_H
+#define LIBDPKG_DEBUG_H
-#include <sys/types.h>
+#include <dpkg/macros.h>
#include <stdbool.h>
-
-#include <dpkg/macros.h>
+#include <stdio.h>
DPKG_BEGIN_DECLS
-struct file_stat {
- uid_t uid;
- gid_t gid;
- mode_t mode;
- time_t mtime;
-};
-
-void file_copy_perms(const char *src, const char *dst);
-
-enum file_lock_flags {
- FILE_LOCK_NOWAIT,
- FILE_LOCK_WAIT,
+enum debugflags {
+ dbg_general = 01,
+ dbg_scripts = 02,
+ dbg_eachfile = 010,
+ dbg_eachfiledetail = 0100,
+ dbg_conff = 020,
+ dbg_conffdetail = 0200,
+ dbg_depcon = 040,
+ dbg_depcondetail = 0400,
+ dbg_veryverbose = 01000,
+ dbg_stupidlyverbose = 02000,
+ dbg_triggers = 010000,
+ dbg_triggersdetail = 020000,
+ dbg_triggersstupid = 040000,
};
-bool file_is_locked(int lockfd, const char *filename);
-void file_lock(int *lockfd, enum file_lock_flags flags, const char *filename,
- const char *desc);
-void file_unlock(void);
+void debug_set_output(FILE *output);
+void debug_set_mask(int mask);
+bool debug_has_flag(int flag);
+void debug(int flag, const char *fmt, ...) DPKG_ATTR_PRINTF(2);
DPKG_END_DECLS
-#endif /* LIBDPKG_FILE_H */
+#endif /* LIBDPKG_DEBUG_H */
diff --git a/lib/dpkg/libdpkg.Versions b/lib/dpkg/libdpkg.Versions
index 648a420..8100b00 100644
--- a/lib/dpkg/libdpkg.Versions
+++ b/lib/dpkg/libdpkg.Versions
@@ -28,6 +28,11 @@ LIBDPKG_PRIVATE {
warningv;
warning;
+ debug_set_output;
+ debug_set_mask;
+ debug_has_flag;
+ debug;
+
# Generic cleanup
cu_closepipe;
cu_closefile;
diff --git a/src/depcon.c b/src/depcon.c
index 02dacb4..084e021 100644
--- a/src/depcon.c
+++ b/src/depcon.c
@@ -110,7 +110,7 @@ findbreakcyclerecursive(struct pkginfo *pkg, struct
cyclesofarlink *sofar)
return false;
pkg->clientdata->color = gray;
- if (f_debug & dbg_depcondetail) {
+ if (debug_has_flag(dbg_depcondetail)) {
struct varbuf str_pkgs = VARBUF_INIT;
for (sol = sofar; sol; sol = sol->prev) {
diff --git a/src/help.c b/src/help.c
index 63e0031..551592a 100644
--- a/src/help.c
+++ b/src/help.c
@@ -190,7 +190,7 @@ preexecscript(struct command *cmd)
if (chdir("/"))
ohshite(_("failed to chdir to `%.255s'"), "/");
}
- if (f_debug & dbg_scripts) {
+ if (debug_has_flag(dbg_scripts)) {
struct varbuf args = VARBUF_INIT;
const char **argv = cmd->argv;
@@ -458,17 +458,6 @@ void clear_istobes(void) {
pkg_db_iter_free(it);
}
-void debug(int which, const char *fmt, ...) {
- va_list args;
-
- if (!(f_debug & which)) return;
- fprintf(stderr,"D0%05o: ",which);
- va_start(args, fmt);
- vfprintf(stderr, fmt, args);
- va_end(args);
- putc('\n',stderr);
-}
-
/*
* Returns true if the directory contains conffiles belonging to pkg,
* false otherwise.
diff --git a/src/main.c b/src/main.c
index dfbdb73..3e6277a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -179,7 +179,6 @@ const char printforhelp[]= N_(
int f_pending=0, f_recursive=0, f_alsoselect=1, f_skipsame=0, f_noact=0;
int f_autodeconf=0, f_nodebsig=0;
int f_triggers = 0;
-unsigned long f_debug=0;
int fc_downgrade=1, fc_configureany=0, fc_hold=0, fc_removereinstreq=0,
fc_overwrite=0;
int fc_removeessential=0, fc_conflicts=0, fc_depends=0, fc_dependsversion=0;
int fc_breaks=0, fc_badpath=0, fc_overwritediverted=0, fc_architecture=0;
@@ -225,6 +224,7 @@ static const struct forceinfo {
static void setdebug(const struct cmdinfo *cpi, const char *value) {
char *endp;
+ unsigned long mask;
if (*value == 'h') {
printf(_(
@@ -251,8 +251,10 @@ static void setdebug(const struct cmdinfo *cpi, const char
*value) {
exit(0);
}
- f_debug= strtoul(value,&endp,8);
+ mask = strtoul(value, &endp, 8);
if (value == endp || *endp) badusage(_("--debug requires an octal
argument"));
+
+ debug_set_mask(mask);
}
static void
diff --git a/src/main.h b/src/main.h
index 1316ba1..463ad99 100644
--- a/src/main.h
+++ b/src/main.h
@@ -21,6 +21,7 @@
#ifndef MAIN_H
#define MAIN_H
+#include <dpkg/debug.h>
#include <dpkg/pkg-list.h>
/* These two are defined in filesdb.h. */
@@ -124,7 +125,6 @@ extern const char *const statusstrings[];
extern int f_pending, f_recursive, f_alsoselect, f_skipsame, f_noact;
extern int f_autodeconf, f_nodebsig;
extern int f_triggers;
-extern unsigned long f_debug;
extern int fc_downgrade, fc_configureany, fc_hold, fc_removereinstreq,
fc_overwrite;
extern int fc_removeessential, fc_conflicts, fc_depends, fc_dependsversion;
extern int fc_breaks, fc_badpath, fc_overwritediverted, fc_architecture;
@@ -253,23 +253,6 @@ void clear_istobes(void);
bool isdirectoryinuse(struct filenamenode *namenode, struct pkginfo *pkg);
bool hasdirectoryconffiles(struct filenamenode *namenode, struct pkginfo *pkg);
-enum debugflags {
- dbg_general= 00001,
- dbg_scripts= 00002,
- dbg_eachfile= 00010,
- dbg_eachfiledetail= 00100,
- dbg_conff= 00020,
- dbg_conffdetail= 00200,
- dbg_depcon= 00040,
- dbg_depcondetail= 00400,
- dbg_veryverbose= 01000,
- dbg_stupidlyverbose= 02000,
- dbg_triggers = 010000,
- dbg_triggersdetail = 020000,
- dbg_triggersstupid = 040000,
-};
-
-void debug(int which, const char *fmt, ...) DPKG_ATTR_PRINTF(2);
void log_action(const char *action, struct pkginfo *pkg);
/* from trigproc.c */
--
dpkg's main repository
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]