From c2d998b0c5fdb7c85576f9b3ecbb13960ddf2a0c Mon Sep 17 00:00:00 2001 From: Roger Zhong Date: Tue, 5 Apr 2022 16:00:07 -0700 Subject: [PATCH] fix formatting --- source/main.cpp | 3 +- source/util/LockFileUtils.cpp | 9 +++--- source/util/LockFileUtils.h | 54 ++++++++++++++++----------------- test/util/TestLockFileUtils.cpp | 2 -- 4 files changed, 31 insertions(+), 37 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index 63b364fb8..b4fc14a29 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -7,8 +7,8 @@ #include "Version.h" #include "config/Config.h" #include "util/EnvUtils.h" -#include "util/Retry.h" #include "util/LockFileUtils.h" +#include "util/Retry.h" #if !defined(EXCLUDE_DD) @@ -57,7 +57,6 @@ #include #include #include -#include using namespace std; using namespace Aws::Iot::DeviceClient; diff --git a/source/util/LockFileUtils.cpp b/source/util/LockFileUtils.cpp index 8ef3833ff..1d528967b 100644 --- a/source/util/LockFileUtils.cpp +++ b/source/util/LockFileUtils.cpp @@ -1,11 +1,11 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +#include "LockFileUtils.h" #include #include -#include #include -#include "LockFileUtils.h" +#include using namespace std; using namespace Aws::Iot::DeviceClient::Util; @@ -25,7 +25,7 @@ int LockFileUtils::ProcessLock() string storedPid; if (fileIn >> storedPid) { - //sets flag if process exists and contains name + // sets flag if process exists and contains name if (!(kill(stoi(storedPid), 0) == -1 && errno == ESRCH)) { string path = "/proc/" + storedPid + "/cmdline"; @@ -62,9 +62,8 @@ void LockFileUtils::WriteToLockFile(const std::string &pid) { FILE *lockfile; lockfile = fopen(FILE_NAME, "w"); - flockfile(lockfile); //flock + flockfile(lockfile); // flock fputs(pid.c_str(), lockfile); funlockfile(lockfile); fclose(lockfile); } - diff --git a/source/util/LockFileUtils.h b/source/util/LockFileUtils.h index 04c645bcf..7be38a059 100644 --- a/source/util/LockFileUtils.h +++ b/source/util/LockFileUtils.h @@ -19,35 +19,33 @@ namespace Aws */ class LockFileUtils { - private: - static constexpr char TAG[] = "LockFileUtils.cpp"; - static constexpr char FILE_NAME[] = "/var/run/devicecl.lock"; - static constexpr char PROCESS_NAME[] = "aws-iot-device-client"; - - /** - * \brief Gives the current process exclusive write access and writes the pid into the lock file - * @param pid - */ - static void WriteToLockFile(const std::string &pid); - - public: - /** - * \brief Creates a lock file in the default directory if it does not exist, aborts execution if another process is running. - * @return 0 upon success - */ - static int ProcessLock(); - - /** - * \brief Deletes the lock file when device client shuts down - * @return 0 upon success - */ - static int ProcessUnlock(); - - + private: + static constexpr char TAG[] = "LockFileUtils.cpp"; + static constexpr char FILE_NAME[] = "/var/run/devicecl.lock"; + static constexpr char PROCESS_NAME[] = "aws-iot-device-client"; + + /** + * \brief Gives the current process exclusive write access and writes the pid into the lock file + * @param pid + */ + static void WriteToLockFile(const std::string &pid); + + public: + /** + * \brief Creates a lock file in the default directory if it does not exist, aborts execution if another process is running. + * @return 0 upon success + */ + static int ProcessLock(); + + /** + * \brief Deletes the lock file when device client shuts down + * @return 0 upon success + */ + static int ProcessUnlock(); }; } // namespace Util - } // namespace DeviceClient - } // namespace Iot + } // namespace DeviceClient + } // namespace Iot } // namespace Aws -#endif //AWS_IOT_DEVICE_CLIENT_LOCKFILEUTILS_H +#endif // AWS_IOT_DEVICE_CLIENT_LOCKFILEUTILS_H diff --git a/test/util/TestLockFileUtils.cpp b/test/util/TestLockFileUtils.cpp index ecc087d66..326703154 100644 --- a/test/util/TestLockFileUtils.cpp +++ b/test/util/TestLockFileUtils.cpp @@ -28,5 +28,3 @@ TEST(LockFileUtils, unlockProcess) int res = LockFileUtils::ProcessUnlock(); ASSERT_EQ(res, 0); } - -