Skip to contentSkip to conversation

converted debugf from macro to a function

PATCH In review Ildar Muslukhov 1 participant 2 messages Oct 8, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 converted debugf from macro to a function

This patch replaces debugf macro with a function.

---
 fils.c       |  6 +++---
 include/log.h |  1 +
 log.c         | 13 ++++++++++++-
 main.c        |  2 --
 sockets.c     |  8 ++++----
 tables.c      |  2 +-
 6 files changed, 21 insertions(+), 11 deletions(-)
files.c +3 -3
index a5296da..7fcfb77 100644
@@ -68,7 +68,7 @@ static int ignore_files(const char *path)
 		}
 
 		if (!strcmp(path, ignored_paths[i])) {
-//			printf("Skipping %s\n", path);
+			debugf("Skipping %s\n", path);
 			return 1;
 		}
 	}
@@ -85,14 +85,14 @@ static int ignore_files(const char *path)
 
 	for (i = 0; ignored_patterns[i]; i++) {
 		if (!strcmp(path + offset, ignored_patterns[i])) {
-//			printf("Skipping pattern %s\n", path);
+			debugf("Skipping pattern %s\n", path);
 			return 1;
 		}
 	}
 
 	/* special case to match tty* until I do globbing */
 	if (!strncmp(path + offset, "tty", 3)) {
-//		printf("Skipping %s\n", path);
+		debugf("Skipping %s\n", path);
 		return 1;
 	}
 	return 0;
include/log.h +1 -0
index bc870ab..b257b53 100644
@@ -36,6 +36,7 @@ void output_syscall_postfix(unsigned long ret, int errno_saved, bool err);
 
 void open_logfiles(void);
 void close_logfiles(void);
+void debugf(const char *fmt, ...);
 
 #define __stringify_1(x...)     #x
 #define __stringify(x...)       __stringify_1(x)
log.c +12 -1
index 6340d59..705153c 100644
@@ -423,4 +423,15 @@ void output_syscall_postfix(unsigned long ret, int errno_saved, bool err)
 		if (quiet_level == MAX_LOGLEVEL)
 			output_syscall_postfix_success(ret, stdout, monochrome);
 	}
-}
\ No newline at end of file
+}
+
+void debugf(const char *fmt, ...)
+{
+	va_list args;
+
+	if (debug == TRUE) {
+		va_start(args, fmt);
+		vprintf(fmt, args);
+		va_end(args);
+	}
+}
main.c +0 -2
index 0a1eba7..51732a6 100644
@@ -84,8 +84,6 @@ static void oom_score_adj(int adj)
 	fclose(fp);
 }
 
-#define debugf if (debug == TRUE) printf
-
 static void fork_children(void)
 {
 	int pidslot;
sockets.c +4 -4
index de43d4b..ee56e49 100644
@@ -49,15 +49,15 @@ static int open_socket(unsigned int domain, unsigned int type, unsigned int prot
 
 		ret = bind(fd, &sa, salen);
 /*		if (ret == -1)
-			printf("bind: %s\n", strerror(errno));
+			debugf("bind: %s\n", strerror(errno));
 		else
-			printf("bind: success!\n");
+			debugf("bind: success!\n");
 */
 		ret = listen(fd, (rand() % 2) + 1);
 /*		if (ret == -1)
-			printf("listen: %s\n", strerror(errno));
+			debugf("listen: %s\n", strerror(errno));
 		else
-			printf("listen: success!\n");
+			debugf("listen: success!\n");
 */
 	}
 
tables.c +1 -1
index fab6675..f159814 100644
@@ -38,7 +38,7 @@ int search_syscall_table(const struct syscalltable *table, unsigned int nr_sysca
 	/* search by name */
 	for (i = 0; i < nr_syscalls; i++) {
 		if (strcmp(arg, table[i].entry->name) == 0) {
-			//printf("Found %s at %u\n", table[i].entry->name, i);
+			//debugf("Found %s at %u\n", table[i].entry->name, i);
 			return i;
 		}
 	}
Signature · 1 line
1.8.4
#1 lore raw

This one is nothing major, just decided to fill one of the TODO on converting it to a function in order to contain as many printf in one source file as possible.

-ildar

Quoted 130 lines · Ildar Muslukhov

This patch replaces debugf macro with a function.

---
 fils.c       |  6 +++---
 include/log.h |  1 +
 log.c         | 13 ++++++++++++-
 main.c        |  2 --
 sockets.c     |  8 ++++----
 tables.c      |  2 +-
 6 files changed, 21 insertions(+), 11 deletions(-)
files.c +3 -3
index a5296da..7fcfb77 100644
@@ -68,7 +68,7 @@ static int ignore_files(const char *path)
                }
 
                if (!strcmp(path, ignored_paths[i])) {
-//                     printf("Skipping %s\n", path);
+                       debugf("Skipping %s\n", path);
                        return 1;
                }
        }
