From 234e22f635867d7962d22d730fa629bc192aaf42 Mon Sep 17 00:00:00 2001 From: Alex Harpin Date: Mon, 12 Jan 2015 23:24:56 +0000 Subject: vyatta-cfg: fix for "failed to generate commited config" When changes are made to the system by more than one user, only the first user after a reboot is able to commit successfully, the others fail with "Failed to generate committed config". This is caused as a result of the underlying unionfs-fuse mount used for the system configuration and the fact that a .unionfs directory if left in the active configuration with permissions set such that only the original committing user can change them. Bug #403 http://bugzilla.vyos.net/show_bug.cgi?id=403 --- src/cstore/unionfs/cstore-unionfs.cpp | 17 +++++++++++++++++ src/cstore/unionfs/cstore-unionfs.hpp | 1 + 2 files changed, 18 insertions(+) diff --git a/src/cstore/unionfs/cstore-unionfs.cpp b/src/cstore/unionfs/cstore-unionfs.cpp index 2e6f4ad..f253454 100644 --- a/src/cstore/unionfs/cstore-unionfs.cpp +++ b/src/cstore/unionfs/cstore-unionfs.cpp @@ -62,6 +62,7 @@ const string UnionfsCstore::C_MARKER_DEF_VALUE = "def"; const string UnionfsCstore::C_MARKER_DEACTIVATE = ".disable"; const string UnionfsCstore::C_MARKER_CHANGED = ".modified"; const string UnionfsCstore::C_MARKER_UNSAVED = ".unsaved"; +const string UnionfsCstore::C_MARKER_UNIONFS = ".unionfs"; const string UnionfsCstore::C_COMMITTED_MARKER_FILE = ".changes"; const string UnionfsCstore::C_COMMENT_FILE = ".comment"; const string UnionfsCstore::C_TAG_NAME = "node.tag"; @@ -640,6 +641,9 @@ UnionfsCstore::sync_dir(const FsPath& src, const FsPath& dst, bool UnionfsCstore::commitConfig(commit::PrioNode& node) { + FsPath active_unionfs = active_root; + active_unionfs.push(C_MARKER_UNIONFS); + // make a copy of current "work" dir try { if (path_exists(tmp_work_root)) { @@ -651,6 +655,7 @@ UnionfsCstore::commitConfig(commit::PrioNode& node) } output_internal("cp[%s]->[%s]\n", work_root.path_cstr(), tmp_work_root.path_cstr()); + recursive_copy_dir(work_root, tmp_work_root, true); } catch (const b_fs::filesystem_error& e) { output_internal("cp w->tw failed[%s]\n", e.what()); @@ -700,6 +705,18 @@ UnionfsCstore::commitConfig(commit::PrioNode& node) output_user("failed to remove temp directories\n"); return false; } + try { + b_fs::remove_all(active_unionfs.path_cstr()); + } catch (const b_fs::filesystem_error& e) { + output_internal("rm active unionfs failed[%s]\n", e.what()); + return false; + } catch (...) { + output_internal("rm active unionfs[unknown exception]\n"); + return false; + } + if (path_exists(active_unionfs)) { + output_internal("failed to remove unionfs directories from active config\n"); + } // all done return true; } diff --git a/src/cstore/unionfs/cstore-unionfs.hpp b/src/cstore/unionfs/cstore-unionfs.hpp index 4edcfa7..fa504ab 100644 --- a/src/cstore/unionfs/cstore-unionfs.hpp +++ b/src/cstore/unionfs/cstore-unionfs.hpp @@ -78,6 +78,7 @@ private: static const string C_MARKER_DEACTIVATE; static const string C_MARKER_CHANGED; static const string C_MARKER_UNSAVED; + static const string C_MARKER_UNIONFS; static const string C_COMMITTED_MARKER_FILE; static const string C_COMMENT_FILE; static const string C_TAG_NAME; -- cgit v1.2.3