42#include "MagickCore/studio.h"
43#include "MagickCore/cache.h"
44#include "MagickCore/configure.h"
45#include "MagickCore/exception.h"
46#include "MagickCore/exception-private.h"
47#include "MagickCore/linked-list.h"
48#include "MagickCore/log.h"
49#include "MagickCore/image.h"
50#include "MagickCore/image-private.h"
51#include "MagickCore/memory_.h"
52#include "MagickCore/nt-base-private.h"
53#include "MagickCore/option.h"
54#include "MagickCore/policy.h"
55#include "MagickCore/random_.h"
56#include "MagickCore/registry.h"
57#include "MagickCore/resource_.h"
58#include "MagickCore/resource-private.h"
59#include "MagickCore/semaphore.h"
60#include "MagickCore/signature-private.h"
61#include "MagickCore/string_.h"
62#include "MagickCore/string-private.h"
63#include "MagickCore/splay-tree.h"
64#include "MagickCore/thread-private.h"
65#include "MagickCore/timer-private.h"
66#include "MagickCore/token.h"
67#include "MagickCore/utility.h"
68#include "MagickCore/utility-private.h"
73#define NumberOfResourceTypes \
74 (sizeof(resource_semaphore)/sizeof(*resource_semaphore))
117 MagickULLConstant(0),
118 MagickULLConstant(0),
119 MagickULLConstant(0),
120 MagickULLConstant(0),
121 MagickULLConstant(0),
122 MagickULLConstant(0),
123 MagickULLConstant(0),
124 MagickULLConstant(0),
125 MagickULLConstant(0),
126 MagickULLConstant(0),
127 MagickULLConstant(0),
128 (MagickSizeType) (MAGICK_SSIZE_MAX/
sizeof(Quantum)/MaxPixelChannels),
129 (MagickSizeType) (MAGICK_SSIZE_MAX/
sizeof(Quantum)/MaxPixelChannels),
130 MagickResourceInfinity,
131 MagickULLConstant(3072)*1024*1024,
132 MagickULLConstant(1536)*1024*1024,
133 MagickULLConstant(3072)*1024*1024,
134 MagickResourceInfinity,
135 MagickULLConstant(768),
136 MagickULLConstant(1),
137 MagickULLConstant(0),
138 MagickULLConstant(0),
142 *resource_semaphore[] = {
187MagickExport MagickBooleanType AcquireMagickResource(
const ResourceType type,
188 const MagickSizeType size)
201 request=(MagickOffsetType) size;
217 ActivateSemaphoreInfo(&resource_semaphore[type]);
218 LockSemaphoreInfo(resource_semaphore[type]);
228 resource_info.area=request;
229 limit=resource_info.area_limit;
230 if ((limit == MagickResourceInfinity) || (size < limit))
237 limit=resource_info.disk_limit;
238 if (((MagickSizeType) resource_info.disk+(MagickSizeType) request) > (MagickSizeType) resource_info.disk)
240 resource_info.disk+=request;
241 if ((limit == MagickResourceInfinity) ||
242 (resource_info.disk < (MagickOffsetType) limit))
245 resource_info.disk-=request;
247 current=resource_info.disk;
252 limit=resource_info.file_limit;
253 if (((MagickSizeType) resource_info.file+(MagickSizeType) request) > (MagickSizeType) resource_info.file)
255 resource_info.file+=request;
256 if ((limit == MagickResourceInfinity) ||
257 (resource_info.file < (MagickOffsetType) limit))
260 current=resource_info.file;
266 resource_info.height=request;
267 limit=resource_info.height_limit;
268 if ((limit == MagickResourceInfinity) || (size < limit))
272 case ListLengthResource:
274 resource_info.list_length=request;
275 limit=resource_info.list_length_limit;
276 if ((limit == MagickResourceInfinity) || (size < limit))
283 limit=resource_info.map_limit;
284 if (((MagickSizeType) resource_info.map+(MagickSizeType) request) > (MagickSizeType) resource_info.map)
286 resource_info.map+=request;
287 if ((limit == MagickResourceInfinity) ||
288 (resource_info.map < (MagickOffsetType) limit))
291 resource_info.map-=request;
293 current=resource_info.map;
299 limit=resource_info.memory_limit;
300 if (((MagickSizeType) resource_info.memory+(MagickSizeType) request) > (MagickSizeType) resource_info.memory)
302 resource_info.memory+=request;
303 if ((limit == MagickResourceInfinity) ||
304 (resource_info.memory < (MagickOffsetType) limit))
307 resource_info.memory-=request;
309 current=resource_info.memory;
314 limit=resource_info.thread_limit;
315 if ((limit == MagickResourceInfinity) ||
316 (resource_info.thread < (MagickOffsetType) limit))
320 case ThrottleResource:
322 limit=resource_info.throttle_limit;
323 if ((limit == MagickResourceInfinity) ||
324 (resource_info.throttle < (MagickOffsetType) limit))
330 limit=resource_info.time_limit;
331 if (((MagickSizeType) resource_info.time+(MagickSizeType) request) > (MagickSizeType) resource_info.time)
333 resource_info.time+=request;
334 if ((limit == 0) || (resource_info.time < (MagickOffsetType) limit))
337 resource_info.time-=request;
339 current=resource_info.time;
345 resource_info.width=request;
346 limit=resource_info.width_limit;
347 if ((limit == MagickResourceInfinity) || (size < limit))
365 UnlockSemaphoreInfo(resource_semaphore[type]);
370 if ((GetLogEventMask() & ResourceEvent) != 0)
373 resource_current[MagickFormatExtent],
374 resource_limit[MagickFormatExtent],
375 resource_request[MagickFormatExtent];
377 (void) FormatMagickSize(size,bi,(bi != MagickFalse) ?
"B" :
378 (
const char *) NULL,MagickFormatExtent,resource_request);
379 (void) FormatMagickSize((MagickSizeType) current,bi,(bi != MagickFalse) ?
380 "B" : (const char *) NULL,MagickFormatExtent,resource_current);
381 (void) FormatMagickSize(limit,bi,(bi != MagickFalse) ?
"B" :
382 (
const char *) NULL,MagickFormatExtent,resource_limit);
383 (void) LogMagickEvent(ResourceEvent,GetMagickModule(),
"%s: %s/%s/%s",
384 CommandOptionToMnemonic(MagickResourceOptions,(ssize_t) type),
385 resource_request,resource_current,resource_limit);
410MagickExport
void AsynchronousResourceComponentTerminus(
void)
420 ResetSplayTreeIterator(temporary_resources);
421 path=(
const char *) GetNextKeyInSplayTree(temporary_resources);
422 while (path != (
const char *) NULL)
424 (void) ShredFile(path);
425 (void) remove_utf8(path);
426 path=(
const char *) GetNextKeyInSplayTree(temporary_resources);
455static void *DestroyTemporaryResources(
void *temporary_resource)
457 (void) ShredFile((
char *) temporary_resource);
458 (void) remove_utf8((
char *) temporary_resource);
459 temporary_resource=DestroyString((
char *) temporary_resource);
460 return((
void *) NULL);
463MagickExport
int AcquireUniqueFileResource(
char *path)
465#if !defined(O_NOFOLLOW)
469# define TMP_MAX 238328
483 portable_filename[65] =
484 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
492 assert(path != (
char *) NULL);
493 if ((GetLogEventMask() & ResourceEvent) != 0)
494 (void) LogMagickEvent(ResourceEvent,GetMagickModule(),
"...");
497 if (resource_semaphore[FileResource] == (
SemaphoreInfo *) NULL)
498 ActivateSemaphoreInfo(&resource_semaphore[FileResource]);
499 LockSemaphoreInfo(resource_semaphore[FileResource]);
501 random_info=AcquireRandomInfo();
502 UnlockSemaphoreInfo(resource_semaphore[FileResource]);
505 for (i=0; i < (ssize_t) TMP_MAX; i++)
513 (void) GetPathTemplate(path);
514 key=GetRandomKey(random_info,strlen(MagickPathTemplate)-6);
515 p=path+strlen(path)-strlen(MagickPathTemplate);
516 datum=GetStringInfoDatum(key);
517 for (j=0; j < (ssize_t) GetStringInfoLength(key); j++)
519 c=(int) (datum[j] & 0x3f);
520 *p++=portable_filename[c];
522 key=DestroyStringInfo(key);
523#if defined(MAGICKCORE_HAVE_MKSTEMP)
527#if defined(MAGICKCORE_HAVE_FCHMOD)
528 (void) fchmod(file,0600);
531 setmode(file,O_BINARY);
536 key=GetRandomKey(random_info,strlen(MagickPathTemplate));
537 p=path+strlen(path)-strlen(MagickPathTemplate);
538 datum=GetStringInfoDatum(key);
539 for (j=0; j < (ssize_t) GetStringInfoLength(key); j++)
541 c=(int) (datum[j] & 0x3f);
542 *p++=portable_filename[c];
544 key=DestroyStringInfo(key);
545 file=open_utf8(path,O_RDWR | O_CREAT | O_EXCL | O_BINARY | O_NOFOLLOW,
547 if ((file >= 0) || (errno != EEXIST))
550 if ((GetLogEventMask() & ResourceEvent) != 0)
551 (void) LogMagickEvent(ResourceEvent,GetMagickModule(),
"%s",path);
554 if (resource_semaphore[FileResource] == (
SemaphoreInfo *) NULL)
555 ActivateSemaphoreInfo(&resource_semaphore[FileResource]);
556 LockSemaphoreInfo(resource_semaphore[FileResource]);
558 temporary_resources=NewSplayTree(CompareSplayTreeString,
559 DestroyTemporaryResources,(
void *(*)(
void *)) NULL);
560 UnlockSemaphoreInfo(resource_semaphore[FileResource]);
561 (void) AddValueToSplayTree(temporary_resources,ConstantString(path),
562 (
const void *) NULL);
588MagickExport MagickSizeType GetMagickResource(
const ResourceType type)
603 ActivateSemaphoreInfo(&resource_semaphore[type]);
604 LockSemaphoreInfo(resource_semaphore[type]);
613 resource=(MagickSizeType) resource_info.area;
618 resource=(MagickSizeType) resource_info.disk;
623 resource=(MagickSizeType) resource_info.file;
628 resource=(MagickSizeType) resource_info.height;
631 case ListLengthResource:
633 resource=(MagickSizeType) resource_info.list_length;
638 resource=(MagickSizeType) resource_info.map;
643 resource=(MagickSizeType) resource_info.memory;
648 resource=(MagickSizeType) resource_info.time;
653 resource=(MagickSizeType) resource_info.thread;
656 case ThrottleResource:
658 resource=(MagickSizeType) resource_info.throttle;
663 resource=(MagickSizeType) resource_info.width;
677 UnlockSemaphoreInfo(resource_semaphore[type]);
708MagickExport MagickBooleanType IsFileResourceIdentityValid(
const char *path)
711 *temporary_attributes;
721 LockSemaphoreInfo(resource_semaphore[FileResource]);
722 temporary_attributes=(
const struct stat *) GetValueFromSplayTree(
723 temporary_resources,(
const void *) path);
724 if (temporary_attributes != (
const struct stat *) NULL)
726 status=GetPathAttributes(path,&attributes);
727 if (status != MagickFalse)
728 if ((attributes.st_dev != temporary_attributes->st_dev) ||
729 (attributes.st_ino != temporary_attributes->st_ino) ||
730 (attributes.st_mode != temporary_attributes->st_mode))
733 UnlockSemaphoreInfo(resource_semaphore[FileResource]);
759MagickExport MagickSizeType GetMagickResourceLimit(
const ResourceType type)
767 return(resource_info.area_limit);
769 return(resource_info.height_limit);
770 case ListLengthResource:
771 return(resource_info.list_length_limit);
773 return(resource_info.thread_limit);
774 case ThrottleResource:
775 return(resource_info.throttle_limit);
777 return(resource_info.width_limit);
782 ActivateSemaphoreInfo(&resource_semaphore[type]);
783 LockSemaphoreInfo(resource_semaphore[type]);
788 resource=resource_info.disk_limit;
793 resource=resource_info.file_limit;
798 resource=resource_info.map_limit;
803 resource=resource_info.memory_limit;
808 resource=resource_info.time_limit;
814 UnlockSemaphoreInfo(resource_semaphore[type]);
844static void FormatTimeToLive(
const MagickSizeType ttl,
char *timeString)
856 seconds=ttl % 31536000;
859 (void) FormatLocaleString(timeString,MagickPathExtent,
"%lld years",years);
863 seconds=ttl % 2628000;
866 (void) FormatLocaleString(timeString,MagickPathExtent,
"%lld months",
871 seconds=ttl % 604800;
874 (void) FormatLocaleString(timeString,MagickPathExtent,
"%lld weeks",weeks);
881 (void) FormatLocaleString(timeString,MagickPathExtent,
"%lld days",days);
888 (void) FormatLocaleString(timeString,MagickPathExtent,
"%lld hours",hours);
895 (void) FormatLocaleString(timeString,MagickPathExtent,
"%lld minutes",
899 (void) FormatLocaleString(timeString,MagickPathExtent,
"%lld seconds",ttl);
902MagickExport MagickBooleanType ListMagickResourceInfo(FILE *file,
906 area_limit[MagickFormatExtent],
907 disk_limit[MagickFormatExtent],
908 height_limit[MagickFormatExtent],
909 list_length_limit[MagickFormatExtent],
910 map_limit[MagickFormatExtent],
911 memory_limit[MagickFormatExtent],
912 time_limit[MagickFormatExtent],
913 width_limit[MagickFormatExtent];
915 magick_unreferenced(exception);
917 if (file == (
const FILE *) NULL)
919 if (resource_semaphore[FileResource] == (
SemaphoreInfo *) NULL)
920 ActivateSemaphoreInfo(&resource_semaphore[FileResource]);
921 LockSemaphoreInfo(resource_semaphore[FileResource]);
922 (void) FormatMagickSize(resource_info.width_limit,MagickFalse,
"P",
923 MagickFormatExtent,width_limit);
924 (void) FormatMagickSize(resource_info.height_limit,MagickFalse,
"P",
925 MagickFormatExtent,height_limit);
926 (void) FormatMagickSize(resource_info.area_limit,MagickFalse,
"P",
927 MagickFormatExtent,area_limit);
928 (void) CopyMagickString(list_length_limit,
"unlimited",MagickFormatExtent);
929 if (resource_info.list_length_limit != MagickResourceInfinity)
930 (void) FormatMagickSize(resource_info.list_length_limit,MagickTrue,
"B",
931 MagickFormatExtent,list_length_limit);
932 (void) FormatMagickSize(resource_info.memory_limit,MagickTrue,
"B",
933 MagickFormatExtent,memory_limit);
934 (void) FormatMagickSize(resource_info.map_limit,MagickTrue,
"B",
935 MagickFormatExtent,map_limit);
936 (void) CopyMagickString(disk_limit,
"unlimited",MagickFormatExtent);
937 if (resource_info.disk_limit != MagickResourceInfinity)
938 (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,
"B",
939 MagickFormatExtent,disk_limit);
940 (void) CopyMagickString(time_limit,
"unlimited",MagickFormatExtent);
941 if (resource_info.time_limit != 0)
942 FormatTimeToLive(resource_info.time_limit,time_limit);
943 (void) FormatLocaleFile(file,
"Resource limits:\n");
944 (void) FormatLocaleFile(file,
" Width: %s\n",width_limit);
945 (void) FormatLocaleFile(file,
" Height: %s\n",height_limit);
946 (void) FormatLocaleFile(file,
" Area: %s\n",area_limit);
947 (void) FormatLocaleFile(file,
" List length: %s\n",list_length_limit);
948 (void) FormatLocaleFile(file,
" Memory: %s\n",memory_limit);
949 (void) FormatLocaleFile(file,
" Map: %s\n",map_limit);
950 (void) FormatLocaleFile(file,
" Disk: %s\n",disk_limit);
951 (void) FormatLocaleFile(file,
" File: %.20g\n",(
double) ((MagickOffsetType)
952 resource_info.file_limit));
953 (void) FormatLocaleFile(file,
" Thread: %.20g\n",(
double) ((MagickOffsetType)
954 resource_info.thread_limit));
955 (void) FormatLocaleFile(file,
" Throttle: %.20g\n",(
double)
956 ((MagickOffsetType) resource_info.throttle_limit));
957 (void) FormatLocaleFile(file,
" Time: %s\n",time_limit);
959 UnlockSemaphoreInfo(resource_semaphore[FileResource]);
988MagickExport
void RelinquishMagickResource(
const ResourceType type,
989 const MagickSizeType size)
1006 case MemoryResource:
1010 ActivateSemaphoreInfo(&resource_semaphore[type]);
1011 LockSemaphoreInfo(resource_semaphore[type]);
1021 resource_info.disk-=(MagickOffsetType) size;
1022 current=(MagickSizeType) resource_info.disk;
1023 limit=resource_info.disk_limit;
1024 assert(resource_info.disk >= 0);
1029 resource_info.file-=(MagickOffsetType) size;
1030 current=(MagickSizeType) resource_info.file;
1031 limit=resource_info.file_limit;
1032 assert(resource_info.file >= 0);
1038 resource_info.map-=(MagickOffsetType) size;
1039 current=(MagickSizeType) resource_info.map;
1040 limit=resource_info.map_limit;
1041 assert(resource_info.map >= 0);
1044 case MemoryResource:
1047 resource_info.memory-=(MagickOffsetType) size;
1048 current=(MagickSizeType) resource_info.memory;
1049 limit=resource_info.memory_limit;
1050 assert(resource_info.memory >= 0);
1056 resource_info.time-=(MagickOffsetType) size;
1057 current=(MagickSizeType) resource_info.time;
1058 limit=resource_info.time_limit;
1059 assert(resource_info.time >= 0);
1073 case MemoryResource:
1076 UnlockSemaphoreInfo(resource_semaphore[type]);
1081 if ((GetLogEventMask() & ResourceEvent) != 0)
1084 resource_current[MagickFormatExtent],
1085 resource_limit[MagickFormatExtent],
1086 resource_request[MagickFormatExtent];
1088 (void) FormatMagickSize(size,bi,(bi != MagickFalse) ?
"B" :
1089 (
const char *) NULL,MagickFormatExtent,resource_request);
1090 (void) FormatMagickSize(current,bi,(bi != MagickFalse) ?
"B" :
1091 (
const char *) NULL,MagickFormatExtent,resource_current);
1092 (void) FormatMagickSize(limit,bi,(bi != MagickFalse) ?
"B" :
1093 (
const char *) NULL,MagickFormatExtent,resource_limit);
1094 (void) LogMagickEvent(ResourceEvent,GetMagickModule(),
"%s: %s/%s/%s",
1095 CommandOptionToMnemonic(MagickResourceOptions,(ssize_t) type),
1096 resource_request,resource_current,resource_limit);
1122MagickExport MagickBooleanType RelinquishUniqueFileResource(
const char *path)
1125 cache_path[MagickPathExtent];
1130 assert(path != (
const char *) NULL);
1132 if ((GetLogEventMask() & ResourceEvent) != 0)
1133 (void) LogMagickEvent(ResourceEvent,GetMagickModule(),
"%s",path);
1134 if (resource_semaphore[FileResource] == (
SemaphoreInfo *) NULL)
1135 ActivateSemaphoreInfo(&resource_semaphore[FileResource]);
1136 LockSemaphoreInfo(resource_semaphore[FileResource]);
1138 status=DeleteNodeFromSplayTree(temporary_resources,(
const void *) path);
1139 UnlockSemaphoreInfo(resource_semaphore[FileResource]);
1140 (void) CopyMagickString(cache_path,path,MagickPathExtent);
1141 AppendImageFormat(
"cache",cache_path);
1142 if (access_utf8(cache_path,F_OK) == 0)
1144 status=ShredFile(cache_path);
1145 status|=(MagickStatusType) remove_utf8(cache_path);
1147 if (status == MagickFalse)
1149 status=ShredFile(path);
1150 status|=(MagickStatusType) remove_utf8(path);
1152 return(status == 0 ? MagickFalse : MagickTrue);
1174MagickPrivate MagickBooleanType ResourceComponentGenesis(
void)
1192 for (i=0; i < (ssize_t) NumberOfResourceTypes; i++)
1194 resource_semaphore[i]=AcquireSemaphoreInfo();
1195 (void) SetMagickResourceLimit(WidthResource,resource_info.width_limit);
1196 limit=GetEnvironmentValue(
"MAGICK_WIDTH_LIMIT");
1197 if (limit != (
char *) NULL)
1199 (void) SetMagickResourceLimit(WidthResource,StringToMagickSizeType(limit,
1201 limit=DestroyString(limit);
1203 (void) SetMagickResourceLimit(HeightResource,resource_info.height_limit);
1204 limit=GetEnvironmentValue(
"MAGICK_HEIGHT_LIMIT");
1205 if (limit != (
char *) NULL)
1207 (void) SetMagickResourceLimit(HeightResource,StringToMagickSizeType(
1209 limit=DestroyString(limit);
1211 pagesize=GetMagickPageSize();
1213#if defined(MAGICKCORE_HAVE_SYSCONF) && defined(_SC_PHYS_PAGES)
1214 pages=(ssize_t) sysconf(_SC_PHYS_PAGES);
1215#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1219 memory=(MagickSizeType) ((MagickOffsetType) pages*pagesize);
1220 if ((pagesize <= 0) || (pages <= 0))
1221 memory=2048UL*1024UL*1024UL;
1222#if defined(MAGICKCORE_PixelCacheThreshold)
1223 memory=MAGICKCORE_PixelCacheThreshold;
1225 (void) SetMagickResourceLimit(AreaResource,4*memory);
1226 limit=GetEnvironmentValue(
"MAGICK_AREA_LIMIT");
1227 if (limit != (
char *) NULL)
1229 (void) SetMagickResourceLimit(AreaResource,StringToMagickSizeType(limit,
1231 limit=DestroyString(limit);
1233 (void) SetMagickResourceLimit(MemoryResource,memory);
1234 limit=GetEnvironmentValue(
"MAGICK_MEMORY_LIMIT");
1235 if (limit != (
char *) NULL)
1237 (void) SetMagickResourceLimit(MemoryResource,StringToMagickSizeType(
1239 limit=DestroyString(limit);
1241 (void) SetMagickResourceLimit(MapResource,2*memory);
1242 limit=GetEnvironmentValue(
"MAGICK_MAP_LIMIT");
1243 if (limit != (
char *) NULL)
1245 (void) SetMagickResourceLimit(MapResource,StringToMagickSizeType(limit,
1247 limit=DestroyString(limit);
1249 (void) SetMagickResourceLimit(DiskResource,MagickResourceInfinity);
1250 limit=GetEnvironmentValue(
"MAGICK_DISK_LIMIT");
1251 if (limit != (
char *) NULL)
1253 (void) SetMagickResourceLimit(DiskResource,StringToMagickSizeType(limit,
1255 limit=DestroyString(limit);
1258#if defined(MAGICKCORE_HAVE_SYSCONF) && defined(_SC_OPEN_MAX)
1259 files=(ssize_t) sysconf(_SC_OPEN_MAX);
1261#if defined(MAGICKCORE_HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
1267 if (getrlimit(RLIMIT_NOFILE,&resources) != -1)
1268 files=(ssize_t) resources.rlim_cur;
1271#if defined(MAGICKCORE_HAVE_GETDTABLESIZE) && defined(MAGICKCORE_POSIX_SUPPORT)
1273 files=(ssize_t) getdtablesize();
1277 (void) SetMagickResourceLimit(FileResource,MagickMax((
size_t)
1279 limit=GetEnvironmentValue(
"MAGICK_FILE_LIMIT");
1280 if (limit != (
char *) NULL)
1282 (void) SetMagickResourceLimit(FileResource,StringToMagickSizeType(limit,
1284 limit=DestroyString(limit);
1286 number_threads=(ssize_t) GetOpenMPMaximumThreads();
1287 if (number_threads > 1)
1289 (void) SetMagickResourceLimit(ThreadResource,(
size_t) number_threads);
1290 limit=GetEnvironmentValue(
"MAGICK_THREAD_LIMIT");
1291 if (limit != (
char *) NULL)
1293 (void) SetMagickResourceLimit(ThreadResource,StringToMagickSizeType(
1295 limit=DestroyString(limit);
1297 (void) SetMagickResourceLimit(ThrottleResource,0);
1298 limit=GetEnvironmentValue(
"MAGICK_THROTTLE_LIMIT");
1299 if (limit != (
char *) NULL)
1301 (void) SetMagickResourceLimit(ThrottleResource,StringToMagickSizeType(
1303 limit=DestroyString(limit);
1305 (void) SetMagickResourceLimit(TimeResource,0);
1306 limit=GetEnvironmentValue(
"MAGICK_TIME_LIMIT");
1307 if (limit != (
char *) NULL)
1309 (void) SetMagickResourceLimit(TimeResource,(MagickSizeType)
1310 ParseMagickTimeToLive(limit));
1311 limit=DestroyString(limit);
1313 (void) SetMagickResourceLimit(ListLengthResource,MagickResourceInfinity);
1314 limit=GetEnvironmentValue(
"MAGICK_LIST_LENGTH_LIMIT");
1315 if (limit != (
char *) NULL)
1317 (void) SetMagickResourceLimit(ListLengthResource,
1318 StringToMagickSizeType(limit,100.0));
1319 limit=DestroyString(limit);
1342MagickPrivate
void ResourceComponentTerminus(
void)
1347 for (i=0; i < (ssize_t) NumberOfResourceTypes; i++)
1349 resource_semaphore[i]=AcquireSemaphoreInfo();
1350 LockSemaphoreInfo(resource_semaphore[FileResource]);
1352 temporary_resources=DestroySplayTree(temporary_resources);
1354 random_info=DestroyRandomInfo(random_info);
1355 UnlockSemaphoreInfo(resource_semaphore[FileResource]);
1356 for (i=0; i < (ssize_t) NumberOfResourceTypes; i++)
1357 RelinquishSemaphoreInfo(&resource_semaphore[i]);
1385MagickExport MagickBooleanType SetMagickResourceLimit(
const ResourceType type,
1386 const MagickSizeType limit)
1395 value=(
char *) NULL;
1401 case MemoryResource:
1405 ActivateSemaphoreInfo(&resource_semaphore[type]);
1406 LockSemaphoreInfo(resource_semaphore[type]);
1415 value=GetPolicyValue(
"resource:area");
1416 if (value == (
char *) NULL)
1417 resource_info.area_limit=limit;
1419 resource_info.area_limit=MagickMin(limit,StringToMagickSizeType(value,
1425 value=GetPolicyValue(
"resource:disk");
1426 if (value == (
char *) NULL)
1427 resource_info.disk_limit=limit;
1429 resource_info.disk_limit=MagickMin(limit,StringToMagickSizeType(value,
1435 value=GetPolicyValue(
"resource:file");
1436 if (value == (
char *) NULL)
1437 resource_info.file_limit=limit;
1439 resource_info.file_limit=MagickMin(limit,StringToMagickSizeType(value,
1443 case HeightResource:
1445 value=GetPolicyValue(
"resource:height");
1446 if (value == (
char *) NULL)
1447 resource_info.height_limit=limit;
1449 resource_info.height_limit=MagickMin(limit,StringToMagickSizeType(
1451 resource_info.height_limit=MagickMin(resource_info.height_limit,
1452 (MagickSizeType) MAGICK_SSIZE_MAX);
1455 case ListLengthResource:
1457 value=GetPolicyValue(
"resource:list-length");
1458 if (value == (
char *) NULL)
1459 resource_info.list_length_limit=limit;
1461 resource_info.list_length_limit=MagickMin(limit,
1462 StringToMagickSizeType(value,100.0));
1467 value=GetPolicyValue(
"resource:map");
1468 if (value == (
char *) NULL)
1469 resource_info.map_limit=limit;
1471 resource_info.map_limit=MagickMin(limit,StringToMagickSizeType(
1475 case MemoryResource:
1477 value=GetPolicyValue(
"resource:memory");
1478 if (value == (
char *) NULL)
1479 resource_info.memory_limit=limit;
1481 resource_info.memory_limit=MagickMin(limit,StringToMagickSizeType(
1485 case ThreadResource:
1487 value=GetPolicyValue(
"resource:thread");
1488 if (value == (
char *) NULL)
1489 resource_info.thread_limit=limit;
1491 resource_info.thread_limit=MagickMin(limit,StringToMagickSizeType(
1493 if (resource_info.thread_limit > GetOpenMPMaximumThreads())
1494 resource_info.thread_limit=GetOpenMPMaximumThreads();
1496 if (resource_info.thread_limit == 0)
1497 resource_info.thread_limit=1;
1500 case ThrottleResource:
1502 value=GetPolicyValue(
"resource:throttle");
1503 if (value == (
char *) NULL)
1504 resource_info.throttle_limit=limit;
1506 resource_info.throttle_limit=MagickMax(limit,StringToMagickSizeType(
1512 value=GetPolicyValue(
"resource:time");
1513 if (value == (
char *) NULL)
1514 resource_info.time_limit=limit;
1516 resource_info.time_limit=MagickMin(limit,(MagickSizeType)
1517 ParseMagickTimeToLive(value));
1522 value=GetPolicyValue(
"resource:width");
1523 if (value == (
char *) NULL)
1524 resource_info.width_limit=limit;
1526 resource_info.width_limit=MagickMin(limit,StringToMagickSizeType(value,
1528 resource_info.width_limit=MagickMin(resource_info.width_limit,
1529 (MagickSizeType) MAGICK_SSIZE_MAX);
1543 case MemoryResource:
1546 UnlockSemaphoreInfo(resource_semaphore[type]);
1551 if (value != (
char *) NULL)
1552 value=DestroyString(value);