diff mbox series

[RFC,v7] ell/edit: Rename 'l_term_{open,close}'.

Message ID 20240404233826.3466674-8-gerickson@nuovations.com (mailing list archive)
State New
Headers show
Series [RFC,v7] ell/edit: Rename 'l_term_{open,close}'. | expand

Checks

Context Check Description
tedd_an/pre-ci_am fail error: patch failed: ell/ell.sym:632 error: ell/ell.sym: patch does not apply error: ell/term.c: does not exist in index error: ell/term.h: does not exist in index hint: Use 'git am --show-current-patch' to see the failed patch

Commit Message

Grant Erickson April 4, 2024, 11:38 p.m. UTC
Renames 'l_term_{open,close}' to 'l_term_{acquire,release}' since this
aligns more closely with what is happening with the underlying file
descriptors. In particular, those descriptors are not being opened or
closed. Rather, their TTY parameters are being saved and altered on
'open' (now 'acquire') and restored on 'close' (now 'release'). At no
point are the descriptors being transformed with the 'open' or 'close'
system calls.
---
 ell/ell.sym |  4 ++--
 ell/term.c  | 18 ++++++++++++------
 ell/term.h  |  4 ++--
 3 files changed, 16 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/ell/ell.sym b/ell/ell.sym
index 2767bf55e079..0026bbe1afcf 100644
--- a/ell/ell.sym
+++ b/ell/ell.sym
@@ -632,8 +632,8 @@  global:
 	l_term_set_output;
 	l_term_set_output_stdout;
 	l_term_set_key_handler;
-	l_term_open;
-	l_term_close;
+	l_term_acquire;
+	l_term_release;
 	l_term_io_callback;
 	l_term_process;
 	l_term_putnstr;
diff --git a/ell/term.c b/ell/term.c
index 7ec92476e14e..f3801bcb1200 100644
--- a/ell/term.c
+++ b/ell/term.c
@@ -126,7 +126,7 @@  struct l_term {
 	unsigned short num_row;
 	unsigned short num_col;
 	struct l_signal *sigwinch;
-	bool is_running;
+	bool is_acquired;
 	char key_buf[8];
 	size_t key_len;
 	l_term_key_func_t key_handler;
@@ -145,7 +145,7 @@  LIB_EXPORT struct l_term *l_term_new(void)
 	term->out_fd = -1;
 	term->out_ops = NULL;
 
-	term->is_running = false;
+	term->is_acquired = false;
 
 	return term;
 }
@@ -241,7 +241,7 @@  static void sigwinch_handler(void *user_data)
 					&term->num_row, &term->num_col);
 }
 
-LIB_EXPORT int l_term_open(struct l_term *term)
+LIB_EXPORT int l_term_acquire(struct l_term *term)
 {
 	struct termios termios;
 	int retval = 0;
@@ -249,6 +249,9 @@  LIB_EXPORT int l_term_open(struct l_term *term)
 	if (!term)
 		return -EINVAL;
 
+	if (term->is_acquired)
+		return -EALREADY;
+
 	/* Missing input or output file descriptor is a non-recoverable
 	 * situation at this point.
 	 */
@@ -317,19 +320,20 @@  LIB_EXPORT int l_term_open(struct l_term *term)
 	IO_HANDLER(term, term->in_fd, 1, 0);
 	IO_HANDLER(term, term->out_fd, 0, 1);
 
-	term->is_running = true;
+	term->is_acquired = true;
 
 	return retval;
 }
 
-LIB_EXPORT int l_term_close(struct l_term *term)
+LIB_EXPORT int l_term_release(struct l_term *term)
 {
 	int retval = 0;
 
 	if (!term)
 		return -EINVAL;
 
-	term->is_running = false;
+	if (!term->is_acquired)
+		return -EALREADY;
 
 	IO_HANDLER(term, term->in_fd, 0, 0);
 	IO_HANDLER(term, term->out_fd, 0, 0);
@@ -347,6 +351,8 @@  LIB_EXPORT int l_term_close(struct l_term *term)
 	if (retval < 0)
 		return retval;
 
+	term->is_acquired = false;
+
 	return retval;
 }
 
diff --git a/ell/term.h b/ell/term.h
index 89ed6c97c7ce..50831c166c78 100644
--- a/ell/term.h
+++ b/ell/term.h
@@ -44,8 +44,8 @@  typedef void (*l_term_key_func_t) (struct l_term *term, wint_t wch, void *user_d
 int  l_term_set_key_handler(struct l_term *term,
 				l_term_key_func_t handler, void *user_data);
 
-int  l_term_open(struct l_term *term);
-int  l_term_close(struct l_term *term);
+int  l_term_acquire(struct l_term *term);
+int  l_term_release(struct l_term *term);
 
 bool l_term_io_callback(struct l_io *io, void *user_data);