Log server messages to file
authorGeoff Levand <geoffrey.levand@am.sony.com>
Fri, 27 Feb 2009 14:54:06 +0000 (14:54 +0000)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 23 Mar 2009 10:49:44 +0000 (21:49 +1100)
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
discover/params.c
discover/pb-discover.c
discover/udev.c

index e03a44a6ba8b564e306ff519169f2c74c7f22ea9..47ab4945e2df3071b2f35899cdff48b9badd0f50 100644 (file)
@@ -66,12 +66,12 @@ static void print_clients(struct discover_server *server)
 {
        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);
 }
index 76a14514912804a829d4c2769c6dfed745179192..d78730a0ef0253e7a0a5ab8a502a7b31142a7b6e 100644 (file)
 #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
index d8709b3974693f8657a61709e032486ec2ead08e..2b04e62ee0247ab95d153325c9d3f2f865ca28bb 100644 (file)
@@ -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;
 }
index 9d628407ca761bd3894c29ad122d6cffbf2fa974..b93c1a5f0ff6d68dace1c0cf8605c528dd11f3c2 100644 (file)
@@ -82,10 +82,10 @@ static void print_event(struct udev_event *event)
        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]));
 
 }