1
1
Fork 0
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:
John Ericson 2025-05-27 14:51:39 -04:00
parent 653a93ac0f
commit 625dce659a
19 changed files with 198 additions and 15 deletions

View 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

View 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);
};
}

View file

@ -0,0 +1,7 @@
# Public headers directory
include_dirs += include_directories('../..')
headers += files(
'freebsd-jail.hh',
)

View file

@ -0,0 +1,5 @@
sources += files(
'freebsd-jail.cc',
)
subdir('include/nix/util')