Compare commits

...

28 commits
1.1.x ... main

Author SHA1 Message Date
Denis Knauf 2902c02478 arch_to_personality removed (lxc_config_parse_arch is not provided in API). lxc_wait_for_pid_status implementation added (not provided in API) 2023-10-10 15:31:34 +02:00
Stéphane Graber cf94855c8e
github: Update for main branch
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
2023-07-24 11:07:35 -04:00
Stéphane Graber 6bddbee7a5
github: Add DCO/target tests
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2023-06-21 21:43:46 -04:00
Andre Nathan b3f43f2739 Version 1.2.3 2018-07-10 10:29:34 -03:00
Andre Nathan 5a93ebcf9c
Merge pull request #42 from aither64/master
Fix build with LXC 3.0
2018-04-12 18:50:14 -03:00
Jakub Skokan 0eb378c291 Fix build with LXC 3.0 2018-04-12 12:29:36 +02:00
Andre Nathan e4f78ad7f8 Version 1.2.2 2016-10-24 10:55:25 -02:00
Andre Nathan 882436fc01 Merge pull request #40 from Jafaral/master
Fix: undefined symbol error when loading lxc.so
2016-10-24 10:53:58 -02:00
Jafar Al-Gharaibeh f1f178610f Merge pull request #1 from Jafaral/lxc_strerror
Fix: undefined symbol error when loading lxc.so
2016-10-13 13:07:50 -05:00
Jafar Al-Gharaibeh c0712e16d6 Fix: undefined symbol error when loading lxc.so
lxc_strerror() doesn't not exist, it is nothing more than an idea. 
LXC folks don't have plans to add it any time soon

Signed-off-by: Jafar Al-Gharaibeh <to.jafar@gmail.com>
2016-10-13 13:07:05 -05:00
Andre Nathan 5039b493c5 Version 1.2.1 2016-01-04 11:43:50 -02:00
Andre Nathan 9dbd2e901a Fix debian dependencies 2016-01-04 11:41:36 -02:00
Andre Nathan b262a3f5ad Avoid rb_std{in,out,err} name clash with rubinius 2016-01-04 11:22:21 -02:00
Andre Nathan e18dc18d8d Merge pull request #28 from fanyeren/patch-1
Update README.md
2015-03-06 08:09:02 -03:00
有张纸 75c0db54a8 Update README.md
you need to install ruby-dev/lxc-dev(debian/ubuntu) before $(gem install ruby-lxc)
2015-03-06 12:22:51 +08:00
Stéphane Graber 03584f60c5
Update Travis configuration
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2015-02-23 18:41:18 -05:00
Andre Nathan 9bbf0444a7 Raise errors for attach options 2014-09-24 10:43:18 -03:00
Andre Nathan 10ff154014 Better check for std{in,out,err} attach options 2014-09-24 10:28:22 -03:00
Andre Nathan 6024d0e40b Add travis build status 2014-06-16 14:17:40 -03:00
Andre Nathan 850b1f4b8a Add notifications 2014-06-13 14:50:09 -03:00
Andre Nathan 9d231bc99e Version 1.2.0 2014-06-13 14:38:05 -03:00
Andre Nathan 0914af2914 Next version will be 1.2.0 2014-06-11 09:29:57 -03:00
Andre Nathan eaaf5a2bc8 Merge pull request #21 from NiR-/master
Fixing travis builds for master branch
2014-06-10 15:54:53 -03:00
NiR- f1aef98626 Adding rdoc dependencies for ruby 1.8 2014-06-09 21:45:28 +02:00
NiR- 06cbff1bcf Removing unused packages from travis conf 2014-06-09 21:26:53 +02:00
NiR- e69f956f1e Fixing liblxc name in travis conf. 2014-06-09 18:13:58 +02:00
Andre Nathan c2518f1a7a Merge pull request #20 from NiR-/fix-lxc-devel
Correcting compilation for the last lxc development version.
2014-06-09 09:35:45 -03:00
NiR- 8e8d8cc253 Correcting compilation for the last lxc development version. 2014-06-09 08:21:45 +02:00
8 changed files with 193 additions and 81 deletions

40
.github/workflows/commits.yml vendored Normal file
View file

@ -0,0 +1,40 @@
name: Commits
on:
- pull_request
permissions:
contents: read
jobs:
dco-check:
permissions:
pull-requests: read # for tim-actions/get-pr-commits to get list of commits from the PR
name: Signed-off-by (DCO)
runs-on: ubuntu-20.04
steps:
- name: Get PR Commits
id: 'get-pr-commits'
uses: tim-actions/get-pr-commits@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check that all commits are signed-off
uses: tim-actions/dco@master
with:
commits: ${{ steps.get-pr-commits.outputs.commits }}
target-branch:
permissions:
contents: none
name: Branch target
runs-on: ubuntu-20.04
steps:
- name: Check branch target
env:
TARGET: ${{ github.event.pull_request.base.ref }}
run: |
set -x
[ "${TARGET}" = "main" ] && exit 0
echo "Invalid branch target: ${TARGET}"
exit 1

