vzctl: refactor write_conf()

There were a few bugs:
1. If CT config file was a symlink pointing to a file residing
   on another partition, we failed miserably (bug #1270). To fix,
   use canonicalize_file_name. Bug reported by xavier martin.

2. Return value from write() syscall was not checked in one place.

In addition to fixing the above bugs, the following improvements were made:
1. Buffer for tmpfile is allocated dynamically.
2. Get rid of functionality of writing to stderr, it was never used
   (maybe only for debug, but it's prehistorical).
3. Switched from open/write/close to fopen/fprintf/fclose.
4. Saved (potentially) one syscall for writing '\n'.

Hope I haven't added more bugs...

NOTE1: check (strchr(conf->val, '\n') == NULL) is sufficient here,
since those lines are read by fgets() in read_conf(), so they can
only contain '\n' in the end, not in the middle.

NOTE2: we still do not check fprintf() result properly, since it may
end up writing only part of given string. Not sure if it can hit or not.

http://bugzilla.openvz.org/1270

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
1 file changed