From: 张胜举 <zhangshengju@cmss.chinamobile.com>
To: "'David Laight'" <David.Laight@ACULAB.COM>, <netdev@vger.kernel.org>
Subject: RE: [PATCH iproute2] ip: replace exit with return
Date: Thu, 13 Aug 2015 09:47:07 +0800 [thread overview]
Message-ID: <000001d0d569$f7d9e8c0$e78dba40$@cmss.chinamobile.com> (raw)
>
> From: netdev-owner@vger.kernel.org
> > Sent: 11 August 2015 10:40
> > In our manual, we have this description of 'EXIT STATUS':
> > Exit status is 0 if command was successful, and 1 if there is a syntax
> > error.
> >
> > But we exit in command functions with code -1 when there is a syntax
error.
> > It's better to use return.
>
> Eh?
> Using exit() makes it much more obvious that the program is going to exit.
>
> I've not looked at the call site (I'm not entirely sure where this code is
in the
> source tree), but main() shouldn't return -1 any more than exit(-1) is
invalid.
> The domain for both is 0..127.
> So the code should be using a valid value.
1. Using exit(-1) will make program exit with -1.
With return -1, the do_cmd() function will make sure 1 is returned.
do_cmd()
{
xxxx
return -(c->func(argc-1, argv+1));
xxxx
}
2. Replace with return will confirm with manual description like I said in
last mail.
BRs,
Zhang
>
> ...
> > diff --git a/ip/ipaddress.c b/ip/ipaddress.c index b7b4e3e..6d29a69
> > 100644
> > --- a/ip/ipaddress.c
> > +++ b/ip/ipaddress.c
> > @@ -1879,5 +1879,5 @@ int do_ipaddr(int argc, char **argv)
> > if (matches(*argv, "help") == 0)
> > usage();
> > fprintf(stderr, "Command \"%s\" is unknown, try \"ip addr
help\".\n",
> *argv);
> > - exit(-1);
> > + return -1;
> > }
> ...
>
> David
next reply other threads:[~2015-08-13 1:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-13 1:47 张胜举 [this message]
-- strict thread matches above, loose matches on Subject: below --
2015-08-11 9:40 [PATCH iproute2] ip: replace exit with return Zhang Shengju
2015-08-12 9:58 ` David Laight
2015-08-19 23:31 ` Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='000001d0d569$f7d9e8c0$e78dba40$@cmss.chinamobile.com' \
--to=zhangshengju@cmss.chinamobile.com \
--cc=David.Laight@ACULAB.COM \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).