+int fsck(const char *argv0) {
+ exe_name = argv0;
+
+ // Check that tinc.conf is readable and read our name if it is.
+ char *name = read_node_name();
+
+ if(!name) {
+ fprintf(stderr, "ERROR: tinc cannot run without a valid Name.\n");
+ exe_name = NULL;
+ return EXIT_FAILURE;
+ }
+
+ // Avoid touching global configuration here. Read the config files into
+ // a temporary configuration tree, then throw it away after fsck is done.
+ splay_tree_t config;
+ init_configuration(&config);
+
+ // Read the server configuration file and append host configuration for our node.
+ bool success = read_server_config(&config) &&
+ read_host_config(&config, name, true);
+
+ // Check both RSA and EC key pairs.
+ // We need working configuration to run this check.
+ if(success) {
+ success = check_keypairs(&config, name);
+ }
+
+ // Check that scripts are executable and check the config for invalid variables.
+ // This check does not require working configuration, so run it always.
+ // This way, we can diagnose more issues on the first run.
+ success = success & check_scripts_and_configs();
+
+ splay_empty_tree(&config);
+ free(name);
+ exe_name = NULL;
+
+ return success ? EXIT_SUCCESS : EXIT_FAILURE;
+}