Skip to content

Commit 13d0f7b

Browse files
bmenegdavem330
authored andcommitted
net/bpfilter: fix dprintf usage for /dev/kmsg
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0d1c353 commit 13d0f7b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

net/bpfilter/main.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <asm/unistd.h>
1111
#include "msgfmt.h"
1212

13-
int debug_fd;
13+
FILE *debug_f;
1414

1515
static int handle_get_cmd(struct mbox_request *cmd)
1616
{
@@ -35,9 +35,10 @@ static void loop(void)
3535
struct mbox_reply reply;
3636
int n;
3737

38+
fprintf(debug_f, "testing the buffer\n");
3839
n = read(0, &req, sizeof(req));
3940
if (n != sizeof(req)) {
40-
dprintf(debug_fd, "invalid request %d\n", n);
41+
fprintf(debug_f, "invalid request %d\n", n);
4142
return;
4243
}
4344

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

4849
n = write(1, &reply, sizeof(reply));
4950
if (n != sizeof(reply)) {
50-
dprintf(debug_fd, "reply failed %d\n", n);
51+
fprintf(debug_f, "reply failed %d\n", n);
5152
return;
5253
}
5354
}
5455
}
5556

5657
int main(void)
5758
{
58-
debug_fd = open("/dev/kmsg", 00000002);
59-
dprintf(debug_fd, "Started bpfilter\n");
59+
debug_f = fopen("/dev/kmsg", "w");
60+
setvbuf(debug_f, 0, _IOLBF, 0);
61+
fprintf(debug_f, "Started bpfilter\n");
6062
loop();
61-
close(debug_fd);
63+
fclose(debug_f);
6264
return 0;
6365
}

0 commit comments

Comments
 (0)