From: Serge Hallyn <serge.hal...@ubuntu.com>

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.hal...@ubuntu.com>
---
 src/lxc/lxc_user_nic.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/lxc/lxc_user_nic.c b/src/lxc/lxc_user_nic.c
index 4154e83..ff5393e 100644
--- a/src/lxc/lxc_user_nic.c
+++ b/src/lxc/lxc_user_nic.c
@@ -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);
-- 
1.8.3.2


------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation.
Intel(R) Software Adrenaline delivers strategic insight and game-changing 
conversations that shape the rapidly evolving mobile landscape. Sign up now. 
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to