e576bb | 2002-10-11 | Martin Nilsson | |
|
aedfb1 | 2002-10-09 | Martin Nilsson | |
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | #include "global.h"
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #include "fdlib.h"
|
6e27c9 | 1998-02-19 | Fredrik Hübinette (Hubbe) | | #include "fd_control.h"
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | #include "svalue.h"
#include "interpret.h"
#include "stralloc.h"
|
06983f | 1996-09-22 | Fredrik Hübinette (Hubbe) | | #include "constants.h"
|
bb55f8 | 1997-03-16 | Fredrik Hübinette (Hubbe) | | #include "pike_macros.h"
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | #include "backend.h"
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | #include "pike_error.h"
|
a29e02 | 1996-10-15 | Fredrik Hübinette (Hubbe) | | #include "callback.h"
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #include "mapping.h"
#include "threads.h"
#include "signal_handler.h"
#include "module_support.h"
|
0d52dd | 1998-01-16 | Fredrik Hübinette (Hubbe) | | #include "operators.h"
#include "builtin_functions.h"
|
5f0624 | 1999-04-11 | Fredrik Hübinette (Hubbe) | | #include "main.h"
|
f01020 | 2011-11-16 | Tobias S. Josefowitz | | #include "time_stuff.h"
|
711287 | 2015-10-18 | Martin Nilsson | |
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | #include <signal.h>
|
711287 | 2015-10-18 | Martin Nilsson | | #include <errno.h>
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_PASSWD_H
# include <passwd.h>
#endif
#ifdef HAVE_GROUP_H
# include <group.h>
#endif
#ifdef HAVE_PWD_H
# include <pwd.h>
#endif
#ifdef HAVE_GRP_H
# include <grp.h>
#endif
|
857ea7 | 2000-08-17 | Henrik Grubbström (Grubba) | | #ifdef HAVE_SYS_ID_H
# include <sys/id.h>
#endif
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_WINBASE_H
#include <winbase.h>
#endif
|
bdfb86 | 1997-12-22 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_SYS_WAIT_H
|
15a436 | 1995-11-15 | Fredrik Hübinette (Hubbe) | | #include <sys/wait.h>
|
bdfb86 | 1997-12-22 | Fredrik Hübinette (Hubbe) | | #endif
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | |
|
cf2a15 | 1996-04-13 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
|
d4debf | 1997-05-19 | Henrik Grubbström (Grubba) | | #ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
|
51e884 | 2015-10-18 | Martin Nilsson | |
|
52ad0d | 1998-11-23 | Marcus Comstedt | | #ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
|
27205b | 2003-11-25 | Jonas Wallden | | #ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
|
bfd94e | 2000-10-18 | Henrik Grubbström (Grubba) | | #ifdef HAVE_POLL
#ifdef HAVE_POLL_H
#include <poll.h>
#endif /* HAVE_POLL_H */
#ifdef HAVE_SYS_POLL_H
#include <sys/poll.h>
#endif /* HAVE_SYS_POLL_H */
#endif /* HAVE_POLL */
|
62e3f5 | 2000-12-06 | Marcus Comstedt | | #ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
|
06dda5 | 2002-08-21 | Marcus Comstedt | | #ifdef HAVE_SYS_TERMIO_H
# include <sys/termio.h>
#endif
|
6abd86 | 2017-08-27 | Henrik Grubbström (Grubba) | | #ifdef HAVE_TERMIOS_H
# include <termios.h>
#elif defined(HAVE_SYS_TERMIOS_H)
|
06dda5 | 2002-08-21 | Marcus Comstedt | | # include <sys/termios.h>
#endif
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | #ifdef HAVE_SYS_PTRACE_H
#include <sys/ptrace.h>
#endif
|
d0d796 | 2005-12-02 | Henrik Grubbström (Grubba) | | #ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | | #ifdef HAVE_SYS_USER_H
|
fe2c20 | 2003-04-14 | Henrik Grubbström (Grubba) | |
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | | #include <sys/user.h>
#endif
|
0c9594 | 2018-01-12 | Stephen R. van den Berg | | #ifdef __amigaos__
#define timeval amigaos_timeval
#include <exec/types.h>
#include <dos/dos.h>
#include <dos/dostags.h>
#include <dos/exall.h>
#ifdef __amigaos4__
#include <interfaces/dos.h>
#include <inline4/dos.h>
#else
#include <clib/dos_protos.h>
#include <inline/dos.h>
#endif
#undef timeval
#endif
|
531c17 | 2002-05-11 | Martin Nilsson | | #define fp Pike_fp
|
52ad0d | 1998-11-23 | Marcus Comstedt | |
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | #ifdef NSIG
#define MAX_SIGNALS NSIG
#else
#define MAX_SIGNALS 256
|
15fafe | 1999-11-16 | Henrik Grubbström (Grubba) | | #define NSIG 256
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | #endif
#define SIGNAL_BUFFER 16384
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #define WAIT_BUFFER 4096
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | |
|
ae2cc6 | 1998-05-19 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_UNION_WAIT
#define WAITSTATUSTYPE union wait
#else
#define WAITSTATUSTYPE int
#endif
|
5096d7 | 1998-05-17 | Henrik Grubbström (Grubba) | | #ifndef WEXITSTATUS
#ifdef HAVE_UNION_WAIT
#define WEXITSTATUS(x) ((x).w_retcode)
#else /* !HAVE_UNION_WAIT */
#define WEXITSTATUS(x) (((x)>>8)&0xff)
#endif /* HAVE_UNION_WAIT */
#endif /* !WEXITSTATUS */
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | #ifndef WUNTRACED
#define WUNTRACED 0
#endif /* !WUNTRACED */
|
75c9d5 | 2003-03-01 | Henrik Grubbström (Grubba) | | #ifdef HAVE_PTRACE
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | *
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | | * ... and so does HPUX...
*
* And Solaris 2.9 and later don't name them at all...
*
* Requests 0 - 9 are standardized by AT&T/SVID as follows:
*
* PTRACE_TRACEME 0 Enter trace mode. Stop at exec() and signals.
* PTRACE_PEEKTEXT 1 Read a word from the text area.
* PTRACE_PEEKDATA 2 Read a word from the data area.
* PTRACE_PEEKUSER 3 Read a word from the user area.
* PTRACE_POKETEXT 4 Set a word in the text area.
* PTRACE_POKEDATA 5 Set a word in the data area.
* PTRACE_POKEUSER 6 Set a word in the user area.
* PTRACE_CONT 7 Continue process with specified signal.
* PTRACE_KILL 8 Exit process.
* PTRACE_SINGLESTEP 9 Execute a single instruction.
*
* NB: In Solaris 2.x ptrace() is simulated by libc.
|
75c9d5 | 2003-03-01 | Henrik Grubbström (Grubba) | | */
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | #ifndef PTRACE_TRACEME
#ifdef PT_TRACE_ME
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | |
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | #define PTRACE_TRACEME PT_TRACE_ME
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | | #elif defined(PT_SETTRC)
#define PTRACE_TRACEME PT_SETTRC
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | #else
#define PTRACE_TRACEME 0
#endif
#endif
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | | #ifndef PTRACE_PEEKUSER
#ifdef PT_READ_U
#define PTRACE_PEEKUSER PT_READ_U
#elif defined(PT_RUAREA)
#define PTRACE_PEEKUSER PT_RUAREA
#else
#define PTRACE_PEEKUSER 3
#endif
#endif
|
75c9d5 | 2003-03-01 | Henrik Grubbström (Grubba) | | #ifndef PTRACE_CONT
#ifdef PT_CONTINUE
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | |
|
75c9d5 | 2003-03-01 | Henrik Grubbström (Grubba) | | #define PTRACE_CONT PT_CONTINUE
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | | #elif defined(PT_CONTIN)
#define PTRACE_CONT PT_CONTIN
|
75c9d5 | 2003-03-01 | Henrik Grubbström (Grubba) | | #else
#define PTRACE_CONT 7
#endif
#endif
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | #ifndef PTRACE_KILL
#ifdef PT_KILL
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | |
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | #define PTRACE_KILL PT_KILL
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | | #elif defined(PT_EXIT)
#define PTRACE_KILL PT_EXIT
|
75c9d5 | 2003-03-01 | Henrik Grubbström (Grubba) | | #else
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | #define PTRACE_KILL 8
|
75c9d5 | 2003-03-01 | Henrik Grubbström (Grubba) | | #endif
#endif
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | | #ifndef PTRACE_TAKES_FOUR_ARGS
#define ptrace(R,P,A,D) ptrace(R,P,A,D,NULL)
#endif
|
d574b8 | 2003-03-27 | Henrik Grubbström (Grubba) | | #ifdef PTRACE_ADDR_TYPE_IS_POINTER
#define CAST_TO_PTRACE_ADDR(X) ((void *)(ptrdiff_t)(X))
#else /* !PTRACE_ADDR_TYPE_IS_POINTER */
#define CAST_TO_PTRACE_ADDR(X) ((ptrdiff_t)(X))
#endif /* PTRACE_ADDR_TYPE_IS_POINTER */
|
75c9d5 | 2003-03-01 | Henrik Grubbström (Grubba) | | #endif /* HAVE_PTRACE */
|
6465ab | 2002-04-26 | Henrik Grubbström (Grubba) | |
#ifndef PIKE_BADF_LIMIT
#define PIKE_BADF_LIMIT 1024
#endif /* !PIKE_BADF_LIMIT */
|
b73c45 | 2003-03-25 | Martin Nilsson | |
|
a9590d | 1998-04-21 | Henrik Grubbström (Grubba) | |
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | | #ifdef PROC_DEBUG
|
a91d9a | 2016-01-11 | Martin Nilsson | | #define PROC_FPRINTF(...) fprintf(stderr, __VA_ARGS__)
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | | #else
|
a91d9a | 2016-01-11 | Martin Nilsson | | #define PROC_FPRINTF(...)
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | | #endif /* PROC_DEBUG */
|
0c9594 | 2018-01-12 | Stephen R. van den Berg | | #if !defined(__NT__) && !defined(__amigaos__)
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | #define USE_PID_MAPPING
#else
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | #undef USE_WAIT_THREAD
#undef USE_SIGCHILD
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | #endif
|
3be550 | 1999-06-08 | Fredrik Hübinette (Hubbe) | | #if defined(USE_SIGCHILD) && defined(__linux__) && defined(_REENTRANT)
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | | #define NEED_SIGNAL_SAFE_FIFO
#endif
#ifndef NEED_SIGNAL_SAFE_FIFO
#ifdef DEBUG
#define SAFE_FIFO_DEBUG_BEGIN() do {\
static volatile int inside=0; \
if(inside) \
|
5aad93 | 2002-08-15 | Marcus Comstedt | | Pike_fatal("You need to define NEED_SIGNAL_SAFE_FIFO in signal_handler.c!\n"); \
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | | inside=1;
#define SAFE_FIFO_DEBUG_END() inside=0; }while(0)
|
45f2a2 | 2002-09-10 | Martin Nilsson | | #endif /* DEBUG */
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | |
|
fae26d | 2013-01-26 | Henrik Grubbström (Grubba) | | #define DECLARE_FIFO(pre,TYPE) \
static volatile TYPE PIKE_CONCAT(pre,buf) [SIGNAL_BUFFER]; \
static volatile int PIKE_CONCAT(pre,_first)=0,PIKE_CONCAT(pre,_last)=0; \
|
148616 | 2013-01-29 | Henrik Grubbström (Grubba) | | static inline int PIKE_CONCAT(pre,_pop)(TYPE *val) { \
|
fae26d | 2013-01-26 | Henrik Grubbström (Grubba) | | int tmp2 = PIKE_CONCAT(pre,_first); \
|
148616 | 2013-01-29 | Henrik Grubbström (Grubba) | | if(PIKE_CONCAT(pre,_last) != tmp2) { \
|
fae26d | 2013-01-26 | Henrik Grubbström (Grubba) | | int tmp; \
if( ++ PIKE_CONCAT(pre,_last) == SIGNAL_BUFFER) \
PIKE_CONCAT(pre,_last)=0; \
tmp = PIKE_CONCAT(pre,_last); \
|
148616 | 2013-01-29 | Henrik Grubbström (Grubba) | | *val = PIKE_CONCAT(pre,buf)[tmp]; \
return 1; \
|
fae26d | 2013-01-26 | Henrik Grubbström (Grubba) | | } \
|
148616 | 2013-01-29 | Henrik Grubbström (Grubba) | | return 0; \
|
fae26d | 2013-01-26 | Henrik Grubbström (Grubba) | | } \
\
static inline void PIKE_CONCAT(pre,_push)(TYPE val) { \
int tmp = PIKE_CONCAT(pre, _first) + 1; \
if (tmp >= SIGNAL_BUFFER) tmp = 0; \
PIKE_CONCAT(pre, buf)[tmp] = val; \
PIKE_CONCAT(pre, _first) = tmp; \
}
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | |
#define QUICK_CHECK_FIFO(pre,TYPE) ( PIKE_CONCAT(pre,_first) != PIKE_CONCAT(pre,_last) )
#define INIT_FIFO(pre,TYPE)
|
23c513 | 2017-10-03 | Per Cederqvist | | #define REINIT_FIFO(pre,TYPE)
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | |
|
45f2a2 | 2002-09-10 | Martin Nilsson | | #else /* NEED_SIGNAL_SAFE_FIFO */
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | |
|
fae26d | 2013-01-26 | Henrik Grubbström (Grubba) | | #define DECLARE_FIFO(pre,TYPE) \
static int PIKE_CONCAT(pre,_fd)[2]; \
static volatile sig_atomic_t PIKE_CONCAT(pre,_data_available); \
static inline int PIKE_CONCAT(pre, _pop)(TYPE *val) { \
PIKE_CONCAT(pre,_data_available) = 0; \
if (read(PIKE_CONCAT(pre,_fd)[0], val, sizeof(*val)) \
== sizeof(*val)) { \
/* NB: We must reset and set data_available here \
* to avoid races. */ \
PIKE_CONCAT(pre,_data_available) = 1; \
return 1; \
} \
return 0; \
} \
\
static inline void PIKE_CONCAT(pre, _push)(TYPE val) { \
int sz; \
int errno_save = errno; \
while( (sz = write(PIKE_CONCAT(pre,_fd)[1], (char *)&val, \
sizeof(val))) < 0 && \
errno==EINTR) \
; \
DO_IF_DEBUG(if (sz != sizeof(val)) \
Pike_fatal("Atomic pipe write failed!!\n"); ) \
errno = errno_save; \
PIKE_CONCAT(pre,_data_available)=1; \
}
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | |
#define QUICK_CHECK_FIFO(pre,TYPE) PIKE_CONCAT(pre,_data_available)
#define INIT_FIFO(pre,TYPE) do { \
if(pike_make_pipe(PIKE_CONCAT(pre,_fd)) <0) \
|
5aad93 | 2002-08-15 | Marcus Comstedt | | Pike_fatal("Couldn't create buffer " #pre ".\n"); \
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | | \
set_nonblocking(PIKE_CONCAT(pre,_fd)[0],1); \
set_nonblocking(PIKE_CONCAT(pre,_fd)[1],1); \
set_close_on_exec(PIKE_CONCAT(pre,_fd)[0], 1); \
set_close_on_exec(PIKE_CONCAT(pre,_fd)[1], 1); \
}while(0)
|
13670c | 2015-05-25 | Martin Nilsson | |
|
23c513 | 2017-10-03 | Per Cederqvist | | #define REINIT_FIFO(pre,TYPE) do { \
close(PIKE_CONCAT(pre,_fd)[0]); \
close(PIKE_CONCAT(pre,_fd)[1]); \
INIT_FIFO(pre,TYPE); \
} while(0)
|
45f2a2 | 2002-09-10 | Martin Nilsson | | #endif /* else NEED_SIGNAL_SAFE_FIFO */
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | |
#ifndef SAFE_FIFO_DEBUG_END
#define SAFE_FIFO_DEBUG_BEGIN() do {
#define SAFE_FIFO_DEBUG_END() }while(0)
#endif
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
0d7c54 | 2014-05-20 | Per Hedbor | |
#ifdef __GNUC__
#pragma GCC optimize "-Os"
#endif
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | extern int fd_from_object(struct object *o);
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | static int set_priority( int pid, char *to );
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | |
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | |
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | static struct svalue signal_callbacks[MAX_SIGNALS];
|
b88736 | 2013-01-27 | Henrik Grubbström (Grubba) | | static sig_atomic_t signal_masks[MAX_SIGNALS];
|
5f0624 | 1999-04-11 | Fredrik Hübinette (Hubbe) | | static void (*default_signals[MAX_SIGNALS])(INT32);
|
a29e02 | 1996-10-15 | Fredrik Hübinette (Hubbe) | | static struct callback *signal_evaluator_callback =0;
|
aec902 | 1999-06-12 | Henrik Grubbström (Grubba) | | DECLARE_FIFO(sig, unsigned char);
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | |
|
e51c9b | 1999-05-03 | Fredrik Hübinette (Hubbe) | | #ifdef USE_PID_MAPPING
static void report_child(int pid,
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | WAITSTATUSTYPE status,
const char *called_from);
|
e51c9b | 1999-05-03 | Fredrik Hübinette (Hubbe) | | #endif
#ifdef USE_SIGCHILD
static RETSIGTYPE receive_sigchild(int signum);
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | | typedef struct wait_data_s {
|
e51c9b | 1999-05-03 | Fredrik Hübinette (Hubbe) | | pid_t pid;
WAITSTATUSTYPE status;
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | | } wait_data;
|
aec902 | 1999-06-12 | Henrik Grubbström (Grubba) | | DECLARE_FIFO(wait, wait_data);
|
e51c9b | 1999-05-03 | Fredrik Hübinette (Hubbe) | |
|
45f2a2 | 2002-09-10 | Martin Nilsson | | #endif /* USE_SIGCHILD */
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | |
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | | #ifdef __NT__
#ifndef SIGKILL
#define SIGKILL 9
#endif
#endif /* __NT__ */
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | struct sigdesc
{
int signum;
char *signame;
};
|
eb5410 | 2004-06-23 | Martin Nilsson | | static const struct sigdesc signal_desc []={
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | #ifdef SIGHUP
{ SIGHUP, "SIGHUP" },
#endif
#ifdef SIGINT
{ SIGINT, "SIGINT" },
#endif
#ifdef SIGQUIT
{ SIGQUIT, "SIGQUIT" },
#endif
#ifdef SIGILL
{ SIGILL, "SIGILL" },
#endif
#ifdef SIGTRAP
{ SIGTRAP, "SIGTRAP" },
#endif
#ifdef SIGABRT
{ SIGABRT, "SIGABRT" },
#endif
#ifdef SIGIOT
{ SIGIOT, "SIGIOT" },
#endif
|
775f49 | 1998-01-18 | Henrik Grubbström (Grubba) | | #ifdef SIGEMT
{ SIGEMT, "SIGEMT" },
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | #endif
#ifdef SIGFPE
{ SIGFPE, "SIGFPE" },
#endif
#ifdef SIGKILL
{ SIGKILL, "SIGKILL" },
#endif
|
775f49 | 1998-01-18 | Henrik Grubbström (Grubba) | | #ifdef SIGBUS
{ SIGBUS, "SIGBUS" },
|
0e2fd0 | 1997-06-17 | Fredrik Hübinette (Hubbe) | | #endif
#ifdef SIGSEGV
{ SIGSEGV, "SIGSEGV" },
#endif
|
775f49 | 1998-01-18 | Henrik Grubbström (Grubba) | | #ifdef SIGSYS
{ SIGSYS, "SIGSYS" },
#endif
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | #ifdef SIGPIPE
{ SIGPIPE, "SIGPIPE" },
#endif
#ifdef SIGALRM
{ SIGALRM, "SIGALRM" },
#endif
#ifdef SIGTERM
{ SIGTERM, "SIGTERM" },
#endif
|
775f49 | 1998-01-18 | Henrik Grubbström (Grubba) | | #ifdef SIGUSR1
{ SIGUSR1, "SIGUSR1" },
#endif
#ifdef SIGUSR2
{ SIGUSR2, "SIGUSR2" },
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | #endif
#ifdef SIGCHLD
{ SIGCHLD, "SIGCHLD" },
#endif
#ifdef SIGCLD
{ SIGCLD, "SIGCLD" },
#endif
|
775f49 | 1998-01-18 | Henrik Grubbström (Grubba) | | #ifdef SIGPWR
{ SIGPWR, "SIGPWR" },
#endif
#ifdef SIGWINCH
{ SIGWINCH, "SIGWINCH" },
#endif
#ifdef SIGURG
{ SIGURG, "SIGURG" },
#endif
#ifdef SIGIO
{ SIGIO, "SIGIO" },
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | #endif
#ifdef SIGSTOP
{ SIGSTOP, "SIGSTOP" },
#endif
#ifdef SIGTSTP
{ SIGTSTP, "SIGTSTP" },
#endif
|
775f49 | 1998-01-18 | Henrik Grubbström (Grubba) | | #ifdef SIGCONT
{ SIGCONT, "SIGCONT" },
#endif
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | #ifdef SIGTSTP
{ SIGTSTP, "SIGTSTP" },
#endif
#ifdef SIGTTIN
{ SIGTTIN, "SIGTTIN" },
#endif
#ifdef SIGTTIO
{ SIGTTIO, "SIGTTIO" },
#endif
#ifdef SIGVTALRM
{ SIGVTALRM, "SIGVTALRM" },
#endif
#ifdef SIGPROF
{ SIGPROF, "SIGPROF" },
#endif
|
775f49 | 1998-01-18 | Henrik Grubbström (Grubba) | | #ifdef SIGXCPU
{ SIGXCPU, "SIGXCPU" },
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | #endif
|
775f49 | 1998-01-18 | Henrik Grubbström (Grubba) | | #ifdef SIGXFSZ
{ SIGXFSZ, "SIGXFSZ" },
#endif
#ifdef SIGSTKFLT
{ SIGSTKFLT, "SIGSTKFLT" },
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | #endif
#ifdef SIGPOLL
{ SIGPOLL, "SIGPOLL" },
#endif
#ifdef SIGLOST
{ SIGLOST, "SIGLOST" },
#endif
#ifdef SIGUNUSED
{ SIGUNUSED, "SIGUNUSED" },
#endif
|
775f49 | 1998-01-18 | Henrik Grubbström (Grubba) | | #ifdef SIGINFO
{ SIGINFO, "SIGINFO" },
#endif
#ifdef SIGMSG
{ SIGMSG, "SIGMSG" },
#endif
#ifdef SIGDANGER
{ SIGDANGER, "SIGDANGER" },
#endif
#ifdef SIGMIGRATE
{ SIGMIGRATE, "SIGMIGRATE" },
#endif
#ifdef SIGPRE
{ SIGPRE, "SIGPRE" },
#endif
#ifdef SIGVIRT
{ SIGVIRT, "SIGVIRT" },
#endif
#ifdef SIGALRM1
{ SIGALRM1, "SIGALRM1" },
#endif
#ifdef SIGWAITING
{ SIGWAITING, "SIGWAITING" },
#endif
#ifdef SIGKAP
{ SIGKAP, "SIGKAP" },
#endif
#ifdef SIGGRANT
{ SIGGRANT, "SIGGRANT" },
#endif
#ifdef SIGRETRACT
{ SIGRETRACT, "SIGRETRACT" },
#endif
#ifdef SIGSOUND
{ SIGSOUND, "SIGSOUND" },
#endif
#ifdef SIGSAK
{ SIGSAK, "SIGSAK" },
#endif
#ifdef SIGDIL
{ SIGDIL, "SIGDIL" },
#endif
#ifdef SIG32
{ SIG32, "SIG32" },
#endif
#ifdef SIGCKPT
{ SIGCKPT, "SIGCKPT" },
#endif
#ifdef SIGPTRESCHED
{ SIGPTRESCHED, "SIGPTRESCHED" },
#endif
|
17fde5 | 1998-05-09 | Henrik Grubbström (Grubba) | |
#ifndef _REENTRANT
|
775f49 | 1998-01-18 | Henrik Grubbström (Grubba) | | #ifdef SIGWAITING
{ SIGWAITING, "SIGWAITING" },
#endif
#ifdef SIGLWP
{ SIGLWP, "SIGLWP" },
#endif
#ifdef SIGCANCEL
{ SIGCANCEL, "SIGCANCEL" },
#endif
#endif /* !_REENTRANT */
#ifdef SIGFREEZE
{ SIGFREEZE, "SIGFREEZE" },
#endif
#ifdef SIGTHAW
{ SIGTHAW, "SIGTHAW" },
#endif
|
fac113 | 2001-09-28 | Tomas Nilsson | | #ifdef SIGBREAK
{ SIGBREAK, "SIGBREAK" },
#endif
|
775f49 | 1998-01-18 | Henrik Grubbström (Grubba) | |
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | { -1, "END" }
};
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | |
|
df7807 | 1999-06-10 | Fredrik Hübinette (Hubbe) | |
|
f62ab8 | 1999-06-25 | Fredrik Hübinette (Hubbe) | | #ifdef PIKE_DEBUG
|
df7807 | 1999-06-10 | Fredrik Hübinette (Hubbe) | |
|
955f5c | 1999-08-27 | Fredrik Hübinette (Hubbe) | | #define MY_MAX_PID 65536
char process_info[MY_MAX_PID];
|
df7807 | 1999-06-10 | Fredrik Hübinette (Hubbe) | | int last_pid_p;
int last_pids[4096];
#define P_NOT_STARTED 0
#define P_RUNNING 1
#define P_DONE 2
#define P_RUNNING_AGAIN 3
#define P_DONE_AGAIN 4
void dump_process_history(pid_t pid)
{
int e;
|
955f5c | 1999-08-27 | Fredrik Hübinette (Hubbe) | | if(pid < 1)
|
5aad93 | 2002-08-15 | Marcus Comstedt | | Pike_fatal("Pid out of range: %ld\n",(long)pid);
|
df7807 | 1999-06-10 | Fredrik Hübinette (Hubbe) | |
fprintf(stderr,"Process history:");
for(e=MAXIMUM(-4095,-last_pid_p);e<0;e++)
{
fprintf(stderr," %d",last_pids[ (last_pid_p + e) & 4095]);
}
|
955f5c | 1999-08-27 | Fredrik Hübinette (Hubbe) | | if(pid<MY_MAX_PID)
fprintf(stderr,"\nProblem pid = %d, status = %d\n",
(int)pid, process_info[pid]);
|
df7807 | 1999-06-10 | Fredrik Hübinette (Hubbe) | | }
void process_started(pid_t pid)
{
|
955f5c | 1999-08-27 | Fredrik Hübinette (Hubbe) | | if(pid < 1)
|
5aad93 | 2002-08-15 | Marcus Comstedt | | Pike_fatal("Pid out of range: %ld\n",(long)pid);
|
df7807 | 1999-06-10 | Fredrik Hübinette (Hubbe) | |
last_pids[last_pid_p++ & 4095]=pid;
|
48bfd1 | 1999-08-30 | Fredrik Hübinette (Hubbe) | | if(pid>=MY_MAX_PID)
|
955f5c | 1999-08-27 | Fredrik Hübinette (Hubbe) | | return;
|
df7807 | 1999-06-10 | Fredrik Hübinette (Hubbe) | | switch(process_info[pid])
{
case P_NOT_STARTED:
case P_DONE:
process_info[pid]++;
break;
case P_DONE_AGAIN:
process_info[pid]=P_RUNNING_AGAIN;
break;
default:
dump_process_history(pid);
|
5aad93 | 2002-08-15 | Marcus Comstedt | | Pike_fatal("Process debug: Pid %ld started without stopping! (status=%d)\n",(long)pid,process_info[pid]);
|
df7807 | 1999-06-10 | Fredrik Hübinette (Hubbe) | | }
}
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | void process_done(pid_t pid, const char *from)
|
df7807 | 1999-06-10 | Fredrik Hübinette (Hubbe) | | {
|
955f5c | 1999-08-27 | Fredrik Hübinette (Hubbe) | | if(pid < 1)
|
5aad93 | 2002-08-15 | Marcus Comstedt | | Pike_fatal("Pid out of range in %s: %ld\n",from,(long)pid);
|
955f5c | 1999-08-27 | Fredrik Hübinette (Hubbe) | |
|
48bfd1 | 1999-08-30 | Fredrik Hübinette (Hubbe) | | if(pid>=MY_MAX_PID)
|
955f5c | 1999-08-27 | Fredrik Hübinette (Hubbe) | | return;
|
df7807 | 1999-06-10 | Fredrik Hübinette (Hubbe) | | switch(process_info[pid])
{
case P_RUNNING:
case P_RUNNING_AGAIN:
process_info[pid]++;
break;
default:
|
948afd | 1999-07-16 | Fredrik Hübinette (Hubbe) | | #ifdef PROC_DEBUG
|
df7807 | 1999-06-10 | Fredrik Hübinette (Hubbe) | | dump_process_history(pid);
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] Process debug: Unknown child %ld in %s! (status=%d)\n",
getpid(), (long)pid,from,process_info[pid]);
|
948afd | 1999-07-16 | Fredrik Hübinette (Hubbe) | | #endif
|
2fafca | 1999-07-20 | Fredrik Hübinette (Hubbe) | | break;
|
df7807 | 1999-06-10 | Fredrik Hübinette (Hubbe) | | }
}
#else
|
74dfe8 | 2012-12-30 | Jonas Walldén | | void process_started(pid_t UNUSED(pid)) { }
void process_done(pid_t UNUSED(pid), const char *UNUSED(from)) { }
|
df7807 | 1999-06-10 | Fredrik Hübinette (Hubbe) | |
|
45f2a2 | 2002-09-10 | Martin Nilsson | | #endif /* PIKE_DEBUG */
|
df7807 | 1999-06-10 | Fredrik Hübinette (Hubbe) | |
|
e51c9b | 1999-05-03 | Fredrik Hübinette (Hubbe) | | static void register_signal(int signum)
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | {
|
fae26d | 2013-01-26 | Henrik Grubbström (Grubba) | | sig_push(signum);
|
e51c9b | 1999-05-03 | Fredrik Hübinette (Hubbe) | | wake_up_backend();
}
static RETSIGTYPE receive_signal(int signum)
{
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | | SAFE_FIFO_DEBUG_BEGIN();
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | if ((signum < 0) || (signum >= MAX_SIGNALS)) {
#ifdef SIGCHLD
signum = SIGCHLD;
#else
signum = 0;
#endif
}
|
e51c9b | 1999-05-03 | Fredrik Hübinette (Hubbe) | | register_signal(signum);
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | | SAFE_FIFO_DEBUG_END();
|
e51c9b | 1999-05-03 | Fredrik Hübinette (Hubbe) | | #ifdef SIGNAL_ONESHOT
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | my_signal(signum, receive_signal);
#endif
}
|
cd8352 | 1998-02-02 | Fredrik Hübinette (Hubbe) | | void my_signal(int sig, sigfunctype fun)
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | {
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] my_signal(%d, 0x%p)\n", getpid(), sig, (void *)fun);
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_SIGACTION
{
struct sigaction action;
|
17fde5 | 1998-05-09 | Henrik Grubbström (Grubba) | |
|
21b12a | 2014-09-03 | Martin Nilsson | | memset(&action, 0, sizeof(action));
|
17fde5 | 1998-05-09 | Henrik Grubbström (Grubba) | | action.sa_handler = fun;
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | sigfillset(&action.sa_mask);
|
17fde5 | 1998-05-09 | Henrik Grubbström (Grubba) | | action.sa_flags = 0;
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | #ifdef SA_INTERRUPT
|
6307e0 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | if(fun != SIG_IGN)
|
17fde5 | 1998-05-09 | Henrik Grubbström (Grubba) | | action.sa_flags |= SA_INTERRUPT;
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | #endif
|
17fde5 | 1998-05-09 | Henrik Grubbström (Grubba) | | sigaction(sig, &action, NULL);
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | }
#else
#ifdef HAVE_SIGVEC
{
struct sigvec action;
|
21b12a | 2014-09-03 | Martin Nilsson | | memset(&action, 0, sizeof(action));
|
6307e0 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | action.sv_handler= fun;
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | action.sv_mask=-1;
|
17fde5 | 1998-05-09 | Henrik Grubbström (Grubba) | | #ifdef SV_INTERRUPT
|
6307e0 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | if(fun != SIG_IGN)
action.sv_flags=SV_INTERRUPT;
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | #endif
sigvec(sig,&action,0);
}
#else
|
04554a | 1997-04-10 | Fredrik Hübinette (Hubbe) | | signal(sig, fun);
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | #endif
#endif
}
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
74dfe8 | 2012-12-30 | Jonas Walldén | | PMOD_EXPORT void check_signals(struct callback *UNUSED(foo), void *UNUSED(bar), void *UNUSED(gazonk))
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | {
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | #ifdef PIKE_DEBUG
if(d_flag>5) do_debug();
#endif
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
|
b88736 | 2013-01-27 | Henrik Grubbström (Grubba) | | if (QUICK_CHECK_FIFO(sig, unsigned char))
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | {
|
fae26d | 2013-01-26 | Henrik Grubbström (Grubba) | | unsigned char sig = ~0;
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
fae26d | 2013-01-26 | Henrik Grubbström (Grubba) | | while (sig_pop(&sig)) {
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
e51c9b | 1999-05-03 | Fredrik Hübinette (Hubbe) | | #ifdef USE_SIGCHILD
|
fae26d | 2013-01-26 | Henrik Grubbström (Grubba) | | if(sig == SIGCHLD)
{
wait_data wd;
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | |
|
fae26d | 2013-01-26 | Henrik Grubbström (Grubba) | | while (wait_pop(&wd)) {
if(!wd.pid)
Pike_fatal("wd.pid=0 NEED_SIGNAL_SAFE_FIFO is "
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | | #ifndef NEED_SIGNAL_SAFE_FIFO
|
fae26d | 2013-01-26 | Henrik Grubbström (Grubba) | | "not "
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | | #endif
|
fae26d | 2013-01-26 | Henrik Grubbström (Grubba) | | "defined.\n");
report_child(wd.pid, wd.status, "check_signals");
}
}
|
eaf8b9 | 1998-07-15 | Fredrik Hübinette (Hubbe) | | #endif
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
a03cc4 | 2013-02-06 | Henrik Grubbström (Grubba) | | #if MAX_SIGNALS < 256
if (sig >= MAX_SIGNALS) continue;
#endif
|
b88736 | 2013-01-27 | Henrik Grubbström (Grubba) | | if (!signal_masks[sig]) {
signal_masks[sig] = 1;
do {
if(SAFE_IS_ZERO(signal_callbacks + sig))
{
if(default_signals[sig])
default_signals[sig](sig);
} else {
JMP_BUF recovery;
free_svalue(&throw_value);
mark_free_svalue(&throw_value);
if (SETJMP_SP(recovery, 0)) {
call_handle_error();
} else {
push_svalue(signal_callbacks + sig);
push_int(sig);
f_call_function(2);
pop_stack();
}
UNSETJMP(recovery);
}
} while (--signal_masks[sig]);
|
18c1c0 | 2013-01-20 | Henrik Grubbström (Grubba) | | } else {
|
b88736 | 2013-01-27 | Henrik Grubbström (Grubba) | |
signal_masks[sig] = 2;
|
18c1c0 | 2013-01-20 | Henrik Grubbström (Grubba) | | }
}
|
7faf3c | 1998-06-17 | Fredrik Noring | | }
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | }
|
ba89b7 | 1998-05-05 | Marcus Comstedt | |
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
static char *signame(int sig)
{
int e;
for(e=0;e<(int)NELEM(signal_desc)-1;e++)
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | {
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | if(sig==signal_desc[e].signum)
return signal_desc[e].signame;
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | }
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | return 0;
}
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
static int signum(char *name)
{
int e;
for(e=0;e<(int)NELEM(signal_desc)-1;e++)
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | {
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | if(!STRCASECMP(name,signal_desc[e].signame) ||
!STRCASECMP(name,signal_desc[e].signame+3) )
return signal_desc[e].signum;
}
return -1;
}
|
1bb661 | 2012-07-30 | Chris Angelico | | |
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *!
*! Trap signals.
*!
*! This function allows you to trap a signal and have a function called
*! when the process receives a signal. Although it IS possible to trap
|
1bb661 | 2012-07-30 | Chris Angelico | | *! SIGBUS, SIGSEGV etc, I advise you not to; Pike should not receive any
*! such signals, and if it does, it is because of bugs in the Pike
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *! interpreter. And all bugs should be reported, no matter how trifle.
*!
*! The callback will receive the signal number as its only argument.
*!
*! See the documentation for @[kill()] for a list of signals.
*!
*! If no second argument is given, the signal handler for that signal
*! is restored to the default handler.
*!
*! If the second argument is zero, the signal will be completely ignored.
*!
|
1bb661 | 2012-07-30 | Chris Angelico | | *! @returns
*! Returns the previous signal function, or 0 if none had been registered.
*!
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @seealso
*! @[kill()], @[signame()], @[signum()]
*/
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | static void f_signal(int args)
{
int signum;
sigfunctype func;
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] f_signal(%d)\n", getpid(), args);
|
c0110f | 2003-08-20 | Henrik Grubbström (Grubba) | |
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | check_signals(0,0,0);
if(args < 1)
|
06bd61 | 2016-01-26 | Martin Nilsson | | SIMPLE_WRONG_NUM_ARGS_ERROR("signal", 1);
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(Pike_sp[-args]) != PIKE_T_INT)
|
f98274 | 2016-01-26 | Martin Nilsson | | SIMPLE_ARG_TYPE_ERROR("signal", 1, "int");
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | signum=Pike_sp[-args].u.integer;
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | if(signum <0 ||
signum >=MAX_SIGNALS
)
{
|
7db339 | 2017-03-07 | Martin Nilsson | | Pike_error("Signal %d out of range.\n", signum);
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | }
if(!signal_evaluator_callback)
{
signal_evaluator_callback=add_to_callback(&evaluator_callbacks,
check_signals,
0,0);
|
424d9c | 1999-05-02 | Fredrik Hübinette (Hubbe) | | dmalloc_accept_leak(signal_evaluator_callback);
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | }
if(args == 1)
{
push_int(0);
args++;
switch(signum)
{
|
e51c9b | 1999-05-03 | Fredrik Hübinette (Hubbe) | | #ifdef USE_SIGCHILD
|
5f0624 | 1999-04-11 | Fredrik Hübinette (Hubbe) | | case SIGCHLD:
func=receive_sigchild;
break;
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | #endif
|
13670c | 2015-05-25 | Martin Nilsson | |
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | #ifdef SIGPIPE
|
5f0624 | 1999-04-11 | Fredrik Hübinette (Hubbe) | | case SIGPIPE:
func=(sigfunctype) SIG_IGN;
break;
|
061ca9 | 1999-04-01 | Fredrik Hübinette (Hubbe) | | #endif
|
13670c | 2015-05-25 | Martin Nilsson | |
|
5f0624 | 1999-04-11 | Fredrik Hübinette (Hubbe) | | default:
if(default_signals[signum])
func=receive_signal;
else
func=(sigfunctype) SIG_DFL;
|
061ca9 | 1999-04-01 | Fredrik Hübinette (Hubbe) | | break;
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | }
} else {
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | if(SAFE_IS_ZERO(Pike_sp+1-args))
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | {
|
5f0624 | 1999-04-11 | Fredrik Hübinette (Hubbe) | |
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | func=(sigfunctype) SIG_IGN;
}else{
func=receive_signal;
|
e51c9b | 1999-05-03 | Fredrik Hübinette (Hubbe) | | #ifdef USE_SIGCHILD
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | if(signum == SIGCHLD)
func=receive_sigchild;
#endif
}
}
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | assign_svalue(Pike_sp-args,signal_callbacks+signum);
assign_svalue(signal_callbacks + signum, Pike_sp+1-args);
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | my_signal(signum, func);
|
c6e0d3 | 2000-03-07 | Fredrik Hübinette (Hubbe) | | pop_n_elems(args-1);
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | }
|
5f0624 | 1999-04-11 | Fredrik Hübinette (Hubbe) | | void set_default_signal_handler(int signum, void (*func)(INT32))
{
|
9f516a | 2001-12-16 | Martin Stjernholm | | int is_on=!!SAFE_IS_ZERO(signal_callbacks+signum);
|
5f0624 | 1999-04-11 | Fredrik Hübinette (Hubbe) | | int want_on=!!func;
default_signals[signum]=func;
if(is_on!=want_on)
my_signal(signum, want_on ? receive_signal : (sigfunctype) SIG_DFL);
}
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | |
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | static void f_signum(int args)
{
int i;
if(args < 1)
|
06bd61 | 2016-01-26 | Martin Nilsson | | SIMPLE_WRONG_NUM_ARGS_ERROR("signum", 1);
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(Pike_sp[-args]) != T_STRING)
|
f98274 | 2016-01-26 | Martin Nilsson | | SIMPLE_ARG_TYPE_ERROR("signum", 1, "string");
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | i=signum(Pike_sp[-args].u.string->str);
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | pop_n_elems(args);
push_int(i);
}
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | |
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | static void f_signame(int args)
{
char *n;
if(args < 1)
|
06bd61 | 2016-01-26 | Martin Nilsson | | SIMPLE_WRONG_NUM_ARGS_ERROR("signame", 1);
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(Pike_sp[-args]) != PIKE_T_INT)
|
f98274 | 2016-01-26 | Martin Nilsson | | SIMPLE_ARG_TYPE_ERROR("signame", 1, "int");
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | n=signame(Pike_sp[-args].u.integer);
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | pop_n_elems(args);
if(n)
|
2d1a3e | 2003-12-06 | Martin Nilsson | | push_text(n);
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | else
push_int(0);
}
|
ef2407 | 2009-04-22 | Henrik Grubbström (Grubba) | |
#ifdef PIKE_USE_FORKD
static int forkd_fd = -1;
void forkd(int fd)
{
struct msghdr msg;
struct iovec iov;
char cmsgbuf[CMSG_LEN(sizeof(int))];
char buf;
int i;
int num_fail = 0;
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_flags = 0;
if (fd != 3) {
do {
i = dup2(fd, 3);
|
0d7c54 | 2014-05-20 | Per Hedbor | | } while (UNLIKELY(i < 0) && UNLIKELY((errno == EINTR) || (errno == EBUSY)));
|
ef2407 | 2009-04-22 | Henrik Grubbström (Grubba) | | if (i < 0) {
write(2, "FORKD: Failed to dup fd!\n", 25);
_exit(0);
}
fd = 3;
}
for (i = 4; num_fail < PIKE_BADF_LIMIT; i++) {
int j;
do {
j = close(i);
|
0d7c54 | 2014-05-20 | Per Hedbor | | } while (UNLIKELY(j < 0) && UNLIKELY(errno == EINTR));
|
b0a1a9 | 2012-12-02 | Peter Bortas | | if ((j < 0) && (errno == EBADF)) num_fail++;
|
ef2407 | 2009-04-22 | Henrik Grubbström (Grubba) | | }
while (1) {
int i;
struct cmsghdr *cmsg;
msg.msg_control = cmsgbuf;
msg.msg_controllen = sizeof(cmsgbuf);
iov.iov_base = &buf;
iov.iov_len = 1;
do {
i = recvmsg(fd, &msg, 0);
|
0d7c54 | 2014-05-20 | Per Hedbor | | } while (UNLIKELY(i < 0) && UNLIKELY(errno == EINTR));
|
ef2407 | 2009-04-22 | Henrik Grubbström (Grubba) | | if (!i) _exit(0);
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
int ctrl_fd = NULL;
if ((cmsg->cmsg_level != SOL_SOCKET) ||
(cmsg->cmsg_type != SCM_RIGHTS) ||
(cmsg->cmsg_len != CMSG_LEN(sizeof(int)))) {
continue;
}
ctrl_fd = ((int *)CMSG_DATA(cmsg))[0];
num_fds = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int);
do {
i = fork();
|
0d7c54 | 2014-05-20 | Per Hedbor | | } while (UNLIKELY(i < 0) && UNLIKELY(errno == EINTR));
|
ef2407 | 2009-04-22 | Henrik Grubbström (Grubba) | | if (i < 0) {
} else if (i) {
} else {
forkd_child(ctrl_fd);
}
do {
i = close(ctrl_fd);
|
0d7c54 | 2014-05-20 | Per Hedbor | | } while (UNLIKELY(i < 0) && UNLIKELY(errno == EINTR));
|
ef2407 | 2009-04-22 | Henrik Grubbström (Grubba) | | }
}
}
#endif
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
acff29 | 2003-03-25 | Henrik Grubbström (Grubba) | |
#if defined(HAVE_WAIT4) && defined(HAVE_WAITPID) && defined(__FreeBSD__)
#undef HAVE_WAITPID
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | #endif
|
ae2cc6 | 1998-05-19 | Fredrik Hübinette (Hubbe) | |
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_WAITPID
|
acff29 | 2003-03-25 | Henrik Grubbström (Grubba) | | #define WAITPID(PID,STATUS,OPT) waitpid((PID), (STATUS), (OPT))
#define MY_WAIT_ANY(STATUS,OPT) waitpid(-1, (STATUS), (OPT))
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | #else
|
acff29 | 2003-03-25 | Henrik Grubbström (Grubba) | | #ifdef HAVE_WAIT4
#define WAITPID(PID,STATUS,OPT) wait4((PID), (STATUS), (OPT), 0)
#define MY_WAIT_ANY(STATUS,OPT) wait4(0, (STATUS), (OPT), 0)
#else
#define WAITPID(PID,STATUS,OPT) -1
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_WAIT3
|
acff29 | 2003-03-25 | Henrik Grubbström (Grubba) | | #define MY_WAIT_ANY(STATUS,OPT) wait3((STATUS), (OPT), 0)
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | #else
|
acff29 | 2003-03-25 | Henrik Grubbström (Grubba) | | #define MY_WAIT_ANY(STATUS,OPT) ((errno=ENOTSUP), -1)
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #endif
#endif
#endif
|
b3cc13 | 1998-01-15 | Fredrik Hübinette (Hubbe) | |
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
d3c5f4 | 1999-03-10 | Fredrik Hübinette (Hubbe) | | #ifdef USE_SIGCHILD
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | |
|
b6722b | 2014-07-03 | Arne Goedeke | | #ifdef SIGNAL_ONESHOT
static RETSIGTYPE receive_sigchild(int signum)
#else
|
dffabf | 2014-02-24 | Per Hedbor | | static RETSIGTYPE receive_sigchild(int UNUSED(signum))
|
b6722b | 2014-07-03 | Arne Goedeke | | #endif
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | {
pid_t pid;
WAITSTATUSTYPE status;
|
11c2a2 | 2014-09-17 | Tobias S. Josefowitz | | int masked_errno = errno;
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | |
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] receive_sigchild\n", getpid());
|
4c4a74 | 2002-12-18 | Martin Stjernholm | |
|
80d770 | 2013-01-01 | Henrik Grubbström (Grubba) | | #ifdef SIGNAL_ONESHOT
my_signal(signum, receive_sigchild);
#endif
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | | SAFE_FIFO_DEBUG_BEGIN();
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | try_reap_again:
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | pid=MY_WAIT_ANY(&status, WNOHANG|WUNTRACED);
|
13670c | 2015-05-25 | Martin Nilsson | |
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | if(pid>0)
{
|
fae26d | 2013-01-26 | Henrik Grubbström (Grubba) | | wait_data wd;
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | |
|
c6196a | 2009-07-23 | Henrik Grubbström (Grubba) | | #ifdef __CHECKER__
|
21b12a | 2014-09-03 | Martin Nilsson | | memset(&wd, 0, sizeof(wd));
|
c6196a | 2009-07-23 | Henrik Grubbström (Grubba) | | #endif
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] receive_sigchild got pid %d\n",
getpid(), pid);
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | |
|
fae26d | 2013-01-26 | Henrik Grubbström (Grubba) | | wd.pid=pid;
wd.status=status;
wait_push(wd);
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | | goto try_reap_again;
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | }
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] receive_sigchild: No more dead children.\n",
getpid());
|
e51c9b | 1999-05-03 | Fredrik Hübinette (Hubbe) | | register_signal(SIGCHLD);
|
4743f8 | 1999-06-02 | Fredrik Hübinette (Hubbe) | |
SAFE_FIFO_DEBUG_END();
|
11c2a2 | 2014-09-17 | Tobias S. Josefowitz | |
errno = masked_errno;
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | }
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #endif
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | |
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | #define PROCESS_UNKNOWN -1
#define PROCESS_RUNNING 0
#define PROCESS_STOPPED 1
#define PROCESS_EXITED 2
|
42c95b | 2003-03-03 | Henrik Grubbström (Grubba) | |
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | #define PROCESS_FLAG_TRACED 0x01
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | |
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #undef THIS
|
60d987 | 2000-03-23 | Fredrik Hübinette (Hubbe) | | #define THIS ((struct pid_status *)CURRENT_STORAGE)
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | |
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | #ifdef USE_PID_MAPPING
static struct mapping *pid_mapping=0;
#endif
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | struct pid_status
{
|
099503 | 2011-09-08 | Henrik Grubbström (Grubba) | | INT_TYPE pid;
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #ifdef __NT__
HANDLE handle;
|
15f49f | 2020-02-13 | Henrik Grubbström (Grubba) | | struct pid_status *next_pty_client;
struct my_pty *pty;
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #else
|
099503 | 2011-09-08 | Henrik Grubbström (Grubba) | | INT_TYPE sig;
INT_TYPE flags;
INT_TYPE state;
INT_TYPE result;
|
2fc55f | 2006-12-27 | Henrik Grubbström (Grubba) | | struct svalue callback;
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #endif
};
static struct program *pid_status_program=0;
|
74dfe8 | 2012-12-30 | Jonas Walldén | | static void init_pid_status(struct object *UNUSED(o))
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | {
THIS->pid=-1;
#ifdef __NT__
|
bd6739 | 2015-10-14 | Martin Nilsson | | THIS->handle = INVALID_HANDLE_VALUE;
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #else
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | THIS->sig=0;
THIS->flags=0;
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | THIS->state=PROCESS_UNKNOWN;
THIS->result=-1;
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | SET_SVAL(THIS->callback, T_INT, NUMBER_NUMBER, integer, 0);
|
bdfb86 | 1997-12-22 | Fredrik Hübinette (Hubbe) | | #endif
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | | }
|
15f49f | 2020-02-13 | Henrik Grubbström (Grubba) | | #ifdef __NT__
struct pid_status *pid_status_unlink_pty(struct pid_status *pid)
{
struct pid_status *ret;
if (!pid) return NULL;
ret = pid->next_pty_client;
pid->next_pty_client = NULL;
if (pid->pty) {
free_pty(pid->pty);
pid->pty = NULL;
}
return ret;
}
static void pid_status_link_pty(struct pid_status *pid, struct my_pty *pty)
{
add_ref(pty);
pid->pty = pty;
pid->next_pty_client = pty->clients;
pty->clients = pid;
}
int check_pty_clients(struct my_pty *pty)
{
struct pid_status *pid;
while ((pid = pty->clients)) {
DWORD status;
if ((pid->pid == -1) && (pid->handle == INVALID_HANDLE_VALUE)) return 1;
if (GetExitCodeProcess(pid->handle, &status) &&
(status == STILL_ACTIVE)) {
return 1;
}
pty->clients = pid_status_unlink_pty(pid);
}
return 0;
}
#endif /* __NT__ */
|
74dfe8 | 2012-12-30 | Jonas Walldén | | static void exit_pid_status(struct object *UNUSED(o))
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | {
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | #ifdef USE_PID_MAPPING
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | if(pid_mapping)
{
struct svalue key;
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | SET_SVAL(key, PIKE_T_INT, NUMBER_NUMBER, integer, THIS->pid);
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | map_delete(pid_mapping, &key);
}
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | #endif
#ifdef __NT__
|
15f49f | 2020-02-13 | Henrik Grubbström (Grubba) | | if (THIS->pty) {
struct my_pty *pty = THIS->pty;
|
d59f12 | 2020-02-13 | Henrik Grubbström (Grubba) | | struct pid_status **pidptr = &pty->clients;
|
15f49f | 2020-02-13 | Henrik Grubbström (Grubba) | | while (*pidptr && (*pidptr != THIS)) {
pidptr = &(*pidptr)->next_pty_client;
}
if (*pidptr) {
*pidptr = pid_status_unlink_pty(THIS);
}
|
d59f12 | 2020-02-13 | Henrik Grubbström (Grubba) | | if (!pty->clients && !pty->other && pty->conpty) {
Pike_NT_ClosePseudoConsole(pty->conpty);
pty->conpty = 0;
}
|
15f49f | 2020-02-13 | Henrik Grubbström (Grubba) | | }
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | CloseHandle(THIS->handle);
#endif
}
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | |
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | #ifdef USE_PID_MAPPING
|
74dfe8 | 2012-12-30 | Jonas Walldén | | static void call_pid_status_callback(struct callback *cb, void *pid, void *UNUSED(arg))
|
2fc55f | 2006-12-27 | Henrik Grubbström (Grubba) | | {
struct object *o = pid;
struct pid_status *p;
remove_callback(cb);
if (!o) return;
|
13b5ed | 2014-05-26 | Per Hedbor | | if(!(p=get_storage(o, pid_status_program))) {
|
2fc55f | 2006-12-27 | Henrik Grubbström (Grubba) | | free_object(o);
return;
}
push_object(o);
safe_apply_svalue(&p->callback, 1, 1);
pop_stack();
}
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | static void report_child(int pid,
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | WAITSTATUSTYPE status,
const char *from)
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | {
|
53acc2 | 1999-05-24 | Henrik Grubbström (Grubba) | |
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] report_child(%d, %d, \"%s\")\n",
getpid(), (int)pid, *(int *) &status, from);
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | |
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | if (!WIFSTOPPED(status)) {
process_done(pid, from);
}
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | if(pid_mapping)
{
struct svalue *s, key;
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | SET_SVAL(key, PIKE_T_INT, NUMBER_NUMBER, integer, pid);
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | if((s=low_mapping_lookup(pid_mapping, &key)))
{
|
2fc55f | 2006-12-27 | Henrik Grubbström (Grubba) | | struct pid_status *p = NULL;
int call_callback = 0;
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(*s) == T_OBJECT)
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | {
|
2fc55f | 2006-12-27 | Henrik Grubbström (Grubba) | | struct object *o;
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] Found pid object for pid %d: %p\n",
getpid(), (int)pid, s->u.object);
|
13b5ed | 2014-05-26 | Per Hedbor | | if((p=get_storage((o = s->u.object),
pid_status_program)))
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | {
|
2fc55f | 2006-12-27 | Henrik Grubbström (Grubba) | | if (!SAFE_IS_ZERO(&p->callback)) {
add_ref(o);
add_to_callback(&evaluator_callbacks, call_pid_status_callback,
o, NULL);
|
13f8cb | 2009-03-30 | Per Hedbor | | wake_up_backend();
|
2fc55f | 2006-12-27 | Henrik Grubbström (Grubba) | | }
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | if(WIFSTOPPED(status)) {
p->sig = WSTOPSIG(status);
p->state = PROCESS_STOPPED;
|
b4b3a8 | 2015-07-31 | Martin Nilsson | |
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | |
return;
|
5096d7 | 1998-05-17 | Henrik Grubbström (Grubba) | | } else {
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | if(WIFEXITED(status)) {
p->result = WEXITSTATUS(status);
} else {
if (WIFSIGNALED(status)) {
|
374576 | 2007-06-17 | Martin Stjernholm | | #if 0
|
940a4b | 2005-05-25 | Henrik Grubbström (Grubba) | | if (WTERMSIG(status) != 9) {
fprintf(stderr, "Process %d died of signal %d.\n",
pid, WTERMSIG(status));
}
|
374576 | 2007-06-17 | Martin Stjernholm | | #endif
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | p->sig = WTERMSIG(status);
|
940a4b | 2005-05-25 | Henrik Grubbström (Grubba) | | } else {
|
35e115 | 2016-02-07 | Martin Nilsson | | DWERR("Process %d died of strange cause 0x%08lx.\n",
pid, (unsigned long)status);
}
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | p->result=-1;
}
p->state = PROCESS_EXITED;
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] Pid %d has exited\n",
getpid(), (int)pid);
|
5096d7 | 1998-05-17 | Henrik Grubbström (Grubba) | | }
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | }
}
|
77a2e8 | 1999-04-23 | Henrik Grubbström (Grubba) | | |
8822ff | 2002-12-18 | Martin Stjernholm | | *
* But that will only happen if there isn't a proper pid status
* object in the value, i.e. either a destructed object or
* garbage that shouldn't be in the mapping to begin with. /mast
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | *
* Now when we wait(2) with WUNTRACED, there are cases
* when we want to keep the entry. This is currently
* achieved with the return above.
* /grubba 2003-02-28
|
2fc55f | 2006-12-27 | Henrik Grubbström (Grubba) | | *
* Note that this also invalidates s (and p unless we have added
* extra references to the object).
* /grubba 2006-12-27
|
77a2e8 | 1999-04-23 | Henrik Grubbström (Grubba) | | */
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | map_delete(pid_mapping, &key);
|
f09777 | 1999-01-07 | Fredrik Hübinette (Hubbe) | | }else{
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] report_child on unknown child: %d,%d\n",
getpid(),pid,status);
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | }
}
}
|
bdfb86 | 1997-12-22 | Fredrik Hübinette (Hubbe) | | #endif
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | |
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | #ifdef USE_WAIT_THREAD
|
b4b3a8 | 2015-07-31 | Martin Nilsson | | static COND_T process_status_change;
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | static COND_T start_wait_thread;
|
74ea78 | 2016-01-29 | Martin Nilsson | | static PIKE_MUTEX_T wait_thread_mutex;
|
eecd3d | 2003-11-21 | Henrik Grubbström (Grubba) | | static int wait_thread_running = 0;
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | static void do_da_lock(void)
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | {
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] fork: getting the lock.\n", getpid());
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | |
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | mt_lock(&wait_thread_mutex);
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | |
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] fork: got the lock.\n", getpid());
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | }
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | static void do_bi_do_da_lock(void)
{
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] wait thread: This is your wakeup call!\n",
getpid());
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | |
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | co_signal(&start_wait_thread);
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | |
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] fork: releasing the lock.\n", getpid());
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | |
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | mt_unlock(&wait_thread_mutex);
}
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
74dfe8 | 2012-12-30 | Jonas Walldén | | static TH_RETURN_TYPE wait_thread(void *UNUSED(data))
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | {
|
71ac9e | 1999-08-29 | Fredrik Hübinette (Hubbe) | | if(th_atfork(do_da_lock,do_bi_do_da_lock,0))
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | {
perror("pthread atfork");
exit(1);
}
|
fb4549 | 2014-05-20 | Per Hedbor | |
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | while(1)
{
WAITSTATUSTYPE status;
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | int pid;
|
42c95b | 2003-03-03 | Henrik Grubbström (Grubba) | | int err;
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | |
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] wait_thread: getting the lock.\n", getpid());
|
915d09 | 1999-04-23 | Henrik Grubbström (Grubba) | |
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | mt_lock(&wait_thread_mutex);
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | pid=MY_WAIT_ANY(&status, WNOHANG|WUNTRACED);
|
42c95b | 2003-03-03 | Henrik Grubbström (Grubba) | |
err = errno;
|
fb4549 | 2014-05-20 | Per Hedbor | |
|
42c95b | 2003-03-03 | Henrik Grubbström (Grubba) | | if(pid < 0 && err == ECHILD)
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | {
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] wait_thread: sleeping\n", getpid());
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | |
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | co_wait(&start_wait_thread, &wait_thread_mutex);
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] wait_thread: waking up\n", getpid());
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | }
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] wait_thread: releasing the lock.\n", getpid());
|
915d09 | 1999-04-23 | Henrik Grubbström (Grubba) | |
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | mt_unlock(&wait_thread_mutex);
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
840d48 | 2003-03-18 | Henrik Grubbström (Grubba) | | #ifdef ENODEV
do {
#endif
errno = 0;
if(pid <= 0) pid=MY_WAIT_ANY(&status, 0|WUNTRACED);
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | |
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] wait thread: pid=%d status=%d errno=%d\n",
getpid(), pid, status, errno);
|
0d7c54 | 2014-05-20 | Per Hedbor | |
|
840d48 | 2003-03-18 | Henrik Grubbström (Grubba) | | #ifdef ENODEV
|
0d7c54 | 2014-05-20 | Per Hedbor | | } while (UNLIKELY(errno == ENODEV));
|
840d48 | 2003-03-18 | Henrik Grubbström (Grubba) | | #endif
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | if(pid>0)
{
|
928254 | 2003-05-17 | Henrik Grubbström (Grubba) | | #if defined(HAVE_PTRACE) && \
(defined(SIGPROF) || \
defined(_W_SLWTED) || defined(_W_SEWTED) || defined(_W_SFWTED))
if (WIFSTOPPED(status) &&
|
7a24f5 | 2003-05-17 | Henrik Grubbström (Grubba) | | #if !defined(_W_SLWTED) && !defined(_W_SEWTED) && !defined(_W_SFWTED)
|
52531f | 2003-05-17 | Henrik Grubbström (Grubba) | |
|
baf4c2 | 2003-05-23 | Henrik Grubbström (Grubba) | | ((WSTOPSIG(status) == SIGPROF) ||
|
f9cc13 | 2003-05-22 | Henrik Grubbström (Grubba) | |
|
baf4c2 | 2003-05-23 | Henrik Grubbström (Grubba) | | (WSTOPSIG(status) == SIGKILL))
|
928254 | 2003-05-17 | Henrik Grubbström (Grubba) | | #else
|
52531f | 2003-05-17 | Henrik Grubbström (Grubba) | |
|
928254 | 2003-05-17 | Henrik Grubbström (Grubba) | | ((status & 0xff) != 0x7f)
#endif
) {
|
52531f | 2003-05-17 | Henrik Grubbström (Grubba) | | #if !defined(_W_SLWTED) && !defined(_W_SEWTED) && !defined(_W_SFWTED)
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | |
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] wait thread: Got signal %d from pid %d\n",
getpid(), WSTOPSIG(status), pid);
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | |
|
f9cc13 | 2003-05-22 | Henrik Grubbström (Grubba) | | ptrace(PTRACE_CONT, pid, CAST_TO_PTRACE_ADDR(1), WSTOPSIG(status));
|
f6fd61 | 2003-05-17 | Henrik Grubbström (Grubba) | | #else /* defined(_W_SLWTED) || defined(_W_SEWTED) || defined(_W_SFWTED) */
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | |
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] wait thread: Got L/E/F status (0x%08x) from pid %d\n",
getpid(), status, pid);
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | |
|
f6fd61 | 2003-05-17 | Henrik Grubbström (Grubba) | | ptrace(PTRACE_CONT, pid, CAST_TO_PTRACE_ADDR(1), 0);
#endif /* !defined(_W_SLWTED) && !defined(_W_SEWTED) && !defined(_W_SFWTED) */
|
a4b2dd | 2003-03-16 | Henrik Grubbström (Grubba) | | continue;
}
|
928254 | 2003-05-17 | Henrik Grubbström (Grubba) | | #endif /* HAVE_PTRACE && (SIGPROF || _W_SLWTED || _W_SEWTED || _W_SFWTED) */
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] wait thread: locking interpreter, pid=%d\n",
getpid(), pid);
|
915d09 | 1999-04-23 | Henrik Grubbström (Grubba) | |
|
bc21dc | 2001-11-01 | Martin Stjernholm | | low_mt_lock_interpreter();
|
915d09 | 1999-04-23 | Henrik Grubbström (Grubba) | |
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] wait thread: reporting the event!\n", getpid());
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | |
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | report_child(pid, status, "wait_thread");
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | co_broadcast(& process_status_change);
|
c91f89 | 2000-04-19 | Martin Stjernholm | | mt_unlock_interpreter();
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | continue;
}
if(pid == -1)
{
|
42c95b | 2003-03-03 | Henrik Grubbström (Grubba) | | switch(err)
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | {
|
940a4b | 2005-05-25 | Henrik Grubbström (Grubba) | | #if 0
case 0:
#endif /* 0 */
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | case EINTR:
case ECHILD:
break;
default:
|
42c95b | 2003-03-03 | Henrik Grubbström (Grubba) | | fprintf(stderr,"Wait thread: waitpid returned error: %d\n",err);
|
d561d6 | 1999-03-07 | Fredrik Hübinette (Hubbe) | | }
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | }
}
}
#endif
|
eb9a04 | 2001-08-14 | Martin Nilsson | |
|
099503 | 2011-09-08 | Henrik Grubbström (Grubba) | | *!
*! @seealso
*! @[Process]
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | */
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | |
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | *! Waits for the process to end.
*!
|
0b3a1b | 2002-10-31 | Johan Sundström | | *! @returns
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | *! @int
*! @value 0..
*! The exit code of the process.
*! @value -1
*! The process was killed by a signal.
|
9cb49c | 2007-10-04 | Henrik Grubbström (Grubba) | | *! @value -2
*! The process is stopped.
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | *! @endint
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | *!
|
992ac6 | 2003-03-13 | Martin Nilsson | | *! @seealso
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | *! @[TraceProcess()->wait()]
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | */
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | static void f_pid_status_wait(INT32 args)
{
if(THIS->pid == -1)
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("This process object has no process associated with it.\n");
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | |
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #ifdef __NT__
{
int err=0;
DWORD xcode;
HANDLE h=THIS->handle;
THREADS_ALLOW();
while(1)
{
if(GetExitCodeProcess(h, &xcode))
{
if(xcode == STILL_ACTIVE)
{
WaitForSingleObject(h, INFINITE);
}else{
break;
}
}else{
err=1;
break;
}
}
THREADS_DISALLOW();
if(err)
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Failed to get status of process.\n");
|
42c95b | 2003-03-03 | Henrik Grubbström (Grubba) | |
pop_n_elems(args);
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | push_int(xcode);
}
#else
|
1abbfb | 2006-07-05 | Martin Stjernholm | | {
|
2209de | 2013-01-18 | Stephen R. van den Berg | | int wait_for_stopped, alreadydied = 0;
|
cb5e3a | 2004-04-01 | Henrik Grubbström (Grubba) | | if (THIS->pid == getpid())
Pike_error("Waiting for self.\n");
|
42c95b | 2003-03-03 | Henrik Grubbström (Grubba) | |
wait_for_stopped = THIS->flags & PROCESS_FLAG_TRACED;
|
a4b2dd | 2003-03-16 | Henrik Grubbström (Grubba) | | while((THIS->state == PROCESS_RUNNING) ||
(!wait_for_stopped && (THIS->state == PROCESS_STOPPED)))
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | {
|
b4b3a8 | 2015-07-31 | Martin Nilsson | | #ifdef USE_WAIT_THREAD
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | SWAP_OUT_CURRENT_THREAD();
|
b4b3a8 | 2015-07-31 | Martin Nilsson | | co_wait_interpreter( & process_status_change);
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | SWAP_IN_CURRENT_THREAD();
|
b4b3a8 | 2015-07-31 | Martin Nilsson | | #else
int err;
int pid = THIS->pid;
WAITSTATUSTYPE status;
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] wait(%d): Waiting for child...\n", getpid(), pid);
|
b4b3a8 | 2015-07-31 | Martin Nilsson | |
THREADS_ALLOW();
pid = WAITPID(pid, &status, 0|WUNTRACED);
err = errno;
THREADS_DISALLOW();
if(pid > 0)
{
report_child(pid, status, "->wait");
}
else if(pid<0)
{
switch(err)
{
case EINTR:
break;
#if defined(_REENTRANT) || defined(USE_SIGCHILD)
case ECHILD:
pid = THIS->pid;
if ((THIS->state == PROCESS_RUNNING) ||
(!wait_for_stopped && (THIS->state == PROCESS_STOPPED))) {
struct pid_status *this = THIS;
int killret, killerr;
THREADS_ALLOW();
while ((!(killret = kill(pid, 0), killerr = errno, killret)) &&
(!wait_for_stopped || (this->state != PROCESS_STOPPED))) {
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] wait(%d): Sleeping...\n", getpid(), pid);
|
b4b3a8 | 2015-07-31 | Martin Nilsson | | #ifdef HAVE_POLL
{
struct pollfd pfd[1];
#ifdef NEED_SIGNAL_SAFE_FIFO
pfd[0].fd = wait_fd[0];
pfd[0].events = POLLIN;
poll (pfd, 1, 10000);
#else
poll(pfd, 0, 100);
#endif
}
#else /* !HAVE_POLL */
sleep(1);
#endif /* HAVE_POLL */
}
THREADS_DISALLOW();
if (killret && killerr == ESRCH) {
if (alreadydied)
goto lostchild;
alreadydied = 1;
}
}
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] wait(%d): Process dead.\n", getpid(), pid);
|
b4b3a8 | 2015-07-31 | Martin Nilsson | |
if ((THIS->state == PROCESS_RUNNING) ||
(!wait_for_stopped && THIS->state == PROCESS_STOPPED)) {
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] wait(%d): ... but not officially, yet.\n"
"[%d] wait(%d): Sleeping some more...\n",
getpid(), pid, getpid(), pid);
|
b4b3a8 | 2015-07-31 | Martin Nilsson | | THREADS_ALLOW();
#ifdef HAVE_POLL
poll(NULL, 0, 100);
#else /* !HAVE_POLL */
sleep(1);
#endif /* HAVE_POLL */
THREADS_DISALLOW();
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] wait(%d): Child isn't reaped yet, looping.\n",
getpid(), pid);
|
b4b3a8 | 2015-07-31 | Martin Nilsson | | }
break;
#endif /* _REENTRANT || USE_SIGCHILD */
default:
lostchild:
Pike_error("Lost track of a child (pid %d, errno from wait %d).\n",
THIS->pid, err);
break;
}
} else {
Pike_fatal("Pid = 0 in waitpid(%d)\n",pid);
}
#endif
|
3cad0a | 2013-01-01 | Henrik Grubbström (Grubba) | | check_threads_etc();
|
cb5e3a | 2004-04-01 | Henrik Grubbström (Grubba) | | }
|
42c95b | 2003-03-03 | Henrik Grubbström (Grubba) | | pop_n_elems(args);
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | if (THIS->state == PROCESS_STOPPED) {
push_int(-2);
} else {
push_int(THIS->result);
}
|
1abbfb | 2006-07-05 | Martin Stjernholm | | }
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #endif /* __NT__ */
|
f01020 | 2011-11-16 | Tobias S. Josefowitz | |
INVALIDATE_CURRENT_TIME();
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | }
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | |
0b3a1b | 2002-10-31 | Johan Sundström | | *! @int
*! @value -1
*! Unknown
*! @value 0
*! Running
*! @value 1
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | *! Stopped
*! @value 2
|
0b3a1b | 2002-10-31 | Johan Sundström | | *! Exited
*! @endint
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | */
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | static void f_pid_status_status(INT32 args)
{
pop_n_elems(args);
#ifdef __NT__
{
DWORD x;
if(GetExitCodeProcess(THIS->handle, &x))
{
push_int( x == STILL_ACTIVE ? PROCESS_RUNNING : PROCESS_EXITED);
}else{
push_int(PROCESS_UNKNOWN);
}
}
#else
push_int(THIS->state);
#endif
}
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | |
static void f_pid_status_last_signal(INT32 args)
{
pop_n_elems(args);
#ifdef __NT__
push_int(0);
#else
push_int(THIS->sig);
#endif
}
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | |
0b3a1b | 2002-10-31 | Johan Sundström | | *! Returns the process identifier of the process.
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | */
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | static void f_pid_status_pid(INT32 args)
{
pop_n_elems(args);
push_int(THIS->pid);
}
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | |
0b3a1b | 2002-10-31 | Johan Sundström | | *! Sets the priority of the process. @[priority] is one of the strings
*! @dl
*! @item "realtime"
*! @item "highest"
*! @item "higher"
*! @item "high"
|
2d3e79 | 2014-10-08 | Per Cederqvist | | *! @item "normal"
|
0b3a1b | 2002-10-31 | Johan Sundström | | *! @item "low"
*! @item "lowest"
*! @enddl
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | */
|
72850a | 1999-02-01 | Per Hedbor | | static void f_pid_status_set_priority(INT32 args)
{
char *to;
int r;
|
811116 | 2003-09-07 | Martin Nilsson | |
|
c91b1d | 2018-08-05 | Martin Nilsson | | get_all_args(NULL, args, "%s", &to);
|
72850a | 1999-02-01 | Per Hedbor | | r = set_priority( THIS->pid, to );
pop_n_elems(args);
push_int(r);
}
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | |
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | |
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | |
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | #ifdef HAVE_PTRACE
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | |
|
74dfe8 | 2012-12-30 | Jonas Walldén | | static void init_trace_process(struct object *UNUSED(o))
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | {
THIS->flags |= PROCESS_FLAG_TRACED;
}
|
74dfe8 | 2012-12-30 | Jonas Walldén | | static void exit_trace_process(struct object *UNUSED(o))
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | {
}
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | *! Allow a traced process to continue.
*!
*! @param signal
*! Deliver this signal to the process.
*!
*! @note
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | *! This function may only be called for stopped processes.
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | *!
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | *! @seealso
*! @[wait()]
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | */
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | static void f_trace_process_cont(INT32 args)
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | {
int cont_signal = 0;
|
811116 | 2003-09-07 | Martin Nilsson | |
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | if(THIS->pid == -1)
Pike_error("This process object has no process associated with it.\n");
if (THIS->state != PROCESS_STOPPED) {
if (THIS->state == PROCESS_RUNNING) {
Pike_error("Process already running.\n");
}
Pike_error("Process not stopped\n");
}
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if (args && TYPEOF(Pike_sp[-args]) == PIKE_T_INT) {
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | cont_signal = Pike_sp[-args].u.integer;
}
THIS->state = PROCESS_RUNNING;
|
ab6e69 | 2003-04-06 | Henrik Grubbström (Grubba) | |
if (ptrace(PTRACE_CONT, THIS->pid,
CAST_TO_PTRACE_ADDR(1), cont_signal) == -1) {
int err = errno;
THIS->state = PROCESS_STOPPED;
|
5272b2 | 2004-09-22 | Martin Stjernholm | | Pike_error("Failed to release process: %s (errno %d)\n", strerror (err), err);
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | }
|
f9cc13 | 2003-05-22 | Henrik Grubbström (Grubba) | |
#ifdef __FreeBSD__
if (cont_signal == SIGKILL) {
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] cont(): Continue with SIGKILL for pid %d on FreeBSD\n",
getpid(), THIS->pid);
|
f9cc13 | 2003-05-22 | Henrik Grubbström (Grubba) | | if (kill(THIS->pid, SIGKILL) == -1) {
int err = errno;
|
baf4c2 | 2003-05-23 | Henrik Grubbström (Grubba) | | if (err != ESRCH) {
Pike_error("Failed to kill process. errno:%d\n", err);
}
|
f9cc13 | 2003-05-22 | Henrik Grubbström (Grubba) | | }
}
#endif /* __FreeBSD__ */
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | }
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | |
static void f_trace_process_exit(INT32 args)
{
if(THIS->pid == -1)
Pike_error("This process object has no process associated with it.\n");
if (THIS->state != PROCESS_STOPPED) {
if (THIS->state == PROCESS_EXITED) {
Pike_error("Process already exited.\n");
}
Pike_error("Process not stopped\n");
}
if (ptrace(PTRACE_KILL, THIS->pid, NULL, 0) == -1) {
int err = errno;
Pike_error("Failed to exit process. errno:%d\n", err);
}
pop_n_elems(args);
}
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | |
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | | #if 0 /* Disabled for now. */
|
13e2ba | 2014-04-26 | Henrik Grubbström (Grubba) | | #define THIS_PROC_REG_PROC_ID ((struct pid_status *)parent_storage(1, pid_status_program))
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | |
static void f_proc_reg_index(INT32 args)
{
struct pid_status *proc = THIS_PROC_REG_PROC_ID;
|
a92ad6 | 2003-10-13 | Henrik Grubbström (Grubba) | | INT_TYPE regno = 0;
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | | long val;
if(proc->pid == -1)
Pike_error("This process object has no process associated with it.\n");
if (proc->state != PROCESS_STOPPED) {
if (proc->state == PROCESS_EXITED) {
Pike_error("Process has exited.\n");
}
Pike_error("Process not stopped.\n");
}
|
c91b1d | 2018-08-05 | Martin Nilsson | | get_all_args(NULL, args, "%+", ®no);
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | |
|
111b1d | 2014-08-22 | Martin Nilsson | | if (regno * sizeof(long) > sizeof(((struct user *)NULL)->regs))
|
f98274 | 2016-01-26 | Martin Nilsson | | SIMPLE_ARG_TYPE_ERROR("`[]", 1, "register number");
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | |
if ((val = ptrace(PTRACE_PEEKUSER, proc->pid,
|
d2361e | 2003-06-30 | Martin Stjernholm | | ((long *)(((struct user *)NULL)->regs)) + regno, 0)) == -1) {
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | | int err = errno;
if (errno) {
Pike_error("Failed to exit process. errno:%d\n", err);
}
}
pop_n_elems(args);
push_int64(val);
}
#endif /* 0 */
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | |
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | #endif /* HAVE_PTRACE */
|
eb9a04 | 2001-08-14 | Martin Nilsson | |
|
0c9594 | 2018-01-12 | Stephen R. van den Berg | | #ifdef __amigaos__
extern struct DosLibrary *DOSBase;
#ifdef __amigaos4__
extern struct DOSIFace *IDOS;
#endif
static BPTR get_amigados_handle(struct mapping *optional, char *name, int fd)
{
char buf[32];
long ext;
struct svalue *tmp;
BPTR b;
if(optional && (tmp=simple_mapping_string_lookup(optional, name)))
{
if(TYPEOF(*tmp) == T_OBJECT)
{
fd = fd_from_object(tmp->u.object);
if(fd == -1)
Pike_error("File for %s is not open.\n",name);
}
}
#ifdef __ixemul__
if((ext = fcntl(fd, F_EXTERNALIZE, 0)) < 0)
Pike_error("File for %s can not be externalized.\n", name);
sprintf(buf, "IXPIPE:%lx", ext);
if((b = Open(buf, 0x4242)) == 0)
Pike_error("File for %s can not be internalized.\n", name);
return b;
#else
return MKBADDR(NULL);
#endif
}
struct perishables
{
BPTR stdin_b;
BPTR stdout_b;
BPTR stderr_b;
BPTR cwd_lock;
struct byte_buffer cmd_buf;
};
static void free_perishables(struct perishables *storage)
{
if(storage->stdin_b!=0) Close(storage->stdin_b);
if(storage->stdout_b!=0) Close(storage->stdout_b);
if(storage->stderr_b!=0) Close(storage->stderr_b);
if(storage->cwd_lock!=0)
UnLock(storage->cwd_lock);
buffer_free(&storage->cmd_buf);
}
#else /* !__amigaos__ */
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #ifdef __NT__
|
65c26d | 2018-04-26 | Henrik Grubbström (Grubba) | |
|
864d3c | 1998-01-29 | Fredrik Hübinette (Hubbe) | | static HANDLE get_inheritable_handle(struct mapping *optional,
char *name,
|
1797d9 | 2020-02-10 | Henrik Grubbström (Grubba) | | int for_reading,
HPCON *conpty)
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | {
|
bd6739 | 2015-10-14 | Martin Nilsson | | HANDLE ret = INVALID_HANDLE_VALUE;
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | struct svalue *save_stack=Pike_sp;
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | struct svalue *tmp;
if((tmp=simple_mapping_string_lookup(optional, name)))
{
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(*tmp) == T_OBJECT)
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | {
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | INT32 fd=fd_from_object(tmp->u.object);
|
65c26d | 2018-04-26 | Henrik Grubbström (Grubba) | | HANDLE h;
|
1797d9 | 2020-02-10 | Henrik Grubbström (Grubba) | | int type;
|
5a7ab6 | 1998-01-31 | Fredrik Hübinette (Hubbe) | |
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | if(fd == -1)
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("File for %s is not open.\n",name);
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | |
if(!(fd_query_properties(fd, 0) & fd_INTERPROCESSABLE))
{
void create_proxy_pipe(struct object *o, int for_reading);
|
13670c | 2015-05-25 | Martin Nilsson | |
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | create_proxy_pipe(tmp->u.object, for_reading);
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | fd=fd_from_object(Pike_sp[-1].u.object);
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | }
|
13670c | 2015-05-25 | Martin Nilsson | |
|
1797d9 | 2020-02-10 | Henrik Grubbström (Grubba) | | if(fd_to_handle(fd, &type, &h, 0) < 0)
|
65c26d | 2018-04-26 | Henrik Grubbström (Grubba) | | Pike_error("File for %s is not open.\n",name);
|
13670c | 2015-05-25 | Martin Nilsson | |
|
1797d9 | 2020-02-10 | Henrik Grubbström (Grubba) | | if (type == FD_PTY) {
struct my_pty *pty = (struct my_pty *)h;
if (!conpty || pty->conpty || !pty->other || !pty->other->conpty ||
(*conpty && (*conpty != pty->other->conpty))) {
if (for_reading) {
|
858770 | 2020-02-10 | Henrik Grubbström (Grubba) | | h = pty->read_pipe;
|
1797d9 | 2020-02-10 | Henrik Grubbström (Grubba) | | } else {
|
858770 | 2020-02-10 | Henrik Grubbström (Grubba) | | h = pty->write_pipe;
|
1797d9 | 2020-02-10 | Henrik Grubbström (Grubba) | | }
} else {
|
d59f12 | 2020-02-13 | Henrik Grubbström (Grubba) | | * NB: Stdin, stdout and stderr are handled automatically
* by setting the conpty. The conpty has duplicated
* handles of the original pipes, and in turn provides
* actual CONSOLE handles to the subprocess. We thus
* do NOT return the base pipe handle.
|
1797d9 | 2020-02-10 | Henrik Grubbström (Grubba) | | *
* BUGS: It is not possible to have multiple conpty
* objects for the same process, so the first
* pty for stdin, stdout and stderr wins
* (see above).
|
d59f12 | 2020-02-13 | Henrik Grubbström (Grubba) | | *
|
126a97 | 2020-02-19 | Henrik Grubbström (Grubba) | | * BUGS: As the conpty is a separate process that may survive
* our subprocess terminating, we need to keep track
|
d59f12 | 2020-02-13 | Henrik Grubbström (Grubba) | | * of which master pty the process was bound to so
* that we can close the corresponding conpty
* when no one else will use it.
|
126a97 | 2020-02-19 | Henrik Grubbström (Grubba) | | *
* BUGS: The above behavior is apparently a bug according
* to the ConPTY developers. Fixing the bug however
* leads to a race condition with respect to short-
* lived processes causing the ConPTY to terminate
* before we have closed out slave connection.
|
1797d9 | 2020-02-10 | Henrik Grubbström (Grubba) | | */
|
d59f12 | 2020-02-13 | Henrik Grubbström (Grubba) | | pid_status_link_pty(THIS, pty->other);
|
1797d9 | 2020-02-10 | Henrik Grubbström (Grubba) | | *conpty = pty->other->conpty;
release_fd(fd);
|
d59f12 | 2020-02-13 | Henrik Grubbström (Grubba) | |
return 0;
|
1797d9 | 2020-02-10 | Henrik Grubbström (Grubba) | | }
}
|
8d6012 | 2000-10-08 | Henrik Grubbström (Grubba) | | if(!DuplicateHandle(GetCurrentProcess(),
|
65c26d | 2018-04-26 | Henrik Grubbström (Grubba) | | h,
|
8d6012 | 2000-10-08 | Henrik Grubbström (Grubba) | | GetCurrentProcess(),
&ret,
0,
1,
|
65c26d | 2018-04-26 | Henrik Grubbström (Grubba) | | DUPLICATE_SAME_ACCESS)) {
release_fd(fd);
Pike_error("Failed to duplicate handle %d.\n", GetLastError());
}
release_fd(fd);
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | }
}
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | pop_n_elems(Pike_sp-save_stack);
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | return ret;
}
#endif
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | #ifndef __NT__
|
72850a | 1999-02-01 | Per Hedbor | | #ifdef HAVE_SETRLIMIT
#include <sys/time.h>
|
f1e4ee | 2003-03-06 | Henrik Grubbström (Grubba) | | struct pike_limit
|
72850a | 1999-02-01 | Per Hedbor | | {
int resource;
struct rlimit rlp;
|
f1e4ee | 2003-03-06 | Henrik Grubbström (Grubba) | | struct pike_limit *next;
|
72850a | 1999-02-01 | Per Hedbor | | };
#endif
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | struct perishables
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | | {
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | char **env;
char **argv;
|
72850a | 1999-02-01 | Per Hedbor | |
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | int *fds;
|
283361 | 1998-07-09 | Henrik Grubbström (Grubba) | | int disabled;
|
72850a | 1999-02-01 | Per Hedbor | | #ifdef HAVE_SETRLIMIT
|
f1e4ee | 2003-03-06 | Henrik Grubbström (Grubba) | | struct pike_limit *limits;
|
72850a | 1999-02-01 | Per Hedbor | | #endif
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_SETGROUPS
gid_t *wanted_gids;
struct array *wanted_gids_array;
int num_wanted_gids;
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | | #endif
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | };
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | |
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | static void free_perishables(struct perishables *storage)
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | | {
|
6e9223 | 1998-08-07 | Henrik Grubbström (Grubba) | | if (storage->disabled) {
|
ffb70d | 1998-07-09 | Henrik Grubbström (Grubba) | | exit_threads_disable(NULL);
|
6e9223 | 1998-08-07 | Henrik Grubbström (Grubba) | | }
|
b8d9ee | 1998-06-30 | Henrik Grubbström (Grubba) | |
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | if (storage->fds) free(storage->fds);
|
72850a | 1999-02-01 | Per Hedbor | | if(storage->env) free( storage->env );
if(storage->argv) free( storage->argv );
|
bccf0c | 2000-07-11 | David Hedbor | | #ifdef HAVE_SETRLIMIT
|
13670c | 2015-05-25 | Martin Nilsson | | while(storage->limits)
|
72850a | 1999-02-01 | Per Hedbor | | {
|
f1e4ee | 2003-03-06 | Henrik Grubbström (Grubba) | | struct pike_limit *n = storage->limits->next;
|
72850a | 1999-02-01 | Per Hedbor | | free( storage->limits );
storage->limits = n;
}
|
bccf0c | 2000-07-11 | David Hedbor | | #endif
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_SETGROUPS
|
72850a | 1999-02-01 | Per Hedbor | | if(storage->wanted_gids) free(storage->wanted_gids);
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | if(storage->wanted_gids_array) free_array(storage->wanted_gids_array);
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | | #endif
}
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | |
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | | #endif
|
0c9594 | 2018-01-12 | Stephen R. van den Berg | | #endif
#if !defined(__NT__) && !defined(__amigaos__)
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | |
extern int pike_make_pipe(int *);
|
80923b | 1999-05-01 | Henrik Grubbström (Grubba) | | *
* NOTE: 0 is reserved.
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | | */
#define PROCE_CHDIR 1
#define PROCE_DUP2 2
#define PROCE_SETGID 3
#define PROCE_SETGROUPS 4
#define PROCE_GETPWUID 5
#define PROCE_INITGROUPS 6
#define PROCE_SETUID 7
#define PROCE_EXEC 8
|
d887b6 | 1999-05-26 | Fredrik Hübinette (Hubbe) | | #define PROCE_CLOEXEC 9
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | #define PROCE_DUP 10
|
8f6385 | 2000-09-16 | Mirar (Pontus Hagland) | | #define PROCE_SETSID 11
|
06dda5 | 2002-08-21 | Marcus Comstedt | | #define PROCE_SETCTTY 12
|
6b4714 | 2003-12-05 | Martin Nilsson | | #define PROCE_CHROOT 13
|
493ee5 | 2004-07-02 | Henrik Grubbström (Grubba) | | #define PROCE_CLRCLOEXEC 14
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | |
#define PROCERROR(err, id) do { int _l, _i; \
buf[0] = err; buf[1] = errno; buf[2] = id; \
for(_i = 0; _i < 3; _i += _l) { \
while (((_l = write(control_pipe[1], buf + _i, 3 - _i)) < 0) && \
(errno == EINTR)) \
; \
|
941b5a | 2004-06-21 | Martin Stjernholm | | if (_l < 0) exit (99 - errno); \
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | | } \
|
941b5a | 2004-06-21 | Martin Stjernholm | | while((_l = close(control_pipe[1])) < 0 && errno==EINTR); \
if (_l < 0) exit (99 + errno); \
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | | exit(99); \
} while(0)
|
0c9594 | 2018-01-12 | Stephen R. van den Berg | | #endif /* !__NT__ && !__amigaos__ */
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | |
|
dedd3d | 1999-02-01 | Per Hedbor | | #ifdef HAVE___PRIOCNTL
# include <sys/priocntl.h>
# include <sys/rtpriocntl.h>
# include <sys/tspriocntl.h>
#else
# ifdef HAVE_SCHED_SETSCHEDULER
|
3adb2f | 2000-08-28 | Fredrik Hübinette (Hubbe) | | # ifdef HAVE_SCHED_H
# include <sched.h>
# else
# ifdef HAVE_SYS_SCHED_H
# include <sys/sched.h>
# endif
# endif
|
dedd3d | 1999-02-01 | Per Hedbor | | # endif
#endif
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | |
|
72850a | 1999-02-01 | Per Hedbor | | static int set_priority( int pid, char *to )
{
int prilevel = 0;
if(!strcmp( to, "realtime" ) ||
!strcmp( to, "highest" ))
prilevel = 3;
|
1f8eb4 | 2014-10-08 | Per Cederqvist | | else if(!strcmp( to, "higher" ))
|
72850a | 1999-02-01 | Per Hedbor | | prilevel = 2;
else if(!strcmp( to, "high" ))
prilevel = 1;
|
2d3e79 | 2014-10-08 | Per Cederqvist | | else if(!strcmp( to, "normal" ))
prilevel = 0;
|
72850a | 1999-02-01 | Per Hedbor | | else if(!strcmp( to, "low" ))
prilevel = -1;
else if(!strcmp( to, "lowest" ))
prilevel = -2;
|
1f8eb4 | 2014-10-08 | Per Cederqvist | | else
Pike_error("bad priority %s", to);
|
bebf3e | 2003-01-11 | Per Hedbor | | #ifdef __NT__
{
HANDLE process;
|
da6c40 | 2004-11-20 | Martin Nilsson | | DWORD how = NORMAL_PRIORITY_CLASS;
|
8d7cee | 2003-05-04 | Martin Nilsson | | if( pid == getpid() || !pid )
|
bebf3e | 2003-01-11 | Per Hedbor | | process = GetCurrentProcess();
else
process = OpenProcess( PROCESS_SET_INFORMATION, FALSE, pid );
if( !process )
{
|
8d7cee | 2003-05-04 | Martin Nilsson | |
|
bebf3e | 2003-01-11 | Per Hedbor | | return 0;
}
|
13670c | 2015-05-25 | Martin Nilsson | |
|
bebf3e | 2003-01-11 | Per Hedbor | | switch( prilevel )
{
|
da6c40 | 2004-11-20 | Martin Nilsson | | case -1:
|
56a199 | 2014-10-08 | Per Cederqvist | | # ifdef BELOW_NORMAL_PRIORITY_CLASS
|
da6c40 | 2004-11-20 | Martin Nilsson | | how = BELOW_NORMAL_PRIORITY_CLASS;
break;
|
56a199 | 2014-10-08 | Per Cederqvist | | # endif
|
da6c40 | 2004-11-20 | Martin Nilsson | |
case -2: how = IDLE_PRIORITY_CLASS; break;
|
bebf3e | 2003-01-11 | Per Hedbor | | case 0: how = NORMAL_PRIORITY_CLASS; break;
|
da6c40 | 2004-11-20 | Martin Nilsson | | case 1:
|
56a199 | 2014-10-08 | Per Cederqvist | | # ifdef ABOVE_NORMAL_PRIORITY_CLASS
|
da6c40 | 2004-11-20 | Martin Nilsson | | how = ABOVE_NORMAL_PRIORITY_CLASS;
break;
|
56a199 | 2014-10-08 | Per Cederqvist | | # endif
|
da6c40 | 2004-11-20 | Martin Nilsson | |
case 2: how = HIGH_PRIORITY_CLASS; break;
|
bebf3e | 2003-01-11 | Per Hedbor | | case 3: how = REALTIME_PRIORITY_CLASS; break;
}
|
13670c | 2015-05-25 | Martin Nilsson | |
|
bebf3e | 2003-01-11 | Per Hedbor | | if( SetPriorityClass( process, how ) )
how = 1;
|
13670c | 2015-05-25 | Martin Nilsson | | else
|
bebf3e | 2003-01-11 | Per Hedbor | | how = 0;
CloseHandle( process );
return how;
}
#else
|
56a199 | 2014-10-08 | Per Cederqvist | | # ifdef HAVE___PRIOCNTL
|
72850a | 1999-02-01 | Per Hedbor | | if(!pid) pid = getpid();
if( prilevel > 1 )
{
struct {
id_t pc_cid;
|
d4bb2a | 1999-05-17 | Fredrik Hübinette (Hubbe) | | short rt_pri;
|
72850a | 1999-02-01 | Per Hedbor | | ulong rt_tqsecs;
long rt_tqnsecs;
long padding[10];
} params;
struct {
id_t pc_cid;
char pc_clname[PC_CLNMSZ];
short rt_maxpri;
short _pad;
long pad2[10];
} foo;
|
21b12a | 2014-09-03 | Martin Nilsson | | memset(¶ms, 0, sizeof(params));
memset(&foo, 0, sizeof(foo));
|
72850a | 1999-02-01 | Per Hedbor | |
strcpy(foo.pc_clname, "RT");
|
6d81e4 | 1999-02-17 | Henrik Grubbström (Grubba) | | if( priocntl((idtype_t)0, (id_t)0, PC_GETCID, (void *)(&foo)) == -1)
|
72850a | 1999-02-01 | Per Hedbor | | return 0;
params.pc_cid = foo.pc_cid;
params.rt_pri = prilevel == 3 ? foo.rt_maxpri : 0;
params.rt_tqsecs = 1;
params.rt_tqnsecs = 0;
|
6d81e4 | 1999-02-17 | Henrik Grubbström (Grubba) | | return priocntl(P_PID, (id_t)pid, PC_SETPARMS, (void *)(¶ms)) != -1;
|
72850a | 1999-02-01 | Per Hedbor | | } else {
struct {
id_t pc_cid;
pri_t ts_uprilim;
pri_t ts_upri;
long padding[12];
} params;
struct {
id_t pc_cid;
char pc_clname[PC_CLNMSZ];
short ts_maxupri;
short _pad;
long pad2[10];
} foo;
|
21b12a | 2014-09-03 | Martin Nilsson | | memset(¶ms, 0, sizeof(params));
memset(&foo, 0, sizeof(foo));
|
72850a | 1999-02-01 | Per Hedbor | | strcpy(foo.pc_clname, "TS");
|
6d81e4 | 1999-02-17 | Henrik Grubbström (Grubba) | | if( priocntl((idtype_t)0, (id_t)0, PC_GETCID, (void *)(&foo)) == -1)
|
72850a | 1999-02-01 | Per Hedbor | | return 0;
params.pc_cid = foo.pc_cid;
params.ts_upri = TS_NOCHANGE;
params.ts_uprilim = prilevel*foo.ts_maxupri/2;
|
6d81e4 | 1999-02-17 | Henrik Grubbström (Grubba) | | return priocntl(P_PID, (id_t)pid, PC_SETPARMS, (void *)(¶ms)) != -1;
|
72850a | 1999-02-01 | Per Hedbor | | }
|
56a199 | 2014-10-08 | Per Cederqvist | | # else
# ifdef HAVE_SCHED_SETSCHEDULER
|
72850a | 1999-02-01 | Per Hedbor | | {
|
48aa6a | 2014-10-08 | Per Cederqvist | | int class;
int maxprio = 2;
int minprio = -2;
|
0994f9 | 2014-10-09 | Martin Nilsson | | struct sched_param param;
memset(¶m, 0, sizeof(param));
|
48aa6a | 2014-10-08 | Per Cederqvist | | if( prilevel == 3 )
{
class = SCHED_FIFO;
param.sched_priority = sched_get_priority_max( class );
return !sched_setscheduler( pid, class, ¶m );
}
|
56a199 | 2014-10-08 | Per Cederqvist | | # ifdef SCHED_RR
|
72850a | 1999-02-01 | Per Hedbor | | if(prilevel == 2)
{
class = SCHED_RR;
|
f91b7e | 2014-10-08 | Per Cederqvist | | param.sched_priority = sched_get_priority_min( class );
|
72850a | 1999-02-01 | Per Hedbor | | return !sched_setscheduler( pid, class, ¶m );
|
f91b7e | 2014-10-08 | Per Cederqvist | | }
|
48aa6a | 2014-10-08 | Per Cederqvist | | maxprio = 1;
|
56a199 | 2014-10-08 | Per Cederqvist | | # endif
|
23e8e5 | 2014-10-08 | Per Cederqvist | | # ifdef SCHED_IDLE
if(prilevel == -2)
{
class = SCHED_IDLE;
param.sched_priority = sched_get_priority_min( class );
return !sched_setscheduler( pid, class, ¶m );
}
minprio = -1;
# endif
|
48aa6a | 2014-10-08 | Per Cederqvist | |
class = SCHED_OTHER;
|
72850a | 1999-02-01 | Per Hedbor | | param.sched_priority = sched_get_priority_min( class )+
(sched_get_priority_max( class )-
|
48aa6a | 2014-10-08 | Per Cederqvist | | sched_get_priority_min( class ))/(maxprio-minprio) * (prilevel-minprio);
if (sched_setscheduler( pid, class, ¶m ) < 0)
return 0;
|
72850a | 1999-02-01 | Per Hedbor | | }
|
48aa6a | 2014-10-08 | Per Cederqvist | |
# endif
# ifdef HAVE_SETPRIORITY
|
72850a | 1999-02-01 | Per Hedbor | | {
|
13670c | 2015-05-25 | Martin Nilsson | | if(prilevel == 3)
|
72850a | 1999-02-01 | Per Hedbor | | prilevel = 2;
errno = 0;
return setpriority( PRIO_PROCESS, pid, -prilevel*10 )!=-1 || errno==0;
}
|
48aa6a | 2014-10-08 | Per Cederqvist | | # else
# ifdef HAVE_NICE
|
72850a | 1999-02-01 | Per Hedbor | | if(!pid || pid == getpid())
{
errno=0;
return !(nice( -prilevel*10 - nice(0) ) != -1) || errno!=EPERM;
}
|
56a199 | 2014-10-08 | Per Cederqvist | | # endif
# endif
# endif
|
72850a | 1999-02-01 | Per Hedbor | | #endif
return 0;
}
|
111b1d | 2014-08-22 | Martin Nilsson | | |
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | */
|
72850a | 1999-02-01 | Per Hedbor | | void f_set_priority( INT32 args )
{
|
edbaf3 | 2008-01-13 | Henrik Grubbström (Grubba) | | INT_TYPE pid = 0;
|
72850a | 1999-02-01 | Per Hedbor | | char *plevel;
|
811116 | 2003-09-07 | Martin Nilsson | |
|
111b1d | 2014-08-22 | Martin Nilsson | | get_all_args("set_priority", args, "%s.%+", &plevel, &pid);
|
72850a | 1999-02-01 | Per Hedbor | | pid = set_priority( pid, plevel );
pop_n_elems(args);
push_int( pid );
}
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | |
|
0c9594 | 2018-01-12 | Stephen R. van den Berg | | #ifndef __amigaos__
|
72850a | 1999-02-01 | Per Hedbor | | #ifdef HAVE_SETRLIMIT
|
13670c | 2015-05-25 | Martin Nilsson | | static void internal_add_limit( struct perishables *storage,
|
72850a | 1999-02-01 | Per Hedbor | | int limit_resource,
struct svalue *limit_value )
{
struct rlimit ol;
|
f1e4ee | 2003-03-06 | Henrik Grubbström (Grubba) | | struct pike_limit *l = NULL;
|
fb4549 | 2014-05-20 | Per Hedbor | |
if( limit_resource < 0 )
return;
|
72850a | 1999-02-01 | Per Hedbor | | #ifndef RLIM_SAVED_MAX
getrlimit( limit_resource, &ol );
#else
ol.rlim_max = RLIM_SAVED_MAX;
ol.rlim_cur = RLIM_SAVED_CUR;
#endif
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(*limit_value) == PIKE_T_INT)
|
72850a | 1999-02-01 | Per Hedbor | | {
|
f1e4ee | 2003-03-06 | Henrik Grubbström (Grubba) | | l = malloc(sizeof( struct pike_limit ));
|
72850a | 1999-02-01 | Per Hedbor | | l->rlp.rlim_max = ol.rlim_max;
l->rlp.rlim_cur = limit_value->u.integer;
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | } else if(TYPEOF(*limit_value) == T_MAPPING) {
|
72850a | 1999-02-01 | Per Hedbor | | struct svalue *tmp3;
|
f1e4ee | 2003-03-06 | Henrik Grubbström (Grubba) | | l = malloc(sizeof( struct pike_limit ));
|
14b810 | 1999-02-11 | Henrik Grubbström (Grubba) | | if((tmp3=simple_mapping_string_lookup(limit_value->u.mapping, "soft"))) {
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(*tmp3) == PIKE_T_INT)
|
7e8ea3 | 2000-08-13 | Henrik Grubbström (Grubba) | | l->rlp.rlim_cur = (tmp3->u.integer >= 0) ?
(unsigned INT32)tmp3->u.integer:(unsigned INT32)ol.rlim_cur;
|
72850a | 1999-02-01 | Per Hedbor | | else
l->rlp.rlim_cur = RLIM_INFINITY;
|
14b810 | 1999-02-11 | Henrik Grubbström (Grubba) | | } else
|
72850a | 1999-02-01 | Per Hedbor | | l->rlp.rlim_cur = ol.rlim_cur;
|
14b810 | 1999-02-11 | Henrik Grubbström (Grubba) | | if((tmp3=simple_mapping_string_lookup(limit_value->u.mapping, "hard"))) {
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(*tmp3) == PIKE_T_INT)
|
7e8ea3 | 2000-08-13 | Henrik Grubbström (Grubba) | | l->rlp.rlim_max = (tmp3->u.integer >= 0) ?
(unsigned INT32)tmp3->u.integer:(unsigned INT32)ol.rlim_max;
|
72850a | 1999-02-01 | Per Hedbor | | else
l->rlp.rlim_max = RLIM_INFINITY;
|
14b810 | 1999-02-11 | Henrik Grubbström (Grubba) | | } else
|
72850a | 1999-02-01 | Per Hedbor | | l->rlp.rlim_max = ol.rlim_max;
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | } else if(TYPEOF(*limit_value) == T_ARRAY && limit_value->u.array->size == 2) {
|
f1e4ee | 2003-03-06 | Henrik Grubbström (Grubba) | | l = malloc(sizeof( struct pike_limit ));
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(limit_value->u.array->item[0]) == PIKE_T_INT)
|
72850a | 1999-02-01 | Per Hedbor | | l->rlp.rlim_max = limit_value->u.array->item[0].u.integer;
else
l->rlp.rlim_max = ol.rlim_max;
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(limit_value->u.array->item[1]) == PIKE_T_INT)
|
72850a | 1999-02-01 | Per Hedbor | | l->rlp.rlim_cur = limit_value->u.array->item[1].u.integer;
else
|
81d929 | 2013-01-29 | Henrik Grubbström (Grubba) | | l->rlp.rlim_cur = ol.rlim_cur;
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | } else if(TYPEOF(*limit_value) == T_STRING) {
|
f1e4ee | 2003-03-06 | Henrik Grubbström (Grubba) | | l = malloc(sizeof(struct pike_limit));
|
72850a | 1999-02-01 | Per Hedbor | | l->rlp.rlim_max = RLIM_INFINITY;
l->rlp.rlim_cur = RLIM_INFINITY;
}
if(l)
{
l->resource = limit_resource;
l->next = storage->limits;
storage->limits = l;
}
}
#endif
|
0c9594 | 2018-01-12 | Stephen R. van den Berg | | #endif /* __amigaos__ */
|
72850a | 1999-02-01 | Per Hedbor | |
|
2b52ff | 2001-01-16 | Johan Sundström | |
|
6ace4f | 2006-04-24 | Henrik Grubbström (Grubba) | | #ifdef HAVE_FDWALK
struct fd_cleanup_info
{
int num_fds;
int control_pipe;
};
int fd_cleanup_cb(void *data, int fd)
{
struct fd_cleanup_info *info = data;
if ((fd < 2) || (fd < info->num_fds)) return 0;
#ifdef HAVE_BROKEN_F_SETFD
if (fd == info->control_pipe) return 0;
while ((close(fd) == -1) && (errno == EINTR))
;
#else
set_close_on_exec(fd, 1);
#endif
|
2fc55f | 2006-12-27 | Henrik Grubbström (Grubba) | | return 0;
|
6ace4f | 2006-04-24 | Henrik Grubbström (Grubba) | | }
#endif /* HAVE_FDWALK */
|
2b52ff | 2001-01-16 | Johan Sundström | |
|
b4e0fc | 2001-01-23 | David Norlin | | |
2b52ff | 2001-01-16 | Johan Sundström | | *!
*! @param command_args
*! The command name and its command-line arguments. You do not have
*! to worry about quoting them; pike does this for you.
*!
*! @param modifiers
*! This optional mapping can can contain zero or more of the
*! following parameters:
*!
*! @mapping
*!
|
2fc55f | 2006-12-27 | Henrik Grubbström (Grubba) | | *! @member function(Process.Process:void) "callback"
*! Function called when the created process changes state.
*!
|
ce852e | 2015-05-25 | Henrik Grubbström (Grubba) | | *! Note that this function is called in a signal handler context,
*! which means that it may be called by any thread at any time after
*! the child process has changed state, and is thus not only called
*! by the main thread when the main backend is idle. Indeed, you can
*! specify a callback even if your program does not use a backend.
*!
|
2b52ff | 2001-01-16 | Johan Sundström | | *! @member string "cwd"
*! Execute the command in another directory than the current
*! directory of this process. Please note that if the command is
*! given is a relative path, it will be relative to this directory
*! rather than the current directory of this process.
*!
|
e2eb64 | 2015-05-25 | Henrik Grubbström (Grubba) | | *! Note also that the path is relative to the @expr{"chroot"@} if used.
*!
|
bd9d40 | 2003-12-05 | Stephen R. van den Berg | | *! @member string "chroot"
*! Chroot to this directory before executing the command.
*!
|
28370c | 2013-02-01 | Henrik Grubbström (Grubba) | | *! Note that the current directory will be changed to @expr{"/"@} in
*! the chroot environment, unless @expr{"cwd"@} above has been set.
*!
|
2b52ff | 2001-01-16 | Johan Sundström | | *! @member Stdio.File "stdin"
*! @member Stdio.File "stdout"
*! @member Stdio.File "stderr"
*! These parameters allows you to change the standard input, output
*! and error streams of the newly created process. This is
*! particularly useful in combination with @[Stdio.File.pipe].
*!
*! @member mapping(string:string) "env"
*! This mapping will become the environment variables for the
*! created process. Normally you will want to only add or change
*! variables which can be achived by getting the environment mapping
*! for this process with @[getenv]. See the examples section.
*!
*! @member int|string "uid"
*! This parameter changes which user the new process will execute
*! as. Note that the current process must be running as UID 0 to use
*! this option. The uid can be given either as an integer as a
*! string containing the login name of that user.
*!
*! The "gid" and "groups" for the new process will be set to the
*! right values for that user unless overriden by options below.
*!
*! (See @[setuid] and @[getpwuid] for more info.)
*!
*! @member int|string "gid"
*! This parameter changes the primary group for the new process.
*! When the new process creates files, they will will be created
*! with this group. The group can either be given as an int or a
*! string containing the name of the group. (See @[setuid]
*! and @[getgrgid] for more info.)
*!
|
06dda5 | 2002-08-21 | Marcus Comstedt | | *! @member int(0..1)|object(Stdio.File) "setsid"
|
cbe8c9 | 2003-04-07 | Martin Nilsson | | *! Set this to @expr{1@} to create a new session group.
|
06dda5 | 2002-08-21 | Marcus Comstedt | | *! It is also possible to set it to a File object, in which
*! case a new session group will be created with this file
*! as the controlling terminal.
|
2a82e7 | 2001-04-29 | Henrik Grubbström (Grubba) | | *!
|
2b52ff | 2001-01-16 | Johan Sundström | | *! @member array(int|string) "setgroups"
*! This parameter allows you to the set the list of groups that the
*! new process belongs to. It is recommended that if you use this
*! parameter you supply at least one and no more than 16 groups.
*! (Some system only support up to 8...) The groups can be given as
*! gids or as strings with the group names.
*!
*! @member int(0..1) "noinitgroups"
*! This parameter overrides a behaviour of the "uid" parameter. If
*! this parameter is used, the gid and groups of the new process
*! will be inherited from the current process rather than changed to
*! the approperiate values for that uid.
*!
*! @member string "priority"
*! This sets the priority of the new process, see
*! @[set_priority] for more info.
*!
*! @member int "nice"
*! This sets the nice level of the new process; the lower the
*! number, the higher the priority of the process. Note that only
*! UID 0 may use negative numbers.
*!
*! @member int(0..1) "keep_signals"
*! This prevents Pike from restoring all signal handlers to their
*! default values for the new process. Useful to ignore certain
*! signals in the new process.
*!
*! @member array(Stdio.File|int(0..0)) "fds"
*! This parameter allows you to map files to filedescriptors 3 and
|
cbe8c9 | 2003-04-07 | Martin Nilsson | | *! up. The file @expr{fds[0]@} will be remapped to fd 3 in the new
|
2b52ff | 2001-01-16 | Johan Sundström | | *! process, etc.
*!
*! @member mapping(string:limit_value) "rlimit"
*! There are two values for each limit, the soft limit and the hard
*! limit. Processes that do not have UID 0 may not raise the hard
*! limit, and the soft limit may never be increased over the hard
*! limit. The indices of the mapping indicate what limit to impose,
*! and the values dictate what the limit should be. (See also
|
e1ea35 | 2002-02-14 | Martin Nilsson | | *! @[System.setrlimit])
|
2b52ff | 2001-01-16 | Johan Sundström | | *!
*! @mapping
*! @member limit_value "core"
*! maximum core file size in bytes
*!
*! @member limit_value "cpu"
*! maximum amount of cpu time used by the process in seconds
*!
*! @member limit_value "data"
*! maximum heap (brk, malloc) size in bytes
*!
*! @member limit_value "fsize"
*! maximum size of files created by the process in bytes
*!
*! @member limit_value "map_mem"
*! maximum size of the process's mapped address space (mmap() and
*! heap size) in bytes
*!
*! @member limit_value "mem"
*! maximum size of the process's total amount of available memory
*! (mmap, heap and stack size) in bytes
*!
*! @member limit_value "nofile"
*! maximum number of file descriptors the process may create
*!
*! @member limit_value "stack"
*! maximum stack size in bytes
*! @endmapping
*!
|
126a97 | 2020-02-19 | Henrik Grubbström (Grubba) | | *! @member Stdio.File "conpty"
*! Bind the process to the console associated with this
*! pty slave. NT only.
*!
|
2b52ff | 2001-01-16 | Johan Sundström | | *! @endmapping
*!
*! @example
*! Process.create_process(({ "/usr/bin/env" }),
*! (["env" : getenv() + (["TERM":"vt100"]) ]));
*!
|
a4bb2a | 2001-10-08 | Johan Sundström | | *! @example
|
230dd2 | 2002-11-26 | Henrik Grubbström (Grubba) | | *! //! Spawn a new process with the args @@[args] and optionally a
*! //! standard input if you provide such a @@[Stdio.File] object.
*! //! @@returns
*! //! Returns the new process and a pipe from which you can read
*! //! its output.
|
a4bb2a | 2001-10-08 | Johan Sundström | | *! array(Process.Process|Stdio.File) spawn(Stdio.File|void stdin, string ... args)
*! {
*! Stdio.File stdout = Stdio.File();
*! mapping opts = ([ "stdout" : stdout->pipe() ]);
*! if( stdin )
*! opts->stdin = stdin;
*! return ({ Process.create_process( args, opts ), stdout });
*! }
*!
|
2b52ff | 2001-01-16 | Johan Sundström | | *! @note
|
230dd2 | 2002-11-26 | Henrik Grubbström (Grubba) | | *! All parameters that accept both string or int input can be
*! noticeably slower using a string instead of an integer; if maximum
*! performance is an issue, please use integers.
|
2b52ff | 2001-01-16 | Johan Sundström | | *!
|
2fc55f | 2006-12-27 | Henrik Grubbström (Grubba) | | *! @note
|
28370c | 2013-02-01 | Henrik Grubbström (Grubba) | | *! On NT the only supported modifiers are: @expr{"cwd"@},
|
126a97 | 2020-02-19 | Henrik Grubbström (Grubba) | | *! @expr{"conpty"@}, @expr{"stdin"@}, @expr{"stdout"@}, @expr{"stderr"@}
*! and @expr{"env"@}. All other modifiers are silently ignored.
|
2fc55f | 2006-12-27 | Henrik Grubbström (Grubba) | | *!
*! @note
*! Support for @expr{"callback"@} was added in Pike 7.7.
|
28370c | 2013-02-01 | Henrik Grubbström (Grubba) | | *!
*! @note
*! Chroot changing directory to @expr{"/"@} was added in Pike 7.9.
|
2b52ff | 2001-01-16 | Johan Sundström | | */
|
98e083 | 2002-02-04 | Tomas Nilsson | | #ifdef __NT__
DEFINE_IMUTEX(handle_protection_mutex);
|
303207 | 2002-02-04 | Martin Nilsson | | #endif /* __NT__ */
|
98e083 | 2002-02-04 | Tomas Nilsson | |
|
fb4549 | 2014-05-20 | Per Hedbor | | #ifdef HAVE_SETRLIMIT
extern int get_limit_id( const char *limit );
#endif
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | void f_create_process(INT32 args)
{
struct array *cmd=0;
struct mapping *optional=0;
struct svalue *tmp;
int e;
|
d10342 | 2018-08-05 | Martin Nilsson | | check_all_args(NULL, args, BIT_ARRAY, BIT_MAPPING | BIT_VOID, 0);
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
switch(args)
{
default:
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | optional=Pike_sp[1-args].u.mapping;
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | mapping_fix_type_field(optional);
if(m_ind_types(optional) & ~BIT_STRING)
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Bad index type in argument 2 to Process->create()\n");
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
|
5f5084 | 2018-02-12 | Marcus Comstedt | |
|
7447e7 | 2015-04-22 | Henrik Grubbström (Grubba) | |
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | case 1: cmd=Pike_sp[-args].u.array;
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | if(cmd->size < 1)
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Too few elements in argument array.\n");
|
13670c | 2015-05-25 | Martin Nilsson | |
|
257524 | 2004-05-14 | Martin Nilsson | | if( (cmd->type_field & ~BIT_STRING) &&
(array_fix_type_field(cmd) & ~BIT_STRING) )
Pike_error("Bad argument 1 to Process().\n");
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
|
e0d56d | 2004-05-03 | Martin Nilsson | | for(e=0;e<cmd->size;e++)
if(ITEM(cmd)[e].u.string->size_shift)
|
13670c | 2015-05-25 | Martin Nilsson | | Pike_error("Argument is not an 8-bit string.\n");
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | }
#ifdef __NT__
{
|
bd6739 | 2015-10-14 | Martin Nilsson | | HANDLE t1 = INVALID_HANDLE_VALUE;
HANDLE t2 = INVALID_HANDLE_VALUE;
HANDLE t3 = INVALID_HANDLE_VALUE;
|
d63915 | 2020-02-10 | Henrik Grubbström (Grubba) | | STARTUPINFOEXW info;
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | PROCESS_INFORMATION proc;
|
175ede | 2020-02-12 | Henrik Grubbström (Grubba) | | int ret = 0, err;
|
602774 | 2020-02-07 | Henrik Grubbström (Grubba) | | WCHAR *filename=NULL, *command_line=NULL, *dir=NULL;
WCHAR *env=NULL;
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
|
126c38 | 1998-04-24 | Fredrik Hübinette (Hubbe) | |
|
1d7b37 | 1998-05-01 | Fredrik Hübinette (Hubbe) | |
|
e5d029 | 2001-09-13 | Henrik Grubbström (Grubba) | |
|
126c38 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | {
int e,d;
|
c73de5 | 2020-02-07 | Henrik Grubbström (Grubba) | | struct byte_buffer buf;
|
2d10fb | 2016-12-29 | Arne Goedeke | | buffer_init(&buf);
|
126c38 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | for(e=0;e<cmd->size;e++)
{
|
2fafca | 1999-07-20 | Fredrik Hübinette (Hubbe) | | int quote=0;
|
83f2e3 | 1999-08-06 | Fredrik Hübinette (Hubbe) | | if(e)
|
126c38 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | {
|
2d10fb | 2016-12-29 | Arne Goedeke | | buffer_add_char( &buf, ' ');
|
1d7b37 | 1998-05-01 | Fredrik Hübinette (Hubbe) | | }
|
dc10f2 | 2001-10-12 | Tomas Nilsson | |
if (ITEM(cmd)[e].u.string->len <= 1 ||
ITEM(cmd)[e].u.string->str[0] != '"' ||
ITEM(cmd)[e].u.string->str[ITEM(cmd)[e].u.string->len-1] != '"')
{
|
5aa54c | 2014-09-03 | Martin Nilsson | | quote=strchr(ITEM(cmd)[e].u.string->str,'"') ||
strchr(ITEM(cmd)[e].u.string->str,' ');
|
dc10f2 | 2001-10-12 | Tomas Nilsson | | }
|
1d7b37 | 1998-05-01 | Fredrik Hübinette (Hubbe) | |
if(quote)
{
|
dc10f2 | 2001-10-12 | Tomas Nilsson | | int numslash;
|
2d10fb | 2016-12-29 | Arne Goedeke | | buffer_add_char( &buf, '"');
|
1d7b37 | 1998-05-01 | Fredrik Hübinette (Hubbe) | |
|
dc10f2 | 2001-10-12 | Tomas Nilsson | |
|
1d7b37 | 1998-05-01 | Fredrik Hübinette (Hubbe) | | for(d=0;d<ITEM(cmd)[e].u.string->len;d++)
|
126c38 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | {
|
1d7b37 | 1998-05-01 | Fredrik Hübinette (Hubbe) | | switch(ITEM(cmd)[e].u.string->str[d])
{
case '\\':
|
dc10f2 | 2001-10-12 | Tomas Nilsson | | numslash = 1;
while(++d<ITEM(cmd)[e].u.string->len &&
ITEM(cmd)[e].u.string->str[d] == '\\')
{
numslash++;
}
if (d >= ITEM(cmd)[e].u.string->len)
|
13670c | 2015-05-25 | Martin Nilsson | | numslash *= 2; |
dc10f2 | 2001-10-12 | Tomas Nilsson | | double because we add a doubleqoute below */
else if (ITEM(cmd)[e].u.string->str[d] == '"')
numslash = 2*numslash + 1;
for (;numslash > 0; numslash--)
|
2d10fb | 2016-12-29 | Arne Goedeke | | buffer_add_char( &buf, '\\');
|
dc10f2 | 2001-10-12 | Tomas Nilsson | |
if (d<ITEM(cmd)[e].u.string->len)
|
2d10fb | 2016-12-29 | Arne Goedeke | | buffer_add_char( &buf, ITEM(cmd)[e].u.string->str[d]);
|
dc10f2 | 2001-10-12 | Tomas Nilsson | |
|
2b24ea | 2000-05-23 | Fredrik Hübinette (Hubbe) | | break;
|
dc10f2 | 2001-10-12 | Tomas Nilsson | |
|
2b24ea | 2000-05-23 | Fredrik Hübinette (Hubbe) | | case '"':
|
2d10fb | 2016-12-29 | Arne Goedeke | | buffer_add_char( &buf, '\\');
|
dc10f2 | 2001-10-12 | Tomas Nilsson | |
|
1d7b37 | 1998-05-01 | Fredrik Hübinette (Hubbe) | | default:
|
2d10fb | 2016-12-29 | Arne Goedeke | | buffer_add_char( &buf, ITEM(cmd)[e].u.string->str[d]);
|
1d7b37 | 1998-05-01 | Fredrik Hübinette (Hubbe) | | }
|
126c38 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | }
|
2d10fb | 2016-12-29 | Arne Goedeke | | buffer_add_char( &buf, '"');
|
1d7b37 | 1998-05-01 | Fredrik Hübinette (Hubbe) | | }else{
|
2d10fb | 2016-12-29 | Arne Goedeke | | buffer_memcpy(&buf, ITEM(cmd)[e].u.string->str, ITEM(cmd)[e].u.string->len);
|
126c38 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | }
}
|
2d10fb | 2016-12-29 | Arne Goedeke | | buffer_add_char( &buf, 0);
|
13670c | 2015-05-25 | Martin Nilsson | |
|
83f2e3 | 1999-08-06 | Fredrik Hübinette (Hubbe) | |
|
e5d029 | 2001-09-13 | Henrik Grubbström (Grubba) | |
|
c73de5 | 2020-02-07 | Henrik Grubbström (Grubba) | | command_line = pike_dwim_utf8_to_utf16(buffer_get_string(&buf));
buffer_free(&buf);
|
126c38 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | }
|
e5d029 | 2001-09-13 | Henrik Grubbström (Grubba) | |
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
|
21b12a | 2014-09-03 | Martin Nilsson | | memset(&info,0,sizeof(info));
|
858770 | 2020-02-10 | Henrik Grubbström (Grubba) | | info.StartupInfo.cb = sizeof(info);
|
13670c | 2015-05-25 | Martin Nilsson | |
|
175ede | 2020-02-12 | Henrik Grubbström (Grubba) | | #if 0
|
d63915 | 2020-02-10 | Henrik Grubbström (Grubba) | | GetStartupInfoW(&info.StartupInfo);
|
175ede | 2020-02-12 | Henrik Grubbström (Grubba) | | #endif
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
|
98e083 | 2002-02-04 | Tomas Nilsson | |
LOCK_IMUTEX(&handle_protection_mutex);
|
858770 | 2020-02-10 | Henrik Grubbström (Grubba) | | info.StartupInfo.dwFlags |= STARTF_USESTDHANDLES;
info.StartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
info.StartupInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
info.StartupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
SetHandleInformation(info.StartupInfo.hStdInput, HANDLE_FLAG_INHERIT, 0);
SetHandleInformation(info.StartupInfo.hStdOutput, HANDLE_FLAG_INHERIT, 0);
SetHandleInformation(info.StartupInfo.hStdError, HANDLE_FLAG_INHERIT, 0);
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
|
d63915 | 2020-02-10 | Henrik Grubbström (Grubba) | | info.lpAttributeList = NULL;
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | if(optional)
{
|
1797d9 | 2020-02-10 | Henrik Grubbström (Grubba) | | HPCON conpty = (HPCON)0;
|
da6c40 | 2004-11-20 | Martin Nilsson | | if( (tmp=simple_mapping_string_lookup(optional, "cwd")) )
|
83f2e3 | 1999-08-06 | Fredrik Hübinette (Hubbe) | | {
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(*tmp) == T_STRING)
|
83f2e3 | 1999-08-06 | Fredrik Hübinette (Hubbe) | | {
|
602774 | 2020-02-07 | Henrik Grubbström (Grubba) | | dir = pike_dwim_utf8_to_utf16(STR0(tmp->u.string));
|
924577 | 2000-06-26 | Martin Stjernholm | |
|
83f2e3 | 1999-08-06 | Fredrik Hübinette (Hubbe) | | }
}
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
|
126a97 | 2020-02-19 | Henrik Grubbström (Grubba) | | CloseHandle(get_inheritable_handle(optional, "conpty", 1, &conpty));
|
1797d9 | 2020-02-10 | Henrik Grubbström (Grubba) | | t1 = get_inheritable_handle(optional, "stdin", 1, &conpty);
|
3eee2e | 2020-02-10 | Henrik Grubbström (Grubba) | | if(t1 != INVALID_HANDLE_VALUE) {
|
858770 | 2020-02-10 | Henrik Grubbström (Grubba) | | info.StartupInfo.hStdInput = t1;
}
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
|
1797d9 | 2020-02-10 | Henrik Grubbström (Grubba) | | t2 = get_inheritable_handle(optional, "stdout", 0, &conpty);
|
3eee2e | 2020-02-10 | Henrik Grubbström (Grubba) | | if(t2 != INVALID_HANDLE_VALUE) {
|
858770 | 2020-02-10 | Henrik Grubbström (Grubba) | | info.StartupInfo.hStdOutput = t2;
}
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
|
1797d9 | 2020-02-10 | Henrik Grubbström (Grubba) | | t3 = get_inheritable_handle(optional, "stderr", 0, &conpty);
|
3eee2e | 2020-02-10 | Henrik Grubbström (Grubba) | | if(t3 != INVALID_HANDLE_VALUE) {
|
858770 | 2020-02-10 | Henrik Grubbström (Grubba) | | info.StartupInfo.hStdError = t3;
}
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
|
1797d9 | 2020-02-10 | Henrik Grubbström (Grubba) | | if (conpty) {
LPPROC_THREAD_ATTRIBUTE_LIST attrlist = NULL;
SIZE_T attrlist_sz = 0;
Pike_NT_InitializeProcThreadAttributeList(attrlist, 1, 0, &attrlist_sz);
if (!(attrlist = malloc(attrlist_sz)) ||
!(Pike_NT_InitializeProcThreadAttributeList(attrlist, 1, 0,
&attrlist_sz) &&
(info.lpAttributeList = attrlist)) ||
!Pike_NT_UpdateProcThreadAttribute(attrlist, 0,
PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE,
conpty, sizeof(conpty),
NULL, NULL)) {
if (attrlist) {
err = GetLastError();
if (!info.lpAttributeList) {
free(attrlist);
}
} else {
err = ERROR_NOT_ENOUGH_MEMORY;
}
goto fail;
}
}
|
0d52dd | 1998-01-16 | Fredrik Hübinette (Hubbe) | | if((tmp=simple_mapping_string_lookup(optional, "env")))
{
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(*tmp) == T_MAPPING)
|
0d52dd | 1998-01-16 | Fredrik Hübinette (Hubbe) | | {
struct mapping *m=tmp->u.mapping;
struct array *i,*v;
int ptr=0;
i=mapping_indices(m);
|
0912b3 | 1999-04-08 | Fredrik Hübinette (Hubbe) | | v=mapping_values(m);
|
0d52dd | 1998-01-16 | Fredrik Hübinette (Hubbe) | |
|
3f6e52 | 2001-11-13 | Tomas Nilsson | |
ref_push_array(i);
ref_push_array(v);
f_sort(2);
pop_stack();
|
0d52dd | 1998-01-16 | Fredrik Hübinette (Hubbe) | | for(e=0;e<i->size;e++)
{
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(ITEM(i)[e]) == T_STRING &&
TYPEOF(ITEM(v)[e]) == T_STRING)
|
0d52dd | 1998-01-16 | Fredrik Hübinette (Hubbe) | | {
check_stack(3);
|
7ced79 | 1998-04-09 | Henrik Grubbström (Grubba) | | ref_push_string(ITEM(i)[e].u.string);
|
75367d | 2014-08-22 | Arne Goedeke | | push_static_text("=");
|
7ced79 | 1998-04-09 | Henrik Grubbström (Grubba) | | ref_push_string(ITEM(v)[e].u.string);
|
0d52dd | 1998-01-16 | Fredrik Hübinette (Hubbe) | | f_add(3);
ptr++;
}
}
free_array(i);
free_array(v);
|
3f6e52 | 2001-11-13 | Tomas Nilsson | | push_string(make_shared_binary_string("\0",1));
|
0d52dd | 1998-01-16 | Fredrik Hübinette (Hubbe) | | f_aggregate(ptr+1);
|
0912b3 | 1999-04-08 | Fredrik Hübinette (Hubbe) | | push_string(make_shared_binary_string("\0",1));
|
0d52dd | 1998-01-16 | Fredrik Hübinette (Hubbe) | | o_multiply();
|
602774 | 2020-02-07 | Henrik Grubbström (Grubba) | |
env = low_dwim_utf8_to_utf16(Pike_sp[-1].u.string->str,
|
c84429 | 2020-02-07 | Henrik Grubbström (Grubba) | | Pike_sp[-1].u.string->len);
|
602774 | 2020-02-07 | Henrik Grubbström (Grubba) | | pop_stack();
|
0d52dd | 1998-01-16 | Fredrik Hübinette (Hubbe) | | }
}
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
}
|
ba510c | 1998-03-27 | Henrik Grubbström (Grubba) | | THREADS_ALLOW_UID();
|
83f2e3 | 1999-08-06 | Fredrik Hübinette (Hubbe) | |
|
858770 | 2020-02-10 | Henrik Grubbström (Grubba) | | SetHandleInformation(info.StartupInfo.hStdInput, HANDLE_FLAG_INHERIT,
|
602774 | 2020-02-07 | Henrik Grubbström (Grubba) | | HANDLE_FLAG_INHERIT);
|
858770 | 2020-02-10 | Henrik Grubbström (Grubba) | | SetHandleInformation(info.StartupInfo.hStdOutput, HANDLE_FLAG_INHERIT,
|
602774 | 2020-02-07 | Henrik Grubbström (Grubba) | | HANDLE_FLAG_INHERIT);
|
858770 | 2020-02-10 | Henrik Grubbström (Grubba) | | SetHandleInformation(info.StartupInfo.hStdError, HANDLE_FLAG_INHERIT,
|
602774 | 2020-02-07 | Henrik Grubbström (Grubba) | | HANDLE_FLAG_INHERIT);
ret = CreateProcessW(filename,
command_line,
NULL,
NULL,
1,
|
d63915 | 2020-02-10 | Henrik Grubbström (Grubba) | | CREATE_UNICODE_ENVIRONMENT |
EXTENDED_STARTUPINFO_PRESENT,
|
602774 | 2020-02-07 | Henrik Grubbström (Grubba) | | env,
dir,
|
d63915 | 2020-02-10 | Henrik Grubbström (Grubba) | | &info.StartupInfo,
|
602774 | 2020-02-07 | Henrik Grubbström (Grubba) | | &proc);
|
83f2e3 | 1999-08-06 | Fredrik Hübinette (Hubbe) | | err=GetLastError();
|
13670c | 2015-05-25 | Martin Nilsson | |
|
5267bd | 2004-09-06 | Henrik Grubbström (Grubba) | | THREADS_DISALLOW_UID();
|
1797d9 | 2020-02-10 | Henrik Grubbström (Grubba) | | fail:
|
76b0aa | 2004-09-13 | Henrik Grubbström (Grubba) | | UNLOCK_IMUTEX(&handle_protection_mutex);
|
1797d9 | 2020-02-10 | Henrik Grubbström (Grubba) | | if (info.lpAttributeList) {
Pike_NT_DeleteProcThreadAttributeList(info.lpAttributeList);
free(info.lpAttributeList);
}
|
602774 | 2020-02-07 | Henrik Grubbström (Grubba) | | if(env) free(env);
if(dir) free(dir);
if(filename) free(filename);
|
0f8729 | 1999-05-07 | Fredrik Hübinette (Hubbe) | | if(command_line) free(command_line);
|
a12f27 | 1998-01-10 | Fredrik Hübinette (Hubbe) | | #if 1
|
bd6739 | 2015-10-14 | Martin Nilsson | | if(t1 != INVALID_HANDLE_VALUE) CloseHandle(t1);
if(t2 != INVALID_HANDLE_VALUE) CloseHandle(t2);
if(t3 != INVALID_HANDLE_VALUE) CloseHandle(t3);
|
a12f27 | 1998-01-10 | Fredrik Hübinette (Hubbe) | | #endif
|
13670c | 2015-05-25 | Martin Nilsson | |
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | if(ret)
{
CloseHandle(proc.hThread);
THIS->handle=proc.hProcess;
|
72850a | 1999-02-01 | Per Hedbor | |
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | THIS->pid=proc.dwProcessId;
}else{
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Failed to start process (%d).\n",err);
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | }
}
|
d6ac73 | 1998-04-20 | Henrik Grubbström (Grubba) | | #else /* !__NT__ */
|
0c9594 | 2018-01-12 | Stephen R. van den Berg | | #ifdef __amigaos__
{
ONERROR err;
struct perishables storage;
int d, e;
storage.stdin_b = storage.stdout_b = storage.stderr_b = 0;
storage.cwd_lock = 0;
buffer_init(&storage.cmd_buf);
SET_ONERROR(err, free_perishables, &storage);
for(e=0;e<cmd->size;e++)
{
if(e)
buffer_add_char( &storage.cmd_buf, ' ');
if(strchr(STR0(ITEM(cmd)[e].u.string),'"') || strchr(STR0(ITEM(cmd)[e].u.string),' ')) {
buffer_add_char( &storage.cmd_buf, '"');
for(d=0;d<ITEM(cmd)[e].u.string->len;d++)
{
switch(STR0(ITEM(cmd)[e].u.string)[d])
{
case '*':
case '"':
buffer_add_char( &storage.cmd_buf, '*');
default:
buffer_add_char( &storage.cmd_buf, STR0(ITEM(cmd)[e].u.string)[d]);
}
}
buffer_add_char( &storage.cmd_buf, '"');
} else
buffer_memcpy(&storage.cmd_buf, STR0(ITEM(cmd)[e].u.string), ITEM(cmd)[e].u.string->len);
}
buffer_add_char( &storage.cmd_buf, '\0');
if(optional && (tmp=simple_mapping_string_lookup(optional, "cwd")))
if(TYPEOF(*tmp) == T_STRING)
if((storage.cwd_lock=Lock((char *)STR0(tmp->u.string), ACCESS_READ))==0)
Pike_error("Failed to lock cwd \"%S\".\n", tmp->u.string);
storage.stdin_b = get_amigados_handle(optional, "stdin", 0);
storage.stdout_b = get_amigados_handle(optional, "stdout", 1);
storage.stderr_b = get_amigados_handle(optional, "stderr", 2);
PROC_FPRINTF("[%d] SystemTags(\"%s\", SYS_Asynch, TRUE, NP_Input, %p, "
"NP_Output, %p, NP_Error, %p, %s, %p, TAG_END);\n",
getpid(),
|
dfbce8 | 2019-12-15 | Marcus Comstedt | | buffer_get_string(&storage.cmd_buf), storage.stdin_b,
|
0c9594 | 2018-01-12 | Stephen R. van den Berg | | storage.stdout_b, storage.stderr_b,
(storage.cwd_lock!=0? "NP_CurrentDir":"TAG_IGNORE"),
storage.cwd_lock);
|
dfbce8 | 2019-12-15 | Marcus Comstedt | | if(SystemTags(buffer_get_string(&storage.cmd_buf), SYS_Asynch, TRUE,
|
0c9594 | 2018-01-12 | Stephen R. van den Berg | | NP_Input, storage.stdin_b, NP_Output, storage.stdout_b,
NP_Error, storage.stderr_b,
(storage.cwd_lock!=0? NP_CurrentDir:TAG_IGNORE),
storage.cwd_lock, TAG_END))
Pike_error("Failed to start process (%ld).\n", IoErr());
UNSET_ONERROR(err);
}
#else /* !__amigaos__ */
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | {
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | struct svalue *stack_save=Pike_sp;
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | ONERROR err;
struct passwd *pw=0;
struct perishables storage;
int do_initgroups=1;
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | | int do_trace=0;
|
8af522 | 1998-04-30 | Fredrik Hübinette (Hubbe) | | uid_t wanted_uid;
gid_t wanted_gid;
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | int gid_request=0;
|
8f6385 | 2000-09-16 | Mirar (Pontus Hagland) | | int setsid_request=0;
|
b4f022 | 1998-04-12 | Henrik Grubbström (Grubba) | | int keep_signals = 0;
|
f62ab8 | 1999-06-25 | Fredrik Hübinette (Hubbe) | | pid_t pid=-2;
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | | int control_pipe[2];
char buf[4];
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | |
|
72850a | 1999-02-01 | Per Hedbor | | int nice_val;
int stds[3];
|
06dda5 | 2002-08-21 | Marcus Comstedt | | int cterm;
|
72850a | 1999-02-01 | Per Hedbor | | char *tmp_cwd;
|
bd9d40 | 2003-12-05 | Stephen R. van den Berg | | char *mchroot;
|
72850a | 1999-02-01 | Per Hedbor | | char *priority = NULL;
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | int *fds;
int num_fds = 3;
|
42c95b | 2003-03-03 | Henrik Grubbström (Grubba) | | int errnum = 0;
|
72850a | 1999-02-01 | Per Hedbor | |
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | stds[0] = stds[1] = stds[2] = -1;
|
06dda5 | 2002-08-21 | Marcus Comstedt | | cterm = -1;
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | fds = stds;
|
72850a | 1999-02-01 | Per Hedbor | | nice_val = 0;
tmp_cwd = NULL;
|
bd9d40 | 2003-12-05 | Stephen R. van den Berg | | mchroot = NULL;
|
72850a | 1999-02-01 | Per Hedbor | |
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | storage.env=0;
storage.argv=0;
|
ffb70d | 1998-07-09 | Henrik Grubbström (Grubba) | | storage.disabled=0;
|
72850a | 1999-02-01 | Per Hedbor | |
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | storage.fds = NULL;
|
72850a | 1999-02-01 | Per Hedbor | | #ifdef HAVE_SETRLIMIT
storage.limits = 0;
#endif
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | |
#ifdef HAVE_SETGROUPS
storage.wanted_gids=0;
storage.wanted_gids_array=0;
#endif
#ifdef HAVE_GETEUID
|
a9590d | 1998-04-21 | Henrik Grubbström (Grubba) | | wanted_uid=geteuid();
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | #else
|
d17158 | 1998-04-21 | Henrik Grubbström (Grubba) | | wanted_uid=getuid();
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | #endif
|
a9590d | 1998-04-21 | Henrik Grubbström (Grubba) | | #ifdef HAVE_GETEGID
wanted_gid=getegid();
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | #else
|
a9590d | 1998-04-21 | Henrik Grubbström (Grubba) | | wanted_gid=getgid();
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | #endif
|
831c4a | 1998-07-16 | Henrik Grubbström (Grubba) | | SET_ONERROR(err, free_perishables, &storage);
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | if(optional)
{
|
2fc55f | 2006-12-27 | Henrik Grubbström (Grubba) | | if ((tmp = simple_mapping_string_lookup(optional, "callback"))) {
assign_svalue(&(THIS->callback), tmp);
}
|
72850a | 1999-02-01 | Per Hedbor | | if((tmp = simple_mapping_string_lookup(optional, "priority")) &&
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | TYPEOF(*tmp) == T_STRING)
|
72850a | 1999-02-01 | Per Hedbor | | priority = tmp->u.string->str;
|
a9590d | 1998-04-21 | Henrik Grubbström (Grubba) | | if((tmp = simple_mapping_string_lookup(optional, "gid")))
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | {
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | switch(TYPEOF(*tmp))
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | {
|
fe2c20 | 2003-04-14 | Henrik Grubbström (Grubba) | | case PIKE_T_INT:
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | wanted_gid=tmp->u.integer;
gid_request=1;
break;
#if defined(HAVE_GETGRNAM) || defined(HAVE_GETGRENT)
case T_STRING:
{
extern void f_getgrnam(INT32);
push_svalue(tmp);
f_getgrnam(1);
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(Pike_sp[-1]) != T_ARRAY)
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("No such group.\n");
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(Pike_sp[-1].u.array->item[2]) != PIKE_T_INT)
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Getgrnam failed!\n");
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | wanted_gid = Pike_sp[-1].u.array->item[2].u.integer;
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | pop_stack();
gid_request=1;
}
|
a9590d | 1998-04-21 | Henrik Grubbström (Grubba) | | break;
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | #endif
default:
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Invalid argument for gid.\n");
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | }
}
|
bd9d40 | 2003-12-05 | Stephen R. van den Berg | |
if((tmp = simple_mapping_string_lookup( optional, "chroot" )) &&
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | TYPEOF(*tmp) == T_STRING && !tmp->u.string->size_shift)
|
bd9d40 | 2003-12-05 | Stephen R. van den Berg | | mchroot = tmp->u.string->str;
|
72850a | 1999-02-01 | Per Hedbor | | if((tmp = simple_mapping_string_lookup( optional, "cwd" )) &&
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | TYPEOF(*tmp) == T_STRING && !tmp->u.string->size_shift)
|
72850a | 1999-02-01 | Per Hedbor | | tmp_cwd = tmp->u.string->str;
|
8f6385 | 2000-09-16 | Mirar (Pontus Hagland) | | if((tmp = simple_mapping_string_lookup( optional, "setsid" )) &&
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | ((TYPEOF(*tmp) == PIKE_T_INT && tmp->u.integer) ||
(TYPEOF(*tmp) == T_OBJECT &&
|
06dda5 | 2002-08-21 | Marcus Comstedt | | (cterm = fd_from_object(tmp->u.object)) >= 0)))
|
8f6385 | 2000-09-16 | Mirar (Pontus Hagland) | | setsid_request=1;
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | if ((tmp = simple_mapping_string_lookup( optional, "fds" )) &&
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | TYPEOF(*tmp) == T_ARRAY) {
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | struct array *a = tmp->u.array;
int i = a->size;
if (i) {
num_fds = i+3;
|
dc8d02 | 2014-04-27 | Martin Nilsson | | storage.fds = fds = xalloc(sizeof(int)*(num_fds));
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | fds[0] = fds[1] = fds[2] = -1;
while (i--) {
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if (TYPEOF(a->item[i]) == T_OBJECT) {
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | fds[i+3] = fd_from_object(a->item[i].u.object);
} else {
fds[i+3] = -1;
}
}
}
}
|
72850a | 1999-02-01 | Per Hedbor | | if((tmp = simple_mapping_string_lookup( optional, "stdin" )) &&
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | TYPEOF(*tmp) == T_OBJECT)
|
72850a | 1999-02-01 | Per Hedbor | | {
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | fds[0] = fd_from_object( tmp->u.object );
if(fds[0] == -1)
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Invalid stdin file\n");
|
72850a | 1999-02-01 | Per Hedbor | | }
|
66440c | 1999-02-16 | Henrik Grubbström (Grubba) | | if((tmp = simple_mapping_string_lookup( optional, "stdout" )) &&
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | TYPEOF(*tmp) == T_OBJECT)
|
72850a | 1999-02-01 | Per Hedbor | | {
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | fds[1] = fd_from_object( tmp->u.object );
if(fds[1] == -1)
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Invalid stdout file\n");
|
72850a | 1999-02-01 | Per Hedbor | | }
|
66440c | 1999-02-16 | Henrik Grubbström (Grubba) | | if((tmp = simple_mapping_string_lookup( optional, "stderr" )) &&
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | TYPEOF(*tmp) == T_OBJECT)
|
72850a | 1999-02-01 | Per Hedbor | | {
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | fds[2] = fd_from_object( tmp->u.object );
if(fds[2] == -1)
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Invalid stderr file\n");
|
72850a | 1999-02-01 | Per Hedbor | | }
if((tmp = simple_mapping_string_lookup( optional, "nice"))
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | && TYPEOF(*tmp) == PIKE_T_INT )
|
72850a | 1999-02-01 | Per Hedbor | | nice_val = tmp->u.integer;
#ifdef HAVE_SETRLIMIT
if((tmp=simple_mapping_string_lookup(optional, "rlimit")))
{
struct svalue *tmp2;
|
fb4549 | 2014-05-20 | Per Hedbor | | unsigned int i;
struct mapping *m = tmp->u.mapping;
struct keypair *k;
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(*tmp) != T_MAPPING)
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Wrong type of argument for the 'rusage' option. "
|
fb4549 | 2014-05-20 | Per Hedbor | | "Should be mapping.\n");
NEW_MAPPING_LOOP( m->data )
if( TYPEOF(k->ind) == PIKE_T_STRING )
internal_add_limit( &storage, get_limit_id(k->ind.u.string->str), &k->val );
|
72850a | 1999-02-01 | Per Hedbor | | }
|
fb4549 | 2014-05-20 | Per Hedbor | | #endif
|
72850a | 1999-02-01 | Per Hedbor | |
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | if((tmp=simple_mapping_string_lookup(optional, "uid")))
{
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | switch(TYPEOF(*tmp))
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | {
|
fe2c20 | 2003-04-14 | Henrik Grubbström (Grubba) | | case PIKE_T_INT:
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | wanted_uid=tmp->u.integer;
#if defined(HAVE_GETPWUID) || defined(HAVE_GETPWENT)
if(!gid_request)
{
|
a9590d | 1998-04-21 | Henrik Grubbström (Grubba) | | extern void f_getpwuid(INT32);
push_int(wanted_uid);
f_getpwuid(1);
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | |
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(Pike_sp[-1]) == T_ARRAY)
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | {
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(Pike_sp[-1].u.array->item[3]) != PIKE_T_INT)
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Getpwuid failed!\n");
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | wanted_gid = Pike_sp[-1].u.array->item[3].u.integer;
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | }
pop_stack();
}
#endif
break;
|
fb4549 | 2014-05-20 | Per Hedbor | |
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | #if defined(HAVE_GETPWNAM) || defined(HAVE_GETPWENT)
case T_STRING:
{
extern void f_getpwnam(INT32);
push_svalue(tmp);
f_getpwnam(1);
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(Pike_sp[-1]) != T_ARRAY)
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("No such user.\n");
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(Pike_sp[-1].u.array->item[2]) != PIKE_T_INT ||
TYPEOF(Pike_sp[-1].u.array->item[3]) != PIKE_T_INT)
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Getpwnam failed!\n");
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | wanted_uid=Pike_sp[-1].u.array->item[2].u.integer;
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | if(!gid_request)
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | wanted_gid=Pike_sp[-1].u.array->item[3].u.integer;
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | pop_stack();
break;
}
#endif
default:
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Invalid argument for uid.\n");
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | }
}
if((tmp=simple_mapping_string_lookup(optional, "setgroups")))
{
#ifdef HAVE_SETGROUPS
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(*tmp) == T_ARRAY)
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | {
storage.wanted_gids_array=tmp->u.array;
|
868c30 | 1998-04-21 | Henrik Grubbström (Grubba) | | add_ref(storage.wanted_gids_array);
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | for(e=0;e<storage.wanted_gids_array->size;e++)
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(storage.wanted_gids_array->item[e]) != PIKE_T_INT)
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Invalid type for setgroups.\n");
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | do_initgroups=0;
}else{
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Invalid type for setgroups.\n");
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | }
#else
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Setgroups is not available.\n");
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | #endif
}
if((tmp=simple_mapping_string_lookup(optional, "env")))
{
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(*tmp) == T_MAPPING)
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | {
struct mapping *m=tmp->u.mapping;
struct array *i,*v;
int ptr=0;
i=mapping_indices(m);
v=mapping_values(m);
|
fb4549 | 2014-05-20 | Per Hedbor | |
|
dc8d02 | 2014-04-27 | Martin Nilsson | | storage.env=xalloc((1+m_sizeof(m)) * sizeof(char *));
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | for(e=0;e<i->size;e++)
{
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(ITEM(i)[e]) == T_STRING &&
TYPEOF(ITEM(v)[e]) == T_STRING)
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | {
check_stack(3);
|
acded5 | 1998-04-09 | Henrik Grubbström (Grubba) | | ref_push_string(ITEM(i)[e].u.string);
|
75367d | 2014-08-22 | Arne Goedeke | | push_static_text("=");
|
acded5 | 1998-04-09 | Henrik Grubbström (Grubba) | | ref_push_string(ITEM(v)[e].u.string);
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | f_add(3);
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | storage.env[ptr++]=Pike_sp[-1].u.string->str;
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | }
}
storage.env[ptr++]=0;
free_array(i);
free_array(v);
}
}
if((tmp=simple_mapping_string_lookup(optional, "noinitgroups")))
|
9f516a | 2001-12-16 | Martin Stjernholm | | if(!SAFE_IS_ZERO(tmp))
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | do_initgroups=0;
|
b4f022 | 1998-04-12 | Henrik Grubbström (Grubba) | |
if((tmp=simple_mapping_string_lookup(optional, "keep_signals")))
|
9f516a | 2001-12-16 | Martin Stjernholm | | keep_signals = !SAFE_IS_ZERO(tmp);
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | }
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | if (THIS->flags & PROCESS_FLAG_TRACED) {
do_trace = 1;
}
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_SETGROUPS
#ifdef HAVE_GETGRENT
if(wanted_uid != getuid() && do_initgroups)
{
extern void f_get_groups_for_user(INT32);
push_int(wanted_uid);
f_get_groups_for_user(1);
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(Pike_sp[-1]) == T_ARRAY)
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | {
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | storage.wanted_gids_array=Pike_sp[-1].u.array;
Pike_sp--;
dmalloc_touch_svalue(Pike_sp);
|
a9590d | 1998-04-21 | Henrik Grubbström (Grubba) | | } else {
pop_stack();
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | }
}
#endif
if(storage.wanted_gids_array)
{
int e;
|
679945 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | storage.wanted_gids=(gid_t *)xalloc(sizeof(gid_t) * (storage.wanted_gids_array->size + 1));
storage.wanted_gids[0]=65534;
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | for(e=0;e<storage.wanted_gids_array->size;e++)
{
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | switch(TYPEOF(storage.wanted_gids_array->item[e]))
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | {
|
fe2c20 | 2003-04-14 | Henrik Grubbström (Grubba) | | case PIKE_T_INT:
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | storage.wanted_gids[e]=storage.wanted_gids_array->item[e].u.integer;
break;
#if defined(HAVE_GETGRENT) || defined(HAVE_GETGRNAM)
case T_STRING:
{
extern void f_getgrnam(INT32);
ref_push_string(storage.wanted_gids_array->item[e].u.string);
f_getgrnam(2);
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(Pike_sp[-1]) != T_ARRAY)
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("No such group.\n");
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | |
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | storage.wanted_gids[e]=Pike_sp[-1].u.array->item[2].u.integer;
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | pop_stack();
break;
}
#endif
default:
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Gids must be integers or strings only.\n");
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | }
}
storage.num_wanted_gids=storage.wanted_gids_array->size;
free_array(storage.wanted_gids_array);
storage.wanted_gids_array=0;
do_initgroups=0;
}
#endif /* HAVE_SETGROUPS */
|
fb4549 | 2014-05-20 | Per Hedbor | |
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | storage.argv=(char **)xalloc((1+cmd->size) * sizeof(char *));
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | | if (pike_make_pipe(control_pipe) < 0) {
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Failed to create child communication pipe.\n");
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | | }
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] control_pipe: %d, %d\n",
getpid(), control_pipe[0], control_pipe[1]);
|
eecd3d | 2003-11-21 | Henrik Grubbström (Grubba) | | #ifdef USE_WAIT_THREAD
if (!wait_thread_running) {
THREAD_T foo;
if (th_create_small(&foo, wait_thread, 0)) {
Pike_error("Failed to create wait thread!\n"
"errno: %d\n", errno);
}
wait_thread_running = 1;
}
num_threads++;
#endif
|
71ac9e | 1999-08-29 | Fredrik Hübinette (Hubbe) | | th_atfork_prepare();
|
f43e42 | 1999-10-21 | Fredrik Hübinette (Hubbe) | | {
|
bb24ae | 2000-10-16 | Henrik Grubbström (Grubba) | | int loop_cnt = 0;
|
f43e42 | 1999-10-21 | Fredrik Hübinette (Hubbe) | | sigset_t new_sig, old_sig;
sigfillset(&new_sig);
|
bfd94e | 2000-10-18 | Henrik Grubbström (Grubba) | | while(sigprocmask(SIG_BLOCK, &new_sig, &old_sig))
;
|
f43e42 | 1999-10-21 | Fredrik Hübinette (Hubbe) | |
|
bb24ae | 2000-10-16 | Henrik Grubbström (Grubba) | | do {
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] Forking... (pid=%d errno=%d)\n",
getpid(), pid, errno);
|
bf782a | 2003-12-01 | Henrik Grubbström (Grubba) | | #ifdef HAVE_VFORK
pid=vfork();
#else /* !HAVE_VFORK */
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #if defined(HAVE_FORK1) && defined(_REENTRANT)
|
bb24ae | 2000-10-16 | Henrik Grubbström (Grubba) | | pid=fork1();
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #else
|
bb24ae | 2000-10-16 | Henrik Grubbström (Grubba) | | pid=fork();
#endif
|
bf782a | 2003-12-01 | Henrik Grubbström (Grubba) | | #endif /* HAVE_VFORK */
|
bb24ae | 2000-10-16 | Henrik Grubbström (Grubba) | | if (pid == -1) {
|
42c95b | 2003-03-03 | Henrik Grubbström (Grubba) | | errnum = errno;
|
0d7c54 | 2014-05-20 | Per Hedbor | | if (UNLIKELY(errnum == EAGAIN)) {
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] Fork failed with EAGAIN\n", getpid());
|
bb24ae | 2000-10-16 | Henrik Grubbström (Grubba) | |
if (loop_cnt++ < 60) {
#ifdef HAVE_POLL
poll(NULL, 0, 100);
#else /* !HAVE_POLL */
sleep(1);
#endif /* HAVE_POLL */
continue;
}
|
0d7c54 | 2014-05-20 | Per Hedbor | | } else if (UNLIKELY(errnum == EINTR)) {
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] Fork failed with EINTR\n", getpid());
|
bb24ae | 2000-10-16 | Henrik Grubbström (Grubba) | |
continue;
|
b3752c | 2001-06-20 | Henrik Grubbström (Grubba) | | } else {
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] Fork failed with errno:%d\n",
getpid(), errnum);
|
bb24ae | 2000-10-16 | Henrik Grubbström (Grubba) | | }
}
|
b3752c | 2001-06-20 | Henrik Grubbström (Grubba) | | #ifdef PROC_DEBUG
|
42c95b | 2003-03-03 | Henrik Grubbström (Grubba) | | else if (pid) {
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] Fork ok pid:%d\n", getpid(), pid);
|
b3752c | 2001-06-20 | Henrik Grubbström (Grubba) | | } else {
write(2, "Fork ok pid:0\n", 14);
}
#endif /* PROC_DEBUG */
|
bb24ae | 2000-10-16 | Henrik Grubbström (Grubba) | | break;
} while(1);
|
0f7787 | 1998-07-16 | Henrik Grubbström (Grubba) | |
|
0d7c54 | 2014-05-20 | Per Hedbor | | while(UNLIKELY(sigprocmask(SIG_SETMASK, &old_sig, 0))) {
|
b3752c | 2001-06-20 | Henrik Grubbström (Grubba) | | #ifdef PROC_DEBUG
char errcode[3] = {
'0'+((errno/100)%10),
'0'+((errno/10)%10),
'0'+(errno%10),
};
write(2, "sigprocmask() failed with errno:", 32);
write(2, errcode, 3);
write(2, "\n", 1);
#endif /* PROC_DEBUG */
}
|
f43e42 | 1999-10-21 | Fredrik Hübinette (Hubbe) | | }
|
57f53c | 1999-09-25 | Henrik Grubbström (Grubba) | | if(pid) {
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] th_at_fork_parent()...\n", getpid());
|
fec300 | 1999-08-30 | Fredrik Hübinette (Hubbe) | | th_atfork_parent();
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] th_at_fork_parent() done\n", getpid());
|
57f53c | 1999-09-25 | Henrik Grubbström (Grubba) | | } else {
|
b3752c | 2001-06-20 | Henrik Grubbström (Grubba) | | #ifdef PROC_DEBUG
write(2, "th_at_fork_child()...\n", 22);
#endif /* PROC_DEBUG */
|
fec300 | 1999-08-30 | Fredrik Hübinette (Hubbe) | | th_atfork_child();
|
b3752c | 2001-06-20 | Henrik Grubbström (Grubba) | | #ifdef PROC_DEBUG
write(2, "th_at_fork_child() done\n", 24);
#endif /* PROC_DEBUG */
|
57f53c | 1999-09-25 | Henrik Grubbström (Grubba) | | }
|
71ac9e | 1999-08-29 | Fredrik Hübinette (Hubbe) | |
|
b3752c | 2001-06-20 | Henrik Grubbström (Grubba) | | if (pid) {
UNSET_ONERROR(err);
}
|
0f7787 | 1998-07-16 | Henrik Grubbström (Grubba) | |
|
0144fe | 1998-11-30 | Henrik Grubbström (Grubba) | | if(pid == -1) {
|
c5679e | 2015-05-07 | Chris Angelico | | while(UNLIKELY(close(control_pipe[0]) < 0) && UNLIKELY(errno==EINTR));
while(UNLIKELY(close(control_pipe[1]) < 0) && UNLIKELY(errno==EINTR));
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | |
|
0f7787 | 1998-07-16 | Henrik Grubbström (Grubba) | | free_perishables(&storage);
|
0d7c54 | 2014-05-20 | Per Hedbor | | if (UNLIKELY(errnum == EAGAIN)) {
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("fork() failed with EAGAIN. Process table full?\n");
|
d951de | 2000-02-08 | Henrik Grubbström (Grubba) | | }
#ifdef ENOMEM
|
0d7c54 | 2014-05-20 | Per Hedbor | | if (UNLIKELY(errnum == ENOMEM)) {
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("fork() failed with ENOMEM. Out of memory?\n");
|
d951de | 2000-02-08 | Henrik Grubbström (Grubba) | | }
#endif /* ENOMEM */
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("fork() failed. errno:%d\n", errnum);
|
0f7787 | 1998-07-16 | Henrik Grubbström (Grubba) | | } else if(pid) {
|
70b508 | 1999-05-01 | Henrik Grubbström (Grubba) | | int olderrno;
|
6a9cbc | 2006-04-05 | Henrik Grubbström (Grubba) | | int cnt = 0;
|
70b508 | 1999-05-01 | Henrik Grubbström (Grubba) | |
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] Parent\n", getpid());
|
b3752c | 2001-06-20 | Henrik Grubbström (Grubba) | |
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | process_started(pid);
|
0144fe | 1998-11-30 | Henrik Grubbström (Grubba) | |
|
0d7c54 | 2014-05-20 | Per Hedbor | | while(UNLIKELY(close(control_pipe[1]) < 0) && UNLIKELY(errno==EINTR));
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | |
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | free_perishables(&storage);
|
805834 | 1998-06-25 | Henrik Grubbström (Grubba) | |
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | pop_n_elems(Pike_sp - stack_save);
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | |
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
#ifdef USE_SIGCHILD
|
a4a172 | 2000-12-05 | Per Hedbor | |
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | if(!signal_evaluator_callback)
{
signal_evaluator_callback=add_to_callback(&evaluator_callbacks,
check_signals,
0,0);
|
424d9c | 1999-05-02 | Fredrik Hübinette (Hubbe) | | dmalloc_accept_leak(signal_evaluator_callback);
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | }
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | #endif
|
0144fe | 1998-11-30 | Henrik Grubbström (Grubba) | | THIS->pid = pid;
THIS->state = PROCESS_RUNNING;
|
628cd2 | 2000-08-13 | Henrik Grubbström (Grubba) | | ref_push_object(Pike_fp->current_object);
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | push_int(pid);
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | mapping_insert(pid_mapping, Pike_sp-1, Pike_sp-2);
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | pop_n_elems(2);
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | |
buf[0] = 0;
|
46fb4a | 1999-09-11 | Fredrik Hübinette (Hubbe) | |
|
a4b2dd | 2003-03-16 | Henrik Grubbström (Grubba) | | THREADS_ALLOW();
|
68aab5 | 2003-03-16 | Henrik Grubbström (Grubba) | |
|
bf782a | 2003-12-01 | Henrik Grubbström (Grubba) | | #ifndef HAVE_VFORK
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] Parent: Wake up child.\n", getpid());
|
0d7c54 | 2014-05-20 | Per Hedbor | | while (UNLIKELY(((e = write(control_pipe[0], buf, 1)) < 0)) && UNLIKELY(errno == EINTR))
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | | ;
|
1a6879 | 1999-03-13 | Henrik Grubbström (Grubba) | | if(e!=1) {
|
80923b | 1999-05-01 | Henrik Grubbström (Grubba) | | olderrno = errno;
|
0d7c54 | 2014-05-20 | Per Hedbor | | while(UNLIKELY(close(control_pipe[0]) < 0) && UNLIKELY(errno==EINTR))
|
a4b2dd | 2003-03-16 | Henrik Grubbström (Grubba) | | ;
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("Child process died prematurely. (e=%d errno=%d)\n",
|
42c95b | 2003-03-03 | Henrik Grubbström (Grubba) | | e ,olderrno);
|
1a6879 | 1999-03-13 | Henrik Grubbström (Grubba) | | }
|
bf782a | 2003-12-01 | Henrik Grubbström (Grubba) | | #endif /* !HAVE_VFORK */
|
1e3da5 | 1999-01-07 | Fredrik Hübinette (Hubbe) | |
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] Parent: Wait for child...\n", getpid());
|
a4a172 | 2000-12-05 | Per Hedbor | |
|
6a9cbc | 2006-04-05 | Henrik Grubbström (Grubba) | | #if defined(EBADF) && defined(EPIPE)
|
0d7c54 | 2014-05-20 | Per Hedbor | | while (UNLIKELY((e = read(control_pipe[0], buf, 3)) < 0) &&
|
d56a96 | 2016-09-23 | Tobias S. Josefowitz | | (errno == EINTR ||
(LIKELY(errno != EBADF) && (errno != EPIPE) && (cnt++ < 16))))
|
6a9cbc | 2006-04-05 | Henrik Grubbström (Grubba) | | ;
#else /* !EBADF || !EPIPE */
|
0d7c54 | 2014-05-20 | Per Hedbor | | while (UNLIKELY((e = read(control_pipe[0], buf, 3)) < 0) && (errno == EINTR))
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | | ;
|
6a9cbc | 2006-04-05 | Henrik Grubbström (Grubba) | | #endif /* EBADF && EPIPE */
|
80923b | 1999-05-01 | Henrik Grubbström (Grubba) | |
olderrno = errno;
|
d887b6 | 1999-05-26 | Fredrik Hübinette (Hubbe) | |
|
0d7c54 | 2014-05-20 | Per Hedbor | | while(UNLIKELY(close(control_pipe[0]) < 0) && UNLIKELY(errno==EINTR));
|
68aab5 | 2003-03-16 | Henrik Grubbström (Grubba) | |
THREADS_DISALLOW();
|
46fb4a | 1999-09-11 | Fredrik Hübinette (Hubbe) | |
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] Parent: Child init done.\n", getpid());
|
a4b2dd | 2003-03-16 | Henrik Grubbström (Grubba) | |
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | | if (!e) {
|
0144fe | 1998-11-30 | Henrik Grubbström (Grubba) | | pop_n_elems(args);
|
05e4e2 | 2016-12-12 | Martin Nilsson | | return;
|
c2eb24 | 2003-11-21 | Henrik Grubbström (Grubba) | | } else if (e < 0) {
#ifdef ENODEV
if (olderrno == ENODEV) {
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("read(2) failed with ENODEV. Probable operating system bug.\n");
|
c2eb24 | 2003-11-21 | Henrik Grubbström (Grubba) | | }
#endif /* ENODEV */
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("read(2) failed with errno %d.\n", olderrno);
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | | } else {
|
c2eb24 | 2003-11-21 | Henrik Grubbström (Grubba) | |
|
64f945 | 1998-11-29 | Henrik Grubbström (Grubba) | | switch(buf[0]) {
case PROCE_CHDIR:
|
28370c | 2013-02-01 | Henrik Grubbström (Grubba) | | if (buf[2]) {
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("chdir(\"/\") in chroot failed. errno:%d.\n", buf[1]);
|
28370c | 2013-02-01 | Henrik Grubbström (Grubba) | | }
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("chdir() failed. errno:%d.\n", buf[1]);
|
64f945 | 1998-11-29 | Henrik Grubbström (Grubba) | | break;
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | case PROCE_DUP:
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("dup() failed. errno:%d.\n", buf[1]);
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | break;
|
64f945 | 1998-11-29 | Henrik Grubbström (Grubba) | | case PROCE_DUP2:
|
ca7534 | 2000-01-27 | Henrik Grubbström (Grubba) | | if (buf[1] == EINVAL) {
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("dup2(x, %d) failed with EINVAL.\n", buf[2]);
|
ca7534 | 2000-01-27 | Henrik Grubbström (Grubba) | | }
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("dup2(x, %d) failed. errno:%d.\n", buf[2], buf[1]);
|
64f945 | 1998-11-29 | Henrik Grubbström (Grubba) | | break;
case PROCE_SETGID:
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("setgid(%d) failed. errno:%d\n", buf[2], buf[1]);
|
64f945 | 1998-11-29 | Henrik Grubbström (Grubba) | | break;
|
bccf0c | 2000-07-11 | David Hedbor | | #ifdef HAVE_SETGROUPS
|
64f945 | 1998-11-29 | Henrik Grubbström (Grubba) | | case PROCE_SETGROUPS:
|
ca7534 | 2000-01-27 | Henrik Grubbström (Grubba) | | if (buf[1] == EINVAL) {
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("setgroups() failed with EINVAL.\n"
|
42c95b | 2003-03-03 | Henrik Grubbström (Grubba) | | "Too many supplementary groups (%d)?\n",
storage.num_wanted_gids);
|
ca7534 | 2000-01-27 | Henrik Grubbström (Grubba) | | }
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("setgroups() failed. errno:%d.\n", buf[1]);
|
64f945 | 1998-11-29 | Henrik Grubbström (Grubba) | | break;
|
bccf0c | 2000-07-11 | David Hedbor | | #endif
|
64f945 | 1998-11-29 | Henrik Grubbström (Grubba) | | case PROCE_GETPWUID:
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("getpwuid(%d) failed. errno:%d.\n", buf[2], buf[1]);
|
64f945 | 1998-11-29 | Henrik Grubbström (Grubba) | | break;
case PROCE_INITGROUPS:
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("initgroups() failed. errno:%d.\n", buf[1]);
|
64f945 | 1998-11-29 | Henrik Grubbström (Grubba) | | break;
case PROCE_SETUID:
|
ca7534 | 2000-01-27 | Henrik Grubbström (Grubba) | | if (buf[1] == EINVAL) {
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("Invalid uid: %d.\n", (int)wanted_uid);
|
ca7534 | 2000-01-27 | Henrik Grubbström (Grubba) | | }
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("setuid(%d) failed. errno:%d.\n", buf[2], buf[1]);
|
64f945 | 1998-11-29 | Henrik Grubbström (Grubba) | | break;
|
8f6385 | 2000-09-16 | Mirar (Pontus Hagland) | | case PROCE_SETSID:
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("setsid() failed.\n");
|
8f6385 | 2000-09-16 | Mirar (Pontus Hagland) | | break;
|
06dda5 | 2002-08-21 | Marcus Comstedt | | case PROCE_SETCTTY:
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("Failed to set controlling TTY. errno:%d.\n", buf[1]);
|
06dda5 | 2002-08-21 | Marcus Comstedt | | break;
|
64f945 | 1998-11-29 | Henrik Grubbström (Grubba) | | case PROCE_EXEC:
|
cb250e | 2001-10-10 | Henrik Grubbström (Grubba) | | switch(buf[1]) {
case ENOENT:
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("Executable file not found.\n");
|
cb250e | 2001-10-10 | Henrik Grubbström (Grubba) | | break;
case EACCES:
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("Access denied.\n");
|
cb250e | 2001-10-10 | Henrik Grubbström (Grubba) | | break;
#ifdef E2BIG
case E2BIG:
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("Arglist too long.\n");
|
cb250e | 2001-10-10 | Henrik Grubbström (Grubba) | | break;
#endif /* E2BIG */
|
ca7534 | 2000-01-27 | Henrik Grubbström (Grubba) | | }
|
fb4549 | 2014-05-20 | Per Hedbor | |
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("exec() failed. errno:%d. File not found?\n", buf[1]);
|
64f945 | 1998-11-29 | Henrik Grubbström (Grubba) | | break;
|
d887b6 | 1999-05-26 | Fredrik Hübinette (Hubbe) | | case PROCE_CLOEXEC:
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("set_close_on_exec(%d, 1) failed. errno:%d.\n",
|
493ee5 | 2004-07-02 | Henrik Grubbström (Grubba) | | buf[2], buf[1]);
break;
case PROCE_CLRCLOEXEC:
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("set_close_on_exec(%d, 0) failed. errno:%d.\n",
|
493ee5 | 2004-07-02 | Henrik Grubbström (Grubba) | | buf[2], buf[1]);
|
d887b6 | 1999-05-26 | Fredrik Hübinette (Hubbe) | | break;
|
5c70db | 2003-12-05 | Henrik Grubbström (Grubba) | | case PROCE_CHROOT:
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("chroot() failed. errno:%d.\n", buf[1]);
|
5c70db | 2003-12-05 | Henrik Grubbström (Grubba) | | break;
|
64f945 | 1998-11-29 | Henrik Grubbström (Grubba) | | case 0:
default:
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("Child failed: %d, %d, %d, %d, %d!\n",
|
42c95b | 2003-03-03 | Henrik Grubbström (Grubba) | | buf[0], buf[1], buf[2], e, olderrno);
|
64f945 | 1998-11-29 | Henrik Grubbström (Grubba) | | break;
}
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | | }
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | }else{
|
0144fe | 1998-11-30 | Henrik Grubbström (Grubba) | | |
e97495 | 2013-01-01 | Henrik Grubbström (Grubba) | | *
* NB: Avoid calling any functions in libc here, since
* internal mutexes may be held by other nonforked
* threads.
|
0144fe | 1998-11-30 | Henrik Grubbström (Grubba) | | */
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #ifdef DECLARE_ENVIRON
extern char **environ;
#endif
extern void my_set_close_on_exec(int,int);
extern void do_set_close_on_exec(void);
|
b3752c | 2001-06-20 | Henrik Grubbström (Grubba) | | #ifdef PROC_DEBUG
|
e97495 | 2013-01-01 | Henrik Grubbström (Grubba) | | char debug_prefix[] = {
'[',
'0' + (getpid()/100000)%10,
'0' + (getpid()/10000)%10,
'0' + (getpid()/1000)%10,
'0' + (getpid()/100)%10,
'0' + (getpid()/10)%10,
'0' + getpid()%10,
']',
' ',
};
write(2, debug_prefix, sizeof(debug_prefix));
|
b3752c | 2001-06-20 | Henrik Grubbström (Grubba) | | write(2, "Child\n", 6);
#endif /* PROC_DEBUG */
|
06dda5 | 2002-08-21 | Marcus Comstedt | | pid = getpid();
|
0144fe | 1998-11-30 | Henrik Grubbström (Grubba) | |
|
0d7c54 | 2014-05-20 | Per Hedbor | | while(UNLIKELY(close(control_pipe[0]) < 0) && UNLIKELY(errno==EINTR));
|
d887b6 | 1999-05-26 | Fredrik Hübinette (Hubbe) | |
|
bf782a | 2003-12-01 | Henrik Grubbström (Grubba) | | #ifndef HAVE_VFORK
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | |
|
0d7c54 | 2014-05-20 | Per Hedbor | | while (UNLIKELY((( e = read(control_pipe[1], buf, 1)) < 0)) && UNLIKELY((errno == EINTR)))
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | | ;
|
a4b2dd | 2003-03-16 | Henrik Grubbström (Grubba) | | #ifdef PROC_DEBUG
|
e97495 | 2013-01-01 | Henrik Grubbström (Grubba) | | if (e < 0) {
char buf[5] = {
'0' + (errno/1000)%10,
'0' + (errno/100)%10,
'0' + (errno/10)%10,
'0' + errno%10,
'\n'
};
write(2, debug_prefix, sizeof(debug_prefix));
write(2, "Child: Control pipe read failed with errno: ", 44);
write(2, buf, 5);
} else if (!e) {
write(2, debug_prefix, sizeof(debug_prefix));
write(2, "Child: No data from control pipe.\n", 34);
}
write(2, debug_prefix, sizeof(debug_prefix));
|
a4b2dd | 2003-03-16 | Henrik Grubbström (Grubba) | | write(2, "Child: Woken up.\n", 17);
#endif /* PROC_DEBUG */
|
bf782a | 2003-12-01 | Henrik Grubbström (Grubba) | | #endif /* HAVE_VFORK */
|
303a83 | 2001-09-26 | Fredrik Hübinette (Hubbe) | | for(e=0;e<cmd->size;e++) storage.argv[e]=cmd->item[e].u.string->str;
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | storage.argv[e]=0;
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | |
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | if(storage.env) environ=storage.env;
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | |
#ifdef HAVE_SETEUID
|
dffabf | 2014-02-24 | Per Hedbor | | if( seteuid(0) == -1 ) {
}
|
9a8c98 | 1998-03-03 | Henrik Grubbström (Grubba) | | #else /* !HAVE_SETEUID */
#ifdef HAVE_SETRESUID
setresuid(0,0,-1);
#endif /* HAVE_SETRESUID */
#endif /* HAVE_SETEUID */
|
0d52dd | 1998-01-16 | Fredrik Hübinette (Hubbe) | |
|
fb4549 | 2014-05-20 | Per Hedbor | | if (!keep_signals)
|
72850a | 1999-02-01 | Per Hedbor | | {
|
5f3285 | 2007-05-17 | Henrik Grubbström (Grubba) | | int i;
|
b4f022 | 1998-04-12 | Henrik Grubbström (Grubba) | |
|
15fafe | 1999-11-16 | Henrik Grubbström (Grubba) | | #ifdef _sys_nsig
for(i=0; i<_sys_nsig; i++)
signal(i, SIG_DFL);
#else /* !_sys_nsig */
|
54a979 | 1999-11-16 | Thomas Bellman | | for(i=0; i<NSIG; i++)
|
72850a | 1999-02-01 | Per Hedbor | | signal(i, SIG_DFL);
|
15fafe | 1999-11-16 | Henrik Grubbström (Grubba) | | #endif /* _sys_nsig */
|
b4f022 | 1998-04-12 | Henrik Grubbström (Grubba) | | }
|
a42cce | 2021-01-04 | Marcus Comstedt | | #ifdef HAVE_CHROOT
|
bd9d40 | 2003-12-05 | Stephen R. van den Berg | | if(mchroot)
{
if( chroot( mchroot ) )
{
|
293624 | 2014-05-20 | Martin Nilsson | |
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] child: chroot(\"%s\") failed, errno=%d\n",
getpid(), chroot, errno);
|
6b4714 | 2003-12-05 | Martin Nilsson | | PROCERROR(PROCE_CHROOT, 0);
|
bd9d40 | 2003-12-05 | Stephen R. van den Berg | | }
|
28370c | 2013-02-01 | Henrik Grubbström (Grubba) | | if (chdir("/"))
{
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] child: chdir(\"/\") failed, errno=%d\n",
getpid(), errno);
|
28370c | 2013-02-01 | Henrik Grubbström (Grubba) | | PROCERROR(PROCE_CHDIR, 1);
}
|
bd9d40 | 2003-12-05 | Stephen R. van den Berg | | }
|
a42cce | 2021-01-04 | Marcus Comstedt | | #endif
|
bd9d40 | 2003-12-05 | Stephen R. van den Berg | |
|
72850a | 1999-02-01 | Per Hedbor | | if(tmp_cwd)
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | {
|
72850a | 1999-02-01 | Per Hedbor | | if( chdir( tmp_cwd ) )
{
|
293624 | 2014-05-20 | Martin Nilsson | |
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] child: chdir(\"%s\") failed, errno=%d\n",
getpid(), tmp_cwd, errno);
|
72850a | 1999-02-01 | Per Hedbor | | PROCERROR(PROCE_CHDIR, 0);
}
}
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
|
c7cfc9 | 1998-01-20 | Henrik Grubbström (Grubba) | | #ifdef HAVE_NICE
|
72850a | 1999-02-01 | Per Hedbor | | if(nice_val)
|
dffabf | 2014-02-24 | Per Hedbor | | if( nice(nice_val) == -1 )
{
}
|
72850a | 1999-02-01 | Per Hedbor | | #endif
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
|
72850a | 1999-02-01 | Per Hedbor | | #ifdef HAVE_SETRLIMIT
if(storage.limits)
{
|
f1e4ee | 2003-03-06 | Henrik Grubbström (Grubba) | | struct pike_limit *l = storage.limits;
|
72850a | 1999-02-01 | Per Hedbor | | while(l)
{
setrlimit( l->resource, &l->rlp );
l = l->next;
}
}
#endif
|
0d52dd | 1998-01-16 | Fredrik Hübinette (Hubbe) | |
|
06dda5 | 2002-08-21 | Marcus Comstedt | | #ifdef HAVE_SETSID
if (setsid_request) {
int fd;
#ifdef TIOCNOTTY
fd = open("/dev/tty", O_RDWR | O_NOCTTY);
if (fd >= 0) {
(void) ioctl(fd, TIOCNOTTY, NULL);
close(fd);
}
#endif
if (setsid()==-1)
PROCERROR(PROCE_SETSID,0);
#ifdef TCSETCTTY
if (cterm >= 0)
if (ioctl(cterm, TCSETCTTY, NULL)<0)
PROCERROR(PROCE_SETCTTY,0);
#else
if (cterm >= 0) {
char *ttn;
#ifdef TIOCSCTTY
if (ioctl(cterm, TIOCSCTTY, NULL)<0)
PROCERROR(PROCE_SETCTTY,0);
#endif
ttn = ttyname(cterm);
if (ttn == NULL)
PROCERROR(PROCE_SETCTTY,0);
fd = open(ttn, O_RDWR);
if (fd < 0)
PROCERROR(PROCE_SETCTTY,0);
close(fd);
}
#endif
}
#endif
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | |
|
72850a | 1999-02-01 | Per Hedbor | | {
|
6465ab | 2002-04-26 | Henrik Grubbström (Grubba) | | int fd;
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | |
for (fd=0; fd<num_fds; fd++) {
|
493ee5 | 2004-07-02 | Henrik Grubbström (Grubba) | |
if (fds[fd] == -1) continue;
if (fds[fd] == fd) {
int code = set_close_on_exec(fd, 0);
if (code < 0)
PROCERROR(PROCE_CLRCLOEXEC, fd);
continue;
}
if (fd == control_pipe[1]) {
int remapped;
if ((remapped = dup(fd)) < 0)
PROCERROR(PROCE_DUP, fd);
control_pipe[1] = remapped;
} else {
int fd2;
int remapped = -1;
for (fd2 = fd+1; fd2 < num_fds; fd2++) {
if (fds[fd2] == fd) {
|
940a4b | 2005-05-25 | Henrik Grubbström (Grubba) | | |
493ee5 | 2004-07-02 | Henrik Grubbström (Grubba) | | * since it's in the way
*/
if (remapped == -1) {
if ((remapped = dup(fd)) < 0)
PROCERROR(PROCE_DUP, fd);
}
fds[fd2] = remapped;
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | }
}
}
if (dup2(fds[fd], fd) < 0)
PROCERROR(PROCE_DUP2, fd);
|
493ee5 | 2004-07-02 | Henrik Grubbström (Grubba) | |
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | }
for (fd=0; fd<num_fds; fd++) {
if (fds[fd] > 2) {
if ((fds[fd] >= num_fds) ||
(fds[fds[fd]] == -1)) {
|
493ee5 | 2004-07-02 | Henrik Grubbström (Grubba) | |
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | | close(fds[fd]);
}
}
}
|
1e1ebe | 2002-04-24 | Jonas Wallden | |
|
6ace4f | 2006-04-24 | Henrik Grubbström (Grubba) | | #ifdef HAVE_FDWALK
{
struct fd_cleanup_info info = {
num_fds, control_pipe[1],
};
fdwalk(fd_cleanup_cb, &info);
}
#else /* !HAVE_FDWALK */
|
6465ab | 2002-04-26 | Henrik Grubbström (Grubba) | | {
int num_fail = 0;
|
1f3ce3 | 2002-10-03 | Martin Stjernholm | | #ifdef _SC_OPEN_MAX
|
6465ab | 2002-04-26 | Henrik Grubbström (Grubba) | | int max_fds = sysconf(_SC_OPEN_MAX);
|
1f3ce3 | 2002-10-03 | Martin Stjernholm | | #endif
for (fd = num_fds;
#ifdef _SC_OPEN_MAX
fd < max_fds;
#else
1;
#endif
fd++) {
|
6ace4f | 2006-04-24 | Henrik Grubbström (Grubba) | | #ifdef HAVE_CLOSEFROM
if (fd > control_pipe[1]) {
|
9b5600 | 2006-05-02 | Henrik Grubbström (Grubba) | |
|
6ace4f | 2006-04-24 | Henrik Grubbström (Grubba) | | do {
errno = 0;
closefrom(fd);
|
9b5600 | 2006-05-02 | Henrik Grubbström (Grubba) | |
|
0d7c54 | 2014-05-20 | Per Hedbor | | } while (UNLIKELY(errno && (errno != EBADF)));
|
6ace4f | 2006-04-24 | Henrik Grubbström (Grubba) | | break;
}
#endif
|
493ee5 | 2004-07-02 | Henrik Grubbström (Grubba) | | #ifdef HAVE_BROKEN_F_SETFD
|
6465ab | 2002-04-26 | Henrik Grubbström (Grubba) | | int code = 0;
if (fd != control_pipe[1]) {
code = close(fd);
|
493ee5 | 2004-07-02 | Henrik Grubbström (Grubba) | | }
|
1e1ebe | 2002-04-24 | Jonas Wallden | | #else /* !HAVE_BROKEN_F_SETFD */
|
493ee5 | 2004-07-02 | Henrik Grubbström (Grubba) | |
int code = set_close_on_exec(fd, 1);
|
1e1ebe | 2002-04-24 | Jonas Wallden | | #endif /* HAVE_BROKEN_F_SETFD */
|
6465ab | 2002-04-26 | Henrik Grubbström (Grubba) | | if (code == -1) {
if (++num_fail >= PIKE_BADF_LIMIT) {
break;
}
} else {
|
493ee5 | 2004-07-02 | Henrik Grubbström (Grubba) | |
|
6465ab | 2002-04-26 | Henrik Grubbström (Grubba) | | num_fail = 0;
}
}
}
|
6ace4f | 2006-04-24 | Henrik Grubbström (Grubba) | | #endif /* HAVE_FDWALK */
|
47a745 | 2000-01-14 | Henrik Grubbström (Grubba) | |
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | }
|
0d52dd | 1998-01-16 | Fredrik Hübinette (Hubbe) | |
|
493ee5 | 2004-07-02 | Henrik Grubbström (Grubba) | |
if(set_close_on_exec(control_pipe[1], 1) < 0)
PROCERROR(PROCE_CLOEXEC, control_pipe[1]);
|
72850a | 1999-02-01 | Per Hedbor | | if(priority)
set_priority( 0, priority );
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_SETGID
#ifdef HAVE_GETGID
if(wanted_gid != getgid())
#endif
{
if(setgid(wanted_gid))
#ifdef _HPUX_SOURCE
if(wanted_gid > 60000 && setgid(-2) && setgid(65534) && setgid(60001))
#endif
|
7dd197 | 1998-10-02 | Henrik Grubbström (Grubba) | | {
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | | PROCERROR(PROCE_SETGID, (int)wanted_gid);
|
7dd197 | 1998-10-02 | Henrik Grubbström (Grubba) | | }
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | | }
|
0d52dd | 1998-01-16 | Fredrik Hübinette (Hubbe) | | #endif
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_SETGROUPS
if(storage.wanted_gids)
{
if(setgroups(storage.num_wanted_gids, storage.wanted_gids))
{
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | | PROCERROR(PROCE_SETGROUPS,0);
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | }
}
#endif
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_SETUID
#ifdef HAVE_GETUID
if(wanted_uid != getuid())
#endif
{
#ifdef HAVE_INITGROUPS
if(do_initgroups)
{
int initgroupgid;
if(!pw) pw=getpwuid(wanted_uid);
|
90143c | 1998-08-12 | Henrik Grubbström (Grubba) | | if(!pw) {
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | | PROCERROR(PROCE_GETPWUID, wanted_uid);
|
90143c | 1998-08-12 | Henrik Grubbström (Grubba) | | }
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | | initgroupgid=pw->pw_gid;
if(initgroups(pw->pw_name, initgroupgid))
#ifdef _HPUX_SOURCE
|
b7fc92 | 1998-08-09 | Henrik Grubbström (Grubba) | | if((initgroupgid > 60000) &&
initgroups(pw->pw_name, -2) &&
initgroups(pw->pw_name, 65534) &&
initgroups(pw->pw_name, 60001))
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | | #endif /* _HPUX_SOURCE */
{
#ifdef HAVE_SETGROUPS
gid_t x[]={ 65534 };
|
b7fc92 | 1998-08-09 | Henrik Grubbström (Grubba) | | if(setgroups(0, x))
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | | #endif /* SETGROUPS */
|
90143c | 1998-08-12 | Henrik Grubbström (Grubba) | | {
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | |
PROCERROR(PROCE_INITGROUPS, 0);
|
90143c | 1998-08-12 | Henrik Grubbström (Grubba) | | }
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | | }
}
#endif /* INITGROUPS */
if(setuid(wanted_uid))
{
perror("setuid");
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | |
PROCERROR(PROCE_SETUID, (int)wanted_uid);
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | | }
}
#endif /* SETUID */
#ifdef HAVE_SETEUID
|
dffabf | 2014-02-24 | Per Hedbor | | if( seteuid(wanted_uid) == -1 )
{
perror("seteuid");
PROCERROR(PROCE_SETUID, (int)wanted_uid);
}
|
9a8c98 | 1998-03-03 | Henrik Grubbström (Grubba) | | #else /* !HAVE_SETEUID */
#ifdef HAVE_SETRESUID
setresuid(wanted_uid, wanted_uid, -1);
#endif /* HAVE_SETRESUID */
#endif /* HAVE_SETEUID */
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | |
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | do_set_close_on_exec();
|
f087c4 | 1998-02-04 | Fredrik Hübinette (Hubbe) | | set_close_on_exec(0,0);
set_close_on_exec(1,0);
set_close_on_exec(2,0);
|
dffabf | 2014-02-24 | Per Hedbor | |
|
5539c5 | 1998-06-08 | Henrik Grubbström (Grubba) | | #ifdef HAVE_BROKEN_F_SETFD
do_close_on_exec();
#endif /* HAVE_BROKEN_F_SETFD */
|
a4b2dd | 2003-03-16 | Henrik Grubbström (Grubba) | | #ifdef HAVE_PTRACE
if (do_trace) {
#ifdef PROC_DEBUG
|
e97495 | 2013-01-01 | Henrik Grubbström (Grubba) | | write(2, debug_prefix, sizeof(debug_prefix));
|
a4b2dd | 2003-03-16 | Henrik Grubbström (Grubba) | | write(2, "Child: Calling ptrace()...\n", 27);
#endif /* PROC_DEBUG */
|
158853 | 2012-12-29 | Jonas Walldén | | ptrace(PTRACE_TRACEME, 0, NULL, 0);
|
a4b2dd | 2003-03-16 | Henrik Grubbström (Grubba) | | }
#endif /* HAVE_PTRACE */
|
dffabf | 2014-02-24 | Per Hedbor | |
|
a4b2dd | 2003-03-16 | Henrik Grubbström (Grubba) | | #ifdef PROC_DEBUG
|
e97495 | 2013-01-01 | Henrik Grubbström (Grubba) | | write(2, debug_prefix, sizeof(debug_prefix));
|
a4b2dd | 2003-03-16 | Henrik Grubbström (Grubba) | | write(2, "Child: Calling exec()...\n", 25);
#endif /* PROC_DEBUG */
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | execvp(storage.argv[0],storage.argv);
|
392e4b | 2004-04-01 | Henrik Grubbström (Grubba) | |
|
293624 | 2014-05-20 | Martin Nilsson | |
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] Child: execvp(\"%s\", ...) failed\n"
"errno = %d\n",
getpid(), storage.argv[0], errno);
|
a4b2dd | 2003-03-16 | Henrik Grubbström (Grubba) | | #ifndef HAVE_BROKEN_F_SETFD
|
77ae43 | 1998-11-29 | Henrik Grubbström (Grubba) | |
PROCERROR(PROCE_EXEC, 0);
#endif /* HAVE_BROKEN_F_SETFD */
exit(99);
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | }
}
|
0c9594 | 2018-01-12 | Stephen R. van den Berg | | #endif /* __amigaos__ */
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #endif /* __NT__ */
pop_n_elems(args);
}
#ifdef HAVE_FORK
|
4c74bf | 2003-04-30 | Martin Nilsson | | |
ee18f3 | 2001-02-09 | Henrik Grubbström (Grubba) | | *!
*! Fork the process in two.
*!
|
4c74bf | 2003-04-30 | Martin Nilsson | | *! Fork splits the process in two, and for the parent it returns a
*! pid object for the child. Refer to your Unix manual for further
*! details.
|
ee18f3 | 2001-02-09 | Henrik Grubbström (Grubba) | | *!
*! @note
*! This function can cause endless bugs if used without proper care.
*!
*! This function is disabled when using threads.
*!
|
45f2a2 | 2002-09-10 | Martin Nilsson | | *! This function is not available on all platforms.
*!
|
ee18f3 | 2001-02-09 | Henrik Grubbström (Grubba) | | *! The most common use for fork is to start sub programs, which is
*! better done with @[Process.create_process()].
*!
*! @seealso
*! @[Process.create_process()]
*/
|
cfbc2e | 2000-03-21 | Fredrik Hübinette (Hubbe) | | void Pike_f_fork(INT32 args)
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | {
struct object *o;
pid_t pid;
pop_n_elems(args);
|
ba510c | 1998-03-27 | Henrik Grubbström (Grubba) | |
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | #ifdef _REENTRANT
if(num_threads >1)
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | Pike_error("You cannot use fork in a multithreaded application.\n");
|
965cb1 | 1998-04-06 | Fredrik Hübinette (Hubbe) | | #endif
|
71ac9e | 1999-08-29 | Fredrik Hübinette (Hubbe) | | th_atfork_prepare();
|
3d56e1 | 1999-01-07 | Fredrik Hübinette (Hubbe) | |
|
a96cca | 2004-10-22 | Henrik Grubbström (Grubba) | | #if defined(HAVE_FORK1) && defined(_REENTRANT)
|
b0d10a | 1999-03-07 | Henrik Grubbström (Grubba) | | |
a96cca | 2004-10-22 | Henrik Grubbström (Grubba) | | *
* Reenabled since fork() usually performs a fork1() anyway.
* /grubba 2004-04-02
|
b0d10a | 1999-03-07 | Henrik Grubbström (Grubba) | | */
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | pid=fork1();
#else
pid=fork();
#endif
|
3d56e1 | 1999-01-07 | Fredrik Hübinette (Hubbe) | |
|
ba510c | 1998-03-27 | Henrik Grubbström (Grubba) | |
|
57f53c | 1999-09-25 | Henrik Grubbström (Grubba) | | if(pid) {
|
a8df4e | 2003-11-21 | Henrik Grubbström (Grubba) | | #ifdef USE_WAIT_THREAD
if (!wait_thread_running) {
THREAD_T foo;
if (th_create_small(&foo, wait_thread, 0)) {
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("Failed to create wait thread. errno: %d.\n", errno);
|
a8df4e | 2003-11-21 | Henrik Grubbström (Grubba) | | }
wait_thread_running = 1;
}
num_threads++;
#endif
|
fec300 | 1999-08-30 | Fredrik Hübinette (Hubbe) | | th_atfork_parent();
|
57f53c | 1999-09-25 | Henrik Grubbström (Grubba) | | } else {
|
fec300 | 1999-08-30 | Fredrik Hübinette (Hubbe) | | th_atfork_child();
|
1b3ff5 | 2004-06-15 | Henrik Grubbström (Grubba) | | DO_IF_PROFILING({
struct pike_frame *frame = Pike_fp;
cpu_time_t now = get_cpu_time();
Pike_interpreter.unlocked_time = 0;
Pike_interpreter.accounted_time = 0;
while(frame) {
frame->start_time = now;
frame->children_base = 0;
frame = frame->next;
}
});
|
ba5857 | 2008-07-09 | Henrik Grubbström (Grubba) | | in_forked_child = 1;
|
57f53c | 1999-09-25 | Henrik Grubbström (Grubba) | | }
|
13670c | 2015-05-25 | Martin Nilsson | |
|
1b6dba | 1998-05-19 | Henrik Grubbström (Grubba) | | if(pid==-1) {
|
d3a1c8 | 2014-10-31 | Martin Nilsson | | Pike_error("Fork failed. errno:%d.\n", errno);
|
1b6dba | 1998-05-19 | Henrik Grubbström (Grubba) | | }
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
if(pid)
{
struct pid_status *p;
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | |
|
a2e200 | 2003-09-30 | Martin Stjernholm | | process_started(pid);
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | #ifdef USE_SIGCHILD
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | if(!signal_evaluator_callback)
{
signal_evaluator_callback=add_to_callback(&evaluator_callbacks,
check_signals,
0,0);
|
424d9c | 1999-05-02 | Fredrik Hübinette (Hubbe) | | dmalloc_accept_leak(signal_evaluator_callback);
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | }
|
70e978 | 1999-03-06 | Fredrik Hübinette (Hubbe) | | #endif
|
cff634 | 2017-06-17 | Martin Nilsson | | o=fast_clone_object(pid_status_program);
|
13b5ed | 2014-05-26 | Per Hedbor | | p=get_storage(o,pid_status_program);
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | p->pid=pid;
p->state=PROCESS_RUNNING;
push_object(o);
push_int(pid);
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | mapping_insert(pid_mapping,Pike_sp-1, Pike_sp-2);
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | pop_stack();
}else{
#ifdef _REENTRANT
num_threads=1;
#endif
|
23c513 | 2017-10-03 | Per Cederqvist | |
REINIT_FIFO(sig, unsigned char);
REINIT_FIFO(wait,wait_data);
|
a92ad6 | 2003-10-13 | Henrik Grubbström (Grubba) | |
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | call_callback(&fork_child_callback, 0);
push_int(0);
}
}
|
a96cca | 2004-10-22 | Henrik Grubbström (Grubba) | |
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #endif /* HAVE_FORK */
#ifdef HAVE_KILL
|
2f7050 | 2014-07-10 | Henrik Grubbström (Grubba) | | |
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *!
|
2f7050 | 2014-07-10 | Henrik Grubbström (Grubba) | | *! Send a signal to another process.
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *!
*! Some signals and their supposed purpose:
*! @int
*! @value SIGHUP
*! Hang-up, sent to process when user logs out.
*! @value SIGINT
*! Interrupt, normally sent by ctrl-c.
*! @value SIGQUIT
*! Quit, sent by ctrl-\.
*! @value SIGILL
*! Illegal instruction.
*! @value SIGTRAP
*! Trap, mostly used by debuggers.
*! @value SIGABRT
*! Aborts process, can be caught, used by Pike whenever something
*! goes seriously wrong.
|
0da61a | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @value SIGEMT
*! Emulation trap.
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @value SIGFPE
*! Floating point error (such as division by zero).
*! @value SIGKILL
*! Really kill a process, cannot be caught.
|
0da61a | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @value SIGBUS
*! Bus error.
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @value SIGSEGV
*! Segmentation fault, caused by accessing memory where you
*! shouldn't. Should never happen to Pike.
|
0da61a | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @value SIGSYS
*! Bad system call. Should never happen to Pike.
*! @value SIGPIPE
*! Broken pipe.
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @value SIGALRM
*! Signal used for timer interrupts.
*! @value SIGTERM
*! Termination signal.
|
0da61a | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @value SIGUSR1
*! Signal reserved for whatever you want to use it for.
*! Note that some OSs reserve this signal for the thread library.
*! @value SIGUSR2
*! Signal reserved for whatever you want to use it for.
*! Note that some OSs reserve this signal for the thread library.
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @value SIGCHLD
*! Child process died. This signal is reserved for internal use
*! by the Pike run-time.
|
0da61a | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @value SIGPWR
*! Power failure or restart.
*! @value SIGWINCH
*! Window change signal.
*! @value SIGURG
*! Urgent socket data.
*! @value SIGIO
*! Pollable event.
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @value SIGSTOP
*! Stop (suspend) process.
|
0da61a | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @value SIGTSTP
*! Stop (suspend) process. Sent by ctrl-z.
*! @value SIGCONT
*! Continue suspended.
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @value SIGTTIN
*! TTY input for background process.
*! @value SIGTTOU
*! TTY output for background process.
|
0da61a | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @value SIGVTALRM
*! Virtual timer expired.
*! @value SIGPROF
*! Profiling trap.
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @value SIGXCPU
*! Out of CPU.
*! @value SIGXFSZ
*! File size limit exceeded.
|
0da61a | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @value SIGSTKFLT
*! Stack fault
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @endint
*!
|
2f7050 | 2014-07-10 | Henrik Grubbström (Grubba) | | *! @returns
*! @int
*! @value 1
*! Success.
*! @value 0
*! Failure. @[errno()] is set to EINVAL, EPERM or ESRCH.
*! @endint
*!
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @note
*! Note that you have to use signame to translate the name of a signal
*! to its number.
*!
|
45f2a2 | 2002-09-10 | Martin Nilsson | | *! Note that the kill function is not available on platforms that do not
|
27b40e | 2002-09-10 | Henrik Grubbström (Grubba) | | *! support signals. Some platforms may also have signals not listed here.
|
0da61a | 2001-01-31 | Henrik Grubbström (Grubba) | | *!
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @seealso
*! @[signal()], @[signum()], @[signame()], @[fork()]
*/
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | static void f_kill(INT32 args)
{
|
ba510c | 1998-03-27 | Henrik Grubbström (Grubba) | | int signum;
|
571f0a | 2001-03-29 | Henrik Grubbström (Grubba) | | int pid = 0;
|
0c6a6c | 2002-04-16 | Martin Stjernholm | | int res, save_errno;
|
ba510c | 1998-03-27 | Henrik Grubbström (Grubba) | |
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | if(args < 2)
|
06bd61 | 2016-01-26 | Martin Nilsson | | SIMPLE_WRONG_NUM_ARGS_ERROR("kill", 2);
|
b3cc13 | 1998-01-15 | Fredrik Hübinette (Hubbe) | |
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | switch(TYPEOF(Pike_sp[-args]))
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | {
|
fe2c20 | 2003-04-14 | Henrik Grubbström (Grubba) | | case PIKE_T_INT:
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | pid = Pike_sp[-args].u.integer;
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | break;
|
53acc2 | 1999-05-24 | Henrik Grubbström (Grubba) | |
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | default:
|
f98274 | 2016-01-26 | Martin Nilsson | | SIMPLE_ARG_TYPE_ERROR("kill", 1, "int");
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | }
|
13670c | 2015-05-25 | Martin Nilsson | |
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(Pike_sp[1-args]) != PIKE_T_INT)
|
f98274 | 2016-01-26 | Martin Nilsson | | SIMPLE_ARG_TYPE_ERROR("kill", 2, "int");
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | |
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | signum = Pike_sp[1-args].u.integer;
|
ba510c | 1998-03-27 | Henrik Grubbström (Grubba) | |
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] kill: pid=%d, signum=%d\n", getpid(), pid, signum);
|
53acc2 | 1999-05-24 | Henrik Grubbström (Grubba) | |
|
ba510c | 1998-03-27 | Henrik Grubbström (Grubba) | | THREADS_ALLOW_UID();
res = !kill(pid, signum);
|
0c6a6c | 2002-04-16 | Martin Stjernholm | | save_errno = errno;
|
ba510c | 1998-03-27 | Henrik Grubbström (Grubba) | | THREADS_DISALLOW_UID();
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | check_signals(0,0,0);
|
ba510c | 1998-03-27 | Henrik Grubbström (Grubba) | | pop_n_elems(args);
push_int(res);
|
0c6a6c | 2002-04-16 | Martin Stjernholm | | errno = save_errno;
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | }
|
eb9a04 | 2001-08-14 | Martin Nilsson | |
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | */
|
2f7050 | 2014-07-10 | Henrik Grubbström (Grubba) | | |
0c8843 | 2006-10-31 | Martin Nilsson | | *!
*! @returns
*! @int
*! @value 1
|
2f7050 | 2014-07-10 | Henrik Grubbström (Grubba) | | *! Success.
|
0c8843 | 2006-10-31 | Martin Nilsson | | *! @value 0
|
2f7050 | 2014-07-10 | Henrik Grubbström (Grubba) | | *! Failure. @[errno()] is set to EINVAL, EPERM or ESRCH.
|
0c8843 | 2006-10-31 | Martin Nilsson | | *! @endint
|
45f2a2 | 2002-09-10 | Martin Nilsson | | *!
*! @note
*! This function is only available on platforms that
|
27b40e | 2002-09-10 | Henrik Grubbström (Grubba) | | *! support signals.
|
c67a1b | 2011-09-08 | Henrik Grubbström (Grubba) | | *!
*! @seealso
*! @[predef::kill()]
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | */
|
53acc2 | 1999-05-24 | Henrik Grubbström (Grubba) | | static void f_pid_status_kill(INT32 args)
{
int pid = THIS->pid;
INT_TYPE signum;
|
0c6a6c | 2002-04-16 | Martin Stjernholm | | int res, save_errno;
|
53acc2 | 1999-05-24 | Henrik Grubbström (Grubba) | |
|
c91b1d | 2018-08-05 | Martin Nilsson | | get_all_args(NULL, args, "%+", &signum);
|
53acc2 | 1999-05-24 | Henrik Grubbström (Grubba) | |
|
a91d9a | 2016-01-11 | Martin Nilsson | | PROC_FPRINTF("[%d] kill: pid=%d, signum=%d\n", getpid(), pid, signum);
|
53acc2 | 1999-05-24 | Henrik Grubbström (Grubba) | |
THREADS_ALLOW_UID();
res = !kill(pid, signum);
|
0c6a6c | 2002-04-16 | Martin Stjernholm | | save_errno = errno;
|
53acc2 | 1999-05-24 | Henrik Grubbström (Grubba) | | THREADS_DISALLOW_UID();
check_signals(0,0,0);
pop_n_elems(args);
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | push_int(res);
|
0c6a6c | 2002-04-16 | Martin Stjernholm | | errno = save_errno;
|
53acc2 | 1999-05-24 | Henrik Grubbström (Grubba) | | }
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | |
|
eb9a04 | 2001-08-14 | Martin Nilsson | |
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | | #else
#ifdef __NT__
|
ea5c9e | 1998-02-28 | Fredrik Hübinette (Hubbe) | | #define HAVE_KILL
|
58854e | 1999-04-11 | Fredrik Hübinette (Hubbe) | | static void f_kill(INT32 args)
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | | {
|
bd6739 | 2015-10-14 | Martin Nilsson | | HANDLE proc = INVALID_HANDLE_VALUE;
HANDLE tofree = INVALID_HANDLE_VALUE;
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | |
if(args < 2)
|
06bd61 | 2016-01-26 | Martin Nilsson | | SIMPLE_WRONG_NUM_ARGS_ERROR("kill", 2);
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | |
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | switch(TYPEOF(Pike_sp[-args]))
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | | {
|
fe2c20 | 2003-04-14 | Henrik Grubbström (Grubba) | | case PIKE_T_INT:
|
ae3688 | 1999-08-27 | Fredrik Hübinette (Hubbe) | | tofree=proc=OpenProcess(PROCESS_TERMINATE,
0,
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | Pike_sp[-args].u.integer);
|
ae3688 | 1999-08-27 | Fredrik Hübinette (Hubbe) | |
|
bd6739 | 2015-10-14 | Martin Nilsson | | if(!proc || proc == INVALID_HANDLE_VALUE)
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | | {
errno=EPERM;
pop_n_elems(args);
|
ae3688 | 1999-08-27 | Fredrik Hübinette (Hubbe) | | push_int(0);
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | | return;
}
break;
case T_OBJECT:
{
struct pid_status *p;
|
13b5ed | 2014-05-26 | Per Hedbor | | if((p=get_storage(Pike_sp[-args].u.object,
pid_status_program)))
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | | {
proc=p->handle;
break;
}
}
default:
|
f98274 | 2016-01-26 | Martin Nilsson | | SIMPLE_ARG_TYPE_ERROR("kill", 1, "int|object");
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | | }
|
13670c | 2015-05-25 | Martin Nilsson | |
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(Pike_sp[1-args]) != PIKE_T_INT)
|
f98274 | 2016-01-26 | Martin Nilsson | | SIMPLE_ARG_TYPE_ERROR("kill", 2, "int");
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | |
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | switch(Pike_sp[1-args].u.integer)
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | | {
|
ae3688 | 1999-08-27 | Fredrik Hübinette (Hubbe) | | case 0:
pop_n_elems(args);
push_int(1);
break;
|
13670c | 2015-05-25 | Martin Nilsson | |
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | | case SIGKILL:
{
|
ae3688 | 1999-08-27 | Fredrik Hübinette (Hubbe) | | int i=TerminateProcess(proc,0xff);
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | | pop_n_elems(args);
push_int(i);
check_signals(0,0,0);
break;
}
|
13670c | 2015-05-25 | Martin Nilsson | |
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | | default:
|
ea5c9e | 1998-02-28 | Fredrik Hübinette (Hubbe) | | errno=EINVAL;
pop_n_elems(args);
|
ae3688 | 1999-08-27 | Fredrik Hübinette (Hubbe) | | push_int(0);
|
ea5c9e | 1998-02-28 | Fredrik Hübinette (Hubbe) | | break;
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | | }
|
bd6739 | 2015-10-14 | Martin Nilsson | | if(tofree != INVALID_HANDLE_VALUE)
|
ae3688 | 1999-08-27 | Fredrik Hübinette (Hubbe) | | CloseHandle(tofree);
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | | }
|
53acc2 | 1999-05-24 | Henrik Grubbström (Grubba) | |
static void f_pid_status_kill(INT32 args)
{
INT_TYPE signum;
|
c91b1d | 2018-08-05 | Martin Nilsson | | get_all_args(NULL, args, "%i", &signum);
|
53acc2 | 1999-05-24 | Henrik Grubbström (Grubba) | |
pop_n_elems(args);
push_int(THIS->pid);
push_int(signum);
f_kill(2);
}
|
c33e76 | 1998-02-27 | Fredrik Hübinette (Hubbe) | | #endif
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #endif
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | |
e1ea35 | 2002-02-14 | Martin Nilsson | | *! @[System.getppid()], @[System.getpgrp()]
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | */
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | static void f_getpid(INT32 args)
{
pop_n_elems(args);
push_int(getpid());
}
|
75920f | 1997-12-28 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_ALARM
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | |
cbe8c9 | 2003-04-07 | Martin Nilsson | | *! If @[seconds] is @expr{0@} (zero), no new alarm will be scheduled.
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *!
*! Any previous alarms will in any case be canceled.
*!
*! @returns
*! Returns the number of seconds remaining until any previously
*! scheduled alarm was due to be delivered, or zero if there was
*! no previously scheduled alarm.
*!
|
45f2a2 | 2002-09-10 | Martin Nilsson | | *! @note
|
27b40e | 2002-09-10 | Henrik Grubbström (Grubba) | | *! This function is only available on platforms that support
|
45f2a2 | 2002-09-10 | Martin Nilsson | | *! signals.
*!
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @seealso
*! @[ualarm()], @[signal()], @[call_out()]
*/
|
cf2a15 | 1996-04-13 | Fredrik Hübinette (Hubbe) | | static void f_alarm(INT32 args)
{
long seconds;
if(args < 1)
|
06bd61 | 2016-01-26 | Martin Nilsson | | SIMPLE_WRONG_NUM_ARGS_ERROR("alarm", 1);
|
cf2a15 | 1996-04-13 | Fredrik Hübinette (Hubbe) | |
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(Pike_sp[-args]) != PIKE_T_INT)
|
f98274 | 2016-01-26 | Martin Nilsson | | SIMPLE_ARG_TYPE_ERROR("alarm", 1, "int");
|
cf2a15 | 1996-04-13 | Fredrik Hübinette (Hubbe) | |
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | seconds=Pike_sp[-args].u.integer;
|
cf2a15 | 1996-04-13 | Fredrik Hübinette (Hubbe) | |
pop_n_elems(args);
push_int(alarm(seconds));
}
|
75920f | 1997-12-28 | Fredrik Hübinette (Hubbe) | | #endif
|
cf2a15 | 1996-04-13 | Fredrik Hübinette (Hubbe) | |
|
d1b8ea | 1998-09-05 | Henrik Grubbström (Grubba) | | #if defined(HAVE_UALARM) || defined(HAVE_SETITIMER)
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | |
cbe8c9 | 2003-04-07 | Martin Nilsson | | *! If @[useconds] is @expr{0@} (zero), no new alarm will be scheduled.
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *!
*! Any previous alarms will in any case be canceled.
*!
*! @returns
*! Returns the number of microseconds remaining until any previously
*! scheduled alarm was due to be delivered, or zero if there was
*! no previously scheduled alarm.
*!
|
45f2a2 | 2002-09-10 | Martin Nilsson | | *! @note
|
27b40e | 2002-09-10 | Henrik Grubbström (Grubba) | | *! This function is only available on platforms that support
|
45f2a2 | 2002-09-10 | Martin Nilsson | | *! signals.
*!
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *! @seealso
*! @[alarm()], @[signal()], @[call_out()]
*/
|
28119b | 1996-06-09 | Fredrik Hübinette (Hubbe) | | static void f_ualarm(INT32 args)
{
|
d1b8ea | 1998-09-05 | Henrik Grubbström (Grubba) | | #ifndef HAVE_UALARM
struct itimerval new, old;
#endif /* !HAVE_UALARM */
long useconds;
|
28119b | 1996-06-09 | Fredrik Hübinette (Hubbe) | |
if(args < 1)
|
06bd61 | 2016-01-26 | Martin Nilsson | | SIMPLE_WRONG_NUM_ARGS_ERROR("ualarm", 1);
|
28119b | 1996-06-09 | Fredrik Hübinette (Hubbe) | |
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | if(TYPEOF(Pike_sp[-args]) != PIKE_T_INT)
|
f98274 | 2016-01-26 | Martin Nilsson | | SIMPLE_ARG_TYPE_ERROR("ualarm", 1, "int");
|
28119b | 1996-06-09 | Fredrik Hübinette (Hubbe) | |
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | useconds=Pike_sp[-args].u.integer;
|
28119b | 1996-06-09 | Fredrik Hübinette (Hubbe) | |
pop_n_elems(args);
|
d1b8ea | 1998-09-05 | Henrik Grubbström (Grubba) | |
#ifdef HAVE_UALARM
|
06983f | 1996-09-22 | Fredrik Hübinette (Hubbe) | | #ifdef UALARM_TAKES_TWO_ARGS
|
d1b8ea | 1998-09-05 | Henrik Grubbström (Grubba) | | push_int(ualarm(useconds,0));
|
06983f | 1996-09-22 | Fredrik Hübinette (Hubbe) | | #else
|
d1b8ea | 1998-09-05 | Henrik Grubbström (Grubba) | | push_int(ualarm(useconds));
#endif
#else /* !HAVE_UALARM */
new.it_value.tv_sec = useconds / 1000000;
new.it_value.tv_usec = useconds % 1000000;
new.it_interval.tv_sec = 0;
new.it_interval.tv_usec = 0;
if (!setitimer(ITIMER_REAL, &new, &old)) {
push_int(old.it_value.tv_usec + old.it_value.tv_sec * 1000000);
} else {
push_int(-1);
}
#endif /* HAVE_UALARM */
|
28119b | 1996-06-09 | Fredrik Hübinette (Hubbe) | | }
|
d1b8ea | 1998-09-05 | Henrik Grubbström (Grubba) | | #endif /* HAVE_UALARM || HAVE_SETITIMER */
|
28119b | 1996-06-09 | Fredrik Hübinette (Hubbe) | |
|
5f0624 | 1999-04-11 | Fredrik Hübinette (Hubbe) | | static struct array *atexit_functions;
|
985a56 | 2019-04-16 | Henrik Grubbström (Grubba) | | static void run_atexit_functions(struct callback *UNUSED(cb),
void *UNUSED(arg),
void *UNUSED(arg2))
|
5f0624 | 1999-04-11 | Fredrik Hübinette (Hubbe) | | {
if(atexit_functions)
{
|
5272b2 | 2004-09-22 | Martin Stjernholm | | int i;
|
77bcee | 2004-10-15 | Martin Stjernholm | | for (i = atexit_functions->size; i--;) {
|
5272b2 | 2004-09-22 | Martin Stjernholm | | struct svalue *s = ITEM (atexit_functions) + i;
|
985a56 | 2019-04-16 | Henrik Grubbström (Grubba) | | if (callablep(s)) {
|
5272b2 | 2004-09-22 | Martin Stjernholm | | safe_apply_svalue (s, 0, 1);
pop_stack();
}
}
|
5207f0 | 2004-09-30 | Martin Stjernholm | | free_array (atexit_functions);
atexit_functions = 0;
|
5f0624 | 1999-04-11 | Fredrik Hübinette (Hubbe) | | }
}
static void do_signal_exit(INT32 sig)
{
push_int(sig);
f_exit(1);
}
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | |
f6aab2 | 2004-09-30 | Martin Stjernholm | | *! call when pike exits. The call order is reversed, i.e. callbacks
*! that have been added earlier are called after @[callback].
|
685fb6 | 2001-01-31 | Henrik Grubbström (Grubba) | | *!
*! @note
*! Please note that @[atexit] callbacks are not called if Pike
*! exits abnormally.
*!
*! @seealso
*! @[exit()], @[_exit()]
*/
|
5f0624 | 1999-04-11 | Fredrik Hübinette (Hubbe) | | void f_atexit(INT32 args)
{
|
9a5bb9 | 2003-01-04 | Martin Nilsson | | if(args < 1)
|
06bd61 | 2016-01-26 | Martin Nilsson | | SIMPLE_WRONG_NUM_ARGS_ERROR("atexit", 1);
|
9a5bb9 | 2003-01-04 | Martin Nilsson | |
|
5f0624 | 1999-04-11 | Fredrik Hübinette (Hubbe) | | if(!atexit_functions)
{
#ifdef SIGHUP
set_default_signal_handler(SIGHUP, do_signal_exit);
#endif
#ifdef SIGINT
set_default_signal_handler(SIGINT, do_signal_exit);
#endif
|
fac113 | 2001-09-28 | Tomas Nilsson | | #ifdef SIGBREAK
set_default_signal_handler(SIGBREAK, do_signal_exit);
#endif
|
5f0624 | 1999-04-11 | Fredrik Hübinette (Hubbe) | | #ifdef SIGQUIT
set_default_signal_handler(SIGQUIT, do_signal_exit);
#endif
add_exit_callback(run_atexit_functions,0,0);
atexit_functions=low_allocate_array(0,1);
}
|
fc6846 | 2002-10-31 | Henrik Grubbström (Grubba) | | atexit_functions=append_array(atexit_functions,Pike_sp-args);
|
5272b2 | 2004-09-22 | Martin Stjernholm | | atexit_functions->flags |= ARRAY_WEAK_FLAG;
|
58854e | 1999-04-11 | Fredrik Hübinette (Hubbe) | | pop_n_elems(args);
|
5f0624 | 1999-04-11 | Fredrik Hübinette (Hubbe) | | }
|
a658b7 | 2015-10-23 | Henrik Grubbström (Grubba) | | |
940a4b | 2005-05-25 | Henrik Grubbström (Grubba) | | */
|
a658b7 | 2015-10-23 | Henrik Grubbström (Grubba) | | PMOD_EXPORT void restore_signal_handler(int sig)
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | {
|
a658b7 | 2015-10-23 | Henrik Grubbström (Grubba) | | if ((TYPEOF(signal_callbacks[sig]) != PIKE_T_INT) || default_signals[sig])
{
sigfunctype func = receive_signal;
|
e51c9b | 1999-05-03 | Fredrik Hübinette (Hubbe) | | #ifdef USE_SIGCHILD
|
a658b7 | 2015-10-23 | Henrik Grubbström (Grubba) | | if (sig == SIGCHLD) {
func = receive_sigchild;
}
#endif
my_signal(sig, func);
} else {
switch(sig) {
#ifdef SIGCHLD
case SIGCHLD:
#ifdef USE_SIGCHILD
my_signal(sig, receive_sigchild);
#else
my_signal(sig, SIG_DFL);
#endif
break;
#endif
#ifdef SIGFPE
case SIGFPE:
#ifdef IGNORE_SIGFPE
my_signal(sig, SIG_IGN);
#else
my_signal(sig, SIG_DFL);
#endif
break;
|
bdfb86 | 1997-12-22 | Fredrik Hübinette (Hubbe) | | #endif
|
a658b7 | 2015-10-23 | Henrik Grubbström (Grubba) | |
|
bdfb86 | 1997-12-22 | Fredrik Hübinette (Hubbe) | | #ifdef SIGPIPE
|
a658b7 | 2015-10-23 | Henrik Grubbström (Grubba) | | case SIGPIPE:
my_signal(sig, SIG_IGN);
break;
|
bdfb86 | 1997-12-22 | Fredrik Hübinette (Hubbe) | | #endif
|
8dd237 | 1995-11-02 | Fredrik Hübinette (Hubbe) | |
|
1ed689 | 2010-09-22 | Henrik Grubbström (Grubba) | |
|
cd8352 | 1998-02-02 | Fredrik Hübinette (Hubbe) | | #ifdef SIGSEGV
|
a658b7 | 2015-10-23 | Henrik Grubbström (Grubba) | | case SIGSEGV:
my_signal(sig, SIG_DFL);
break;
|
cd8352 | 1998-02-02 | Fredrik Hübinette (Hubbe) | | #endif
#ifdef SIGBUS
|
a658b7 | 2015-10-23 | Henrik Grubbström (Grubba) | | case SIGBUS:
my_signal(sig, SIG_DFL);
break;
|
cd8352 | 1998-02-02 | Fredrik Hübinette (Hubbe) | | #endif
|
1ed689 | 2010-09-22 | Henrik Grubbström (Grubba) | | #ifdef SIGXFSZ
|
a658b7 | 2015-10-23 | Henrik Grubbström (Grubba) | | case SIGXFSZ:
my_signal(sig, SIG_DFL);
break;
|
1ed689 | 2010-09-22 | Henrik Grubbström (Grubba) | | #endif
#ifdef SIGILL
|
a658b7 | 2015-10-23 | Henrik Grubbström (Grubba) | | case SIGILL:
my_signal(SIGILL, SIG_DFL);
break;
|
71b44e | 1998-06-05 | Fredrik Hübinette (Hubbe) | | #endif
|
a658b7 | 2015-10-23 | Henrik Grubbström (Grubba) | | default:
break;
|
a96b28 | 2007-05-17 | Henrik Grubbström (Grubba) | | }
}
|
a658b7 | 2015-10-23 | Henrik Grubbström (Grubba) | | }
|
a96b28 | 2007-05-17 | Henrik Grubbström (Grubba) | |
|
a658b7 | 2015-10-23 | Henrik Grubbström (Grubba) | |
PMOD_EXPORT void low_init_signals(void)
{
int e;
|
e97495 | 2013-01-01 | Henrik Grubbström (Grubba) | |
|
940a4b | 2005-05-25 | Henrik Grubbström (Grubba) | | for(e=0;e<MAX_SIGNALS;e++) {
|
a658b7 | 2015-10-23 | Henrik Grubbström (Grubba) | | restore_signal_handler(e);
|
940a4b | 2005-05-25 | Henrik Grubbström (Grubba) | | }
}
void init_signals(void)
{
int e;
INIT_FIFO(sig, unsigned char);
INIT_FIFO(wait,wait_data);
#ifdef __NT__
init_interleave_mutex(&handle_protection_mutex);
#endif /* __NT__ */
|
061ca9 | 1999-04-01 | Fredrik Hübinette (Hubbe) | |
|
1ab4ac | 2008-01-26 | Martin Stjernholm | | for(e=0;e<MAX_SIGNALS;e++) {
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | SET_SVAL_TYPE(signal_callbacks[e], PIKE_T_INT);
SET_SVAL_SUBTYPE(signal_callbacks[e], NUMBER_NUMBER);
|
1ab4ac | 2008-01-26 | Martin Stjernholm | | }
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | |
|
940a4b | 2005-05-25 | Henrik Grubbström (Grubba) | | low_init_signals();
#ifdef USE_PID_MAPPING
pid_mapping=allocate_mapping(2);
#endif
|
b4b3a8 | 2015-07-31 | Martin Nilsson | | #ifdef USE_WAIT_THREAD
co_init(& process_status_change);
co_init(& start_wait_thread);
mt_init(& wait_thread_mutex);
#endif
|
8a9b65 | 2001-08-30 | Fredrik Hübinette (Hubbe) | | #if 0
|
c38ede | 1999-04-02 | Fredrik Hübinette (Hubbe) | | if(!signal_evaluator_callback)
{
signal_evaluator_callback=add_to_callback(&evaluator_callbacks,
check_signals,
0,0);
|
424d9c | 1999-05-02 | Fredrik Hübinette (Hubbe) | | dmalloc_accept_leak(signal_evaluator_callback);
|
c38ede | 1999-04-02 | Fredrik Hübinette (Hubbe) | | }
|
8a9b65 | 2001-08-30 | Fredrik Hübinette (Hubbe) | | #endif
|
c38ede | 1999-04-02 | Fredrik Hübinette (Hubbe) | |
|
2fc55f | 2006-12-27 | Henrik Grubbström (Grubba) | | START_NEW_PROGRAM_ID(PROCESS);
|
90e978 | 1999-01-31 | Fredrik Hübinette (Hubbe) | | ADD_STORAGE(struct pid_status);
|
099503 | 2011-09-08 | Henrik Grubbström (Grubba) | | PIKE_MAP_VARIABLE("__pid", OFFSETOF(pid_status, pid),
tInt, T_INT, ID_PROTECTED);
|
2fc55f | 2006-12-27 | Henrik Grubbström (Grubba) | | #ifndef __NT__
|
c67a1b | 2011-09-08 | Henrik Grubbström (Grubba) | |
|
099503 | 2011-09-08 | Henrik Grubbström (Grubba) | | PIKE_MAP_VARIABLE("__last_signal", OFFSETOF(pid_status, sig),
tInt, T_INT, ID_PROTECTED);
PIKE_MAP_VARIABLE("__flags", OFFSETOF(pid_status, flags),
tInt, T_INT, ID_PROTECTED|ID_PRIVATE);
|
c67a1b | 2011-09-08 | Henrik Grubbström (Grubba) | | PIKE_MAP_VARIABLE("__status", OFFSETOF(pid_status, state),
|
099503 | 2011-09-08 | Henrik Grubbström (Grubba) | | tInt, T_INT, ID_PROTECTED);
PIKE_MAP_VARIABLE("__result", OFFSETOF(pid_status, result),
tInt, T_INT, ID_PROTECTED);
|
2fc55f | 2006-12-27 | Henrik Grubbström (Grubba) | | PIKE_MAP_VARIABLE("__callback", OFFSETOF(pid_status, callback),
|
099503 | 2011-09-08 | Henrik Grubbström (Grubba) | | tFunc(tObjIs_PROCESS,tVoid), T_MIXED, ID_PROTECTED);
|
2fc55f | 2006-12-27 | Henrik Grubbström (Grubba) | | #endif /* !__NT__ */
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | set_init_callback(init_pid_status);
set_exit_callback(exit_pid_status);
|
45ee5d | 1999-02-10 | Fredrik Hübinette (Hubbe) | |
|
111b1d | 2014-08-22 | Martin Nilsson | | ADD_FUNCTION("set_priority",f_pid_status_set_priority,tFunc(tStr,tIntPos),0);
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | |
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | ADD_FUNCTION("wait",f_pid_status_wait,tFunc(tNone,tInt),0);
|
45ee5d | 1999-02-10 | Fredrik Hübinette (Hubbe) | |
|
e64f5a | 1999-06-19 | Fredrik Hübinette (Hubbe) | | ADD_FUNCTION("status",f_pid_status_status,tFunc(tNone,tInt),0);
|
b14354 | 2003-02-28 | Henrik Grubbström (Grubba) | |
ADD_FUNCTION("last_signal", f_pid_status_last_signal,tFunc(tNone,tInt),0);
|
45ee5d | 1999-02-10 | Fredrik Hübinette (Hubbe) | |
|
e64f5a | 1999-06-19 | Fredrik Hübinette (Hubbe) | | ADD_FUNCTION("pid",f_pid_status_pid,tFunc(tNone,tInt),0);
|
53acc2 | 1999-05-24 | Henrik Grubbström (Grubba) | | #ifdef HAVE_KILL
|
2f7050 | 2014-07-10 | Henrik Grubbström (Grubba) | | ADD_FUNCTION("kill", f_pid_status_kill, tFunc(tInt,tInt01), 0);
|
53acc2 | 1999-05-24 | Henrik Grubbström (Grubba) | | #endif /* HAVE_KILL */
|
45ee5d | 1999-02-10 | Fredrik Hübinette (Hubbe) | |
ADD_FUNCTION("create",f_create_process,tFunc(tArr(tStr) tOr(tVoid,tMap(tStr,tMix)),tObj),0);
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | |
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | pid_status_program=end_program();
add_program_constant("create_process",pid_status_program,0);
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | #ifdef HAVE_PTRACE
start_new_program();
low_inherit(pid_status_program, NULL, -1, 0, 0, NULL);
set_init_callback(init_trace_process);
set_exit_callback(exit_trace_process);
ADD_FUNCTION("cont",f_trace_process_cont,
tFunc(tOr(tVoid,tInt),tVoid), 0);
ADD_FUNCTION("exit", f_trace_process_exit,
tFunc(tNone, tVoid), 0);
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | | #if 0 /* Disabled for now. */
start_new_program();
Pike_compiler->new_program->flags |= PROGRAM_USES_PARENT;
|
95489a | 2008-06-29 | Martin Nilsson | | ADD_FUNCTION("`[]", f_proc_reg_index, tFunc(tMix, tInt), ID_PROTECTED);
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | | end_class("Registers", 0);
#endif /* 0 */
|
dad69b | 2003-03-01 | Henrik Grubbström (Grubba) | | end_class("TraceProcess", 0);
#endif /* HAVE_PTRACE */
|
13670c | 2015-05-25 | Martin Nilsson | |
|
45ee5d | 1999-02-10 | Fredrik Hübinette (Hubbe) | |
ADD_EFUN("set_priority",f_set_priority,tFunc(tStr tOr(tInt,tVoid),tInt),
|
72850a | 1999-02-01 | Per Hedbor | | OPT_SIDE_EFFECT);
|
13670c | 2015-05-25 | Martin Nilsson | |
|
8057a3 | 2003-05-10 | Henrik Grubbström (Grubba) | | ADD_EFUN("signal",f_signal,
tFunc(tInt tOr(tVoid,tFunc(tOr(tVoid,tInt),tVoid)),tMix),
|
022070 | 2003-05-10 | Martin Stjernholm | | OPT_SIDE_EFFECT);
|
45f2a2 | 2002-09-10 | Martin Nilsson | |
|
75920f | 1997-12-28 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_KILL
|
45ee5d | 1999-02-10 | Fredrik Hübinette (Hubbe) | |
|
2f7050 | 2014-07-10 | Henrik Grubbström (Grubba) | | ADD_EFUN("kill", f_kill, tFunc(tOr(tInt,tObj) tInt,tInt01), OPT_SIDE_EFFECT);
|
75920f | 1997-12-28 | Fredrik Hübinette (Hubbe) | | #endif
|
45f2a2 | 2002-09-10 | Martin Nilsson | |
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_FORK
|
45ee5d | 1999-02-10 | Fredrik Hübinette (Hubbe) | |
|
cfbc2e | 2000-03-21 | Fredrik Hübinette (Hubbe) | | ADD_EFUN("fork",Pike_f_fork,tFunc(tVoid,tObj),OPT_SIDE_EFFECT);
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | #endif
|
45ee5d | 1999-02-10 | Fredrik Hübinette (Hubbe) | |
ADD_EFUN("signame",f_signame,tFunc(tInt,tStr),0);
|
13670c | 2015-05-25 | Martin Nilsson | |
|
45ee5d | 1999-02-10 | Fredrik Hübinette (Hubbe) | |
ADD_EFUN("signum",f_signum,tFunc(tStr,tInt),0);
|
13670c | 2015-05-25 | Martin Nilsson | |
|
45ee5d | 1999-02-10 | Fredrik Hübinette (Hubbe) | |
|
3bda2c | 2004-01-13 | Martin Nilsson | | ADD_EFUN("getpid",f_getpid,tFunc(tNone,tInt),OPT_EXTERNAL_DEPEND);
|
45f2a2 | 2002-09-10 | Martin Nilsson | |
|
75920f | 1997-12-28 | Fredrik Hübinette (Hubbe) | | #ifdef HAVE_ALARM
|
45ee5d | 1999-02-10 | Fredrik Hübinette (Hubbe) | |
ADD_EFUN("alarm",f_alarm,tFunc(tInt,tInt),OPT_SIDE_EFFECT);
|
75920f | 1997-12-28 | Fredrik Hübinette (Hubbe) | | #endif
|
45f2a2 | 2002-09-10 | Martin Nilsson | |
|
d1b8ea | 1998-09-05 | Henrik Grubbström (Grubba) | | #if defined(HAVE_UALARM) || defined(HAVE_SETITIMER)
|
45ee5d | 1999-02-10 | Fredrik Hübinette (Hubbe) | |
ADD_EFUN("ualarm",f_ualarm,tFunc(tInt,tInt),OPT_SIDE_EFFECT);
|
0f8729 | 1999-05-07 | Fredrik Hübinette (Hubbe) | | #endif
|
5f0624 | 1999-04-11 | Fredrik Hübinette (Hubbe) | |
|
abe661 | 2000-01-15 | Fredrik Hübinette (Hubbe) | | ADD_EFUN("atexit",f_atexit,tFunc(tMix,tVoid),OPT_SIDE_EFFECT);
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | }
|
be478c | 1997-08-30 | Henrik Grubbström (Grubba) | | void exit_signals(void)
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | {
int e;
|
4499d5 | 2003-03-06 | Henrik Grubbström (Grubba) | | #ifdef USE_PID_MAPPING
|
85f59e | 1998-01-08 | Fredrik Hübinette (Hubbe) | | if(pid_mapping)
{
free_mapping(pid_mapping);
pid_mapping=0;
}
#endif
if(pid_status_program)
{
free_program(pid_status_program);
pid_status_program=0;
}
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | for(e=0;e<MAX_SIGNALS;e++)
{
free_svalue(signal_callbacks+e);
|
017b57 | 2011-10-28 | Henrik Grubbström (Grubba) | | SET_SVAL_TYPE(signal_callbacks[e], PIKE_T_INT);
SET_SVAL_SUBTYPE(signal_callbacks[e], NUMBER_NUMBER);
|
cb2256 | 1995-10-11 | Fredrik Hübinette (Hubbe) | | }
}
|