posix signals support, 1st pass

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1623 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
lillo
2002-10-23 17:31:10 +00:00
parent 54d6a27c67
commit f510e6ce60
24 changed files with 789 additions and 196 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
SubDir OBOS_TOP src kernel apps ;
KernelObjects false_main.c fibo_main.c init.c true_main.c ;
KernelObjects false_main.c fibo_main.c init.c true_main.c sig_test.c ;
SubInclude OBOS_TOP src kernel apps cpuinfo ;
SubInclude OBOS_TOP src kernel apps echo ;
+17
View File
@@ -6,6 +6,7 @@
#include <syscalls.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
@@ -21,6 +22,7 @@ struct command cmds[] = {
{"cat", &cmd_cat},
{"cd", &cmd_cd},
{"pwd", &cmd_pwd},
{"kill", &cmd_kill},
{"help", &cmd_help},
{NULL, NULL}
};
@@ -185,6 +187,20 @@ int cmd_stat(int argc, char *argv[])
return 0;
}
int cmd_kill(int argc, char *argv[])
{
int rc;
if (argc < 3) {
printf("not enough arguments to kill\n");
return 0;
}
rc = sys_kill(atoi(argv[2]), atoi(argv[1]));
if (rc)
printf("kill failed\n");
return 0;
}
int cmd_help(int argc, char *argv[])
{
printf("command list:\n\n");
@@ -198,6 +214,7 @@ int cmd_help(int argc, char *argv[])
printf("cat <file> : dumps the file to stdout\n");
printf("mount <path> <device> <fsname> : tries to mount <device> at <path>\n");
printf("unmount <path> : tries to unmount at <path>\n");
printf("kill <sig> <tid> : sends signal <sig> to thread <tid>\n");
return 0;
}
+1
View File
@@ -8,6 +8,7 @@ int cmd_mkdir(int argc, char *argv[]);
int cmd_cat(int argc, char *argv[]);
int cmd_cd(int argc, char *argv[]);
int cmd_pwd(int argc, char *argv[]);
int cmd_kill(int argc, char *argv[]);
int cmd_help(int argc, char *argv[]);
int cmd_create_proc(int argc,char *argv[]);
typedef int(cmd_handler_proc)(int argc,char *argv[]);
+80
View File
@@ -0,0 +1,80 @@
/*
** Small test for signals handling
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <syscalls.h>
void sig_handler(int);
void install_handler(int);
int32 thread(void *);
void
sig_handler(int sig)
{
int i;
printf("sig_test (sig_handler): Received signal #%d...\n", sig);
printf("Counting for fun: ");
for (i=0; i<10; i++)
printf("%d ", i);
printf("\n");
}
void
install_handler(int sig)
{
struct sigaction newa;
struct sigaction olda;
memset(&newa, 0, sizeof(newa));
newa.sa_handler = sig_handler;
newa.sa_flags = SA_NOMASK | SA_RESTART;
if (sys_sigaction(sig, &newa, &olda) < 0) {
printf("Failed installing handler for sig #%d!\n", sig);
}
}
int32
thread(void *data)
{
printf("Started snoozing thread...\n");
while (1) {
if (snooze(1000000000L) == B_INTERRUPTED)
printf("sig_test (thread): snooze was interrupted!\n");
}
return 0;
}
int
main(int argc, char **argv)
{
int i;
printf("Installing signal handlers...\n");
for (i=1; i<=NSIG; i++)
install_handler(i);
printf("Spawning some threads...\n");
for (i=0; i<5; i++)
resume_thread(spawn_thread(thread, "sig_test aux thread", B_NORMAL_PRIORITY, NULL));
printf("Done. Entering sleep mode...\n");
while (1) {
if (sys_snooze(1000000000L) == B_INTERRUPTED)
// this never gets called as the syscall is always restarted
printf("sig_test (main): snooze was interrupted!\n");
}
return 0;
}