Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerZhongAWS committed Apr 5, 2022
1 parent 99e8619 commit c2d998b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 37 deletions.
3 changes: 1 addition & 2 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -57,7 +57,6 @@
#include <memory>
#include <thread>
#include <vector>
#include <unistd.h>

using namespace std;
using namespace Aws::Iot::DeviceClient;
Expand Down
9 changes: 4 additions & 5 deletions source/util/LockFileUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#include "LockFileUtils.h"
#include <csignal>
#include <fstream>
#include <unistd.h>
#include <iostream>
#include "LockFileUtils.h"
#include <unistd.h>

using namespace std;
using namespace Aws::Iot::DeviceClient::Util;
Expand All @@ -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";
Expand Down Expand Up @@ -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);
}

54 changes: 26 additions & 28 deletions source/util/LockFileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions test/util/TestLockFileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ TEST(LockFileUtils, unlockProcess)
int res = LockFileUtils::ProcessUnlock();
ASSERT_EQ(res, 0);
}


0 comments on commit c2d998b

Please sign in to comment.