On Fri, Jun 7, 2019 at 5:25 PM Stephen Hemminger
<step...@networkplumber.org> wrote:
>
> On Fri,  7 Jun 2019 12:13:13 +0200
> Matteo Croce <mcr...@redhat.com> wrote:
>
> > +void netns_restore(void)
> > +{
> > +     if (saved_netns != -1) {
>
> If saved_netns is -1 then it is a program bug becase
> no save was done? then do something?
>

saved_netns can be -1 if you execute a batch which doesn't never
change the current netns, e.g: only link, addr, route etc.
In this case netns_restore() will do nothing as there is nothing to restore

> > +             if (!setns(saved_netns, CLONE_NEWNET)) {
> > +                     close(saved_netns);
> > +                     saved_netns = -1;
> > +             } else {
> > +                     perror("setns");
>
> If you are going to look for errors. then you need to either
> return the error or cause the program to exit.
> You don't want later commands in the batch to be applied
> to wrong namespace.

Right. A failure in restoring a saved netns means that something bad
happened, so better stop.

Regards,

--
Matteo Croce
per aspera ad upstream

Reply via email to