/* for lxc-wait */
char *states;
+ /* close fds from parent? */
+ int close_all_fds;
+
/* remaining arguments */
char *const *argv;
int argc;
struct lxc_console console;
struct lxc_rootfs rootfs;
char *ttydir;
+ int close_all_fds;
};
/*
.quiet = quiet
};
- if (lxc_check_inherited(-1))
+ if (lxc_check_inherited(conf, -1))
return -1;
return __lxc_start(name, conf, &execute_start_ops, &args);
{
switch (c) {
case 'c': args->console = arg; break;
- case 'd': args->daemonize = 1; break;
+ case 'd': args->daemonize = 1; args->close_all_fds = 1; break;
case 'f': args->rcfile = arg; break;
+ case 'C': args->close_all_fds = 1; break;
case 's': return lxc_config_define_add(&defines, arg);
}
return 0;
{"rcfile", required_argument, 0, 'f'},
{"define", required_argument, 0, 's'},
{"console", required_argument, 0, 'c'},
+ {"close-all-fds", no_argument, 0, 'C'},
LXC_COMMON_OPTIONS
};
-d, --daemon daemonize the container\n\
-f, --rcfile=FILE Load 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\
+ If not specified, exit with failure instead\n\
+ Note: --daemon implies --close-all-fds\n\
-s, --define KEY=VAL Assign VAL to configuration variable KEY\n",
.options = my_longopts,
.parser = my_parser,
return err;
}
+ if (my_args.close_all_fds)
+ conf->close_all_fds = 1;
+
err = lxc_start(my_args.name, args, conf);
/*
.flags = flags
};
- if (lxc_check_inherited(sfd))
+ if (lxc_check_inherited(conf, sfd))
return -1;
return __lxc_start(name, conf, &restart_ops, &restart_arg);
return (fd == 0 || fd == 1 || fd == 2);
}
-int lxc_check_inherited(int fd_to_ignore)
+int lxc_check_inherited(struct lxc_conf *conf, int fd_to_ignore)
{
struct dirent dirent, *direntp;
int fd, fddir;
DIR *dir;
+restart:
dir = opendir("/proc/self/fd");
if (!dir) {
WARN("failed to open directory: %m");
if (match_fd(fd))
continue;
+ if (conf->close_all_fds) {
+ close(fd);
+ closedir(dir);
+ INFO("closed inherited fd %d", fd);
+ goto restart;
+ }
WARN("inherited fd %d", fd);
}
.argv = argv,
};
- if (lxc_check_inherited(-1))
+ if (lxc_check_inherited(conf, -1))
return -1;
conf->need_utmp_watch = 1;
extern void lxc_abort(const char *name, struct lxc_handler *handler);
extern void lxc_fini(const char *name, struct lxc_handler *handler);
extern int lxc_set_state(const char *, struct lxc_handler *, lxc_state_t);
-extern int lxc_check_inherited(int fd_to_ignore);
+extern int lxc_check_inherited(struct lxc_conf *conf, int fd_to_ignore);
int __lxc_start(const char *, struct lxc_conf *, struct lxc_operations *,
void *);