Update BSD::Control::Feature#sysdef!

This commit is contained in:
0x1eef 2024-03-10 11:15:28 -03:00
parent 04af09b700
commit b6e28f02b0
4 changed files with 34 additions and 8 deletions

View file

@ -50,12 +50,16 @@ VALUE
ffi_sysdef(VALUE self, VALUE rb_feature, VALUE rb_path) ffi_sysdef(VALUE self, VALUE rb_feature, VALUE rb_path)
{ {
struct Options options; struct Options options;
int r; int result;
errno = 0;
options = __options_init(rb_feature, rb_path); options = __options_init(rb_feature, rb_path);
r = hbsdcontrol_extattr_rm_attr(options.path, options.disable_flag); result = hbsdcontrol_extattr_rm_attr(options.path, options.disable_flag) == 0 &&
r &= hbsdcontrol_extattr_rm_attr(options.path, options.enable_flag); hbsdcontrol_extattr_rm_attr(options.path, options.enable_flag) == 0;
return (r == 0 ? Qtrue : Qfalse); if (result) {
return (Qtrue);
} else {
rb_syserr_fail(errno, "hbsdcontrol_extattr_rm_attr");
}
} }

View file

@ -46,8 +46,8 @@ module BSD::Control
# @param [String] path # @param [String] path
# The path to a file. # The path to a file.
# #
# @raise [BSD::Control::Error] # @raise [SystemCallError]
# When the operation fails. # Might raise a number of Errno exceptions.
# #
# @return [Boolean] # @return [Boolean]
# Returns true on success. # Returns true on success.

View file

@ -1,6 +1,6 @@
require_relative "../setup" require_relative "../setup"
module BSD::Control module BSD::Control
class FeatureBangTest < Test::Unit::TestCase class FeatureTest < Test::Unit::TestCase
def test_mprotect_feature def test_mprotect_feature
assert_instance_of BSD::Control::Feature, assert_instance_of BSD::Control::Feature,
BSD::Control.feature(:mprotect) BSD::Control.feature(:mprotect)

View file

@ -0,0 +1,22 @@
require_relative "../setup"
module BSD::Control
class SysDefTest < Test::Unit::TestCase
require "fileutils"
include FileUtils
def test_sysdef!_lacks_privileges
touch(file)
assert_raises(Errno::EPERM) do
BSD::Control.feature(:mprotect).sysdef!(file)
end
ensure
rm(file)
end
private
def file
File.join(__dir__, "file")
end
end
end