Browse Source

netifd: propagate error code on netifd_reload()

The context is that we generate some of the UCI config
for netifd via scripts/programs.

Every once in a while, there's a goof when doing that
UCI generation, and netifd prints out the error at
stderr, but returns 0 (success) err-code.

This change will fail the ubus call if UCI config
is invalid or missing for /etc/config/network.

Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Acked-by: Hans Dedecker  <dedeckeh@gmail.com>
Alexandru Ardelean 7 years ago
parent
commit
5fbd904e5b
5 changed files with 16 additions and 8 deletions
  1. 8 2
      config.c
  2. 1 1
      config.h
  3. 2 2
      main.c
  4. 1 1
      netifd.h
  5. 4 2
      ubus.c

+ 8 - 2
config.c

@@ -393,16 +393,20 @@ config_init_wireless(void)
 		vlist_flush(&wdev->interfaces);
 }
 
-void
+int
 config_init_all(void)
 {
+	int ret = 0;
+
 	uci_network = config_init_package("network");
 	if (!uci_network) {
 		fprintf(stderr, "Failed to load network config\n");
-		return;
+		return -1;
 	}
 
 	uci_wireless = config_init_package("wireless");
+	if (!uci_wireless)
+		ret = -1;
 
 	vlist_update(&interfaces);
 	config_init = true;
@@ -426,4 +430,6 @@ config_init_all(void)
 	interface_refresh_assignments(false);
 	interface_start_pending();
 	wireless_start_pending();
+
+	return ret;
 }

+ 1 - 1
config.h

@@ -19,6 +19,6 @@
 
 extern bool config_init;
 
-void config_init_all(void);
+int config_init_all(void);
 
 #endif

+ 2 - 2
main.c

@@ -208,9 +208,9 @@ static void netifd_do_restart(struct uloop_timeout *timeout)
 	execvp(global_argv[0], global_argv);
 }
 
-void netifd_reload(void)
+int netifd_reload(void)
 {
-	config_init_all();
+	return config_init_all();
 }
 
 void netifd_restart(void)

+ 1 - 1
netifd.h

@@ -98,6 +98,6 @@ struct interface;
 extern const char *main_path;
 extern const char *config_path;
 void netifd_restart(void);
-void netifd_reload(void);
+int netifd_reload(void);
 
 #endif

+ 4 - 2
ubus.c

@@ -44,8 +44,10 @@ netifd_handle_reload(struct ubus_context *ctx, struct ubus_object *obj,
 		     struct ubus_request_data *req, const char *method,
 		     struct blob_attr *msg)
 {
-	netifd_reload();
-	return 0;
+	if (netifd_reload())
+		return UBUS_STATUS_UNKNOWN_ERROR;
+
+	return UBUS_STATUS_OK;
 }
 
 enum {