Skip to content

Commit

Permalink
Removed DC initialization code which creates multiple lock files. (#419)
Browse files Browse the repository at this point in the history
* Removed DC initialization code which creates multiple lock files.

Device Client uses a lock files for making sure only 1 instance of Device Client is running at a given time. With Fleet Provisioning feature enabled, DC was accidentally creating multiple lock files which was resulting in DC abort. By updating the logic, DC will now only create one lock file as expected.

* resolved indentation errors
  • Loading branch information
HarshGandhi-AWS authored Jun 29, 2023
1 parent 239d10d commit a0d1cf4
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,19 @@ int main(int argc, char *argv[])
LOG_WARN(TAG, "Unable to append current working directory to PATH environment variable.");
}

#if !defined(DISABLE_MQTT)
/**
* init() is currently responsible for making sure only 1 instance of Device Client is running at a given time.
* In the future, we may want to move other Device Client startup logic into this function.
* returns false if an exception is thrown
*/
if (!init(argc, argv))
{
LOGM_ERROR(TAG, "*** %s: An instance of Device Client is already running.", DC_FATAL_ERROR);
deviceClientAbort("An instance of Device Client is already running.");
}
#endif

features = make_shared<FeatureRegistry>();

LOGM_INFO(TAG, "Now running AWS IoT Device Client version %s", DEVICE_CLIENT_VERSION_FULL);
Expand All @@ -346,16 +359,6 @@ int main(int argc, char *argv[])
if (config.config.fleetProvisioning.enabled &&
!config.config.fleetProvisioningRuntimeConfig.completedFleetProvisioning)
{
/**
* init() is currently responsible for making sure only 1 instance of Device Client is running at a given time.
* In the future, we may want to move other Device Client startup logic into this function.
* returns false if an exception is thrown
*/
if (!init(argc, argv))
{
LOGM_ERROR(TAG, "*** %s: An instance of Device Client is already running.", DC_FATAL_ERROR);
deviceClientAbort("An instance of Device Client is already running.");
}
/*
* Establish MQTT connection using claim certificates and private key to provision the device/thing.
*/
Expand Down Expand Up @@ -394,16 +397,6 @@ int main(int argc, char *argv[])
#endif

#if !defined(DISABLE_MQTT)
/**
* init() is currently responsible for making sure only 1 instance of Device Client is running at a given time.
* In the future, we may want to move other Device Client startup logic into this function.
* returns false if an exception is thrown
*/
if (!init(argc, argv))
{
LOGM_ERROR(TAG, "*** %s: An instance of Device Client is already running.", DC_FATAL_ERROR);
deviceClientAbort("An instance of Device Client is already running.");
}
/*
* Establish MQTT connection using permanent certificate and private key to start and run AWS IoT Device Client
* features.
Expand Down

0 comments on commit a0d1cf4

Please sign in to comment.