~ubuntu-branches/ubuntu/precise/lxc/precise-updates

« back to all changes in this revision

Viewing changes to src/lxc/conf.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2012-03-21 08:20:06 UTC
  • Revision ID: package-import@ubuntu.com-20120321082006-bsepg8w3z7qb79xt
Tags: 0.7.5-3ubuntu41
* add lxc-shutdown command:
  - 0060-lxc-shutdown: add the command to the source
  - debian/lxc.upstart: use lxc-shutdown to shut down containers cleanly
  - debian/lxc.default: add LXC_SHUTDOWN_TIMEOUT (default 120s)
* support per-container apparmor policies:  (LP: #953453)
  - 0061-lxc-start-apparmor: add lxc.aa_profile to config file.  If not
    specified, lxc-default profile is used for container.  Otherwise, the
    specified profile is used.
    Note that per-container profiles must be named 'lxc-*'.
  - split debian/lxc-default.apparmor from debian/lxc.apparmor.
  - have /etc/apparmor.d/lxc-containers #include /etc/apparmor.d/lxc/*
  - debian/lxc.postinst: load the new lxc-containers profiles
  - debian/lxc.postrm: remove lxc-containers profiles
  - debian/rules: make new etc/apparmor.d/lxc dir and copy lxc-default into it
  - debian/control: add libapparmor-dev to build-depends
  - debian/lxc.upstart: load apparmor per-container policies at pre-start.
* debian/lxc.apparmor: insert the stricter mount rules for lxc-start
  (LP: #645625) (LP: #942934)
* debian/local/lxc-start-ephemeral: re-enable aufs option (LP: #960262)
* replace upstream lxc-wait with our own bash script (LP: #951181)
  - debian/local/lxc-wait: the script
  - debian/rules: copy the script into place
* 0062-templates-relative-paths: update templates to use relative paths,
  and make lxc-start always accept /var/lib/lxc/CN/rootfs as target prefix,
  to make lvm containers work.  (LP: #960860)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1135
1135
}
1136
1136
 
1137
1137
static int mount_entry_on_absolute_rootfs(struct mntent *mntent,
1138
 
                                          const struct lxc_rootfs *rootfs)
 
1138
                                          const struct lxc_rootfs *rootfs,
 
1139
                                          const char *lxc_name)
1139
1140
{
1140
1141
        char *aux;
1141
1142
        char path[MAXPATHLEN];
1142
1143
        unsigned long mntflags;
1143
1144
        char *mntdata;
1144
 
        int ret = 0;
 
1145
        int r, ret = 0, offset;
1145
1146
 
1146
1147
        if (parse_mntopts(mntent->mnt_opts, &mntflags, &mntdata) < 0) {
1147
1148
                ERROR("failed to parse mount option '%s'", mntent->mnt_opts);
1148
1149
                return -1;
1149
1150
        }
1150
1151
 
 
1152
        /* if rootfs->path is a blockdev path, allow container fstab to
 
1153
         * use /var/lib/lxc/CN/rootfs as the target prefix */
 
1154
        r = snprintf(path, MAXPATHLEN, "/var/lib/lxc/%s/rootfs", lxc_name);
 
1155
        if (r < 0 || r >= MAXPATHLEN)
 
1156
                goto skipvarlib;
 
1157
 
 
1158
        aux = strstr(mntent->mnt_dir, path);
 
1159
        if (aux) {
 
1160
                offset = strlen(path);
 
1161
                goto skipabs;
 
1162
        }
 
1163
 
 
1164
skipvarlib:
1151
1165
        aux = strstr(mntent->mnt_dir, rootfs->path);
1152
1166
        if (!aux) {
1153
1167
                WARN("ignoring mount point '%s'", mntent->mnt_dir);
1154
1168
                goto out;
1155
1169
        }
 
1170
        offset = strlen(rootfs->path);
 
1171
 
 
1172
skipabs:
1156
1173
 
1157
1174
        snprintf(path, MAXPATHLEN, "%s/%s", rootfs->mount,
1158
 
                 aux + strlen(rootfs->path));
 
1175
                 aux + offset);
 
1176
        if (r < 0 || r >= MAXPATHLEN) {
 
1177
                WARN("pathnme too long for '%s'", mntent->mnt_dir);
 
1178
                ret = -1;
 
1179
                goto out;
 
1180
        }
 
1181
 
1159
1182
 
1160
1183
        ret = mount_entry(mntent->mnt_fsname, path, mntent->mnt_type,
1161
1184
                          mntflags, mntdata);
1189
1212
        return ret;
1190
1213
}
1191
1214
 
1192
 
static int mount_file_entries(const struct lxc_rootfs *rootfs, FILE *file)
 
1215
static int mount_file_entries(const struct lxc_rootfs *rootfs, FILE *file,
 
1216
        const char *lxc_name)
1193
1217
{
1194
1218
        struct mntent *mntent;
1195
1219
        int ret = -1;
1210
1234
                        continue;
1211
1235
                }
1212
1236
 
1213
 
                if (mount_entry_on_absolute_rootfs(mntent, rootfs))
 
1237
                if (mount_entry_on_absolute_rootfs(mntent, rootfs, lxc_name))
1214
1238
                        goto out;
1215
1239
        }
1216
1240
 
1221
1245
        return ret;
1222
1246
}
1223
1247
 
