No more need for the refresh signal because select() timeout replaces it

This commit is contained in:
Mohamed Boussaffa
2016-03-07 06:13:04 +08:00
parent cb2a699d57
commit 9015e6c27f
5 changed files with 16 additions and 83 deletions

View File

@@ -24,7 +24,7 @@ CFLAGS?=-Wall -Wextra
CXXFLAGS?=-Wall -Wextra
endif
OBJS=packet.o connection.o process.o refresh.o decpcap.o cui.o inode2prog.o conninode.o devices.o
OBJS=packet.o connection.o process.o decpcap.o cui.o inode2prog.o conninode.o devices.o
NCURSES_LIBS?=-lncurses
@@ -64,8 +64,6 @@ decpcap_test: decpcap_test.cpp decpcap.o
#-lefence
refresh.o: refresh.cpp refresh.h nethogs.h
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c refresh.cpp
process.o: process.cpp process.h nethogs.h
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c process.cpp
packet.o: packet.cpp packet.h nethogs.h

View File

@@ -3,6 +3,7 @@
#include <vector>
std::pair<int,int> self_pipe = std::make_pair(-1, -1);
time_t last_refresh_time = 0;
static void versiondisplay(void)
{
@@ -131,17 +132,17 @@ int main (int argc, char** argv)
}
}
if ((!tracemode) && (!DEBUG)){
init_ui();
}
std::pair<int,int> self_pipe = createSelfPipe();
self_pipe = createSelfPipe();
if( self_pipe.first == -1 || self_pipe.second == -1 )
{
perror("Error creating pipe file descriptors\n");
return 0;
}
if ((!tracemode) && (!DEBUG)){
init_ui();
}
if (NEEDROOT && (geteuid() != 0))
forceExit(false, "You need to be root to run NetHogs!");
@@ -209,9 +210,7 @@ int main (int argc, char** argv)
pc_loop_fd_list.push_back(self_pipe.first);
}
signal (SIGALRM, &alarm_cb);
signal (SIGINT, &quit_cb);
alarm (refreshdelay);
fprintf(stderr, "Waiting for first packet to arrive (see sourceforge.net bug 1019381)\n");
struct dpargs * userdata = (dpargs *) malloc (sizeof (struct dpargs));
@@ -241,16 +240,16 @@ int main (int argc, char** argv)
current_handle = current_handle->next;
}
if (needrefresh)
time_t const now = ::time(NULL);
if( last_refresh_time + refreshdelay <= now )
{
last_refresh_time = now;
if ((!DEBUG)&&(!tracemode))
{
// handle user input
ui_tick();
}
do_refresh();
needrefresh = false;
}
//if not packets, do a select() until next packet
@@ -270,8 +269,8 @@ int main (int argc, char** argv)
timeval timeout = {refreshdelay, 0};
if( select(nfds, &pc_loop_fd_set, 0, 0, &timeout) == -1 )
{
perror("error in select()\n");
break;
//this happens on system signal
continue;
}
if( FD_ISSET(self_pipe.first, &pc_loop_fd_set) )
{

View File

@@ -46,7 +46,6 @@ extern "C" {
#include "packet.h"
#include "connection.h"
#include "process.h"
#include "refresh.h"
#include "devices.h"
extern Process * unknownudp;
@@ -57,7 +56,6 @@ unsigned refreshcount = 0;
unsigned processlimit = 0;
bool tracemode = false;
bool bughuntmode = false;
bool needrefresh = false;
// sort on sent or received?
bool sortRecv = true;
// viewMode: kb/s or total

View File

@@ -1,39 +0,0 @@
/*
* refresh.cpp
*
* Copyright (c) 2004 Arnout Engelen
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <iostream>
#include <csignal>
#include <unistd.h>
#include "nethogs.h"
extern bool needrefresh;
extern unsigned refreshdelay;
void alarm_cb (int /*i*/)
{
needrefresh = true;
//cout << "Setting needrefresh\n";
signal (SIGALRM, &alarm_cb);
alarm(refreshdelay);
}

View File

@@ -1,23 +0,0 @@
/*
* refresh.h
*
* Copyright (c) 2004 Arnout Engelen
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
void alarm_cb (int i);