chiark / gitweb /
networkctl: show the network file applied to each link
[elogind.git] / src / network / networkctl.c
index bf95aa2c90332ab21fb43a733cce1a2633d1c6ee..43258bb942538be3568eb6efd59f4ae2bd77666d 100644 (file)
@@ -141,7 +141,7 @@ static int decode_and_sort_links(sd_rtnl_message *m, LinkInfo **ret) {
                 c++;
         }
 
-        qsort(links, c, sizeof(LinkInfo), link_info_compare);
+        qsort_safe(links, c, sizeof(LinkInfo), link_info_compare);
 
         *ret = links;
         links = NULL;
@@ -294,7 +294,7 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) {
         _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL;
         _cleanup_udev_device_unref_ struct udev_device *d = NULL;
         char devid[2 + DECIMAL_STR_MAX(int)];
-        _cleanup_free_ char *t = NULL;
+        _cleanup_free_ char *t = NULL, *network = NULL;
         const char *driver = NULL, *path = NULL, *vendor = NULL, *model = NULL;
         const char *on_color_operational, *off_color_operational,
                    *on_color_setup, *off_color_setup;
@@ -371,7 +371,11 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) {
                 char *wildcard;
 
                 wildcard = strdup("*");
-                strv_push(&domains, wildcard);
+                if (!wildcard)
+                        return log_oom();
+
+                if (strv_consume(&domains, wildcard) < 0)
+                        return log_oom();
         }
 
         sprintf(devid, "n%i", ifindex);
@@ -392,11 +396,14 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) {
                         model = udev_device_get_property_value(d, "ID_MODEL");
         }
 
+        sd_network_link_get_network_file(ifindex, &network);
 
         printf("%s%s%s %i: %s\n", on_color_operational, draw_special_char(DRAW_BLACK_CIRCLE), off_color_operational, ifindex, name);
 
-        printf("        Type: %s\n"
+        printf("Network File: %s\n"
+               "        Type: %s\n"
                "       State: %s%s%s (%s%s%s)\n",
+               strna(network),
                strna(t),
                on_color_operational, strna(operational_state), off_color_operational,
                on_color_setup, strna(setup_state), off_color_setup);
@@ -423,7 +430,7 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) {
         if (!strv_isempty(dns))
                 dump_list("         DNS: ", dns);
         if (!strv_isempty(domains))
-                dump_list("     Domains: ", domains);
+                dump_list("      Domain: ", domains);
         if (!strv_isempty(ntp))
                 dump_list("         NTP: ", ntp);
 
@@ -450,7 +457,7 @@ static int link_status(char **args, unsigned n) {
 
         if (n <= 1 && !arg_all) {
                 _cleanup_free_ char *operational_state = NULL;
-                _cleanup_strv_free_ char **dns = NULL, **ntp = NULL;
+                _cleanup_strv_free_ char **dns = NULL, **ntp = NULL, **domains = NULL;
                 _cleanup_free_ struct local_address *addresses = NULL;
                 const char *on_color_operational, *off_color_operational;
                 int i, c;
@@ -476,7 +483,11 @@ static int link_status(char **args, unsigned n) {
                 if (!strv_isempty(dns))
                         dump_list("         DNS: ", dns);
 
-                sd_network_get_dns(&ntp);
+                sd_network_get_domains(&domains);
+                if (!strv_isempty(domains))
+                        dump_list("      Domain: ", domains);
+
+                sd_network_get_ntp(&ntp);
                 if (!strv_isempty(ntp))
                         dump_list("         NTP: ", ntp);