From 2c04ca926776a33d7a7471b98564e4f124fcec09 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Thu, 15 Mar 2012 20:53:25 +0000 Subject: [PATCH] Use negative return values on errors --- cui.cpp | 2 +- nethogs.cpp | 6 +++--- nethogs.h | 2 +- packet.cpp | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cui.cpp b/cui.cpp index d0224a8..5d9541b 100644 --- a/cui.cpp +++ b/cui.cpp @@ -430,7 +430,7 @@ void do_refresh() } else { - forceExit("Invalid viewmode"); + forceExit("Invalid viewmode", -1); } uid_t uid = curproc->getVal()->getUid(); #ifndef NDEBUG diff --git a/nethogs.cpp b/nethogs.cpp index a5bed8e..53ff9ce 100644 --- a/nethogs.cpp +++ b/nethogs.cpp @@ -222,7 +222,7 @@ void quit_cb (int /* i */) exit(0); } -void forceExit(const char *msg, ...) +void forceExit(const char *msg, int errcode, ...) { if ((!tracemode)&&(!DEBUG)){ exit_ui(); @@ -234,7 +234,7 @@ void forceExit(const char *msg, ...) va_end(argp); std::cerr << std::endl; - exit(0); + exit(errcode); } static void versiondisplay(void) @@ -331,7 +331,7 @@ int main (int argc, char** argv) } if (NEEDROOT && (getuid() != 0)) - forceExit("You need to be root to run NetHogs!"); + forceExit("You need to be root to run NetHogs!", -2); char errbuf[PCAP_ERRBUF_SIZE]; diff --git a/nethogs.h b/nethogs.h index a39bc16..a39d99f 100644 --- a/nethogs.h +++ b/nethogs.h @@ -63,7 +63,7 @@ #define PROGNAME_WIDTH 512 -void forceExit(const char *msg, ...); +void forceExit(const char *msg, int errcode, ...); class local_addr { public: diff --git a/packet.cpp b/packet.cpp index 35aa2d1..36e19e1 100644 --- a/packet.cpp +++ b/packet.cpp @@ -61,11 +61,11 @@ void getLocal (const char *device, bool tracemode) struct sockaddr_in *saddr; if((sock=socket(AF_INET, SOCK_RAW, htons(0x0806)))<0){ - forceExit("creating socket failed while establishing local IP - are you root?"); + forceExit("creating socket failed while establishing local IP - are you root?", -3); } strcpy(iFreq.ifr_name, device); if(ioctl(sock, SIOCGIFADDR, &iFreq)<0){ - forceExit("ioctl failed while establishing local IP for selected device %s. You may specify the device on the command line.", device); + forceExit("ioctl failed while establishing local IP for selected device %s. You may specify the device on the command line.", -4, device); } saddr=(struct sockaddr_in*)&iFreq.ifr_addr; local_addrs = new local_addr (saddr->sin_addr.s_addr, local_addrs);