static int configure_find_fstype(const char *rootfs, char *fstype, int mntopt)
{
int i, found;
- char buffer[MAXPATHLEN];
struct cbarg {
const char *rootfs;
found = lxc_file_for_each_line(fsfile[i],
configure_find_fstype_cb,
- buffer, sizeof(buffer), &cbarg);
+ &cbarg);
if (found < 0) {
SYSERROR("failed to read '%s'", fsfile[i]);
static int setup_rootfs_pivot_root(const char *rootfs, const char *pivotdir)
{
- char path[MAXPATHLEN], buffer[MAXPATHLEN];
+ char path[MAXPATHLEN];
void *cbparm[2];
struct lxc_list mountlist, *iterator;
int ok, still_mounted, last_still_mounted;
}
snprintf(path, sizeof(path), "/%s/proc/mounts", pivotdir);
- ok = lxc_file_for_each_line(path,
- setup_rootfs_pivot_root_cb,
- buffer, sizeof(buffer), &cbparm);
+ ok = lxc_file_for_each_line(path, setup_rootfs_pivot_root_cb, &cbparm);
if (ok < 0) {
SYSERROR("failed to read or parse mount list '%s'", path);
return -1;
int lxc_config_read(const char *file, struct lxc_conf *conf)
{
- char buffer[MAXPATHLEN];
-
- return lxc_file_for_each_line(file, parse_line, buffer,
- sizeof(buffer), conf);
+ return lxc_file_for_each_line(file, parse_line, conf);
}
int lxc_config_define_add(struct lxc_list *defines, char* arg)
return ret;
}
-int lxc_file_for_each_line(const char *file, lxc_file_cb callback,
- char *buffer, size_t len, void* data)
+int lxc_file_for_each_line(const char *file, lxc_file_cb callback, void *data)
{
FILE *f;
int err = 0;
+ char *line = NULL;
+ size_t len = 0;
f = fopen(file, "r");
if (!f) {
return -1;
}
- while (fgets(buffer, len, f)) {
- err = callback(buffer, data);
+ while (getline(&line, &len, f) != -1) {
+ err = callback(line, data);
if (err) {
- ERROR("failed to process '%s'", buffer);
- goto out;
+ ERROR("failed to process '%s'", line);
+ break;
}
}
-out:
+
+ if (line)
+ free(line);
fclose(f);
return err;
}
lxc_dir_cb callback, void *data);
extern int lxc_file_for_each_line(const char *file, lxc_file_cb callback,
- char *buffer, size_t len, void* data);
+ void* data);
extern int lxc_char_left_gc(char *buffer, size_t len);