return def;
}
-
-
-static int qemuParseProcFileStrings(int pid_value,
- const char *name,
- char ***list)
-{
- char *path = NULL;
- int ret = -1;
- char *data = NULL;
- ssize_t len;
- char *tmp;
- size_t nstr = 0;
- char **str = NULL;
-
- if (virAsprintf(&path, "/proc/%d/%s", pid_value, name) < 0)
- goto cleanup;
-
- if ((len = virFileReadAll(path, 1024*128, &data)) < 0)
- goto cleanup;
-
- tmp = data;
- while (tmp < (data + len)) {
- if (VIR_EXPAND_N(str, nstr, 1) < 0)
- goto cleanup;
-
- if (VIR_STRDUP(str[nstr-1], tmp) < 0)
- goto cleanup;
- /* Skip arg */
- tmp += strlen(tmp);
- /* Skip \0 separator */
- tmp++;
- }
-
- if (VIR_EXPAND_N(str, nstr, 1) < 0)
- goto cleanup;
-
- str[nstr-1] = NULL;
-
- ret = nstr-1;
- *list = str;
-
- cleanup:
- if (ret < 0)
- virStringListFree(str);
- VIR_FREE(data);
- VIR_FREE(path);
- return ret;
-}
-
-virDomainDefPtr qemuParseCommandLinePid(virFileCachePtr capsCache,
- virCapsPtr caps,
- virDomainXMLOptionPtr xmlopt,
- pid_t pid,
- char **pidfile,
- virDomainChrSourceDefPtr *monConfig,
- bool *monJSON)
-{
- virDomainDefPtr def = NULL;
- char **progargv = NULL;
- char **progenv = NULL;
- char *exepath = NULL;
- char *emulator;
-
- /* The parser requires /proc/pid, which only exists on platforms
- * like Linux where pid_t fits in int. */
- if ((int)pid != pid ||
- qemuParseProcFileStrings(pid, "cmdline", &progargv) < 0 ||
- qemuParseProcFileStrings(pid, "environ", &progenv) < 0)
- goto cleanup;
-
- if (!(def = qemuParseCommandLine(capsCache, caps, xmlopt, progenv, progargv,
- pidfile, monConfig, monJSON)))
- goto cleanup;
-
- if (virAsprintf(&exepath, "/proc/%d/exe", (int)pid) < 0)
- goto cleanup;
-
- if (virFileResolveLink(exepath, &emulator) < 0) {
- virReportSystemError(errno,
- _("Unable to resolve %s for pid %u"),
- exepath, (int)pid);
- goto cleanup;
- }
- VIR_FREE(def->emulator);
- def->emulator = emulator;
-
- cleanup:
- VIR_FREE(exepath);
- virStringListFree(progargv);
- virStringListFree(progenv);
- return def;
-}