Welcome to little lamb

Code » limb » release » tree

[release] / src / liblimb / term.h / term_ensurefg.c

/* This file is part of limb                           https://lila.oss/limb
 * Copyright (C) 2023 Olivier Brunel                          jjk@jjacky.com */
/* SPDX-License-Identifier: GPL-2.0-only */
#include <signal.h>
#include <unistd.h>
#include <limb/term.h>

int
term_ensurefg(int fd)
{
    struct sigaction oact;
    struct sigaction act = { .sa_handler = SIG_IGN, .sa_flags = SA_RESTART };
    int r;

    sigaction(SIGTTOU, &act, &oact);
    r = tcsetpgrp(fd, getpgid(0));
    sigaction(SIGTTOU, &oact, NULL);

    return !r;
}