style: cppcheck cleanup

[command/guid.cpp:37]: (style) The scope of the variable 'rc' can be
reduced.
[socket_channel.hpp:44]: (performance) Variable 'timeout' is assigned
in constructor body. Consider performing initialization in
initialization list.
[sd_event_loop.cpp:107]: (style) The scope of the variable 'instance'
can be reduced.
[sd_event_loop.cpp:108]: (style) The scope of the variable 'rc' can be
reduced.
[sd_event_loop.cpp:142]: (style) The scope of the variable 'instance'
can be reduced.
[sd_event_loop.cpp:304]: (style) The scope of the variable 'rc' can be
reduced.

Change-Id: Id090cb217ea7ed9019f1b8d39ebebd6bb73113b1
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/command/guid.cpp b/command/guid.cpp
index 67b71e2..8cd95a6 100644
--- a/command/guid.cpp
+++ b/command/guid.cpp
@@ -34,13 +34,12 @@
     sd_bus_message* reply = nullptr;
     sd_bus_error error = SD_BUS_ERROR_NULL;
     sd_bus* bus = ipmid_get_sd_bus_connection();
-    int rc = 0;
     char* uuid = nullptr;
     char* busname = nullptr;
 
     do
     {
-        rc = mapper_get_service(bus, guidObjPath, &busname);
+        int rc = mapper_get_service(bus, guidObjPath, &busname);
         if (rc < 0)
         {
             std::cerr << "Failed to get " << guidObjPath
diff --git a/sd_event_loop.cpp b/sd_event_loop.cpp
index 7ec4db9..a5fd41d 100644
--- a/sd_event_loop.cpp
+++ b/sd_event_loop.cpp
@@ -104,20 +104,20 @@
 static int charAccTimerHandler(sd_event_source* s, uint64_t usec,
                                void* userdata)
 {
-    // The instance is hardcoded to 1, in the case of supporting multiple
-    // payload instances we would need to populate it from userdata
-    uint8_t instance = 1;
-    int rc = 0;
     auto bufferSize = std::get<sol::Manager&>(singletonPool).dataBuffer.size();
 
     try
     {
+        // The instance is hardcoded to 1, in the case of supporting multiple
+        // payload instances we would need to populate it from userdata
+        uint8_t instance = 1;
+
         if (bufferSize > 0)
         {
             auto& context =
                 std::get<sol::Manager&>(singletonPool).getContext(instance);
 
-            rc = context.sendOutboundPayload();
+            int rc = context.sendOutboundPayload();
 
             if (rc == 0)
             {
@@ -138,12 +138,12 @@
 
 static int retryTimerHandler(sd_event_source* s, uint64_t usec, void* userdata)
 {
-    // The instance is hardcoded to 1, in the case of supporting multiple
-    // payload instances we would need to populate it from userdata
-    uint8_t instance = 1;
-
     try
     {
+        // The instance is hardcoded to 1, in the case of supporting multiple
+        // payload instances we would need to populate it from userdata
+        uint8_t instance = 1;
+
         auto& context =
             std::get<sol::Manager&>(singletonPool).getContext(instance);
 
@@ -302,12 +302,10 @@
 
 void EventLoop::stopHostConsole()
 {
-    int rc = 0;
-
     if (hostConsole.get())
     {
         // Disable the host console payload
-        rc = sd_event_source_set_enabled(hostConsole.get(), SD_EVENT_OFF);
+        int rc = sd_event_source_set_enabled(hostConsole.get(), SD_EVENT_OFF);
         if (rc < 0)
         {
             log<level::ERR>("Failed to disable the host console socket",
diff --git a/socket_channel.hpp b/socket_channel.hpp
index 8a2edce..4b10b9a 100644
--- a/socket_channel.hpp
+++ b/socket_channel.hpp
@@ -38,10 +38,9 @@
      *
      * @return None
      */
-    Channel(int insockfd, timeval& inTimeout)
+    Channel(int insockfd, timeval& inTimeout) :
+        sockfd(insockfd), timeout(inTimeout)
     {
-        sockfd = insockfd;
-        timeout = inTimeout;
     }
 
     /**