net/failsafe: fix errno set on command execution
authorGaetan Rivet <gaetan.rivet@6wind.com>
Wed, 30 Aug 2017 15:59:54 +0000 (17:59 +0200)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 6 Oct 2017 00:49:47 +0000 (02:49 +0200)
This is unacceptable behavior.

Fixes: a0194d828100 ("net/failsafe: add flexible device definition")
Fixes: 35ffe4208140 ("net/failsafe: fix missing pclose after popen")
Cc: stable@dpdk.org
Reported-by: Matan Azrad <matan@mellanox.com>
Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
drivers/net/failsafe/failsafe_args.c

index ae857b0..cfc83e3 100644 (file)
@@ -115,8 +115,7 @@ fs_execute_cmd(struct sub_device *sdev, char *cmdline)
        /* store possible newline as well */
        char output[DEVARGS_MAXLEN + 1];
        size_t len;
-       int old_err;
-       int ret, pclose_ret;
+       int ret;
 
        RTE_ASSERT(cmdline != NULL || sdev->cmdline != NULL);
        if (sdev->cmdline == NULL) {
@@ -135,12 +134,10 @@ fs_execute_cmd(struct sub_device *sdev, char *cmdline)
                                sdev->cmdline[i] = ' ';
        }
        DEBUG("'%s'", sdev->cmdline);
-       old_err = errno;
        fp = popen(sdev->cmdline, "r");
        if (fp == NULL) {
-               ret = errno;
+               ret = -errno;
                ERROR("popen: %s", strerror(errno));
-               errno = old_err;
                return ret;
        }
        /* We only read one line */
@@ -155,18 +152,11 @@ fs_execute_cmd(struct sub_device *sdev, char *cmdline)
                goto ret_pclose;
        }
        ret = fs_parse_device(sdev, output);
-       if (ret) {
+       if (ret)
                ERROR("Parsing device '%s' failed", output);
-               goto ret_pclose;
-       }
 ret_pclose:
-       pclose_ret = pclose(fp);
-       if (pclose_ret) {
-               pclose_ret = errno;
+       if (pclose(fp) == -1)
                ERROR("pclose: %s", strerror(errno));
-               errno = old_err;
-               return pclose_ret;
-       }
        return ret;
 }