MCPcopy Create free account
hub / github.com/F-Stack/f-stack / fs_execute_cmd

Function fs_execute_cmd

dpdk/drivers/net/failsafe/failsafe_args.c:86–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84}
85
86static int
87fs_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);
132ret_pclose:
133 if (pclose(fp) == -1)
134 ERROR("pclose: %s", strerror(errno));
135 return ret;
136}
137
138static int
139fs_read_fd(struct sub_device *sdev, char *fd_str)

Callers 2

fs_parse_device_paramFunction · 0.85
failsafe_args_parse_subsFunction · 0.85

Calls 4

callocFunction · 0.85
fs_sanitize_cmdlineFunction · 0.85
fs_parse_deviceFunction · 0.85
strlcpyFunction · 0.50

Tested by

no test coverage detected