chiark / gitweb /
dbus: use _cleanup_free_ instead of freeing ourself
[elogind.git] / src / hostname / hostnamectl.c
index 064581a31cfdb26b81829fadc3b1e6bf04345fab..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;
@@ -219,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;
@@ -311,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);
@@ -333,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);
@@ -362,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"
@@ -420,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: