Skip to content

Commit

Permalink
Patch to make sure the container limit is only done on non windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Nov 9, 2024
1 parent 78f65f8 commit c7b5d68
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Magick.Native/ResourceLimits.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,19 @@ MAGICK_NATIVE_EXPORT void ResourceLimits_Width_Set(const MagickSizeType limit)

static unsigned long long GetContainerMemoryLimit()
{
#if defined(MAGICK_NATIVE_WINDOWS)
return 0;
#else
int
fd;

unsigned long long
memory_limit;

memory_limit = 0;
fd = _open("/sys/fs/cgroup/memory/memory.limit_in_bytes", O_RDONLY);
fd = open("/sys/fs/cgroup/memory/memory.limit_in_bytes", O_RDONLY);
if (fd == -1)
fd = _open("/sys/fs/cgroup/memory.max", O_RDONLY);
fd = open("/sys/fs/cgroup/memory.max", O_RDONLY);
if (fd != -1)
{
char
Expand All @@ -146,15 +149,17 @@ static unsigned long long GetContainerMemoryLimit()
int
count;

count = _read(fd, buffer, sizeof(buffer) - 1);
count = read(fd, buffer, sizeof(buffer) - 1);
if (count != -1)
{
buffer[count] = '\0';
memory_limit = strtoull(buffer, NULL, 10);
}
close(fd);
}

return memory_limit;
#endif
}

MAGICK_NATIVE_EXPORT void ResourceLimits_LimitMemory(const double percentage)
Expand Down

0 comments on commit c7b5d68

Please sign in to comment.