Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hsh-maxima
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
hsh-maxima
Commits
8a19c2cc
Commit
8a19c2cc
authored
2 years ago
by
Lennart Kramer
Browse files
Options
Downloads
Patches
Plain Diff
add nproc rlimit
parent
af49de98
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/maxima_fork.c
+30
-7
30 additions, 7 deletions
src/maxima_fork.c
with
30 additions
and
7 deletions
src/maxima_fork.c
+
30
−
7
View file @
8a19c2cc
...
...
@@ -14,10 +14,23 @@
#include
<bsd/unistd.h>
#include
<limits.h>
#include
<grp.h>
// number of processes
#ifndef N_SLOT
#define N_SLOT 32
#endif
// maximum number of open file descriptors
#ifndef RNOFILE
#define RNOFILE 256
#endif
// maximum number of threads that the current user may have
// note that this is not limited to the container but the global user
// so make sure to make this reasonably high
#ifndef RNPROC
#define RNPROC 4096
#endif
#define FILEPATH_LEN (PATH_MAX + 1)
char
filepath
[
FILEPATH_LEN
];
...
...
@@ -125,6 +138,13 @@ char *fork_new_process() {
continue
;
}
// verify valid slot number
if
(
slot
<=
0
||
slot
>
N_SLOT
)
{
dprintf
(
STDERR_FILENO
,
"Invalid slot number: %d
\n
"
,
slot
);
ret
=
NULL
;
break
;
}
uid_t
uid
=
user_id
[
slot
-
1
];
gid_t
gid
=
group_id
[
slot
-
1
];
// note: setgid should be executed before setuid when dropping from root
...
...
@@ -154,6 +174,16 @@ char *fork_new_process() {
break
;
}
// to prevent fork bombs from slowing down the server to a crawl,
// limit the number of processes the user may have
struct
rlimit
noproc
=
{
.
rlim_cur
=
RNPROC
,
.
rlim_max
=
RNPROC
};
if
(
setrlimit
(
RLIMIT_NPROC
,
&
noproc
)
==
-
1
)
{
perror
(
"Error setting rlimit_nproc"
);
ret
=
NULL
;
break
;
}
// redirect stdout to pipe
// note: open outpipe before inpipe to avoid deadlock
if
(
!
freopen
(
"outpipe"
,
"a"
,
stdout
))
{
...
...
@@ -173,13 +203,6 @@ char *fork_new_process() {
// note: this is a function from libbsd
closefrom
(
3
);
// verify valid slot number
if
(
slot
<=
0
||
slot
>
N_SLOT
)
{
dprintf
(
STDERR_FILENO
,
"Invalid slot number: %d
\n
"
,
slot
);
ret
=
NULL
;
break
;
}
// create temporary folders and files
if
(
mkdir
(
"output"
,
0755
)
==
-
1
)
{
perror
(
"Could not create output directory"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment