summaryrefslogtreecommitdiff
path: root/src/hostname
diff options
context:
space:
mode:
Diffstat (limited to 'src/hostname')
-rw-r--r--src/hostname/hostnamectl.c20
-rw-r--r--src/hostname/hostnamed.c27
2 files changed, 17 insertions, 30 deletions
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
index dcbad99ae9..0724fcc16d 100644
--- a/src/hostname/hostnamectl.c
+++ b/src/hostname/hostnamectl.c
@@ -19,21 +19,21 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include <stdlib.h>
-#include <stdbool.h>
#include <getopt.h>
#include <locale.h>
+#include <stdbool.h>
+#include <stdlib.h>
#include <string.h>
#include "sd-bus.h"
#include "sd-id128.h"
-#include "hostname-util.h"
-#include "bus-util.h"
+
+#include "architecture.h"
#include "bus-error.h"
-#include "util.h"
+#include "bus-util.h"
+#include "hostname-util.h"
#include "spawn-polkit-agent.h"
-#include "build.h"
-#include "architecture.h"
+#include "util.h"
static bool arg_ask_password = true;
static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
@@ -387,9 +387,7 @@ static int parse_argv(int argc, char *argv[]) {
return 0;
case ARG_VERSION:
- puts(PACKAGE_STRING);
- puts(SYSTEMD_FEATURES);
- return 0;
+ return version();
case 'H':
arg_transport = BUS_TRANSPORT_REMOTE;
@@ -519,7 +517,7 @@ int main(int argc, char *argv[]) {
if (r <= 0)
goto finish;
- r = bus_open_transport(arg_transport, arg_host, false, &bus);
+ r = bus_connect_transport(arg_transport, arg_host, false, &bus);
if (r < 0) {
log_error_errno(r, "Failed to create bus connection: %m");
goto finish;
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index c423be3767..dd508aefb5 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -63,10 +63,8 @@ static void context_reset(Context *c) {
assert(c);
- for (p = 0; p < _PROP_MAX; p++) {
- free(c->data[p]);
- c->data[p] = NULL;
- }
+ for (p = 0; p < _PROP_MAX; p++)
+ c->data[p] = mfree(c->data[p]);
}
static void context_free(Context *c) {
@@ -114,12 +112,11 @@ static int context_read_data(Context *c) {
"PRETTY_NAME", &c->data[PROP_OS_PRETTY_NAME],
"CPE_NAME", &c->data[PROP_OS_CPE_NAME],
NULL);
- if (r == -ENOENT) {
+ if (r == -ENOENT)
r = parse_env_file("/usr/lib/os-release", NEWLINE,
"PRETTY_NAME", &c->data[PROP_OS_PRETTY_NAME],
"CPE_NAME", &c->data[PROP_OS_CPE_NAME],
NULL);
- }
if (r < 0 && r != -ENOENT)
return r;
@@ -155,11 +152,11 @@ static const char* fallback_chassis(void) {
unsigned t;
int v;
- v = detect_virtualization(NULL);
+ v = detect_virtualization();
- if (v == VIRTUALIZATION_VM)
+ if (VIRTUALIZATION_IS_VM(v))
return "vm";
- if (v == VIRTUALIZATION_CONTAINER)
+ if (VIRTUALIZATION_IS_CONTAINER(v))
return "container";
r = read_one_line_file("/sys/firmware/acpi/pm_profile", &type);
@@ -498,8 +495,7 @@ static int method_set_static_hostname(sd_bus_message *m, void *userdata, sd_bus_
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
if (isempty(name)) {
- free(c->data[PROP_STATIC_HOSTNAME]);
- c->data[PROP_STATIC_HOSTNAME] = NULL;
+ c->data[PROP_STATIC_HOSTNAME] = mfree(c->data[PROP_STATIC_HOSTNAME]);
} else {
char *h;
@@ -570,8 +566,7 @@ static int set_machine_info(Context *c, sd_bus_message *m, int prop, sd_bus_mess
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
if (isempty(name)) {
- free(c->data[prop]);
- c->data[prop] = NULL;
+ c->data[prop] = mfree(c->data[prop]);
} else {
char *h;
@@ -714,12 +709,6 @@ int main(int argc, char *argv[]) {
goto finish;
}
- if (argc != 1) {
- log_error("This program takes no arguments.");
- r = -EINVAL;
- goto finish;
- }
-
r = sd_event_default(&event);
if (r < 0) {
log_error_errno(r, "Failed to allocate event loop: %m");