#include <sys/utsname.h>
#include <sys/wait.h>
#include <dirent.h>
-#include "qemu-common.h"
#include "guest-agent-core.h"
#include "qga-qapi-commands.h"
#include "qapi/error.h"
#include <utmpx.h>
#endif
-#ifndef CONFIG_HAS_ENVIRON
-#ifdef __APPLE__
-#include <crt_externs.h>
-#define environ (*_NSGetEnviron())
-#else
-extern char **environ;
-#endif
-#endif
-
#if defined(__linux__)
#include <mntent.h>
#include <linux/fs.h>
reopen_fd_to_null(1);
reopen_fd_to_null(2);
- execle("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0",
- "hypervisor initiated shutdown", (char*)NULL, environ);
+ execl("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0",
+ "hypervisor initiated shutdown", (char *)NULL);
_exit(EXIT_FAILURE);
} else if (pid < 0) {
error_setg_errno(errp, errno, "failed to create child process");
/* succeeded */
}
-int64_t qmp_guest_get_time(Error **errp)
-{
- int ret;
- qemu_timeval tq;
-
- ret = qemu_gettimeofday(&tq);
- if (ret < 0) {
- error_setg_errno(errp, errno, "Failed to get time");
- return -1;
- }
-
- return tq.tv_sec * 1000000000LL + tq.tv_usec * 1000;
-}
-
void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
{
int ret;
/* Use '/sbin/hwclock -w' to set RTC from the system time,
* or '/sbin/hwclock -s' to set the system time from RTC. */
- execle(hwclock_path, "hwclock", has_time ? "-w" : "-s",
- NULL, environ);
+ execl(hwclock_path, "hwclock", has_time ? "-w" : "-s", NULL);
_exit(EXIT_FAILURE);
} else if (pid < 0) {
error_setg_errno(errp, errno, "failed to create child process");
gfh->state = RW_STATE_NEW;
}
- buf = g_malloc0(count+1);
+ buf = g_malloc0(count + 1);
read_count = fread(buf, 1, count, fh);
if (ferror(fh)) {
error_setg_errno(errp, errno, "failed to read file");
partition = g_new0(GuestDiskInfo, 1);
partition->name = dev_name;
partition->partition = true;
+ partition->has_dependencies = true;
/* Add parent disk as dependent for easier tracking of hierarchy */
QAPI_LIST_PREPEND(partition->dependencies, g_strdup(disk_dev));
reopen_fd_to_null(1);
reopen_fd_to_null(2);
- execle(hook, hook, arg_str, NULL, environ);
+ execl(hook, hook, arg_str, NULL);
_exit(EXIT_FAILURE);
} else if (pid < 0) {
error_setg_errno(errp, errno, "failed to create child process");
spawn_flag = G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL |
G_SPAWN_STDERR_TO_DEV_NULL;
- success = g_spawn_sync(NULL, (char **)command, environ, spawn_flag,
+ success = g_spawn_sync(NULL, (char **)command, NULL, spawn_flag,
NULL, NULL, NULL, NULL,
&exit_status, &g_err);
return NULL;
}
-#define SYSCONF_EXACT(name, errp) sysconf_exact((name), #name, (errp))
-
-static long sysconf_exact(int name, const char *name_str, Error **errp)
-{
- long ret;
-
- errno = 0;
- ret = sysconf(name);
- if (ret == -1) {
- if (errno == 0) {
- error_setg(errp, "sysconf(%s): value indefinite", name_str);
- } else {
- error_setg_errno(errp, errno, "sysconf(%s)", name_str);
- }
- }
- return ret;
-}
-
/* Transfer online/offline status between @vcpu and the guest system.
*
* On input either @errp or *@errp must be NULL.
GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
{
- int64_t current;
GuestLogicalProcessorList *head, **tail;
- long sc_max;
+ const char *cpu_dir = "/sys/devices/system/cpu";
+ const gchar *line;
+ g_autoptr(GDir) cpu_gdir = NULL;
Error *local_err = NULL;
- current = 0;
head = NULL;
tail = &head;
- sc_max = SYSCONF_EXACT(_SC_NPROCESSORS_CONF, &local_err);
+ cpu_gdir = g_dir_open(cpu_dir, 0, NULL);
- while (local_err == NULL && current < sc_max) {
- GuestLogicalProcessor *vcpu;
- int64_t id = current++;
- char *path = g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId64 "/",
- id);
+ if (cpu_gdir == NULL) {
+ error_setg_errno(errp, errno, "failed to list entries: %s", cpu_dir);
+ return NULL;
+ }
- if (g_file_test(path, G_FILE_TEST_EXISTS)) {
+ while (local_err == NULL && (line = g_dir_read_name(cpu_gdir)) != NULL) {
+ GuestLogicalProcessor *vcpu;
+ int64_t id;
+ if (sscanf(line, "cpu%" PRId64, &id)) {
+ g_autofree char *path = g_strdup_printf("/sys/devices/system/cpu/"
+ "cpu%" PRId64 "/", id);
vcpu = g_malloc0(sizeof *vcpu);
vcpu->logical_id = id;
vcpu->has_can_offline = true; /* lolspeak ftw */
transfer_vcpu(vcpu, true, path, &local_err);
QAPI_LIST_APPEND(tail, vcpu);
}
- g_free(path);
}
if (local_err == NULL) {
reopen_fd_to_null(2);
if (crypted) {
- execle(passwd_path, "chpasswd", "-e", NULL, environ);
+ execl(passwd_path, "chpasswd", "-e", NULL);
} else {
- execle(passwd_path, "chpasswd", NULL, environ);
+ execl(passwd_path, "chpasswd", NULL);
}
_exit(EXIT_FAILURE);
} else if (pid < 0) {