@@ -85,14 +85,14 @@ static int ignore_files(const char *path)
 
        for (i = 0; ignored_patterns[i]; i++) {
                if (!strcmp(path + offset, ignored_patterns[i])) {
-//                     printf("Skipping pattern %s\n", path);
+                       debugf("Skipping pattern %s\n", path);
                        return 1;
                }
        }
 
        /* special case to match tty* until I do globbing */
        if (!strncmp(path + offset, "tty", 3)) {
-//             printf("Skipping %s\n", path);
+               debugf("Skipping %s\n", path);
                return 1;
        }
        return 0;
include/log.h +1 -0
index bc870ab..b257b53 100644
@@ -36,6 +36,7 @@ void output_syscall_postfix(unsigned long ret, int errno_saved, bool err);
 
 void open_logfiles(void);
 void close_logfiles(void);
+void debugf(const char *fmt, ...);
 
 #define __stringify_1(x...)     #x
 #define __stringify(x...)       __stringify_1(x)
log.c +12 -1
index 6340d59..705153c 100644
@@ -423,4 +423,15 @@ void output_syscall_postfix(unsigned long ret, int errno_saved, bool err)
                if (quiet_level == MAX_LOGLEVEL)
                        output_syscall_postfix_success(ret, stdout, monochrome);
        }
-}
\ No newline at end of file
+}
+
+void debugf(const char *fmt, ...)
+{
+       va_list args;
+
+       if (debug == TRUE) {
+               va_start(args, fmt);
+               vprintf(fmt, args);
+               va_end(args);
+       }
+}
main.c +0 -2
index 0a1eba7..51732a6 100644
@@ -84,8 +84,6 @@ static void oom_score_adj(int adj)
        fclose(fp);
 }
 
-#define debugf if (debug == TRUE) printf
-
 static void fork_children(void)
 {
        int pidslot;
sockets.c +4 -4
index de43d4b..ee56e49 100644
@@ -49,15 +49,15 @@ static int open_socket(unsigned int domain, unsigned int type, unsigned int prot
 
                ret = bind(fd, &sa, salen);
 /*             if (ret == -1)
-                       printf("bind: %s\n", strerror(errno));
+                       debugf("bind: %s\n", strerror(errno));
                else
-                       printf("bind: success!\n");
+                       debugf("bind: success!\n");
 */
                ret = listen(fd, (rand() % 2) + 1);
 /*             if (ret == -1)
-                       printf("listen: %s\n", strerror(errno));
+                       debugf("listen: %s\n", strerror(errno));
                else
-                       printf("listen: success!\n");
+                       debugf("listen: success!\n");
 */
        }
 
tables.c +1 -2
index fab6675..f159814 100644
@@ -38,7 +38,7 @@ int search_syscall_table(const struct syscalltable *table, unsigned int nr_sysca
        /* search by name */
        for (i = 0; i < nr_syscalls; i++) {
                if (strcmp(arg, table[i].entry->name) == 0) {
-                       //printf("Found %s at %u\n", table[i].entry->name, i);
+                       //debugf("Found %s at %u\n", table[i].entry->name, i);
                        return i;
                }
        }
--

1.8.4