#include <stdlib.h>
#include <stdbool.h>
-#include <unistd.h>
#include <getopt.h>
#include <locale.h>
#include <string.h>
-#include <sys/timex.h>
-#include <sys/utsname.h>
#include "sd-bus.h"
-
+#include "sd-id128.h"
+#include "hostname-util.h"
#include "bus-util.h"
#include "bus-error.h"
#include "util.h"
#include "spawn-polkit-agent.h"
#include "build.h"
-#include "clock-util.h"
-#include "strv.h"
-#include "sd-id128.h"
-#include "virt.h"
#include "architecture.h"
-#include "fileio.h"
static bool arg_ask_password = true;
static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
static int set_hostname(sd_bus *bus, char **args, unsigned n) {
_cleanup_free_ char *h = NULL;
- const char *hostname = args[1];
+ char *hostname = args[1];
int r;
assert(args);
* just set the passed hostname as static/dynamic
* hostname. */
- h = strdup(hostname);
- if (!h)
- return log_oom();
-
- hostname_cleanup(h, true);
-
- if (arg_static && streq(h, hostname))
+ if (arg_static && hostname_is_valid(hostname, true)) {
p = "";
- else {
- p = hostname;
- hostname = h;
+ /* maybe get rid of trailing dot */
+ hostname = hostname_cleanup(hostname);
+ } else {
+ p = h = strdup(hostname);
+ if (!p)
+ return log_oom();
+
+ hostname_cleanup(hostname);
}
r = set_simple_string(bus, "SetPrettyHostname", p);
break;
case 'M':
- arg_transport = BUS_TRANSPORT_CONTAINER;
+ arg_transport = BUS_TRANSPORT_MACHINE;
arg_host = optarg;
break;
}
int main(int argc, char *argv[]) {
- _cleanup_bus_close_unref_ sd_bus *bus = NULL;
+ _cleanup_bus_flush_close_unref_ sd_bus *bus = NULL;
int r;
setlocale(LC_ALL, "");