Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/MakeLib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,4 @@ clean:
rm -f $(OBJS)
rm -f $(LIBNAME)
rm -f libnethogs.a
mkdir -p $(ODIR)
rmdir -p --ignore-fail-on-non-empty $(ODIR)
rmdir -p $(ODIR) 2>/dev/null || true
12 changes: 6 additions & 6 deletions src/conninode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,25 +188,25 @@ void refreshconninode() {
// delete conninode;
// conninode = new HashTable (256);

#if defined(__APPLE__) || defined(__FreeBSD__)
addprocinfo("net.inet.tcp.pcblist", conninode_tcp);
#else
#ifdef NETHOGS_HAVE_PROC
if (!addprocinfo("/proc/net/tcp", conninode_tcp)) {
std::cout << "Error: couldn't open /proc/net/tcp\n";
exit(0);
}
addprocinfo("/proc/net/tcp6", conninode_tcp);
#else
addprocinfo("net.inet.tcp.pcblist", conninode_tcp);
#endif

if (catchall) {
#if defined(__APPLE__) || defined(__FreeBSD__)
addprocinfo("net.inet.udp.pcblist", conninode_udp);
#else
#ifdef NETHOGS_HAVE_PROC
if (!addprocinfo("/proc/net/udp", conninode_udp)) {
std::cout << "Error: couldn't open /proc/net/udp\n";
exit(0);
}
addprocinfo("/proc/net/udp6", conninode_udp);
#else
addprocinfo("net.inet.udp.pcblist", conninode_udp);
#endif
}

Expand Down
10 changes: 9 additions & 1 deletion src/inode2prog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ void get_info_for_pid(const char *pid) {
closedir(dir);
}

#ifdef NETHOGS_HAVE_PROC
static quad_t get_ms() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
Expand All @@ -252,8 +253,14 @@ static void get_pids(std::set<pid_t> *pids) {
}
closedir(proc);
}
#endif /* NETHOGS_HAVE_PROC */

void garbage_collect_inodeproc() {
#ifndef NETHOGS_HAVE_PROC
/* No /proc to enumerate live pids against; the inode->pid table is never
* populated on these platforms, so there is nothing to collect. */
return;
#else
static quad_t last_ms = 0;
quad_t start_ms = 0;
if (bughuntmode) {
Expand Down Expand Up @@ -292,6 +299,7 @@ void garbage_collect_inodeproc() {
std::cout << "PERF: GC proctime: " << last_ms - start_ms << "[ms]"
<< std::endl;
}
#endif
}

/* updates the `inodeproc' inode-to-prg_node mapping
Expand Down Expand Up @@ -329,7 +337,7 @@ struct prg_node *findPID(unsigned long inode) {
return node;
}

#ifndef __APPLE__
#ifdef NETHOGS_HAVE_PROC
reread_mapping();
#endif

Expand Down
9 changes: 9 additions & 0 deletions src/nethogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@

#define _BSD_SOURCE 1

/* Linux exposes the connection->inode and inode->pid mappings through the
* /proc filesystem; macOS and the BSDs do not (and their native procfs, when
* present, has a different layout). Gate every /proc-based lookup on this
* single feature macro so the BSD-family builds stay connections-only (as the
* README advertises) instead of aborting on a missing /proc. */
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#define NETHOGS_HAVE_PROC 1
#endif

/* take the average speed over the last 5 seconds */
#define PERIOD 5

Expand Down
2 changes: 1 addition & 1 deletion src/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ Process *getProcess(Connection *connection, const char *devicename,
// We take the fact for granted that we might already know the inode->pid
// (unlikely anyway if we
// haven't seen the connection->inode yet though).
#ifndef __APPLE__
#ifdef NETHOGS_HAVE_PROC
reread_mapping();
#endif
refreshconninode();
Expand Down