2017-08-11 02:01:55 +02:00
|
|
|
/*
|
|
|
|
* This file is part of Jehanne.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Giacomo Tesio <giacomo@tesio.it>
|
|
|
|
*
|
|
|
|
* Jehanne is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 2 of the License.
|
|
|
|
*
|
|
|
|
* Jehanne is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Jehanne. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <u.h>
|
|
|
|
#include <lib9.h>
|
|
|
|
|
|
|
|
/* verify that rwakeup returns 0 on Rendez that was timedout */
|
|
|
|
|
|
|
|
Rendez r;
|
|
|
|
QLock l;
|
|
|
|
int ready;
|
|
|
|
int verbose = 0;
|
|
|
|
|
|
|
|
int killerProc; /* pid, will kill the other processes if starved */
|
|
|
|
|
|
|
|
int
|
|
|
|
handletimeout(void *v, char *s)
|
|
|
|
{
|
|
|
|
/* just not exit, please */
|
|
|
|
if(strcmp(s, "timedout") == 0){
|
|
|
|
if(verbose)
|
|
|
|
print("%d: noted: %s\n", getpid(), s);
|
|
|
|
print("FAIL: %s timedout\n", argv0);
|
|
|
|
exits("FAIL");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
killKiller(void)
|
|
|
|
{
|
|
|
|
postnote(PNPROC, killerProc, "interrupt");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
stopAllAfter(int seconds)
|
|
|
|
{
|
|
|
|
int pid;
|
|
|
|
|
2019-11-28 02:35:52 +01:00
|
|
|
switch((pid = sys_rfork(RFMEM|RFPROC|RFNOWAIT)))
|
2017-08-11 02:01:55 +02:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if(verbose)
|
|
|
|
print("killer proc started: pid %d\n", getpid());
|
|
|
|
sleep(seconds * 1000);
|
|
|
|
postnote(PNGROUP, killerProc, "timedout");
|
|
|
|
if(verbose)
|
|
|
|
print("killer proc timedout: pid %d\n", getpid());
|
|
|
|
exits("FAIL");
|
|
|
|
case -1:
|
|
|
|
fprint(2, "%r\n");
|
2019-11-28 02:35:52 +01:00
|
|
|
exits("sys_rfork fails");
|
2017-08-11 02:01:55 +02:00
|
|
|
default:
|
|
|
|
killerProc = pid;
|
|
|
|
atexit(killKiller);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
int s, w;
|
|
|
|
|
|
|
|
ARGBEGIN{
|
|
|
|
}ARGEND;
|
|
|
|
|
2019-11-28 02:35:52 +01:00
|
|
|
sys_rfork(RFNOTEG|RFREND);
|
2017-08-11 02:01:55 +02:00
|
|
|
if (!atnotify(handletimeout, 1)){
|
|
|
|
fprint(2, "%r\n");
|
|
|
|
exits("atnotify fails");
|
|
|
|
}
|
|
|
|
|
|
|
|
r.l = &l;
|
|
|
|
|
|
|
|
stopAllAfter(30);
|
|
|
|
/* one process to sleep for 100ms */
|
2019-11-28 02:35:52 +01:00
|
|
|
switch((s = sys_rfork(RFMEM|RFPROC|RFNOWAIT)))
|
2017-08-11 02:01:55 +02:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
qlock(&l);
|
|
|
|
rsleept(&r, 100);
|
|
|
|
qunlock(&l);
|
|
|
|
ready = 1;
|
|
|
|
exits(nil);
|
|
|
|
break;
|
|
|
|
case -1:
|
2019-11-28 02:35:52 +01:00
|
|
|
print("sys_rfork: %r\n");
|
|
|
|
exits("sys_rfork fails");
|
2017-08-11 02:01:55 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
while(ready == 0)
|
|
|
|
;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* now, we try to wakeup a free Rendez */
|
|
|
|
qlock(&l);
|
|
|
|
if(rwakeup(&r) == 0){
|
|
|
|
qunlock(&l);
|
|
|
|
print("PASS\n");
|
|
|
|
exits("PASS");
|
|
|
|
}
|
2019-11-28 02:35:52 +01:00
|
|
|
if((s = sys_open(smprint("/proc/%d/ctl", s), OWRITE)) >= 0){
|
|
|
|
jehanne_write(s, "kill", 5);
|
|
|
|
sys_close(s);
|
2017-08-11 02:01:55 +02:00
|
|
|
}
|
2019-11-28 02:35:52 +01:00
|
|
|
if((w = sys_open(smprint("/proc/%d/ctl", w), OWRITE)) >= 0){
|
|
|
|
jehanne_write(s, "kill", 5);
|
|
|
|
sys_close(s);
|
2017-08-11 02:01:55 +02:00
|
|
|
}
|
|
|
|
print("FAIL\n");
|
|
|
|
exits("FAIL");
|
|
|
|
}
|