diff options
author | netblue30 <netblue30@yahoo.com> | 2016-02-11 09:03:35 -0500 |
---|---|---|
committer | netblue30 <netblue30@yahoo.com> | 2016-02-11 09:03:35 -0500 |
commit | 8fdc4029ad9bd2489aa0266bbbcaefac4fb239d1 (patch) | |
tree | 24b29e51104c6bda6700f1771becf7f41cdcaba0 /src | |
parent | fix problem with relative path in storage_find function (diff) | |
download | firejail-8fdc4029ad9bd2489aa0266bbbcaefac4fb239d1.tar.gz firejail-8fdc4029ad9bd2489aa0266bbbcaefac4fb239d1.tar.zst firejail-8fdc4029ad9bd2489aa0266bbbcaefac4fb239d1.zip |
set sandbox nice value
Diffstat (limited to 'src')
-rw-r--r-- | src/firejail/firejail.h | 4 | ||||
-rw-r--r-- | src/firejail/main.c | 6 | ||||
-rw-r--r-- | src/firejail/profile.c | 7 | ||||
-rw-r--r-- | src/firejail/sandbox.c | 13 | ||||
-rw-r--r-- | src/firejail/usage.c | 1 | ||||
-rw-r--r-- | src/man/firejail-profile.txt | 4 | ||||
-rw-r--r-- | src/man/firejail.txt | 10 |
7 files changed, 43 insertions, 2 deletions
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h index 90c3589d9..feb6854fc 100644 --- a/src/firejail/firejail.h +++ b/src/firejail/firejail.h | |||
@@ -157,8 +157,9 @@ typedef struct config_t { | |||
157 | unsigned rlimit_fsize; | 157 | unsigned rlimit_fsize; |
158 | unsigned rlimit_sigpending; | 158 | unsigned rlimit_sigpending; |
159 | 159 | ||
160 | // cpu affinity and control groups | 160 | // cpu affinity, nice and control groups |
161 | uint32_t cpus; | 161 | uint32_t cpus; |
162 | int nice; | ||
162 | char *cgroup; | 163 | char *cgroup; |
163 | 164 | ||
164 | 165 | ||
@@ -231,6 +232,7 @@ extern int arg_nosound; // disable sound | |||
231 | extern int arg_quiet; // no output for scripting | 232 | extern int arg_quiet; // no output for scripting |
232 | extern int arg_join_network; // join only the network namespace | 233 | extern int arg_join_network; // join only the network namespace |
233 | extern int arg_join_filesystem; // join only the mount namespace | 234 | extern int arg_join_filesystem; // join only the mount namespace |
235 | extern int arg_nice; // nice value configured | ||
234 | 236 | ||
235 | extern int parent_to_child_fds[2]; | 237 | extern int parent_to_child_fds[2]; |
236 | extern int child_to_parent_fds[2]; | 238 | extern int child_to_parent_fds[2]; |
diff --git a/src/firejail/main.c b/src/firejail/main.c index 5b88481d1..2f64d2268 100644 --- a/src/firejail/main.c +++ b/src/firejail/main.c | |||
@@ -92,7 +92,7 @@ int arg_nosound = 0; // disable sound | |||
92 | int arg_quiet = 0; // no output for scripting | 92 | int arg_quiet = 0; // no output for scripting |
93 | int arg_join_network = 0; // join only the network namespace | 93 | int arg_join_network = 0; // join only the network namespace |
94 | int arg_join_filesystem = 0; // join only the mount namespace | 94 | int arg_join_filesystem = 0; // join only the mount namespace |
95 | 95 | int arg_nice = 0; // nice value configured | |
96 | 96 | ||
97 | int parent_to_child_fds[2]; | 97 | int parent_to_child_fds[2]; |
98 | int child_to_parent_fds[2]; | 98 | int child_to_parent_fds[2]; |
@@ -678,6 +678,10 @@ int main(int argc, char **argv) { | |||
678 | arg_ipc = 1; | 678 | arg_ipc = 1; |
679 | else if (strncmp(argv[i], "--cpu=", 6) == 0) | 679 | else if (strncmp(argv[i], "--cpu=", 6) == 0) |
680 | read_cpu_list(argv[i] + 6); | 680 | read_cpu_list(argv[i] + 6); |
681 | else if (strncmp(argv[i], "--nice=", 7) == 0) { | ||
682 | cfg.nice = atoi(argv[i] + 7); | ||
683 | arg_nice = 1; | ||
684 | } | ||
681 | else if (strncmp(argv[i], "--cgroup=", 9) == 0) { | 685 | else if (strncmp(argv[i], "--cgroup=", 9) == 0) { |
682 | if (arg_cgroup) { | 686 | if (arg_cgroup) { |
683 | fprintf(stderr, "Error: only a cgroup can be defined\n"); | 687 | fprintf(stderr, "Error: only a cgroup can be defined\n"); |
diff --git a/src/firejail/profile.c b/src/firejail/profile.c index bbec17447..e0de69e5e 100644 --- a/src/firejail/profile.c +++ b/src/firejail/profile.c | |||
@@ -290,6 +290,13 @@ int profile_check_line(char *ptr, int lineno, const char *fname) { | |||
290 | return 0; | 290 | return 0; |
291 | } | 291 | } |
292 | 292 | ||
293 | // nice value | ||
294 | if (strncmp(ptr, "nice ", 4) == 0) { | ||
295 | cfg.nice = atoi(ptr + 5); | ||
296 | arg_nice = 1; | ||
297 | return 0; | ||
298 | } | ||
299 | |||
293 | // cgroup | 300 | // cgroup |
294 | if (strncmp(ptr, "cgroup ", 7) == 0) { | 301 | if (strncmp(ptr, "cgroup ", 7) == 0) { |
295 | set_cgroup(ptr + 7); | 302 | set_cgroup(ptr + 7); |
diff --git a/src/firejail/sandbox.c b/src/firejail/sandbox.c index 85f65b610..1ba655301 100644 --- a/src/firejail/sandbox.c +++ b/src/firejail/sandbox.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <sys/resource.h> | 27 | #include <sys/resource.h> |
28 | #include <sys/types.h> | 28 | #include <sys/types.h> |
29 | #include <dirent.h> | 29 | #include <dirent.h> |
30 | #include <errno.h> | ||
30 | 31 | ||
31 | #include <sched.h> | 32 | #include <sched.h> |
32 | #ifndef CLONE_NEWUSER | 33 | #ifndef CLONE_NEWUSER |
@@ -582,6 +583,18 @@ int sandbox(void* sandbox_arg) { | |||
582 | // set user-supplied environment variables | 583 | // set user-supplied environment variables |
583 | env_apply(); | 584 | env_apply(); |
584 | 585 | ||
586 | // set nice | ||
587 | if (arg_nice) { | ||
588 | errno = 0; | ||
589 | int rv = nice(cfg.nice); | ||
590 | (void) rv; | ||
591 | printf("nice rv %d\n", rv); | ||
592 | if (errno) { | ||
593 | fprintf(stderr, "Warning: cannot set nice value\n"); | ||
594 | errno = 0; | ||
595 | } | ||
596 | } | ||
597 | |||
585 | //**************************** | 598 | //**************************** |
586 | // set security filters | 599 | // set security filters |
587 | //**************************** | 600 | //**************************** |
diff --git a/src/firejail/usage.c b/src/firejail/usage.c index fa48c55cf..33724c80f 100644 --- a/src/firejail/usage.c +++ b/src/firejail/usage.c | |||
@@ -178,6 +178,7 @@ void usage(void) { | |||
178 | printf("\t--netstats - monitor network statistics for sandboxes creating a new\n"); | 178 | printf("\t--netstats - monitor network statistics for sandboxes creating a new\n"); |
179 | printf("\t\tnetwork namespace.\n\n"); | 179 | printf("\t\tnetwork namespace.\n\n"); |
180 | #endif | 180 | #endif |
181 | printf("\t--nice=value - set nice value\n\n"); | ||
181 | printf("\t--noblacklist=dirname_or_filename - disable blacklist for directory\n"); | 182 | printf("\t--noblacklist=dirname_or_filename - disable blacklist for directory\n"); |
182 | printf("\t\tor file.\n\n"); | 183 | printf("\t\tor file.\n\n"); |
183 | printf("\t--nogroups - disable supplementary groups. Without this option,\n"); | 184 | printf("\t--nogroups - disable supplementary groups. Without this option,\n"); |
diff --git a/src/man/firejail-profile.txt b/src/man/firejail-profile.txt index 20fd731e1..3ebb11549 100644 --- a/src/man/firejail-profile.txt +++ b/src/man/firejail-profile.txt | |||
@@ -228,6 +228,10 @@ Set the CPU cores available for this sandbox using \fBcpu\fR command. Examples: | |||
228 | cpu 1,2,3 | 228 | cpu 1,2,3 |
229 | Use only CPU cores 0, 1 and 2. | 229 | Use only CPU cores 0, 1 and 2. |
230 | 230 | ||
231 | .TP | ||
232 | nice -5 | ||
233 | Set a nice value of -5 to all processes running inside the sandbox. | ||
234 | |||
231 | .SH Control Groups | 235 | .SH Control Groups |
232 | Place the sandbox in an existing control group specified by the full path of the task file using \fBcgroup\fR. Example: | 236 | Place the sandbox in an existing control group specified by the full path of the task file using \fBcgroup\fR. Example: |
233 | 237 | ||
diff --git a/src/man/firejail.txt b/src/man/firejail.txt index 784f1583e..bdd1bb1f6 100644 --- a/src/man/firejail.txt +++ b/src/man/firejail.txt | |||
@@ -761,6 +761,16 @@ PID User RX(KB/s) TX(KB/s) Command | |||
761 | .br | 761 | .br |
762 | 7383 netblue 9.045 0.112 firejail \-\-net=eth0 transmission | 762 | 7383 netblue 9.045 0.112 firejail \-\-net=eth0 transmission |
763 | 763 | ||
764 | .TP | ||
765 | \fB\-\-nice=value | ||
766 | Set nice value for all processes running inside the sandbox. | ||
767 | .br | ||
768 | |||
769 | .br | ||
770 | Example: | ||
771 | .br | ||
772 | $ firejail --nice=-5 firefox | ||
773 | |||
764 | 774 | ||
765 | .TP | 775 | .TP |
766 | \fB\-\-noblacklist=dirname_or_filename | 776 | \fB\-\-noblacklist=dirname_or_filename |