#include "MagickCore/utility-private.h"
#include "MagickCore/version.h"
#include "MagickCore/xml-tree.h"
+#include "MagickCore/xml-tree-private.h"
\f
/*
Define declarations.
log_name[MaxTextExtent] = "Magick";
static LinkedListInfo
- *log_list = (LinkedListInfo *) NULL;
+ *log_cache = (LinkedListInfo *) NULL;
static SemaphoreInfo
+ *event_semaphore = (SemaphoreInfo *) NULL,
*log_semaphore = (SemaphoreInfo *) NULL;
-
-static volatile MagickBooleanType
- instantiate_log = MagickFalse;
\f
/*
Forward declarations.
*GetLogInfo(const char *,ExceptionInfo *);
static MagickBooleanType
- InitializeLogList(ExceptionInfo *),
- LoadLogLists(const char *,ExceptionInfo *);
+ IsLogCacheInstantiated(ExceptionInfo *),
+ LoadLogCache(LinkedListInfo *,const char *,const char *,const size_t,
+ ExceptionInfo *);
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% A c q u i r e L o g C a c h e %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% AcquireLogCache() caches one or more log configurations which provides a
+% mapping between log attributes and log name.
+%
+% The format of the AcquireLogCache method is:
+%
+% LinkedListInfo *AcquireLogCache(const char *filename,
+% ExceptionInfo *exception)
+%
+% A description of each parameter follows:
+%
+% o filename: the log configuration filename.
+%
+% o exception: return any errors or warnings in this structure.
+%
+*/
+static LinkedListInfo *AcquireLogCache(const char *filename,
+ ExceptionInfo *exception)
+{
+ const StringInfo
+ *option;
+
+ LinkedListInfo
+ *log_cache,
+ *options;
+
+ MagickStatusType
+ status;
+
+ register ssize_t
+ i;
+
+ /*
+ Load external log map.
+ */
+ log_cache=NewLinkedList(0);
+ if (log_cache == (LinkedListInfo *) NULL)
+ ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
+ status=MagickTrue;
+ options=GetConfigureOptions(filename,exception);
+ option=(const StringInfo *) GetNextValueInLinkedList(options);
+ while (option != (const StringInfo *) NULL)
+ {
+ status&=LoadLogCache(log_cache,(const char *) GetStringInfoDatum(option),
+ GetStringInfoPath(option),0,exception);
+ option=(const StringInfo *) GetNextValueInLinkedList(options);
+ }
+ options=DestroyConfigureOptions(options);
+ /*
+ Load built-in log map.
+ */
+ for (i=0; i < (ssize_t) (sizeof(LogMap)/sizeof(*LogMap)); i++)
+ {
+ LogInfo
+ *log_info;
+
+ register const LogMapInfo
+ *p;
+
+ p=LogMap+i;
+ log_info=(LogInfo *) AcquireMagickMemory(sizeof(*log_info));
+ if (log_info == (LogInfo *) NULL)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ ResourceLimitError,"MemoryAllocationFailed","`%s'",p->filename);
+ continue;
+ }
+ (void) ResetMagickMemory(log_info,0,sizeof(*log_info));
+ log_info->path=ConstantString("[built-in]");
+ GetTimerInfo((TimerInfo *) &log_info->timer);
+ log_info->event_mask=p->event_mask;
+ log_info->handler_mask=p->handler_mask;
+ log_info->filename=ConstantString(p->filename);
+ log_info->format=ConstantString(p->format);
+ log_info->signature=MagickSignature;
+ status&=AppendValueToLinkedList(log_cache,log_info);
+ if (status == MagickFalse)
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ ResourceLimitError,"MemoryAllocationFailed","`%s'",log_info->name);
+ }
+ return(log_cache);
+}
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*p;
assert(exception != (ExceptionInfo *) NULL);
- if ((log_list == (LinkedListInfo *) NULL) || (instantiate_log == MagickFalse))
- if (InitializeLogList(exception) == MagickFalse)
- return((LogInfo *) NULL);
- if ((log_list == (LinkedListInfo *) NULL) ||
- (IsLinkedListEmpty(log_list) != MagickFalse))
+ if (IsLogCacheInstantiated(exception) == MagickFalse)
return((LogInfo *) NULL);
- if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
- return((LogInfo *) GetValueFromLinkedList(log_list,0));
/*
Search for log tag.
*/
LockSemaphoreInfo(log_semaphore);
- ResetLinkedListIterator(log_list);
- p=(LogInfo *) GetNextValueInLinkedList(log_list);
+ ResetLinkedListIterator(log_cache);
+ p=(LogInfo *) GetNextValueInLinkedList(log_cache);
+ if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
+ {
+ UnlockSemaphoreInfo(log_semaphore);
+ return(p);
+ }
while (p != (LogInfo *) NULL)
{
if (LocaleCompare(name,p->name) == 0)
break;
- p=(LogInfo *) GetNextValueInLinkedList(log_list);
+ p=(LogInfo *) GetNextValueInLinkedList(log_cache);
}
if (p != (LogInfo *) NULL)
- (void) InsertValueInLinkedList(log_list,0,
- RemoveElementByValueFromLinkedList(log_list,p));
+ (void) InsertValueInLinkedList(log_cache,0,
+ RemoveElementByValueFromLinkedList(log_cache,p));
UnlockSemaphoreInfo(log_semaphore);
return(p);
}
if (p == (const LogInfo *) NULL)
return((const LogInfo **) NULL);
preferences=(const LogInfo **) AcquireQuantumMemory((size_t)
- GetNumberOfElementsInLinkedList(log_list)+1UL,sizeof(*preferences));
+ GetNumberOfElementsInLinkedList(log_cache)+1UL,sizeof(*preferences));
if (preferences == (const LogInfo **) NULL)
return((const LogInfo **) NULL);
/*
Generate log list.
*/
LockSemaphoreInfo(log_semaphore);
- ResetLinkedListIterator(log_list);
- p=(const LogInfo *) GetNextValueInLinkedList(log_list);
+ ResetLinkedListIterator(log_cache);
+ p=(const LogInfo *) GetNextValueInLinkedList(log_cache);
for (i=0; p != (const LogInfo *) NULL; )
{
if ((p->stealth == MagickFalse) &&
(GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
preferences[i++]=p;
- p=(const LogInfo *) GetNextValueInLinkedList(log_list);
+ p=(const LogInfo *) GetNextValueInLinkedList(log_cache);
}
UnlockSemaphoreInfo(log_semaphore);
qsort((void *) preferences,(size_t) i,sizeof(*preferences),LogInfoCompare);
if (p == (const LogInfo *) NULL)
return((char **) NULL);
preferences=(char **) AcquireQuantumMemory((size_t)
- GetNumberOfElementsInLinkedList(log_list)+1UL,sizeof(*preferences));
+ GetNumberOfElementsInLinkedList(log_cache)+1UL,sizeof(*preferences));
if (preferences == (char **) NULL)
return((char **) NULL);
/*
Generate log list.
*/
LockSemaphoreInfo(log_semaphore);
- ResetLinkedListIterator(log_list);
- p=(const LogInfo *) GetNextValueInLinkedList(log_list);
+ ResetLinkedListIterator(log_cache);
+ p=(const LogInfo *) GetNextValueInLinkedList(log_cache);
for (i=0; p != (const LogInfo *) NULL; )
{
if ((p->stealth == MagickFalse) &&
(GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
preferences[i++]=ConstantString(p->name);
- p=(const LogInfo *) GetNextValueInLinkedList(log_list);
+ p=(const LogInfo *) GetNextValueInLinkedList(log_cache);
}
UnlockSemaphoreInfo(log_semaphore);
qsort((void *) preferences,(size_t) i,sizeof(*preferences),LogCompare);
% %
% %
% %
-+ I n i t i a l i z e L o g L i s t %
++ I s L o g C a c h e I n s t a n t i a t e d %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% InitializeLogList() initialize the log list.
+% IsLogCacheInstantiated() determines if the log list is instantiated. If
+% not, it instantiates the list and returns it.
%
-% The format of the InitializeLogList method is:
+% The format of the IsLogInstantiated method is:
%
-% MagickBooleanType InitializeLogList(ExceptionInfo *exception)
+% MagickBooleanType IsLogCacheInstantiated(ExceptionInfo *exception)
%
% A description of each parameter follows.
%
% o exception: return any errors or warnings in this structure.
%
*/
-static MagickBooleanType InitializeLogList(ExceptionInfo *exception)
+static MagickBooleanType IsLogCacheInstantiated(ExceptionInfo *exception)
{
- if ((log_list == (LinkedListInfo *) NULL) ||
- (instantiate_log == MagickFalse))
+ if (log_cache == (LinkedListInfo *) NULL)
{
if (log_semaphore == (SemaphoreInfo *) NULL)
ActivateSemaphoreInfo(&log_semaphore);
LockSemaphoreInfo(log_semaphore);
- if ((log_list == (LinkedListInfo *) NULL) ||
- (instantiate_log == MagickFalse))
- {
- (void) LoadLogLists(LogFilename,exception);
- instantiate_log=MagickTrue;
- }
+ if (log_cache == (LinkedListInfo *) NULL)
+ log_cache=AcquireLogCache(LogFilename,exception);
UnlockSemaphoreInfo(log_semaphore);
}
- return(log_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
+ return(log_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
}
\f
/*
ExceptionInfo
*exception;
- if ((log_list == (LinkedListInfo *) NULL) ||
- (IsLinkedListEmpty(log_list) != MagickFalse))
+ if ((log_cache == (LinkedListInfo *) NULL) ||
+ (IsLinkedListEmpty(log_cache) != MagickFalse))
return(MagickFalse);
exception=AcquireExceptionInfo();
log_info=GetLogInfo("*",exception);
size_t
mask;
+ if (LogHandlers[j].name == (const char *) NULL)
+ break;
mask=1;
mask<<=j;
if ((log_info[i]->handler_mask & mask) != 0)
ExceptionInfo
*exception;
- log_semaphore=AcquireSemaphoreInfo();
+ if (log_semaphore == (SemaphoreInfo *) NULL)
+ log_semaphore=AcquireSemaphoreInfo();
exception=AcquireExceptionInfo();
(void) GetLogInfo("*",exception);
exception=DestroyExceptionInfo(exception);
+ event_semaphore=AcquireSemaphoreInfo();
return(MagickTrue);
}
\f
MagickPrivate void LogComponentTerminus(void)
{
+ if (event_semaphore == (SemaphoreInfo *) NULL)
+ ActivateSemaphoreInfo(&event_semaphore);
+ LockSemaphoreInfo(event_semaphore);
+ UnlockSemaphoreInfo(event_semaphore);
+ RelinquishSemaphoreInfo(&event_semaphore);
if (log_semaphore == (SemaphoreInfo *) NULL)
ActivateSemaphoreInfo(&log_semaphore);
LockSemaphoreInfo(log_semaphore);
- if (log_list != (LinkedListInfo *) NULL)
- log_list=DestroyLinkedList(log_list,DestroyLogElement);
- instantiate_log=MagickFalse;
+ if (log_cache != (LinkedListInfo *) NULL)
+ log_cache=DestroyLinkedList(log_cache,DestroyLogElement);
UnlockSemaphoreInfo(log_semaphore);
RelinquishSemaphoreInfo(&log_semaphore);
}
exception=AcquireExceptionInfo();
log_info=(LogInfo *) GetLogInfo("*",exception);
exception=DestroyExceptionInfo(exception);
- LockSemaphoreInfo(log_semaphore);
+ if (event_semaphore == (SemaphoreInfo *) NULL)
+ ActivateSemaphoreInfo(&event_semaphore);
+ LockSemaphoreInfo(event_semaphore);
if ((log_info->event_mask & type) == 0)
{
- UnlockSemaphoreInfo(log_semaphore);
+ UnlockSemaphoreInfo(event_semaphore);
return(MagickTrue);
}
domain=CommandOptionToMnemonic(MagickLogEventOptions,type);
if (text == (char *) NULL)
{
(void) ContinueTimer((TimerInfo *) &log_info->timer);
- UnlockSemaphoreInfo(log_semaphore);
+ UnlockSemaphoreInfo(event_semaphore);
return(MagickFalse);
}
if ((log_info->handler_mask & ConsoleHandler) != 0)
if (filename == (char *) NULL)
{
(void) ContinueTimer((TimerInfo *) &log_info->timer);
- UnlockSemaphoreInfo(log_semaphore);
+ UnlockSemaphoreInfo(event_semaphore);
return(MagickFalse);
}
log_info->append=IsPathAccessible(filename);
filename=(char *) RelinquishMagickMemory(filename);
if (log_info->file == (FILE *) NULL)
{
- UnlockSemaphoreInfo(log_semaphore);
+ UnlockSemaphoreInfo(event_semaphore);
return(MagickFalse);
}
log_info->generation++;
"encoding=\"UTF-8\" standalone=\"yes\"?>\n");
(void) FormatLocaleFile(log_info->file,"<log>\n");
}
- (void) FormatLocaleFile(log_info->file," <event>%s</event>\n",text);
+ (void) FormatLocaleFile(log_info->file," <event>%s</event>\n",text);
(void) fflush(log_info->file);
}
if ((log_info->handler_mask & MethodHandler) != 0)
}
text=(char *) RelinquishMagickMemory(text);
(void) ContinueTimer((TimerInfo *) &log_info->timer);
- UnlockSemaphoreInfo(log_semaphore);
+ UnlockSemaphoreInfo(event_semaphore);
return(MagickTrue);
}
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% LoadLogList() loads the log configuration file which provides a
+% LoadLogCache() loads the log configurations which provides a
% mapping between log attributes and log name.
%
-% The format of the LoadLogList method is:
+% The format of the LoadLogCache method is:
%
-% MagickBooleanType LoadLogList(const char *xml,const char *filename,
-% const size_t depth,ExceptionInfo *exception)
+% MagickBooleanType LoadLogCache(LinkedListInfo *log_cache,const char *xml,
+% const char *filename,const size_t depth,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o exception: return any errors or warnings in this structure.
%
*/
-static MagickBooleanType LoadLogList(const char *xml,const char *filename,
- const size_t depth,ExceptionInfo *exception)
+static MagickBooleanType LoadLogCache(LinkedListInfo *log_cache,const char *xml,
+ const char *filename,const size_t depth,ExceptionInfo *exception)
{
char
keyword[MaxTextExtent],
*/
if (xml == (const char *) NULL)
return(MagickFalse);
- if (log_list == (LinkedListInfo *) NULL)
- {
- log_list=NewLinkedList(0);
- if (log_list == (LinkedListInfo *) NULL)
- {
- ThrowFileException(exception,ResourceLimitError,
- "MemoryAllocationFailed",filename);
- return(MagickFalse);
- }
- }
status=MagickTrue;
token=AcquireString((const char *) xml);
for (q=(const char *) xml; *q != '\0'; )
(void) CopyMagickString(path,token,MaxTextExtent);
else
(void) ConcatenateMagickString(path,token,MaxTextExtent);
- xml=FileToString(path,~0UL,exception);
+ xml=FileToXML(path,~0UL);
if (xml != (char *) NULL)
{
- status&=LoadLogList(xml,path,depth+1,exception);
+ status&=LoadLogCache(log_cache,xml,path,depth+1,
+ exception);
xml=DestroyString(xml);
}
}
continue;
if (LocaleCompare(keyword,"</logmap>") == 0)
{
- status=AppendValueToLinkedList(log_list,log_info);
+ status=AppendValueToLinkedList(log_cache,log_info);
if (status == MagickFalse)
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",filename);
}
}
token=DestroyString(token);
- if (log_list == (LinkedListInfo *) NULL)
+ if (log_cache == (LinkedListInfo *) NULL)
return(MagickFalse);
return(status != 0 ? MagickTrue : MagickFalse);
}
% %
% %
% %
-% L o a d L o g L i s t s %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% LoadLogLists() loads one or more log configuration file which provides a
-% mapping between log attributes and log name.
-%
-% The format of the LoadLogLists method is:
-%
-% MagickBooleanType LoadLogLists(const char *filename,
-% ExceptionInfo *exception)
-%
-% A description of each parameter follows:
-%
-% o filename: the log configuration filename.
-%
-% o exception: return any errors or warnings in this structure.
-%
-*/
-static MagickBooleanType LoadLogLists(const char *filename,
- ExceptionInfo *exception)
-{
- const StringInfo
- *option;
-
- LinkedListInfo
- *options;
-
- MagickStatusType
- status;
-
- register ssize_t
- i;
-
- /*
- Load external log map.
- */
- if (log_list == (LinkedListInfo *) NULL)
- {
- log_list=NewLinkedList(0);
- if (log_list == (LinkedListInfo *) NULL)
- {
- ThrowFileException(exception,ResourceLimitError,
- "MemoryAllocationFailed",filename);
- return(MagickFalse);
- }
- }
- status=MagickTrue;
- options=GetConfigureOptions(filename,exception);
- option=(const StringInfo *) GetNextValueInLinkedList(options);
- while (option != (const StringInfo *) NULL)
- {
- status&=LoadLogList((const char *) GetStringInfoDatum(option),
- GetStringInfoPath(option),0,exception);
- option=(const StringInfo *) GetNextValueInLinkedList(options);
- }
- options=DestroyConfigureOptions(options);
- /*
- Load built-in log map.
- */
- for (i=0; i < (ssize_t) (sizeof(LogMap)/sizeof(*LogMap)); i++)
- {
- LogInfo
- *log_info;
-
- register const LogMapInfo
- *p;
-
- p=LogMap+i;
- log_info=(LogInfo *) AcquireMagickMemory(sizeof(*log_info));
- if (log_info == (LogInfo *) NULL)
- {
- (void) ThrowMagickException(exception,GetMagickModule(),
- ResourceLimitError,"MemoryAllocationFailed","`%s'",p->filename);
- continue;
- }
- (void) ResetMagickMemory(log_info,0,sizeof(*log_info));
- log_info->path=ConstantString("[built-in]");
- GetTimerInfo((TimerInfo *) &log_info->timer);
- log_info->event_mask=p->event_mask;
- log_info->handler_mask=p->handler_mask;
- log_info->filename=ConstantString(p->filename);
- log_info->format=ConstantString(p->format);
- log_info->signature=MagickSignature;
- status&=AppendValueToLinkedList(log_list,log_info);
- if (status == MagickFalse)
- (void) ThrowMagickException(exception,GetMagickModule(),
- ResourceLimitError,"MemoryAllocationFailed","`%s'",log_info->name);
- }
- return(status != 0 ? MagickTrue : MagickFalse);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
+ P a r s e L o g H a n d l e r s %
% %
% %
exception=DestroyExceptionInfo(exception);
option=ParseCommandOption(MagickLogEventOptions,MagickTrue,events);
LockSemaphoreInfo(log_semaphore);
- log_info=(LogInfo *) GetValueFromLinkedList(log_list,0);
+ log_info=(LogInfo *) GetValueFromLinkedList(log_cache,0);
log_info->event_mask=(LogEventType) option;
if (option == -1)
log_info->event_mask=UndefinedEvents;
log_info=(LogInfo *) GetLogInfo("*",exception);
exception=DestroyExceptionInfo(exception);
LockSemaphoreInfo(log_semaphore);
- log_info=(LogInfo *) GetValueFromLinkedList(log_list,0);
+ log_info=(LogInfo *) GetValueFromLinkedList(log_cache,0);
log_info->handler_mask=(LogHandlerType) (log_info->handler_mask |
MethodHandler);
log_info->method=method;