Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix codechecker violations #5271

Merged
merged 1 commit into from Jan 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Detectors/ZDC/raw/src/DumpRaw.cxx
Expand Up @@ -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;
}
Expand Down
20 changes: 15 additions & 5 deletions Utilities/Tools/cpulimit/process_group.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
39 changes: 28 additions & 11 deletions Utilities/Tools/cpulimit/process_iterator_linux.c
Expand Up @@ -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;
}

Expand Down Expand Up @@ -77,23 +79,29 @@ 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;
}
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);
Expand All @@ -113,15 +121,19 @@ 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;
}
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);
}

Expand All @@ -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;
Expand Down