aboutsummaryrefslogtreecommitdiff
path: root/job.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2021-08-14 01:34:54 +0100
committerThomas Adam <thomas@xteddy.org>2021-08-14 01:34:54 +0100
commit54773d23b5ceb779c524dcac6bf3b848886fb6d6 (patch)
tree5c60007637121f63c8c730a04f4e8e741577c21a /job.c
parent4c07367bfe626fce990f5b5b2d00516ae8249a93 (diff)
parent63aa96864280ff07f706ebbae302b7c15abb964f (diff)
downloadrtmux-54773d23b5ceb779c524dcac6bf3b848886fb6d6.tar.gz
rtmux-54773d23b5ceb779c524dcac6bf3b848886fb6d6.tar.bz2
rtmux-54773d23b5ceb779c524dcac6bf3b848886fb6d6.zip
Merge branch 'obsd-master' into master
Diffstat (limited to 'job.c')
-rw-r--r--job.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/job.c b/job.c
index a1fc0cf5..3624c679 100644
--- a/job.c
+++ b/job.c
@@ -50,6 +50,7 @@ struct job {
char *cmd;
pid_t pid;
+ char tty[TTY_NAME_MAX];
int status;
int fd;
@@ -79,7 +80,7 @@ job_run(const char *cmd, int argc, char **argv, struct session *s,
const char *home;
sigset_t set, oldset;
struct winsize ws;
- char **argvp;
+ char **argvp, tty[TTY_NAME_MAX];
/*
* Do not set TERM during .tmux.conf, it is nice to be able to use
@@ -94,7 +95,7 @@ job_run(const char *cmd, int argc, char **argv, struct session *s,
memset(&ws, 0, sizeof ws);
ws.ws_col = sx;
ws.ws_row = sy;
- pid = fdforkpty(ptm_fd, &master, NULL, NULL, &ws);
+ pid = fdforkpty(ptm_fd, &master, tty, NULL, &ws);
} else {
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, out) != 0)
goto fail;
@@ -168,6 +169,7 @@ job_run(const char *cmd, int argc, char **argv, struct session *s,
else
job->cmd = cmd_stringify_argv(argc, argv);
job->pid = pid;
+ strlcpy(job->tty, tty, sizeof job->tty);
job->status = 0;
LIST_INSERT_HEAD(&all_jobs, job, entry);
@@ -199,6 +201,32 @@ fail:
return (NULL);
}
+/* Take job's file descriptor and free the job. */
+int
+job_transfer(struct job *job, pid_t *pid, char *tty, size_t ttylen)
+{
+ int fd = job->fd;
+
+ log_debug("transfer job %p: %s", job, job->cmd);
+
+ if (pid != NULL)
+ *pid = job->pid;
+ if (tty != NULL)
+ strlcpy(tty, job->tty, ttylen);
+
+ LIST_REMOVE(job, entry);
+ free(job->cmd);
+
+ if (job->freecb != NULL && job->data != NULL)
+ job->freecb(job->data);
+
+ if (job->event != NULL)
+ bufferevent_free(job->event);
+
+ free(job);
+ return (fd);
+}
+
/* Kill and free an individual job. */
void
job_free(struct job *job)