aboutsummaryrefslogtreecommitdiffstats
path: root/src/pty-unix.c
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2016-05-10 17:25:12 -0400
committerJesse Luehrs <doy@tozt.net>2016-05-10 17:31:39 -0400
commitec77a7037586864ece6505c448ab5c15bf8a57d9 (patch)
treead23ca8d2ded6ffc0a9d9c6c5320e457c37ece32 /src/pty-unix.c
parent9118ead5ae15548c8a5b96340f9a0a24b3104e32 (diff)
downloadrunes-ec77a7037586864ece6505c448ab5c15bf8a57d9.tar.gz
runes-ec77a7037586864ece6505c448ab5c15bf8a57d9.zip
refactor how submodules are handled
let them own their own memory, so that they can free themselves once they exit the loop. also split out the parts of the terminal that we only want to initialize once, even if we open multiple terminal windows
Diffstat (limited to 'src/pty-unix.c')
-rw-r--r--src/pty-unix.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/pty-unix.c b/src/pty-unix.c
index 27419ce..2430cd2 100644
--- a/src/pty-unix.c
+++ b/src/pty-unix.c
@@ -19,11 +19,16 @@
static void runes_pty_backend_read(void *t);
static int runes_pty_backend_got_data(void *t);
-void runes_pty_backend_init(RunesPtyBackend *pty)
+RunesPtyBackend *runes_pty_backend_new()
{
+ RunesPtyBackend *pty;
+
+ pty = calloc(1, sizeof(RunesPtyBackend));
pty->master = posix_openpt(O_RDWR);
grantpt(pty->master);
unlockpt(pty->master);
+
+ return pty;
}
void runes_pty_backend_spawn_subprocess(RunesTerm *t)
@@ -94,12 +99,11 @@ void runes_pty_backend_spawn_subprocess(RunesTerm *t)
fprintf(old_stderr, "Couldn't run %s: %s\n", cmd, strerror(errno));
exit(1);
}
-
- runes_term_refcnt_inc(t);
}
void runes_pty_backend_init_loop(RunesTerm *t, RunesLoop *loop)
{
+ runes_term_refcnt_inc(t);
runes_loop_start_work(loop, t, runes_pty_backend_read,
runes_pty_backend_got_data);
}
@@ -128,9 +132,11 @@ void runes_pty_backend_request_close(RunesTerm *t)
kill(pty->child_pid, SIGHUP);
}
-void runes_pty_backend_cleanup(RunesPtyBackend *pty)
+void runes_pty_backend_delete(RunesPtyBackend *pty)
{
close(pty->master);
+
+ free(pty);
}
static void runes_pty_backend_read(void *t)
@@ -157,8 +163,6 @@ static int runes_pty_backend_got_data(void *t)
return 1;
}
else {
- runes_pty_backend_cleanup(pty);
- free(pty);
runes_window_backend_request_close(t);
runes_term_refcnt_dec(t);