Skip to content

Commit 79b3023

Browse files
committed
Apply easy pick linter fixes
1 parent acdda04 commit 79b3023

File tree

5 files changed

+132
-132
lines changed

5 files changed

+132
-132
lines changed

check_interfaces.c

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
// This one is needed on FreeBSD and it has to be before the others or at least some of them
42
#include <getopt.h>
53

@@ -95,22 +93,24 @@ typedef enum returncode returncode_t;
9593

9694
// Forward declarations
9795
void parse_and_check_commandline(int argc, char **argv, struct configuration_struct *config);
98-
bool fetch_interface_aliases(struct configuration_struct *, char **, netsnmp_session *ss, netsnmp_session *session,
99-
struct ifStruct *interfaces, int ifNumber);
100-
bool fetch_interface_names(struct configuration_struct *, char **oid_namesp, netsnmp_session *ss, netsnmp_session *session,
101-
struct ifStruct *interfaces, int ifNumber);
96+
bool fetch_interface_aliases(struct configuration_struct * /*config*/, char ** /*oid_aliasp*/, netsnmp_session *snmp_session,
97+
netsnmp_session *session, struct ifStruct *interfaces, int ifNumber);
98+
bool fetch_interface_names(struct configuration_struct * /*config*/, char **oid_namesp, netsnmp_session *snmp_session,
99+
netsnmp_session *session, struct ifStruct *interfaces, int ifNumber);
102100
returncode_t print_output(struct configuration_struct *config, struct ifStruct *oldperfdata, long double starttime,
103101
struct ifStruct *interfaces, String *out, char **if_vars, unsigned int number_of_matched_interfaces,
104-
struct timeval *tv, int uptime, int ifNumber);
102+
struct timeval *time_value, int uptime, int ifNumber);
105103
void print_version(void);
106104

