libcgroup 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ffi-libcgroup.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Vincent Batts
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ # Libcgroup
2
+
3
+ Bindings for the libcgroup library.
4
+ Control Groups provide mechanisms to contain, limit and account for resource
5
+ usage of process groups.
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'libcgroup'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install libcgroup
21
+
22
+ ## Usage
23
+
24
+ require 'libcgroup'
25
+ puts LibCgroup.cgroup_init
26
+ puts root = LibCgroup.cgroup_new_cgroup("/")
27
+ puts LibCgroup.cgroup_get_cgroup(root)
28
+ puts ctl = LibCgroup.cgroup_get_controller(root, "cpu")
29
+ (0..(LibCgroup.cgroup_get_value_name_count(ctl)-1)).each do |i|
30
+ name = LibCgroup.cgroup_get_value_name(ctl, i)
31
+ s = FFI::MemoryPointer.new :pointer, 1
32
+ LibCgroup.cgroup_get_value_string(ctl, name, s)
33
+ strPtr = s.read_pointer
34
+ if strPtr.null?
35
+ puts name
36
+ else
37
+ puts "#{name} #{strPtr.read_string}"
38
+ end
39
+ end
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
48
+
49
+ Checkout https://github.com/ffi/ffi/wiki/Examples for FFI introduction.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ require "libcgroup/version"
2
+ require "libcgroup/cg"
3
+
4
+ module LibCgroup
5
+ end
@@ -0,0 +1,41 @@
1
+ require 'ffi'
2
+
3
+ module LibCgroup
4
+ extend FFI::Library
5
+ ffi_lib [FFI::CURRENT_PROCESS, 'cgroup', '/lib64/libcgroup.so.1']
6
+
7
+ typedef :pointer, :cgroup
8
+ typedef :pointer, :controller
9
+ typedef :pointer, :FILE
10
+
11
+ CGFLAG_USECACHE = 0x01
12
+
13
+ # init.h
14
+ attach_function :cgroup_init, [], :int
15
+ attach_function :cgroup_get_subsys_mount_point, [:string, :pointer], :int
16
+
17
+ # tasks.h
18
+ attach_function :cgroup_attach_task, [:cgroup], :int
19
+ attach_function :cgroup_attach_task_pid, [:cgroup, :pid_t], :int
20
+ attach_function :cgroup_init_rules_cache, [], :int
21
+ attach_function :cgroup_reload_cached_rules, [], :int
22
+ attach_function :cgroup_print_rules_config, [:FILE], :void
23
+
24
+ # config.h
25
+ attach_function :cgroup_config_load_config, [:string], :int
26
+ attach_function :cgroup_unload_cgroups, [], :int
27
+ attach_function :cgroup_config_unload_config, [:string, :int], :int
28
+ attach_function :cgroup_config_set_default, [:string, :int], :int
29
+
30
+ # groups.h
31
+ attach_function :cgroup_new_cgroup, [:string], :cgroup
32
+ attach_function :cgroup_get_cgroup, [:cgroup], :int
33
+ attach_function :cgroup_add_controller, [:cgroup, :string], :controller
34
+ attach_function :cgroup_get_controller, [:cgroup, :string], :controller
35
+ attach_function :cgroup_free, [:pointer], :void
36
+ attach_function :cgroup_free_controllers, [:cgroup], :void
37
+ attach_function :cgroup_get_value_name, [:controller, :int], :string
38
+ attach_function :cgroup_get_value_name_count, [:controller], :int
39
+ attach_function :cgroup_get_value_string, [:controller, :string, :pointer], :int
40
+ end
41
+
@@ -0,0 +1,4 @@
1
+ module LibCgroup
2
+ VERSION = "0.0.1"
3
+ end
4
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'libcgroup/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "libcgroup"
8
+ spec.version = LibCgroup::VERSION
9
+ spec.authors = ["Vincent Batts"]
10
+ spec.email = ["vbatts@redhat.com"]
11
+ spec.description = %q{bindings for libcgroup}
12
+ spec.summary = %q{bindings for libcgroup}
13
+ spec.homepage = "http://github.com/vbatts/ffi-libcgroup/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "ffi"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libcgroup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Vincent Batts
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ffi
16
+ requirement: &11238360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *11238360
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &11237860 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '1.3'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *11237860
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &11237440 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *11237440
47
+ description: bindings for libcgroup
48
+ email:
49
+ - vbatts@redhat.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - lib/libcgroup.rb
60
+ - lib/libcgroup/cg.rb
61
+ - lib/libcgroup/version.rb
62
+ - libcgroup.gemspec
63
+ homepage: http://github.com/vbatts/ffi-libcgroup/
64
+ licenses:
65
+ - MIT
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.17
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: bindings for libcgroup
88
+ test_files: []
89
+ has_rdoc: