No more need for the refresh signal because select() timeout replaces it
This commit is contained in:
4
Makefile
4
Makefile
@@ -24,7 +24,7 @@ CFLAGS?=-Wall -Wextra
|
|||||||
CXXFLAGS?=-Wall -Wextra
|
CXXFLAGS?=-Wall -Wextra
|
||||||
endif
|
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
|
NCURSES_LIBS?=-lncurses
|
||||||
|
|
||||||
@@ -64,8 +64,6 @@ decpcap_test: decpcap_test.cpp decpcap.o
|
|||||||
|
|
||||||
#-lefence
|
#-lefence
|
||||||
|
|
||||||
refresh.o: refresh.cpp refresh.h nethogs.h
|
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c refresh.cpp
|
|
||||||
process.o: process.cpp process.h nethogs.h
|
process.o: process.cpp process.h nethogs.h
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c process.cpp
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c process.cpp
|
||||||
packet.o: packet.cpp packet.h nethogs.h
|
packet.o: packet.cpp packet.h nethogs.h
|
||||||
|
|||||||
29
main.cpp
29
main.cpp
@@ -3,6 +3,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
std::pair<int,int> self_pipe = std::make_pair(-1, -1);
|
std::pair<int,int> self_pipe = std::make_pair(-1, -1);
|
||||||
|
time_t last_refresh_time = 0;
|
||||||
|
|
||||||
static void versiondisplay(void)
|
static void versiondisplay(void)
|
||||||
{
|
{
|
||||||
@@ -131,17 +132,17 @@ int main (int argc, char** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!tracemode) && (!DEBUG)){
|
self_pipe = createSelfPipe();
|
||||||
init_ui();
|
if( self_pipe.first == -1 || self_pipe.second == -1 )
|
||||||
}
|
|
||||||
|
|
||||||
std::pair<int,int> self_pipe = createSelfPipe();
|
|
||||||
if( self_pipe.first == -1|| self_pipe.second == -1 )
|
|
||||||
{
|
{
|
||||||
perror("Error creating pipe file descriptors\n");
|
perror("Error creating pipe file descriptors\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((!tracemode) && (!DEBUG)){
|
||||||
|
init_ui();
|
||||||
|
}
|
||||||
|
|
||||||
if (NEEDROOT && (geteuid() != 0))
|
if (NEEDROOT && (geteuid() != 0))
|
||||||
forceExit(false, "You need to be root to run NetHogs!");
|
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);
|
pc_loop_fd_list.push_back(self_pipe.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
signal (SIGALRM, &alarm_cb);
|
|
||||||
signal (SIGINT, &quit_cb);
|
signal (SIGINT, &quit_cb);
|
||||||
alarm (refreshdelay);
|
|
||||||
|
|
||||||
fprintf(stderr, "Waiting for first packet to arrive (see sourceforge.net bug 1019381)\n");
|
fprintf(stderr, "Waiting for first packet to arrive (see sourceforge.net bug 1019381)\n");
|
||||||
struct dpargs * userdata = (dpargs *) malloc (sizeof (struct dpargs));
|
struct dpargs * userdata = (dpargs *) malloc (sizeof (struct dpargs));
|
||||||
@@ -241,16 +240,16 @@ int main (int argc, char** argv)
|
|||||||
current_handle = current_handle->next;
|
current_handle = current_handle->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time_t const now = ::time(NULL);
|
||||||
if (needrefresh)
|
if( last_refresh_time + refreshdelay <= now )
|
||||||
{
|
{
|
||||||
if ((!DEBUG)&&(!tracemode))
|
last_refresh_time = now;
|
||||||
|
if ((!DEBUG)&&(!tracemode))
|
||||||
{
|
{
|
||||||
// handle user input
|
// handle user input
|
||||||
ui_tick();
|
ui_tick();
|
||||||
}
|
}
|
||||||
do_refresh();
|
do_refresh();
|
||||||
needrefresh = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//if not packets, do a select() until next packet
|
//if not packets, do a select() until next packet
|
||||||
@@ -270,8 +269,8 @@ int main (int argc, char** argv)
|
|||||||
timeval timeout = {refreshdelay, 0};
|
timeval timeout = {refreshdelay, 0};
|
||||||
if( select(nfds, &pc_loop_fd_set, 0, 0, &timeout) == -1 )
|
if( select(nfds, &pc_loop_fd_set, 0, 0, &timeout) == -1 )
|
||||||
{
|
{
|
||||||
perror("error in select()\n");
|
//this happens on system signal
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
if( FD_ISSET(self_pipe.first, &pc_loop_fd_set) )
|
if( FD_ISSET(self_pipe.first, &pc_loop_fd_set) )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ extern "C" {
|
|||||||
#include "packet.h"
|
#include "packet.h"
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
#include "process.h"
|
#include "process.h"
|
||||||
#include "refresh.h"
|
|
||||||
#include "devices.h"
|
#include "devices.h"
|
||||||
|
|
||||||
extern Process * unknownudp;
|
extern Process * unknownudp;
|
||||||
@@ -57,7 +56,6 @@ unsigned refreshcount = 0;
|
|||||||
unsigned processlimit = 0;
|
unsigned processlimit = 0;
|
||||||
bool tracemode = false;
|
bool tracemode = false;
|
||||||
bool bughuntmode = false;
|
bool bughuntmode = false;
|
||||||
bool needrefresh = false;
|
|
||||||
// sort on sent or received?
|
// sort on sent or received?
|
||||||
bool sortRecv = true;
|
bool sortRecv = true;
|
||||||
// viewMode: kb/s or total
|
// viewMode: kb/s or total
|
||||||
|
|||||||
39
refresh.cpp
39
refresh.cpp
@@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
23
refresh.h
23
refresh.h
@@ -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);
|
|
||||||
Reference in New Issue
Block a user