From f6d211974eff4ba67461262031af54fdb4f54210 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Thu, 7 May 2015 08:48:19 +0300 Subject: netsniff-ng: Open pcap w/o O_NOATIME on 2nd try If the file open fails with O_NOATIME option then try to open it w/o this option in case if the user does not have enough prvileges to use O_NOATIME. It fixes the case when user made pcap file in sudo mode but after it should still use sudo to read it because of setting O_NOATIME option requires higher privileges. Signed-off-by: Vadim Kochan Signed-off-by: Tobias Klauser --- netsniff-ng.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/netsniff-ng.c b/netsniff-ng.c index dfab81a..d6782ac 100644 --- a/netsniff-ng.c +++ b/netsniff-ng.c @@ -570,7 +570,12 @@ static void read_pcap(struct ctx *ctx) if (ctx->pcap == PCAP_OPS_MM) ctx->pcap = PCAP_OPS_SG; } else { - fd = open_or_die(ctx->device_in, O_RDONLY | O_LARGEFILE | O_NOATIME); + fd = open(ctx->device_in, O_RDONLY | O_LARGEFILE | O_NOATIME); + if (fd < 0 && errno == EPERM) + fd = open_or_die(ctx->device_in, O_RDONLY | O_LARGEFILE); + if (fd < 0) + panic("Cannot open file %s! %s.\n", ctx->device_in, + strerror(errno)); } if (__pcap_io->init_once_pcap) -- cgit v1.2.3-54-g00ecf