MagickCore 7.0.10
wizard.c
Go to the documentation of this file.
1/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% W W IIIII ZZZZZ AAA RRRR DDDD %
7% W W I ZZ A A R R D KD %
8% W W W I ZZZ AAAAA RRRR D D %
9% WW WW I ZZ A A R R D D %
10% W W IIIII ZZZZZ A A R R DDDD %
11% %
12% Wizard's Toolkit Wizard Methods %
13% %
14% Software Design %
15% Cristy %
16% March 2003 %
17% %
18% %
19% Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization %
20% dedicated to making software imaging solutions freely available. %
21% %
22% You may not use this file except in compliance with the License. You may %
23% obtain a copy of the License at %
24% %
25% https://imagemagick.org/script/license.php %
26% %
27% Unless required by applicable law or agreed to in writing, software %
28% distributed under the License is distributed on an "AS IS" BASIS, %
29% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
30% See the License for the specific language governing permissions and %
31% limitations under the License. %
32% %
33%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34%
35%
36*/
37
38/*
39 Include declarations.
40*/
41#include "wizard/studio.h"
42#include "wizard/client.h"
43#include "wizard/configure.h"
44#include "wizard/hash.h"
45#include "wizard/log.h"
46#include "wizard/magick.h"
47#include "wizard/memory_.h"
48#include "wizard/mime.h"
49#include "wizard/random_.h"
50#include "wizard/resource_.h"
51#include "wizard/semaphore.h"
53#include "wizard/string_.h"
54#include "wizard/utility.h"
55#include "wizard/wizard.h"
56
57/*
58 Define declarations.
59*/
60#if !defined(WIZARDSTOOLKIT_RETSIGTYPE)
61# define WIZARDSTOOLKIT_RETSIGTYPE void
62#endif
63#if !defined(SIG_DFL)
64# define SIG_DFL ((SignalHandler *) 0)
65#endif
66#if !defined(SIG_ERR)
67# define SIG_ERR ((SignalHandler *) -1)
68#endif
69#if !defined(SIGMAX)
70#define SIGMAX 64
71#endif
72
73/*
74 Typedef declarations.
75*/
78
79/*
80 Global declarations.
81*/
82static SignalHandler
84
85static volatile WizardBooleanType
88
89/*
90%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91% %
92% %
93% %
94% W i z a r d s T o o l k i t G e n e s i s %
95% %
96% %
97% %
98%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99%
100% WizardsToolkitGenesis() initializes the Wizard's Toolkit environment.
101%
102% The format of the WizardsToolkitGenesis function is:
103%
104% WizardsToolkitGenesis(const char *path)
105%
106% A description of each parameter follows:
107%
108% o path: The execution path of the current Wizard's Toolkit client.
109%
110*/
111
112static void WizardExitHandler(void)
113{
115}
116
118 SignalHandler *handler)
119{
120#if defined(WIZARDSTOOLKIT_HAVE_SIGACTION) && defined(WIZARDSTOOLKIT_HAVE_SIGEMPTYSET)
121 int
122 status;
123
124 sigset_t
125 mask;
126
127 struct sigaction
128 action,
129 previous_action;
130
131 sigemptyset(&mask);
132 sigaddset(&mask,signal_number);
133 sigprocmask(SIG_BLOCK,&mask,NULL);
134 action.sa_mask=mask;
135 action.sa_handler=handler;
136 action.sa_flags=0;
137#if defined(SA_INTERRUPT)
138 action.sa_flags|=SA_INTERRUPT;
139#endif
140#if defined(SA_ONSTACK)
141 action.sa_flags|=SA_ONSTACK;
142#endif
143 previous_action.sa_handler=SIG_DFL;
144 status=sigaction(signal_number,&action,&previous_action);
145 if (status < 0)
146 return(SIG_ERR);
147 sigprocmask(SIG_UNBLOCK,&mask,NULL);
148 return(previous_action.sa_handler);
149#else
150 return(signal(signal_number,handler));
151#endif
152}
153
155{
160#if !defined(WIZARDSTOOLKIT_HAVE__EXIT)
161 exit(signal_number);
162#else
163#if defined(SIGHUP)
164 if (signal_number == SIGHUP)
165 exit(signal_number);
166#endif
167#if defined(SIGBREAK)
168 if (signal_number == SIGBREAK)
169 exit(signal_number);
170#endif
171#if defined(SIGINT)
172 if (signal_number == SIGINT)
173 exit(signal_number);
174#endif
175#if defined(SIGTERM)
176 if (signal_number == SIGTERM)
177 exit(signal_number);
178#endif
179#if defined(SIGSEGV)
180 if (signal_number == SIGSEGV)
181 exit(signal_number);
182#endif
183#if defined(WIZARDSTOOLKIT_HAVE_RAISE)
185 raise(signal_number);
186#endif
187 _exit(signal_number); /* do not invoke registered atexit() methods */
188#endif
189}
190
192{
194 *handler;
195
197 if (handler == SIG_ERR)
198 return(handler);
199 if (handler != SIG_DFL)
200 handler=SetWizardSignalHandler(signal_number,handler);
201 else
203 "Register handler for signal: %d",signal_number);
204 return(handler);
205}
206
208{
209 char
210 *events,
211 execution_path[WizardPathExtent],
212 filename[WizardPathExtent];
213
214 /*
215 Initialize the Wizard environment.
216 */
220 {
222 return;
223 }
224 (void) setlocale(LC_ALL,"");
225 (void) setlocale(LC_NUMERIC,"C");
227 (void) LogComponentGenesis();
228 (void) RandomComponentGenesis();
229 events=GetEnvironmentValue("WIZARD_DEBUG");
230 if (events != (char *) NULL)
231 {
232 (void) SetLogEventMask(events);
233 events=(char *) RelinquishWizardMemory(events);
234 }
235#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
236#if defined(_DEBUG) && !defined(__BORLANDC__)
238 {
239 int
240 debug;
241
242 debug=_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
243 debug|=_CRTDBG_CHECK_ALWAYS_DF |_CRTDBG_DELAY_FREE_MEM_DF |
244 _CRTDBG_LEAK_CHECK_DF;
245 if (0)
246 {
247 debug=_CrtSetDbgFlag(debug);
248 _ASSERTE(_CrtCheckMemory());
249 }
250 }
251#endif
252#endif
253 /*
254 Set client name and execution path.
255 */
256 (void) GetExecutionPath(execution_path,WizardPathExtent);
257 if ((path != (const char *) NULL) && (*path != '\0'))
258 (void) CopyWizardString(execution_path,path,WizardPathExtent);
259 GetPathComponent(execution_path,TailPath,filename);
260 (void) SetClientName(filename);
261 GetPathComponent(execution_path,HeadPath,execution_path);
262 (void) SetClientPath(execution_path);
263 /*
264 Set signal handlers.
265 */
266#if defined(SIGABRT)
267 if (signal_handlers[SIGABRT] == (SignalHandler *) NULL)
269#endif
270#if defined(SIGBREAK)
271 if (signal_handlers[SIGBREAK] == (SignalHandler *) NULL)
273#endif
274#if defined(SIGFPE)
275 if (signal_handlers[SIGFPE] == (SignalHandler *) NULL)
277#endif
278#if defined(SIGHUP)
279 if (signal_handlers[SIGHUP] == (SignalHandler *) NULL)
281#endif
282#if defined(SIGINT) && !defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
283 if (signal_handlers[SIGINT] == (SignalHandler *) NULL)
285#endif
286#if defined(SIGQUIT)
287 if (signal_handlers[SIGQUIT] == (SignalHandler *) NULL)
289#endif
290#if defined(SIGTERM)
291 if (signal_handlers[SIGTERM] == (SignalHandler *) NULL)
293#endif
294#if defined(SIGSEGV)
295 if (signal_handlers[SIGSEGV] == (SignalHandler *) NULL)
297#endif
298#if defined(SIGXCPU)
299 if (signal_handlers[SIGXCPU] == (SignalHandler *) NULL)
301#endif
302#if defined(SIGXFSZ)
303 if (signal_handlers[SIGXFSZ] == (SignalHandler *) NULL)
305#endif
306 /*
307 Initialize wizard resources.
308 */
311 (void) MimeComponentGenesis();
314}
315
316/*
317%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
318% %
319% %
320% %
321% W i z a r d s T o o l k i t T e r m i n u s %
322% %
323% %
324% %
325%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
326%
327% WizardsToolkitTerminus() destroys the Wizard's Toolkit environment.
328%
329% The format of the WizardsToolkitTerminus method is:
330%
331% WizardsToolkitTerminus(void)
332%
333*/
335{
339 {
341 return;
342 }
350}
WizardExport const char * SetClientPath(const char *path)
Definition client.c:148
WizardExport const char * SetClientName(const char *name)
Definition client.c:114
WizardExport WizardBooleanType ConfigureComponentGenesis(void)
Definition configure.c:211
WizardBooleanType LogWizardEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition log.c:1390
WizardExport WizardBooleanType LogComponentGenesis(void)
Definition log.c:824
WizardExport LogEventType SetLogEventMask(const char *events)
Definition log.c:1731
WizardExport void LogComponentTerminus(void)
Definition log.c:882
WizardExport WizardBooleanType IsEventLogging(void)
Definition log.c:688
@ ConfigureEvent
Definition log.h:44
#define GetWizardModule()
Definition log.h:30
WizardExport void * RelinquishWizardMemory(void *memory)
Definition memory.c:1039
#define WizardExport
#define WizardPathExtent
WizardExport WizardBooleanType MimeComponentGenesis(void)
Definition mime.c:991
WizardExport void MimeComponentTerminus(void)
Definition mime.c:1037
static volatile sig_atomic_t signal_number
Definition passphrase.c:82
WizardExport WizardBooleanType RandomComponentGenesis(void)
Definition random.c:910
WizardExport void RandomComponentTerminus(void)
Definition random.c:935
WizardExport WizardBooleanType ResourceComponentGenesis(void)
Definition resource.c:887
WizardExport void AsynchronousResourceComponentTerminus(void)
Definition resource.c:511
WizardExport void ResourceComponentTerminus(void)
Definition resource.c:983
static void InitializeWizardMutex(void)
static void UnlockWizardMutex(void)
static void LockWizardMutex(void)
WizardExport void SemaphoreComponentTerminus(void)
Definition semaphore.c:410
WizardExport WizardBooleanType SemaphoreComponentGenesis(void)
Definition semaphore.c:386
WizardExport char * GetEnvironmentValue(const char *name)
Definition string.c:1177
WizardExport size_t CopyWizardString(char *destination, const char *source, const size_t length)
Definition string.c:762
WizardExport WizardBooleanType GetExecutionPath(char *, const size_t)
Definition utility.c:643
WizardExport void GetPathComponent(const char *path, PathType type, char *component)
Definition utility.c:415
@ TailPath
Definition utility.h:31
@ HeadPath
Definition utility.h:30
WizardBooleanType
Definition wizard-type.h:26
@ WizardTrue
Definition wizard-type.h:28
@ WizardFalse
Definition wizard-type.h:27
static SignalHandler * RegisterWizardSignalHandler(int signal_number)
Definition wizard.c:191
#define SIG_DFL
Definition wizard.c:64
static SignalHandler * signal_handlers[SIGMAX]
Definition wizard.c:83
#define SIG_ERR
Definition wizard.c:67
static void WizardExitHandler(void)
Definition wizard.c:112
WizardExport void WizardsToolkitGenesis(const char *path)
Definition wizard.c:207
#define SIGMAX
Definition wizard.c:70
WIZARDSTOOLKIT_RETSIGTYPE SignalHandler(int)
Definition wizard.c:77
WizardExport void WizardsToolkitTerminus(void)
Definition wizard.c:334
static void WizardSignalHandler(int signal_number)
Definition wizard.c:154
static SignalHandler * SetWizardSignalHandler(int signal_number, SignalHandler *handler)
Definition wizard.c:117
static volatile WizardBooleanType instantiate_wizardstoolkit
Definition wizard.c:86
static volatile WizardBooleanType wizard_signal_in_progress
Definition wizard.c:87
#define WIZARDSTOOLKIT_RETSIGTYPE
Definition wizard.c:61