From a4703f2a060a81397da497b85bc135187f0f89e9 Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Tue, 9 Apr 2013 09:51:26 +0200 Subject: pcap_io: introduce init_once helper that is called with priviledges When using netsniff-ng with dropping priviledges, we have to introduce another pcap helper function that is called once before we drop the priviledges. In this function we have to invoke the disc I/O scheduler policy, because it needs priviledges. Otherwise netsniff-ng will fail with "Failed to set io prio for pid" on startup, since we're not root anymore. Reported-by: Doug Burks Signed-off-by: Daniel Borkmann --- pcap_sg.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'pcap_sg.c') diff --git a/pcap_sg.c b/pcap_sg.c index ad78ce7..6902001 100644 --- a/pcap_sg.c +++ b/pcap_sg.c @@ -146,6 +146,11 @@ static void pcap_sg_fsync(int fd) fdatasync(fd); } +static void pcap_sg_init_once(void) +{ + set_ioprio_rt(); +} + static int pcap_sg_prepare_access(int fd, enum pcap_mode mode, bool jumbo) { int i, ret; @@ -160,8 +165,6 @@ static int pcap_sg_prepare_access(int fd, enum pcap_mode mode, bool jumbo) iov[i].iov_len = len; } - set_ioprio_rt(); - if (mode == PCAP_MODE_RD) { ret = readv(fd, iov, array_size(iov)); if (ret <= 0) @@ -183,6 +186,7 @@ static void pcap_sg_prepare_close(int fd, enum pcap_mode mode) } const struct pcap_file_ops pcap_sg_ops = { + .init_once_pcap = pcap_sg_init_once, .pull_fhdr_pcap = pcap_generic_pull_fhdr, .push_fhdr_pcap = pcap_generic_push_fhdr, .prepare_access_pcap = pcap_sg_prepare_access, -- cgit v1.2.3-54-g00ecf