Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first attempt new chrooting. It is just Proof of concept
- Loading branch information
1 parent
f16ee8e
commit f39a93e
Showing
3 changed files
with
94 additions
and
59 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#-- | ||
# Config Agents Framework | ||
# | ||
# Copyright (C) 2011 Novell, Inc. | ||
# This library is free software; you can redistribute it and/or modify | ||
# it only under the terms of version 2.1 or version 3 of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation. | ||
# | ||
# This library is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public | ||
# License along with this library; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
#++ | ||
|
||
# Provides chrooting ability | ||
module ChrootEnv | ||
# Run block in changed root to dir | ||
# @param [String] dir of new root | ||
# @yield code that runs in changed root with all limitations | ||
# @yieldreturn [Object] Returns return value of block with limitation that for serialization is used YAML, so object to serialize must support it. | ||
# @note exception is transformed into hash with key error and backtrace or specialized hash for BackendException | ||
def self.run dir | ||
rd,wr = IO.pipe | ||
fork do | ||
Dir.chroot(dir) | ||
rd.close | ||
result = yield rescue $! | ||
wr.write result Marshal.dump(result) | ||
wr.close | ||
exit 0 | ||
end | ||
wr.close | ||
result = Marshal.load rd.read | ||
rd.close | ||
Process.wait | ||
if result.is_a? Exception | ||
raise result.class,result.message,result.backtrace #continue with exception | ||
end | ||
return result | ||
end | ||
end |
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 was deleted.
Oops, something went wrong.