tc: replace print_string with fprintf for error messages
Subsystems (2)
PATCH 1/2 tc: replace print_string with fprintf for error messages
Any error output should go to standard error.
Signed-off-by Stephen Hemminger <[email protected]>
--- tc/f_matchall.c | 2 +- tc/m_connmark.c | 2 +- tc/m_csum.c | 2 +- tc/m_gact.c | 2 +- tc/m_ife.c | 2 +- tc/m_mirred.c | 2 +- tc/m_nat.c | 2 +- tc/m_sample.c | 2 +- tc/m_skbedit.c | 2 +- tc/m_vlan.c | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-)
tc/f_matchall.c +1 -1
@@ -146,7 +146,7 @@ static int matchall_print_opt(struct filter_util *qu, FILE *f,if (tb[TCA_MATCHALL_PCNT ]) {if (RTA_PAYLOAD (tb[TCA_MATCHALL_PCNT ]) <sizeof (*pf)) { -print_string (PRINT_FP ,NULL ,"Broken perf counters\n" ,NULL ); +fprintf (stderr,"Performance counter size mismatch\n" );return -1 ; } pf =RTA_DATA (tb[TCA_MATCHALL_PCNT ]);
tc/m_connmark.c +1 -1
@@ -114,7 +114,7 @@ static int print_connmark(struct action_util *au, FILE *f, struct rtattr *arg)parse_rtattr_nested (tb,TCA_CONNMARK_MAX , arg);if (tb[TCA_CONNMARK_PARMS ] ==NULL ) { -print_string (PRINT_FP ,NULL ,"%s" ,"[NULL connmark parameters]" ); +fprintf (stderr,"NULL connmark parameters\n" );return -1 ; }
tc/m_csum.c +1 -1
@@ -172,7 +172,7 @@ print_csum(struct action_util *au, FILE *f, struct rtattr *arg)parse_rtattr_nested (tb,TCA_CSUM_MAX , arg);if (tb[TCA_CSUM_PARMS ] ==NULL ) { -fprintf (f,"[NULL csum parameters]" ); +fprintf (stderr,"missing csum parameters\n" );return -1 ; } sel =RTA_DATA (tb[TCA_CSUM_PARMS ]);
tc/m_gact.c +1 -1
@@ -174,7 +174,7 @@ print_gact(struct action_util *au, FILE *f, struct rtattr *arg)parse_rtattr_nested (tb,TCA_GACT_MAX , arg);if (tb[TCA_GACT_PARMS ] ==NULL ) { -print_string (PRINT_FP ,NULL ,"%s" ,"[NULL gact parameters]" ); +fprintf (stderr,"[NULL gact parameters]\n" );return -1 ; } p =RTA_DATA (tb[TCA_GACT_PARMS ]);
tc/m_ife.c +1 -1
@@ -234,7 +234,7 @@ static int print_ife(struct action_util *au, FILE *f, struct rtattr *arg)parse_rtattr_nested (tb,TCA_IFE_MAX , arg);if (tb[TCA_IFE_PARMS ] ==NULL ) { -print_string (PRINT_FP ,NULL ,"%s" ,"[NULL ife parameters]" ); +fprintf (stderr,"[NULL ife parameters]\n" );return -1 ; } p =RTA_DATA (tb[TCA_IFE_PARMS ]);
tc/m_mirred.c +1 -1
@@ -286,7 +286,7 @@ print_mirred(struct action_util *au, FILE *f, struct rtattr *arg)parse_rtattr_nested (tb,TCA_MIRRED_MAX , arg);if (tb[TCA_MIRRED_PARMS ] ==NULL ) { -print_string (PRINT_FP ,NULL ,"%s" ,"[NULL mirred parameters]" ); +fprintf (stderr,"mirred parameters missing\n" );return -1 ; } p =RTA_DATA (tb[TCA_MIRRED_PARMS ]);
tc/m_nat.c +1 -1
@@ -152,7 +152,7 @@ print_nat(struct action_util *au, FILE * f, struct rtattr *arg)parse_rtattr_nested (tb,TCA_NAT_MAX , arg);if (tb[TCA_NAT_PARMS ] ==NULL ) { -print_string (PRINT_FP ,NULL ,"%s" ,"[NULL nat parameters]" ); +fprintf (stderr,"[NULL nat parameters]\n" );return -1 ; } sel =RTA_DATA (tb[TCA_NAT_PARMS ]);
tc/m_sample.c +1 -1
@@ -149,7 +149,7 @@ static int print_sample(struct action_util *au, FILE *f, struct rtattr *arg)if (!tb[TCA_SAMPLE_PARMS ] || !tb[TCA_SAMPLE_RATE ] || !tb[TCA_SAMPLE_PSAMPLE_GROUP ]) { -print_string (PRINT_FP ,NULL ,"%s" ,"[NULL sample parameters]" ); +fprintf (stderr,"[NULL sample parameters]\n" );return -1 ; } p =RTA_DATA (tb[TCA_SAMPLE_PARMS ]);
tc/m_skbedit.c +1 -1
@@ -186,7 +186,7 @@ static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg)parse_rtattr_nested (tb,TCA_SKBEDIT_MAX , arg);if (tb[TCA_SKBEDIT_PARMS ] ==NULL ) { -print_string (PRINT_FP ,NULL ,"%s" ,"[NULL skbedit parameters]" ); +fprintf (stderr,"[NULL skbedit parameters]\n" );return -1 ; } p =RTA_DATA (tb[TCA_SKBEDIT_PARMS ]);
tc/m_vlan.c +1 -1
@@ -188,7 +188,7 @@ static int print_vlan(struct action_util *au, FILE *f, struct rtattr *arg)parse_rtattr_nested (tb,TCA_VLAN_MAX , arg);if (!tb[TCA_VLAN_PARMS ]) { -print_string (PRINT_FP ,NULL ,"%s" ,"[NULL vlan parameters]" ); +fprintf (stderr,"[NULL vlan parameters]\n" );return -1 ; } parm =RTA_DATA (tb[TCA_VLAN_PARMS ]);
Signature · 1 line
2.17.1
PATCH 2/2 tc: replace left side comparison
The kernel (and iproute2) don't use the if (NULL == x) style and instead prefer if (!x)
Signed-off-by Stephen Hemminger <[email protected]>
--- tc/m_action.c | 2 +- tc/m_ipt.c | 3 +-- tc/m_xt_old.c | 3 +-- tc/tc_util.c | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-)
tc/m_action.c +1 -1
@@ -363,7 +363,7 @@ tc_print_action(FILE *f, const struct rtattr *arg, unsigned short tot_acts)parse_rtattr_nested (tb, tot_acts, arg); -if (tab_flush &&NULL != tb[0 ] &&NULL == tb[1 ]) +if (tab_flush && tb[0 ] && !tb[1 ])return tc_print_action_flush (f, tb[0 ]);open_json_array (PRINT_JSON ,"actions" );
tc/m_ipt.c +1 -2
@@ -299,9 +299,8 @@ static int parse_ipt(struct action_util *a, int *argc_p,int i;for (i =0 ; i < rargc; i++) { -if (NULL == argv[i] ||0 ==strcmp (argv[i],"action" )) { +if (!argv[i] ||strcmp (argv[i],"action" ) ==0 )break ; - } } iargc = argc = i; }
tc/m_xt_old.c +1 -2
@@ -224,9 +224,8 @@ static int parse_ipt(struct action_util *a, int *argc_p,int i;for (i =0 ; i < rargc; i++) { -if (NULL == argv[i] ||0 ==strcmp (argv[i],"action" )) { +if (!argv[i] ||strcmp (argv[i],"action" ) ==0 )break ; - } } iargc = argc = i; }
tc/tc_util.c +1 -1
@@ -857,7 +857,7 @@ void print_tcstats_attr(FILE *fp, struct rtattr *tb[], char *prefix, struct rtatif (tb[TCA_STATS2 ]) {print_tcstats2_attr (fp, tb[TCA_STATS2 ], prefix, xstats); -if (xstats &&NULL == *xstats) +if (xstats && !*xstats) goto compat_xstats;return ; }
Signature · 1 line
2.17.1
David Ahern
AppliedRe: [PATCH iproute2-next 2/2] tc: replace left side comparison
Quoted 11 lines · Stephen Hemminger
The kernel (and iproute2) don't use the if (NULL == x) style and instead prefer if (!x)
Signed-off-by Stephen Hemminger <[email protected]>--- tc/m_action.c | 2 +- tc/m_ipt.c | 3 +-- tc/m_xt_old.c | 3 +-- tc/tc_util.c | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-)
applied to iproute2-next. Thanks
Quoted 31 lines · Stephen Hemminger
tc/m_connmark.c +1
-1@@ -114,7 +114,7 @@ static int print_connmark(struct action_util *au, FILE *f, struct rtattr *arg)parse_rtattr_nested (tb,TCA_CONNMARK_MAX , arg);if (tb[TCA_CONNMARK_PARMS ] ==NULL ) { -print_string (PRINT_FP ,NULL ,"%s" ,"[NULL connmark parameters]" ); +fprintf (stderr,"NULL connmark parameters\n" );return -1 ; }tc/m_csum.c +1
-1@@ -172,7 +172,7 @@ print_csum(struct action_util *au, FILE *f, struct rtattr *arg)parse_rtattr_nested (tb,TCA_CSUM_MAX , arg);if (tb[TCA_CSUM_PARMS ] ==NULL ) { -fprintf (f,"[NULL csum parameters]" ); +fprintf (stderr,"missing csum parameters\n" );return -1 ; } sel =RTA_DATA (tb[TCA_CSUM_PARMS ]);tc/m_gact.c +0
-0
tc/m_gact.c print_gact(struct action_util *au, FILE *f, struct rtattr *arg) · line 177
Quoted 5 lines
tc/m_gact.c +1
-1@@ -174,7 +174,7 @@ print_gact(struct action_util *au, FILE *f, struct rtattr *arg)parse_rtattr_nested (tb,TCA_GACT_MAX , arg);if (tb[TCA_GACT_PARMS ] ==NULL ) { -print_string (PRINT_FP ,NULL ,"%s" ,"[NULL gact parameters]" ); +fprintf (stderr,"[NULL gact parameters]\n" );
We should be consistent and not showing the the '[]'. You have several error messages with those included.