Browse Source

Log message when scheme is illegal or not defined.

When the client connects to klishd the klishd tries to create
ksession. Firstly it gets scheme starting entry. When the starting
entry is not found it means that scheme is illegal or not defined.
Often klishd can't found scheme configuration. Previously log says
that session can't be created. It's true but doesn't explain the
possible cause of problem. Now the message is logged that says
about probably illegal scheme.
Serj Kalichev 4 months ago
parent
commit
49a2e3e132
6 changed files with 36 additions and 17 deletions
  1. 5 0
      klish/kscheme.h
  2. 23 0
      klish/kscheme/kscheme.c
  3. 1 2
      klish/ksession.h
  4. 3 12
      klish/ksession/ksession.c
  5. 3 2
      klish/ktp/ktpd_session.c
  6. 1 1
      klish/ktp_session.h

+ 5 - 0
klish/kscheme.h

@@ -13,6 +13,9 @@
 #include <klish/kudata.h>
 
 
+#define KSCHEME_DEFAULT_STARTING_ENTRY "main"
+
+
 typedef struct kscheme_s kscheme_t;
 
 typedef faux_list_node_t kscheme_plugins_node_t;
@@ -47,6 +50,8 @@ kentry_t *kscheme_find_entry(const kscheme_t *scheme, const char *name);
 ssize_t kscheme_entrys_len(const kscheme_t *scheme);
 kscheme_entrys_node_t *kscheme_entrys_iter(const kscheme_t *scheme);
 kentry_t *kscheme_entrys_each(kscheme_entrys_node_t **iter);
+kentry_t *kscheme_starting_entry(const kscheme_t *scheme,
+	const char *starting_entry);
 
 // User data store
 bool_t kscheme_named_udata_new(kscheme_t *scheme,

+ 23 - 0
klish/kscheme/kscheme.c

@@ -87,6 +87,29 @@ void kscheme_free(kscheme_t *scheme)
 	faux_free(scheme);
 }
 
+
+kentry_t *kscheme_starting_entry(const kscheme_t *scheme,
+	const char *starting_entry)
+{
+	const char *entry_to_search = NULL;
+
+	assert(scheme);
+	if (!scheme)
+		return NULL;
+
+	// Starting entry can be get from the function argument, from the STARTUP
+	// tag or default name "main" can be used. Priorities are (from higher):
+	// argument, STARTUP, default name.
+	if (starting_entry)
+		entry_to_search = starting_entry;
+	// STARTUP is not implemented yet
+	else
+		entry_to_search = KSCHEME_DEFAULT_STARTING_ENTRY;
+
+	return kscheme_find_entry_by_path(scheme, entry_to_search);
+}
+
+
 #define TAG "PLUGIN"
 
 static bool_t kscheme_load_plugins(kscheme_t *scheme, kcontext_t *context,

+ 1 - 2
klish/ksession.h

@@ -9,14 +9,13 @@
 #include <klish/kscheme.h>
 #include <klish/kpath.h>
 
-#define KSESSION_STARTING_ENTRY "main"
 
 typedef struct ksession_s ksession_t;
 
 
 C_DECL_BEGIN
 
-ksession_t *ksession_new(kscheme_t *scheme, const char *start_entry);
+ksession_t *ksession_new(kscheme_t *scheme, const char *starting_entry);
 void ksession_free(ksession_t *session);
 
 kscheme_t *ksession_scheme(const ksession_t *session);

+ 3 - 12
klish/ksession/ksession.c

@@ -72,11 +72,10 @@ KGET_BOOL(session, isatty_stderr);
 KSET_BOOL(session, isatty_stderr);
 
 
-ksession_t *ksession_new(kscheme_t *scheme, const char *start_entry)
+ksession_t *ksession_new(kscheme_t *scheme, const char *starting_entry)
 {
 	ksession_t *session = NULL;
 	const kentry_t *entry = NULL;
-	const char *entry_to_search = NULL;
 	klevel_t *level = NULL;
 
 	assert(scheme);
@@ -84,16 +83,8 @@ ksession_t *ksession_new(kscheme_t *scheme, const char *start_entry)
 		return NULL;
 
 	// Before real session allocation we will try to find starting entry.
-	// Starting entry can be get from function argument, from STARTUP tag or
-	// default name 'main' can be used. Don't create session if we can't get
-	// starting entry at all. Priorities are (from higher) argument, STARTUP,
-	// default name.
-	if (start_entry)
-		entry_to_search = start_entry;
-	// STARTUP is not implemented yet
-	else
-		entry_to_search = KSESSION_STARTING_ENTRY;
-	entry = kscheme_find_entry_by_path(scheme, entry_to_search);
+	// Don't create session if we can't get starting entry.
+	entry = kscheme_starting_entry(scheme, starting_entry);
 	if (!entry)
 		return NULL; // Can't find starting entry
 

+ 3 - 2
klish/ktp/ktpd_session.c

@@ -69,7 +69,7 @@ static bool_t get_stream(ktpd_session_t *ktpd, kexec_t *exec, int fd, bool_t is_
 
 
 ktpd_session_t *ktpd_session_new(int sock, kscheme_t *scheme,
-	const char *start_entry, faux_eloop_t *eloop)
+	const char *starting_entry, faux_eloop_t *eloop)
 {
 	ktpd_session_t *ktpd = NULL;
 
@@ -86,8 +86,9 @@ ktpd_session_t *ktpd_session_new(int sock, kscheme_t *scheme,
 	// Init
 	ktpd->state = KTPD_SESSION_STATE_UNAUTHORIZED;
 	ktpd->eloop = eloop;
-	ktpd->session = ksession_new(scheme, start_entry);
+	ktpd->session = ksession_new(scheme, starting_entry);
 	if (!ktpd->session) {
+		syslog(LOG_ERR, "Probably the scheme is illegal or not defined");
 		faux_free(ktpd);
 		return NULL;
 	}

+ 1 - 1
klish/ktp_session.h

@@ -114,7 +114,7 @@ typedef bool_t (*ktpd_session_stall_cb_fn)(ktpd_session_t *session,
 	void *user_data);
 
 ktpd_session_t *ktpd_session_new(int sock, kscheme_t *scheme,
-	const char *start_entry, faux_eloop_t *eloop);
+	const char *starting_entry, faux_eloop_t *eloop);
 void ktpd_session_free(ktpd_session_t *session);
 bool_t ktpd_session_connected(ktpd_session_t *session);
 int ktpd_session_fd(const ktpd_session_t *session);