|
@@ -111,39 +111,9 @@ void clish_shell_load_files(clish_shell_t * this)
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
- * This is invoked when the thread ends or is cancelled.
|
|
|
- */
|
|
|
-static void clish_shell_thread_cleanup(clish_shell_t * this)
|
|
|
-{
|
|
|
-#ifdef __vxworks
|
|
|
- int last_state;
|
|
|
-
|
|
|
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &last_state);
|
|
|
-#endif
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-#ifdef __vxworks
|
|
|
- pthread_setcancelstate(last_state, &last_state);
|
|
|
-#endif
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- * This provides the thread of execution for a shell instance
|
|
|
- */
|
|
|
-static void *clish_shell_thread(void *arg)
|
|
|
+static bool_t _loop(clish_shell_t * this, bool_t is_thread)
|
|
|
{
|
|
|
bool_t running = BOOL_TRUE;
|
|
|
- clish_shell_t *this = arg;
|
|
|
- int last_type;
|
|
|
-
|
|
|
-
|
|
|
- pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &last_type);
|
|
|
-
|
|
|
- pthread_cleanup_push((void (*)(void *))clish_shell_thread_cleanup, this);
|
|
|
-
|
|
|
|
|
|
* Check the shell isn't closing down
|
|
|
*/
|
|
@@ -152,13 +122,11 @@ static void *clish_shell_thread(void *arg)
|
|
|
(void)clish_shell_push_file(this,
|
|
|
fdopen(fileno(tinyrl__get_istream(this->tinyrl)),"r"), BOOL_TRUE);
|
|
|
|
|
|
- pthread_testcancel();
|
|
|
+ if (is_thread)
|
|
|
+ pthread_testcancel();
|
|
|
|
|
|
|
|
|
while (running) {
|
|
|
- const clish_command_t *cmd;
|
|
|
- const clish_view_t *view;
|
|
|
-
|
|
|
if ((SHELL_STATE_SCRIPT_ERROR == this->state) &&
|
|
|
(BOOL_TRUE == tinyrl__get_isatty(this->tinyrl))) {
|
|
|
|
|
@@ -178,9 +146,50 @@ static void *clish_shell_thread(void *arg)
|
|
|
running = clish_shell_pop_file(this);
|
|
|
}
|
|
|
|
|
|
- pthread_testcancel();
|
|
|
+ if (is_thread)
|
|
|
+ pthread_testcancel();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ return BOOL_TRUE;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * This is invoked when the thread ends or is cancelled.
|
|
|
+ */
|
|
|
+static void clish_shell_thread_cleanup(clish_shell_t * this)
|
|
|
+{
|
|
|
+#ifdef __vxworks
|
|
|
+ int last_state;
|
|
|
+
|
|
|
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &last_state);
|
|
|
+#endif
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+#ifdef __vxworks
|
|
|
+ pthread_setcancelstate(last_state, &last_state);
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * This provides the thread of execution for a shell instance
|
|
|
+ */
|
|
|
+static void *clish_shell_thread(void *arg)
|
|
|
+{
|
|
|
+ clish_shell_t *this = arg;
|
|
|
+ int last_type;
|
|
|
+
|
|
|
+
|
|
|
+ pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &last_type);
|
|
|
+
|
|
|
+ pthread_cleanup_push((void (*)(void *))clish_shell_thread_cleanup, this);
|
|
|
+
|
|
|
+ if (this)
|
|
|
+ _loop(this, BOOL_TRUE);
|
|
|
+
|
|
|
|
|
|
pthread_cleanup_pop(1);
|
|
|
|
|
@@ -219,9 +228,11 @@ int clish_shell_spawn_and_wait(clish_shell_t * this,
|
|
|
return clish_shell_wait(this);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
|
|
|
-bool_t clish_shell_spawn_from_file(clish_shell_t * this,
|
|
|
- const pthread_attr_t * attr, const char *filename)
|
|
|
+static bool_t _from_file(clish_shell_t * this,
|
|
|
+ bool_t is_thread, const pthread_attr_t * attr,
|
|
|
+ const char *filename)
|
|
|
{
|
|
|
bool_t result = BOOL_FALSE;
|
|
|
FILE *file;
|
|
@@ -233,12 +244,38 @@ bool_t clish_shell_spawn_from_file(clish_shell_t * this,
|
|
|
if (NULL == file)
|
|
|
return result;
|
|
|
tinyrl__set_istream(this->tinyrl, file);
|
|
|
-
|
|
|
- result = clish_shell_spawn_and_wait(this, attr) ?
|
|
|
- BOOL_TRUE : BOOL_FALSE;
|
|
|
+ if (is_thread) {
|
|
|
+
|
|
|
+ result = clish_shell_spawn_and_wait(this, attr) ?
|
|
|
+ BOOL_TRUE : BOOL_FALSE;
|
|
|
+ } else {
|
|
|
+
|
|
|
+ result = clish_shell_loop(this);
|
|
|
+ }
|
|
|
fclose(file);
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
+bool_t clish_shell_spawn_from_file(clish_shell_t * this,
|
|
|
+ const pthread_attr_t * attr, const char *filename)
|
|
|
+{
|
|
|
+ return _from_file(this, BOOL_TRUE, attr, filename);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+bool_t clish_shell_from_file(clish_shell_t * this,
|
|
|
+ const char *filename)
|
|
|
+{
|
|
|
+ return _from_file(this, BOOL_FALSE, NULL, filename);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+bool_t clish_shell_loop(clish_shell_t * this)
|
|
|
+{
|
|
|
+ return _loop(this, BOOL_FALSE);
|
|
|
+}
|
|
|
+
|
|
|
+
|