Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / procmgmt / procmgmt.h
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10 #ifndef OPENAFS_PROCMGMT_H
11 #define OPENAFS_PROCMGMT_H
12
13
14 #ifdef AFS_NT40_ENV
15 /* Process management definitions for Windows NT */
16
17 #include <process.h>
18
19
20 /* ----------------- Processes ---------------- */
21
22
23 typedef int pid_t; /* process id type */
24
25 /* Wait status macros -- status returned in standard Unix format */
26
27 #define WIFEXITED(wstat) ((int)((wstat) & 0xFF) == 0)
28 #define WIFSIGNALED(wstat) ((int)((wstat) & 0xFF) != 0)
29 #define WEXITSTATUS(wstat) ((int)(((wstat) >> 8) & 0xFF))
30 #define WTERMSIG(wstat) ((int)((wstat) & 0xFF))
31 #define WCOREDUMP(wstat) ((int)0)
32
33 #define WEXITED_ENCODE(status) ((int)(((status) & 0xFF) << 8))
34 #define WSIGNALED_ENCODE(signo) ((int)((signo) & 0xFF))
35
36 /* Wait option macros */
37
38 #define WNOHANG 0x01
39
40 /* Process related data declarations */
41
42 #ifndef PMGTEXPORT
43 #define PMGTEXPORT __declspec(dllimport)
44 #endif
45
46 #define spawnDatap pmgt_spawnData
47 PMGTEXPORT extern void *pmgt_spawnData;
48
49 #define spawnDataLen pmgt_spawnDataLen
50 PMGTEXPORT extern size_t pmgt_spawnDataLen;
51
52
53 /* Process related function declarations */
54
55 #define PMGT_SPAWN_DETACHED_ENV_NAME "TransarcAfsPmgtSpawnDetached"
56
57 #define spawnprocveb(spath, sargv, senvp, sdatap, sdatalen) \
58 pmgt_ProcessSpawnVEB(spath, sargv, senvp, sdatap, sdatalen)
59 #define spawnprocve(spath, sargv, senvp, estatus) \
60 pmgt_ProcessSpawnVEB(spath, sargv, senvp, NULL, 0)
61 #define spawnprocve_sig(spath, sargv, senvp, estatus, mask) \
62 pmgt_ProcessSpawnVEB(spath, sargv, senvp, NULL, 0)
63 #define spawnprocv(spath, sargv, estatus) \
64 pmgt_ProcessSpawnVEB(spath, sargv, NULL, NULL, 0)
65
66 extern pid_t pmgt_ProcessSpawnVEB(const char *spath, char **sargv,
67 char **senvp, void *sdatap,
68 size_t sdatalen);
69
70
71 #define waitpid(pid, statusP, options) \
72 pmgt_ProcessWaitPid(pid, statusP, options)
73 #define wait(statusP) \
74 pmgt_ProcessWaitPid((pid_t)-1, statusP, 0)
75
76 extern pid_t pmgt_ProcessWaitPid(pid_t pid, int *statusP, int options);
77
78
79
80
81
82
83 /* ----------------- Signals ---------------- */
84
85
86 /* Attempt to override Microsoft (MSVC) signal definitions */
87 #ifndef _INC_SIGNAL
88 #define _INC_SIGNAL
89 #else
90 #error "Windows requires custom signal definitions; do not include signal.h."
91 #endif
92
93
94 /* Supported signals
95 * Support is provided for a subset of the standard Unix signals.
96 * Note that Windows NT (via the MSVC runtime) will NOT generate signals
97 * in response to most HW faults or terminal activity; in particular,
98 * Windows NT will NOT generate SIGILL, SIGSEGV, SIGINT, or SIGTERM.
99 */
100
101
102 #define SIGHUP 1 /* hangup */
103 #define SIGINT 2 /* interrupt */
104 #define SIGQUIT 3 /* quit */
105 #define SIGILL 4 /* illegal instruction */
106 #define SIGABRT 6 /* abnormal termination triggered by abort() */
107 #define SIGFPE 8 /* floating point exception */
108 #define SIGKILL 9 /* kill */
109 #define SIGSEGV 11 /* segmentation violation */
110 #define SIGTERM 15 /* software termination signal from kill */
111 #define SIGUSR1 16 /* user defined signal 1 */
112 #define SIGUSR2 17 /* user defined signal 2 */
113 #define SIGCLD 18 /* child status change - alias for compatability */
114 #define SIGCHLD 18 /* child status change */
115 #define SIGTSTP 24 /* user stop requested from tty */
116
117 #define NSIG 25 /* max signal number + 1 (sig set macros presume <= 33) */
118
119
120 /* Signal actions */
121
122 #define SIG_ERR ((void (__cdecl *)(int))-1) /* signal() error value */
123 #define SIG_DFL ((void (__cdecl *)(int))0) /* default signal action */
124 #define SIG_IGN ((void (__cdecl *)(int))1) /* ignore signal */
125
126
127 /* Signal set type and set manipulation macros */
128
129 typedef unsigned int sigset_t;
130
131 #define sigsetbit(signo) ((unsigned int)1 << (((signo) - 1) & (32 - 1)))
132
133 #define sigemptyset(setP) ((*(setP) = 0) ? 0 : 0)
134 #define sigfillset(setP) ((*(setP) = ~(unsigned int)0) ? 0 : 0)
135 #define sigaddset(setP, signo) ((*(setP) |= sigsetbit(signo)) ? 0 : 0)
136 #define sigdelset(setP, signo) ((*(setP) &= ~sigsetbit(signo)) ? 0 : 0)
137 #define sigismember(setP, signo) ((*(setP) & sigsetbit(signo)) ? 1 : 0)
138
139
140 /* Sigaction type and related macros */
141
142 struct sigaction {
143 void (__cdecl * sa_handler) (int);
144 sigset_t sa_mask;
145 int sa_flags;
146 };
147
148 #define SA_RESETHAND 0x00000001
149
150
151 /* Signal related function declarations */
152
153 #define sigaction(signo, actP, oactP) pmgt_SigactionSet(signo, actP, oactP)
154 extern int pmgt_SigactionSet(int signo, const struct sigaction *actionP,
155 struct sigaction *old_actionP);
156
157 #define signal(signo, dispP) pmgt_SignalSet(signo, dispP)
158 extern void (__cdecl *
159 pmgt_SignalSet(int signo, void (__cdecl * dispP) (int))) (int);
160
161 #define raise(signo) pmgt_SignalRaiseLocal(signo)
162 extern int pmgt_SignalRaiseLocal(int signo);
163
164 #define kill(pid, signo) pmgt_SignalRaiseRemote(pid, signo)
165 extern int pmgt_SignalRaiseRemote(pid_t pid, int signo);
166
167
168
169 #else
170 /* Process management definitions for Unix */
171
172 #include <sys/types.h>
173 #include <sys/wait.h>
174
175 #include <signal.h>
176 #include <unistd.h>
177
178
179 /* ----------------- Processes ---------------- */
180
181 #define spawnprocve(spath, sargv, senvp, estatus) \
182 pmgt_ProcessSpawnVE(spath, sargv, senvp, estatus, NULL)
183 #define spawnprocve_sig(spath, sargv, senvp, estatus, mask) \
184 pmgt_ProcessSpawnVE(spath, sargv, senvp, estatus, mask)
185 #define spawnprocv(spath, sargv, estatus) \
186 pmgt_ProcessSpawnVE(spath, sargv, NULL, estatus, NULL)
187
188 extern pid_t pmgt_ProcessSpawnVE(const char *spath, char **sargv,
189 char **senvp, int estatus, sigset_t *mask);
190
191
192 #endif /* AFS_NT40_ENV */
193
194 #endif /* OPENAFS_PROCMGMT_H */