Skip to content

Commit

Permalink
Fixes issue where running discovery may prevent access to preferences…
Browse files Browse the repository at this point in the history
…, causing iscsid to crash.
  • Loading branch information
nsinenian committed Dec 20, 2016
1 parent c8df7c6 commit 3f168f9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 19 deletions.
39 changes: 30 additions & 9 deletions Source/User/iscsid/iSCSIDaemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ IONotificationPortRef powerNotifyPortRef;
// Used to fire discovery timer at specified intervals
CFRunLoopTimerRef discoveryTimer = NULL;

// Used by discovery to notify the main daemon thread that data is ready
CFRunLoopSourceRef discoverySource = NULL;

// Used to point to discovery records
CFDictionaryRef discoveryRecords = NULL;

// Mutex lock when discovery is running
pthread_mutex_t discoveryMutex = PTHREAD_MUTEX_INITIALIZER;

Expand Down Expand Up @@ -366,10 +372,8 @@ errno_t iSCSIDLoginCommon(SessionIdentifier sessionId,
// Update target alias in preferences (if one was furnished)
else
{
pthread_mutex_lock(&preferencesMutex);
iSCSIPreferencesSetTargetAlias(preferences,targetIQN,iSCSITargetGetAlias(target));
iSCSIPreferencesSynchronzeAppValues(preferences);
pthread_mutex_unlock(&preferencesMutex);
}

if(sessCfg)
Expand Down Expand Up @@ -1302,8 +1306,21 @@ CFDictionaryRef iSCSIDCreateRecordsWithSendTargets(iSCSISessionManagerRef manage

void * iSCSIDRunDiscovery(void * context)
{
CFDictionaryRef discoveryRecords = iSCSIDCreateRecordsWithSendTargets(sessionManager,preferences);
if(discoveryRecords != NULL)
CFRelease(discoveryRecords);

discoveryRecords = iSCSIDCreateRecordsWithSendTargets(sessionManager,preferences);


// Clear mutex created when discovery was launched
pthread_mutex_unlock(&discoveryMutex);

CFRunLoopSourceSignal(discoverySource);
return NULL;
}

void iSCSIDProcessDiscoveryData(void * info)
{
// Process discovery results if any
if(discoveryRecords) {

Expand All @@ -1314,19 +1331,15 @@ void * iSCSIDRunDiscovery(void * context)
const void * keys[count];
const void * values[count];
CFDictionaryGetKeysAndValues(discoveryRecords,keys,values);

for(CFIndex i = 0; i < count; i++)
iSCSIDUpdatePreferencesWithDiscoveredTargets(sessionManager,preferences,keys[i],values[i]);

iSCSIPreferencesSynchronzeAppValues(preferences);
pthread_mutex_unlock(&preferencesMutex);

CFRelease(discoveryRecords);
}

pthread_mutex_unlock(&discoveryMutex);

return NULL;
}


Expand Down Expand Up @@ -2112,6 +2125,14 @@ int main(void)
reqInfo->socket = socket;
reqInfo->socketSourceRead = sockSourceRead;
reqInfo->fd = 0;

// Runloop source signal by deamoen when discovery data is ready to be processed
CFRunLoopSourceContext discoveryContext;
bzero(&discoveryContext,sizeof(discoveryContext));
discoveryContext.info = &discoveryRecords;
discoveryContext.perform = iSCSIDProcessDiscoveryData;
discoverySource = CFRunLoopSourceCreate(kCFAllocatorDefault,1,&discoveryContext);
CFRunLoopAddSource(CFRunLoopGetMain(),sockSourceRead,kCFRunLoopDefaultMode);

asl_log(NULL,NULL,ASL_LEVEL_INFO,"daemon started");

Expand Down
12 changes: 6 additions & 6 deletions iSCSIInitiator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0820;
TargetAttributes = {
2B1A490B1D3D40FE00D3ED0D = {
CreatedOnToolsVersion = 7.3.1;
Expand Down Expand Up @@ -709,7 +709,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "";
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEBUG_INFORMATION_FORMAT = dwarf;
DYLIB_CURRENT_VERSION = 1.0.0;
ENABLE_NS_ASSERTIONS = NO;
GCC_C_LANGUAGE_STANDARD = "compiler-default";
Expand Down Expand Up @@ -789,7 +789,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand Down Expand Up @@ -922,7 +922,7 @@
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = "";
DYLIB_CURRENT_VERSION = 1.0.0;
Expand Down Expand Up @@ -1023,7 +1023,7 @@
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = YES;
CURRENT_PROJECT_VERSION = "1.0.0-beta5";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEBUG_INFORMATION_FORMAT = dwarf;
DYLIB_CURRENT_VERSION = 1.0.0;
ENABLE_NS_ASSERTIONS = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand Down Expand Up @@ -1114,7 +1114,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = YES;
CURRENT_PROJECT_VERSION = "1.0.0-beta5";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEBUG_INFORMATION_FORMAT = dwarf;
DYLIB_CURRENT_VERSION = 1.0.0;
ENABLE_NS_ASSERTIONS = NO;
GCC_C_LANGUAGE_STANDARD = "compiler-default";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down

0 comments on commit 3f168f9

Please sign in to comment.