]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: simplify lua debug stack check
authorPatrick Donnelly <pdonnell@redhat.com>
Tue, 13 Oct 2020 16:47:32 +0000 (09:47 -0700)
committerPatrick Donnelly <pdonnell@redhat.com>
Wed, 14 Oct 2020 13:50:53 +0000 (06:50 -0700)
The function should also return 0, i.e. no result.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/rgw/rgw_lua_utils.cc
src/test/rgw/test_rgw_lua.cc

index abb355592d4b1ea7036f847f416aabc7b19e5f83..45ef0e8e5e21d96e02b56ca335b90400ef98c70a 100644 (file)
@@ -24,21 +24,10 @@ int RGWDebugLog(lua_State* L)
 {
   auto cct = reinterpret_cast<CephContext*>(lua_touserdata(L, lua_upvalueindex(1)));
 
-  constexpr auto NUM_RETURN = 0;
-
-  if (!lua_isstring(L, -1)) {
-    if (cct) {
-      ldout(cct, 1) << "Lua ERROR: missing/invalid 'message' parameter when calling Log"  << dendl;
-    }
-    return NUM_RETURN;
-  }
-  const char* message = lua_tostring(L, -1);
-  if (cct) {
-    ldout(cct, 20) << "Lua INFO: " << message << dendl;
-  }
-
-  return NUM_RETURN;
-};
+  auto message = luaL_checkstring(L, 1);
+  ldout(cct, 20) << "Lua INFO: " << message << dendl;
+  return 0;
+}
 
 void create_debug_action(lua_State* L, CephContext* cct) {
   lua_pushlightuserdata(L, cct);
index 632dda114cfa351365d0f74bae1e85a02855abcc..2df08bd3c2812a1de9d3ef068772bee102d6bd62 100644 (file)
@@ -111,6 +111,30 @@ TEST(TestRGWLua, Hello)
   ASSERT_EQ(rc, 0);
 }
 
+TEST(TestRGWLua, RGWDebugLogNumber)
+{
+  const std::string script = R"(
+    RGWDebugLog(1234567890)
+  )";
+
+  DEFINE_REQ_STATE;
+
+  const auto rc = lua::request::execute(nullptr, nullptr, nullptr, &s, "", script);
+  ASSERT_EQ(rc, 0);
+}
+
+TEST(TestRGWLua, RGWDebugNil)
+{
+  const std::string script = R"(
+    RGWDebugLog(nil)
+  )";
+
+  DEFINE_REQ_STATE;
+
+  const auto rc = lua::request::execute(nullptr, nullptr, nullptr, &s, "", script);
+  ASSERT_EQ(rc, -1);
+}
+
 TEST(TestRGWLua, URI)
 {
   const std::string script = R"(