shill: Almost complete support for terminating dhcpcd.

BUG=chromium-os:16365,chromium-os:16013
TEST=unit tests

Change-Id: I00a46e8364fc4de3cc48ef72c1b0a9a88e95e6a0
Reviewed-on: http://gerrit.chromium.org/gerrit/2435
Tested-by: Darin Petkov <petkov@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
diff --git a/dhcp_config.h b/dhcp_config.h
index 0e25873..6d4ca2b 100644
--- a/dhcp_config.h
+++ b/dhcp_config.h
@@ -5,7 +5,9 @@
 #ifndef SHILL_DHCP_CONFIG_
 #define SHILL_DHCP_CONFIG_
 
+#include <base/file_path.h>
 #include <base/memory/scoped_ptr.h>
+#include <glib.h>
 #include <gtest/gtest_prod.h>  // for FRIEND_TEST
 #include <dbus-c++/connection.h>
 
@@ -40,8 +42,9 @@
   virtual ~DHCPConfig();
 
   // Inherited from IPConfig.
-  virtual bool Request();
-  virtual bool Renew();
+  virtual bool RequestIP();
+  virtual bool RenewIP();
+  virtual bool ReleaseIP();
 
   // If |proxy_| is not initialized already, sets it to a new D-Bus proxy to
   // |service|.
@@ -54,13 +57,19 @@
  private:
   FRIEND_TEST(DHCPConfigTest, GetIPv4AddressString);
   FRIEND_TEST(DHCPConfigTest, ParseConfiguration);
-  FRIEND_TEST(DHCPConfigTest, Start);
+  FRIEND_TEST(DHCPConfigTest, StartFail);
+  FRIEND_TEST(DHCPConfigTest, StartSuccess);
 
   static const char kDHCPCDPath[];
+  static const char kDHCPCDPathFormatLease[];
+  static const char kDHCPCDPathFormatPID[];
 
   // Starts dhcpcd, returns true on success and false otherwise.
   bool Start();
 
+  // Stops dhcpcd if running.
+  void Stop();
+
   // Parses |configuration| into |properties|. Returns true on success, and
   // false otherwise.
   bool ParseConfiguration(const Configuration& configuration,
@@ -70,15 +79,26 @@
   // empty string on failure.
   std::string GetIPv4AddressString(unsigned int address);
 
+  // Called when the dhcpcd client process exits.
+  static void ChildWatchCallback(GPid pid, gint status, gpointer data);
+
+  void CleanupClientState();
+
   DHCPProvider *provider_;
 
   // The PID of the spawned DHCP client. May be 0 if no client has been spawned
   // yet or the client has died.
-  unsigned int pid_;
+  int pid_;
+
+  // Child exit watch callback source tag.
+  unsigned int child_watch_tag_;
 
   // The proxy for communicating with the DHCP client.
   scoped_ptr<DHCPProxyInterface> proxy_;
 
+  // Root file path, used for testing.
+  FilePath root_;
+
   GLibInterface *glib_;
 
   DISALLOW_COPY_AND_ASSIGN(DHCPConfig);