]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc_user_nic: fix get_allotted description.
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 19 Nov 2013 16:17:49 +0000 (16:17 +0000)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 19 Nov 2013 22:27:02 +0000 (16:27 -0600)
get_allotted doesn't get the list of nic names, only the # of nics
allowed to the user.  We check the db_file later for existing
number of nics.

Also close the conf file on success, and print filename and errno
if we failed to open conf file.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/lxc_user_nic.c

index 4154e8341b7b8445e147517b6b6a85c9dcda6a60..ff5393e48724b2369cec33f4c8f7856f201e4c37 100644 (file)
@@ -138,12 +138,10 @@ char *get_username(void)
 
 /* The configuration file consists of lines of the form:
  *
- * user type bridge nic-name count
+ * user type bridge count
  *
- * We simply count the number of lines in the file, making sure that
- * every listed nic is still present.  Any nics which have disappeared
- * is removed when we count, in case the container died a harsh death
- * without being able to clean up after itself.
+ * Return the count entry for the calling user if there is one.  Else
+ * return -1.
  */
 int get_alloted(char *me, char *intype, char *link)
 {
@@ -153,8 +151,11 @@ int get_alloted(char *me, char *intype, char *link)
        size_t len = 0;
        int n = -1, ret;
 
-       if (!fin)
+       if (!fin) {
+               fprintf(stderr, "Failed to open %s: %s\n", CONF_FILE,
+                       strerror(errno));
                return -1;
+       }
 
        while ((getline(&line, &len, fin)) != -1) {
                ret = sscanf(line, "%99[^ \t] %99[^ \t] %99[^ \t] %d", user, type, br, &n);
@@ -168,6 +169,7 @@ int get_alloted(char *me, char *intype, char *link)
                if (strcmp(link, br) != 0)
                        continue;
                free(line);
+               fclose(fin);
                return n;
        }
        fclose(fin);