~serge-hallyn/ubuntu/quantal/lxc/lxc-fixapi

« back to all changes in this revision

Viewing changes to src/lxc/start.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2012-04-26 15:18:35 UTC
  • mfrom: (3.1.41 sid)
  • Revision ID: package-import@ubuntu.com-20120426151835-3vz6kb4m90gb26js
Tags: 0.8.0~rc1-4ubuntu1
* Merge from unstable.  Remaining changes:
  - control:
    - update maintainer
    - Build-Depends: add dh-apparmor and libapparmor-dev
    - lxc Depends: add bridge-utils, dnsmasq-base, iptables, rsync
    - lxc Recommends: add cgroup-lite | cgroup-bin, openssl
    - lxc Suggests: add btrfs-tools, lvm2, qemu-user-static
    - lxc Conflicts: remove (cgroup-bin)
  - Add lxc-start-ephemeral and lxc-wait to debian/local
  - apparmor:
    - add lxc.apparmor, lxc-containers.apparmor,
      lxc-default.apparmor, and new lxc.apparmor.in
  - add debian/lxc.conf (default container creation config file)
  - debian/lxc.install.in:
    * add lxc-start-ephemeral
    * add debian/lxc.conf
    * skip lxc-debconf*
    * skip lxc-ls (Use upstream's)
  - debian/lxc*.install.in: use '*', not @DEB_HOST_MULTIARCH@
  - Use our own completely different lxc.postinst and lxc.postrm
  - remove lxc.templates
  - debian/rules:
    * add DEB_DH_INSTALLINIT_ARGS = --upstart-only
    * don't do debconf stuff
    * add debian/*.apparmor.in to files processed under
      override_dh_auto_clean
    * don't comment out ubuntu or busybox templates
    * do apparmor stuff and install our own lxc-wait under override_dh_install
    * install our upstart scripts in override_dh_installinit
  - add lxc.default, lxc.lxc-net.upstart, lxc.upstart under
    debian/

* patches kept:
  - 0013-lxc-create-use-default-config.patch (needed manual rebase)
  - 0030-ubuntu-template-fail.patch
  - 0031-ubuntu-template-resolvconf.patch
  - 0044-lxc-destroy-rm-autos
  - debian/patches/0045-fix-other-templates
  - debian/patches/0046-lxc-clone-change-hwaddr
  - debian/patches/0047-bindhome-check-shell
  - debian/patches/0049-ubuntu-template-sudo-and-cleanup
  - debian/patches/0050-clone-lvm-sizes
  - debian/patches/0052-ubuntu-bind-user-conflict
  - debian/patches/0053-lxc-start-pin-rootfs
  - debian/patches/0054-ubuntu-debug
  - debian/patches/0055-ubuntu-handle-badgrp
  - debian/patches/0056-dont-watch-utmp
  - debian/patches/0057-update-manpages
  - debian/patches/0058-fixup-ubuntu-cloud
  - debian/patches/0059-reenable-daily-cloudimg
  - debian/patches/0060-lxc-shutdown
  - debian/patches/0061-lxc-start-apparmor
  - debian/patches/0062-templates-relative-paths
  - debian/patches/0063-check-apparmor-enabled
  - debian/patches/0064-apparmor-mount-proc
  - debian/patches/0065-fix-bindhome-relpath
  - debian/patches/0066-confile-typo
  - debian/patches/0067-templates-lxc-profile
  - debian/patches/0068-fix-lxc-config-layout 
  - debian/patches/0069-ubuntu-cloud-fix
  - debian/patches/0070-templates-rmdir-dev-shm
  - debian/patches/0071-ubuntu-cloud-fix-image-extraction
  - debian/patches/0072-lxc-shutdown-help
  - debian/patches/0073-lxc-destroy-waits-before-destroy
  - mark all patches which have been forwarded as such, refresh all
* 0074-lxc-execute-find-init: lxc-init had moved.  Introduce a function in
  lxc-execute to go find it.  Otherwise lxc-execute for any older releases
  will fail.
* 0075-lxc-ls-bash: lxc-ls needs bash, not sh
* add debian/lxc.apparmor.in so DEB_HOST_MULTIARCH can be expanded
* 0076-fix-sprintfs:  - check return values for all sprintfs and snprintfs
  which could overflow (LP: #988918)
* 0077-execute-without-rootfs: let lxc-execute succeed with no rootfs
  (LP: #981955)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
22
 */
23
23
 
24
 
#include "../config.h"
 
24
#include "config.h"
 
25
 
25
26
#include <stdio.h>
26
27
#undef _GNU_SOURCE
27
28
#include <string.h>
32
33
#include <signal.h>
33
34
#include <fcntl.h>
34
35
#include <termios.h>
35
 
#include <namespace.h>
36
36
#include <sys/param.h>
37
37
#include <sys/file.h>
38
38
#include <sys/mount.h>
128
128
#include "commands.h"
129
129
#include "console.h"
130
130
#include "sync.h"
 
131
#include "namespace.h"
131
132
 
132
133
lxc_log_define(lxc_start, lxc);
133
134
 
134
 
LXC_TTY_HANDLER(SIGINT);
135
 
LXC_TTY_HANDLER(SIGQUIT);
136
 
 
137
135
static int match_fd(int fd)
138
136
{
139
137
        return (fd == 0 || fd == 1 || fd == 2);
144
142
        struct dirent dirent, *direntp;
145
143
        int fd, fddir;
146
144
        DIR *dir;
147
 
        int ret = 0;
148
145
 
149
146
restart:
150
147
        dir = opendir("/proc/self/fd");
156
153
        fddir = dirfd(dir);
157
154
 
158
155
        while (!readdir_r(dir, &dirent, &direntp)) {
159
 
                char procpath[64];
160
 
                char path[PATH_MAX];
161
 
                int gotpath = 1;
162
 
 
163
156
                if (!direntp)
164
157
                        break;
165
158
 
177
170
                if (match_fd(fd))
178
171
                        continue;
179
172
 
180
 
                snprintf(procpath, sizeof(procpath), "/proc/self/fd/%d", fd);
181
 
                if (readlink(procpath, path, sizeof(path)) == -1)
182
 
                        gotpath = 0;
183
 
 
184
 
                /*
185
 
                 * found inherited fd
186
 
                 */
187
 
 
188
173
                if (conf->close_all_fds) {
189
 
                        if (!gotpath)
190
 
                                INFO("closing inherited fd %d\n", fd);
191
 
                        else
192
 
                                INFO("closing inherited fd %d (%s)", fd, path);
193
174
                        close(fd);
194
175
                        closedir(dir);
 
176
                        INFO("closed inherited fd %d", fd);
195
177
                        goto restart;
196
178
                }
197
 
 
198
 
                ret = -1;
199
 
 
200
 
                snprintf(procpath, sizeof(procpath), "/proc/self/fd/%d", fd);
201
 
 
202
 
                if (!gotpath)
203
 
                        ERROR("readlink(%s) failed : %m", procpath);
204
 
                else
205
 
                        ERROR("inherited fd %d on %s", fd, path);
 
179
                WARN("inherited fd %d", fd);
206
180
        }
207
181
 
208
 
        if (closedir(dir))
209
 
                ERROR("failed to close directory");
210
 
        return ret;
 
182
        closedir(dir); /* cannot fail */
 
183
        return 0;
211
184
}
212
185
 
213
186
static int setup_signal_fd(sigset_t *oldmask)
639
612
 
640
613
                clone_flags |= CLONE_NEWNET;
641
614
 
 
615
                /* Find gateway addresses from the link device, which is
 
616
                 * no longer accessible inside the container. Do this
 
617
                 * before creating network interfaces, since goto
 
618
                 * out_delete_net does not work before lxc_clone. */
 
619
                if (lxc_find_gateway_addresses(handler)) {
 
620
                        ERROR("failed to find gateway addresses");
 
621
                        lxc_sync_fini(handler);
 
622
                        return -1;
 
623
                }
 
624
 
642
625
                /* that should be done before the clone because we will
643
626
                 * fill the netdev index and use them in the child
644
627
                 */
649
632
                }
650
633
        }
651
634
 
652
 
 
653
635
        /*
654
636
         * if the rootfs is not a blockdev, prevent the container from
655
637
         * marking it readonly.
747
729
                goto out_fini;
748
730
        }
749
731
 
750
 
        /* Avoid signals from terminal */
751
 
        LXC_TTY_ADD_HANDLER(SIGINT);
752
 
        LXC_TTY_ADD_HANDLER(SIGQUIT);
753
 
 
754
732
        err = lxc_poll(name, handler);
755
733
        if (err) {
756
734
                ERROR("mainloop exited with an error");
783
761
 
784
762
        err =  lxc_error_set_and_log(handler->pid, status);
785
763
out_fini:
786
 
        LXC_TTY_DEL_HANDLER(SIGQUIT);
787
 
        LXC_TTY_DEL_HANDLER(SIGINT);
788
764
        lxc_cgroup_destroy(name);
789
765
        lxc_fini(name, handler);
790
766
        return err;