mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-06-14 00:59:05 +00:00
lxc-execute: find lxc-init
lxc-init used to be under /usr/lib/lxc. Now it is under /usr/lib/<multiarch>/lxc, but old containers will still have it under /usr/lib/lxc. So search for a valid lxc-init to run. Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com> Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
parent
d1252b8425
commit
a0a2066d93
@ -21,10 +21,13 @@
|
|||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "start.h"
|
#include "start.h"
|
||||||
|
|
||||||
@ -35,12 +38,42 @@ struct execute_args {
|
|||||||
int quiet;
|
int quiet;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* historically lxc-init has been under /usr/lib/lxc. Now with
|
||||||
|
* multi-arch it can be under /usr/lib/$ARCH/lxc. Serge thinks
|
||||||
|
* it makes more sense to put it under /sbin.
|
||||||
|
* If /usr/lib/$ARCH/lxc exists and is used, then LXCINITDIR will
|
||||||
|
* point to it.
|
||||||
|
*/
|
||||||
|
static char *choose_init(void)
|
||||||
|
{
|
||||||
|
char *retv = malloc(PATH_MAX);
|
||||||
|
int ret;
|
||||||
|
struct stat mystat;
|
||||||
|
if (!retv)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
snprintf(retv, PATH_MAX-1, LXCINITDIR "/lxc/lxc-init");
|
||||||
|
ret = stat(retv, &mystat);
|
||||||
|
if (ret == 0)
|
||||||
|
return retv;
|
||||||
|
snprintf(retv, PATH_MAX-1, "/usr/lib/lxc/lxc-init");
|
||||||
|
ret = stat(retv, &mystat);
|
||||||
|
if (ret == 0)
|
||||||
|
return retv;
|
||||||
|
snprintf(retv, PATH_MAX-1, "/sbin/lxc-init");
|
||||||
|
ret = stat(retv, &mystat);
|
||||||
|
if (ret == 0)
|
||||||
|
return retv;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static int execute_start(struct lxc_handler *handler, void* data)
|
static int execute_start(struct lxc_handler *handler, void* data)
|
||||||
{
|
{
|
||||||
int j, i = 0;
|
int j, i = 0;
|
||||||
struct execute_args *my_args = data;
|
struct execute_args *my_args = data;
|
||||||
char **argv;
|
char **argv;
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
|
char *initpath;
|
||||||
|
|
||||||
while (my_args->argv[argc++]);
|
while (my_args->argv[argc++]);
|
||||||
|
|
||||||
@ -48,7 +81,12 @@ static int execute_start(struct lxc_handler *handler, void* data)
|
|||||||
if (!argv)
|
if (!argv)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
argv[i++] = LXCINITDIR "/lxc-init";
|
initpath = choose_init();
|
||||||
|
if (!initpath) {
|
||||||
|
ERROR("Failed to find an lxc-init");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
argv[i++] = initpath;
|
||||||
if (my_args->quiet)
|
if (my_args->quiet)
|
||||||
argv[i++] = "--quiet";
|
argv[i++] = "--quiet";
|
||||||
argv[i++] = "--";
|
argv[i++] = "--";
|
||||||
|
Loading…
Reference in New Issue
Block a user