#include <asm/unistd.h>
 #include "msgfmt.h"
 
-int debug_fd;
+FILE *debug_f;
 
 static int handle_get_cmd(struct mbox_request *cmd)
 {
                struct mbox_reply reply;
                int n;
 
+               fprintf(debug_f, "testing the buffer\n");
                n = read(0, &req, sizeof(req));
                if (n != sizeof(req)) {
-                       dprintf(debug_fd, "invalid request %d\n", n);
+                       fprintf(debug_f, "invalid request %d\n", n);
                        return;
                }
 
 
                n = write(1, &reply, sizeof(reply));
                if (n != sizeof(reply)) {
-                       dprintf(debug_fd, "reply failed %d\n", n);
+                       fprintf(debug_f, "reply failed %d\n", n);
                        return;
                }
        }
 
 int main(void)
 {
-       debug_fd = open("/dev/kmsg", 00000002);
-       dprintf(debug_fd, "Started bpfilter\n");
+       debug_f = fopen("/dev/kmsg", "w");
+       setvbuf(debug_f, 0, _IOLBF, 0);
+       fprintf(debug_f, "Started bpfilter\n");
        loop();
-       close(debug_fd);
+       fclose(debug_f);
        return 0;
 }