Skip to content

Commit

Permalink
Merge pull request #79 from shoshanatech/image-portability
Browse files Browse the repository at this point in the history
Better support for moving images between Windows and Linux (fixes #78)
  • Loading branch information
jecisc committed Nov 30, 2023
2 parents f4c1da6 + 116c972 commit 06ec31d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 47 deletions.
20 changes: 10 additions & 10 deletions repository/OSSubprocess/OSSUnixSubprocess.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ Class {
#category : #OSSubprocess
}

{ #category : #'temp files' }
OSSUnixSubprocess class >> createTempFilename [
"Read comment of createTempFileToBeUsedAsReadStreamOn:.
This answers just ONE WAY of defining a temp filename"

^ self name , '-p', OSSVMProcess vmProcess pid asString, '-', UUID new printString, '.deleteme'

]

{ #category : #'temp files' }
OSSUnixSubprocess class >> createTempFileToBeUsedAsReadStreamOn: aDirectoryPath [
"Important: for some reason, if we use MultiByteFileStream instances, we have some test failures.
Expand All @@ -90,16 +100,6 @@ OSSUnixSubprocess class >> createTempFileToBeUsedAsWriteStreamOn: aDirectoryPath
^ OldStandardFileStream forceNewFileNamed: (aDirectoryPath asFileReference / self createTempFilename) fullName
]

{ #category : #'temp files' }
OSSUnixSubprocess class >> createTempFilename [
"Read comment of createTempFileToBeUsedAsReadStreamOn:.
This answers just ONE WAY of defining a temp filename"

^ self name , '-p', OSSVMProcess vmProcess pid asString, '-', UUID new printString, '.deleteme'

]

{ #category : #'env building' }
OSSUnixSubprocess >> addAllEnvVariablesFromParentWithoutOverride [
"The user may have done an explicit set of a variable via #environmentAt:put: in which case
Expand Down
59 changes: 22 additions & 37 deletions repository/OSSubprocess/OSSVMProcess.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,24 @@ Class {
'LibCErrnoSharedPool',
'LibCWaitSharedPool'
],
#category : 'OSSubprocess'
#category : #OSSubprocess
}

{ #category : #'initialize - release' }
OSSVMProcess class >> initialize [
Smalltalk os isWindows ifTrue: [ ^ self ]. "Cannot be initialized nor used on Windows."

self initializeVMProcessInstance.
self flag: #removeIt.
"This IF will be eliminated soon...only here temporary"
(SystemVersion current highestUpdate >= 50558)
ifTrue: [
SessionManager default registerToolClassNamed: self name
]
ifFalse: [
Smalltalk addToStartUpList: OSSVMProcess.
Smalltalk addToShutDownList: OSSVMProcess.
]


self initializeVMProcessInstance.
SessionManager default registerToolClassNamed: self name
]

{ #category : #'initialize - release' }
OSSVMProcess class >> initializeVMProcessInstance [
VMProcess isNil
ifTrue: [ VMProcess := self basicNew. ]
ifFalse: [ VMProcess finalizePreviousSession ].
VMProcess initialize.

VMProcess ifNotNil: [
VMProcess finalizePreviousSession.
VMProcess := nil ].
Smalltalk os isWindows ifFalse: [
VMProcess := self basicNew initialize ]
]

{ #category : #'instance creation' }
Expand All @@ -73,18 +64,8 @@ OSSVMProcess class >> shutDown: quitting [

{ #category : #'system startup' }
OSSVMProcess class >> startUp: resuming [

resuming ifTrue: [
"To understand why the #stopWaiting, first read the comment of
OSSVMProcess shutDown:
It could happen that when the shutDown happened, the child process
was in the wait of #waitForExitPollingEvery:doing:. Therefore, until the
next cycle of the loop it won't do the queryExitStatus. So we may still
have this problem in image startup. So just in case we run it too in the startup code.
"
self vmProcess activeChildren do: [ :each | each stopWaiting ].
self initializeVMProcessInstance.
]

resuming ifTrue: [ self initializeVMProcessInstance ]
]

{ #category : #'OS Process' }
Expand Down Expand Up @@ -187,15 +168,19 @@ OSSVMProcess >> finalizePreviousSession [
"This method is likely called at image startup and it's job is to finalize
stuff related to the previous run and let everything clean so that
the unique instance vmProcess of OSSVMProcess can be initialized correctly at startup. "
childWatcher ifNotNil: [

childWatcher ifNotNil: [
childWatcher isTerminated ifFalse: [ childWatcher terminate ].
childWatcher := nil.
].
childWatcher := nil ].
sigChldSemaphore ifNotNil: [
self systemAccessor restoreSigChld.
sigChldSemaphore := nil
]

sigChldSemaphore := nil ].
"To understand why the #stopWaiting, first read the comment of #shutDown:.
It could happen that when the shutDown happened, the child process was in
the wait of #waitForExitPollingEvery:doing:. Therefore, until the next cycle
of the loop it won't do the queryExitStatus. So we may still have this
problem in image startup. So just in case we run it too in the startup code."
self activeChildren do: [ :each | each stopWaiting ]
]

{ #category : #'initialize - release' }
Expand Down

0 comments on commit 06ec31d

Please sign in to comment.