initutils: remove fgets() from lxc_global_con[...]

parent c4382ee2
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "initutils.h" #include "initutils.h"
#include "log.h" #include "log.h"
#include "macro.h" #include "macro.h"
#include "memory_utils.h"
#ifndef HAVE_STRLCPY #ifndef HAVE_STRLCPY
#include "include/strlcpy.h" #include "include/strlcpy.h"
...@@ -115,7 +116,6 @@ const char *lxc_global_config_value(const char *option_name) ...@@ -115,7 +116,6 @@ const char *lxc_global_config_value(const char *option_name)
const char * const (*ptr)[2]; const char * const (*ptr)[2];
size_t i; size_t i;
char buf[1024], *p, *p2;
FILE *fin = NULL; FILE *fin = NULL;
for (i = 0, ptr = options; (*ptr)[0]; ptr++, i++) { for (i = 0, ptr = options; (*ptr)[0]; ptr++, i++) {
...@@ -142,51 +142,64 @@ const char *lxc_global_config_value(const char *option_name) ...@@ -142,51 +142,64 @@ const char *lxc_global_config_value(const char *option_name)
fin = fopen_cloexec(user_config_path, "r"); fin = fopen_cloexec(user_config_path, "r");
free(user_config_path); free(user_config_path);
if (fin) { if (fin) {
while (fgets(buf, 1024, fin)) { __do_free char *line = NULL;
if (buf[0] == '#') size_t len = 0;
char *slider1, *slider2;
while (getline(&line, &len, fin) > 0) {
if (*line == '#')
continue; continue;
p = strstr(buf, option_name);
if (!p) slider1 = strstr(line, option_name);
if (!slider1)
continue; continue;
/* see if there was just white space in front /* see if there was just white space in front
* of the option name * of the option name
*/ */
for (p2 = buf; p2 < p; p2++) { for (slider2 = line; slider2 < slider1; slider2++)
if (*p2 != ' ' && *p2 != '\t') if (*slider2 != ' ' && *slider2 != '\t')
break; break;
}
if (p2 < p) if (slider2 < slider1)
continue; continue;
p = strchr(p, '=');
if (!p) slider1 = strchr(slider1, '=');
if (!slider1)
continue; continue;
/* see if there was just white space after /* see if there was just white space after
* the option name * the option name
*/ */
for (p2 += strlen(option_name); p2 < p; p2++) { for (slider2 += strlen(option_name); slider2 < slider1;
if (*p2 != ' ' && *p2 != '\t') slider2++)
if (*slider2 != ' ' && *slider2 != '\t')
break; break;
}
if (p2 < p) if (slider2 < slider1)
continue; continue;
p++;
while (*p && (*p == ' ' || *p == '\t')) p++; slider1++;
if (!*p) while (*slider1 && (*slider1 == ' ' || *slider1 == '\t'))
slider1++;
if (!*slider1)
continue; continue;
if (strcmp(option_name, "lxc.lxcpath") == 0) { if (strcmp(option_name, "lxc.lxcpath") == 0) {
free(user_lxc_path); free(user_lxc_path);
user_lxc_path = copy_global_config_value(p); user_lxc_path = copy_global_config_value(slider1);
remove_trailing_slashes(user_lxc_path); remove_trailing_slashes(user_lxc_path);
values[i] = user_lxc_path; values[i] = user_lxc_path;
user_lxc_path = NULL; user_lxc_path = NULL;
goto out; goto out;
} }
values[i] = copy_global_config_value(p); values[i] = copy_global_config_value(slider1);
goto out; goto out;
} }
} }
/* could not find value, use default */ /* could not find value, use default */
if (strcmp(option_name, "lxc.lxcpath") == 0) { if (strcmp(option_name, "lxc.lxcpath") == 0) {
remove_trailing_slashes(user_lxc_path); remove_trailing_slashes(user_lxc_path);
......
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