mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 19:43:32 +00:00
33d280c8ba
- Blocking read operations on the Windows Console can now EINTR - Blocking read operations on Windows pipes now EINTR more reliably - setitimer() will no longer be inherited across fork() on Windows - It's now possible to use ECHO when the console is in raw mode - The ECHOCTL flag now works correctly on the Windows Console - The ICRNL flag now works correctly on the Windows Console - pread() and pwrite() will now raise ESPIPE on Windows - Opening /dev/tty on Windows is improved (untested) - Overlapped I/O is now implemented in a better way
76 lines
3.6 KiB
C
76 lines
3.6 KiB
C
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
|
│ │
|
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
|
│ any purpose with or without fee is hereby granted, provided that the │
|
|
│ above copyright notice and this permission notice appear in all copies. │
|
|
│ │
|
|
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
|
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
|
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
|
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
|
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
|
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
|
#include "libc/calls/calls.h"
|
|
#include "libc/calls/struct/itimerval.h"
|
|
#include "libc/calls/struct/sigaction.h"
|
|
#include "libc/calls/struct/siginfo.h"
|
|
#include "libc/calls/struct/sigset.h"
|
|
#include "libc/calls/struct/timeval.h"
|
|
#include "libc/calls/ucontext.h"
|
|
#include "libc/runtime/runtime.h"
|
|
#include "libc/sysv/consts/itimer.h"
|
|
#include "libc/sysv/consts/sa.h"
|
|
#include "libc/sysv/consts/sicode.h"
|
|
#include "libc/sysv/consts/sig.h"
|
|
#include "libc/testlib/subprocess.h"
|
|
#include "libc/testlib/testlib.h"
|
|
#include "libc/time/time.h"
|
|
|
|
bool gotsig;
|
|
|
|
void SetUpOnce(void) {
|
|
ASSERT_SYS(0, 0, pledge("stdio proc", 0));
|
|
}
|
|
|
|
void OnSigAlrm(int sig, siginfo_t *si, void *ctx) {
|
|
EXPECT_EQ(SIGALRM, sig);
|
|
EXPECT_EQ(SIGALRM, si->si_signo);
|
|
gotsig = true;
|
|
}
|
|
|
|
TEST(setitimer, testSingleShot) {
|
|
sigset_t block, oldmask;
|
|
struct sigaction oldalrm;
|
|
struct itimerval it = {{0, 0}, {0, 10000}};
|
|
struct sigaction sa = {.sa_sigaction = OnSigAlrm,
|
|
.sa_flags = SA_RESETHAND | SA_SIGINFO};
|
|
gotsig = false;
|
|
sigemptyset(&block);
|
|
sigaddset(&block, SIGALRM);
|
|
EXPECT_EQ(0, sigprocmask(SIG_BLOCK, &block, &oldmask));
|
|
ASSERT_EQ(0, sigaction(SIGALRM, &sa, &oldalrm));
|
|
ASSERT_EQ(0, setitimer(ITIMER_REAL, &it, 0));
|
|
sigdelset(&block, SIGALRM);
|
|
EXPECT_EQ(-1, sigsuspend(&block));
|
|
EXPECT_EQ(0, sigprocmask(SIG_SETMASK, &oldmask, 0));
|
|
EXPECT_EQ(0, sigaction(SIGUSR1, &oldalrm, 0));
|
|
EXPECT_EQ(true, gotsig);
|
|
}
|
|
|
|
TEST(setitimer, notInheritedAcrossFork) {
|
|
struct itimerval disarm = {0};
|
|
struct itimerval singleshot = {{0}, {100}};
|
|
ASSERT_SYS(0, 0, setitimer(ITIMER_REAL, &singleshot, 0));
|
|
SPAWN(fork);
|
|
struct itimerval it;
|
|
ASSERT_SYS(0, 0, setitimer(ITIMER_REAL, 0, &it));
|
|
ASSERT_TRUE(timeval_iszero(it.it_value));
|
|
EXITS(0);
|
|
ASSERT_SYS(0, 0, setitimer(ITIMER_REAL, &disarm, 0));
|
|
}
|