Patchwork [16/16] petitboot: Log server messages to file

login
register
mail settings
Submitter Geoff Levand
Date Feb. 28, 2009, 12:54 a.m.
Message ID <20090228005351.105452208@am.sony.com>
Download mbox | patch
Permalink /patch/23861/
State Accepted
Headers show

Comments

Geoff Levand - Feb. 28, 2009, 12:54 a.m.
Log discover server messages to a file.  Helps in debugging
the server when is has problems at system startup.

Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
---
 discover/discover-server.c |    4 ++--
 discover/params.c          |    8 ++++----
 discover/pb-discover.c     |   12 ++++++++++++
 discover/udev.c            |    4 ++--
 4 files changed, 20 insertions(+), 8 deletions(-)

Patch

--- a/discover/discover-server.c
+++ b/discover/discover-server.c
@@ -66,12 +66,12 @@  static void print_clients(struct discove
 {
 	struct client *client;
 
-	printf("current clients [%p,%p,%p]:\n",
+	pb_log("current clients [%p,%p,%p]:\n",
 			&server->clients.head,
 			server->clients.head.prev,
 			server->clients.head.next);
 	list_for_each_entry(&server->clients, client, list)
-		printf("\t[%p,%p,%p] client: %d\n", &client->list,
+		pb_log("\t[%p,%p,%p] client: %d\n", &client->list,
 				client->list.prev, client->list.next,
 				client->fd);
 }
--- a/discover/params.c
+++ b/discover/params.c
@@ -28,10 +28,10 @@ 
 #define realloc_array(ptr, type, num) \
 	((type *)_realloc_array((ptr), sizeof(type), (num)))
 
-#define rprintf(x, ...) do { fprintf(stderr, ##__VA_ARGS__);	\
-				fprintf(stderr, "\n"); } while (0)
-#define rsyserr(x, y, ...) do { fprintf(stderr, ##__VA_ARGS__);	\
-				fprintf(stderr, "\n"); } while (0)
+#define rprintf(x, ...) do { pb_log(stderr, ##__VA_ARGS__);	\
+				pb_log(stderr, "\n"); } while (0)
+#define rsyserr(x, y, ...) do { pb_log(stderr, ##__VA_ARGS__);	\
+				pb_log(stderr, "\n"); } while (0)
 
 #define MALLOC_MAX 0x40000000
 #define False 0
--- a/discover/pb-discover.c
+++ b/discover/pb-discover.c
@@ -1,4 +1,5 @@ 
 
+#include <assert.h>
 #include <stdlib.h>
 #include <signal.h>
 
@@ -21,6 +22,16 @@  int main(void)
 	struct device_handler *handler;
 	struct discover_server *server;
 	struct udev *udev;
+	FILE *log;
+
+	log = fopen("pb-discover.log", "a");
+	assert(log);
+	pb_log_set_stream(log);
+
+#if defined(DEBUG)
+	pb_log_always_flush(1);
+#endif
+	pb_log("--- pb-discover ---\n");
 
 	/* we look for closed sockets when we write, so ignore SIGPIPE */
 	signal(SIGPIPE, SIG_IGN);
@@ -48,6 +59,7 @@  int main(void)
 
 	device_handler_destroy(handler);
 
+	pb_log("--- end ---\n");
 
 	return EXIT_SUCCESS;
 }
--- a/discover/udev.c
+++ b/discover/udev.c
@@ -82,10 +82,10 @@  static void print_event(struct udev_even
 	action = event->action == UDEV_ACTION_ADD ? "add" : "remove";
 
 	pb_log("udev %s event:\n", action);
-	printf("\tdevice: %s\n", event->device);
+	pb_log("\tdevice: %s\n", event->device);
 
 	for (i = 0; params[i]; i++)
-		printf("\t%-12s => %s\n",
+		pb_log("\t%-12s => %s\n",
 				params[i], udev_event_param(event, params[i]));
 
 }