1224
 
static int setup_mount(const struct lxc_rootfs *rootfs, const char *fstab)
 
1248
static int setup_mount(const struct lxc_rootfs *rootfs, const char *fstab,
 
1249
        const char *lxc_name)
1225
1250
{
1226
1251
        FILE *file;
1227
1252
        int ret;
1235
1260
                return -1;
1236
1261
        }
1237
1262
 
1238
 
        ret = mount_file_entries(rootfs, file);
 
1263
        ret = mount_file_entries(rootfs, file, lxc_name);
1239
1264
 
1240
1265
        endmntent(file);
1241
1266
        return ret;
1242
1267
}
1243
1268
 
1244
 
static int setup_mount_entries(const struct lxc_rootfs *rootfs, struct lxc_list *mount)
 
1269
static int setup_mount_entries(const struct lxc_rootfs *rootfs, struct lxc_list *mount,
 
1270
        const char *lxc_name)
1245
1271
{
1246
1272
        FILE *file;
1247
1273
        struct lxc_list *iterator;
1261
1287
 
1262
1288
        rewind(file);
1263
1289
 
1264
 
        ret = mount_file_entries(rootfs, file);
 
1290
        ret = mount_file_entries(rootfs, file, lxc_name);
1265
1291
 
1266
1292
        fclose(file);
1267
1293
        return ret;
1523
1549
        lxc_list_init(&new->network);
1524
1550
        lxc_list_init(&new->mount_list);
1525
1551
        lxc_list_init(&new->caps);
 
1552
        new->aa_profile = NULL;
1526
1553
 
1527
1554
        return new;
1528
1555
}
1870
1897
                return -1;
1871
1898
        }
1872
1899
 
1873
 
        if (setup_mount(&lxc_conf->rootfs, lxc_conf->fstab)) {
 
1900
        if (setup_mount(&lxc_conf->rootfs, lxc_conf->fstab, name)) {
1874
1901
                ERROR("failed to setup the mounts for '%s'", name);
1875
1902
                return -1;
1876
1903
        }
1877
1904
 
1878
 
        if (setup_mount_entries(&lxc_conf->rootfs, &lxc_conf->mount_list)) {
 
1905
        if (setup_mount_entries(&lxc_conf->rootfs, &lxc_conf->mount_list, name)) {
1879
1906
                ERROR("failed to setup the mount entries for '%s'", name);
1880
1907
                return -1;
1881
1908
        }