using process name as the key for add/remove events
This commit is contained in:
@@ -8,6 +8,7 @@ extern "C"
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <cstring>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
@@ -23,7 +24,7 @@ static std::pair<int,int> self_pipe = std::make_pair(-1, -1);
|
|||||||
|
|
||||||
static bool monitor_run_flag = false;
|
static bool monitor_run_flag = false;
|
||||||
static NethogsMonitorCallback monitor_udpate_callback;
|
static NethogsMonitorCallback monitor_udpate_callback;
|
||||||
typedef std::map<int, NethogsMonitorUpdate> NethogsAppUpdateMap;
|
typedef std::map<const char*, NethogsMonitorUpdate> NethogsAppUpdateMap;
|
||||||
static NethogsAppUpdateMap monitor_update_data;
|
static NethogsAppUpdateMap monitor_update_data;
|
||||||
|
|
||||||
static int monitor_refresh_delay = 1;
|
static int monitor_refresh_delay = 1;
|
||||||
@@ -206,13 +207,13 @@ static void nethogsmonitor_handle_update(NethogsMonitorCallback cb)
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
std::cout << "PROC: Deleting process\n";
|
std::cout << "PROC: Deleting process\n";
|
||||||
|
|
||||||
NethogsAppUpdateMap::iterator it = monitor_update_data.find(curproc->getVal()->pid);
|
NethogsAppUpdateMap::iterator it = monitor_update_data.find(curproc->getVal()->name);
|
||||||
if( it != monitor_update_data.end() )
|
if( it != monitor_update_data.end() )
|
||||||
{
|
{
|
||||||
NethogsMonitorUpdate& data = it->second;
|
NethogsMonitorUpdate& data = it->second;
|
||||||
data.action = NETHOGS_APP_ACTION_REMOVE;
|
data.action = NETHOGS_APP_ACTION_REMOVE;
|
||||||
(*cb)(&data);
|
(*cb)(&data);
|
||||||
monitor_update_data.erase(curproc->getVal()->pid);
|
monitor_update_data.erase(curproc->getVal()->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcList * todelete = curproc;
|
ProcList * todelete = curproc;
|
||||||
@@ -233,7 +234,7 @@ static void nethogsmonitor_handle_update(NethogsMonitorCallback cb)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const int pid = curproc->getVal()->pid;
|
const char* name = curproc->getVal()->name;
|
||||||
const u_int32_t uid = curproc->getVal()->getUid();
|
const u_int32_t uid = curproc->getVal()->getUid();
|
||||||
u_int32_t sent_bytes;
|
u_int32_t sent_bytes;
|
||||||
u_int32_t recv_bytes;
|
u_int32_t recv_bytes;
|
||||||
@@ -243,16 +244,16 @@ static void nethogsmonitor_handle_update(NethogsMonitorCallback cb)
|
|||||||
curproc->getVal()->gettotal (&recv_bytes, &sent_bytes);
|
curproc->getVal()->gettotal (&recv_bytes, &sent_bytes);
|
||||||
|
|
||||||
//notify update
|
//notify update
|
||||||
bool const new_data = (monitor_update_data.find(pid) == monitor_update_data.end());
|
bool const new_data = (monitor_update_data.find(name) == monitor_update_data.end());
|
||||||
NethogsMonitorUpdate &data = monitor_update_data[pid];
|
NethogsMonitorUpdate &data = monitor_update_data[name];
|
||||||
|
|
||||||
bool data_change = false;
|
bool data_change = false;
|
||||||
if( new_data )
|
if( new_data )
|
||||||
{
|
{
|
||||||
data_change = true;
|
data_change = true;
|
||||||
memset(&data, 0, sizeof(data));
|
memset(&data, 0, sizeof(data));
|
||||||
data.pid = pid;
|
data.name = curproc->getVal()->name;
|
||||||
data.app_name = curproc->getVal()->name;
|
data.pid = curproc->getVal()->pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.device_name = curproc->getVal()->devicename;
|
data.device_name = curproc->getVal()->devicename;
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ extern "C" {
|
|||||||
|
|
||||||
typedef struct NethogsMonitorUpdate
|
typedef struct NethogsMonitorUpdate
|
||||||
{
|
{
|
||||||
int action;
|
int action; // NETHOGS_APP_ACTION_SET or NETHOGS_APP_ACTION_REMOVE
|
||||||
|
const char* name; //the key of the set/remove
|
||||||
int pid;
|
int pid;
|
||||||
uint32_t uid;
|
uint32_t uid;
|
||||||
const char* app_name;
|
|
||||||
const char* device_name;
|
const char* device_name;
|
||||||
uint32_t sent_bytes;
|
uint32_t sent_bytes;
|
||||||
uint32_t recv_bytes;
|
uint32_t recv_bytes;
|
||||||
|
|||||||
Reference in New Issue
Block a user