return virBufferContentAndReset(&buf);
}
+
char *virSystemdMakeMachineName(const char *name,
const char *drivername,
bool privileged)
return machinename;
}
+
+char *
+virSystemdGetMachineNameByPID(pid_t pid)
+{
+ DBusConnection *conn;
+ DBusMessage *reply;
+ char *name = NULL, *object = NULL;
+
+ if (virDBusIsServiceEnabled("org.freedesktop.machine1") < 0)
+ goto cleanup;
+
+ if (virDBusIsServiceRegistered("org.freedesktop.systemd1") < 0)
+ goto cleanup;
+
+ if (!(conn = virDBusGetSystemBus()))
+ goto cleanup;
+
+ if (virDBusCallMethod(conn, &reply, NULL,
+ "org.freedesktop.machine1",
+ "/org/freedesktop/machine1",
+ "org.freedesktop.machine1.Manager",
+ "GetMachineByPID",
+ "u", pid) < 0)
+ goto cleanup;
+
+ if (virDBusMessageRead(reply, "o", &object) < 0)
+ goto cleanup;
+
+ VIR_DEBUG("Domain with pid %llu has object path '%s'",
+ (unsigned long long)pid, object);
+
+ if (virDBusCallMethod(conn, &reply, NULL,
+ "org.freedesktop.machine1",
+ object,
+ "org.freedesktop.DBus.Properties",
+ "Get",
+ "ss",
+ "org.freedesktop.machine1.Machine",
+ "Name") < 0)
+ goto cleanup;
+
+ if (virDBusMessageRead(reply, "v", "s", &name) < 0)
+ goto cleanup;
+
+ VIR_DEBUG("Domain with pid %llu has machine name '%s'",
+ (unsigned long long)pid, name);
+
+ cleanup:
+ VIR_FREE(object);
+ dbus_message_unref(reply);
+
+ return name;
+}
+
+
/**
* virSystemdCreateMachine:
* @name: driver unique name of the machine
"Something went wrong creating the machine");
} else {
reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
+
+ if (STREQ(member, "GetMachineByPID")) {
+ const char *object_path = "/org/freedesktop/machine1/machine/qemu_2ddemo";
+ DBusMessageIter iter;
+
+ dbus_message_iter_init_append(reply, &iter);
+ if (!dbus_message_iter_append_basic(&iter,
+ DBUS_TYPE_OBJECT_PATH,
+ &object_path))
+ goto error;
+ } else if (STREQ(member, "Get")) {
+ const char *name = "qemu-demo";
+ DBusMessageIter iter;
+ DBusMessageIter sub;
+
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
+ "s", &sub);
+
+ if (!dbus_message_iter_append_basic(&sub,
+ DBUS_TYPE_STRING,
+ &name))
+ goto error;
+ dbus_message_iter_close_container(&iter, &sub);
+ }
}
} else if (STREQ(service, "org.freedesktop.login1")) {
char *supported = getenv("RESULT_SUPPORT");
}
+static int
+testGetMachineName(const void *opaque ATTRIBUTE_UNUSED)
+{
+ char *tmp = virSystemdGetMachineNameByPID(1234);
+ int ret = -1;
+
+ if (!tmp) {
+ fprintf(stderr, "%s", "Failed to create LXC machine\n");
+ return ret;
+ }
+
+ if (STREQ(tmp, "qemu-demo"))
+ ret = 0;
+
+ VIR_FREE(tmp);
+ return ret;
+}
+
+
struct testNameData {
const char *name;
const char *expected;
ret = -1;
if (virtTestRun("Test create with network ", testCreateNetwork, NULL) < 0)
ret = -1;
+ if (virtTestRun("Test getting machine name ", testGetMachineName, NULL) < 0)
+ ret = -1;
# define TEST_SCOPE(name, unitname) \
do { \