#include "missing_securebits.h"
#include "missing_syscall.h"
#include "mkdir-label.h"
+#include "osc-context.h"
#include "proc-cmdline.h"
#include "process-util.h"
#include "psi-util.h"
}
(void) exec_context_apply_tty_size(context, STDIN_FILENO, STDOUT_FILENO, /* tty_path= */ NULL);
+
+ if (use_ansi)
+ (void) osc_context_open_service(p->unit_id, p->invocation_id, /* ret_seq= */ NULL);
}
int exec_invoke(
* disallocate the VT), to get rid of any prior uses of the device. Note that we do not keep any fd
* open here, hence some of the settings made here might vanish again, depending on the TTY driver
* used. A 2nd ("constructive") initialization after we opened the input/output fds we actually want
- * will fix this. */
- exec_context_tty_reset(context, params);
+ * will fix this. Note that we pass a NULL invocation ID here – as exec_context_tty_reset() expects
+ * the invocation ID associated with the OSC 3008 context ID to close. But we don't want to close any
+ * OSC 3008 context here, and opening a fresh OSC 3008 context happens a bit further down. */
+ exec_context_tty_reset(context, params, /* invocation_id= */ SD_ID128_NULL);
if (params->shall_confirm_spawn && exec_context_shall_confirm_spawn(context)) {
_cleanup_free_ char *cmdline = NULL;
#include "format-util.h"
#include "glob-util.h"
#include "hexdecoct.h"
+#include "io-util.h"
#include "ioprio-util.h"
#include "lock-util.h"
#include "log.h"
#include "missing_prctl.h"
#include "mkdir-label.h"
#include "namespace.h"
+#include "osc-context.h"
#include "parse-util.h"
#include "path-util.h"
#include "process-util.h"
return terminal_set_size_fd(output_fd, tty_path, rows, cols);
}
-void exec_context_tty_reset(const ExecContext *context, const ExecParameters *p) {
+void exec_context_tty_reset(const ExecContext *context, const ExecParameters *p, sd_id128_t invocation_id) {
_cleanup_close_ int _fd = -EBADF, lock_fd = -EBADF;
int fd, r;
if (r < 0)
log_debug_errno(r, "Failed to configure TTY dimensions, ignoring: %m");
+ if (!sd_id128_is_null(invocation_id)) {
+ sd_id128_t context_id;
+
+ r = osc_context_id_from_invocation_id(invocation_id, &context_id);
+ if (r < 0)
+ log_debug_errno(r, "Failed to derive context ID from invocation ID, ignoring: %m");
+ else {
+ _cleanup_free_ char *seq = NULL;
+
+ r = osc_context_close(context_id, &seq);
+ if (r < 0)
+ log_debug_errno(r, "Failed to acquire OSC close sequence, ignoring: %m");
+ else
+ (void) loop_write(fd, seq, SIZE_MAX);
+ }
+ }
+
if (context->tty_vhangup)
(void) terminal_vhangup_fd(fd);
c->n_log_extra_fields = 0;
}
-void exec_context_revert_tty(ExecContext *c) {
+void exec_context_revert_tty(ExecContext *c, sd_id128_t invocation_id) {
_cleanup_close_ int fd = -EBADF;
const char *path;
struct stat st;
assert(c);
/* First, reset the TTY (possibly kicking everybody else from the TTY) */
- exec_context_tty_reset(c, /* parameters= */ NULL);
+ exec_context_tty_reset(c, /* parameters= */ NULL, invocation_id);
/* And then undo what chown_terminal() did earlier. Note that we only do this if we have a path
* configured. If the TTY was passed to us as file descriptor we assume the TTY is opened and managed
void exec_context_free_log_extra_fields(ExecContext *c);
-void exec_context_revert_tty(ExecContext *c);
+void exec_context_revert_tty(ExecContext *c, sd_id128_t invocation_id);
int exec_context_get_clean_directories(ExecContext *c, char **prefix, ExecCleanMask mask, char ***ret);
int exec_context_get_clean_mask(ExecContext *c, ExecCleanMask *ret);
const char* exec_context_tty_path(const ExecContext *context);
int exec_context_apply_tty_size(const ExecContext *context, int input_fd, int output_fd, const char *tty_path);
-void exec_context_tty_reset(const ExecContext *context, const ExecParameters *p);
+void exec_context_tty_reset(const ExecContext *context, const ExecParameters *p, sd_id128_t invocation_id);
uint64_t exec_context_get_rlimit(const ExecContext *c, const char *name);
int exec_context_get_oom_score_adjust(const ExecContext *c);
(void) unlink(s->pid_file);
/* Reset TTY ownership if necessary */
- exec_context_revert_tty(&s->exec_context);
+ exec_context_revert_tty(&s->exec_context, UNIT(s)->invocation_id);
}
static void service_enter_stop_post(Service *s, ServiceResult f) {
kill "$PID"
# Test varlinkctl's --exec fd passing logic properly
-assert_eq "$(varlinkctl --exec call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.Open '{"name": ".host", "mode": "shell", "user": "root", "path": "/bin/bash", "args": ["/bin/bash", "-c", "echo $((7 + 8))"]}' -- bash -c 'read -r -N 2 x <&3 ; echo "$x"')" 15
+assert_eq "$(varlinkctl --exec call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.Open '{"name": ".host", "mode": "shell", "user": "root", "path": "/bin/bash", "args": ["/bin/bash", "-c", "echo $((7 + 8))"], "environment": ["TERM=dumb"]}' -- bash -c 'read -r -N 2 x <&3 ; echo "$x"')" 15
# test io.systemd.Machine.MapFrom
varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.MapFrom '{"name": "long-running", "uid":0, "gid": 0}'