this repo has no description
1#include <stdlib.h>
2#include <unistd.h>
3#include <fcntl.h>
4#include <string.h>
5#include <errno.h>
6
7#include <caml/mlvalues.h>
8#include <caml/unixsupport.h>
9#include <caml/memory.h>
10#include <caml/custom.h>
11#include <caml/fail.h>
12
13#include "include/fork_action.h"
14
15static void action_setuid(int errors, value v_config) {
16 #ifdef _WIN32
17 eio_unix_fork_error(errors, "action_setuid", "Unsupported operation on windows");
18 #else
19 value v_uid = Field(v_config, 1);
20 int r;
21 r = setuid(Int_val(v_uid));
22 if (r != 0) {
23 eio_unix_fork_error(errors, "setuid", strerror(errno));
24 _exit(1);
25 }
26 #endif
27}
28
29CAMLprim value eio_unix_fork_setuid(value v_unit) {
30 return Val_fork_fn(action_setuid);
31}
32
33static void action_setcgroup(int errors, value v_config) {
34 value v_path = Field(v_config, 1);
35
36 int r;
37 pid_t pid = getpid();
38 FILE *f = fopen(String_val(v_path), "w");
39 if (f == NULL) {
40 eio_unix_fork_error(errors, "cgroup", strerror(errno));
41 _exit(1);
42 }
43
44 if (fprintf(f, "%d\n", pid) < 0) {
45 fclose(f);
46 eio_unix_fork_error(errors, "cgroup", strerror(errno));
47 _exit(1);
48 }
49
50 fclose(f);
51}
52
53CAMLprim value eio_unix_fork_setcgroup(value v_unit) {
54 return Val_fork_fn(action_setcgroup);
55}
56