libposix: deep refactor; add sys/posixly command

With these changes, libposix (and newlib) can run MirBSD Korn Shell.
This commit is contained in:
2017-09-11 01:01:11 +02:00
parent 2f99fb162f
commit 001069aa7b
56 changed files with 4939 additions and 608 deletions

View File

@ -0,0 +1,58 @@
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <errno.h>
void catcher(int sig) {
printf("Signal catcher called for signal %d\n", sig);
}
void timestamp(char *str) {
time_t t;
time(&t);
printf("The time %s is %s\n", str, ctime(&t));
}
int main(int argc, char *argv[]) {
int result = 0;
int err = 0;
struct sigaction sigact;
sigset_t waitset;
siginfo_t info;
struct timespec timeout;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
sigact.sa_handler = catcher;
sigaction(SIGALRM, &sigact, NULL);
sigemptyset(&waitset);
sigaddset(&waitset, SIGALRM);
sigprocmask(SIG_BLOCK, &waitset, NULL);
timeout.tv_sec = 4; /* Number of seconds to wait */
timeout.tv_nsec = 1000; /* Number of nanoseconds to wait */
alarm(2);
timestamp("before sigtimedwait()");
result = sigtimedwait(&waitset, &info, &timeout);
err = errno;
timestamp("after sigtimedwait()");
if(result > 0){
printf("sigtimedwait() returned for signal %d\n", info.si_signo);
return 0;
}
printf("sigtimedwait() returned %d; errno = %d\n", result, err);
perror("sigtimedwait() function failed");
return 1;
}