chiark / gitweb /
dbus: use _cleanup_free_ instead of freeing ourself
[elogind.git] / src / hostname / hostnamectl.c
index a1e1bd84437afb0cb79a04cf992f17f60c0e1cf3..f7d844b9757ba5f7bd695c2e9c05805299c2474a 100644 (file)
@@ -44,7 +44,8 @@ static enum transport {
         TRANSPORT_POLKIT
 } arg_transport = TRANSPORT_NORMAL;
 static bool arg_ask_password = true;
-static const char *arg_host = NULL;
+static char *arg_host = NULL;
+static char *arg_user = NULL;
 static bool arg_set_transient = false;
 static bool arg_set_pretty = false;
 static bool arg_set_static = false;
@@ -79,14 +80,18 @@ static void print_status_info(StatusInfo *i) {
         printf("   Static hostname: %s\n",
                strna(i->static_hostname));
 
-        if (!streq_ptr(i->hostname, i->static_hostname))
+        if (!isempty(i->pretty_hostname) &&
+            !streq_ptr(i->pretty_hostname, i->static_hostname))
+                printf("   Pretty hostname: %s\n",
+                       strna(i->pretty_hostname));
+
+        if (!isempty(i->hostname) &&
+            !streq_ptr(i->hostname, i->static_hostname))
                 printf("Transient hostname: %s\n",
                        strna(i->hostname));
 
-        printf("   Pretty hostname: %s\n"
-               "         Icon name: %s\n"
+        printf("         Icon name: %s\n"
                "           Chassis: %s\n",
-               strna(i->pretty_hostname),
                strna(i->icon_name),
                strna(i->chassis));
 
@@ -215,7 +220,7 @@ static int show_status(DBusConnection *bus, char **args, unsigned n) {
 
 static int set_hostname(DBusConnection *bus, char **args, unsigned n) {
         _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
-        dbus_bool_t interactive = true;
+        dbus_bool_t interactive = arg_ask_password;
         _cleanup_free_ char *h = NULL;
         const char *hostname = args[1];
         int r;
@@ -307,7 +312,7 @@ static int set_hostname(DBusConnection *bus, char **args, unsigned n) {
 
 static int set_icon_name(DBusConnection *bus, char **args, unsigned n) {
         _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
-        dbus_bool_t interactive = true;
+        dbus_bool_t interactive = arg_ask_password;
 
         assert(args);
         assert(n == 2);
@@ -329,7 +334,7 @@ static int set_icon_name(DBusConnection *bus, char **args, unsigned n) {
 
 static int set_chassis(DBusConnection *bus, char **args, unsigned n) {
         _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
-        dbus_bool_t interactive = true;
+        dbus_bool_t interactive = arg_ask_password;
 
         assert(args);
         assert(n == 2);
@@ -358,6 +363,7 @@ static int help(void) {
                "     --transient         Only set transient hostname\n"
                "     --static            Only set static hostname\n"
                "     --pretty            Only set pretty hostname\n"
+               "  -P --privileged        Acquire privileges before execution\n"
                "     --no-ask-password   Do not prompt for password\n"
                "  -H --host=[USER@]HOST  Operate on remote host\n\n"
                "Commands:\n"
@@ -416,7 +422,7 @@ static int parse_argv(int argc, char *argv[]) {
 
                 case 'H':
                         arg_transport = TRANSPORT_SSH;
-                        arg_host = optarg;
+                        parse_user_at_host(optarg, &arg_user, &arg_host);
                         break;
 
                 case ARG_SET_TRANSIENT: