summaryrefslogtreecommitdiff
path: root/pcap_sg.c
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-04-09 09:51:26 +0200
committerDaniel Borkmann <dborkman@redhat.com>2013-04-09 09:51:26 +0200
commita4703f2a060a81397da497b85bc135187f0f89e9 (patch)
treedbae97c2ec9e0b74fa85e06ccdc18e3f6197b515 /pcap_sg.c
parent5be3139e456d85b18e166643ce1636b0ecdbccc3 (diff)
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 <doug.burks@gmail.com> Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Diffstat (limited to 'pcap_sg.c')
-rw-r--r--pcap_sg.c8
1 files changed, 6 insertions, 2 deletions
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,