chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
bus: connect directly via kdbus in sd_bus_open_system_container()
[elogind.git]
/
src
/
hostname
/
hostnamectl.c
diff --git
a/src/hostname/hostnamectl.c
b/src/hostname/hostnamectl.c
index af428179144cea540b87acf2160961b10cb3bb29..3150396c70e89d2167e94616f4953d7694cea43f 100644
(file)
--- a/
src/hostname/hostnamectl.c
+++ b/
src/hostname/hostnamectl.c
@@
-48,6
+48,18
@@
static bool arg_transient = false;
static bool arg_pretty = false;
static bool arg_static = false;
static bool arg_pretty = false;
static bool arg_static = false;
+static void polkit_agent_open_if_enabled(void) {
+
+ /* Open the polkit agent as a child process if necessary */
+ if (!arg_ask_password)
+ return;
+
+ if (arg_transport != BUS_TRANSPORT_LOCAL)
+ return;
+
+ polkit_agent_open();
+}
+
typedef struct StatusInfo {
char *hostname;
char *static_hostname;
typedef struct StatusInfo {
char *hostname;
char *static_hostname;
@@
-133,7
+145,7
@@
static int show_one_name(sd_bus *bus, const char* attr) {
r = sd_bus_message_read(reply, "s", &s);
if (r < 0)
r = sd_bus_message_read(reply, "s", &s);
if (r < 0)
- return
r
;
+ return
bus_log_parse_error(r)
;
printf("%s\n", s);
printf("%s\n", s);
@@
-192,12
+204,9
@@
static int show_status(sd_bus *bus, char **args, unsigned n) {
static int set_simple_string(sd_bus *bus, const char *method, const char *value) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
static int set_simple_string(sd_bus *bus, const char *method, const char *value) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
- static bool first=true;
int r = 0;
int r = 0;
- if (first && arg_ask_password)
- polkit_agent_open();
- first = false;
+ polkit_agent_open_if_enabled();
r = sd_bus_call_method(
bus,
r = sd_bus_call_method(
bus,
@@
-276,7
+285,7
@@
static int set_chassis(sd_bus *bus, char **args, unsigned n) {
assert(args);
assert(n == 2);
assert(args);
assert(n == 2);
- return set_simple_string(bus, "SetChasis", args[1]);
+ return set_simple_string(bus, "SetChas
s
is", args[1]);
}
static int help(void) {
}
static int help(void) {
@@
-285,12
+294,12
@@
static int help(void) {
"Query or change system hostname.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
"Query or change system hostname.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
- " --transient Only set transient hostname\n"
- " --static Only set static hostname\n"
- " --pretty Only set pretty hostname\n"
" --no-ask-password Do not prompt for password\n"
" -H --host=[USER@]HOST Operate on remote host\n"
" --no-ask-password Do not prompt for password\n"
" -H --host=[USER@]HOST Operate on remote host\n"
- " -M --machine=CONTAINER Operate on local container\n\n"
+ " -M --machine=CONTAINER Operate on local container\n"
+ " --transient Only set transient hostname\n"
+ " --static Only set static hostname\n"
+ " --pretty Only set pretty hostname\n\n"
"Commands:\n"
" status Show current hostname settings\n"
" set-hostname NAME Set system hostname\n"
"Commands:\n"
" status Show current hostname settings\n"
" set-hostname NAME Set system hostname\n"