Skip to content

Commit

Permalink
net/bpfilter: fix dprintf usage for /dev/kmsg
Browse files Browse the repository at this point in the history
The bpfilter UMH code was recently changed to log its informative messages to
/dev/kmsg, however this interface doesn't support SEEK_CUR yet, used by
dprintf(). As result dprintf() returns -EINVAL and doesn't log anything.

However there already had some discussions about supporting SEEK_CUR into
/dev/kmsg interface in the past it wasn't concluded. Since the only user of
that from userspace perspective inside the kernel is the bpfilter UMH
(userspace) module it's better to correct it here instead waiting a conclusion
on the interface.

Fixes: 36c4357 ("net: bpfilter: print umh messages to /dev/kmsg")
Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Bruno Meneguele authored and David S. Miller committed Mar 15, 2020
1 parent 0d1c353 commit 13d0f7b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions net/bpfilter/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <asm/unistd.h>
#include "msgfmt.h"

int debug_fd;
FILE *debug_f;

static int handle_get_cmd(struct mbox_request *cmd)
{
Expand All @@ -35,9 +35,10 @@ static void loop(void)
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;
}

Expand All @@ -47,17 +48,18 @@ static void loop(void)

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;
}

0 comments on commit 13d0f7b

Please sign in to comment.