From d8fddb81be1b4dd48b8022417901d8f9aafb246c Mon Sep 17 00:00:00 2001 From: Herman Semenoff Date: Wed, 1 Jul 2026 21:22:54 +0300 Subject: [PATCH] netatop: use const ptr struct for micro-op and readability --- atop.h | 2 +- netatopbpfif.c | 8 ++++---- netatopif.c | 8 ++++---- photoproc.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/atop.h b/atop.h index 1bf0ec68..c836af3a 100644 --- a/atop.h +++ b/atop.h @@ -238,7 +238,7 @@ void netatop_gettask(pid_t, char, struct tstat *); unsigned int netatop_exitstore(void); void netatop_exiterase(void); void netatop_exithash(char); -void netatop_exitfind(unsigned long, struct tstat *, struct tstat *); +void netatop_exitfind(unsigned long, struct tstat *, const struct tstat *); void netatop_bpf_ipopen(void); void netatop_bpf_probe(void); diff --git a/netatopbpfif.c b/netatopbpfif.c index 7827bf47..1037fa3c 100644 --- a/netatopbpfif.c +++ b/netatopbpfif.c @@ -49,8 +49,8 @@ static int netsock = -1; -static void fill_networkcnt(struct tstat *, struct tstat *, - struct taskcount *); +static void fill_networkcnt(struct tstat *, const struct tstat *, + const struct taskcount *); void my_handler(int); int len; @@ -154,7 +154,7 @@ netatop_bpf_gettask() void netatop_bpf_exitfind(unsigned long key, struct tstat *dev, struct tstat *pre) { - struct taskcount *tc = g_hash_table_lookup(ghash_net, &key); + const struct taskcount *tc = g_hash_table_lookup(ghash_net, &key); /* ** correct PID found */ @@ -173,7 +173,7 @@ netatop_bpf_exitfind(unsigned long key, struct tstat *dev, struct tstat *pre) } static void -fill_networkcnt(struct tstat *dev, struct tstat *pre, struct taskcount *tc) +fill_networkcnt(struct tstat *dev, const struct tstat *pre, const struct taskcount *tc) { dev->net.tcpsnd = tc->tcpsndpacks - pre->net.tcpsnd; dev->net.tcpssz = tc->tcpsndbytes - pre->net.tcpssz; diff --git a/netatopif.c b/netatopif.c index d0e9c29d..5f4da516 100644 --- a/netatopif.c +++ b/netatopif.c @@ -76,8 +76,8 @@ static struct exitstore *exitall; static int exitnum; static char exithash; -static void fill_networkcnt(struct tstat *, struct tstat *, - struct exitstore *); +static void fill_networkcnt(struct tstat *, const struct tstat *, + const struct exitstore *); /* ** open a raw socket to the IP layer (root privs required) @@ -464,7 +464,7 @@ netatop_exithash(char hashtype) ** update counters in tstat struct */ void -netatop_exitfind(unsigned long key, struct tstat *dev, struct tstat *pre) +netatop_exitfind(unsigned long key, struct tstat *dev, const struct tstat *pre) { int h = HASHCALC(key); struct exitstore *esp; @@ -524,7 +524,7 @@ netatop_exitfind(unsigned long key, struct tstat *dev, struct tstat *pre) } static void -fill_networkcnt(struct tstat *dev, struct tstat *pre, struct exitstore *esp) +fill_networkcnt(struct tstat *dev, const struct tstat *pre, const struct exitstore *esp) { dev->net.tcpsnd = esp->npt.tc.tcpsndpacks - pre->net.tcpsnd; dev->net.tcpssz = esp->npt.tc.tcpsndbytes - pre->net.tcpssz; diff --git a/photoproc.c b/photoproc.c index 78be340f..8a4e587e 100644 --- a/photoproc.c +++ b/photoproc.c @@ -219,7 +219,7 @@ photoproc(struct tstat *tasklist, int maxtask) procwchan(curtask); if (supportflags & NETATOPBPF) { - struct taskcount *tc = g_hash_table_lookup(ghash_net, &(curtask->gen.tgid)); + const struct taskcount *tc = g_hash_table_lookup(ghash_net, &(curtask->gen.tgid)); if (tc) { // printf("%d %d %d %d %d\n",curtask->gen.tgid, tc->tcpsndpacks, tc->tcprcvpacks, tc->udpsndpacks, tc->udprcvpacks); curtask->net.tcpsnd = tc->tcpsndpacks;