add support of pid caching
This commit is contained in:
parent
e6816bb0bd
commit
71a1502489
3 changed files with 16 additions and 8 deletions
|
@ -22,5 +22,8 @@
|
|||
/* support for section attributes */
|
||||
#define HAVE_SECTION_ATTRIBUTES 1
|
||||
|
||||
/* definition of an invalid pid */
|
||||
#define INVALID_PID 0
|
||||
|
||||
/* symbol prefix */
|
||||
#define __SYMBOL_PREFIX ""
|
||||
|
|
|
@ -40,6 +40,8 @@
|
|||
#include "warning.h"
|
||||
#include "syscall.h"
|
||||
|
||||
extern int __private_pid;
|
||||
|
||||
int
|
||||
_DEFUN (_fork, (),
|
||||
_NOARGS)
|
||||
|
@ -51,7 +53,7 @@ _DEFUN (_fork, (),
|
|||
if (ret < 0) {
|
||||
errno = -ret;
|
||||
ret = -1;
|
||||
}
|
||||
} else __private_pid = INVALID_PID;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -40,17 +40,20 @@
|
|||
#include "warning.h"
|
||||
#include "syscall.h"
|
||||
|
||||
int __private_pid = INVALID_PID;
|
||||
|
||||
int
|
||||
_DEFUN (_getpid, (),
|
||||
_NOARGS)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = SYSCALL0(__NR_getpid);
|
||||
if (ret < 0) {
|
||||
errno = -ret;
|
||||
ret = -1;
|
||||
if (__private_pid == INVALID_PID) {
|
||||
__private_pid = SYSCALL0(__NR_getpid);
|
||||
if (__private_pid < 0) {
|
||||
errno = -__private_pid;
|
||||
__private_pid = INVALID_PID;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
return __private_pid;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue