[lxc-devel] [PATCH] lxc-start: add option -p, --pidfile=FILE for use with --daemon

2012-11-13 Thread Natanael Copa
Add option to create a pidfile for lxc-start daemon. This is helpful
for init scripts and process monitors.

Signed-off-by: Natanael Copa 
---
 doc/lxc-start.sgml.in | 12 
 src/lxc/arguments.h   |  1 +
 src/lxc/lxc_start.c   | 24 
 3 files changed, 37 insertions(+)

diff --git a/doc/lxc-start.sgml.in b/doc/lxc-start.sgml.in
index 2b6778f..bd875d6 100644
--- a/doc/lxc-start.sgml.in
+++ b/doc/lxc-start.sgml.in
@@ -53,6 +53,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
02111-1307 USA
   -f config_file
   -c console_file
   -d
+  -p pid_file
   -s KEY=VAL
   -C
   command
@@ -109,6 +110,17 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
02111-1307 USA
 
   

+ -p, --pidfile pid_file
+   
+   
+ 
+   Create a pidfile when running as daemon.
+ 
+   
+  
+
+  
+   
  -f, --rcfile config_file


diff --git a/src/lxc/arguments.h b/src/lxc/arguments.h
index 40f0d6c..789ccd9 100644
--- a/src/lxc/arguments.h
+++ b/src/lxc/arguments.h
@@ -45,6 +45,7 @@ struct lxc_arguments {
int daemonize;
const char *rcfile;
const char *console;
+   const char *pidfile;
 
/* for lxc-checkpoint/restart */
const char *statefile;
diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
index 81a5774..a031ee1 100644
--- a/src/lxc/lxc_start.c
+++ b/src/lxc/lxc_start.c
@@ -62,6 +62,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* 
arg)
case 'f': args->rcfile = arg; break;
case 'C': args->close_all_fds = 1; break;
case 's': return lxc_config_define_add(&defines, arg);
+   case 'p': args->pidfile = arg; break;
}
return 0;
 }
@@ -72,6 +73,7 @@ static const struct option my_longopts[] = {
{"define", required_argument, 0, 's'},
{"console", required_argument, 0, 'c'},
{"close-all-fds", no_argument, 0, 'C'},
+   {"pidfile", required_argument, 0, 'p'},
LXC_COMMON_OPTIONS
 };
 
@@ -85,6 +87,7 @@ lxc-start start COMMAND in specified container NAME\n\
 Options :\n\
   -n, --name=NAME  NAME for name of the container\n\
   -d, --daemon daemonize the container\n\
+  -p, --pidfile=FILE   Create pidfile when daemonized\n\
   -f, --rcfile=FILELoad configuration file FILE\n\
   -c, --console=FILE   Set the file output for the container console\n\
   -C, --close-all-fds  If any fds are inherited, close them\n\
@@ -95,6 +98,7 @@ Options :\n\
.parser= my_parser,
.checker   = NULL,
.daemonize = 0,
+   .pidfile = NULL,
 };
 
 int main(int argc, char *argv[])
@@ -200,6 +204,7 @@ int main(int argc, char *argv[])
}
 
if (my_args.daemonize) {
+   FILE *pid_fp;
/* do an early check for needed privs, since otherwise the
 * user won't see the error */
 
@@ -208,10 +213,26 @@ int main(int argc, char *argv[])
return err;
}
 
+   if (my_args.pidfile != NULL) {
+   pid_fp = fopen(my_args.pidfile, "w");
+   if (pid_fp == NULL) {
+   SYSERROR("failed to create '%s'", my_args.name);
+   return err;
+   }
+   }
+
if (daemon(0, 0)) {
SYSERROR("failed to daemonize '%s'", my_args.name);
return err;
}
+
+   if (my_args.pidfile != NULL) {
+   if (fprintf(pid_fp, "%d\n", getpid()) < 0) {
+   SYSERROR("failed to write '%s'", 
my_args.pidfile);
+   return err;
+   }
+   fclose(pid_fp);
+   }
}
 
if (my_args.close_all_fds)
@@ -230,6 +251,9 @@ int main(int argc, char *argv[])
err = -1;
}
 
+   if (my_args.daemonize && my_args.pidfile)
+   unlink(my_args.pidfile);
+
return err;
 }
 
-- 
1.8.0


--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-destroy: make it work with busybox

2012-11-13 Thread Natanael Copa
Busybox 'rm' has no support for --one-file-system. We can make it work
on busybox with find ... -xdev.

Signed-off-by: Natanael Copa 
---
 src/lxc/lxc-destroy.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/lxc/lxc-destroy.in b/src/lxc/lxc-destroy.in
index 846266c..f8f4b48 100644
--- a/src/lxc/lxc-destroy.in
+++ b/src/lxc/lxc-destroy.in
@@ -122,9 +122,9 @@ if [ -n "$rootdev" ]; then
btrfs subvolume delete "$rootdev"
else
# In case rootfs is not under $lxc_path/$lxc_name, 
remove it
-   rm -rf --one-file-system --preserve-root $rootdev
+   find $rootdev -xdev -delete
fi
fi
 fi
 # recursively remove the container to remove old container configuration
-rm -rf --one-file-system --preserve-root $lxc_path/$lxc_name
+find $lxc_path/$lxc_name -xdev -delete
-- 
1.8.0


--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] using posix shell instead of bash

2012-11-13 Thread Natanael Copa
Hi,

I wonder if it there are any interest to make the scripts posix shell
compliant so they can run with for example busybox ash and dash.

I would like to provide proper LCX support for Alpine Linux, which by
default runs from tmpfs. It uses uclibc and busybox as the base system,
which makes it very lightweight. Looking at the scripts, it seems like
it would be fairly easy to adjust the script to not depend on bash at
all, making it possible to make the LCX host even lighter.

Before I start with sending patches, is this something that you would
be interested in, or are you married with bash (like the vserver ppl)?

Would you be prepared for minor sacrifices to use posix compliant shell
scripts?

-nc

--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] using posix shell instead of bash

2012-11-14 Thread Natanael Copa
On Wed, 14 Nov 2012 08:40:39 +0100
Natanael Copa  wrote:

> I wonder if it there are any interest to make the scripts posix shell
> compliant so they can run with for example busybox ash and dash.

I should maybe add that I think the biggest challenge will be the
longopts parsing. That said I have managed to make an alternative that
should make it possible to be compatible with the current option
parsing so we would not need break scripts that uses current lcx-*
scripts.

I also think it might not be worth convert the template scripts since
those probably will depend on bash, perl and other stuff anyways.

The scripts I'm interested in make posix compliant are:
lxc-checkconfig.in
lxc-clone.in
lxc-create.in
lxc-destroy.in
lxc-ls.in
lxc-netstat.in
lxc-ps.in
lxc-setcap.in
lxc-setuid.in
lxc-shutdown.in
lxc-version.in

I have made a few of them already as shown below (mostly untested). I
have a solution for: 'prog arg1 --opt1 -- arg2' in case that would ever
be needed.

I think it would be nice with some kind of feedback before I continue.


commit 6b65cb9e5a33ce3cc1156329b8e775c0b6aa36ee
Author: Natanael Copa 
Date:   Wed Nov 14 13:55:21 2012 +0100

lxc-ls: use posix shell instead of bash
    
Signed-off-by: Natanael Copa 

diff --git a/src/lxc/lxc-ls.in b/src/lxc/lxc-ls.in
index 9293323..948eef9 100644
--- a/src/lxc/lxc-ls.in
+++ b/src/lxc/lxc-ls.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 #
 # lxc: linux Container library
@@ -18,10 +18,11 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 lxc_path=@LXCPATH@
+program=${0##*/}
 
 usage()
 {
-   echo "usage: $(basename $0) [--active] [--] [LS_OPTIONS...]" >&2
+   echo "usage: $program [--active] [--] [LS_OPTIONS...]" >&2
 }
 
 help() {
@@ -61,11 +62,10 @@ get_parent_cgroup()
 
# Return the absolute path to the containers' parent cgroup
# (do not append '/lxc' if the hierarchy contains the 'ns' 
subsystem)
-   if [[ ",$subsystems," == *,ns,* ]]; then
-   parent_cgroup="${mountpoint}${init_cgroup%/}"
-   else
-   parent_cgroup="${mountpoint}${init_cgroup%/}/lxc"
-   fi
+   case ",$subsystems," in
+   *,ns,*) parent_cgroup="${mountpoint}${init_cgroup%/}";;
+   *) parent_cgroup="${mountpoint}${init_cgroup%/}/lxc";;
+   esac
break
done
 }
@@ -91,7 +91,7 @@ if [ ! -z "$directory" ]; then
 fi
 
 if [ -z "$containers" ]; then
-   echo "$(basename $0): no containers found" >&2
+   echo "$program: no containers found" >&2
exit 1
 fi
 

commit bc4c995b12bc6d0df563296d929ccf5266f657d8
Author: Natanael Copa 
Date:   Wed Nov 14 13:54:04 2012 +0100

lxc-create: use posix shell instead of bash

Signed-off-by: Natanael Copa 

diff --git a/src/lxc/lxc-create.in b/src/lxc/lxc-create.in
index b21cdc3..98bf380 100644
--- a/src/lxc/lxc-create.in
+++ b/src/lxc/lxc-create.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 #
 # lxc: linux Container library
@@ -20,8 +20,9 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
+program=${0##*/}
 usage() {
-echo "usage: $(basename $0) -n NAME [-f CONFIG_FILE] [-t TEMPLATE] 
[FS_OPTIONS] --" >&2
+echo "usage: $program -n NAME [-f CONFIG_FILE] [-t TEMPLATE] [FS_OPTIONS] 
--" >&2
 echo " [TEMPLATE_OPTIONS]" >&2
 echo >&2
 echo "where FS_OPTIONS is one of:" >&2
@@ -49,7 +50,7 @@ help() {
 echo >&2
 if [ -z $lxc_template ]; then
 echo "To see template-specific options, specify a template. For 
example:" >&2
-echo "  $(basename $0) -t ubuntu -h" >&2
+echo "  $program -t ubuntu -h" >&2
 exit 0
 fi
 type ${templatedir}/lxc-$lxc_template 2>/dev/null
@@ -60,8 +61,19 @@ help() {
 fi
 }
 
-shortoptions='hn:f:t:B:'
-longoptions='help,name:,config:,template:,backingstore:,fstype:,lvname:,vgname:,fssize:'
+usage_err() {
+[ -n "$1" ] && echo "$1" >&2
+usage
+exit 1
+}
+
+optarg_check() {
+local opt="$1" optarg="$2"
+if [ -z "$optarg" ]; then
+usage_err "option '$opt' requires an argument"
+fi
+}
+
 lxc_path=@LXCPATH@
 bindir=@BINDIR@
 templatedir=@LXCTEMPLATEDIR@
@@ -70,66 +82,65 @@ fstype=ext4
 fssize=500M
 vgname=lxc
 
-getopt=$(getopt -o $shortoptions --longoptions  $longoptions -- "$@")
-if [ $? != 0 ]; then
-usage
-exit

Re: [lxc-devel] using posix shell instead of bash

2012-11-14 Thread Natanael Copa
On Wed, 14 Nov 2012 14:04:43 +0100
Natanael Copa  wrote:


> @@ -18,10 +18,11 @@
>  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
> 02111-1307 USA 
>  lxc_path=@LXCPATH@
> +program=${0##*/}
>  
>  usage()
>  {
> - echo "usage: $(basename $0) [--active] [--] [LS_OPTIONS...]"
> >&2
> + echo "usage: $program [--active] [--] [LS_OPTIONS...]" >&2
>  }

Those hunks are not needed. I'll revert them in final patch.

-nc

--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] lxc-destroy: make it work with busybox

2012-11-14 Thread Natanael Copa
On Wed, 14 Nov 2012 08:51:07 -0600
Serge Hallyn  wrote:

> Quoting Natanael Copa (nc...@alpinelinux.org):
> > Busybox 'rm' has no support for --one-file-system. We can make it
> > work on busybox with find ... -xdev.
> 
> Hm, well it does slow it down a smidgeon, but no real objection
> from me.  Still let's if anyone else has a comment.

Why does it slow down? Did you test it?

-nc

--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] lxc-start: add option -p, --pidfile=FILE for use with --daemon

2012-11-14 Thread Natanael Copa
On Wed, 14 Nov 2012 08:44:41 -0600
Serge Hallyn  wrote:

> Quoting Natanael Copa (nc...@alpinelinux.org):
> > Add option to create a pidfile for lxc-start daemon. This is helpful
> > for init scripts and process monitors.
> 
> Why only when daemonizing?  Someone could presumably first lxc-start
> by hand in the foreground, then another admin walks in and restarts
> the sysvinit lxc job?

I assume 'someone' starting with lxc-start instead of via sysvinit (or
any other init) would not think of appening --pidfile option, but sure,
I think you have a valid point. I'll prepare a new patch.

-nc

--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] using posix shell instead of bash

2012-11-14 Thread Natanael Copa
On Wed, 14 Nov 2012 09:54:58 -0600
Serge Hallyn  wrote:
 
> (Note also that lxc-ls may be rewritten in python.  Is that a problem
> for your use case?)

well... The Alpine Linux base system is 6MB excluding kernel. I offer
to spend a day or so to save 700kb by getting rid of bash.

and now you want pull in python that is at least 36MB + its
dependencies... :)

I'd rather see Lua, which is even smaller than bash. It's not python
but you get pretty much bang for the bucks.

-nc

--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] using posix shell instead of bash

2012-11-14 Thread Natanael Copa
On Wed, 14 Nov 2012 09:54:58 -0600
Serge Hallyn  wrote:

> Quoting Natanael Copa (nc...@alpinelinux.org):

forgot this...
 
> > Would you be prepared for minor sacrifices to use posix compliant
> > shell scripts?
> 
> Someone else can jump in if they object, but I personally don't.  Are
> you willing to subscribe to github.com/lxc/lxc#staging commits and
> watch for new commits re-breaking posix compliance?

yes.

-nc

--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] using posix shell instead of bash

2012-11-14 Thread Natanael Copa
On Wed, 14 Nov 2012 13:50:54 -0500
"Michael H. Warfield"  wrote:

> Converting from bash to ash (which is very sh like) isn't too bad if
> you are not making extensive use of arrays and string functions.  It's
> probably doable (having done it myself with some fairly sophisticated
> bash scripts dealing with LUKS encryption and file systems).  I would
> start by trying to run it under busybox ash and see what breaks.

I looked over the scripts this morning. I could not find any arrays,
one or 2 bash specific variable expansion, and one pipe redirect iirc.
The biggest thing was getopt longopts but I have a plan for that (as i
posted in the diff). The code is also clean and nice. I would not
suggested this if the changes would been intrusive or if the code was
messy.

-nc

--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH v2] lxc-start: add option -p, --pidfile=FILE

2012-11-15 Thread Natanael Copa
Add option to create a pidfile for lxc-start. This is helpful for
init scripts and process monitors when running as daemon.

Signed-off-by: Natanael Copa 
---
Changes v1 -> v2:
 - allow use --pidfile without --daemon
 - update the doc to reflect the above
 - reword usage help text slightly


 doc/lxc-start.sgml.in | 12 
 src/lxc/arguments.h   |  1 +
 src/lxc/lxc_start.c   | 24 
 3 files changed, 37 insertions(+)

diff --git a/doc/lxc-start.sgml.in b/doc/lxc-start.sgml.in
index af79bbc..e4b9007 100644
--- a/doc/lxc-start.sgml.in
+++ b/doc/lxc-start.sgml.in
@@ -53,6 +53,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
02111-1307 USA
   -f config_file
   -c console_file
   -d
+  -p pid_file
   -s KEY=VAL
   -C
   command
@@ -109,6 +110,17 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
02111-1307 USA
 
   

+ -p, --pidfile pid_file
+   
+   
+ 
+   Create a file with the process id.
+ 
+   
+  
+
+  
+   
  -f, --rcfile config_file


diff --git a/src/lxc/arguments.h b/src/lxc/arguments.h
index 3c9d28f..188c460 100644
--- a/src/lxc/arguments.h
+++ b/src/lxc/arguments.h
@@ -45,6 +45,7 @@ struct lxc_arguments {
int daemonize;
const char *rcfile;
const char *console;
+   const char *pidfile;
 
/* for lxc-checkpoint/restart */
const char *statefile;
diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
index 81a5774..ca1cc2a 100644
--- a/src/lxc/lxc_start.c
+++ b/src/lxc/lxc_start.c
@@ -62,6 +62,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* 
arg)
case 'f': args->rcfile = arg; break;
case 'C': args->close_all_fds = 1; break;
case 's': return lxc_config_define_add(&defines, arg);
+   case 'p': args->pidfile = arg; break;
}
return 0;
 }
@@ -72,6 +73,7 @@ static const struct option my_longopts[] = {
{"define", required_argument, 0, 's'},
{"console", required_argument, 0, 'c'},
{"close-all-fds", no_argument, 0, 'C'},
+   {"pidfile", required_argument, 0, 'p'},
LXC_COMMON_OPTIONS
 };
 
@@ -85,6 +87,7 @@ lxc-start start COMMAND in specified container NAME\n\
 Options :\n\
   -n, --name=NAME  NAME for name of the container\n\
   -d, --daemon daemonize the container\n\
+  -p, --pidfile=FILE   Create a file with the process id\n\
   -f, --rcfile=FILELoad configuration file FILE\n\
   -c, --console=FILE   Set the file output for the container console\n\
   -C, --close-all-fds  If any fds are inherited, close them\n\
@@ -95,6 +98,7 @@ Options :\n\
.parser= my_parser,
.checker   = NULL,
.daemonize = 0,
+   .pidfile = NULL,
 };
 
 int main(int argc, char *argv[])
@@ -107,6 +111,7 @@ int main(int argc, char *argv[])
"/sbin/init",
'\0',
};
+   FILE *pid_fp = NULL;
 
lxc_list_init(&defines);
 
@@ -199,6 +204,14 @@ int main(int argc, char *argv[])
free(console);
}
 
+   if (my_args.pidfile != NULL) {
+   pid_fp = fopen(my_args.pidfile, "w");
+   if (pid_fp == NULL) {
+   SYSERROR("failed to create '%s'", my_args.name);
+   return err;
+   }
+   }
+
if (my_args.daemonize) {
/* do an early check for needed privs, since otherwise the
 * user won't see the error */
@@ -214,6 +227,14 @@ int main(int argc, char *argv[])
}
}
 
+   if (pid_fp != NULL) {
+   if (fprintf(pid_fp, "%d\n", getpid()) < 0) {
+   SYSERROR("failed to write '%s'", my_args.pidfile);
+   return err;
+   }
+   fclose(pid_fp);
+   }
+
if (my_args.close_all_fds)
conf->close_all_fds = 1;
 
@@ -230,6 +251,9 @@ int main(int argc, char *argv[])
err = -1;
}
 
+   if (my_args.pidfile)
+   unlink(my_args.pidfile);
+
return err;
 }
 
-- 
1.8.0


--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-checkconfig: use posix shell instead of bash

2012-11-15 Thread Natanael Copa
- replace 'echo -e' with printf
- replace 'if [[ ... ]]' with 'if [ ... ]'
- add \ at after && and || when those are at end of line

Signed-off-by: Natanael Copa 
---
I have tested the patch locally and it appears to work.

On busybox 'echo -e' works but I replaced them since checkbashisms
mentioned them.

 src/lxc/lxc-checkconfig.in | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/lxc/lxc-checkconfig.in b/src/lxc/lxc-checkconfig.in
index 8c2b5e5..db78c7d 100644
--- a/src/lxc/lxc-checkconfig.in
+++ b/src/lxc/lxc-checkconfig.in
@@ -1,13 +1,13 @@
-#!/bin/bash
+#!/bin/sh
 
 # Allow environment variables to override grep and config
 : ${CONFIG:=/proc/config.gz}
 : ${GREP:=zgrep}
 
-SETCOLOR_SUCCESS="echo -en \\033[1;32m"
-SETCOLOR_FAILURE="echo -en \\033[1;31m"
-SETCOLOR_WARNING="echo -en \\033[1;33m"
-SETCOLOR_NORMAL="echo -en \\033[0;39m"
+SETCOLOR_SUCCESS="printf \\e[1;32m"
+SETCOLOR_FAILURE="printf \\e[1;31m"
+SETCOLOR_WARNING="printf \\e[1;33m"
+SETCOLOR_NORMAL="printf \\e[0;39m"
 
 is_set() {
 $GREP -q "$1=[y|m]" $CONFIG
@@ -21,12 +21,12 @@ is_enabled() {
 RES=$?
 
 if [ $RES -eq 0 ]; then
-   $SETCOLOR_SUCCESS && echo -e "enabled" && $SETCOLOR_NORMAL
+   $SETCOLOR_SUCCESS && echo "enabled" && $SETCOLOR_NORMAL
 else
if [ ! -z "$mandatory" -a "$mandatory" = yes ]; then
-   $SETCOLOR_FAILURE && echo -e "required" && $SETCOLOR_NORMAL
+   $SETCOLOR_FAILURE && echo "required" && $SETCOLOR_NORMAL
else
-   $SETCOLOR_WARNING && echo -e "missing" && $SETCOLOR_NORMAL
+   $SETCOLOR_WARNING && echo "missing" && $SETCOLOR_NORMAL
fi
 fi
 }
@@ -73,7 +73,7 @@ echo -n "Cgroup: " && is_enabled CONFIG_CGROUPS yes
 
 if [ -f $CGROUP_MNT_PATH/cgroup.clone_children ]; then
 echo -n "Cgroup clone_children flag: " &&
-$SETCOLOR_SUCCESS && echo -e "enabled" && $SETCOLOR_NORMAL
+$SETCOLOR_SUCCESS && echo "enabled" && $SETCOLOR_NORMAL
 else
 echo -n "Cgroup namespace: " && is_enabled CONFIG_CGROUP_NS yes
 fi
@@ -89,19 +89,19 @@ echo -n "Macvlan: " && is_enabled CONFIG_MACVLAN
 echo -n "Vlan: " && is_enabled CONFIG_VLAN_8021Q
 KVER_MAJOR=$($GREP '^# Linux' $CONFIG | \
 sed -r 's/.* ([0-9])\.[0-9]{1,2}\.[0-9]{1,3}.*/\1/')
-if [[ $KVER_MAJOR == 2 ]]; then
+if [ "$KVER_MAJOR" = "2" ]; then
 KVER_MINOR=$($GREP '^# Linux' $CONFIG | \
 sed -r 's/.* 2.6.([0-9]{2}).*/\1/')
 else
 KVER_MINOR=$($GREP '^# Linux' $CONFIG | \
 sed -r 's/.* [0-9]\.([0-9]{1,3})\.[0-9]{1,3}.*/\1/')
 fi
-echo -n "File capabilities: " &&
-( [[ ${KVER_MAJOR} == 2 && ${KVER_MINOR} < 33 ]] &&
-   is_enabled CONFIG_SECURITY_FILE_CAPABILITIES ) ||
-( [[ ( ${KVER_MAJOR} == 2 && ${KVER_MINOR} > 32 ) ||
- ${KVER_MAJOR} > 2 ]] && $SETCOLOR_SUCCESS &&
- echo -e "enabled" && $SETCOLOR_NORMAL )
+echo -n "File capabilities: " && \
+( [ "${KVER_MAJOR}" = "2" ] && [ ${KVER_MINOR} -lt 33 ] && \
+   is_enabled CONFIG_SECURITY_FILE_CAPABILITIES ) || \
+( ( [ "${KVER_MAJOR}" = "2" ] && [ ${KVER_MINOR} -gt 32 ] ) || \
+ [ ${KVER_MAJOR} -gt 2 ] && $SETCOLOR_SUCCESS && \
+ echo "enabled" && $SETCOLOR_NORMAL )
 
 echo
 echo "Note : Before booting a new kernel, you can check its configuration"
-- 
1.8.0


--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] using posix shell instead of bash

2012-11-16 Thread Natanael Copa
On Wed, 14 Nov 2012 09:54:58 -0600
Serge Hallyn  wrote:
 
> Successful runs of
> https://code.launchpad.net/~serge-hallyn/+junk/lxc-test with your
> patches will also be reassuring.

This is causing problems for me:

if dist[0] != "Ubuntu":
print >>sys.stderr, "This test suite does not yet support %s" % 
(dist[0])
sys.exit(1)

-nc

--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-create: use posix shell instead of bash

2012-11-16 Thread Natanael Copa
- use '[ -x /path/prog ]' instead of 'type /path/prog'
- avoid getopt --longoptions
- add \ at after && and || when those are at end of line
- make sure condition expands to empty string if variable is empty

Signed-off-by: Natanael Copa 
---
I have tested it with 'lxc-create -t debian ...' with busybox as /bin/sh

 src/lxc/lxc-create.in | 70 +--
 1 file changed, 40 insertions(+), 30 deletions(-)

diff --git a/src/lxc/lxc-create.in b/src/lxc/lxc-create.in
index 101e489..e8056e9 100644
--- a/src/lxc/lxc-create.in
+++ b/src/lxc/lxc-create.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 #
 # lxc: linux Container library
@@ -54,16 +54,26 @@ help() {
 echo "  $(basename $0) -t ubuntu -h" >&2
 exit 0
 fi
-type ${templatedir}/lxc-$lxc_template 2>/dev/null
-if [ $? -eq 0 ]; then
+if [ -x ${templatedir}/lxc-$lxc_template ]; then
 echo >&2
 echo "Template-specific options (TEMPLATE_OPTIONS):" >&2
 ${templatedir}/lxc-$lxc_template -h
 fi
 }
 
-shortoptions='hn:f:t:B:'
-longoptions='help,name:,config:,template:,backingstore:,fstype:,dir:,lvname:,vgname:,fssize:'
+usage_err() {
+[ -n "$1" ] && echo "$1" >&2
+usage
+exit 1
+}
+
+optarg_check() {
+local opt="$1" optarg="$2"
+if [ -z "$optarg" ]; then
+usage_err "option '$opt' requires an argument"
+fi
+}
+
 lxc_path=@LXCPATH@
 bindir=@BINDIR@
 templatedir=@LXCTEMPLATEDIR@
@@ -73,68 +83,69 @@ fssize=500M
 vgname=lxc
 custom_rootfs=""
 
-getopt=$(getopt -o $shortoptions --longoptions  $longoptions -- "$@")
-if [ $? != 0 ]; then
-usage
-exit 1;
-fi
-
-eval set -- "$getopt"
-
-while true; do
-case "$1" in
+while [ $# -gt 0 ]; do
+local opt="$1"
+shift
+case "$opt" in
-h|--help)
help
exit 1
;;
-n|--name)
-   shift
+   optarg_check $opt "$1"
lxc_name=$1
shift
;;
-f|--config)
-   shift
+   optarg_check $opt "$1"
lxc_config=$1
shift
;;
-t|--template)
-   shift
+   optarg_check $opt "$1"
lxc_template=$1
shift
;;
-B|--backingstore)
-   shift
+   optarg_check $opt "$1"
backingstore=$1
shift
;;
--dir)
-   shift
+   optarg_check $opt "$1"
custom_rootfs=$1
shift
;;
--lvname)
-   shift
+   optarg_check $opt "$1"
lvname=$1
shift
;;
--vgname)
-   shift
+   optarg_check $opt "$1"
vgname=$1
shift
;;
--fstype)
-   shift
+   optarg_check $opt "$1"
fstype=$1
shift
;;
--fssize)
-   shift
+   optarg_check $opt "$1"
fssize=$1
shift
;;
 --)
shift
break;;
+   -?)
+   usage_err "unknown option '$opt'"
+   ;;
+   -*)
+   # split opts -abc into -a -b -c
+   set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
+   ;;
 *)
usage
exit 1
@@ -200,7 +211,7 @@ rootfs="$lxc_path/$lxc_name/rootfs"
 
 if [ "$backingstore" = "_unset" -o "$backingstore" = "btrfs" ]; then
 # if no backing store was given, then see if btrfs would work
-if which btrfs >/dev/null 2>&1 &&
+if which btrfs >/dev/null 2>&1 && \
 btrfs filesystem df "$lxc_path/" >/dev/null 2>&1; then
 backingstore="btrfs"
 else
@@ -246,10 +257,10 @@ elif [ "$backingstore" = "btrfs" ]; then
 fi
 
 cleanup() {
-if [ $backingstore = "lvm" ]; then
+if [ "$backingstore" = "lvm" ]; then
 umount $rootfs
 lvremove -f $rootdev
-elif [ $backingstore = "btrfs" ]; then
+elif [ "$backingstore" = "btrfs" ]; then
 btrfs subvolume delete "$rootfs"
 fi

[lxc-devel] [PATCH] lxc-create: fix passing over first argument to template script

2012-11-22 Thread Natanael Copa
The e60a8164c12d565f70071ff6b32b823dd495df9e introduced a bug that caused
first argument passed over to the template script get lost.

This patch fixes it.

Signed-off-by: Natanael Copa 
---
 src/lxc/lxc-create.in | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/lxc/lxc-create.in b/src/lxc/lxc-create.in
index e8056e9..26ec6a2 100644
--- a/src/lxc/lxc-create.in
+++ b/src/lxc/lxc-create.in
@@ -137,7 +137,6 @@ while [ $# -gt 0 ]; do
shift
;;
 --)
-   shift
break;;
-?)
usage_err "unknown option '$opt'"
-- 
1.8.0


--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] Rewrite lxc-ls in python

2012-11-22 Thread Natanael Copa
On Wed, 21 Nov 2012 18:04:03 -0500
Stéphane Graber  wrote:

> This rewrite is mostly compatible with the shell version.
> --active and -1 still work and behave as they used to.

Does this mean that python will be a requirement for lxc in future? I
am currently working on switching things from vserver, partially
because lxc has opened for less required dependencies on the host.

Currently an Alpine Linux lxc host with base + lxc installed is 6.9MB
excluding kernel. A corresponding vserver host is 11.6MB.

Python is 37MB.

Do we really need this bloat?

-nc

--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-create: do not use 'local'

2012-11-26 Thread Natanael Copa
Apparently 'local' is not POSIX. Don't use it.

Signed-off-by: Natanael Copa 
---
 src/lxc/lxc-create.in | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/lxc/lxc-create.in b/src/lxc/lxc-create.in
index 26ec6a2..30f0c22 100644
--- a/src/lxc/lxc-create.in
+++ b/src/lxc/lxc-create.in
@@ -68,9 +68,8 @@ usage_err() {
 }
 
 optarg_check() {
-local opt="$1" optarg="$2"
-if [ -z "$optarg" ]; then
-usage_err "option '$opt' requires an argument"
+if [ -z "$2" ]; then
+usage_err "option '$1' requires an argument"
 fi
 }
 
@@ -84,7 +83,7 @@ vgname=lxc
 custom_rootfs=""
 
 while [ $# -gt 0 ]; do
-local opt="$1"
+opt="$1"
 shift
 case "$opt" in
-h|--help)
-- 
1.8.0


--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-info: add option -t, --state-is=STATE to test for a given test

2012-11-26 Thread Natanael Copa
Add an option to test for a give state. This is useful for scripts.
It lets us you do thing like:

 if lxc-info --name myname --state-is RUNNING; then
   ...

Signed-off-by: Natanael Copa 
---
 src/lxc/lxc_info.c | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/lxc/lxc_info.c b/src/lxc/lxc_info.c
index 809769e..1a1cc22 100644
--- a/src/lxc/lxc_info.c
+++ b/src/lxc/lxc_info.c
@@ -34,12 +34,14 @@
 
 static bool state;
 static bool pid;
+static char *test_state = NULL;
 
 static int my_parser(struct lxc_arguments* args, int c, char* arg)
 {
switch (c) {
case 's': state = true; break;
case 'p': pid = true; break;
+   case 't': test_state = arg; break;
}
return 0;
 }
@@ -47,6 +49,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* 
arg)
 static const struct option my_longopts[] = {
{"state", no_argument, 0, 's'},
{"pid", no_argument, 0, 'p'},
+   {"state-is", required_argument, 0, 't'},
LXC_COMMON_OPTIONS,
 };
 
@@ -58,9 +61,11 @@ static struct lxc_arguments my_args = {
 lxc-info display some information about a container with the identifier NAME\n\
 \n\
 Options :\n\
-  -n, --name=NAME   NAME for name of the container\n\
-  -s, --state   shows the state of the container\n\
-  -p, --pid shows the process id of the init container\n",
+  -n, --name=NAME   NAME for name of the container\n\
+  -s, --state   shows the state of the container\n\
+  -p, --pid shows the process id of the init container\n\
+  -t, --state-is=STATE  test if current state is STATE\n\
+returns success if it matches, false otherwise\n",
.options  = my_longopts,
.parser   = my_parser,
.checker  = NULL,
@@ -81,10 +86,12 @@ int main(int argc, char *argv[])
if (!state && !pid)
state = pid = true;
 
-   if (state) {
+   if (state || test_state) {
ret = lxc_getstate(my_args.name);
if (ret < 0)
return 1;
+   if (test_state)
+   return strcmp(lxc_state2str(ret), test_state) != 0;
 
printf("state:%10s\n", lxc_state2str(ret));
}
-- 
1.8.0


--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-version: use POSIX shell instead of bash

2012-11-26 Thread Natanael Copa
There is no reason to depend on bash for a single echo.
---
Should we move this to lxc-info --version?

 src/lxc/lxc-version.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/lxc-version.in b/src/lxc/lxc-version.in
index 1bd055a..b6875da 100644
--- a/src/lxc/lxc-version.in
+++ b/src/lxc/lxc-version.in
@@ -1,3 +1,3 @@
-#!/bin/bash
+#!/bin/sh
 
 echo "lxc version: @PACKAGE_VERSION@"
-- 
1.8.0


--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-setcap: use POSIX shell instead of bash

2012-11-26 Thread Natanael Copa
Avoid getopt --longoptions

Signed-off-by: Natanael Copa 
---
 src/lxc/lxc-setcap.in | 34 +-
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/src/lxc/lxc-setcap.in b/src/lxc/lxc-setcap.in
index 7fd390c..02c1e09 100644
--- a/src/lxc/lxc-setcap.in
+++ b/src/lxc/lxc-setcap.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 #
 # lxc: linux Container library
@@ -81,32 +81,40 @@ lxc_dropcaps()
 chmod 0755 @LXCPATH@
 }
 
-shortoptions='hd'
-longoptions='help'
-
-getopt=$(getopt -o $shortoptions --longoptions  $longoptions -- "$@")
-if [ $? != 0 ]; then
+usage_err() {
+[ -n "$1" ] && echo "$1" >&2
 usage
 exit 1
-fi
+}
 
-eval set -- "$getopt"
+optarg_check() {
+if [ -z "$2" ]; then
+usage_err "option '$1' requires an argument"
+fi
+}
 
-while true; do
-case "$1" in
+while [ $# -gt 0 ]; do
+opt="$1"
+shift
+case "$opt" in
-d)
LXC_DROP_CAPS="yes"
-   shift
;;
-h|--help)
help
exit 0
;;
--)
-   shift
break
;;
-   *)
+-?)
+usage_err "unknown option '$opt'"
+;;
+-*)
+# split opts -abc into -a -b -c
+set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
+;;
+ *)
usage
exit 1
;;
-- 
1.8.0


--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-setuid: use POSIX shell instead of bash

2012-11-26 Thread Natanael Copa
Avoid getop --longoptions.

Signed-off-by: Natanael Copa 
---
 src/lxc/lxc-setuid.in | 34 +-
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/src/lxc/lxc-setuid.in b/src/lxc/lxc-setuid.in
index 84f18af..e6a7b96 100644
--- a/src/lxc/lxc-setuid.in
+++ b/src/lxc/lxc-setuid.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 #
 # lxc: linux Container library
@@ -78,32 +78,40 @@ lxc_dropuid()
 chmod 0755 @LXCPATH@
 }
 
-shortoptions='hd'
-longoptions='help'
-
-getopt=$(getopt -o $shortoptions --longoptions  $longoptions -- "$@")
-if [ $? != 0 ]; then
+usage_err() {
+[ -n "$1" ] && echo "$1" >&2
 usage
 exit 1
-fi
+}
 
-eval set -- "$getopt"
+optarg_check() {
+if [ -z "$2" ]; then
+usage_err "option '$1' requires an argument"
+fi
+}
 
-while true; do
-case "$1" in
+while [ $# -gt 0 ]; do
+opt="$1"
+shift
+case "$opt" in
-d)
LXC_DROP_CAPS="yes"
-   shift
;;
-h|--help)
help
exit 0
;;
--)
-   shift
break
;;
-   *)
+-?)
+usage_err "unknown option '$opt'"
+;;
+-*)
+# split opts -abc into -a -b -c
+set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
+;;
+ *)
usage
exit 1
;;
-- 
1.8.0


--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH v2] lxc-version: use POSIX shell instead of bash

2012-11-26 Thread Natanael Copa
There is no reason to depend on bash for a single echo.

Signed-off-by: Natanael Copa 
---
Changes v1 -> v2:
 - add signed-off-by

 src/lxc/lxc-version.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/lxc-version.in b/src/lxc/lxc-version.in
index 1bd055a..b6875da 100644
--- a/src/lxc/lxc-version.in
+++ b/src/lxc/lxc-version.in
@@ -1,3 +1,3 @@
-#!/bin/bash
+#!/bin/sh
 
 echo "lxc version: @PACKAGE_VERSION@"
-- 
1.8.0


--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH v2] lxc-checkconfig: use POSIX shell instead of bash

2012-11-26 Thread Natanael Copa
- replace 'echo -e' with printf
- replace 'if [[ ... ]]' with 'if [ ... ]'
- add \ at after && and || when those are at end of line

Signed-off-by: Natanael Copa 
---
Changes v1 -> v2:
 - rebase against current staging

 src/lxc/lxc-checkconfig.in | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/lxc/lxc-checkconfig.in b/src/lxc/lxc-checkconfig.in
index 7dd6476..d17bb95 100644
--- a/src/lxc/lxc-checkconfig.in
+++ b/src/lxc/lxc-checkconfig.in
@@ -1,13 +1,13 @@
-#!/bin/bash
+#!/bin/sh
 
 # Allow environment variables to override grep and config
 : ${CONFIG:=/proc/config.gz}
 : ${GREP:=zgrep}
 
-SETCOLOR_SUCCESS="echo -en \\033[1;32m"
-SETCOLOR_FAILURE="echo -en \\033[1;31m"
-SETCOLOR_WARNING="echo -en \\033[1;33m"
-SETCOLOR_NORMAL="echo -en \\033[0;39m"
+SETCOLOR_SUCCESS="printf \\e[1;32m"
+SETCOLOR_FAILURE="printf \\e[1;31m"
+SETCOLOR_WARNING="printf \\e[1;33m"
+SETCOLOR_NORMAL="printf \\e[0;39m"
 
 is_set() {
 $GREP -q "$1=[y|m]" $CONFIG
@@ -21,12 +21,12 @@ is_enabled() {
 RES=$?
 
 if [ $RES -eq 0 ]; then
-   $SETCOLOR_SUCCESS && echo -e "enabled" && $SETCOLOR_NORMAL
+   $SETCOLOR_SUCCESS && echo "enabled" && $SETCOLOR_NORMAL
 else
if [ ! -z "$mandatory" -a "$mandatory" = yes ]; then
-   $SETCOLOR_FAILURE && echo -e "required" && $SETCOLOR_NORMAL
+   $SETCOLOR_FAILURE && echo "required" && $SETCOLOR_NORMAL
else
-   $SETCOLOR_WARNING && echo -e "missing" && $SETCOLOR_NORMAL
+   $SETCOLOR_WARNING && echo "missing" && $SETCOLOR_NORMAL
fi
 fi
 }
@@ -70,7 +70,7 @@ print_cgroups() {
 CGROUP_MNT_PATH=`print_cgroups cgroup /proc/self/mounts | head -1`
 KVER_MAJOR=$($GREP '^# Linux' $CONFIG | \
 sed -r 's/.* ([0-9])\.[0-9]{1,2}\.[0-9]{1,3}.*/\1/')
-if [[ $KVER_MAJOR == 2 ]]; then
+if [ "$KVER_MAJOR" = "2" ]; then
 KVER_MINOR=$($GREP '^# Linux' $CONFIG | \
 sed -r 's/.* 2.6.([0-9]{2}).*/\1/')
 else
@@ -82,7 +82,7 @@ echo -n "Cgroup: " && is_enabled CONFIG_CGROUPS yes
 
 if [ -f $CGROUP_MNT_PATH/cgroup.clone_children ]; then
 echo -n "Cgroup clone_children flag: " &&
-$SETCOLOR_SUCCESS && echo -e "enabled" && $SETCOLOR_NORMAL
+$SETCOLOR_SUCCESS && echo "enabled" && $SETCOLOR_NORMAL
 else
 echo -n "Cgroup namespace: " && is_enabled CONFIG_CGROUP_NS yes
 fi
@@ -101,12 +101,12 @@ echo "--- Misc ---"
 echo -n "Veth pair device: " && is_enabled CONFIG_VETH
 echo -n "Macvlan: " && is_enabled CONFIG_MACVLAN
 echo -n "Vlan: " && is_enabled CONFIG_VLAN_8021Q
-echo -n "File capabilities: " &&
-( [[ ${KVER_MAJOR} == 2 && ${KVER_MINOR} < 33 ]] &&
-   is_enabled CONFIG_SECURITY_FILE_CAPABILITIES ) ||
-( [[ ( ${KVER_MAJOR} == 2 && ${KVER_MINOR} > 32 ) ||
- ${KVER_MAJOR} > 2 ]] && $SETCOLOR_SUCCESS &&
- echo -e "enabled" && $SETCOLOR_NORMAL )
+echo -n "File capabilities: " && \
+( [ "${KVER_MAJOR}" = 2 ] && [ ${KVER_MINOR} -lt 33 ] && \
+   is_enabled CONFIG_SECURITY_FILE_CAPABILITIES ) || \
+( ( [ "${KVER_MAJOR}" = "2" ] && [ ${KVER_MINOR} -gt 32 ] ) || \
+ [ ${KVER_MAJOR} -gt 2 ] && $SETCOLOR_SUCCESS && \
+ echo "enabled" && $SETCOLOR_NORMAL )
 
 echo
 echo "Note : Before booting a new kernel, you can check its configuration"
-- 
1.8.0


--
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] Create busybox commands as symlinks instead of hardlinks

2012-11-30 Thread Natanael Copa
On Fri, 30 Nov 2012 11:49:25 -0500
Dwight Engen  wrote:

> +# it would be nice to just use "chroot $rootfs busybox --install
> -s /bin"
> +# but that only works right in a chroot with busybox >= 1.19.0

I think it should work with busybox before 1.19 if you make
sure /proc/self/exe works in the chroot.

-nc

--
Keep yourself connected to Go Parallel: 
TUNE You got it built. Now make it sing. Tune shows you how.
http://goparallel.sourceforge.net
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCHv2] lxc-create: Store template information in config

2012-11-30 Thread Natanael Copa
On Fri, 30 Nov 2012 17:01:59 -0500
Stéphane Graber  wrote:

> Change lxc-create to add the name of the template, checksum and any
> parameters
> to the container's configuration.
> This makes it easier to debug and figure out exactly how a container
> was built.
> 
> Signed-off-by: Stéphane Graber 
> ---
>  src/lxc/lxc-create.in | 36 +++-
>  1 file changed, 23 insertions(+), 13 deletions(-)
> 
> diff --git a/src/lxc/lxc-create.in b/src/lxc/lxc-create.in
> index 30f0c22..7a50633 100644
> --- a/src/lxc/lxc-create.in
> +++ b/src/lxc/lxc-create.in
> @@ -281,7 +281,29 @@ if [ ! -r "$lxc_config" ]; then
>  exit 1
>  fi
>  -cp $lxc_config $lxc_path/$lxc_name/config
> +# Allow for a path to be provided as the template name
> +if [ -x $lxc_template ]; then

if [ -x "$lxc_template" ]; then

other wise will posix shell barf if $lxc_template is empty.

> +template_path=$lxc_template
> +else
> +template_path=${templatedir}/lxc-$lxc_template
> +fi
> +
> +if ! [ -x "$template_path" ]; then
> +echo "$(basename $0): unknown template '$lxc_template'" >&2
> +cleanup
> +fi
> +
> +if [ ! -z $lxc_template ]; then

Same here. Do:
if [ ! -z "$lxc_template" ]; then

> +sum=$(sha1sum $template_path | cut -d ' ' -f1)
> +echo "# Template used to create this container: $lxc_template" >>
> $lxc_path/$lxc_name/config
> +if [ -n "$*" ]; then

I'm not sure this is ok. I'd do:

if [ $# -gt 0 ]; then

> +echo "# Parameters passed to the template: $*" >>

echo "# Parameters passed to the template: $@" >>

> $lxc_path/$lxc_name/config
> +fi
> +echo "# Checksum of the template script (SHA-1): $sum" >>
> $lxc_path/$lxc_name/config
> +echo "" >> $lxc_path/$lxc_name/config
> +fi
> +
> +cat $lxc_config >> $lxc_path/$lxc_name/config
>   if [ -n "$custom_rootfs" ]; then
>   if grep -q "lxc.rootfs" $lxc_path/$lxc_name/config ; then
> @@ -301,18 +323,6 @@ if [ $backingstore = "lvm" ]; then
>  fi
>   if [ ! -z $lxc_template ]; then
> -# Allow for a path to be provided as the template name
> -if [ -x $lxc_template ]; then
> -template_path=$lxc_template
> -else
> -template_path=${templatedir}/lxc-$lxc_template
> -fi
> -
> -if ! [ -x "$template_path" ]; then
> -echo "$(basename $0): unknown template '$lxc_template'" >&2
> -cleanup
> -fi
> -
>  $template_path --path=$lxc_path/$lxc_name --name=$lxc_name $*
>  if [ $? -ne 0 ]; then
>  echo "$(basename $0): failed to execute template
> '$lxc_template'" >&2


--
Keep yourself connected to Go Parallel: 
TUNE You got it built. Now make it sing. Tune shows you how.
http://goparallel.sourceforge.net
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] templates: initial support for Alpine Linux

2012-12-24 Thread Natanael Copa
Requires apk-tools (http://git.alpinelinux.org/cgit/apk-tools)

Signed-off-by: Natanael Copa 
---
 .gitignore  |   1 +
 configure.ac|   1 +
 templates/lxc-alpine.in | 190 
 3 files changed, 192 insertions(+)
 create mode 100644 templates/lxc-alpine.in

diff --git a/.gitignore b/.gitignore
index a766716..7401b55 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,6 +24,7 @@ libtool
 lxc.spec
 lxc.pc
 
+templates/lxc-alpine
 templates/lxc-altlinux
 templates/lxc-archlinux
 templates/lxc-busybox
diff --git a/configure.ac b/configure.ac
index c4f1b2e..2add6a3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -257,6 +257,7 @@ AC_CONFIG_FILES([
templates/lxc-altlinux
templates/lxc-sshd
templates/lxc-archlinux
+   templates/lxc-alpine
 
src/Makefile
src/lxc/Makefile
diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
new file mode 100644
index 000..6f7c90d
--- /dev/null
+++ b/templates/lxc-alpine.in
@@ -0,0 +1,190 @@
+#!/bin/sh
+
+install_alpine() {
+rootfs="$1"
+mkdir -p "$rootfs"/etc/apk || return 1
+cp -r ${keys_dir:-/etc/apk/keys} "$rootfs"/etc/apk/
+if [ -n "$repository" ]; then
+echo "$repository" > "$rootfs"/etc/apk/repositories
+else
+cp /etc/apk/repositories "$rootfs"/etc/apk/repositories || return 1
+fi
+${APK:-apk} add -U --initdb --root $rootfs alpine-base
+}
+
+configure_alpine() {
+rootfs="$1"
+echo "Setting up /etc/inittab"
+cat >"$rootfs"/etc/inittab< "$rootfs/etc/resolv.conf"
+
+# configure the network using the dhcp
+# note that lxc will set up lo interface
+cat < $rootfs/etc/network/interfaces
+#auto lo
+iface lo inet loopback
+
+auto eth0
+iface eth0 inet dhcp
+EOF
+
+# set the hostname
+echo $hostname > $rootfs/etc/hostname
+
+# missing device nodes
+echo "Setting up device nodes"
+mkdir -p -m 755 "$rootfs/dev/pts"
+mkdir -p -m 1777 "$rootfs/dev/shm"
+mknod -m 666 "$rootfs/dev/full" c 1 7
+mknod -m 666 "$rootfs/dev/random" c 1 8
+mknod -m 666 "$rootfs/dev/urandom" c 1 9
+mknod -m 666 "$rootfs/dev/tty0" c 4 0
+mknod -m 666 "$rootfs/dev/tty1" c 4 1
+mknod -m 666 "$rootfs/dev/tty2" c 4 2
+mknod -m 666 "$rootfs/dev/tty3" c 4 3
+mknod -m 666 "$rootfs/dev/tty4" c 4 4
+#mknod -m 600 "$rootfs/dev/initctl" p
+mknod -m 666 "$rootfs/dev/tty" c 5 0
+mknod -m 666 "$rootfs/dev/console" c 5 1
+mknod -m 666 "$rootfs/dev/ptmx" c 5 2
+
+# start services
+ln -s /etc/init.d/syslog "$rootfs"/etc/runlevels/default/syslog
+
+return 0
+}
+
+copy_configuration() {
+path=$1
+rootfs=$2
+hostname=$3
+
+grep -q "^lxc.rootfs" $path/config 2>/dev/null \
+|| echo "lxc.rootfs = $rootfs" >> $path/config
+cat <> $path/config
+lxc.tty = 4
+lxc.pts = 1024
+lxc.utsname = $hostname
+
+# When using LXC with apparmor, uncomment the next line to run unconfined:
+#lxc.aa_profile = unconfined
+
+# network interface
+lxc.network.name = eth0
+lxc.network.type = veth
+lxc.network.flags = up
+# enable for bridging
+#lxc.network.link = br0
+#lxc.network.ipv4 = n.n.n.n
+#lxc.network.ipv4.gateway = auto
+
+# devices
+lxc.cgroup.devices.deny = a
+# /dev/null and zero
+lxc.cgroup.devices.allow = c 1:3 rwm
+lxc.cgroup.devices.allow = c 1:5 rwm
+# consoles
+lxc.cgroup.devices.allow = c 5:1 rwm
+lxc.cgroup.devices.allow = c 5:0 rwm
+lxc.cgroup.devices.allow = c 4:0 rwm
+lxc.cgroup.devices.allow = c 4:1 rwm
+# /dev/{,u}random
+lxc.cgroup.devices.allow = c 1:9 rwm
+lxc.cgroup.devices.allow = c 1:8 rwm
+lxc.cgroup.devices.allow = c 136:* rwm
+lxc.cgroup.devices.allow = c 5:2 rwm
+# rtc
+lxc.cgroup.devices.allow = c 254:0 rwm
+
+# mounts point
+lxc.mount.entry=proc proc proc nodev,noexec,nosuid 0 0
+lxc.mount.entry=run run tmpfs nodev,noexec,nosuid,relatime,size=1m,mode=0755 0 0
+lxc.mount.entry=none dev/pts devpts gid=5,mode=620 0 0
+
+EOF
+
+return 0
+}
+
+die() {
+echo "$@" >&2
+exit 1
+}
+
+usage() {
+echo "Usage: $(basename $0) [-h|--help] -p|--path  -n|--name " 
>&2
+}
+
+usage_err() {
+usage
+exit 1
+}
+
+optarg_check() {
+if [ -z "$2" ]; then
+usage_err "option '$1' requires an argument"
+fi
+}
+
+default_path=@LXCPATH@
+
+while [ $# -gt 0 ]; do
+opt="$1"
+shift
+case "$opt" in
+-h|--help)
+usage
+exit 0
+;;
+-n|--name)
+optarg_check $opt "$1"
+name=$1
+shift
+;;
+-p|--path)
+   

[lxc-devel] [PATCH] define MS_SHARED if needed

2012-12-25 Thread Natanael Copa
Fixes build on uClibc.

Signed-off-by: Natanael Copa 
---
 src/lxc/conf.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 96940b3..c82e759 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -87,6 +87,10 @@ lxc_log_define(lxc_conf, lxc);
 #define MNT_DETACH 2
 #endif
 
+#ifndef MS_SLAVE
+#define MS_SLAVE (1<<19)
+#endif
+
 #ifndef MS_RELATIME
 #define MS_RELATIME (1 << 21)
 #endif
-- 
1.8.0.2


--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-checkconfig: fix colors when using dash

2012-12-25 Thread Natanael Copa
The \e did not work as expected on dash. Replace with proper posix \033

Signed-off-by: Natanael Copa 
---
 src/lxc/lxc-checkconfig.in | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/lxc/lxc-checkconfig.in b/src/lxc/lxc-checkconfig.in
index 13dbf3b..472755f 100644
--- a/src/lxc/lxc-checkconfig.in
+++ b/src/lxc/lxc-checkconfig.in
@@ -4,10 +4,10 @@
 : ${CONFIG:=/proc/config.gz}
 : ${GREP:=zgrep}
 
-SETCOLOR_SUCCESS="printf \\e[1;32m"
-SETCOLOR_FAILURE="printf \\e[1;31m"
-SETCOLOR_WARNING="printf \\e[1;33m"
-SETCOLOR_NORMAL="printf \\e[0;39m"
+SETCOLOR_SUCCESS="printf \\033[1;32m"
+SETCOLOR_FAILURE="printf \\033[1;31m"
+SETCOLOR_WARNING="printf \\033[1;33m"
+SETCOLOR_NORMAL="printf \\033[0;39m"
 
 is_set() {
 $GREP -q "$1=[y|m]" $CONFIG
-- 
1.8.0.2


--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH 3/4] lxc-clone: use posix shell instead of bash

2012-12-25 Thread Natanael Copa
- avoid getopt --longoptions
- use 'which' instead of 'type' to detect existance of tools
- use 'grep -q -w' instead of bash substring variable expansion
  ${line:0:18}

Signed-off-by: Natanael Copa 
---
 src/lxc/lxc-clone.in | 56 +---
 1 file changed, 31 insertions(+), 25 deletions(-)

diff --git a/src/lxc/lxc-clone.in b/src/lxc/lxc-clone.in
index c9cc5c7..4640149 100644
--- a/src/lxc/lxc-clone.in
+++ b/src/lxc/lxc-clone.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 #
 # lxc: linux Container library
@@ -44,8 +44,16 @@ help() {
 echo "  only works for non-snapshot LVM)" >&2
 }
 
-shortoptions='ho:n:sL:v:p:t:'
-longoptions='help,orig:,name:,snapshot,fssize:,vgname:,lvprefix:,fstype:'
+usage_err() {
+[ -n "$1" ] && echo "$1" >&2
+usage
+exit 1
+}
+
+optarg_check() {
+[ -n "$2" ] || usage_err "option $1 requires an argument"
+}
+
 lxc_path=@LXCPATH@
 bindir=@BINDIR@
 snapshot=no
@@ -55,57 +63,55 @@ lxc_vg=lxc
 lxc_lv_prefix=""
 fstype=ext3
 
-getopt=$(getopt -o $shortoptions --longoptions  $longoptions -- "$@")
-if [ $? != 0 ]; then
-usage
-exit 1;
-fi
-
-eval set -- "$getopt"
-
-while true; do
-case "$1" in
+while [ $# -gt 0 ]; do
+opt="$1"
+shift
+case "$opt" in
 -h|--help)
 help
 exit 1
 ;;
 -s|--snapshot)
-shift
 snapshot=yes
 snapshot_opt="-s"
 ;;
 -o|--orig)
-shift
+optarg_check $opt $1
 lxc_orig=$1
 shift
 ;;
 -L|--fssize)
-shift
+optarg_check $opt $1
 lxc_size=$1
 shift
 ;;
 -v|--vgname)
-shift
+optarg_check $opt $1
 lxc_vg=$1
 shift
 ;;
 -n|--name)
-shift
+optarg_check $opt $1
 lxc_new=$1
 shift
 ;;
 -p|--lvprefix)
-shift
+optarg_check $opt $1
 lxc_lv_prefix=$1
 shift
 ;;
 --)
-shift
 break
 ;;
+-?)
+usage_err "Unknown option: '$opt'"
+;;
+-*)
+# split opts -abc into -a -b -c
+set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
+;;
 *)
-usage
-exit 1
+usage_err
 ;;
 esac
 done
@@ -191,7 +197,7 @@ lxc-info -s -n $lxc_orig|grep RUNNING >/dev/null 2>&1 || 
container_running=False
 
 sed -i '/lxc.rootfs/d' $lxc_path/$lxc_new/config
 if [ -b $oldroot ]; then
-type vgscan || { echo "$(basename $0): lvm is not installed" >&2; false; }
+which vgscan >/dev/null || { echo "$(basename $0): lvm is not installed" 
>&2; false; }
 lvdisplay $oldroot > /dev/null 2>&1 || { echo "$(basename $0): non-lvm 
blockdev cloning is not supported" >&2; false; }
 lvm=TRUE
 # ok, create a snapshot of the lvm device
@@ -204,7 +210,7 @@ if [ -b $oldroot ]; then
 fi
 newlv="${lxc_lv_prefix}${lxc_new}_snapshot"
 lvcreate -s -L $lxc_size -n $newlv $oldroot
-type xfs_admin > /dev/null 2>&1 && {
+which xfs_admin > /dev/null 2>&1 && {
 # change filesystem UUID if it is an xfs filesystem
 xfs_admin -u /dev/$lxc_vg/$newlv && xfs_admin -U generate 
/dev/$lxc_vg/$newlv
 }
@@ -272,7 +278,7 @@ c=$lxc_path/$lxc_new/config
 mv ${c} ${c}.old
 (
 while read line; do
-if [ "${line:0:18}" = "lxc.network.hwaddr" ]; then
+if echo $line | grep -q -w '^lxc.network.hwaddr'; then
 echo "lxc.network.hwaddr= 00:16:3e:$(openssl rand -hex 3| sed 
's/\(..\)/\1:/g; s/.$//')"
 else
 echo "$line"
-- 
1.8.0.2


--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH 1/4] lxc-destroy: use posix shell instead of bash

2012-12-25 Thread Natanael Copa
- avoid use getopt --longoptions

Signed-off-by: Natanael Copa 
---
 src/lxc/lxc-destroy.in | 41 +
 1 file changed, 25 insertions(+), 16 deletions(-)

diff --git a/src/lxc/lxc-destroy.in b/src/lxc/lxc-destroy.in
index 1527495..0c27e4a 100644
--- a/src/lxc/lxc-destroy.in
+++ b/src/lxc/lxc-destroy.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 #
 # lxc: linux Container library
@@ -39,38 +39,47 @@ help() {
 echo "  -fstop the container if it is running (rather than abort)" 
>&2
 }
 
-shortoptions='hn:f'
-longoptions='help,name:'
-lxc_path=@LXCPATH@
-force=0
-
-getopt=$(getopt -o $shortoptions --longoptions  $longoptions -- "$@")
-if [ $? != 0 ]; then
+usage_err() {
+[ -n "$1" ] && echo "$1" >&2
 usage
-exit 1;
-fi
+exit 1
+}
 
-eval set -- "$getopt"
+optarg_check() {
+if [ -z "$2" ]; then
+usage_err "option '$1' requires an argument"
+fi
+}
 
-while true; do
-case "$1" in
+lxc_path=@LXCPATH@
+force=0
+
+while [ $# -gt 0 ]; do
+opt="$1"
+shift
+case "$opt" in
 -h|--help)
 help
 exit 1
 ;;
 -n|--name)
-shift
+optarg_check "$opt" "$1"
 lxc_name=$1
 shift
 ;;
 -f)
 force=1
-shift
 ;;
 --)
-shift
 break
 ;;
+-?)
+usage_err "unknown option '$opt'"
+;;
+-*)
+# split opts -abc into -a -b -c
+set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
+;;
 *)
 usage
 exit 1
-- 
1.8.0.2


--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH 4/4] lxc-netstat: use posix shell instead of bash

2012-12-25 Thread Natanael Copa
- use case .. in instead of comparison with globs
- avoid 'local'

Signed-off-by: Natanael Copa 
---
 src/lxc/lxc-netstat.in | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/lxc/lxc-netstat.in b/src/lxc/lxc-netstat.in
index df18620..87bd3eb 100644
--- a/src/lxc/lxc-netstat.in
+++ b/src/lxc/lxc-netstat.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 #
 # lxc: linux Container library
@@ -32,8 +32,6 @@ help() {
 
 get_parent_cgroup()
 {
-local hierarchies hierarchy fields subsystems init_cgroup mountpoint
-
 parent_cgroup=""
 
 # Obtain a list of hierarchies that contain one or more subsystems
@@ -58,11 +56,10 @@ get_parent_cgroup()
 
 # Return the absolute path to the containers' parent cgroup
 # (do not append '/lxc' if the hierarchy contains the 'ns' subsystem)
-if [[ ",$subsystems," == *,ns,* ]]; then
-parent_cgroup="${mountpoint}${init_cgroup%/}"
-else
-parent_cgroup="${mountpoint}${init_cgroup%/}/lxc"
-fi
+case ",$subsystems," in
+*,ns,*) parent_cgroup="${mountpoint}${init_cgroup%/}";;
+*) parent_cgroup="${mountpoint}${init_cgroup%/}/lxc";;
+esac
 break
 done
 }
-- 
1.8.0.2


--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH 2/4] legacy/lxc-ls: use posix shell instead of bash

2012-12-25 Thread Natanael Copa
- use case .. in instead of comparison with globs
- avoid 'local'

While here, also avoid 'find ... -printf' which is not supported on busybox

Signed-off-by: Natanael Copa 
---
 src/lxc/legacy/lxc-ls.in | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/src/lxc/legacy/lxc-ls.in b/src/lxc/legacy/lxc-ls.in
index f26572d..fbb1385 100644
--- a/src/lxc/legacy/lxc-ls.in
+++ b/src/lxc/legacy/lxc-ls.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 #
 # lxc: linux Container library
@@ -35,8 +35,6 @@ help() {
 
 get_parent_cgroup()
 {
-   local hierarchies hierarchy fields subsystems init_cgroup mountpoint
-
parent_cgroup=""
 
# Obtain a list of hierarchies that contain one or more subsystems
@@ -61,11 +59,10 @@ get_parent_cgroup()
 
# Return the absolute path to the containers' parent cgroup
# (do not append '/lxc' if the hierarchy contains the 'ns' 
subsystem)
-   if [[ ",$subsystems," == *,ns,* ]]; then
-   parent_cgroup="${mountpoint}${init_cgroup%/}"
-   else
-   parent_cgroup="${mountpoint}${init_cgroup%/}/lxc"
-   fi
+   case ",$subsystems," in
+   *,ns,*) parent_cgroup="${mountpoint}${init_cgroup%/}";;
+   *) parent_cgroup="${mountpoint}${init_cgroup%/}/lxc";;
+   esac
break
done
 }
@@ -87,7 +84,7 @@ done
 
 containers=""
 if [ ! -z "$directory" ]; then
-   containers=$(find $directory -mindepth 1 -maxdepth 1 -type d -printf 
"%f\n" 2>/dev/null)
+   containers=$(find $directory -mindepth 1 -maxdepth 1 -type d 
2>/dev/null | sed 's:.*/::')
 fi
 
 cd "$directory"
-- 
1.8.0.2


--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH 2/4] legacy/lxc-ls: use posix shell instead of bash

2012-12-25 Thread Natanael Copa
On Tue, 25 Dec 2012 17:36:12 +0100
Stéphane Graber  wrote:

> On 12/25/2012 05:08 PM, Natanael Copa wrote:
> > Signed-off-by: Natanael Copa 
...
> Pushed to staging. Thanks.
> 
> I also fixed a minor indent problem in that commit (the last esac was
> space indented instead of tab indented).

Sorry about that.

Thanks for fast handling of the paches.

Now I think I only have lxc-ps left, which uses arrays and stuff. I
think I have something almost working already but i wonder if I maybe
should rewrite the whole thing (well the nasty parts) in awk instead.

-nc

--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH 1/2] lxc-netstat: improve finding fs mountpoint of hierarchy

2012-12-26 Thread Natanael Copa
We cannot assume that the mount source name always starts with 'cgroup'
so we check the filesystem type instead.

Use 'awk' instead of 'grep -E' and  as it is a better tool for this job.

This fixes the tool on systems using openrc.

Signed-off-by: Natanael Copa 
---
 src/lxc/lxc-netstat.in | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/lxc/lxc-netstat.in b/src/lxc/lxc-netstat.in
index 87bd3eb..6d08ce3 100644
--- a/src/lxc/lxc-netstat.in
+++ b/src/lxc/lxc-netstat.in
@@ -51,7 +51,8 @@ get_parent_cgroup()
 init_cgroup=${fields#*:}
 
 # Get the filesystem mountpoint of the hierarchy
-mountpoint=$(grep -E "^cgroup [^ ]+ [^ ]+ ([^ ]+,)?$subsystems(,[^ 
]+)? " /proc/self/mounts | cut -d ' ' -f 2)
+mountpoint=$(awk -v subsysregex="(^|,)$subsystems(,|\$)" \
+'$3 == "cgroup" && $4 ~ subsysregex {print $2}' /proc/self/mounts)
 if [ -z "$mountpoint" ]; then continue; fi
 
 # Return the absolute path to the containers' parent cgroup
-- 
1.8.0.2


--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH 2/2] legacy/lxc-ls: improve finding fs mountpoint of hierarchy

2012-12-26 Thread Natanael Copa
We cannot assume that the mount source name always starts with 'cgroup'
so we check the filesystem type instead.

Use 'awk' instead of 'grep -E' and  as it is a better tool for this job.

This fixes the tool on systems using openrc.

Signed-off-by: Natanael Copa 
---
 src/lxc/legacy/lxc-ls.in | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/lxc/legacy/lxc-ls.in b/src/lxc/legacy/lxc-ls.in
index fbb1385..7a90166 100644
--- a/src/lxc/legacy/lxc-ls.in
+++ b/src/lxc/legacy/lxc-ls.in
@@ -54,7 +54,8 @@ get_parent_cgroup()
init_cgroup=${fields#*:}
 
# Get the filesystem mountpoint of the hierarchy
-   mountpoint=$(grep -E "^[^ ]+ [^ ]+ cgroup ([^ 
]+,)?$subsystems(,[^ ]+)? " /proc/self/mounts | cut -d ' ' -f 2)
+   mountpoint=$(awk -v subsysregex="(^|,)$subsystems(,|\$)" \
+   '$3 == "cgroup" && $4 ~ subsysregex {print $2}' 
/proc/self/mounts)
if [ -z "$mountpoint" ]; then continue; fi
 
# Return the absolute path to the containers' parent cgroup
-- 
1.8.0.2


--
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-ps: use posix shell and awk instead of bash

2012-12-26 Thread Natanael Copa
Use awk to parse the output pf 'ps' and the tasks files for the
containers.

Use awk fields to find PID column rather than assume that the PID field
is exactly 5 chars wide and has a leading space ' PID'. This works as
long as the PID field is before the command or other field that include
spaces. This also makes it work with busybox 'ps'.

Signed-off-by: Natanael Copa 
---
 src/lxc/lxc-ps.in | 92 ---
 1 file changed, 54 insertions(+), 38 deletions(-)

diff --git a/src/lxc/lxc-ps.in b/src/lxc/lxc-ps.in
index 1f45044..25e843b 100644
--- a/src/lxc/lxc-ps.in
+++ b/src/lxc/lxc-ps.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 #
 # lxc: linux Container library
@@ -56,16 +56,16 @@ get_parent_cgroup()
 init_cgroup=${fields#*:}
 
 # Get the filesystem mountpoint of the hierarchy
-mountpoint=$(grep -E "^cgroup [^ ]+ [^ ]+ ([^ ]+,)?$subsystems(,[^ 
]+)? " /proc/self/mounts | cut -d ' ' -f 2)
+mountpoint=$(awk -v subsysregex="(^|,)$subsystems(,|\$)" \
+'$3 == "cgroup" && $4 ~ subsysregex {print $2}' /proc/self/mounts)
 if [ -z "$mountpoint" ]; then continue; fi
 
 # Return the absolute path to the containers' parent cgroup
 # (do not append '/lxc' if the hierarchy contains the 'ns' subsystem)
-if [[ ",$subsystems," == *,ns,* ]]; then
-parent_cgroup="${mountpoint}${init_cgroup%/}"
-else
-parent_cgroup="${mountpoint}${init_cgroup%/}/lxc"
-fi
+case ",$subsystems," in
+*,ns,*) parent_cgroup="${mountpoint}${init_cgroup%/}";;
+*) parent_cgroup="${mountpoint}${init_cgroup%/}/lxc";;
+esac
 break
 done
 }
@@ -97,46 +97,62 @@ if [ ! -d "$parent_cgroup" ]; then
 exit 1
 fi
 
-declare -a container_of_pid
-container_field_width=9
-IFS=","
 if [ -z "$containers" ]; then
-containers=( $(find $parent_cgroup -mindepth 1 -maxdepth 1 -type d -printf 
"%f," 2>/dev/null) )
-else
-containers=( $containers )
+containers="$(find $parent_cgroup -mindepth 1 -maxdepth 1 -type d 
2>/dev/null | sed 's:.*/::')"
 fi
 
-declare -i pid
-IFS=$'\n'
-for container in ${containers[@]}; do
+container_field_width=9
+tasks_files=
+for container in ${containers}; do
 if [ "${#container}" -gt "$container_field_width" ]; then
 container_field_width=${#container}
 fi
 
 if [ -f "$parent_cgroup/$container/tasks" ]; then
-while read pid; do
-container_of_pid[$pid]=$container
-done < "$parent_cgroup/$container/tasks"
+tasks_files="$tasks_files $parent_cgroup/$container/tasks"
 fi
 done
 
-declare -i line_pid_end_position
-while read line; do
-if [ -z "$line_pid_end_position" ]; then
-if [[ "$line" != *" PID"* ]]; then
-echo "$(basename $0): no PID column found in \`ps' output" >&2
-exit 1
-fi
-
-buffer=${line%" PID"*}
-let line_pid_end_position=${#buffer}+4
-printf "%-${container_field_width}s %s\n" "CONTAINER" "$line"
-continue
-fi
+# first file is stdin, the rest are the container tasks
+ps "$@" | awk -v container_field_width="$container_field_width" '
+# first line is PS header
+NR == 1 {
+# find pid field index
+for (i = 1; i<=NF; i++)
+if ($i == "PID") {
+pididx = i
+break
+}
+if (pididx == "") {
+print("No PID field found") > "/dev/stderr"
+exit 1
+}
+header = $0
+next
+}
 
-buffer=${line:0:$line_pid_end_position}
-pid=${buffer##* }
-if [ "$list_container_processes" -eq "0" -o ! -z 
"${container_of_pid[pid]}" ]; then
-printf "%-${container_field_width}s %s\n" "${container_of_pid[pid]}" 
"$line"
-fi
-done < <(ps "$@")
+# store lines from ps with pid as index
+NR == FNR {
+ps[$pididx] = $0
+next
+}
+
+# find container name from filename on first line
+FNR == 1 {
+container = FILENAME
+sub(/\/tasks/, "", container)
+sub(/.*\//, "", container)
+}
+
+# container tasks
+{
+container_of_pid[$0] = container
+}
+
+END {
+printf("%-" container_field_width "s %s\n", "CONTAINER", header)
+for (pid in container_of_pid)
+printf("%-" container_field_width "s %s\n", container_of_pid[pid], 
ps[pid])
+}
+
+' - $tasks_files
-- 
1.8.0.2


--
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612 
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-shutdown: use posix shell instead of bash

2012-12-27 Thread Natanael Copa
- avoid getopt --longoptions
- use 'which' instead of 'type' to detect existance of tools
- specify -s SIG with kill

Signed-off-by: Natanael Copa 
---
dash didn't complain when I tested it, but it did not shut down the
container due to busybox init uses other signals for poweroff/reboot.

The poweroff/reboot signal should probably be configurable but thats
other issue.

 src/lxc/lxc-shutdown.in | 52 ++---
 1 file changed, 28 insertions(+), 24 deletions(-)

diff --git a/src/lxc/lxc-shutdown.in b/src/lxc/lxc-shutdown.in
index c0d1702..cf1d603 100644
--- a/src/lxc/lxc-shutdown.in
+++ b/src/lxc/lxc-shutdown.in
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # (C) Copyright Canonical 2011,2012
 
@@ -41,30 +41,30 @@ dolxcstop()
 exit 0
 }
 
-shortoptions='hn:rwt:'
-longoptions='help,name:,wait,reboot,timeout:'
-
-timeout="-1"
-
-getopt=$(getopt -o $shortoptions --longoptions  $longoptions -- "$@")
-if [ $? != 0 ]; then
+usage_err() {
+[ -n "$1" ] && echo "$1" >&2
 usage
-exit 1;
-fi
+exit 1
+}
+
+optarg_check() {
+[ -n "$2" ] || usage_err "option '$1' requires an argument"
+}
 
-eval set -- "$getopt"
+timeout="-1"
 
 reboot=0
 dowait=0
 
-while true; do
-case "$1" in
+while [ $# -gt 0 ]; do
+opt="$1"
+shift
+case "$opt" in
 -h|--help)
 usage
-exit 1
 ;;
 -n|--name)
-shift
+optarg_check $opt "$1"
 lxc_name=$1
 shift
 ;;
@@ -77,19 +77,23 @@ while true; do
 shift
 ;;
 -t|--timeout)
-shift
+optarg_check $opt "$1"
 timeout=$1
 dowait=1
 shift
 ;;
 --)
-shift
 break;;
+-?)
+usage_err "unknown option '$opt'"
+;;
+-*)
+# split opts -abc into -a -b -c
+set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
+;;
 *)
-echo $1
-usage
+usage_err "unknown option '$opt'"
 exit 1
-;;
 esac
 done
 
@@ -104,8 +108,8 @@ if [ "$(id -u)" != "0" ]; then
exit 1
 fi
 
-type lxc-info > /dev/null || { echo "lxc-info not found."; exit 1; }
-type lxc-wait > /dev/null || { echo "lxc-wait not found."; exit 1; }
+which lxc-info > /dev/null || { echo "lxc-info not found."; exit 1; }
+which lxc-wait > /dev/null || { echo "lxc-wait not found."; exit 1; }
 
 pid=`lxc-info -n $lxc_name -p 2>/dev/null | awk '{ print $2 }'`
 if [ "$pid" = "-1" ]; then
@@ -114,10 +118,10 @@ if [ "$pid" = "-1" ]; then
 fi
 
 if [ $reboot -eq 1 ]; then
-kill -INT $pid
+kill -s SIGINT $pid
 exit 0
 else
-kill -PWR $pid
+kill -s SIGPWR $pid
 fi
 
 if [ $dowait -eq 0 ]; then
-- 
1.8.0.2


--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] cleanup: use lxc-info --state-is

2012-12-28 Thread Natanael Copa
We now have the possibility to test for a given state. Use this feature
instead of parsing output with grep or awk

Signed-off-by: Natanael Copa 
---
 src/lxc/lxc-clone.in| 2 +-
 src/lxc/lxc-destroy.in  | 5 ++---
 src/lxc/lxc-netstat.in  | 3 +--
 src/lxc/lxc-shutdown.in | 6 +-
 4 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/src/lxc/lxc-clone.in b/src/lxc/lxc-clone.in
index 4640149..cf349ea 100644
--- a/src/lxc/lxc-clone.in
+++ b/src/lxc/lxc-clone.in
@@ -193,7 +193,7 @@ oldroot=`grep lxc.rootfs $lxc_path/$lxc_orig/config | awk 
-F'[= \t]+' '{ print $
 rootfs=`echo $oldroot |sed "s/$lxc_orig/$lxc_new/"`
 
 container_running=True
-lxc-info -s -n $lxc_orig|grep RUNNING >/dev/null 2>&1 || 
container_running=False
+lxc-info -n $lxc_orig --status-is RUNNING || container_running=False
 
 sed -i '/lxc.rootfs/d' $lxc_path/$lxc_new/config
 if [ -b $oldroot ]; then
diff --git a/src/lxc/lxc-destroy.in b/src/lxc/lxc-destroy.in
index 0c27e4a..497acbe 100644
--- a/src/lxc/lxc-destroy.in
+++ b/src/lxc/lxc-destroy.in
@@ -104,13 +104,12 @@ if [ ! -d "$lxc_path/$lxc_name" ]; then
 fi
 
 # make sure the container is stopped
-state=`lxc-info -n $lxc_name 2>/dev/null | head -1 |awk '{print $2}'`
-if [ $state != "STOPPED" ]; then
+if ! lxc-info -n $lxc_name --state-is "STOPPED"; then
 if [ $force -eq 1 ]; then
 lxc-stop -n $lxc_name
 lxc-wait -n $lxc_name -s STOPPED
 else
-echo "$(basename $0): '$lxc_name' is $state; aborted" >&2
+echo "$(basename $0): '$lxc_name' $(lxc-info -n $lxc_name -s); 
aborted" >&2
 exit 1
 fi
 fi
diff --git a/src/lxc/lxc-netstat.in b/src/lxc/lxc-netstat.in
index 6d08ce3..2fa2d23 100644
--- a/src/lxc/lxc-netstat.in
+++ b/src/lxc/lxc-netstat.in
@@ -96,8 +96,7 @@ if [ -z "$exec" ]; then
 exec @BINDIR@/lxc-unshare -s MOUNT -- $0 -n $name --exec "$@"
 fi
 
-lxc-info -n $name 2>&1 | grep -q 'STOPPED'
-if [ $? -eq 0 ]; then
+if lxc-info -n $name --state-is 'STOPPED'; then
 echo "$(basename $0): container '$name' is not running" >&2
 exit 1
 fi
diff --git a/src/lxc/lxc-shutdown.in b/src/lxc/lxc-shutdown.in
index cf1d603..ad8395b 100644
--- a/src/lxc/lxc-shutdown.in
+++ b/src/lxc/lxc-shutdown.in
@@ -134,11 +134,7 @@ if [ $timeout != "-1" ]; then
 alarmpid=$!
 fi
 
-while [ 1 ]; do
-s=`lxc-info -s -n $lxc_name | awk '{ print $2 }'`
-if [ "$s" = "STOPPED" ]; then
-break;
-fi
+while ! lxc-info -n $lxc_name --state-is STOPPED; do
 sleep 1
 done
 
-- 
1.8.0.2


--
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH 3/5] lxc-alpine: add --repository option

2012-12-31 Thread Natanael Copa
This allows specifying what repository to use for the container.

Signed-off-by: Natanael Copa 
---
 templates/lxc-alpine.in | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
index 7787e75..87886f5 100644
--- a/templates/lxc-alpine.in
+++ b/templates/lxc-alpine.in
@@ -119,7 +119,10 @@ die() {
 }
 
 usage() {
-echo "Usage: $(basename $0) [-h|--help] -p|--path  -n|--name " 
>&2
+cat >&2 <]
+   -p|--path  -n|--name 
+EOF
 }
 
 usage_err() {
@@ -153,6 +156,11 @@ while [ $# -gt 0 ]; do
 path=$1
 shift
 ;;
+-r|--repository)
+optarg_check $opt "$1"
+repository=$1
+shift
+   ;;
 --)
 break;;
 --*=*)
-- 
1.8.0.3


--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122412
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH 2/5] lxc-alpine: indent fixes

2012-12-31 Thread Natanael Copa
Signed-off-by: Natanael Copa 
---
 templates/lxc-alpine.in | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
index 6f7c90d..7787e75 100644
--- a/templates/lxc-alpine.in
+++ b/templates/lxc-alpine.in
@@ -136,41 +136,41 @@ optarg_check() {
 default_path=@LXCPATH@
 
 while [ $# -gt 0 ]; do
-opt="$1"
-shift
-case "$opt" in
--h|--help)
+opt="$1"
+shift
+case "$opt" in
+-h|--help)
 usage
 exit 0
 ;;
--n|--name)
+-n|--name)
 optarg_check $opt "$1"
 name=$1
 shift
 ;;
--p|--path)
+-p|--path)
 optarg_check $opt "$1"
 path=$1
 shift
 ;;
---)
+--)
 break;;
---*=*)
-# split --myopt=foo=bar into --myopt foo=bar
-set -- ${opt%=*} ${opt#*=} "$@"
+--*=*)
+# split --myopt=foo=bar into --myopt foo=bar
+set -- ${opt%=*} ${opt#*=} "$@"
 ;;
--?)
+-?)
 usage_err "unknown option '$opt'"
 ;;
--*)
+-*)
 # split opts -abc into -a -b -c
 set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
 ;;
-*)
+*)
 usage
 exit 1
 ;;
-esac
+esac
 done
 
 
-- 
1.8.0.3


--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122412
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH 5/5] lxc-alpine: add support for installing optional packages

2012-12-31 Thread Natanael Copa
Let users append a list of packages they want install in the container

Signed-off-by: Natanael Copa 
---
 templates/lxc-alpine.in | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
index 5b685b1..b06215f 100644
--- a/templates/lxc-alpine.in
+++ b/templates/lxc-alpine.in
@@ -2,6 +2,7 @@
 
 install_alpine() {
 rootfs="$1"
+shift
 mkdir -p "$rootfs"/etc/apk || return 1
 cp -r ${keys_dir:-/etc/apk/keys} "$rootfs"/etc/apk/
 if [ -n "$repository" ]; then
@@ -13,7 +14,7 @@ install_alpine() {
 if [ -n "$apk_arch" ]; then
 opt_arch="--arch $apk_arch"
 fi
-${APK:-apk} add -U --initdb --root $rootfs $opt_arch alpine-base
+${APK:-apk} add -U --initdb --root $rootfs $opt_arch "$@" alpine-base
 }
 
 configure_alpine() {
@@ -128,7 +129,7 @@ die() {
 usage() {
 cat >&2 <] [-a|--arch ]
-   -p|--path  -n|--name 
+   -p|--path  -n|--name  [PKG...]
 EOF
 }
 
@@ -186,10 +187,6 @@ while [ $# -gt 0 ]; do
 # split opts -abc into -a -b -c
 set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
 ;;
-*)
-usage
-exit 1
-;;
 esac
 done
 
@@ -217,6 +214,6 @@ case "$arch" in
*)  die "unsupported architecture: $arch";;
 esac
 
-install_alpine "$rootfs" || die "Failed to install rootfs for $name"
+install_alpine "$rootfs" "$@" || die "Failed to install rootfs for $name"
 configure_alpine "$rootfs" "$name" || die "Failed to configure $name"
 copy_configuration "$path" "$rootfs" "$name"
-- 
1.8.0.3


--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122412
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH 4/5] lxc-alpine: add support for setting arch from command line

2012-12-31 Thread Natanael Copa
This allows us to lxc-create 32 bit guests on x86_64 hosts.

Signed-off-by: Natanael Copa 
---
 templates/lxc-alpine.in | 28 ++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
index 87886f5..5b685b1 100644
--- a/templates/lxc-alpine.in
+++ b/templates/lxc-alpine.in
@@ -9,7 +9,11 @@ install_alpine() {
 else
 cp /etc/apk/repositories "$rootfs"/etc/apk/repositories || return 1
 fi
-${APK:-apk} add -U --initdb --root $rootfs alpine-base
+opt_arch=
+if [ -n "$apk_arch" ]; then
+opt_arch="--arch $apk_arch"
+fi
+${APK:-apk} add -U --initdb --root $rootfs $opt_arch alpine-base
 }
 
 configure_alpine() {
@@ -68,6 +72,9 @@ copy_configuration() {
 
 grep -q "^lxc.rootfs" $path/config 2>/dev/null \
 || echo "lxc.rootfs = $rootfs" >> $path/config
+if [ -n "$lxc_arch" ]; then
+echo "lxc.arch = $lxc_arch" >> $path/config
+fi
 cat <> $path/config
 lxc.tty = 4
 lxc.pts = 1024
@@ -120,7 +127,7 @@ die() {
 
 usage() {
 cat >&2 <]
+Usage: $(basename $0) [-h|--help] [-r|--repository ] [-a|--arch ]
-p|--path  -n|--name 
 EOF
 }
@@ -161,6 +168,11 @@ while [ $# -gt 0 ]; do
 repository=$1
 shift
;;
+-a|--arch)
+optarg_check $opt "$1"
+arch=$1
+shift
+   ;;
 --)
 break;;
 --*=*)
@@ -193,6 +205,18 @@ if [ -z "$rootfs" ]; then
 rootfs="${path}/rootfs"
 fi
 
+lxc_arch=$arch
+apk_arch=$arch
+
+case "$arch" in
+   i[3-6]86)
+   apk_arch=x86;;
+   x86)
+   lxc_arch=i686;;
+   x86_64|"") ;;
+   *)  die "unsupported architecture: $arch";;
+esac
+
 install_alpine "$rootfs" || die "Failed to install rootfs for $name"
 configure_alpine "$rootfs" "$name" || die "Failed to configure $name"
 copy_configuration "$path" "$rootfs" "$name"
-- 
1.8.0.3


--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122412
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH 1/5] templates: install lxc-alpine

2012-12-31 Thread Natanael Copa
Make sure we actually install lxc-alpine

Signed-off-by: Natanael Copa 
---
 templates/Makefile.am | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/templates/Makefile.am b/templates/Makefile.am
index 9a94f32..be7e9f6 100644
--- a/templates/Makefile.am
+++ b/templates/Makefile.am
@@ -13,4 +13,5 @@ templates_SCRIPTS = \
lxc-altlinux \
lxc-busybox \
lxc-sshd \
-   lxc-archlinux
+   lxc-archlinux \
+   lxc-alpine
-- 
1.8.0.3


--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122412
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-ps: fix order of output and fix --lxc opt

2013-01-04 Thread Natanael Copa
We must output the lines from 'ps' in same order for tree views.

Fix also --lxc option to only show processes from containers.

Signed-off-by: Natanael Copa 
---

The logic was wrong. Sorry.

 src/lxc/lxc-ps.in | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/lxc/lxc-ps.in b/src/lxc/lxc-ps.in
index 25e843b..5f7cf4d 100644
--- a/src/lxc/lxc-ps.in
+++ b/src/lxc/lxc-ps.in
@@ -114,7 +114,8 @@ for container in ${containers}; do
 done
 
 # first file is stdin, the rest are the container tasks
-ps "$@" | awk -v container_field_width="$container_field_width" '
+ps "$@" | awk -v container_field_width="$container_field_width" \
+-v list_container_processes="$list_container_processes" '
 # first line is PS header
 NR == 1 {
 # find pid field index
@@ -133,7 +134,8 @@ NR == 1 {
 
 # store lines from ps with pid as index
 NR == FNR {
-ps[$pididx] = $0
+ps_line[NR] = $0
+pid_of_line[NR] = $pididx
 next
 }
 
@@ -151,8 +153,11 @@ FNR == 1 {
 
 END {
 printf("%-" container_field_width "s %s\n", "CONTAINER", header)
-for (pid in container_of_pid)
-printf("%-" container_field_width "s %s\n", container_of_pid[pid], 
ps[pid])
+for (i in ps_line) {
+   container = container_of_pid[pid_of_line[i]]
+if (list_container_processes == 0 || container != "")
+printf("%-" container_field_width "s %s\n", container, ps_line[i])
+}
 }
 
 ' - $tasks_files
-- 
1.8.0.3


--
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] lxc-shutdown: use posix shell instead of bash

2013-01-04 Thread Natanael Copa
On Wed, 02 Jan 2013 13:49:51 -0500
Stéphane Graber  wrote:
 
> Turns out that not all kill implementations allow "-s SIG", some
> instead required "-s ". As far as I can tell, all
> implementations support the latter, so I pushed a change to use that
> instead.

Sorry about that.

lxc-shutdown does not work with busybox init either because busybox
init uses different signals for poweroff and reboot. We could either
check if init is a symlink to busybox and automatically adjust the
signals or we could let user configure what signals to use for poweroff
and reboot - or we could do both.

What do you prefer?

-nc

--
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-shutdown: special handling for busybox init signals

2013-01-04 Thread Natanael Copa
busybox uses different signals for poweroff and reboot. Check if init
is a symlink to busybox and use the busybox variants, USR2 and TERM.

Signed-off-by: Natanael Copa 
---
I have only tested this busybox so please test before pusing it.

Thanks!

 src/lxc/lxc-shutdown.in | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/lxc/lxc-shutdown.in b/src/lxc/lxc-shutdown.in
index edf735e..1a1f455 100644
--- a/src/lxc/lxc-shutdown.in
+++ b/src/lxc/lxc-shutdown.in
@@ -117,11 +117,21 @@ if [ "$pid" = "-1" ]; then
 exit 1
 fi
 
+signal_reboot=INT
+signal_poweroff=PWR
+init_exe=$(readlink -f /proc/$pid/exe)
+case ${init_exe} in
+*/busybox)
+signal_reboot=TERM
+signal_poweroff=USR2
+   ;;
+esac
+
 if [ $reboot -eq 1 ]; then
-kill -s INT $pid
+kill -s $signal_reboot $pid
 exit 0
 else
-kill -s PWR $pid
+kill -s $signal_poweroff $pid
 fi
 
 if [ $dowait -eq 0 ]; then
-- 
1.8.0.3


--
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [Lxc-users] lxc-ps lxc-netstat not working

2013-01-07 Thread Natanael Copa
On Mon, 7 Jan 2013 09:33:30 -0600
Serge Hallyn  wrote:

> Quoting Shibashish (shi...@gmail.com):
> > I am on CentOS 6.3 and got lxc working on it. But when I run lxc-ps
> > or lxc-netstat, i get the following errors...
> > 
> > lxc-ps: no cgroup mount point found
> > lxc-netstat: no cgroup mount point found
> > 
> > 
> > Relevant lines in lxc-ps.in... (I tried bot the options)
> > 
> > # Get the filesystem mountpoint of the hierarchy
> > #mountpoint=$(grep -E "^cgroup [^ ]+ [^ ]+ ([^
> > ]+,)?$subsystems(,[^ ]+)? " /proc/self/mounts | cut -d ' ' -f 2)
> > mountpoint=$(grep -E "^[^ ]+ [^ ]+ cgroup ([^
> > ]+,)?$subsystems(,[^ ]+)? " /proc/self/mounts | cut -d ' ' -f 2)
> 
> Your problem here (in the second one) is the space before the ".  If
> you remove that you should get results.

I think the same problem happens with busybox.
 
> This appears to be what is in the upstream lxc (on sf.net).  The
> version in github staging (git://github.com/lxc/lxc.git #staging) is
> quite different, you may want to try building and running that.

Yes, I would expect the staging version work. If not, let me know and
I'll fix it.

Thanks!

-nc

--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122412
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH v2] add lua binding for the lxc API

2013-01-29 Thread Natanael Copa
Thanks you very much for working on those bindings!

I think the code is good enough for inclusion in git, even if I have
some comments.


On Thu, 24 Jan 2013 11:42:22 -0500
Dwight Engen  wrote:

> +# Lua module and scripts
> +if test x"$with_distro" = "xdebian" -o x"$with_distro" = "xubuntu" ; then
> +LUAPKGCONFIG=lua5.1
> +else
> +LUAPKGCONFIG=lua
> +fi

I think that we should use 'pkg-config --exists' instead of testing for given 
distros.

Something like:
if pkg-config --exists lua5.1; then
LUAPKGCONFIG=lua5.1
else
LUAPKGCONFIG=lua
fi

In case there might be other variants or if the binding supports both
lua-5.1 and lua-5.2:

for LUAPKGCONFIG in lua5.2 lua5.1 lua; do
if pkg-config --exists $LUAPKGCONFIG; then
break
fi
done

I think you can provide a list of modules to PKG_CHECK_MODULES:

PKG_CHECK_MODULES([LUA], [lua5.1 lua])


> +
> +AC_ARG_ENABLE([lua],
> + [AC_HELP_STRING([--enable-lua], [enable lua binding])],
> + [enable_lua=yes], [enable_lua=no])
> +
> +AM_CONDITIONAL([ENABLE_LUA], [test "x$enable_lua" = "xyes"])
> +
> +AM_COND_IF([ENABLE_LUA],
> + [PKG_CHECK_MODULES([LUA], [$LUAPKGCONFIG >= 5.1],[],[AC_MSG_ERROR([You 
> must install lua-devel for lua 5.1])])

I think this should work without using LUAPKGCONFIG
[PKG_CHECK_MODULE[LUA], [lua5.1 lua >= 5.1],[],[AC_MSG_ERROR([You must 
install lua-devel for lua 5.1])])



> --- /dev/null
> +++ b/src/lua-lxc/Makefile.am
> @@ -0,0 +1,26 @@
> +if ENABLE_LUA
> +
> +luadir=$(datadir)/lua/5.1
> +sodir=$(libdir)/lua/5.1/lxc

maybe use something like:

luadir=$(pkg-config --variable INSTALL_LMOD $(LUAPKGCONFIG))
sodir=$(pkg-config --variable INSTALL_CMOD $(LUAPKGCONFIG))/lxc

It depends on the LUAPKGCONFIG variable above...


> diff --git a/src/lua-lxc/lxc.lua b/src/lua-lxc/lxc.lua
> new file mode 100755
> index 000..c71de48
> --- /dev/null
> +++ b/src/lua-lxc/lxc.lua
...

> @@ -0,0 +1,412 @@
> +--
> +-- lua lxc module
> +--
> +-- Copyright © 2012 Oracle.
> +--
> +-- Authors:
> +-- Dwight Engen 
> +--
> +-- This library is free software; you can redistribute it and/or modify
> +-- it under the terms of the GNU General Public License version 2, as
> +-- published by the Free Software Foundation.
> +--
> +-- This program 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 General Public License for more details.
> +--
> +-- You should have received a copy of the GNU General Public License along
> +-- with this program; if not, write to the Free Software Foundation, Inc.,
> +-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> +--
> +
> +local core   = require("lxc.core")
> +local lfs= require("lfs")
> +local table  = require("table")
> +local string = require("string")
> +local io = require("io")
> +module("lxc", package.seeall)

I think module( ... , package.seeall) is not available in lua 5.2. I
know you focus on 5.1 for now but...

> +function string:split(delim, max_cols)
> +local cols = {}
> +local start = 1
> +local nextc
> +repeat
> + nextc = string.find(self, delim, start)
> + if (nextc and #cols ~= max_cols - 1) then
> + table.insert(cols, string.sub(self, start, nextc-1))
> + start = nextc + #delim
> + else
> + table.insert(cols, string.sub(self, start, string.len(self)))
> + nextc = nil
> + end
> +until nextc == nil or start > #self
> +return cols
> +end
> +
> +function dirname(path)
> +local f,output
> +f = io.popen("dirname " .. path)
> +output = f:read('*all')
> +f:close()
> +return output:sub(1,-2)
> +end
> +
> +function basename(path, suffix)
> +local f,output
> +f = io.popen("basename " .. path .. " " .. (suffix or ""))
> +output = f:read('*all')
> +f:close()
> +return output:sub(1,-2)
> +end

We must be able to do better than popen for dirname/basename.

What about using microlight? http://stevedonovan.github.com/microlight/

local ml = require('ml')

function dirname(path)
local dir, file = ml.splitpath(path)
return dir
end

function basename(path)
local dir, file = ml.splitpath(path)
return file
end

Microlight also ships a split() implementation.

-nc

--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH v2] add lua binding for the lxc API

2013-01-29 Thread Natanael Copa
On Tue, 29 Jan 2013 09:46:29 +0100
Natanael Copa  wrote:
> 
> I think that we should use 'pkg-config --exists' instead of testing for given 
> distros.
> 
> Something like:
> if pkg-config --exists lua5.1; then
> LUAPKGCONFIG=lua5.1
> else
> LUAPKGCONFIG=lua
> fi
> 
> In case there might be other variants or if the binding supports both
> lua-5.1 and lua-5.2:
> 
> for LUAPKGCONFIG in lua5.2 lua5.1 lua; do
> if pkg-config --exists $LUAPKGCONFIG; then
> break
> fi
> done
> 
> I think you can provide a list of modules to PKG_CHECK_MODULES:
> 
> PKG_CHECK_MODULES([LUA], [lua5.1 lua])

No that will fail if any of them are missing.

I think this will work:

PKG_CHECK_EXISTS([lua5.1], [LUAPKGCONFIG=lua5.1], [LUAPKGCONFIG=lua])

 
> 
> > +
> > +AC_ARG_ENABLE([lua],
> > +   [AC_HELP_STRING([--enable-lua], [enable lua binding])],
> > +   [enable_lua=yes], [enable_lua=no])
> > +
> > +AM_CONDITIONAL([ENABLE_LUA], [test "x$enable_lua" = "xyes"])
> > +
> > +AM_COND_IF([ENABLE_LUA],
> > +   [PKG_CHECK_MODULES([LUA], [$LUAPKGCONFIG >= 5.1],[],[AC_MSG_ERROR([You 
> > must install lua-devel for lua 5.1])])
> 
> I think this should work without using LUAPKGCONFIG
>   [PKG_CHECK_MODULE[LUA], [lua5.1 lua >= 5.1],[],[AC_MSG_ERROR([You must 
> install lua-devel for lua 5.1])])

No, I was wrong. It will not work.

-nc




--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH v2] add lua binding for the lxc API

2013-01-31 Thread Natanael Copa
On Tue, 29 Jan 2013 14:43:45 -0500
Dwight Engen  wrote:

> Hi Natanael, thanks for the review!
> 
> On Tue, 29 Jan 2013 09:46:29 +0100
> Natanael Copa  wrote:
> 
> [...]
> > > --- /dev/null
> > > +++ b/src/lua-lxc/Makefile.am
> > > @@ -0,0 +1,26 @@
> > > +if ENABLE_LUA
> > > +
> > > +luadir=$(datadir)/lua/5.1
> > > +sodir=$(libdir)/lua/5.1/lxc
> > 
> > maybe use something like:
> > 
> > luadir=$(pkg-config --variable INSTALL_LMOD $(LUAPKGCONFIG))
> > sodir=$(pkg-config --variable INSTALL_CMOD $(LUAPKGCONFIG))/lxc
> > 
> > It depends on the LUAPKGCONFIG variable above...
> 
> I didn't really like this either but I didn't know what else to do: I
> did look into the pkg-config variables available, and those variables
> are not set in lua.pc on Fedora or Oracle Linux.

That explains. The upstream lua.pc provides those. Fedora has its own
makefiles (using autotools) and they appear to replace the upstream
provided lua.pc.

http://pkgs.fedoraproject.org/cgit/lua.git/tree/lua-5.1.4-autotoolize.patch#n31983

> Do you know of another lua binding that may give a good example of how
> this should be determined?

Not really. It does seam to provide the variable V which should return
'5.1'.

> [...]
> > > +local core   = require("lxc.core")
> > > +local lfs= require("lfs")
> > > +local table  = require("table")
> > > +local string = require("string")
> > > +local io = require("io")
> > > +module("lxc", package.seeall)
> > 
> > I think module( ... , package.seeall) is not available in lua 5.2. I
> > know you focus on 5.1 for now but...
> 
> I originally didn't have the seeall, but I grew weary of putting io.,
> string., and table. in front of so many things as it cluttered the
> code. I did not do anything with 5.2, so if we need to get rid of
> seeall for that, it shouldn't be hard to do.

We can do that later on yes.
 
> > > +function string:split(delim, max_cols)
> > > +local cols = {}
> > > +local start = 1
> > > +local nextc
> > > +repeat
> > > + nextc = string.find(self, delim, start)
> > > + if (nextc and #cols ~= max_cols - 1) then
> > > + table.insert(cols, string.sub(self, start, nextc-1))
> > > + start = nextc + #delim
> > > + else
> > > + table.insert(cols, string.sub(self, start,
> > > string.len(self)))
> > > + nextc = nil
> > > + end
> > > +until nextc == nil or start > #self
> > > +return cols
> > > +end
> > > +
> > > +function dirname(path)
> > > +local f,output
> > > +f = io.popen("dirname " .. path)
> > > +output = f:read('*all')
> > > +f:close()
> > > +return output:sub(1,-2)
> > > +end
> > > +
> > > +function basename(path, suffix)
> > > +local f,output
> > > +f = io.popen("basename " .. path .. " " .. (suffix or ""))
> > > +output = f:read('*all')
> > > +f:close()
> > > +return output:sub(1,-2)
> > > +end
> > 
> > We must be able to do better than popen for dirname/basename.
> > 
> > What about using microlight?
> > http://stevedonovan.github.com/microlight/
> > 
> > local ml = require('ml')
> 
> I was trying to avoid use of modules that are not part of standard
> distributions. As far as I can tell neither microlight nor penlight
> are packaged. I did try a few string recipes that I found, but they did
> not work with all inputs. dirname is only called once to find the path
> to the cgroup mount, so I didn't worry about the performance. 

Makes sense.

> I suppose we could just bring splitpath over (license allowing).

Its a MIT license so it should be ok.

https://github.com/stevedonovan/Microlight/blob/master/ml.lua#L119

Seems like you never use basename so we could make a string editing
dirname only. It is only used for /proc/mounts so we can assume no
relative paths (eg ./somedir), no trailing slashes (eg boot/) and no
multiple slashes (eg /usrbin). But we can expect a single '/'.

I think this should work for our case. Note that you get the trailing
'/' in there but it should not hurt us.

function dirname(abspath)
local i = #abspath
local ch = abspath:sub(i,i)
while i > 0 and ch ~= '/' do
i = i - 1
ch = abspath:sub(i,i)
end
return abspath:sub(1,i)
end

In any case, I think the patch could be applied as is and I could post
improvement patches later.

Thanks!

-nc

--
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-alpine: autodetect standard bridges and set hwaddress

2013-02-13 Thread Natanael Copa
Check for lxcbr0, virbr0 and br0 and use one of those if they exist.

Set mac address if network type is veth.

Signed-off-by: Natanael Copa 
---
 templates/lxc-alpine.in | 38 +-
 1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
index b06215f..962d274 100644
--- a/templates/lxc-alpine.in
+++ b/templates/lxc-alpine.in
@@ -76,7 +76,36 @@ copy_configuration() {
 if [ -n "$lxc_arch" ]; then
 echo "lxc.arch = $lxc_arch" >> $path/config
 fi
+
+lxc_network_link_line="# lxc.network.link = br0"
+for br in lxcbr0 virbr0 br0; do
+if [ -d /sys/class/net/$br/bridge ]; then
+lxc_network_link_line="lxc.network.link = $br"
+break
+fi
+done
+
+if ! grep -q "^lxc.network.type" $path/config 2>/dev/null; then
+cat <> $path/config
+lxc.network.type = veth
+$lxc_network_link_line
+lxc.network.flags = up
+EOF
+fi
+
+# if there is exactly one veth network entry, make sure it has an
+# associated mac address.
+nics=$(grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l)
+if [ "$nics" -eq 1 ] && ! grep -q "^lxc.network.hwaddr" $path/config; then
+# see 
http://sourceforge.net/tracker/?func=detail&aid=3411497&group_id=163076&atid=826303
+hwaddr="fe:$(dd if=/dev/urandom bs=8 count=1 2>/dev/null |od -t x8 | \
+  head -1 |awk '{print $2}' | cut -c1-10 |\
+  sed 's/\(..\)/\1:/g; s/.$//')"
+echo "lxc.network.hwaddr = $hwaddr" >> $path/config
+fi
+
 cat <> $path/config
+
 lxc.tty = 4
 lxc.pts = 1024
 lxc.utsname = $hostname
@@ -84,15 +113,6 @@ lxc.utsname = $hostname
 # When using LXC with apparmor, uncomment the next line to run unconfined:
 #lxc.aa_profile = unconfined
 
-# network interface
-lxc.network.name = eth0
-lxc.network.type = veth
-lxc.network.flags = up
-# enable for bridging
-#lxc.network.link = br0
-#lxc.network.ipv4 = n.n.n.n
-#lxc.network.ipv4.gateway = auto
-
 # devices
 lxc.cgroup.devices.deny = a
 # /dev/null and zero
-- 
1.8.1.2


--
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] Link against pthread when not on bionic.

2013-02-19 Thread Natanael Copa
On Mon, 18 Feb 2013 21:40:42 +0100
Daniel Lezcano  wrote:

> On 02/18/2013 06:23 PM, Stéphane Graber wrote:
> > dpkg spotted that we're not explicitly linking against pthread even though
> > we use some of its symbols (sem_*).
> 
> uh ? wait.
> 
> We shouldn't link against the lib pthread.
> 
> I don't think sem_* is a symbol coming from the pthread library.

Seems to be with uClibc:

ncopa-desktop:~$ nm -D /lib/libpthread.so.0.9.32 | grep sem_
d168 T __new_sem_destroy
a914 T __new_sem_getvalue
a414 T __new_sem_init
c219 T sem_close
d168 W sem_destroy
a914 W sem_getvalue
a414 W sem_init
c744 T sem_open
6db0 T sem_post
6e00 T sem_timedwait
6f80 T sem_trywait
95c8 T sem_unlink
6fb0 T sem_wait

How about let autoconf detect what to link against?

@@ -274,6 +274,9 @@ AC_CHECK_HEADERS([sys/signalfd.h pty.h sys/capability.h sys/
 # Check for some syscalls functions
 AC_CHECK_FUNCS([setns pivot_root sethostname unshare])
 
+# find library for sem_*
+AC_SEARCH_LIBS(sem_open, [pthread rt])
+
 # Check for some functions
 AC_CHECK_LIB(util, openpty)
 AC_CHECK_FUNCS([openpty hasmntopt setmntent endmntent])




--
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] Link against pthread when not on bionic.

2013-02-19 Thread Natanael Copa
On Mon, 18 Feb 2013 12:23:24 -0500
Stéphane Graber  wrote:

> dpkg spotted that we're not explicitly linking against pthread even though
> we use some of its symbols (sem_*).
> 
> Signed-off-by: Stéphane Graber 
> ---
>  src/lxc/Makefile.am | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
> index 8974ca9..a0077aa 100644
> --- a/src/lxc/Makefile.am
> +++ b/src/lxc/Makefile.am
> @@ -115,7 +115,7 @@ liblxc_so_LDFLAGS = \
>  liblxc_so_LDADD = $(CAP_LIBS) $(APPARMOR_LIBS) $(SECCOMP_LIBS)
>  
>  if !IS_BIONIC
> -liblxc_so_LDADD += -lutil -lrt
> +liblxc_so_LDADD += -lutil -lrt -lpthread
>  endif
>  
>  bin_SCRIPTS = \

I don't like conditions based on system. It is normally better let the
configure script test different common variants and pick what works, eg
use AC_SEARCH_LIBS.

-nc

--
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] configure: replace deprecated AM_CONFIG_HEADER

2013-02-19 Thread Natanael Copa
Replace deprecated AM_CONFIG_HEADER with AC_CONFIG_HEADER.

This is needed for automake-1.13.

Signed-off-by: Natanael Copa 
---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 931e0d6..c5c71e4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5,7 +5,7 @@ AC_INIT([lxc], [0.9.0.alpha3])
 
 AC_CONFIG_SRCDIR([configure.ac])
 AC_CONFIG_AUX_DIR([config])
-AM_CONFIG_HEADER([src/config.h])
+AC_CONFIG_HEADER([src/config.h])
 AM_INIT_AUTOMAKE([-Wall -Werror -Wno-portability])
 AC_CANONICAL_HOST
 AM_PROG_CC_C_O
-- 
1.8.1.3


--
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] lxc-alpine: download statically compiled package manager if not available on host

2013-05-14 Thread Natanael Copa
On Tue, 14 May 2013 19:27:32 +0300
Kaarle Ritvanen  wrote:

> Signed-off-by: Kaarle Ritvanen 

I have looked over it and tested it on Alpine Linux.

It should make it very simple to test an Alpine Linux container on any
x86/x86_64 GNU Linux.

Acked-by: Natanael Copa 


> ---
>  templates/lxc-alpine.in | 30 +++---
>  1 file changed, 27 insertions(+), 3 deletions(-)
> 
> diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
> index 98347ed..528ebca 100644
> --- a/templates/lxc-alpine.in
> +++ b/templates/lxc-alpine.in
> @@ -1,6 +1,9 @@
>  #!/bin/sh
>  
>  install_alpine() {
> +apk=${APK:-apk}
> +apk_opts=
> +
>  rootfs="$1"
>  shift
>  mkdir -p "$rootfs"/etc/apk || return 1
> @@ -10,11 +13,32 @@ install_alpine() {
>  else
>  cp /etc/apk/repositories "$rootfs"/etc/apk/repositories || return 1
>  fi
> -opt_arch=
> +
>  if [ -n "$apk_arch" ]; then
> -opt_arch="--arch $apk_arch"
> +apk_opts="--arch $apk_arch"
>  fi
> -${APK:-apk} add -U --initdb --root $rootfs $opt_arch "$@" alpine-base
> +
> +if ! which $apk &> /dev/null; then
> +wget="wget -O - $repository/x86"
> +
> +apk_version=$($wget/APKINDEX.tar.gz | \
> +tar -Oxz APKINDEX | \
> +sed 's/^$//;Ta;x;
> + s/^\(.*\n\)P:apk-tools-static\(\n.*\)$/\1\2/;Tb;
> + s/^\(.*\n\)V:\([^\n]\+\)\(\n.*\)$/\2/;t;
> + :a;H;:b;d')
> +[ "$apk_version" ] || return 1
> +
> +apk=$(mktemp /tmp/apk.static.XX)
> +trap "rm -f $apk" EXIT
> +$wget/apk-tools-static-$apk_version.apk | \
> +tar -Oxz sbin/apk.static > $apk || return 1
> +chmod u+x $apk
> +
> +apk_opts="$apk_opts --allow-untrusted"
> +fi
> +
> +$apk add -U --initdb --root $rootfs $apk_opts "$@" alpine-base
>  }
>  
>  configure_alpine() {


--
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] lxc-alpine: download statically compiled package manager if not available on host

2013-05-16 Thread Natanael Copa
On Wed, 15 May 2013 13:10:06 -0500
Serge Hallyn  wrote:

> Quoting Kaarle Ritvanen (kaarle.ritva...@datakunkku.fi):
> ...
> > +wget="wget -O - $repository/x86"
> ..
> > +$wget/apk-tools-static-$apk_version.apk | \
> > +tar -Oxz sbin/apk.static > $apk || return 1
> > +chmod u+x $apk
> > +
> > +apk_opts="$apk_opts --allow-untrusted"
> > +fi
> > +
> > +$apk add -U --initdb --root $rootfs $apk_opts "$@" alpine-base
> 
> Boy does that scare me though.

We could inline the public key(s) in the script so we could remove the
'--allow-intrusted' above. But verifying the sig for the static binary
might be tricky without having apk-tools installed already.

I suppose you could always ask your distro to ship a proper
apk-tools.deb/rpm.

Or maybe throw an error:

Error: no apk binary was found. You can automatically download a static
apk with: --allow-untrusted-static-apk

Then you'll not by mistake download and execute an untrusted static
binary.


-nc

--
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] lxc-alpine: download statically compiled package manager if not available on host

2013-05-18 Thread Natanael Copa
On Fri, 17 May 2013 09:24:51 -0500
Serge Hallyn  wrote:

> Quoting Kaarle Ritvanen (kaarle.ritva...@datakunkku.fi):
> > On Thu, 16 May 2013, Natanael Copa wrote:
> > 
> > >On Wed, 15 May 2013 13:10:06 -0500
> > >Serge Hallyn  wrote:
> > >
> > >>Quoting Kaarle Ritvanen (kaarle.ritva...@datakunkku.fi):
> > >>...
> > >>>+wget="wget -O - $repository/x86"
> > >>..
> > >>>+$wget/apk-tools-static-$apk_version.apk | \
> > >>>+tar -Oxz sbin/apk.static > $apk || return 1
> > >>>+chmod u+x $apk
> > >>>+
> > >>>+apk_opts="$apk_opts --allow-untrusted"
> > >>>+fi
> > >>>+
> > >>>+$apk add -U --initdb --root $rootfs $apk_opts "$@"

> It's the 'wget $url | /bin/sh' that, not the apk --allow-untrusted,
> that really bothers me.

He is not really piping anything directly to shell. He is piping it to
tar, which will extract a sbin/apk.static (a temp static package
manager binary in case its missing in first place).

It *is* scary that the binary is not checked against anyting, no https
certificate, no pgp signature, no nothing.

> I do see that for instance feeding a
> tar file with malicious /bin/passwd, which templates later run
> under a regular chroot, could be just as easy...

I don't really understand what you mean with this...

If you download and extract a tarball into a dir you intend to chroot
into, then you could always overwrite the etc/passwd before chroot? The
passwd is no problem. The binaries you run in there are.

> Note I haven't nacked this.  I was wondering what others think.

I wouldn't blame anyone for nacking it and I think we (Alpine Linux) can
do better.

> > execute some installed stuff, albeit this is done in chroot.
> > 
> > Would the template be less scary if it ran the statically linked apk
> > in chroot? This would add some complexity, as the template would
> > need to install at least static busybox and resolv.conf to the
> > container root prior to invoking apk.
> 
> Yes it would make me feel a bit better.

As I said, running as root in a chroot offers basically no protection.

> What would really make me
> feel better is if we could run any downloaded code under a different
> MAC (selinux or apparmor) profile.  This might require two- or
> three-stage templates.  Currently most templates first do a
> download_image() (into the cache), then configure_image().

and the code needs to check if you have selinux and if not fall back to
apparmor. The patch is on here for convenience so it "just works"
on distros who don't ship an apk-tools package. apparmor/selinux would
be too much cost/work compared to benefit in my opinion.

> The templates would be called with all the usual args, plus a new
> --{first,second.third}-stage argument.  first-stage runs
> unprotected and only downloads things into cache.

Well, one of the fundamental ideas with apk-tools package manager is
to download and extract in one shot and do the cryptographic
verification on the fly (while waiting for http io). When other package
managers are done downloading and can start verify the pgp signature,
apk-tools is already done.

I looked at the ubuntu and debian templates and I find the caching
feature pretty cleaver. I didn't bother implement it for Alpine Linux
though because the minimal rootfs is only 6MB (which is 2% of the
'debian' size) You could in other words install 50 Alpine containers
while setting up the first debian cache...

>  second-stage
> runs without ability to mount etc (but with CAP_MKNOD), and only
> lays the rootfs down.  third stage does additional setup (like
> setting password) and runs in the regular container MAC
> context/profile and with cgroups and dropped capabilities, i.e. fully
> protected.
> 
> (I'm not asking you to do this)
> 
> What do others think?  Stéphane?  Dwight?
> 
> If we agree on this route, then I would take the lxc-alpine patch
> as is for now.

Kaarle, I have an idea that should be doable without too much effort.

When building the apk.static we also create a signature using the
private keys found on the build box, we ship it within the
apk-tools-static package (as sbin/apk-tools.static.RSA or
similar) The official build servers would have the official build
key(s) and we can embed the official public key(s) in the template.
They don't change that often.


The template script would look something like:
  
  wget="wget -O - $repository/x86"
  ...
  $wget/apk-tools-static-$apk_version.apk | \
tar -C $tmpdir -z sbin/apk.static sbin/apk.static.RSA* \
|| return 1

  # use openssl to

Re: [lxc-devel] [PATCH] lxc-alpine: download statically compiled package manager if not available on host

2013-05-18 Thread Natanael Copa
On Fri, 17 May 2013 11:32:34 -0500
Serge Hallyn  wrote:
 
> I'm not quite ready to send it (and have been derailed with wanting to
> finish api conversion of a few commands, and other stuff next week),
> but I do have a working patch introducing 'lxc-ubuntu-cloud-user'
> template, which allows an unprivileged user to create a container,
> and will run everything (except the tiny program which maps uids)
> without root.
> 
> lxc-alpine looks like it will be another good candidate for this (as
> is lxc-cirros).  Basically anything which untars.  rsync is harder
> (hard enough that we may never support it) and debootstrap
> impossible...

I'd rather aim for not running any binary that has not been
cryptographically verified, at least for Alpine Linux.

-nc

--
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] lxc-alpine: download statically compiled package manager if not available on host

2013-05-18 Thread Natanael Copa
On Fri, 17 May 2013 12:04:01 -0400
"Michael H. Warfield"  wrote:

> On Fri, 2013-05-17 at 09:24 -0500, Serge Hallyn wrote:
> > Quoting Kaarle Ritvanen (kaarle.ritva...@datakunkku.fi):
> > > On Thu, 16 May 2013, Natanael Copa wrote:
> > > 
> > > >On Wed, 15 May 2013 13:10:06 -0500
> > > >Serge Hallyn  wrote:
> > > >
> > > >>Quoting Kaarle Ritvanen (kaarle.ritva...@datakunkku.fi):
> > > >>...
> > > >>>+wget="wget -O - $repository/x86"
> > > >>..
> > > >>>+$wget/apk-tools-static-$apk_version.apk | \
> > > >>>+tar -Oxz sbin/apk.static > $apk || return 1
> > > >>>+chmod u+x $apk

...

> > > >>>+$apk add -U --initdb --root $rootfs $apk_opts "$@"

...
 
> > It's the 'wget $url | /bin/sh' that, not the apk --allow-untrusted,
> > that really bothers me.

...

> As a security researcher (my day job), I have to say, now that you
> specifically pointed it out, that makes the hair on the back of my
> neck stand up.  Even if we only allow a well controlled URL we're
> requesting, the thought of blindly piping the data returned into a
> shell scares the crap out of me,

He pipes it to tar, not to a shell.

> especially since this would presumably be running as root.

Running unverified static binaries as root is scary yes.

> If there was some way to download it
> to a file and verify its contents (md5, sha1, sha256 or -preferably-
> PGP signature) BEFORE sending it into a shell, that would make me
> feel a lot more comfortable.

There is a checksum stored in the APKINDEX.tar.gz (md5 iirc) so it is
fully possible and pretty simple to implement checking the static
binary.

I don't think it provide much value though, because both the APKINDEX
and the tarball containing the static binary comes from the same http
server so it would not protect against bad binaries on a DNS hijack for
example. (the attacker could just store the checksum for his evil static
binary).


-nc


signature.asc
Description: PGP signature
--
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] lxc-alpine: download statically compiled package manager if not available on host

2013-05-19 Thread Natanael Copa
On Sat, 18 May 2013 18:14:36 -0500
Serge Hallyn  wrote:
 
> > > I do see that for instance feeding a
> > > tar file with malicious /bin/passwd, which templates later run
> > > under a regular chroot, could be just as easy...
> > 
> > I don't really understand what you mean with this...
> 
> In the ubuntu-cloud template we wget a tarball which is the rootfs for
> the container, extract it, then chroot into it and run /bin/passwd to

ah. I misread "/bin/passwd" as "/etc/passwd". Get it now, sorry.

It shows that Kaarles' patch is practically not making anything that is
worse than what other templates already do.

> So long as you mean embed the pub keys into the lxc template, that
> would be great.
> 
> And I think I'll pursue the same for ubuntu-cloud and cirros
> templates.
> 
> > --allow-untrusted in the same shot and you will at no point run
> > anything that has not been cryptographically verified.
> 
> Sounds great - thanks.

Will look at it.

Thanks for the feedback!

-nc

--
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] Container autostart proposal

2013-05-28 Thread Natanael Copa
On Mon, 27 May 2013 15:07:03 -0400
Stéphane Graber  wrote:

> Hello,
> 
> One feature that distros have been hacking together on their side for a
> while is container autostart.
...

> So I therefore have two proposals on how to implement this, let me know
> what you prefer:
> 1)
>  - Keep things as they are in Ubuntu and make that the official way of
> auto-starting containers. Documentating /etc/lxc/auto as the location in
> which people need to place their symlinks.
>  - Update our tools to properly list and destroy those auto-started
> containers.
>  - Extend lxc-start and lxc-stop to allow starting all auto containers
> and stopping all known containers (-a flag would be my suggestion).

The nice thing with this is that it is simple and stupid.
 
> 2)
>  - Quite a bit more complex but more flexible.
>  - Introduce a new lxc.autostart system config option (lxc.conf).
>This is a boolean turning autostart on/off on a system level.
>  - Introduce a few more container options:
>+ lxc.start.auto => boolean
...
> start the first one, wait up to lxc.start.time for it to be RUNNING,
> then start the next one, etc...
>  - The defaults would be lxc.start.auto=false, lxc.start.priority=0,
> lxc.start.time=0.
>  - It'd be assumed that only containers in lxc.lxcpath can be autostarted.
>  - This design would also work for unprivileged containers where
> lxc.lxcpath points to the user's home directory, in such case, the
> distros will need to have something call "lxc-start -a" on session open
> and "lxc-stop -a" on session close (or whenever they want).
> 
> 
> While 1) is clearly a lot less pain and much easier for the distros
> already supporting autostart to migrate to, I think there's a pretty big
> benefit in getting 2) as it's more flexible, allows for delayed start
> and supports unprivileged containers.
> 
> Thoughts?

It would be nice to have the concept of groups. Like

 lxc.start.group = default

Then we have an 'lxc-start -a [group]' where you can start all
containers in group 'default' in one shot.

Then I think it would be nice if the init system could take care of
dependency handling and start up delays. Dealing with states,
dependencies and parallel startup can be complicated (think circular
deps, deadlocks etc) and the init system already does all that.

What would be nice though, is some convenient way to fish out the
config options. Like, get me a list of all containers that are in group
'foo'. Get me the value for config option 'lxc.start.wait' for
container 'bar'. (looks like there is a get_config_item for this)

-nc


signature.asc
Description: PGP signature
--
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH v2] lxc-alpine: download a static package manager if its missing

2013-05-28 Thread Natanael Copa
If the package manager, apk-tools is missing, then:
 - download a static binary and public keys
 - verify the keys against embedded checksum
 - verify the signature of the static binary against the downloaded keys
 - use the verified static binary

Signed-off-by: Natanael Copa 
Signed-off-by: Kaarle Ritvanen 
---
Changes since v1:
 - verify signature of static binary

 templates/lxc-alpine.in | 56 +++--
 1 file changed, 54 insertions(+), 2 deletions(-)

diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
index 6180afd..cdf2743 100644
--- a/templates/lxc-alpine.in
+++ b/templates/lxc-alpine.in
@@ -1,10 +1,56 @@
 #!/bin/sh
 
+key_sha256sums="9c102bcc376af1498d549b77bdbfa815ae86faa1d2d82f040e616b18ef2df2d4
  alpine-de...@lists.alpinelinux.org-4a6a0840.rsa.pub
+2adcf7ce224f476330b5360ca5edb92fd0bf91c92d83292ed028d7c4e26333ab  
alpine-de...@lists.alpinelinux.org-4d07755e.rsa.pub"
+
+get_static_apk () {
+rootfs="$1"
+echo "Using static apk from $repository/$apk_arch"
+wget="wget -q -O - $repository/$apk_arch"
+
+# parse APKINDEX to find the current versions
+static_pkgs=$($wget/APKINDEX.tar.gz | \
+tar -Oxz APKINDEX | \
+awk -F: -v pkglist="alpine-keys:apk-tools-static" '
+BEGIN { split(pkglist,pkg) }
+$0 != "" { f[$1] = $2 }
+$0 == "" { for (i in pkg)
+   if (pkg[i] == f["P"])
+   print(f["P"] "-" f["V"] ".apk") }')
+[ "$static_pkgs" ] || return 1
+
+mkdir -p "$rootfs" || return 1
+for pkg in $static_pkgs; do
+echo "Downloading $pkg"
+$wget/$pkg | tar -xz -C "$rootfs"
+done
+
+# clean up .apk meta files
+rm -f "$rootfs"/.[A-Z]*
+
+# verify checksum of the key
+keyname=$(echo $rootfs/sbin/apk.static.*.pub | sed 's/.*\.SIGN\.RSA\.//')
+checksum=$(echo "$key_sha256sums" |  grep -w "$keyname")
+if [ -z "$checksum" ]; then
+echo "ERROR: checksum is missing for $keyname"
+return 1
+fi
+(cd $rootfs/etc/apk/keys && echo "$checksum" | sha256sum -c -) || return 1
+
+# verify the static apk binary signature
+APK=$rootfs/sbin/apk.static
+openssl dgst -verify $rootfs/etc/apk/keys/$keyname \
+-signature "$APK.SIGN.RSA.$keyname" "$APK" || return 1
+}
+
 install_alpine() {
 rootfs="$1"
 shift
 mkdir -p "$rootfs"/etc/apk || return 1
-cp -r ${keys_dir:-/etc/apk/keys} "$rootfs"/etc/apk/
+: ${keys_dir:=/etc/apk/keys}
+if ! [ -d "$rootfs"/etc/apk/keys ] && [ -d "$keys_dir" ]; then
+cp -r "$keys_dir" "$rootfs"/etc/apk/keys
+fi
 if [ -n "$repository" ]; then
 echo "$repository" > "$rootfs"/etc/apk/repositories
 else
@@ -14,7 +60,7 @@ install_alpine() {
 if [ -n "$apk_arch" ]; then
 opt_arch="--arch $apk_arch"
 fi
-${APK:-apk} add -U --initdb --root $rootfs $opt_arch "$@" alpine-base
+$APK add -U --initdb --root $rootfs $opt_arch "$@" alpine-base
 }
 
 configure_alpine() {
@@ -167,6 +213,7 @@ optarg_check() {
 }
 
 default_path=@LXCPATH@
+arch=$(uname -m)
 
 while [ $# -gt 0 ]; do
 opt="$1"
@@ -243,6 +290,11 @@ case "$arch" in
*)  die "unsupported architecture: $arch";;
 esac
 
+: ${APK:=apk}
+if ! which $APK >/dev/null; then
+get_static_apk "$rootfs" || die "Failed to download a valid static apk"
+fi
+
 install_alpine "$rootfs" "$@" || die "Failed to install rootfs for $name"
 configure_alpine "$rootfs" "$name" || die "Failed to configure $name"
 copy_configuration "$path" "$rootfs" "$name"
-- 
1.8.3


--
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH v2] lxc-alpine: download a static package manager if its missing

2013-06-03 Thread Natanael Copa
On Wed, 29 May 2013 15:03:50 -0500
Serge Hallyn  wrote:

> Quoting Natanael Copa (nc...@alpinelinux.org):
> > If the package manager, apk-tools is missing, then:
> >  - download a static binary and public keys
> >  - verify the keys against embedded checksum
> >  - verify the signature of the static binary against the downloaded keys
> >  - use the verified static binary
> > 
> > Signed-off-by: Natanael Copa 
> > Signed-off-by: Kaarle Ritvanen 
> > ---
> > Changes since v1:
> >  - verify signature of static binary
> 
> Hi,
> 
> this looks good, but is there a default repository we should
> code in?

Sounds good, but I would prefer do that in a separate commit.

-nc

--
Get 100% visibility into Java/.NET code with AppDynamics Lite
It's a free troubleshooting tool designed for production
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap2
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] Container autostart proposal V2

2013-06-03 Thread Natanael Copa
On Tue, 28 May 2013 17:36:09 -0400
Dwight Engen  wrote:

> On Tue, 28 May 2013 17:03:43 -0400
> Stéphane Graber  wrote:
...
> > The command line parameter (-g) is comma separate however. So commas
> > should be documented as invalid for a group name and so is "any" which
> > is a special group matching all containers.
> 
> Hmm, that just made me think of the fact that lxc-monitor takes a
> regex, should we be consistent about how to specify multiple
> containers/groups?

I would prefer fnmatch over both regex and a magic 'any' keyword.

  lxc-stop -g '*'
  lxc-start -g 'foo.*'

I fully agree on the point about being consistant though.

-nc

--
Get 100% visibility into Java/.NET code with AppDynamics Lite
It's a free troubleshooting tool designed for production
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap2
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH v2] lxc-alpine: download a static package manager if its missing

2013-06-03 Thread Natanael Copa
On Mon, 3 Jun 2013 08:57:11 -0500
Serge Hallyn  wrote:

> Quoting Natanael Copa (nc...@alpinelinux.org):
> > On Wed, 29 May 2013 15:03:50 -0500
> > Serge Hallyn  wrote:
> > 
> > > Quoting Natanael Copa (nc...@alpinelinux.org):
> > > > If the package manager, apk-tools is missing, then:
> > > >  - download a static binary and public keys
> > > >  - verify the keys against embedded checksum
> > > >  - verify the signature of the static binary against the downloaded keys
> > > >  - use the verified static binary
> > > > 
> > > > Signed-off-by: Natanael Copa 
> > > > Signed-off-by: Kaarle Ritvanen 
> > > > ---
> > > > Changes since v1:
> > > >  - verify signature of static binary
> > > 
> > > Hi,
> > > 
> > > this looks good, but is there a default repository we should
> > > code in?
> > 
> > Sounds good, but I would prefer do that in a separate commit.
> 
> That's fine, but could you tell me a repo I can use for a quick
> test?

http://nl.alpinelinux.org/alpine/edge/main

-nc

--
Get 100% visibility into Java/.NET code with AppDynamics Lite
It's a free troubleshooting tool designed for production
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap2
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-init: continue even if we fail to mount /dev/mqueue

2013-06-12 Thread Natanael Copa
The 'lxc-init' (a lightweight init process used by lxc-execute in place
of upstart etc) tries to mount /dev/mqueue during startup. If that fails
(for instance due to missing support for mqueue in kernel) then it
aborts execution and returns -1. This is unreasonable as very few
applications actually need /dev/mqueue.

This similar to what we do with /dev/shm.

Signed-off-by: Natanael Copa 
---
 src/lxc/utils.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index 6c0f9d0..136f943 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -148,8 +148,9 @@ extern int lxc_setup_fs(void)
return 0;
}
 
+   /* continue even without posix message queue support */
if (mount_fs("mqueue", "/dev/mqueue", "mqueue"))
-   return -1;
+   INFO("failed to mount /dev/mqueue");
 
return 0;
 }
-- 
1.8.3.1


--
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH 1/2] lxc-alpine: automatic repository selection

2013-06-26 Thread Natanael Copa
On Wed, 26 Jun 2013 11:14:59 +0300
Kaarle Ritvanen  wrote:

> pick random server from mirror list
> use the latest stable release
> 
> Signed-off-by: Kaarle Ritvanen 
> ---
>  templates/lxc-alpine.in | 31 +--
>  1 file changed, 29 insertions(+), 2 deletions(-)

ack

-nc

--
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH 2/2] lxc-alpine: option for specifying the release to be installed

2013-06-26 Thread Natanael Copa
On Wed, 26 Jun 2013 11:15:00 +0300
Kaarle Ritvanen  wrote:

> Signed-off-by: Kaarle Ritvanen 
> ---
>  templates/lxc-alpine.in | 23 ---
>  1 file changed, 16 insertions(+), 7 deletions(-)

I tested with '--release v2.6' and '--relase edge'.

It only work when apk is not found.

I think it can be applied as is and I can try make it work on alpine
linux (which has apk).


-nc

--
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-alpine: make --release work when apk exists

2013-06-28 Thread Natanael Copa
Use sed to set the specified alpine release in the copied
/etc/apk/repositories

Signed-off-by: Natanael Copa 
---
 templates/lxc-alpine.in | 4 
 1 file changed, 4 insertions(+)

diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
index 410c817..be2a535 100644
--- a/templates/lxc-alpine.in
+++ b/templates/lxc-alpine.in
@@ -84,6 +84,10 @@ install_alpine() {
 echo "$repository" > "$rootfs"/etc/apk/repositories
 else
 cp /etc/apk/repositories "$rootfs"/etc/apk/repositories || return 1
+if [ -n "$release" ]; then
+sed -i -e "s:/[^/]\+/\([^/]\+\)$:/$release/\1:" \
+"$rootfs"/etc/apk/repositories
+fi
 fi
 opt_arch=
 if [ -n "$apk_arch" ]; then
-- 
1.8.3.1


--
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-alpine: create /dev/zero

2013-08-26 Thread Natanael Copa
Signed-off-by: Natanael Copa 
---
 templates/lxc-alpine.in | 1 +
 1 file changed, 1 insertion(+)

diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
index ce7226f..2ab10bb 100644
--- a/templates/lxc-alpine.in
+++ b/templates/lxc-alpine.in
@@ -126,6 +126,7 @@ EOF
 echo "Setting up device nodes"
 mkdir -p -m 755 "$rootfs/dev/pts"
 mkdir -p -m 1777 "$rootfs/dev/shm"
+mknod -m 666 "$rootfs/dev/zero" c 1 5
 mknod -m 666 "$rootfs/dev/full" c 1 7
 mknod -m 666 "$rootfs/dev/random" c 1 8
 mknod -m 666 "$rootfs/dev/urandom" c 1 9
-- 
1.8.3.4


--
Introducing Performance Central, a new site from SourceForge and 
AppDynamics. Performance Central is your source for news, insights, 
analysis and resources for efficient Application Performance Management. 
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [Lxc-users] Working LXC templates?

2013-09-04 Thread Natanael Copa
On Wed, 04 Sep 2013 09:40:49 -0400
"Michael H. Warfield"  wrote:
 
> I do think it is an issue with the whole "distribution agnostic
> template" problem that may require some help from the distros or some
> innovative ideas of how we can bootstrap distros using distro agnostic
> tools (like stone knives and bear skins style install of the rootfs
> using nothing more than tar, gzip, gpg, and curl or wget).

This would be very nice. I have not had success with any templates
except the debian on Alpine Linux. Debian works because we build a
debootstrap package. Ubuntu template did not work because it uses
'arch' command which we don't have. (ok, should be trivial to implement
if we want it bad enough - and I haven't tested current git templates)

However, the alpine template in current git should work on any distro.

Here is what we do:
* download static apk-tools (package manager) and the package with the
  public keys used for package signature checking.

* unpack the the package manager and public keys package with tar.  The
  package format is basically .tar.gz with some files in the beginning
  with metadata, so the .apk files can be extracted with tar -zx.

* verify that the public keys are unmodified against a sha256 sum that
  is embedded in the template script.

* verify that the static binary is unmodified using the public key and
  openssl. The apk-tools-static package includes a signature for the
  static binary.

* use the verified static package manager to install a rootfs. The
  package manager will use the previously downloaded pub keys.

This should work on any x86/x86_64 distro with tar, gzip, openssl and
wget.


-nc


signature.asc
Description: PGP signature
--
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-alpine: add hwaddr for a single macvlan interface

2013-09-04 Thread Natanael Copa
We already add harware address for a single veth interface. Do the same
with a single macvlan interface.

Signed-off-by: Natanael Copa 
---
 templates/lxc-alpine.in | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
index 2ab10bb..05aec74 100644
--- a/templates/lxc-alpine.in
+++ b/templates/lxc-alpine.in
@@ -173,9 +173,11 @@ lxc.network.flags = up
 EOF
 fi
 
-# if there is exactly one veth network entry, make sure it has an
-# associated mac address.
-nics=$(grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l)
+# if there is exactly one veth or macvlan network entry, make sure
+# it has an associated mac address.
+nics=$(awk -F '[ \t]*=[ \t]*' \
+'$1=="lxc.network.type" && ($2=="veth" || $2=="macvlan") {print $2}' \
+$path/config | wc -l)
 if [ "$nics" -eq 1 ] && ! grep -q "^lxc.network.hwaddr" $path/config; then
 # see 
http://sourceforge.net/tracker/?func=detail&aid=3411497&group_id=163076&atid=826303
 hwaddr="fe:$(dd if=/dev/urandom bs=8 count=1 2>/dev/null |od -t x8 | \
-- 
1.8.4


--
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lua: prepare for Lua 5.2

2013-09-04 Thread Natanael Copa
Adjust code for Lua 5.2 and keep compatibility with Lua 5.1.

We also fix a bug in the parsing of /proc/mounts while here.

Signed-off-by: Natanael Copa 
---
 src/lua-lxc/core.c  | 10 --
 src/lua-lxc/lxc.lua | 18 ++
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c
index 9ccbab4..d404707 100644
--- a/src/lua-lxc/core.c
+++ b/src/lua-lxc/core.c
@@ -25,9 +25,15 @@
 #define _GNU_SOURCE
 #include 
 #include 
+#include 
 #include 
 #include 
 
+#if LUA_VERSION_NUM < 502
+#define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
+#define luaL_setfuncs(L,l,n) (assert(n==0), luaL_register(L,NULL,l))
+#endif
+
 #ifdef NO_CHECK_UDATA
 #define checkudata(L,i,tname)  lua_touserdata(L, i)
 #else
@@ -389,7 +395,7 @@ static int lxc_lib_uninit(lua_State *L) {
 LUALIB_API int luaopen_lxc_core(lua_State *L) {
 /* this is where we would initialize liblxc.so if we needed to */
 
-luaL_register(L, "lxc", lxc_lib_methods);
+luaL_newlib(L, lxc_lib_methods);
 
 lua_newuserdata(L, 0);
 lua_newtable(L);  /* metatable */
@@ -401,12 +407,12 @@ LUALIB_API int luaopen_lxc_core(lua_State *L) {
 lua_rawset(L, -3);
 
 luaL_newmetatable(L, CONTAINER_TYPENAME);
+luaL_setfuncs(L, lxc_container_methods, 0);
 lua_pushvalue(L, -1);  /* push metatable */
 lua_pushstring(L, "__gc");
 lua_pushcfunction(L, container_gc);
 lua_settable(L, -3);
 lua_setfield(L, -2, "__index");  /* metatable.__index = metatable */
-luaL_register(L, NULL, lxc_container_methods);
 lua_pop(L, 1);
 return 1;
 }
diff --git a/src/lua-lxc/lxc.lua b/src/lua-lxc/lxc.lua
index b48eb76..4ef1ff9 100755
--- a/src/lua-lxc/lxc.lua
+++ b/src/lua-lxc/lxc.lua
@@ -32,6 +32,11 @@ local lxc_path
 local cgroup_path
 local log_level = 3
 
+-- lua 5.1 compat
+if table.unpack == nil then
+table.unpack = unpack
+end
+
 -- the following two functions can be useful for debugging
 function printf(...)
 local function wrapper(...) io.write(string.format(...)) end
@@ -89,6 +94,9 @@ function cgroup_path_get()
while true do
local c
line = f:read()
+   if line == nil then
+   break
+   end
c = line:split(" ", 6)
if (c[1] == "cgroup") then
cgroup_path = dirname(c[2])
@@ -283,7 +291,7 @@ function container:stat_get_ints(controller, item, coords)
table.insert(result, val)
end
 end
-return unpack(result)
+return table.unpack(result)
 end
 
 -- read an integer from a cgroup file
@@ -356,10 +364,10 @@ function container:stats_get(total)
 return stat
 end
 
-
+local M = { container = container }
 
 -- return configured containers found in LXC_PATH directory
-function containers_configured(names_only)
+function M.containers_configured(names_only)
 local containers = {}
 
 for dir in lfs.dir(lxc_path) do
@@ -387,7 +395,7 @@ function containers_configured(names_only)
 end
 
 -- return running containers found in cgroup fs
-function containers_running(names_only)
+function M.containers_running(names_only)
 local containers = {}
 local attr
 
@@ -423,3 +431,5 @@ end
 
 lxc_path = core.default_config_path_get()
 cgroup_path = cgroup_path_get()
+
+return M
-- 
1.8.4


--
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] configure/makefile: Allow specify Lua pkg-config file with --with-lua-pc

2013-09-05 Thread Natanael Copa
Enable support for both Lua 5.1 and 5.2 by let user specify the Lua
pkg-config package name. By default it will use 'lua' and try figure
out which version it is.

Signed-off-by: Natanael Copa 
---
 configure.ac| 36 +++-
 src/lua-lxc/Makefile.am |  4 ++--
 2 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/configure.ac b/configure.ac
index 6b68703..cd707ec 100644
--- a/configure.ac
+++ b/configure.ac
@@ -151,21 +151,39 @@ AM_COND_IF([ENABLE_PYTHON],
AC_DEFINE_UNQUOTED([ENABLE_PYTHON], 1, [Python3 is available])])
 
 # Lua module and scripts
-if test x"$with_distro" = "xdebian" -o x"$with_distro" = "xubuntu" ; then
-LUAPKGCONFIG=lua5.1
-else
-LUAPKGCONFIG=lua
-fi
-
 AC_ARG_ENABLE([lua],
[AC_HELP_STRING([--enable-lua], [enable lua binding])],
[enable_lua=yes], [enable_lua=no])
 
-AM_CONDITIONAL([ENABLE_LUA], [test "x$enable_lua" = "xyes"])
+AC_ARG_WITH([lua-pc],
+   [AS_HELP_STRING(
+   [--with-lua-pc=PKG],
+   [Specify pkg-config package name for lua]
+   )],
+   [LUAPKGCONFIG=$with_lua_pc
+   enable_lua=yes], [with_lua_pc=auto])
+
+AM_CONDITIONAL([ENABLE_LUA],
+   [test "x$enable_lua" = "xyes" -o "xwith_lua_pc != xno"])
 
 AM_COND_IF([ENABLE_LUA],
-   [PKG_CHECK_MODULES([LUA], [$LUAPKGCONFIG >= 5.1],[],[AC_MSG_ERROR([You 
must install lua-devel for lua 5.1])])
-   AC_DEFINE_UNQUOTED([ENABLE_LUA], 1, [Lua is available])])
+   [AS_IF([test "x$with_lua_pc" = "xauto"],
+   [PKG_CHECK_MODULES([LUA], [lua],[LUAPKGCONFIG=lua],
+   [PKG_CHECK_MODULES([LUA], 
[lua5.2],[LUAPKGCONFIG=lua5.2],
+   [PKG_CHECK_MODULES([LUA], [lua5.1],
+   [LUAPKGCONFIG=lua5.1])]
+   )]
+   )],
+   [PKG_CHECK_MODULES([LUA], [$with_lua_pc])])
+   AC_MSG_CHECKING([Lua version])
+   PKG_CHECK_VAR([LUA_VERSION], [$LUAPKGCONFIG], [V],,
+   [PKG_CHECK_VAR([LUA_VERSION], [$LUAPKGCONFIG], 
[major_version])])
+   AC_MSG_RESULT([$LUA_VERSION])
+   PKG_CHECK_VAR([LUA_INSTALL_CMOD], [$LUAPKGCONFIG], [INSTALL_CMOD],,
+   [LUA_INSTALL_CMOD=$libdir/lua/$LUA_VERSION])
+   PKG_CHECK_VAR([LUA_INSTALL_LMOD], [$LUAPKGCONFIG], [INSTALL_LMOD],,
+   [LUA_INSTALL_LMOD=$datadir/lua/$LUA_VERSION])
+   ])
 
 # Optional test binaries
 AC_ARG_ENABLE([tests],
diff --git a/src/lua-lxc/Makefile.am b/src/lua-lxc/Makefile.am
index 82dbae8..11eabfd 100644
--- a/src/lua-lxc/Makefile.am
+++ b/src/lua-lxc/Makefile.am
@@ -1,7 +1,7 @@
 if ENABLE_LUA
 
-luadir=$(datadir)/lua/5.1
-sodir=$(libdir)/lua/5.1/lxc
+luadir=$(LUA_INSTALL_LMOD)
+sodir=$(LUA_INSTALL_CMOD)/lxc
 
 lua_SCRIPTS=lxc.lua
 
-- 
1.8.4


--
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lua: implement usleep in C module

2013-09-05 Thread Natanael Copa
So we avoid running os.execute

Signed-off-by: Natanael Copa 
---
 src/lua-lxc/core.c |  9 +
 src/lxc/lxc-top| 12 ++--
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c
index d404707..504e147 100644
--- a/src/lua-lxc/core.c
+++ b/src/lua-lxc/core.c
@@ -27,11 +27,13 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #if LUA_VERSION_NUM < 502
 #define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
 #define luaL_setfuncs(L,l,n) (assert(n==0), luaL_register(L,NULL,l))
+#define luaL_checkunsigned(L,n) luaL_checknumber(L,n)
 #endif
 
 #ifdef NO_CHECK_UDATA
@@ -379,10 +381,17 @@ static int lxc_default_config_path_get(lua_State *L) {
 return 1;
 }
 
+/* utility functions */
+static int lxc_util_usleep(lua_State *L) {
+usleep((useconds_t)luaL_checkunsigned(L, 1));
+return 0;
+}
+
 static luaL_Reg lxc_lib_methods[] = {
 {"version_get",lxc_version_get},
 {"default_config_path_get",lxc_default_config_path_get},
 {"container_new",  container_new},
+{"usleep", lxc_util_usleep},
 {NULL, NULL}
 };
 
diff --git a/src/lxc/lxc-top b/src/lxc/lxc-top
index 31aaecf..8e8bafb 100755
--- a/src/lxc/lxc-top
+++ b/src/lxc/lxc-top
@@ -22,6 +22,7 @@
 --
 
 local lxc= require("lxc")
+local core   = require("lxc.core")
 local getopt = require("alt_getopt")
 local lfs= require("lfs")
 
@@ -95,15 +96,6 @@ function strsisize(size, width)
 return string.format("%3d.00   ", size)
 end
 
-function usleep(n)
-if (n ~= 0) then
-   ret = os.execute("usleep " .. tonumber(n))
-   if (ret ~= 0) then
-   os.exit(0)
-   end
-end
-end
-
 function tty_lines()
 local rows = 25
 local f = assert(io.popen("stty -a | head -n 1"))
@@ -238,5 +230,5 @@ do
 end
 stats_print(string.format("TOTAL (%-2d)", #containers), stats_total)
 io.flush()
-usleep(optarg["d"] * 100)
+core.usleep(optarg["d"] * 100)
 end
-- 
1.8.4


--
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lua: implement dirname in C rather than depen on external executable

2013-09-05 Thread Natanael Copa
Instead of popen and run external executable dirname we implement a
dirname in C in the core module.

We also remove the unused basename function.

Signed-off-by: Natanael Copa 
---
 src/lua-lxc/core.c  |  8 
 src/lua-lxc/lxc.lua | 18 +-
 2 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c
index 504e147..002e8bf 100644
--- a/src/lua-lxc/core.c
+++ b/src/lua-lxc/core.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #if LUA_VERSION_NUM < 502
@@ -387,11 +388,18 @@ static int lxc_util_usleep(lua_State *L) {
 return 0;
 }
 
+static int lxc_util_dirname(lua_State *L) {
+char *path = strdupa(luaL_checkstring(L, 1));
+lua_pushstring(L, dirname(path));
+return 1;
+}
+
 static luaL_Reg lxc_lib_methods[] = {
 {"version_get",lxc_version_get},
 {"default_config_path_get",lxc_default_config_path_get},
 {"container_new",  container_new},
 {"usleep", lxc_util_usleep},
+{"dirname",lxc_util_dirname},
 {NULL, NULL}
 };
 
diff --git a/src/lua-lxc/lxc.lua b/src/lua-lxc/lxc.lua
index 4ef1ff9..2f1204c 100755
--- a/src/lua-lxc/lxc.lua
+++ b/src/lua-lxc/lxc.lua
@@ -70,22 +70,6 @@ function string:split(delim, max_cols)
 return cols
 end
 
-function dirname(path)
-local f,output
-f = io.popen("dirname " .. path)
-output = f:read('*all')
-f:close()
-return output:sub(1,-2)
-end
-
-function basename(path, suffix)
-local f,output
-f = io.popen("basename " .. path .. " " .. (suffix or ""))
-output = f:read('*all')
-f:close()
-return output:sub(1,-2)
-end
-
 function cgroup_path_get()
 local f,line,cgroup_path
 
@@ -99,7 +83,7 @@ function cgroup_path_get()
end
c = line:split(" ", 6)
if (c[1] == "cgroup") then
-   cgroup_path = dirname(c[2])
+   cgroup_path = core.dirname(c[2])
break
end
end
-- 
1.8.4


--
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] lua: prepare for Lua 5.2

2013-09-05 Thread Natanael Copa
On Thu, 5 Sep 2013 08:11:57 -0500
Serge Hallyn  wrote:

> Hi Dwight,
> 
> do you have time to review/ack these (3, so far) lua patches?

I send 2 more patches, to get rid of fork/exec. (os.execute and io.popen)

They should all be available from https://github.com/ncopa/lxc

Thanks!

-nc

--
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] lua: prepare for Lua 5.2

2013-09-05 Thread Natanael Copa
On Thu, 5 Sep 2013 09:34:14 -0400
Dwight Engen  wrote:

> On Thu, 5 Sep 2013 08:11:57 -0500
> Serge Hallyn  wrote:
> 
> > Hi Dwight,
> > 
> > do you have time to review/ack these (3, so far) lua patches?
> > 
> > (I probably don't know enough to do so)
> 
> Yeah I've taken a look. I had already done an update similar to the
> first two and was just getting ready to post after some more testing.
> 
> Natanael, would you mind taking a look at how I did the update and see
> if it works for you? I've integrated the fixes you've done into
> what I had, but I did the autoconf stuff a bit different (the
> INSTALL_[CL]MOD pkg-config variables don't exist on Fedora/Oracle so I
> did it more like lua-filesystem does) and also had to fix up that
> there is no lxc subdir in cgroup anymore.

Yes, but i verified that fedora has the V variable. The patch I sent
should fall back to $libdir/lua/$LUA_VERSION and
$datadir/lua/$LUA_VERSION if INSTALL_[CL]MOD is missing. I tested on my
local workstation to remove the INSTALL_[CL]MOD from the lua.pc file.

Getting Lua correct is tricky... :-/

-nc

--
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] update lua binding to support both 5.2 and 5.1

2013-09-05 Thread Natanael Copa
On Thu, 5 Sep 2013 09:41:12 -0400
Dwight Engen  wrote:

> fix a bug in the parsing of /proc/mounts (from Natanael Copa
> )
> 
> remove lxc subdir in cgroup paths
> 
> remove extraneous debug printfs
> 
> remove extra call to stats_clear
> 
> Tested lxc-top, and apitest.lua on both lua 5.1 and 5.2
> 
> Signed-off-by: Dwight Engen 
> ---
>  configure.ac| 10 +-
>  src/lua-lxc/Makefile.am |  4 ++--
>  src/lua-lxc/lxc.lua | 50 
> ++---
>  src/lxc/lxc-top | 14 ++
>  4 files changed, 43 insertions(+), 35 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index df9a44b..f6f067d 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -164,9 +164,17 @@ AC_ARG_ENABLE([lua],
>  AM_CONDITIONAL([ENABLE_LUA], [test "x$enable_lua" = "xyes"])
>  
>  AM_COND_IF([ENABLE_LUA],
> - [PKG_CHECK_MODULES([LUA], [$LUAPKGCONFIG >= 5.1],[],[AC_MSG_ERROR([You 
> must install lua-devel for lua 5.1])])
> + [AC_CHECK_PROG([LUA],[lua],[lua],[no])
> + PKG_CHECK_MODULES([LUADEVEL], [$LUAPKGCONFIG >= 
> 5.1],[],[AC_MSG_ERROR([You must install lua-devel])])
>   AC_DEFINE_UNQUOTED([ENABLE_LUA], 1, [Lua is available])])
>  
> +AS_IF([test "x$LUA" != "xno"],
> + [AC_MSG_CHECKING([for lua version])
> + LUA_VERSION=`$LUA -e 'print(_VERSION)' | awk '{print $2}'`
> + AC_MSG_RESULT([$LUA_VERSION])
> + AC_SUBST([LUA_VERSION])])
> +
> +
>  # Optional test binaries
>  AC_ARG_ENABLE([tests],
>   [AC_HELP_STRING([--enable-tests], [build test/example binaries])],

What if you have both lua 5.1 and 5.2 installed (eg debian/ubuntu) and
want build against lua 5.1? On Ubuntu I get:

lua -e 'print(_VERSION)' | awk '{print $2}'
5.2

but i might want use the lua5.1.pc

And what happens if you cross-compile? (cross-compiling is a new can of
worms that i don't think we should worry too much about)

This is why i dropped the idea of running lua binary and try to rely on
pkg-config info only.

Even if fedora does not provide INSTALL_[CL]MOD it provides V:
[ncopa@localhost ~]$ uname -a
Linux localhost.localdomain 3.9.5-301.fc19.x86_64 #1 SMP Tue Jun 11 19:39:38 
UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
[ncopa@localhost ~]$ pkg-config --variable V lua
5.1

We can fallback to this in case INSTALL_[CL]MOD is missing.

INSTALL_[CL]MOD appears to be available on Ubuntu(/Debian?), Arch Linux
and Alpine Linux. Suse I don't know.



> diff --git a/src/lxc/lxc-top b/src/lxc/lxc-top
> index 31aaecf..969f1f7 100755
> --- a/src/lxc/lxc-top
> +++ b/src/lxc/lxc-top
> @@ -97,9 +97,16 @@ end
>  
>  function usleep(n)
>  if (n ~= 0) then
> - ret = os.execute("usleep " .. tonumber(n))
> - if (ret ~= 0) then
> - os.exit(0)
> + local ret = os.execute("usleep " .. tonumber(n))
> + if (string.sub(_VERSION, 5) == "5.2") then
> + if (ret == nil) then
> + os.exit(0)
> + end
> + end
> + if (string.sub(_VERSION, 5) == "5.1") then
> + if (ret ~= 0) then
> + os.exit(0)
> + end
>   end
>  end
>  end

How about implement a tiny usleep in core in C instead:

diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c
index d404707..504e147 100644
--- a/src/lua-lxc/core.c
+++ b/src/lua-lxc/core.c
@@ -27,11 +27,13 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #if LUA_VERSION_NUM < 502
 #define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
 #define luaL_setfuncs(L,l,n) (assert(n==0), luaL_register(L,NULL,l))
+#define luaL_checkunsigned(L,n) luaL_checknumber(L,n)
 #endif
 
 #ifdef NO_CHECK_UDATA
@@ -379,10 +381,17 @@ static int lxc_default_config_path_get(lua_State *L) {
 return 1;
 }
 
+/* utility functions */
+static int lxc_util_usleep(lua_State *L) {
+usleep((useconds_t)luaL_checkunsigned(L, 1));
+return 0;
+}
+
 static luaL_Reg lxc_lib_methods[] = {
 {"version_get",lxc_version_get},
 {"default_config_path_get",lxc_default_config_path_get},
 {"container_new",  container_new},
+{"usleep", lxc_util_usleep},
 {NULL, NULL}
 };
 
diff --git a/src/lxc/lxc-top b/src/lxc/lxc-top
index 31aaecf..8e8bafb 100755
--- a/src/lxc/lxc-top
+++ b/src/lxc/lxc-top
@@ -22,6 +22,7 @@
 --
 
 local lxc= require("lxc")
+local core   = require("lxc.core")
 local getopt = require("alt_getopt")
 local lfs= require("lfs")
 
@@ -95,15 +96,6 @@ function strsisize(size, width)
 return string.format("%3d.00   ", size)
 end
 
-function usleep(n)
-if (n ~= 

[lxc-devel] [PATCH v2] configure/makefile: Allow specify Lua pkg-config file with --with-lua-pc

2013-09-05 Thread Natanael Copa
Enable support for both Lua 5.1 and 5.2 by let user specify the Lua
pkg-config package name. By default it will use 'lua' and try figure
out which version it is.

Signed-off-by: Natanael Copa 
---
Changes v1 -> v2:
 - define PKG_CHECK_VAR which was introduced in pkg-config 0.28. Ubuntu
   ships 0.26.

 configure.ac| 47 ++-
 src/lua-lxc/Makefile.am |  4 ++--
 2 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/configure.ac b/configure.ac
index 6b68703..1e2c713 100644
--- a/configure.ac
+++ b/configure.ac
@@ -150,22 +150,51 @@ AM_COND_IF([ENABLE_PYTHON],
PKG_CHECK_MODULES([PYTHONDEV], [python3 >= 3.2],[],[AC_MSG_ERROR([You 
must install python3-dev])])
AC_DEFINE_UNQUOTED([ENABLE_PYTHON], 1, [Python3 is available])])
 
-# Lua module and scripts
-if test x"$with_distro" = "xdebian" -o x"$with_distro" = "xubuntu" ; then
-LUAPKGCONFIG=lua5.1
-else
-LUAPKGCONFIG=lua
-fi
+dnl PKG_CHECK_VAR was introduced with pkg-config 0.28
+m4_ifdef([PKG_CHECK_VAR], [],
+[AC_DEFUN([PKG_CHECK_VAR],
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
+ AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
+ _PKG_CONFIG([$1], [variable="][$3]["], [$2])
+ AS_VAR_COPY([$1], [pkg_cv_][$1])
+ AS_VAR_IF([$1], [""], [$5], [$4])dnl
+])# PKG_CHECK_VAR
+])
 
+# Lua module and scripts
 AC_ARG_ENABLE([lua],
[AC_HELP_STRING([--enable-lua], [enable lua binding])],
[enable_lua=yes], [enable_lua=no])
 
-AM_CONDITIONAL([ENABLE_LUA], [test "x$enable_lua" = "xyes"])
+AC_ARG_WITH([lua-pc],
+   [AS_HELP_STRING(
+   [--with-lua-pc=PKG],
+   [Specify pkg-config package name for lua]
+   )],
+   [LUAPKGCONFIG=$with_lua_pc
+   enable_lua=yes], [with_lua_pc=auto])
+
+AM_CONDITIONAL([ENABLE_LUA],
+   [test "x$enable_lua" = "xyes" -o "xwith_lua_pc != xno"])
 
 AM_COND_IF([ENABLE_LUA],
-   [PKG_CHECK_MODULES([LUA], [$LUAPKGCONFIG >= 5.1],[],[AC_MSG_ERROR([You 
must install lua-devel for lua 5.1])])
-   AC_DEFINE_UNQUOTED([ENABLE_LUA], 1, [Lua is available])])
+   [AS_IF([test "x$with_lua_pc" = "xauto"],
+   [PKG_CHECK_MODULES([LUA], [lua],[LUAPKGCONFIG=lua],
+   [PKG_CHECK_MODULES([LUA], 
[lua5.2],[LUAPKGCONFIG=lua5.2],
+   [PKG_CHECK_MODULES([LUA], [lua5.1],
+   [LUAPKGCONFIG=lua5.1])]
+   )]
+   )],
+   [PKG_CHECK_MODULES([LUA], [$with_lua_pc])])
+   AC_MSG_CHECKING([Lua version])
+   PKG_CHECK_VAR([LUA_VERSION], [$LUAPKGCONFIG], [V],,
+   [PKG_CHECK_VAR([LUA_VERSION], [$LUAPKGCONFIG], 
[major_version])])
+   AC_MSG_RESULT([$LUA_VERSION])
+   PKG_CHECK_VAR([LUA_INSTALL_CMOD], [$LUAPKGCONFIG], [INSTALL_CMOD],,
+   [LUA_INSTALL_CMOD=$libdir/lua/$LUA_VERSION])
+   PKG_CHECK_VAR([LUA_INSTALL_LMOD], [$LUAPKGCONFIG], [INSTALL_LMOD],,
+   [LUA_INSTALL_LMOD=$datadir/lua/$LUA_VERSION])
+   ])
 
 # Optional test binaries
 AC_ARG_ENABLE([tests],
diff --git a/src/lua-lxc/Makefile.am b/src/lua-lxc/Makefile.am
index 82dbae8..11eabfd 100644
--- a/src/lua-lxc/Makefile.am
+++ b/src/lua-lxc/Makefile.am
@@ -1,7 +1,7 @@
 if ENABLE_LUA
 
-luadir=$(datadir)/lua/5.1
-sodir=$(libdir)/lua/5.1/lxc
+luadir=$(LUA_INSTALL_LMOD)
+sodir=$(LUA_INSTALL_CMOD)/lxc
 
 lua_SCRIPTS=lxc.lua
 
-- 
1.8.4


--
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH v2] configure/makefile: Allow specify Lua pkg-config file with --with-lua-pc

2013-09-05 Thread Natanael Copa
On Thu, 5 Sep 2013 21:46:00 -0400
Stéphane Graber  wrote:

> Right, same thing showed up in the latest daily build.
> 
> As that's quite problematic for all of us who don't have lua, I'll
> revert the lua commits if we don't get this fixed tomorrow.

it should be enough to revert:

commit 12e93188de7dfe9ba66e022f9c28aa1f696a22e8
Author: Natanael Copa 
Date:   Thu Sep 5 17:13:07 2013 +0200

configure/makefile: Allow specify Lua pkg-config file with
--with-lua-pc

I will try fix it before you reach to do that though.

> Sorry for not spotting this when testing the commits, unfortunately my
> dev machine did have the lua headers installed...

The intention was that it should not pull in lua unless --enable-lua or
--with-lua-pc was specified.

I'll fix it ASAP.

Sorry.

-nc



signature.asc
Description: PGP signature
--
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lua: fix logic to enable lua support in configure

2013-09-06 Thread Natanael Copa
When there is no --enable-lua or --with-lua-pc, Lua should not be
enabled.

This fixes a bug introduced with 12e93188 (configure/makefile:
Allow specify Lua pkg-config file with --with-lua-pc) that caused
configure script to fail if lua headers was missing.

Signed-off-by: Natanael Copa 
---
PS.

I wonder it it would be an idea to replace the 2 switches:

  --enable-lua
  --with-lua-pc[=PKG]

with a single switch:

  --with-lua[=PKG]

As it works now, if you specify either --enable-lua or --with-lua-pc,
lua will be enabled and configure will fail if Lua headers is missing.
Even '--disable-lua --with-lua-pc' will actually enable Lua.

In any case, this patch fixes the current problem.

 configure.ac | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index 0909da3..481bf06 100644
--- a/configure.ac
+++ b/configure.ac
@@ -182,13 +182,13 @@ AC_ARG_WITH([lua-pc],
[Specify pkg-config package name for lua]
)],
[LUAPKGCONFIG=$with_lua_pc
-   enable_lua=yes], [with_lua_pc=auto])
+   enable_lua=yes])
 
 AM_CONDITIONAL([ENABLE_LUA],
-   [test "x$enable_lua" = "xyes" -o "xwith_lua_pc != xno"])
+   [test "x$enable_lua" = "xyes"])
 
 AM_COND_IF([ENABLE_LUA],
-   [AS_IF([test "x$with_lua_pc" = "xauto"],
+   [AS_IF([test "x$with_lua_pc" = "xyes"],
[PKG_CHECK_MODULES([LUA], [lua],[LUAPKGCONFIG=lua],
[PKG_CHECK_MODULES([LUA], 
[lua5.2],[LUAPKGCONFIG=lua5.2],
[PKG_CHECK_MODULES([LUA], [lua5.1],
-- 
1.8.4


--
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] lua: fix logic to enable lua support in configure

2013-09-06 Thread Natanael Copa
On Fri, 6 Sep 2013 10:56:09 +0200
Thomas Moschny  wrote:

> 2013/9/6 Natanael Copa :
> > I wonder it it would be an idea to replace the 2 switches:
> >
> >   --enable-lua
> >   --with-lua-pc[=PKG]
> >
> > with a single switch:
> >
> >   --with-lua[=PKG]
> >
> > As it works now, if you specify either --enable-lua or --with-lua-pc,
> > lua will be enabled and configure will fail if Lua headers is missing.
> > Even '--disable-lua --with-lua-pc' will actually enable Lua.
> 
> Having only one switch would absolutely make sense imho.

It will break for users/scripts that currently rely on --enable-lua,
but I think it is ok since its not included in any release.

I have a patch for it ready but will wait til the bugfix patch is
applied.

-nc

--
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] configure: enable Lua if found and continue without if not

2013-09-06 Thread Natanael Copa
Search for Lua if no --enable-lua/--disable-lua specified but continue
without if not found.

If --enable-lua is specified and Lua is not found then return error.

If --disable-lua is specified, then don't search for Lua.

Signed-off-by: Natanael Copa 
---
 configure.ac | 40 +++-
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/configure.ac b/configure.ac
index 481bf06..4eaf329 100644
--- a/configure.ac
+++ b/configure.ac
@@ -174,29 +174,43 @@ m4_ifdef([PKG_CHECK_VAR], [],
 # Lua module and scripts
 AC_ARG_ENABLE([lua],
[AC_HELP_STRING([--enable-lua], [enable lua binding])],
-   [enable_lua=yes], [enable_lua=no])
+   [], [enable_lua=check])
 
 AC_ARG_WITH([lua-pc],
[AS_HELP_STRING(
[--with-lua-pc=PKG],
[Specify pkg-config package name for lua]
-   )],
-   [LUAPKGCONFIG=$with_lua_pc
-   enable_lua=yes])
+   )], [], [with_lua_pc=no])
+
+if test "x$enable_lua" = "xyes" -a "x$with_lua_pc" != "xno"; then
+   # exit with error if not found
+   PKG_CHECK_MODULES([LUA], [$with_lua_pc], [LUAPKGCONFIG=$with_lua_pc])
+fi
+
+if test "x$enable_lua" = "xcheck" -a "x$with_lua_pc" != "xno"; then
+   PKG_CHECK_MODULES([LUA], [$with_lua_pc],
+   [LUAPKGCONFIG=$with_lua_pc
+   enable_lua=yes],
+   [enable_lua=no])
+fi
+
+if test "x$enable_lua" != "xno"; then
+   PKG_CHECK_MODULES([LUA], [lua], [LUAPKGCONFIG=lua],
+   [PKG_CHECK_MODULES([LUA], [lua5.2], [LUAPKGCONFIG=lua5.2],
+   [PKG_CHECK_MODULES([LUA], [lua5.1], 
[LUAPKGCONFIG=lua5.1],
+   [AS_IF([test "x$enable_lua" = "xyes"],
+   [AC_MSG_ERROR([Lua not found. Please 
use --with-lua-pc=PKG])],
+   [enable_lua=no])]
+   )]
+   )])
+   AS_IF([test "x$LUAPKGCONFIG" != "x"], [enable_lua=yes])
+fi
 
 AM_CONDITIONAL([ENABLE_LUA],
[test "x$enable_lua" = "xyes"])
 
 AM_COND_IF([ENABLE_LUA],
-   [AS_IF([test "x$with_lua_pc" = "xyes"],
-   [PKG_CHECK_MODULES([LUA], [lua],[LUAPKGCONFIG=lua],
-   [PKG_CHECK_MODULES([LUA], 
[lua5.2],[LUAPKGCONFIG=lua5.2],
-   [PKG_CHECK_MODULES([LUA], [lua5.1],
-   [LUAPKGCONFIG=lua5.1])]
-   )]
-   )],
-   [PKG_CHECK_MODULES([LUA], [$with_lua_pc])])
-   AC_MSG_CHECKING([Lua version])
+   [AC_MSG_CHECKING([Lua version])
PKG_CHECK_VAR([LUA_VERSION], [$LUAPKGCONFIG], [V],,
[PKG_CHECK_VAR([LUA_VERSION], [$LUAPKGCONFIG], 
[major_version])])
AC_MSG_RESULT([$LUA_VERSION])
-- 
1.8.4


--
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [Lxc-users] Working LXC templates?

2013-09-09 Thread Natanael Copa
On Sun, 08 Sep 2013 20:33:16 -0400
"Michael H. Warfield"  wrote:

> With all due respect...
> 
> On Sun, 2013-09-08 at 16:08 -0700, Tony Su wrote: 
> > After putting some thought into this,
> > IMO LXC badly needs a universal tool with the following features
> > 
> > - A single script should be used to run on  HostOS, creating
> >  supported Container OS. Although this would make the script
> > extremely large, IMO it would actually be easier to maintain in the
> > long run.
> 
> Actually, no.  From my experience (30+ years in software development),
> it would turn into a morass.
> 
> The problem here is that the maintainer(s) would then need to understand
> how each and every distribution is installed and how it would be
> installed on each and every distribution.  It would distill the worse of
> all the problems we have now in the templates into one great big dung
> pile.  It would rapidly become unmaintainable.  The "extremely large" is
> the red letter warning that it will become unmaintainable as fewer and
> fewer people understand what this great big huge blob does.

I tend to agree with this.

What I do think could be done is to use template APIs. Either by having
a script "library" with helper functions (for things like:
generate_mac_address etc) or let the template scripts be "plugins" that
must provide a set of pre-defined functions (eg. install_distro,
configure_distro, copy_configuration etc) or maybe a combination of
those two.

-nc


signature.asc
Description: PGP signature
--
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-alpine: enable loopback interface by default

2013-10-16 Thread Natanael Copa
It was probably disabled by a mistake

Signed-off-by: Natanael Copa 
---
 templates/lxc-alpine.in | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
index 05aec74..5fdf36f 100644
--- a/templates/lxc-alpine.in
+++ b/templates/lxc-alpine.in
@@ -110,9 +110,8 @@ EOF
 grep nameserver /etc/resolv.conf > "$rootfs/etc/resolv.conf"
 
 # configure the network using the dhcp
-# note that lxc will set up lo interface
 cat < $rootfs/etc/network/interfaces
-#auto lo
+auto lo
 iface lo inet loopback
 
 auto eth0
-- 
1.8.4


--
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] what happened to the autostart proposals?

2013-10-20 Thread Natanael Copa
On Fri, 18 Oct 2013 15:17:22 -0400
Stéphane Graber  wrote:

> On Fri, Oct 18, 2013 at 08:26:53PM +0200, Harald Dunkel wrote:
> > -BEGIN PGP SIGNED MESSAGE-
> > Hash: SHA256
> > 
> > Hi folks,
> > 
> > there were several proposals on this mailing list about how
> > to start and stop a group of LXC containers, e.g. at boot or
> > shutdown time.
> > 
> > Are there any news about this?
> > 
> > 
> > Regards
> > Harri
> 
> I've been (slowly) working on that. I have a local branch here that adds
> all the needed options and Serge implemented the functions I needed to
> list all the containers 

I would think that this functionallity is all that is needed to be
useful. An initscript could do something like:

for container in $(lxc_list_containers_to_autostart); do
lxc-start -n $container ...
done

> so I just need to find the time to write the
> changes for lxc-start and lxc-stop and then we can land this upstream.


-nc


signature.asc
Description: PGP signature
--
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [lxc/lxc] 07520b: Update maintainers and URLs

2013-10-20 Thread Natanael Copa
On Sat, 19 Oct 2013 21:49:03 -0700
GitHub  wrote:

>   Branch: refs/heads/master
>   Home:   https://github.com/lxc/lxc
>   Commit: 07520b2af5495cbde94645d09b523de73047542d

Would it be an idea to have a separate mailing list for git commits? I
think the mailing list is painfully noisy.

-nc

--
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] what happened to the autostart proposals?

2013-10-21 Thread Natanael Copa
On Sun, 20 Oct 2013 08:46:10 -0400
"Michael H. Warfield"  wrote:

> On Sun, 2013-10-20 at 12:21 +0200, Natanael Copa wrote: 
> > On Fri, 18 Oct 2013 15:17:22 -0400
> > Stéphane Graber  wrote:
> > 
> > > On Fri, Oct 18, 2013 at 08:26:53PM +0200, Harald Dunkel wrote:

> > > > there were several proposals on this mailing list about how
> > > > to start and stop a group of LXC containers, e.g. at boot or
> > > > shutdown time.
...
> > > I've been (slowly) working on that. I have a local branch here that adds
> > > all the needed options and Serge implemented the functions I needed to
> > > list all the containers 
> 
> > I would think that this functionallity is all that is needed to be
> > useful. An initscript could do something like:
> 
> > for container in $(lxc_list_containers_to_autostart); do
> > lxc-start -n $container ...
> > done
> 
> That may be all that's useful to you but there are several of us who
> begged to differ in earlier discussions a year or more ago.
...

I'm not saying that this is enough for everyone. Sorry for not
expressing myself clear enough.

> > > so I just need to find the time to write the
> > > changes for lxc-start and lxc-stop and then we can land this upstream.

My point is that it might be ok to push it to git master before
lxc-start and lxc-stop is fully feature complete. But I am ok with
waiting too.

-nc


signature.asc
Description: PGP signature
--
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] lxc-alpine: allow /dev/full

2013-10-22 Thread Natanael Copa
The template creates /dev/full for the container but needs also give
permission to access it.

Signed-off-by: Natanael Copa 
---
 templates/lxc-alpine.in | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
index 5fdf36f..8600a34 100644
--- a/templates/lxc-alpine.in
+++ b/templates/lxc-alpine.in
@@ -197,9 +197,10 @@ lxc.cap.drop = sys_module mac_admin mac_override sys_time
 
 # devices
 lxc.cgroup.devices.deny = a
-# /dev/null and zero
+# /dev/null, zero and full
 lxc.cgroup.devices.allow = c 1:3 rwm
 lxc.cgroup.devices.allow = c 1:5 rwm
+lxc.cgroup.devices.allow = c 1:7 rwm
 # consoles
 lxc.cgroup.devices.allow = c 5:1 rwm
 lxc.cgroup.devices.allow = c 5:0 rwm
-- 
1.8.4.1


--
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH 1/2] lxc-alpine: run bootmisc and syslog at boot runlevel

2013-10-24 Thread Natanael Copa
The bootmisc script is needed to clean up various temp dirs like /tmp
and migrate /var/run to /run if needed.

The syslog service is started in 'boot' runlevel when running on real
hardware so we do the same for containers.

Signed-off-by: Natanael Copa 
---
 templates/lxc-alpine.in | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
index 8600a34..2756b89 100644
--- a/templates/lxc-alpine.in
+++ b/templates/lxc-alpine.in
@@ -140,7 +140,8 @@ EOF
 mknod -m 666 "$rootfs/dev/ptmx" c 5 2
 
 # start services
-ln -s /etc/init.d/syslog "$rootfs"/etc/runlevels/default/syslog
+ln -s /etc/init.d/bootmisc "$rootfs"/etc/runlevels/boot/bootmisc
+ln -s /etc/init.d/syslog "$rootfs"/etc/runlevels/boot/syslog
 
 return 0
 }
-- 
1.8.4.1


--
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH 2/2] lxc-alpine: enable 4 consoles by default

2013-10-24 Thread Natanael Copa
We allow 4 consoles in the LXC config file so we can enable 4 in the
inittab as well.

Signed-off-by: Natanael Copa 
---
 templates/lxc-alpine.in | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
index 2756b89..258eed4 100644
--- a/templates/lxc-alpine.in
+++ b/templates/lxc-alpine.in
@@ -103,6 +103,9 @@ configure_alpine() {
 ::sysinit:/sbin/rc sysinit
 ::wait:/sbin/rc default
 tty1:12345:respawn:/sbin/getty 38400 tty1
+tty2:12345:respawn:/sbin/getty 38400 tty2
+tty3:12345:respawn:/sbin/getty 38400 tty3
+tty4:12345:respawn:/sbin/getty 38400 tty4
 ::ctrlaltdel:/sbin/reboot
 ::shutdown:/sbin/rc shutdown
 EOF
-- 
1.8.4.1


--
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] Rethinking lxc-info a bit

2013-11-15 Thread Natanael Copa
On Wed, 13 Nov 2013 14:41:55 -0500
Stéphane Graber  wrote:

> So my suggestion for lxc-info in LXC 1.0 are:
>  - Only support one container and make -n mandatory, fail with an error
>if the container can't be found.

I like the idea of lxc-info operating on a single container and have
other tools to do multiple. vserver has a vserver-stat that will show
the status of running vserver containers. I dunno if it would be an
idea to introduce an lxc-stat tool and maybe move some of the 'fancy'
features from lxc-ls to there too while at it.

Example output from vserver-stat:

build:~# vserver-stat 
CTX   PROCVSZRSS  userTIME   sysTIMEUPTIME NAME
100052  23.2M   520K   0m00s23   0m00s26  43d00h06 nc-nptl
100071  19.6M   148K   0m00s27   0m00s18  43d00h06 build-1-10
100103  30.8M   1.3M   0m52s14   1m28s00  43d00h06 distfiles
...

In situations where things go slow you want find out what container is
using memory and cpu (and you often want do it quick).

-nc


signature.asc
Description: PGP signature
--
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel