| 84 | } |
| 85 | |
| 86 | static int |
| 87 | fs_execute_cmd(struct sub_device *sdev, char *cmdline) |
| 88 | { |
| 89 | FILE *fp; |
| 90 | /* store possible newline as well */ |
| 91 | char output[DEVARGS_MAXLEN + 1]; |
| 92 | size_t len; |
| 93 | int ret; |
| 94 | |
| 95 | RTE_ASSERT(cmdline != NULL || sdev->cmdline != NULL); |
| 96 | if (sdev->cmdline == NULL) { |
| 97 | size_t i; |
| 98 | |
| 99 | len = strlen(cmdline) + 1; |
| 100 | sdev->cmdline = calloc(1, len); |
| 101 | if (sdev->cmdline == NULL) { |
| 102 | ERROR("Command line allocation failed"); |
| 103 | return -ENOMEM; |
| 104 | } |
| 105 | strlcpy(sdev->cmdline, cmdline, len); |
| 106 | /* Replace all commas in the command line by spaces */ |
| 107 | for (i = 0; i < len; i++) |
| 108 | if (sdev->cmdline[i] == ',') |
| 109 | sdev->cmdline[i] = ' '; |
| 110 | } |
| 111 | DEBUG("'%s'", sdev->cmdline); |
| 112 | fp = popen(sdev->cmdline, "r"); |
| 113 | if (fp == NULL) { |
| 114 | ret = -errno; |
| 115 | ERROR("popen: %s", strerror(errno)); |
| 116 | return ret; |
| 117 | } |
| 118 | /* We only read one line */ |
| 119 | if (fgets(output, sizeof(output) - 1, fp) == NULL) { |
| 120 | DEBUG("Could not read command output"); |
| 121 | ret = -ENODEV; |
| 122 | goto ret_pclose; |
| 123 | } |
| 124 | fs_sanitize_cmdline(output); |
| 125 | if (output[0] == '\0') { |
| 126 | ret = -ENODEV; |
| 127 | goto ret_pclose; |
| 128 | } |
| 129 | ret = fs_parse_device(sdev, output); |
| 130 | if (ret) |
| 131 | ERROR("Parsing device '%s' failed", output); |
| 132 | ret_pclose: |
| 133 | if (pclose(fp) == -1) |
| 134 | ERROR("pclose: %s", strerror(errno)); |
| 135 | return ret; |
| 136 | } |
| 137 | |
| 138 | static int |
| 139 | fs_read_fd(struct sub_device *sdev, char *fd_str) |
no test coverage detected