-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from robur-coop/root-policy
albatross_daemon: discover root policy and insert this
- Loading branch information
Showing
5 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// (c) 2017, 2018 Hannes Mehnert, all rights reserved | ||
|
||
#include <caml/mlvalues.h> | ||
#include <caml/alloc.h> | ||
#include <caml/memory.h> | ||
#include <caml/fail.h> | ||
#include <caml/unixsupport.h> | ||
|
||
#include <unistd.h> | ||
#include <errno.h> | ||
|
||
CAMLprim value vmm_cpu_count (value unit) { | ||
CAMLparam1(unit); | ||
int r; | ||
r = (int)sysconf(_SC_NPROCESSORS_ONLN); | ||
CAMLreturn(Val_int(r)); | ||
} | ||
|
||
int to_mb (long a, long b) { | ||
int r = 0; | ||
if (a % (1024 * 1024) == 0) | ||
r = (a / 1024 / 1024) * b; | ||
else { | ||
if (b % (1024 * 1024) == 0) | ||
r = a * (b / 1024 / 1024); | ||
else { | ||
if (a % 1024 == 0) { | ||
if (b % 1024 == 0) | ||
r = (a / 1024) * (b / 1024); | ||
else | ||
r = (a / 1024) * b / 1024; | ||
} else { | ||
if (b % 1024 == 0) | ||
r = a * (b / 1024) / 1024; | ||
else | ||
r = a * b / 1024 / 1024; | ||
} | ||
} | ||
} | ||
return r; | ||
} | ||
|
||
CAMLprim value vmm_memory (value unit) { | ||
CAMLparam1(unit); | ||
long pages = sysconf(_SC_PHYS_PAGES); | ||
long page_size = sysconf(_SC_PAGE_SIZE); | ||
CAMLreturn(Val_int(to_mb(pages, page_size))); | ||
} | ||
|
||
#ifdef __linux__ | ||
#include <sys/vfs.h> | ||
#else | ||
#include <sys/param.h> | ||
#include <sys/mount.h> | ||
#endif | ||
|
||
CAMLprim value vmm_disk_space (value path) { | ||
CAMLparam1(path); | ||
struct statfs s; | ||
const char *p = String_val(path); | ||
if (statfs(p, &s) < 0) | ||
uerror("statfs", Nothing); | ||
int r = to_mb(s.f_blocks, s.f_bsize); | ||
if (r < 0) { | ||
errno = EOVERFLOW; | ||
uerror("statfs", Nothing); | ||
} | ||
CAMLreturn(Val_int(to_mb(s.f_blocks, s.f_bsize))); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters