generic: indent and format

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-02-04 01:01:16 +02:00
parent 052e4456b1
commit a433444a79
4 changed files with 462 additions and 481 deletions

View file

@ -213,8 +213,7 @@ updateProcess(struct kinfo_proc *p)
struct passwd* pwent; struct passwd* pwent;
pid_t pid = p->p_pid; pid_t pid = p->p_pid;
if ((ps = findProcessInList(pid)) == 0) if ((ps = findProcessInList(pid)) == 0) {
{
ps = (ProcessInfo*) malloc(sizeof(ProcessInfo)); ps = (ProcessInfo*) malloc(sizeof(ProcessInfo));
ps->pid = pid; ps->pid = pid;
ps->centStamp = 0; ps->centStamp = 0;
@ -264,18 +263,14 @@ cleanupProcessList(void)
ProcessCount = 0; ProcessCount = 0;
/* All processes that do not have the active flag set are assumed dead /* All processes that do not have the active flag set are assumed dead
* and will be removed from the list. The alive flag is cleared. */ * and will be removed from the list. The alive flag is cleared. */
for (ps = first_ctnr(ProcessList); ps; ps = next_ctnr(ProcessList)) for (ps = first_ctnr(ProcessList); ps; ps = next_ctnr(ProcessList)) {
{ if (ps->alive) {
if (ps->alive)
{
/* Process is still alive. Just clear flag. */ /* Process is still alive. Just clear flag. */
ps->alive = 0; ps->alive = 0;
ProcessCount++; ProcessCount++;
} } else {
else
{
/* Process has probably died. We remove it from the list and /* Process has probably died. We remove it from the list and
* destruct the data structure. */ destruct the data structure. */
free(remove_ctnr(ProcessList)); free(remove_ctnr(ProcessList));
} }
} }
@ -293,8 +288,7 @@ initProcessList(struct SensorModul* sm)
registerMonitor("ps", "table", printProcessList, printProcessListInfo, sm); registerMonitor("ps", "table", printProcessList, printProcessListInfo, sm);
registerMonitor("pscount", "integer", printProcessCount, printProcessCountInfo, sm); registerMonitor("pscount", "integer", printProcessCount, printProcessCountInfo, sm);
if (!RunAsDaemon) if (!RunAsDaemon) {
{
registerCommand("kill", killProcess); registerCommand("kill", killProcess);
registerCommand("setpriority", setPriority); registerCommand("setpriority", setPriority);
} }
@ -357,8 +351,7 @@ printProcessList(const char* cmd)
{ {
ProcessInfo* ps; ProcessInfo* ps;
for (ps = first_ctnr(ProcessList); ps; ps = next_ctnr(ProcessList)) for (ps = first_ctnr(ProcessList); ps; ps = next_ctnr(ProcessList)) {
{
fprintf(CurrentClient, "%s\t%ld\t%ld\t%ld\t%ld\t%s\t%.2f\t%.2f\t%d\t%d\t%d\t%s\t%s\n", fprintf(CurrentClient, "%s\t%ld\t%ld\t%ld\t%ld\t%s\t%.2f\t%.2f\t%d\t%d\t%d\t%s\t%s\n",
ps->name, (long)ps->pid, (long)ps->ppid, ps->name, (long)ps->pid, (long)ps->ppid,
(long)ps->uid, (long)ps->gid, ps->status, (long)ps->uid, (long)ps->gid, ps->status,
@ -385,8 +378,7 @@ killProcess(const char* cmd)
int sig, pid; int sig, pid;
sscanf(cmd, "%*s %d %d", &pid, &sig); sscanf(cmd, "%*s %d %d", &pid, &sig);
switch(sig) switch(sig) {
{
case MENU_ID_SIGABRT: case MENU_ID_SIGABRT:
sig = SIGABRT; sig = SIGABRT;
break; break;
@ -445,10 +437,8 @@ killProcess(const char* cmd)
sig = SIGUSR2; sig = SIGUSR2;
break; break;
} }
if (kill((pid_t) pid, sig)) if (kill((pid_t) pid, sig)) {
{ switch(errno) {
switch(errno)
{
case EINVAL: case EINVAL:
fprintf(CurrentClient, "4\t%d\n", pid); fprintf(CurrentClient, "4\t%d\n", pid);
break; break;
@ -462,11 +452,10 @@ killProcess(const char* cmd)
fprintf(CurrentClient, "1\t%d\n", pid); /* unknown error */ fprintf(CurrentClient, "1\t%d\n", pid); /* unknown error */
break; break;
} }
} else {
}
else
fprintf(CurrentClient, "0\t%d\n", pid); fprintf(CurrentClient, "0\t%d\n", pid);
} }
}
void void
setPriority(const char* cmd) setPriority(const char* cmd)
@ -474,10 +463,8 @@ setPriority(const char* cmd)
int pid, prio; int pid, prio;
sscanf(cmd, "%*s %d %d", &pid, &prio); sscanf(cmd, "%*s %d %d", &pid, &prio);
if (setpriority(PRIO_PROCESS, pid, prio)) if (setpriority(PRIO_PROCESS, pid, prio)) {
{ switch(errno) {
switch(errno)
{
case EINVAL: case EINVAL:
fprintf(CurrentClient, "4\n"); fprintf(CurrentClient, "4\n");
break; break;
@ -492,7 +479,7 @@ setPriority(const char* cmd)
fprintf(CurrentClient, "1\n"); /* unknown error */ fprintf(CurrentClient, "1\n"); /* unknown error */
break; break;
} }
} } else {
else
fprintf(CurrentClient, "0\n"); fprintf(CurrentClient, "0\n");
} }
}

View file

@ -187,21 +187,17 @@ long *diffs;
dp = diffs; dp = diffs;
/* calculate changes for each state and the overall change */ /* calculate changes for each state and the overall change */
for (i = 0; i < cnt; i++) for (i = 0; i < cnt; i++) {
{ if ((change = *new - *old) < 0) {
if ((change = *new - *old) < 0)
{
/* this only happens when the counter wraps */ /* this only happens when the counter wraps */
change = (int) change = (int)((unsigned long)*new-(unsigned long)*old);
((unsigned long)*new-(unsigned long)*old);
} }
total_change += (*dp++ = change); total_change += (*dp++ = change);
*old++ = *new++; *old++ = *new++;
} }
/* avoid divide by zero potential */ /* avoid divide by zero potential */
if (total_change == 0) if (total_change == 0) {
{
total_change = 1; total_change = 1;
} }
@ -210,8 +206,7 @@ long *diffs;
/* Do not divide by 0. Causes Floating point exception */ /* Do not divide by 0. Causes Floating point exception */
if(total_change) { if(total_change) {
for (i = 0; i < cnt; i++) for (i = 0; i < cnt; i++) {
{
*out++ = (int)((*diffs++ * 1000 + half_total) / total_change); *out++ = (int)((*diffs++ * 1000 + half_total) / total_change);
} }
} }

View file

@ -149,8 +149,7 @@ ProcessesLocal::ProcessesLocal() : d(new Private())
long ProcessesLocal::getParentPid(long pid) { long ProcessesLocal::getParentPid(long pid) {
long long ppid = 0; long long ppid = 0;
struct kinfo_proc p; struct kinfo_proc p;
if(d->readProc(pid, &p)) if(d->readProc(pid, &p)) {
{
ppid = p.ki_ppid; ppid = p.ki_ppid;
} }
return ppid; return ppid;