mirror of
https://github.com/NixOS/nix.git
synced 2025-11-27 04:30:59 +01:00
Prepare for FreeBSD sandboxing support
This is the utility changes from #9968, which were easier to rebase first. I (@Ericson2314) didn't write this code; I just rebased it. Co-Authored-By: Artemis Tosini <me@artem.ist> Co-Authored-By: Audrey Dutcher <audrey@rhelmot.io>
This commit is contained in:
parent
653a93ac0f
commit
625dce659a
19 changed files with 198 additions and 15 deletions
52
src/libutil/freebsd/freebsd-jail.cc
Normal file
52
src/libutil/freebsd/freebsd-jail.cc
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#ifdef __FreeBSD__
|
||||
# include "nix/util/freebsd-jail.hh"
|
||||
|
||||
# include <sys/resource.h>
|
||||
# include <sys/param.h>
|
||||
# include <sys/jail.h>
|
||||
# include <sys/mount.h>
|
||||
|
||||
# include "nix/util/error.hh"
|
||||
# include "nix/util/util.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
AutoRemoveJail::AutoRemoveJail()
|
||||
: del{false}
|
||||
{
|
||||
}
|
||||
|
||||
AutoRemoveJail::AutoRemoveJail(int jid)
|
||||
: jid(jid)
|
||||
, del(true)
|
||||
{
|
||||
}
|
||||
|
||||
AutoRemoveJail::~AutoRemoveJail()
|
||||
{
|
||||
try {
|
||||
if (del) {
|
||||
if (jail_remove(jid) < 0) {
|
||||
throw SysError("Failed to remove jail %1%", jid);
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
ignoreExceptionInDestructor();
|
||||
}
|
||||
}
|
||||
|
||||
void AutoRemoveJail::cancel()
|
||||
{
|
||||
del = false;
|
||||
}
|
||||
|
||||
void AutoRemoveJail::reset(int j)
|
||||
{
|
||||
del = true;
|
||||
jid = j;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
#endif
|
||||
20
src/libutil/freebsd/include/nix/util/freebsd-jail.hh
Normal file
20
src/libutil/freebsd/include/nix/util/freebsd-jail.hh
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
///@file
|
||||
|
||||
#include "nix/util/types.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
class AutoRemoveJail
|
||||
{
|
||||
int jid;
|
||||
bool del;
|
||||
public:
|
||||
AutoRemoveJail(int jid);
|
||||
AutoRemoveJail();
|
||||
~AutoRemoveJail();
|
||||
void cancel();
|
||||
void reset(int j);
|
||||
};
|
||||
|
||||
}
|
||||
7
src/libutil/freebsd/include/nix/util/meson.build
Normal file
7
src/libutil/freebsd/include/nix/util/meson.build
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Public headers directory
|
||||
|
||||
include_dirs += include_directories('../..')
|
||||
|
||||
headers += files(
|
||||
'freebsd-jail.hh',
|
||||
)
|
||||
5
src/libutil/freebsd/meson.build
Normal file
5
src/libutil/freebsd/meson.build
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
sources += files(
|
||||
'freebsd-jail.cc',
|
||||
)
|
||||
|
||||
subdir('include/nix/util')
|
||||
Loading…
Add table
Add a link
Reference in a new issue