]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/hostname/hostnamed.c
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
[thirdparty/systemd.git] / src / hostname / hostnamed.c
index c423be3767f4db40bc116222aec1217a873f394a..e1fbacd11bbe38628f7e2e6215ac812d338219e8 100644 (file)
 
 #include <errno.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/utsname.h>
+#include <unistd.h>
 
-#include "util.h"
-#include "strv.h"
+#include "alloc-util.h"
+#include "bus-util.h"
 #include "def.h"
-#include "virt.h"
 #include "env-util.h"
 #include "fileio-label.h"
-#include "bus-util.h"
-#include "event-util.h"
-#include "selinux-util.h"
 #include "hostname-util.h"
+#include "parse-util.h"
+#include "path-util.h"
+#include "selinux-util.h"
+#include "strv.h"
+#include "user-util.h"
+#include "util.h"
+#include "virt.h"
 
 #define VALID_DEPLOYMENT_CHARS (DIGITS LETTERS "-.:")
 
@@ -63,10 +66,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 +115,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 +155,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 +498,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 +569,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;
 
@@ -666,7 +664,7 @@ static const sd_bus_vtable hostname_vtable[] = {
 };
 
 static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) {
-        _cleanup_bus_flush_close_unref_ sd_bus *bus = NULL;
+        _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
         int r;
 
         assert(c);
@@ -697,8 +695,8 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) {
 
 int main(int argc, char *argv[]) {
         Context context = {};
-        _cleanup_event_unref_ sd_event *event = NULL;
-        _cleanup_bus_flush_close_unref_ sd_bus *bus = NULL;
+        _cleanup_(sd_event_unrefp) sd_event *event = NULL;
+        _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
         int r;
 
         log_set_target(LOG_TARGET_AUTO);
@@ -714,12 +712,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");