View file

@ -11,6 +11,11 @@ before_install:
- sudo apt-get install -y python-software-properties
- sudo add-apt-repository -y ppa:ubuntu-lxc/daily
- sudo apt-get update -y
- sudo apt-get install -y liblxc0 lxc lxc-dbg lxc-dev lxc-templates lxc-tests lxctl python3-lxc
- sudo apt-get install -y liblxc1
script:
- bundle exec rake clean package
notifications:
webhooks: https://linuxcontainers.org/webhook-lxcbot/
email:
- andrenth@gmail.com

View file

@ -1,5 +1,7 @@
# Ruby-LXC
[![Build Status](https://travis-ci.org/lxc/ruby-lxc.svg?branch=master)](https://travis-ci.org/lxc/ruby-lxc)
## Introduction
Ruby-LXC is a Ruby binding for liblxc. It allows the creation and management
@ -11,10 +13,12 @@ Assuming a current installation of LXC is available, to install Ruby-LXC
simply run the commands below
```sh
sudo apt-get install ruby-dev lxc-dev
bundle install
bundle exec rake compile
bundle exec rake gem
gem install pkg/ruby-lxc-1.1.1.gem
gem install pkg/ruby-lxc-1.2.0.gem
```
or just add this to your ```Gemfile```
```ruby
@ -25,6 +29,7 @@ gem "ruby-lxc", github: "lxc/ruby-lxc", require: "lxc"
- Container lifecycle management (create, start, stop and destroy containers)
```ruby
require 'lxc'
c = LXC::Container.new('foo')
c.create('ubuntu') # create a container named foo with ubuntu template
c.start

24
debian/changelog vendored
View file

@ -1,3 +1,27 @@
ruby-lxc (1.2.3-0digirati1) trusty; urgency=low
* Version 1.2.3.
-- Andre Nathan <andre@digirati.com.br> Mon, 10 Jul 2018 10:29:03 -0300
ruby-lxc (1.2.2-0digirati1) trusty; urgency=low
* Version 1.2.2.
-- Andre Nathan <andre@digirati.com.br> Mon, 24 Oct 2016 10:55:05 -0200
ruby-lxc (1.2.1-0digirati1) trusty; urgency=low
* Version 1.2.1.
-- Andre Nathan <andre@digirati.com.br> Fri, 04 Jan 2016 11:43:33 -0200
ruby-lxc (1.2.0-0digirati1) trusty; urgency=low
* Version 1.2.0.
-- Andre Nathan <andre@digirati.com.br> Fri, 13 Jun 2014 14:37:26 -0300
ruby-lxc (1.1.1-0digirati1) trusty; urgency=low
* Version 1.1.1.

4
debian/control vendored
View file

@ -2,13 +2,13 @@ Source: ruby-lxc
Section: ruby
Priority: optional
Maintainer: Andre Nathan <andrenth@gmail.com>
Build-Depends: debhelper (>= 7.0.50~), gem2deb (>= 0.2.3~)
Build-Depends: debhelper (>= 7.0.50~), gem2deb (>= 0.2.3~), lxc-dev
Standards-Version: 3.9.5
XS-Ruby-Versions: all
Package: ruby-lxc
Architecture: any
XB-Ruby-Versions: ${ruby:Versions}
Depends: ${misc:Depends}, ${shlibs:Depends}, ruby | ruby-interpreter, lxc-dev
Depends: ${misc:Depends}, ${shlibs:Depends}, ruby | ruby-interpreter, liblxc1
Description: Ruby bindings for liblxc
This package provides liblxc bindings for the Ruby programming language.

View file

@ -6,6 +6,7 @@
#include <signal.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#define SYMBOL(s) ID2SYM(rb_intern(s))
@ -40,9 +41,28 @@ extern void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1,
#define RELEASING_GVL2(func, arg, killfunc, killarg) func(arg)
#endif
extern int lxc_wait_for_pid_status(pid_t pid);
extern long lxc_config_parse_arch(const char *arch);
extern const char *lxc_strerror(int error);
//extern int lxc_wait_for_pid_status(pid_t pid);
#include <sys/types.h>
#include <sys/wait.h>
int lxc_wait_for_pid_status(pid_t pid)
{
int status, ret;
again:
ret = waitpid(pid, &status, 0);
if (ret == -1) {
if (errno == EINTR)
goto again;
return -1;
}
if (ret != pid)
goto again;
return status;
}
//extern long lxc_config_parse_arch(const char *arch);
static VALUE Container;
static VALUE Error;
@ -51,20 +71,6 @@ struct container_data {
struct lxc_container *container;
};
struct bdev_specs {
char *fstype;
uint64_t fssize; // fs size in bytes
struct {
char *zfsroot;
} zfs;
struct {
char *vg;
char *lv;
char *thinpool; // lvm thin pool to use, if any
} lvm;
char *dir;
};
static char **
ruby_to_c_string_array(VALUE rb_arr)
{
@ -112,24 +118,24 @@ free_c_string_array(char **arr)
* "personality", either +:linux32+ or +:linux+, for the 32-bit and 64-bit
* architectures, respectively.
*/
static VALUE
lxc_arch_to_personality(VALUE self, VALUE rb_arch)
{
int ret;
char *arch;
arch = StringValuePtr(rb_arch);
ret = lxc_config_parse_arch(arch);
switch (ret) {
case PER_LINUX32:
return SYMBOL("linux32");
case PER_LINUX:
return SYMBOL("linux");
default:
rb_raise(Error, "unknown personality");
}
}
//static VALUE
//lxc_arch_to_personality(VALUE self, VALUE rb_arch)
//{
// int ret;
// char *arch;
//
// arch = StringValuePtr(rb_arch);
// ret = lxc_config_parse_arch(arch);
//
// switch (ret) {
// case PER_LINUX32:
// return SYMBOL("linux32");
// case PER_LINUX:
// return SYMBOL("linux");
// default:
// rb_raise(Error, "unknown personality");
// }
//}
/*
* call-seq:
@ -560,10 +566,10 @@ is_string_array(VALUE v)
}
static int
is_io(VALUE v)
has_file_descriptor(VALUE v)
{
return rb_respond_to(v, rb_intern("sysread")) &&
rb_respond_to(v, rb_intern("syswrite"));
return rb_respond_to(v, rb_intern("fileno")) &&
rb_funcall(v, rb_intern("fileno"), 0) != Qnil;
}
static void
@ -583,11 +589,12 @@ lxc_attach_free_options(lxc_attach_options_t *opts)
static lxc_attach_options_t *
lxc_attach_parse_options(VALUE rb_opts)
{
char *error = NULL;
lxc_attach_options_t default_opts = LXC_ATTACH_OPTIONS_DEFAULT;
lxc_attach_options_t *opts;
VALUE rb_attach_flags, rb_namespaces, rb_personality, rb_initial_cwd;
VALUE rb_uid, rb_gid, rb_env_policy, rb_extra_env_vars, rb_extra_keep_env;
VALUE rb_stdin, rb_stdout, rb_stderr;
VALUE rb_stdin_opt, rb_stdout_opt, rb_stderr_opt;
opts = malloc(sizeof(*opts));
if (opts == NULL)
@ -597,95 +604,124 @@ lxc_attach_parse_options(VALUE rb_opts)
if (NIL_P(rb_opts))
return opts;
error = NULL;
rb_attach_flags = rb_hash_aref(rb_opts, SYMBOL("flags"));
if (!NIL_P(rb_attach_flags)) {
if (is_integer(rb_attach_flags))
if (is_integer(rb_attach_flags)) {
opts->attach_flags = NUM2INT(rb_attach_flags);
else
} else {
error = "flags must be an integer";
goto err;
}
}
rb_namespaces = rb_hash_aref(rb_opts, SYMBOL("namespaces"));
if (!NIL_P(rb_namespaces)) {
if (is_integer(rb_namespaces))
if (is_integer(rb_namespaces)) {
opts->namespaces = NUM2INT(rb_namespaces);
else
} else {
error = "namespaces must be an integer";
goto err;
}
}
rb_personality = rb_hash_aref(rb_opts, SYMBOL("personality"));
if (!NIL_P(rb_personality)) {
if (is_integer(rb_personality))
if (is_integer(rb_personality)) {
opts->personality = NUM2INT(rb_personality);
else
} else {
error = "personality must be an integer";
goto err;
}
}
rb_initial_cwd = rb_hash_aref(rb_opts, SYMBOL("initial_cwd"));
if (!NIL_P(rb_initial_cwd)) {
if (is_string(rb_initial_cwd))
if (is_string(rb_initial_cwd)) {
opts->initial_cwd = StringValuePtr(rb_initial_cwd);
else
} else {
error = "initial_cwd must be a string";
goto err;
}
}
rb_uid = rb_hash_aref(rb_opts, SYMBOL("uid"));
if (!NIL_P(rb_uid)) {
if (is_integer(rb_uid))
if (is_integer(rb_uid)) {
opts->uid = NUM2INT(rb_uid);
else
} else {
error = "uid must be an integer";
goto err;
}
}
rb_gid = rb_hash_aref(rb_opts, SYMBOL("gid"));
if (!NIL_P(rb_gid)) {
if (is_integer(rb_gid))
if (is_integer(rb_gid)) {
opts->gid = NUM2INT(rb_gid);
else
} else {
error = "gid must be an integer";
goto err;
}
}
rb_env_policy = rb_hash_aref(rb_opts, SYMBOL("env_policy"));
if (!NIL_P(rb_env_policy)) {
if (is_integer(rb_env_policy))
if (is_integer(rb_env_policy)) {
opts->env_policy = NUM2INT(rb_env_policy);
else
} else {
error = "env_policy must be an integer";
goto err;
}
}
rb_extra_env_vars = rb_hash_aref(rb_opts, SYMBOL("extra_env_vars"));
if (!NIL_P(rb_extra_env_vars)) {
if (is_string_array(rb_extra_env_vars))
if (is_string_array(rb_extra_env_vars)) {
opts->extra_env_vars = ruby_to_c_string_array(rb_extra_env_vars);
else
} else {
error = "extra_env_vars must be a array of strings";
goto err;
}
}
rb_extra_keep_env = rb_hash_aref(rb_opts, SYMBOL("extra_keep_env"));
if (!NIL_P(rb_extra_keep_env)) {
if (is_string_array(rb_extra_keep_env))
if (is_string_array(rb_extra_keep_env)) {
opts->extra_keep_env = ruby_to_c_string_array(rb_extra_keep_env);
else
} else {
error = "extra_keep_env must be a array of strings";
goto err;
}
rb_stdin = rb_hash_aref(rb_opts, SYMBOL("stdin"));
if (!NIL_P(rb_stdin)) {
if (is_io(rb_stdin))
opts->stdin_fd = io_fileno(rb_stdin);
else
}
rb_stdin_opt = rb_hash_aref(rb_opts, SYMBOL("stdin"));
if (!NIL_P(rb_stdin_opt)) {
if (has_file_descriptor(rb_stdin_opt)) {
opts->stdin_fd = io_fileno(rb_stdin_opt);
} else {
error = "stdin object must have a file descriptor";
goto err;
}
rb_stdout = rb_hash_aref(rb_opts, SYMBOL("stdout"));
if (!NIL_P(rb_stdout)) {
if (is_io(rb_stdout))
opts->stdout_fd = io_fileno(rb_stdout);
else
}
rb_stdout_opt = rb_hash_aref(rb_opts, SYMBOL("stdout"));
if (!NIL_P(rb_stdout_opt)) {
if (has_file_descriptor(rb_stdout_opt)) {
opts->stdout_fd = io_fileno(rb_stdout_opt);
} else {
error = "stdout object must have a file descriptor";
goto err;
}
rb_stderr = rb_hash_aref(rb_opts, SYMBOL("stderr"));
if (!NIL_P(rb_stderr)) {
if (is_io(rb_stderr))
opts->stderr_fd = io_fileno(rb_stderr);
else
}
rb_stderr_opt = rb_hash_aref(rb_opts, SYMBOL("stderr"));
if (!NIL_P(rb_stderr_opt)) {
if (has_file_descriptor(rb_stderr_opt)) {
opts->stderr_fd = io_fileno(rb_stderr_opt);
} else {
error = "stderr object must have a file descriptor";
goto err;
}
}
return opts;
err:
lxc_attach_free_options(opts);
if (error != NULL)
rb_raise(rb_eArgError, "%s", error);
else
return NULL;
}
@ -2053,7 +2089,7 @@ container_unfreeze(VALUE self)
ret = RELEASING_GVL(unfreeze_without_gvl, data);
if (!ret)
rb_raise(Error, "unable to unfreeze container: %s", lxc_strerror(ret));
rb_raise(Error, "unable to unfreeze container");
return self;
}
@ -2111,8 +2147,8 @@ Init_lxc(void)
{
VALUE LXC = rb_define_module("LXC");
rb_define_singleton_method(LXC, "arch_to_personality",
lxc_arch_to_personality, 1);
//rb_define_singleton_method(LXC, "arch_to_personality",
// lxc_arch_to_personality, 1);
rb_define_singleton_method(LXC, "run_command", lxc_run_command, 1);
rb_define_singleton_method(LXC, "run_shell", lxc_run_shell, 0);
rb_define_singleton_method(LXC, "global_config_item",

View file

@ -1,3 +1,3 @@
module LXC
VERSION = '1.1.1'
VERSION = '1.2.3'
end

View file

@ -13,6 +13,8 @@ Gem::Specification.new do |s|
s.extensions = 'ext/lxc/extconf.rb'
s.has_rdoc = true
s.add_development_dependency "rdoc"
s.add_development_dependency "rdoc-data"
s.add_development_dependency "rake-compiler"
s.homepage = 'https://github.com/lxc/ruby-lxc'