summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog20
-rw-r--r--TODO2
-rw-r--r--sbuild/sbuild-chroot.cc33
-rw-r--r--sbuild/sbuild-chroot.h9
-rw-r--r--sbuild/sbuild-keyfile.h112
-rw-r--r--sbuild/sbuild-personality.cc16
-rw-r--r--sbuild/sbuild-personality.h48
7 files changed, 128 insertions, 112 deletions
diff --git a/ChangeLog b/ChangeLog
index 31c00e61..dbae8974 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,25 @@
2006-07-17 Roger Leigh <rleigh@debian.org>
+ * TODO: Remove completed item.
+
+ * sbuild/sbuild-chroot.cc
+ (set_persona): Remove method overloaded for a string.
+ (get_keyfile): Use keyfile::set_object_value for the personality.
+ (set_keyfile): Use keyfile::get_object_value for the personality.
+
+ * sbuild/sbuild-personality.cc: Add a BAD error code for when the
+ personality name is invalid.
+ (get_personalities): Renamed from print_personalities. Create a
+ string, rather than printing to an ostream.
+
+ * sbuild/sbuild-personality.h: Add stream input operator, to set
+ the personality from a stream.
+
+ * sbuild/sbuild-keyfile.h: Move all logic in get_object_value into
+ the try block, to catch and report parse errors in T parsing.
+
+2006-07-17 Roger Leigh <rleigh@debian.org>
+
* dchroot/dchroot.1.in, dchroot-dsa/dchroot-dsa.1.in: Use "users"
instead of "user list", so that the user list name matches the
keyfile key name used in error messages.
diff --git a/TODO b/TODO
index a45b6eed..ec91b732 100644
--- a/TODO
+++ b/TODO
@@ -9,8 +9,6 @@ the Doxygen-generated documentation in doc/schroot/html/todo.html
PENDING
-------
-* personality should include stream operators for serialisation.
-
* Remove all non error-map format strings.
- convert to error<> derived messages wherever possible. This is
diff --git a/sbuild/sbuild-chroot.cc b/sbuild/sbuild-chroot.cc
index 6a3b9af6..69d5c7c9 100644
--- a/sbuild/sbuild-chroot.cc
+++ b/sbuild/sbuild-chroot.cc
@@ -71,7 +71,6 @@ namespace
emap(sbuild::chroot::FILE_STAT, N_("Failed to stat file")),
emap(sbuild::chroot::FILE_UNLOCK, N_("Failed to discard file lock")),
emap(sbuild::chroot::LOCATION_ABS, N_("Location must have an absolute path")),
- emap(sbuild::chroot::PERSONALITY_BAD, N_("Personality '%1%' is unknown")),
emap(sbuild::chroot::SESSION_UNLINK, N_("Failed to unlink session file")),
emap(sbuild::chroot::SESSION_WRITE, N_("Failed to write session file"))
};
@@ -357,28 +356,6 @@ sbuild::chroot::set_persona (personality const& persona)
}
void
-sbuild::chroot::set_persona (std::string const& persona)
-{
- personality new_persona (persona);
-
- if (new_persona.get_name() == "undefined" &&
- new_persona.get_name() != persona)
- {
- std::ostringstream plist;
- personality::print_personalities(plist);
-
- error e(persona, PERSONALITY_BAD);
- format fmt(_("Valid personalities: %1%\n"));
- fmt % plist.str();
- e.set_reason(fmt.str());
-
- throw e;
- }
-
- set_persona(new_persona);
-}
-
-void
sbuild::chroot::setup_env (environment& env)
{
env.add("CHROOT_TYPE", get_chroot_type());
@@ -551,9 +528,8 @@ sbuild::chroot::get_keyfile (keyfile& keyfile) const
keyfile::set_object_list_value(*this, &chroot::get_command_prefix,
keyfile, get_name(), "command-prefix");
- // TODO: Add stream operators to persona.
- keyfile.set_value(get_name(), "personality",
- get_persona().get_name());
+ keyfile::set_object_value(*this, &chroot::get_persona,
+ keyfile, get_name(), "personality");
}
void
@@ -620,12 +596,9 @@ sbuild::chroot::set_keyfile (keyfile const& keyfile)
keyfile, get_name(), "command-prefix",
keyfile::PRIORITY_OPTIONAL);
- void (chroot::* pptr)(std::string const& persona);
- pptr = &chroot::set_persona;
- keyfile::get_object_value(*this, pptr,
+ keyfile::get_object_value(*this, &chroot::set_persona,
keyfile, get_name(), "personality",
keyfile::PRIORITY_OPTIONAL);
-
}
/*
diff --git a/sbuild/sbuild-chroot.h b/sbuild/sbuild-chroot.h
index a8262b34..06810e62 100644
--- a/sbuild/sbuild-chroot.h
+++ b/sbuild/sbuild-chroot.h
@@ -78,7 +78,6 @@ namespace sbuild
FILE_STAT, ///< Failed to stat file.
FILE_UNLOCK, ///< Failed to discard lock.
LOCATION_ABS, ///< Location must have an absolute path.
- PERSONALITY_BAD, ///< Personality is unknown.
SESSION_UNLINK, ///< Failed to unlink session file.
SESSION_WRITE ///< Failed to write session file.
};
@@ -423,14 +422,6 @@ namespace sbuild
set_persona (personality const& persona);
/**
- * Set the process execution domain for the chroot.
- *
- * @param persona the personality.
- */
- void
- set_persona (std::string const& persona);
-
- /**
* Get the type of the chroot.
*
* @returns the chroot type.
diff --git a/sbuild/sbuild-keyfile.h b/sbuild/sbuild-keyfile.h
index 4ea39c5b..7cff8085 100644
--- a/sbuild/sbuild-keyfile.h
+++ b/sbuild/sbuild-keyfile.h
@@ -996,21 +996,19 @@ namespace sbuild
std::string const& key,
keyfile::priority priority)
{
- T value;
- if (keyfile.get_value(group, key, priority, value))
+ try
{
- try
- {
- (object.*method)(value);
- }
- catch (std::runtime_error const& e)
- {
- unsigned int line = keyfile.get_line(group, key);
- if (line)
- throw error(line, group, key, PASSTHROUGH_LGK, e);
- else
- throw error(group, key, PASSTHROUGH_GK, e);
- }
+ T value;
+ if (keyfile.get_value(group, key, priority, value))
+ (object.*method)(value);
+ }
+ catch (std::runtime_error const& e)
+ {
+ unsigned int line = keyfile.get_line(group, key);
+ if (line)
+ throw error(line, group, key, PASSTHROUGH_LGK, e);
+ else
+ throw error(group, key, PASSTHROUGH_GK, e);
}
}
@@ -1037,21 +1035,19 @@ namespace sbuild
std::string const& key,
keyfile::priority priority)
{
- T value;
- if (keyfile.get_value(group, key, priority, value))
+ try
{
- try
- {
- (object.*method)(value);
- }
- catch (std::runtime_error const& e)
- {
- unsigned int line = keyfile.get_line(group, key);
- if (line)
- throw error(line, group, key, PASSTHROUGH_LGK, e);
- else
- throw error(group, key, PASSTHROUGH_GK, e);
- }
+ T value;
+ if (keyfile.get_value(group, key, priority, value))
+ (object.*method)(value);
+ }
+ catch (std::runtime_error const& e)
+ {
+ unsigned int line = keyfile.get_line(group, key);
+ if (line)
+ throw error(line, group, key, PASSTHROUGH_LGK, e);
+ else
+ throw error(group, key, PASSTHROUGH_GK, e);
}
}
@@ -1078,23 +1074,21 @@ namespace sbuild
std::string const& key,
keyfile::priority priority)
{
- T value;
- if (keyfile.get_list_value(group, key, priority, value))
+ try
{
- try
- {
- (object.*method)(value);
- }
- catch (std::runtime_error const& e)
- {
- unsigned int line = keyfile.get_line(group, key);
- if (line)
- throw error(line, group, key, PASSTHROUGH_LGK, e);
- else
- throw error(group, key, PASSTHROUGH_GK, e);
- throw error(keyfile.get_line(group, key),
- group, key, e);
- }
+ T value;
+ if (keyfile.get_list_value(group, key, priority, value))
+ (object.*method)(value);
+ }
+ catch (std::runtime_error const& e)
+ {
+ unsigned int line = keyfile.get_line(group, key);
+ if (line)
+ throw error(line, group, key, PASSTHROUGH_LGK, e);
+ else
+ throw error(group, key, PASSTHROUGH_GK, e);
+ throw error(keyfile.get_line(group, key),
+ group, key, e);
}
}
@@ -1122,23 +1116,21 @@ namespace sbuild
std::string const& key,
keyfile::priority priority)
{
- T value;
- if (keyfile.get_list_value(group, key, priority, value))
+ try
{
- try
- {
- (object.*method)(value);
- }
- catch (std::runtime_error const& e)
- {
- unsigned int line = keyfile.get_line(group, key);
- if (line)
- throw error(line, group, key, PASSTHROUGH_LGK, e);
- else
- throw error(group, key, PASSTHROUGH_GK, e);
- throw error(keyfile.get_line(group, key),
- group, key, e);
- }
+ T value;
+ if (keyfile.get_list_value(group, key, priority, value))
+ (object.*method)(value);
+ }
+ catch (std::runtime_error const& e)
+ {
+ unsigned int line = keyfile.get_line(group, key);
+ if (line)
+ throw error(line, group, key, PASSTHROUGH_LGK, e);
+ else
+ throw error(group, key, PASSTHROUGH_GK, e);
+ throw error(keyfile.get_line(group, key),
+ group, key, e);
}
}
};
diff --git a/sbuild/sbuild-personality.cc b/sbuild/sbuild-personality.cc
index 112f7ccf..a5773312 100644
--- a/sbuild/sbuild-personality.cc
+++ b/sbuild/sbuild-personality.cc
@@ -45,6 +45,7 @@ namespace
*/
emap init_errors[] =
{
+ emap(sbuild::personality::BAD, N_("Personality '%1%' is unknown")),
emap(sbuild::personality::SET, N_("Failed to set personality '%1%'"))
};
@@ -168,18 +169,25 @@ sbuild::personality::set () const
#endif
}
-void
-sbuild::personality::print_personalities (std::ostream& stream)
+std::string
+sbuild::personality::get_personalities ()
{
+ format fmt(_("Valid personalities: %1%\n"));
+ std::string ps;
+
for (std::map<std::string,type>::const_iterator pos = personalities.begin();
pos != personalities.end();
++pos)
{
- stream << pos->first;
+ ps += pos->first;
std::map<std::string,type>::const_iterator stpos = pos;
if (++stpos != personalities.end())
- stream << ", ";
+ ps += ", ";
}
+
+ fmt % ps;
+
+ return fmt.str();
}
/*
diff --git a/sbuild/sbuild-personality.h b/sbuild/sbuild-personality.h
index 14a5aa8e..281175b9 100644
--- a/sbuild/sbuild-personality.h
+++ b/sbuild/sbuild-personality.h
@@ -47,7 +47,8 @@ namespace sbuild
/// Error codes.
enum error_code
{
- SET ///< Could not set personality.
+ BAD, ///< Personality is unknown.
+ SET ///< Could not set personality.
};
/// Exception type.
@@ -103,10 +104,41 @@ namespace sbuild
/**
* Print a list of the available personalities.
*
- * @param stream the stream to output to.
+ * @returns a string of the available personalities.
+ */
+ static std::string
+ get_personalities ();
+
+ /**
+ * Get the personality name from a stream.
+ *
+ * @param stream the stream to get input from.
+ * @param rhs the personality to set.
+ * @returns the stream.
*/
- static void
- print_personalities (std::ostream& stream);
+ template <class charT, class traits>
+ friend
+ std::basic_istream<charT,traits>&
+ operator >> (std::basic_istream<charT,traits>& stream,
+ personality& rhs)
+ {
+ std::string personality_name;
+
+ if (std::getline(stream, personality_name))
+ {
+ rhs.persona = find_personality(personality_name);
+
+ if (rhs.get_name() == "undefined" &&
+ rhs.get_name() != personality_name)
+ {
+ personality::error e(personality_name, personality::BAD);
+ e.set_reason(personality::get_personalities());
+ throw e;
+ }
+ }
+
+ return stream;
+ }
/**
* Print the personality name to a stream.
@@ -115,9 +147,11 @@ namespace sbuild
* @param rhs the personality to output.
* @returns the stream.
*/
- friend std::ostream&
- operator << (std::ostream& stream,
- personality const& rhs)
+ template <class charT, class traits>
+ friend
+ std::basic_ostream<charT,traits>&
+ operator << (std::basic_ostream<charT,traits>& stream,
+ personality const& rhs)
{
return stream << find_personality(rhs.persona);
}