107105
int main(int argc, char *argv[]) {
108-
netsnmp_session session, *ss;
106+
netsnmp_session session;
107+
netsnmp_session *snmp_session;
109108
netsnmp_pdu *pdu;
110109
netsnmp_pdu *response;
111110

112111
netsnmp_variable_list *vars;
113-
int status, status2;
112+
int status;
113+
int status2;
114114
int count = 0; /* used for: the number of interfaces we receive, the number
115115
of regex matches */
116116
size_t size;
@@ -179,10 +179,10 @@ int main(int argc, char *argv[]) {
179179

180180
parse_and_check_commandline(argc, argv, &config);
181181

182-
struct timeval tv;
183-
struct timezone tz;
184-
gettimeofday(&tv, &tz);
185-
starttime = (long double)tv.tv_sec + (((long double)tv.tv_usec) / 1000000);
182+
struct timeval time_value;
183+
struct timezone time_zone;
184+
gettimeofday(&time_value, &time_zone);
185+
starttime = (long double)time_value.tv_sec + (((long double)time_value.tv_usec) / 1000000);
186186

187187
// +1 for the `:` between hostname and port
188188
size_t peername_max_len = strlen(config.hostname) + strlen(config.port) + 1;
@@ -201,10 +201,10 @@ int main(int argc, char *argv[]) {
201201
#endif
202202
if (config.user) {
203203
/* use snmpv3 */
204-
ss = start_session_v3(&session, config.user, config.auth_proto, config.auth_pass, config.priv_proto, config.priv_pass, peername,
205-
config.global_timeout, config.session_retries);
204+
snmp_session = start_session_v3(&session, config.user, config.auth_proto, config.auth_pass, config.priv_proto, config.priv_pass,
205+
peername, config.global_timeout, config.session_retries);
206206
} else {
207-
ss = start_session(&session, config.community, peername, config.mode, config.global_timeout, config.session_retries);
207+
snmp_session = start_session(&session, config.community, peername, config.mode, config.global_timeout, config.session_retries);
208208
}
209209
#ifdef DEBUG
210210
benchmark_end();
@@ -267,7 +267,7 @@ int main(int argc, char *argv[]) {
267267
benchmark_start("Send SNMP request for OIDs: %s", implode_result);
268268
#endif
269269
/* send the request */
270-
status = snmp_synch_response(ss, pdu, &response);
270+
status = snmp_synch_response(snmp_session, pdu, &response);
271271
#ifdef DEBUG
272272
benchmark_end();
273273
free(implode_result);
@@ -403,11 +403,11 @@ int main(int argc, char *argv[]) {
403403
} else if (status == STAT_TIMEOUT) {
404404
printf("Timeout while reading interface descriptions from %s\n", session.peername);
405405
exit(EXITCODE_TIMEOUT);
406-
} else if (status == STAT_ERROR && ss->s_snmp_errno == SNMPERR_TIMEOUT) {
406+
} else if (status == STAT_ERROR && snmp_session->s_snmp_errno == SNMPERR_TIMEOUT) {
407407
printf("Timeout\n");
408408
exit(EXITCODE_TIMEOUT);
409409
} else {
410-
snmp_sess_perror("snmp_bulkget", ss);
410+
snmp_sess_perror("snmp_bulkget", snmp_session);
411411
}
412412
exit(2);
413413
}
@@ -434,7 +434,7 @@ int main(int argc, char *argv[]) {
434434
*/
435435

436436
if (config.match_aliases_flag && config.iface_regex) {
437-
fetch_interface_aliases(&config, oid_aliasp, ss, &session, interfaces, ifNumber);
437+
fetch_interface_aliases(&config, oid_aliasp, snmp_session, &session, interfaces, ifNumber);
438438
}
439439

440440
/* If the get_names_flag is set, we also have to get the interface names so
@@ -445,7 +445,7 @@ int main(int argc, char *argv[]) {
445445
* way
446446
* :-) */
447447
if (config.get_names_flag && config.iface_regex) {
448-
fetch_interface_names(&config, oid_namesp, ss, &session, interfaces, ifNumber);
448+
fetch_interface_names(&config, oid_namesp, snmp_session, &session, interfaces, ifNumber);
449449
}
450450

451451
if (config.iface_regex) {
@@ -513,7 +513,7 @@ int main(int argc, char *argv[]) {
513513
if (!interfaces[j].ignore) {
514514

515515
/* fetch the standard values first */
516-
if (create_request(ss, &OIDp, oid_vals, interfaces[j].index, &response, config.sleep_usecs)) {
516+
if (create_request(snmp_session, &OIDp, oid_vals, interfaces[j].index, &response, config.sleep_usecs)) {
517517
for (vars = response->variables; vars; vars = vars->next_variable) {
518518
k = -1;
519519
/* compare the received value to the requested value */
@@ -582,7 +582,7 @@ int main(int argc, char *argv[]) {
582582
}
583583

584584
/* now fetch the extended oids (64 bit counters etc.) */
585-
if (create_request(ss, &OIDp, oid_extended, interfaces[j].index, &response, config.sleep_usecs)) {
585+
if (create_request(snmp_session, &OIDp, oid_extended, interfaces[j].index, &response, config.sleep_usecs)) {
586586
for (vars = response->variables; vars; vars = vars->next_variable) {
587587
k = -1;
588588
/* compare the received value to the requested value */
@@ -646,7 +646,8 @@ int main(int argc, char *argv[]) {
646646
}
647647

648648
/* now fetch the Cisco-specific extended oids */
649-
if (config.mode == CISCO && create_request(ss, &OIDp, oid_extended_cisco, interfaces[j].index, &response, config.sleep_usecs)) {
649+
if (config.mode == CISCO &&
650+
create_request(snmp_session, &OIDp, oid_extended_cisco, interfaces[j].index, &response, config.sleep_usecs)) {
650651
for (vars = response->variables; vars; vars = vars->next_variable) {
651652
k = -1;
652653
/* compare the received value to the requested value */
@@ -661,7 +662,7 @@ int main(int argc, char *argv[]) {
661662
{
662663
case 0: /* portAdditionalOperStatus */
663664
if (vars->type == ASN_OCTET_STR) {
664-
interfaces[j].err_disable = !!(vars->val.string[1] & (unsigned char)32u);
665+
interfaces[j].err_disable = !!(vars->val.string[1] & (unsigned char)32U);
665666
}
666667
break;
667668
}
@@ -688,14 +689,14 @@ int main(int argc, char *argv[]) {
688689

689690
/* calculate time taken, print perfdata */
690691

691-
gettimeofday(&tv, &tz);
692+
gettimeofday(&time_value, &time_zone);
692693

693-
returncode_t exit_code = print_output(&config, oldperfdata, starttime, interfaces, &out, if_vars, count, &tv, uptime, ifNumber);
694+
returncode_t exit_code = print_output(&config, oldperfdata, starttime, interfaces, &out, if_vars, count, &time_value, uptime, ifNumber);
694695

695696
#ifdef DEBUG
696697
benchmark_start("Close SNMP session");
697698
#endif
698-
snmp_close(ss);
699+
snmp_close(snmp_session);
699700
snmp_close(&session);
700701
#ifdef DEBUG
701702
benchmark_end();
@@ -707,7 +708,7 @@ int main(int argc, char *argv[]) {
707708

708709
returncode_t print_output(struct configuration_struct *config, struct ifStruct *oldperfdata, long double starttime,
709710
struct ifStruct *interfaces, String *out, char **if_vars, unsigned int number_of_matched_interfaces,
710-
struct timeval *tv, int uptime, int ifNumber) {
711+
struct timeval *time_value, int uptime, int ifNumber) {
711712

712713
unsigned int parsed_lastcheck = 0;
713714

@@ -741,7 +742,8 @@ returncode_t print_output(struct configuration_struct *config, struct ifStruct *
741742
bool warnflag = false;
742743

743744
for (int i = 0; i < ifNumber; i++) {
744-
double inload = 0, outload = 0;
745+
double inload = 0;
746+
double outload = 0;
745747
if (!interfaces[i].ignore) {
746748
int warn = 0;
747749

@@ -878,15 +880,16 @@ returncode_t print_output(struct configuration_struct *config, struct ifStruct *
878880

879881
if (config->lastcheck && (interfaces[i].speed || config->speed) &&
880882
(interfaces[i].inbitps > 0ULL || interfaces[i].outbitps > 0ULL) && !interfaces[i].admin_down) {
881-
char *ins, *outs;
883+
char *ins;
884+
char *outs;
882885
gauge_to_si(interfaces[i].inbitps, &ins);
883886
gauge_to_si(interfaces[i].outbitps, &outs);
884887

885888
addstr(&perf, " %sbps(%0.2f%%)/%sbps(%0.2f%%)", ins, inload, outs, outload);
886889
free(ins);
887890
free(outs);
888891
}
889-
if (perf.len > 0u && perf.text[(perf.len - 1u)] != '\n') {
892+
if (perf.len > 0U && perf.text[(perf.len - 1U)] != '\n') {
890893
addstr(&perf, "\n");
891894
}
892895
}
@@ -908,7 +911,7 @@ returncode_t print_output(struct configuration_struct *config, struct ifStruct *
908911
/* now print performance data */
909912

910913
printf("%*s | interfaces::check_multi::plugins=%d time=%.2Lf checktime=%ld", (int)out->len, out->text, number_of_matched_interfaces,
911-
(((long double)tv->tv_sec + ((long double)tv->tv_usec / 1000000)) - starttime), tv->tv_sec);
914+
(((long double)time_value->tv_sec + ((long double)time_value->tv_usec / 1000000)) - starttime), time_value->tv_sec);
912915
if (uptime) {
913916
printf(" %sdevice::check_snmp::uptime=%us", config->prefix ? config->prefix : "", uptime);
914917
}
@@ -932,15 +935,15 @@ returncode_t print_output(struct configuration_struct *config, struct ifStruct *
932935

933936
if (errorflag) {
934937
return CRITICAL;
935-
} else if (warnflag) {
938+
}
939+
if (warnflag) {
936940
return WARNING;
937-
} else {
938-
return OK;
939941
}
942+
return OK;
940943
}
941944

942-
bool fetch_interface_aliases(struct configuration_struct *config, char **oid_aliasp, netsnmp_session *ss, netsnmp_session *session,
943-
struct ifStruct *interfaces, int ifNumber) {
945+
bool fetch_interface_aliases(struct configuration_struct *config, char **oid_aliasp, netsnmp_session *snmp_session,
946+
netsnmp_session *session, struct ifStruct *interfaces, int ifNumber) {
944947
bool lastifflag = false;
945948
int count = 0;
946949
netsnmp_pdu *pdu;
@@ -974,7 +977,7 @@ bool fetch_interface_aliases(struct configuration_struct *config, char **oid_ali
974977
#endif
975978
/* send the request */
976979
int status;
977-
status = snmp_synch_response(ss, pdu, &response);
980+
status = snmp_synch_response(snmp_session, pdu, &response);
978981
#ifdef DEBUG
979982
benchmark_end();
980983
free(implode_result);
@@ -1047,7 +1050,7 @@ bool fetch_interface_aliases(struct configuration_struct *config, char **oid_ali
10471050
printf("Timeout while reading interface aliases from %s\n", (*session).peername);
10481051
exit(EXITCODE_TIMEOUT);
10491052
} else {
1050-
snmp_sess_perror("snmp_bulkget", ss);
1053+
snmp_sess_perror("snmp_bulkget", snmp_session);
10511054
}
10521055
exit(2);
10531056
}
@@ -1063,7 +1066,7 @@ bool fetch_interface_aliases(struct configuration_struct *config, char **oid_ali
10631066
return true;
10641067
}
10651068

1066-
bool fetch_interface_names(struct configuration_struct *config, char **oid_namesp, netsnmp_session *ss, netsnmp_session *session,
1069+
bool fetch_interface_names(struct configuration_struct *config, char **oid_namesp, netsnmp_session *snmp_session, netsnmp_session *session,
10671070
struct ifStruct *interfaces, int ifNumber) {
10681071
bool lastifflag = false;
10691072
netsnmp_pdu *pdu;
@@ -1099,7 +1102,7 @@ bool fetch_interface_names(struct configuration_struct *config, char **oid_names
10991102
benchmark_start("Send SNMP request for OIDs: %s", implode_result);
11001103
#endif
11011104
/* send the request */
1102-
int status = snmp_synch_response(ss, pdu, &response);
1105+
int status = snmp_synch_response(snmp_session, pdu, &response);
11031106
#ifdef DEBUG
11041107
benchmark_end();
11051108
free(implode_result);
@@ -1166,7 +1169,7 @@ bool fetch_interface_names(struct configuration_struct *config, char **oid_names
11661169
printf("Timeout while reading interface names from %s\n", (*session).peername);
11671170
exit(EXITCODE_TIMEOUT);
11681171
} else {
1169-
snmp_sess_perror("snmp_bulkget", ss);
1172+
snmp_sess_perror("snmp_bulkget", snmp_session);
11701173
}
11711174
exit(2);
11721175
}
@@ -1400,7 +1403,6 @@ void print_version(void) {
14001403
}
14011404

14021405
int usage(char *progname) {
1403-
int i;
14041406
printf(
14051407
#ifdef PACKAGE_STRING
14061408
PACKAGE_STRING "\n\n"
@@ -1424,7 +1426,7 @@ int usage(char *progname) {
14241426
printf(" -x|--trim\t\tcut this number of characters from the start of "
14251427
"interface descriptions\n");
14261428
printf(" -m|--mode\t\tspecial operating mode (");
1427-
for (i = 0; modes[i]; i++) {
1429+
for (int i = 0; modes[i]; i++) {
14281430
printf("%s%s", i ? "," : "", modes[i]);
14291431
}
14301432
printf(")\n");

0 commit comments

Comments
 (0)