Commit 8c81de19 by Serge Hallyn

lxc_user_nic: fix get_allotted description.

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: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent c8f73ce2
...@@ -138,12 +138,10 @@ char *get_username(void) ...@@ -138,12 +138,10 @@ char *get_username(void)
/* The configuration file consists of lines of the form: /* 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 * Return the count entry for the calling user if there is one. Else
* every listed nic is still present. Any nics which have disappeared * return -1.
* is removed when we count, in case the container died a harsh death
* without being able to clean up after itself.
*/ */
int get_alloted(char *me, char *intype, char *link) int get_alloted(char *me, char *intype, char *link)
{ {
...@@ -153,8 +151,11 @@ 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; size_t len = 0;
int n = -1, ret; int n = -1, ret;
if (!fin) if (!fin) {
fprintf(stderr, "Failed to open %s: %s\n", CONF_FILE,
strerror(errno));
return -1; return -1;
}
while ((getline(&line, &len, fin)) != -1) { while ((getline(&line, &len, fin)) != -1) {
ret = sscanf(line, "%99[^ \t] %99[^ \t] %99[^ \t] %d", user, type, br, &n); 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) ...@@ -168,6 +169,7 @@ int get_alloted(char *me, char *intype, char *link)
if (strcmp(link, br) != 0) if (strcmp(link, br) != 0)
continue; continue;
free(line); free(line);
fclose(fin);
return n; return n;
} }
fclose(fin); fclose(fin);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment