9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit d120ce85422a76ce88a6f9be7d5123bc42bb21b5
parent e17ee6612569013d56858cba4c0bb1d4d8d94ea7
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 25 Oct 2020 22:47:38 +0100

os9/proc: Add rfork()

Change-Id: I627931dd9348c0d212ca046b87702c30b7f9564f

Diffstat:
Msrc/os9/proc.c | 26++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/src/os9/proc.c b/src/os9/proc.c @@ -146,31 +146,21 @@ int rfork(int flags) { Task *tp, *parent; - int tid; tp = parent = task; - if ((flags & (RFPROC|RFMEM)) == RFPROC|RFMEM - || (flags & (RFNAMEG|RFCNAMEG)) == RFNAMEG|RFCNAMEG - || (flags & (RFFDG|RFCFDG)) == RFFDG|RFCFDG) { + if ((flags & (RFPROC|RFMEM)) == (RFPROC|RFMEM) + || (flags & (RFNAMEG|RFCNAMEG)) == (RFNAMEG|RFCNAMEG) + || (flags & (RFFDG|RFCFDG)) == (RFFDG|RFCFDG)) { errno = EINVAL; return -1; } if ((flags & RFPROC) != 0) { if ((tp = newslot()) == NULL) - return -1; - - for (tp = tasktab; tp < &tasktab[NR_TASKS]; ++tp) { - if (tp->mode == PDISABLED) - break; - } - - if (tp == &tasktab[NR_TASKS] || (tid = newtid()) < 0) { - errno = ENOMEM; - return -1; - } - tp->tid = tid; + goto enomem; + if ((tp->tid = newtid()) < 0) + goto enomem; incref(&parent->text->ref); tp->text = parent->text; @@ -215,4 +205,8 @@ rfork(int flags) } return (flags & RFPROC) ? tp->tid : 0; + +enomem: + errno = ENOMEM; + return -1; }