From e6274c0aa691541ca7088a850464974df5ece65a Mon Sep 17 00:00:00 2001 From: David Rohr Date: Sat, 23 Jan 2021 12:31:36 +0100 Subject: [PATCH] Fix codechecker violations --- Detectors/ZDC/raw/src/DumpRaw.cxx | 2 +- Utilities/Tools/cpulimit/process_group.c | 20 +++++++--- .../Tools/cpulimit/process_iterator_linux.c | 39 +++++++++++++------ 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/Detectors/ZDC/raw/src/DumpRaw.cxx b/Detectors/ZDC/raw/src/DumpRaw.cxx index c139f74cdfaf8..cc5ec357f8208 100644 --- a/Detectors/ZDC/raw/src/DumpRaw.cxx +++ b/Detectors/ZDC/raw/src/DumpRaw.cxx @@ -142,7 +142,7 @@ inline int DumpRaw::getHPos(uint32_t board, uint32_t ch) int DumpRaw::processWord(const UInt_t* word) { - if (word == 0) { + if (word == nullptr) { printf("NULL\n"); return 1; } diff --git a/Utilities/Tools/cpulimit/process_group.c b/Utilities/Tools/cpulimit/process_group.c index 98b6b5ed54c25..c5343e32bd9a1 100644 --- a/Utilities/Tools/cpulimit/process_group.c +++ b/Utilities/Tools/cpulimit/process_group.c @@ -71,7 +71,9 @@ int find_process_by_name(const char *process_name) break; } } - if (close_process_iterator(&it) != 0) exit(1); + if (close_process_iterator(&it) != 0) { + exit(1); + } if (pid >= 0) { //ok, the process was found return pid; @@ -178,7 +180,9 @@ void update_process_group(struct process_group *pgroup) assert(tmp_process.pid == p->pid); assert(tmp_process.starttime == p->starttime); add_elem(pgroup->proclist, p); - if (dt < MIN_DT) continue; + if (dt < MIN_DT) { + continue; + } //process exists. update CPU usage double sample = 1.0 * (tmp_process.cputime - p->cputime) / dt; if (p->cpu_usage == -1) { @@ -194,16 +198,22 @@ void update_process_group(struct process_group *pgroup) } } close_process_iterator(&it); - if (dt < MIN_DT) return; + if (dt < MIN_DT) { + return; + } pgroup->last_update = now; } int remove_process(struct process_group *pgroup, int pid) { int hashkey = pid_hashfn(pid); - if (pgroup->proctable[hashkey] == NULL) return 1; //nothing to delete + if (pgroup->proctable[hashkey] == NULL) { + return 1; //nothing to delete + } struct list_node *node = (struct list_node*)locate_node(pgroup->proctable[hashkey], &pid); - if (node == NULL) return 2; + if (node == NULL) { + return 2; + } delete_node(pgroup->proctable[hashkey], node); return 0; } diff --git a/Utilities/Tools/cpulimit/process_iterator_linux.c b/Utilities/Tools/cpulimit/process_iterator_linux.c index c8cdd07adcbe9..d8d2cab3571da 100644 --- a/Utilities/Tools/cpulimit/process_iterator_linux.c +++ b/Utilities/Tools/cpulimit/process_iterator_linux.c @@ -44,10 +44,12 @@ static int get_boot_time() static int check_proc() { struct statfs mnt; - if (statfs("/proc", &mnt) < 0) + if (statfs("/proc", &mnt) < 0) { return 0; - if (mnt.f_type!=0x9fa0) + } + if (mnt.f_type!=0x9fa0) { return 0; + } return 1; } @@ -77,7 +79,9 @@ static int read_process_info(pid_t pid, struct process *p) //read stat file sprintf(statfile, "/proc/%d/stat", p->pid); FILE *fd = fopen(statfile, "r"); - if (fd==NULL) return -1; + if (fd==NULL) { + return -1; + } if (fgets(buffer, sizeof(buffer), fd)==NULL) { fclose(fd); return -1; @@ -85,15 +89,19 @@ static int read_process_info(pid_t pid, struct process *p) fclose(fd); char *token = strtok(buffer, " "); int i; - for (i=0; i<3; i++) token = strtok(NULL, " "); + for (i=0; i<3; i++) { + token = strtok(NULL, " "); + } p->ppid = atoi(token); - for (i=0; i<10; i++) + for (i=0; i<10; i++) { token = strtok(NULL, " "); + } p->cputime = atoi(token) * 1000 / HZ; token = strtok(NULL, " "); p->cputime += atoi(token) * 1000 / HZ; - for (i=0; i<7; i++) + for (i=0; i<7; i++) { token = strtok(NULL, " "); + } p->starttime = atoi(token) / sysconf(_SC_CLK_TCK); //read command line sprintf(exefile,"/proc/%d/cmdline", p->pid); @@ -113,7 +121,9 @@ static pid_t getppid_of(pid_t pid) char buffer[1024]; sprintf(statfile, "/proc/%d/stat", pid); FILE *fd = fopen(statfile, "r"); - if (fd==NULL) return -1; + if (fd==NULL) { + return -1; + } if (fgets(buffer, sizeof(buffer), fd)==NULL) { fclose(fd); return -1; @@ -121,7 +131,9 @@ static pid_t getppid_of(pid_t pid) fclose(fd); char *token = strtok(buffer, " "); int i; - for (i=0; i<3; i++) token = strtok(NULL, " "); + for (i=0; i<3; i++) { + token = strtok(NULL, " "); + } return atoi(token); } @@ -147,16 +159,21 @@ int get_next_process(struct process_iterator *it, struct process *p) //p->starttime += it->boot_time; closedir(it->dip); it->dip = NULL; - if (ret != 0) return -1; + if (ret != 0) { + return -1; + } return 0; } struct dirent *dit = NULL; //read in from /proc and seek for process dirs while ((dit = readdir(it->dip)) != NULL) { - if(strtok(dit->d_name, "0123456789") != NULL) + if(strtok(dit->d_name, "0123456789") != NULL) { continue; + } p->pid = atoi(dit->d_name); - if (it->filter->pid != 0 && it->filter->pid != p->pid && !is_child_of(p->pid, it->filter->pid)) continue; + if (it->filter->pid != 0 && it->filter->pid != p->pid && !is_child_of(p->pid, it->filter->pid)) { + continue; + } read_process_info(p->pid, p); //p->starttime += it->boot_time; break;