31
|
1 |
/*
|
|
2 |
* Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <fcntl.h>
|
|
20 |
#include <sys/errno.h>
|
|
21 |
#include <sys/serial.h>
|
|
22 |
#include <unistd.h>
|
|
23 |
#include <sys/stat.h>
|
|
24 |
#include <sys/select.h>
|
|
25 |
#include <sys/syslimits.h>
|
|
26 |
#include <utf.h>
|
|
27 |
#include "sysreent.h"
|
|
28 |
#include <sys/socket.h>
|
|
29 |
#include <sys/un.h>
|
|
30 |
#include "sysif.h"
|
|
31 |
#include "fdesc.h"
|
|
32 |
#include "ltime.h"
|
|
33 |
#include "lposix.h"
|
|
34 |
#include "systemspecialfilercg.h"
|
|
35 |
#include "link.h"
|
|
36 |
#ifdef SYMBIAN_OE_POSIX_SIGNALS
|
|
37 |
#include <stdlib.h>
|
|
38 |
#include <signal.h>
|
|
39 |
#include "tsignalmessage.h"
|
|
40 |
#endif // SYMBIAN_OE_POSIX_SIGNALS
|
|
41 |
|
|
42 |
#ifdef SYMBIAN_OE_POSIX_SIGNALS
|
|
43 |
#define SIG_SIGNAL_PRESENT_IN_SIGSET(sig,set) ((set & (1ULL << (sig-1))) != 0x0000000000000000ULL)
|
|
44 |
#define SIG_ISEMPTY_SIGSET(set) (set == 0x0000000000000000ULL)
|
|
45 |
#define SIG_EMPTY_SIGSET(set) {set = 0x0000000000000000ULL;}
|
|
46 |
#define SIG_FILL_SIGSET(set) {set = 0xFFFFFFFFFFFFFFFFULL;}
|
|
47 |
#define SIG_ADD_SIGNAL_TO_SET(sig,set) {set |= (1ULL << (sig-1));}
|
|
48 |
#define SIG_REMOVE_SIGNAL_FROM_SET(sig,set) {set &= ~(1ULL << (sig-1));}
|
|
49 |
|
|
50 |
static void sig_exit();
|
|
51 |
|
|
52 |
const TUint KSignalPipeSize = 1024;
|
|
53 |
#endif
|
|
54 |
|
|
55 |
|
|
56 |
#ifdef __WINSCW__
|
|
57 |
#include <pls.h> // For emulator WSD API
|
|
58 |
const TUid KBackendUid3 = {0x102828D5};
|
|
59 |
#elif defined __X86GCC__
|
|
60 |
// GCC compiler generates an undefined reference error if static CLocalSystemInterface object is created in a local function. Therefore give it global scope on this platform.
|
|
61 |
CLocalSystemInterface TheBackend;
|
|
62 |
#elif defined __EPOC32__
|
|
63 |
//Globally declaring the CLSI object to overcome the DCLP implementation if given a static scope.
|
|
64 |
CLocalSystemInterface backend;
|
|
65 |
#endif
|
|
66 |
|
|
67 |
const TUint KConvertToMicroSecond = 1000000;
|
|
68 |
|
|
69 |
// Create static singleton backend object for the Process and return the same
|
|
70 |
EXPORT_C CLocalSystemInterface* Backend()
|
|
71 |
{
|
|
72 |
#ifdef __WINSCW__
|
|
73 |
// Access the PLS of this process
|
|
74 |
CLocalSystemInterface* backend = Pls<CLocalSystemInterface>(KBackendUid3);
|
|
75 |
return backend;
|
|
76 |
#elif defined __X86GCC__
|
|
77 |
return &TheBackend;
|
|
78 |
#else
|
|
79 |
return &backend;
|
|
80 |
#endif
|
|
81 |
}
|
|
82 |
|
|
83 |
// Construction of Backend Object which is going to be singleton object for the process
|
|
84 |
EXPORT_C CLocalSystemInterface::CLocalSystemInterface() : iOpenDirList(CLocalSystemInterface::KDirGran),
|
|
85 |
iTLDInfoList(CLocalSystemInterface::KTLDInfoListGran)
|
|
86 |
{
|
|
87 |
#ifdef SYMBIAN_OE_POSIX_SIGNALS
|
|
88 |
iSignalsInitialized = EFalse;
|
|
89 |
iSigInitWaitCount = 0;
|
|
90 |
iSigInitWaitMutex.CreateLocal();
|
|
91 |
iSigInitWaitSemaphore.CreateLocal(0);
|
|
92 |
iBlockedSAMutex.CreateLocal();
|
|
93 |
iSignalWaiterMutex.CreateLocal();
|
|
94 |
iSignalInitSemaphore.CreateLocal(0);
|
|
95 |
#endif
|
|
96 |
//Create the Heap for all the libraries (local to this process)
|
|
97 |
const TInt KMaxHeapSize = 1048576 ; // 1MB
|
|
98 |
iPrivateHeap = UserHeap::ChunkHeap(NULL, KMinHeapSize, KMaxHeapSize);
|
|
99 |
if (!iPrivateHeap)
|
|
100 |
{
|
|
101 |
User::Panic(KEstlibInit, KErrNoMemory);
|
|
102 |
}
|
|
103 |
|
|
104 |
// Switch to the backend private heap
|
|
105 |
RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
|
|
106 |
|
|
107 |
TInt err = iFids.Init(iPrivateHeap);
|
|
108 |
if ( !err )
|
|
109 |
{
|
|
110 |
CRedirDesc* redirMedia = new CRedirDesc();
|
|
111 |
if (redirMedia)
|
|
112 |
{
|
|
113 |
CStdErrDesc* errMedia = new CStdErrDesc();
|
|
114 |
if(errMedia)
|
|
115 |
{
|
|
116 |
iFids.Default(redirMedia, errMedia);
|
|
117 |
redirMedia->Close();
|
|
118 |
errMedia->Close();
|
|
119 |
}
|
|
120 |
else
|
|
121 |
{
|
|
122 |
iPrivateHeap->Free(redirMedia);
|
|
123 |
}
|
|
124 |
}
|
|
125 |
}
|
|
126 |
#if (defined SYMBIAN_OE_POSIX_SIGNALS && defined SYMBIAN_OE_LIBRT)
|
|
127 |
iTimerOverrunsMutex.CreateLocal(); //use backend heap
|
|
128 |
#endif
|
|
129 |
|
|
130 |
// Reset to the thread's default heap
|
|
131 |
User::SwitchHeap(oldHeap);
|
|
132 |
|
|
133 |
if (!err)
|
|
134 |
{
|
|
135 |
err=iFs.Connect();
|
|
136 |
if(!err)
|
|
137 |
{
|
|
138 |
err = iFs.ShareAuto();
|
|
139 |
}
|
|
140 |
}
|
|
141 |
|
|
142 |
if (!err)
|
|
143 |
{
|
|
144 |
err = PosixFilesystem::SetDefaultDir(iFs);
|
|
145 |
}
|
|
146 |
|
|
147 |
//Cache the session path to avoid querying RFs every time it is needed
|
|
148 |
if(err == KErrNone)
|
|
149 |
{
|
|
150 |
err = iFs.SessionPath(iSessionPath);
|
|
151 |
}
|
|
152 |
|
|
153 |
|
|
154 |
if(err == KErrNone)
|
|
155 |
{
|
|
156 |
//Create Server Locks
|
|
157 |
err |= iSSLock.CreateLocal();
|
|
158 |
err |= iCSLock.CreateLocal();
|
|
159 |
err |= iIpcS.iLock.CreateLocal();
|
|
160 |
//Create TLDList Lock
|
|
161 |
err |= iTLDListLock.CreateLocal();
|
|
162 |
//Create the lock for Session Path
|
|
163 |
err |= iSessionPathLock.CreateLocal();
|
|
164 |
//Lock for protecting iASelectRequest across threads
|
|
165 |
err |= iASelectLock.CreateLocal();
|
|
166 |
//Protect the iDefConnection from concurrent GetDefaultConnection calls
|
|
167 |
err |= iDefConnLock.CreateLocal();
|
|
168 |
}
|
|
169 |
|
|
170 |
if(err == KErrNone)
|
|
171 |
{
|
|
172 |
err = iTzServer.Connect();
|
|
173 |
if(!err)
|
|
174 |
{
|
|
175 |
err = iTzServer.ShareAuto();
|
|
176 |
}
|
|
177 |
}
|
|
178 |
|
|
179 |
|
|
180 |
//Panic if any of the above operation returns with error
|
|
181 |
if (err)
|
|
182 |
{
|
|
183 |
User::Panic(KEstlibInit, err);
|
|
184 |
}
|
|
185 |
|
|
186 |
iCleanup.StorePtrs(iPrivateHeap, &iFs, &iSs, &iCs, &iSSLock, &iCSLock, &iTzServer);
|
|
187 |
|
|
188 |
// No connection settings by default
|
|
189 |
iDefConnPref = NULL;
|
|
190 |
}
|
|
191 |
|
|
192 |
EXPORT_C CLocalSystemInterface::~CLocalSystemInterface()
|
|
193 |
//
|
|
194 |
// Shut down all server connections in use
|
|
195 |
//
|
|
196 |
{
|
|
197 |
iTLDListLock.Close();
|
|
198 |
iSessionPathLock.Close();
|
|
199 |
// Close the aselect lock
|
|
200 |
iASelectLock.Close();
|
|
201 |
// Close the default connection lock
|
|
202 |
iDefConnLock.Close();
|
|
203 |
//close the default RConnection
|
|
204 |
if(iDefConnection.SubSessionHandle() != 0)
|
|
205 |
iDefConnection.Close();
|
|
206 |
|
|
207 |
RHeap* oHeap = User::SwitchHeap(iPrivateHeap);
|
|
208 |
for (TInt i = 0, count = iTLDInfoList.Count(); i < count; i++ )
|
|
209 |
{
|
|
210 |
iTLDInfoList[i].Close(iPrivateHeap);
|
|
211 |
}
|
|
212 |
|
|
213 |
// close the RArray itself
|
|
214 |
iTLDInfoList.Close();
|
|
215 |
// Cleanup the threads serving aselect requests
|
|
216 |
int err;
|
|
217 |
// passing 1 to cancelaselect will kill all the threads serving aselect
|
|
218 |
cancelaselect(NULL,err,1);
|
|
219 |
// Switch to backend heap
|
|
220 |
RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
|
|
221 |
// Close the array that maintains aselect request details
|
|
222 |
iASelectRequest.Close();
|
|
223 |
//close the RTz server
|
|
224 |
iTzServer.Close();
|
|
225 |
// Switch back to old heap
|
|
226 |
User::SwitchHeap(oldHeap);
|
|
227 |
|
|
228 |
if( iDefConnPref )
|
|
229 |
{
|
|
230 |
switch( iDefConnPref->ExtensionId() )
|
|
231 |
{
|
|
232 |
case TConnPref::EConnPrefSnap:
|
|
233 |
{
|
|
234 |
RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
|
|
235 |
delete (TCommSnapPref*)iDefConnPref;
|
|
236 |
// Switch back to old heap
|
|
237 |
User::SwitchHeap(oldHeap);
|
|
238 |
iDefConnPref = NULL;
|
|
239 |
}
|
|
240 |
break;
|
|
241 |
|
|
242 |
case TConnPref::EConnPrefCommDb:
|
|
243 |
{
|
|
244 |
RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
|
|
245 |
delete (TCommDbConnPref*)iDefConnPref;
|
|
246 |
// Switch back to old heap
|
|
247 |
User::SwitchHeap(oldHeap);
|
|
248 |
iDefConnPref = NULL;
|
|
249 |
}
|
|
250 |
break;
|
|
251 |
|
|
252 |
default:
|
|
253 |
{
|
|
254 |
// Unknown type of Connection Pref, do nothing
|
|
255 |
}
|
|
256 |
}
|
|
257 |
}
|
|
258 |
|
|
259 |
#if (defined SYMBIAN_OE_POSIX_SIGNALS && defined SYMBIAN_OE_LIBRT)
|
|
260 |
iTimerOverrunsMutex.Close();
|
|
261 |
iTimerOverruns.Close();
|
|
262 |
#endif
|
|
263 |
//close the RpointerArray
|
|
264 |
iOpenDirList.Close();
|
|
265 |
User::SwitchHeap(oHeap);
|
|
266 |
}
|
|
267 |
|
|
268 |
#ifdef __SYMBIAN_COMPILE_UNUSED__
|
|
269 |
CLocalSystemInterface& CLocalSystemInterface::Clone()
|
|
270 |
{
|
|
271 |
return *this;
|
|
272 |
}
|
|
273 |
|
|
274 |
void CLocalSystemInterface::Release()
|
|
275 |
{
|
|
276 |
// nada. TODO: Remove this method
|
|
277 |
}
|
|
278 |
|
|
279 |
|
|
280 |
// -----------------------------------------------------------------------------
|
|
281 |
// CLocalSystemInterface::TerminateProcess
|
|
282 |
// Sends a message to Posix Server to Terminate itself!
|
|
283 |
// And delete the Process (self)
|
|
284 |
// -----------------------------------------------------------------------------
|
|
285 |
//
|
|
286 |
void CLocalSystemInterface::TerminateProcess(int status)
|
|
287 |
{
|
|
288 |
//delete this;
|
|
289 |
RProcess().Terminate(status);
|
|
290 |
}
|
|
291 |
#endif //__SYMBIAN_COMPILE_UNUSED__
|
|
292 |
|
|
293 |
|
|
294 |
// -----------------------------------------------------------------------------
|
|
295 |
// CLocalSystemInterface::Exit
|
|
296 |
// Close all the open FIDS,Terminate the process
|
|
297 |
//
|
|
298 |
// -----------------------------------------------------------------------------
|
|
299 |
//
|
|
300 |
void CLocalSystemInterface::Exit(int code)
|
|
301 |
{
|
|
302 |
#ifdef SYMBIAN_OE_POSIX_SIGNALS
|
|
303 |
TRequestStatus status = KRequestPending;
|
|
304 |
iSignalHandlerThread.Logon(status);
|
|
305 |
iSignalLoopRunning = EFalse;
|
|
306 |
iSignalHandlerThread.RequestSignal();
|
|
307 |
User::WaitForRequest(status);
|
|
308 |
#endif
|
|
309 |
iFids.Close();
|
|
310 |
User::SetCritical(User::EProcessPermanent);
|
|
311 |
User::Exit(code);
|
|
312 |
}
|
|
313 |
|
|
314 |
// Simple layer over PosixFilesystem
|
|
315 |
|
|
316 |
wchar_t * CLocalSystemInterface::getcwd (wchar_t* buf, unsigned long len, int& anErrno)
|
|
317 |
{
|
|
318 |
return PosixFilesystem::getcwd(iFs, buf, len, anErrno);
|
|
319 |
}
|
|
320 |
|
|
321 |
int CLocalSystemInterface::chdir (const wchar_t* aPath, int& anErrno)
|
|
322 |
{
|
|
323 |
return PosixFilesystem::chdir(iFs, aPath, anErrno);
|
|
324 |
}
|
|
325 |
|
|
326 |
int CLocalSystemInterface::rmdir (const wchar_t* aPath, int& anErrno)
|
|
327 |
{
|
|
328 |
return PosixFilesystem::rmdir(iFs, aPath, anErrno);
|
|
329 |
}
|
|
330 |
|
|
331 |
int CLocalSystemInterface::mkdir (const wchar_t* aPath, int perms, int& anErrno)
|
|
332 |
{
|
|
333 |
return PosixFilesystem::mkdir(iFs, aPath, perms, anErrno);
|
|
334 |
}
|
|
335 |
|
|
336 |
int CLocalSystemInterface::stat (const wchar_t* name, struct stat *st, int& anErrno)
|
|
337 |
{
|
|
338 |
const wchar_t* filename;
|
|
339 |
// This needs to be zero terminated
|
|
340 |
TBuf<KMaxFileName> inputName;
|
|
341 |
TUint pathAtt = 0;
|
|
342 |
TInt err = GetFullFile(inputName,(const TText16*)name,iFs);
|
|
343 |
if( !err )
|
|
344 |
{
|
|
345 |
TInt err = iFs.Att(inputName,pathAtt);
|
|
346 |
if ( (err == KErrNone) && (pathAtt & KEntryAttDir) )
|
|
347 |
{
|
|
348 |
inputName.Append(_L("\\"));
|
|
349 |
}
|
|
350 |
filename = (wchar_t*)inputName.PtrZ();
|
|
351 |
}
|
|
352 |
// try to stat anyway
|
|
353 |
else
|
|
354 |
{
|
|
355 |
inputName.Copy((const TText16*)name);
|
|
356 |
filename = (wchar_t*)inputName.PtrZ();
|
|
357 |
}
|
|
358 |
TSpecialFileType fileType;
|
|
359 |
struct SLinkInfo enBuf;
|
|
360 |
// Check the type of file
|
|
361 |
fileType = _SystemSpecialFileBasedFilePath(filename, err, iFs);
|
|
362 |
// If it is a symbolic link, follow the link
|
|
363 |
// If _SystemSpecialFileBasedFilePath fails, treat it as normal file
|
|
364 |
// and try to proceed
|
|
365 |
if( fileType == EFileTypeSymLink && err == KErrNone )
|
|
366 |
{
|
|
367 |
err = _ReadSysSplFile(filename, (char*)&enBuf, sizeof(struct SLinkInfo), anErrno, iFs);
|
|
368 |
if (err == KErrNone)
|
|
369 |
{
|
|
370 |
filename = (wchar_t*)enBuf.iParentPath;
|
|
371 |
}
|
|
372 |
else
|
|
373 |
{
|
|
374 |
// errno is already set by _ReadSysSplFile
|
|
375 |
return -1;
|
|
376 |
}
|
|
377 |
}
|
|
378 |
else if ( fileType != EFileGeneralError && err != KErrNone )
|
|
379 |
{
|
|
380 |
return MapError(err,anErrno);
|
|
381 |
}
|
|
382 |
return PosixFilesystem::statbackend(iFs, filename, st, anErrno);
|
|
383 |
}
|
|
384 |
|
|
385 |
int CLocalSystemInterface::lstat (const wchar_t* name, struct stat *st, int& anErrno)
|
|
386 |
{
|
|
387 |
return PosixFilesystem::statbackend(iFs, name, st, anErrno);
|
|
388 |
}
|
|
389 |
|
|
390 |
int CLocalSystemInterface::utime (const wchar_t* name, const struct utimbuf *filetimes, int& anErrno)
|
|
391 |
{
|
|
392 |
return PosixFilesystem::utime(iFs, name, filetimes, anErrno);
|
|
393 |
}
|
|
394 |
|
|
395 |
int CLocalSystemInterface::chmod (const wchar_t* name, int perms, int& anErrno)
|
|
396 |
{
|
|
397 |
return PosixFilesystem::chmod(iFs, name, perms, anErrno);
|
|
398 |
}
|
|
399 |
|
|
400 |
int CLocalSystemInterface::rename (const wchar_t* oldname, const wchar_t* newname, int& anErrno)
|
|
401 |
{
|
|
402 |
return PosixFilesystem::rename(iFs, oldname, newname, anErrno);
|
|
403 |
}
|
|
404 |
|
|
405 |
|
|
406 |
EXPORT_C TInt CLocalSystemInterface::ResolvePath (TParse& aResult, const wchar_t* path, TDes* aFilename)
|
|
407 |
{
|
|
408 |
return PosixFilesystem::ResolvePath(aResult, path, aFilename);
|
|
409 |
}
|
|
410 |
|
|
411 |
// Simple layer over CFileTable synchronous routines
|
|
412 |
|
|
413 |
int CLocalSystemInterface::open (const wchar_t* name, int mode, int perms, int& anErrno)
|
|
414 |
{
|
|
415 |
return iFids.open(name,mode,perms,anErrno);
|
|
416 |
}
|
|
417 |
|
|
418 |
int CLocalSystemInterface::dup (int fid, int& anErrno)
|
|
419 |
{
|
|
420 |
return iFids.dup(fid,anErrno);
|
|
421 |
}
|
|
422 |
|
|
423 |
int CLocalSystemInterface::dup2 (int fid, int fid2, int& anErrno)
|
|
424 |
{
|
|
425 |
return iFids.dup2(fid,fid2,anErrno);
|
|
426 |
}
|
|
427 |
|
|
428 |
int CLocalSystemInterface::close (int fid, int& anErrno)
|
|
429 |
{
|
|
430 |
return iFids.UserClose(fid,anErrno);
|
|
431 |
}
|
|
432 |
|
|
433 |
off_t CLocalSystemInterface::lseek (int fid, off_t offset, int whence, int& anErrno)
|
|
434 |
{
|
|
435 |
return iFids.lseek(fid,offset,whence,anErrno);
|
|
436 |
}
|
|
437 |
|
|
438 |
int CLocalSystemInterface::fstat (int fid, struct stat *st, int& anErrno)
|
|
439 |
{
|
|
440 |
return iFids.fstat(fid,st,anErrno);
|
|
441 |
}
|
|
442 |
|
|
443 |
int CLocalSystemInterface::socket (int family, int style, int protocol, int& anErrno)
|
|
444 |
{
|
|
445 |
//Acquire the Lock before issuing a request to the server and release it later
|
|
446 |
iSSLock.Wait();
|
|
447 |
int retVal = iFids.socket(family,style,protocol,anErrno,iSs);
|
|
448 |
iSSLock.Signal();
|
|
449 |
return retVal;
|
|
450 |
}
|
|
451 |
|
|
452 |
int CLocalSystemInterface::listen (int fid, int n, int& anErrno)
|
|
453 |
{
|
|
454 |
return iFids.listen(fid,n,anErrno);
|
|
455 |
}
|
|
456 |
|
|
457 |
int CLocalSystemInterface::bind (int fid, const struct sockaddr* addr, unsigned long size, int& anErrno)
|
|
458 |
{
|
|
459 |
return iFids.bind(fid,addr,size,anErrno);
|
|
460 |
}
|
|
461 |
|
|
462 |
int CLocalSystemInterface::sockname (int fid, struct sockaddr* addr, unsigned long* size, int anEnd, int& anErrno)
|
|
463 |
{
|
|
464 |
return iFids.sockname(fid,addr,size,anEnd,anErrno);
|
|
465 |
}
|
|
466 |
|
|
467 |
int CLocalSystemInterface::getsockopt (int fid, int level, int opt, void* buf, unsigned long* len, int& anErrno)
|
|
468 |
{
|
|
469 |
return iFids.getsockopt(fid,level,opt,buf,len,anErrno);
|
|
470 |
}
|
|
471 |
|
|
472 |
int CLocalSystemInterface::setsockopt (int fid, int level, int opt, void* buf, unsigned long len, int& anErrno)
|
|
473 |
{
|
|
474 |
return iFids.setsockopt(fid,level,opt,buf,len,anErrno);
|
|
475 |
}
|
|
476 |
|
|
477 |
int CLocalSystemInterface::popen3 (const wchar_t* file, const wchar_t* cmd,
|
|
478 |
wchar_t** env, int fids[3], int& anErrno)
|
|
479 |
{
|
|
480 |
return iFids.popen3(file, cmd, env, fids, anErrno);
|
|
481 |
}
|
|
482 |
|
|
483 |
int CLocalSystemInterface::waitpid (int pid, int* status, int options, int& anErrno)
|
|
484 |
{
|
|
485 |
return iFids.waitpid(pid, status, options, anErrno);
|
|
486 |
}
|
|
487 |
|
|
488 |
// -----------------------------------------------------------------------------
|
|
489 |
// CLocalSystemInterface::popen
|
|
490 |
// Implementation for popen
|
|
491 |
// -----------------------------------------------------------------------------
|
|
492 |
//
|
|
493 |
int CLocalSystemInterface::popen (const wchar_t* file, const wchar_t* cmd,
|
|
494 |
const char* mode, int& anErrno)
|
|
495 |
{
|
|
496 |
return iFids.popen(file, cmd, mode, anErrno);
|
|
497 |
}
|
|
498 |
|
|
499 |
// -----------------------------------------------------------------------------
|
|
500 |
// CLocalSystemInterface::pclose
|
|
501 |
// Implementation for pclose
|
|
502 |
// -----------------------------------------------------------------------------
|
|
503 |
//
|
|
504 |
int CLocalSystemInterface::pclose (int aFid, int& anErrno)
|
|
505 |
{
|
|
506 |
return iFids.pclose(aFid, anErrno);
|
|
507 |
}
|
|
508 |
|
|
509 |
// -----------------------------------------------------------------------------
|
|
510 |
// CLocalSystemInterface::CheckOrigins
|
|
511 |
// Implementation for CheckPipe
|
|
512 |
// -----------------------------------------------------------------------------
|
|
513 |
//
|
|
514 |
EXPORT_C void CLocalSystemInterface::CheckOrigins (wchar_t**& wenvp, int& aCount)
|
|
515 |
{
|
|
516 |
//Acquire the Lock before issuing a request to the server and release it later
|
|
517 |
#ifdef SYMBIAN_OE_POSIX_SIGNALS
|
|
518 |
iFids.CheckOrigins(wenvp, aCount, iSigMask);
|
|
519 |
#else
|
|
520 |
iFids.CheckOrigins(wenvp, aCount);
|
|
521 |
#endif
|
|
522 |
}
|
|
523 |
|
|
524 |
#ifdef SYMBIAN_OE_POSIX_SIGNALS
|
|
525 |
// -----------------------------------------------------------------------------
|
|
526 |
// CLocalSystemInterface::WaitOrHandleSignal
|
|
527 |
// -----------------------------------------------------------------------------
|
|
528 |
//
|
|
529 |
void CLocalSystemInterface::WaitOrHandleSignal(TSignalMessage aMsg)
|
|
530 |
{
|
|
531 |
TInt lSigNum = 0,lIdx = 0,lSigVal = 0;
|
|
532 |
TSignalWaiter lTempWaiter(0,0);
|
|
533 |
|
|
534 |
if(aMsg.mType == TSignalMessage::ESignal)
|
|
535 |
lSigNum = aMsg.mSignal;
|
|
536 |
else if(aMsg.mType == TSignalMessage::ESignalValuePair)
|
|
537 |
{
|
|
538 |
lSigNum = aMsg.mSigVal.mSignal;
|
|
539 |
lSigVal = aMsg.mSigVal.mValue;
|
|
540 |
}
|
|
541 |
else if(aMsg.mType == TSignalMessage::ERtTimerSignal)
|
|
542 |
{
|
|
543 |
lSigNum = aMsg.mRtSignal.mSignal;
|
|
544 |
}
|
|
545 |
|
|
546 |
// check and deliver to waiter (if any)
|
|
547 |
TUint64 lMask;
|
|
548 |
SIG_EMPTY_SIGSET(lMask);
|
|
549 |
SIG_ADD_SIGNAL_TO_SET(lSigNum,lMask);
|
|
550 |
lTempWaiter.iSigWaitMask = lMask;
|
|
551 |
|
|
552 |
lIdx = iSignalWaiterArray.Find(lTempWaiter,TSignalWaiter::MatchByMask);
|
|
553 |
if(lIdx != KErrNotFound)
|
|
554 |
{
|
|
555 |
iSignalWaiterMutex.Wait();
|
|
556 |
iSignalWaiterArray[lIdx].iSigWaitMessagePtr->mType = aMsg.mType;
|
|
557 |
if(aMsg.mType == TSignalMessage::ESignal)
|
|
558 |
iSignalWaiterArray[lIdx].iSigWaitMessagePtr->mSignal = lSigNum;
|
|
559 |
else if(aMsg.mType == TSignalMessage::ESignalValuePair)
|
|
560 |
{
|
|
561 |
iSignalWaiterArray[lIdx].iSigWaitMessagePtr->mSigVal.mSignal = lSigNum;
|
|
562 |
iSignalWaiterArray[lIdx].iSigWaitMessagePtr->mSigVal.mValue = lSigVal;
|
|
563 |
}
|
|
564 |
iSignalWaiterArray[lIdx].iSigWaitSemaphore.Signal();
|
|
565 |
RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
|
|
566 |
iSignalWaiterArray.Remove(lIdx);
|
|
567 |
User::SwitchHeap(oldHeap);
|
|
568 |
iSignalWaiterMutex.Signal();
|
|
569 |
}
|
|
570 |
// queueing if blocked or sigqueue
|
|
571 |
else
|
|
572 |
{
|
|
573 |
HandleSignal(aMsg);
|
|
574 |
}
|
|
575 |
}
|
|
576 |
|
|
577 |
// -----------------------------------------------------------------------------
|
|
578 |
// CLocalSystemInterface::SignalHandler
|
|
579 |
// -----------------------------------------------------------------------------
|
|
580 |
//
|
|
581 |
TInt CLocalSystemInterface::SignalHandler()
|
|
582 |
{
|
|
583 |
// TODO: Put memory barrier to ensure SMP safety
|
|
584 |
TInt lRetVal = KErrGeneral;
|
|
585 |
InitializeSignalHandlers();
|
|
586 |
RPipe::Init(); // check return value
|
|
587 |
lRetVal = RPipe::Create(KSignalPipeSize,iSignalReadPipe,iSignalWritePipe);
|
|
588 |
if(lRetVal != KErrNone)
|
|
589 |
{
|
|
590 |
iSignalInitSemaphore.Signal();
|
|
591 |
return lRetVal;
|
|
592 |
}
|
|
593 |
lRetVal = iSignalSession.SendPipe(iSignalWritePipe); // check return value
|
|
594 |
if(lRetVal != KErrNone)
|
|
595 |
{
|
|
596 |
iSignalInitSemaphore.Signal();
|
|
597 |
return lRetVal;
|
|
598 |
}
|
|
599 |
|
|
600 |
/* Closing the end of the pipe that's been sent to the server */
|
|
601 |
iSignalWritePipe.Close();
|
|
602 |
|
|
603 |
iSignalsInitialized = ETrue;
|
|
604 |
iSignalInitSemaphore.Signal();
|
|
605 |
iSignalLoopRunning = ETrue;
|
|
606 |
iPipeReadStatus = KRequestPending;
|
|
607 |
iSignalReadPipe.NotifyDataAvailable(iPipeReadStatus);
|
|
608 |
while(iSignalLoopRunning)
|
|
609 |
{
|
|
610 |
User::WaitForAnyRequest();
|
|
611 |
if(iSignalLoopRunning == false) {
|
|
612 |
break;
|
|
613 |
}
|
|
614 |
// Check if it is a pipe read
|
|
615 |
if(iPipeReadStatus != KRequestPending)
|
|
616 |
{
|
|
617 |
if(iPipeReadStatus == KErrNone)
|
|
618 |
{
|
|
619 |
TBuf8<KSigMsgLength> lMsgBuf;
|
|
620 |
TInt lRetVal = KErrNone;
|
|
621 |
lRetVal = iSignalReadPipe.Read(lMsgBuf,KSigMsgLength);
|
|
622 |
TSignalMessage lMsg;
|
|
623 |
TInt lIdx = 0;
|
|
624 |
|
|
625 |
if(lMsg.Unmarshall(lMsgBuf)==KErrNone && lRetVal >= 0)
|
|
626 |
|
|
627 |
{
|
|
628 |
TInt lIdx1 = 0, lIdx2 = 0, lIdx3 = 0;
|
|
629 |
TSignalMessage lTmpMsg1,lTmpMsg2,lTmpMsg3;
|
|
630 |
TBool lSignalsFound = ETrue;
|
|
631 |
|
|
632 |
TChildWaiter lWaiter;
|
|
633 |
|
|
634 |
switch(lMsg.mType)
|
|
635 |
{
|
|
636 |
case TSignalMessage::ESignalValuePair:
|
|
637 |
case TSignalMessage::ESignal:
|
|
638 |
case TSignalMessage::ERtTimerSignal:
|
|
639 |
WaitOrHandleSignal(lMsg);
|
|
640 |
break;
|
|
641 |
case TSignalMessage::EDequeueSignal:
|
|
642 |
lTmpMsg1.mType = TSignalMessage::ESignal;
|
|
643 |
lTmpMsg1.mSignal = lMsg.mSignal;
|
|
644 |
|
|
645 |
lTmpMsg2.mType = TSignalMessage::ESignalValuePair;
|
|
646 |
lTmpMsg2.mSigVal.mSignal = lMsg.mSignal;
|
|
647 |
|
|
648 |
lTmpMsg3.mType = TSignalMessage::ERtTimerSignal;
|
|
649 |
lTmpMsg3.mRtSignal.mSignal = lMsg.mSignal;
|
|
650 |
while(lSignalsFound)
|
|
651 |
{
|
|
652 |
iBlockedSAMutex.Wait();
|
|
653 |
lIdx1 = iBlockedSigArray.Find(lTmpMsg1,TSignalMessage::SignalMatchBySigNum);
|
|
654 |
lIdx2 = iBlockedSigArray.Find(lTmpMsg2,TSignalMessage::SigValMatchBySigNum);
|
|
655 |
lIdx3 = iBlockedSigArray.Find(lTmpMsg3,TSignalMessage::SigValMatchBySigNum);
|
|
656 |
iBlockedSAMutex.Signal();
|
|
657 |
if(lIdx1 == KErrNotFound && lIdx2 == KErrNotFound)
|
|
658 |
{
|
|
659 |
lSignalsFound = EFalse;
|
|
660 |
}
|
|
661 |
else
|
|
662 |
{
|
|
663 |
if(lIdx1 != KErrNotFound)
|
|
664 |
{
|
|
665 |
HandleSignal(lTmpMsg1,ETrue);
|
|
666 |
iBlockedSAMutex.Wait();
|
|
667 |
iBlockedSigArray.Remove(lIdx1);
|
|
668 |
iBlockedSAMutex.Signal();
|
|
669 |
}
|
|
670 |
if(lIdx2 != KErrNotFound)
|
|
671 |
{
|
|
672 |
HandleSignal(lTmpMsg2,ETrue);
|
|
673 |
iBlockedSAMutex.Wait();
|
|
674 |
iBlockedSigArray.Remove(lIdx2);
|
|
675 |
iBlockedSAMutex.Signal();
|
|
676 |
}
|
|
677 |
if(lIdx3 != KErrNotFound)
|
|
678 |
{
|
|
679 |
HandleSignal(lTmpMsg3, ETrue);
|
|
680 |
iBlockedSAMutex.Wait();
|
|
681 |
iBlockedSigArray.Remove(lIdx3);
|
|
682 |
iBlockedSAMutex.Signal();
|
|
683 |
}
|
|
684 |
}
|
|
685 |
}
|
|
686 |
break;
|
|
687 |
case TSignalMessage::EAlarmRegistration:
|
|
688 |
if((iAlarmStatus == KRequestPending) && iIsTimerActive)
|
|
689 |
{
|
|
690 |
iAlarmTimer.Cancel();
|
|
691 |
iIsTimerActive = EFalse;
|
|
692 |
}
|
|
693 |
if(lMsg.mTimeOut)
|
|
694 |
{
|
|
695 |
iAlarmTimer.After(iAlarmStatus,lMsg.mTimeOut*1000000);
|
|
696 |
iAlarmStartTime.HomeTime();
|
|
697 |
iIsTimerActive = ETrue;
|
|
698 |
}
|
|
699 |
break;
|
|
700 |
case TSignalMessage::EWaitOnChild:
|
|
701 |
lWaiter.iWaiterPid = TProcessId(lMsg.mPid);
|
|
702 |
lWaiter.iWaiterStatus = KRequestPending;
|
|
703 |
lIdx = iChildWaiterArray.Find(lWaiter,TChildWaiter::MatchByPid);
|
|
704 |
if(lIdx == KErrNotFound)
|
|
705 |
{
|
|
706 |
lWaiter.iWaiterPid = TProcessId(lMsg.mPid);
|
|
707 |
lWaiter.iWaiterStatus = KRequestPending;
|
|
708 |
iChildWaiterArray.Append(lWaiter);
|
|
709 |
lIdx = iChildWaiterArray.Find(lWaiter,TChildWaiter::MatchByPid);
|
|
710 |
if(lIdx != KErrNotFound)
|
|
711 |
{
|
|
712 |
RProcess lProcess;
|
|
713 |
if(lProcess.Open(TProcessId(iChildWaiterArray[lIdx].iWaiterPid)) == KErrNone)
|
|
714 |
{
|
|
715 |
lProcess.Logon(iChildWaiterArray[lIdx].iWaiterStatus);
|
|
716 |
}
|
|
717 |
}
|
|
718 |
}
|
|
719 |
else
|
|
720 |
{
|
|
721 |
TProcessId lPid(iChildWaiterArray[lIdx].iWaiterPid);
|
|
722 |
iChildWaiterArray[lIdx].iWaiterStatus = KRequestPending;
|
|
723 |
RProcess lProcess(lPid);
|
|
724 |
lProcess.Logon(iChildWaiterArray[lIdx].iWaiterStatus);
|
|
725 |
}
|
|
726 |
break;
|
|
727 |
default:
|
|
728 |
break;
|
|
729 |
}
|
|
730 |
}
|
|
731 |
}
|
|
732 |
iPipeReadStatus = KRequestPending;
|
|
733 |
iSignalReadPipe.NotifyDataAvailable(iPipeReadStatus);
|
|
734 |
}
|
|
735 |
if((iAlarmStatus != KRequestPending) && iIsTimerActive)
|
|
736 |
{
|
|
737 |
if(iAlarmStatus == KErrNone)
|
|
738 |
{
|
|
739 |
TSignalMessage lMsg;
|
|
740 |
lMsg.mType = TSignalMessage::ESignal;
|
|
741 |
lMsg.mSignal = SIGALRM;
|
|
742 |
WaitOrHandleSignal(lMsg);
|
|
743 |
}
|
|
744 |
iIsTimerActive = EFalse;
|
|
745 |
}
|
|
746 |
TBool lChildCheckRunning = ETrue;
|
|
747 |
while(lChildCheckRunning)
|
|
748 |
{
|
|
749 |
TChildWaiter lWaiter;
|
|
750 |
lWaiter.iWaiterStatus = KErrNone; // dummy waiter to match non pending waiters
|
|
751 |
TInt lTimerIdx = iChildWaiterArray.Find(lWaiter,TChildWaiter::MatchNotPending);
|
|
752 |
if(lTimerIdx != KErrNotFound)
|
|
753 |
{
|
|
754 |
TSignalMessage lSigChldMsg;
|
|
755 |
lSigChldMsg.mType = TSignalMessage::ESignal;
|
|
756 |
lSigChldMsg.mSignal = SIGCHLD;
|
|
757 |
TBuf8<KSigMsgLength> lMsgBuf;
|
|
758 |
lSigChldMsg.Marshall(lMsgBuf);
|
|
759 |
iSignalWritePipe.Write(lMsgBuf,KSigMsgLength);
|
|
760 |
iChildWaiterArray.Remove(lTimerIdx);
|
|
761 |
}
|
|
762 |
else
|
|
763 |
{
|
|
764 |
lChildCheckRunning = EFalse;
|
|
765 |
}
|
|
766 |
}
|
|
767 |
}
|
|
768 |
if(iPipeReadStatus == KRequestPending)
|
|
769 |
{
|
|
770 |
iSignalReadPipe.CancelDataAvailable();
|
|
771 |
}
|
|
772 |
iSignalReadPipe.Close();
|
|
773 |
|
|
774 |
if(iAlarmStatus == KRequestPending)
|
|
775 |
{
|
|
776 |
iAlarmTimer.Cancel();
|
|
777 |
}
|
|
778 |
TInt lCounterIdx = 0;
|
|
779 |
for(lCounterIdx = 0; lCounterIdx < iChildWaiterArray.Count(); lCounterIdx++)
|
|
780 |
{
|
|
781 |
if(iChildWaiterArray[lCounterIdx].iWaiterStatus == KRequestPending)
|
|
782 |
{
|
|
783 |
RProcess lProcess;
|
|
784 |
if(lProcess.Open(TProcessId(iChildWaiterArray[lCounterIdx].iWaiterPid)) == KErrNone)
|
|
785 |
{
|
|
786 |
lProcess.LogonCancel(iChildWaiterArray[lCounterIdx].iWaiterStatus);
|
|
787 |
lProcess.Close();
|
|
788 |
}
|
|
789 |
}
|
|
790 |
}
|
|
791 |
iSignalSession.Close();
|
|
792 |
return KErrNone;
|
|
793 |
}
|
|
794 |
|
|
795 |
static TInt sSignalHandler(TAny* aData)
|
|
796 |
{
|
|
797 |
CLocalSystemInterface* lClsi = 0;
|
|
798 |
TInt ret = 0;
|
|
799 |
if(aData == 0)
|
|
800 |
return KErrGeneral;
|
|
801 |
|
|
802 |
lClsi = static_cast<CLocalSystemInterface*>(aData);
|
|
803 |
CTrapCleanup* pCleanup = CTrapCleanup::New();
|
|
804 |
if (pCleanup)
|
|
805 |
{
|
|
806 |
ret = lClsi->SignalHandler();
|
|
807 |
delete pCleanup;
|
|
808 |
}
|
|
809 |
else
|
|
810 |
{
|
|
811 |
ret = KErrNoMemory;
|
|
812 |
}
|
|
813 |
return ret;
|
|
814 |
}
|
|
815 |
|
|
816 |
// -----------------------------------------------------------------------------
|
|
817 |
// CLocalSystemInterface::InitSignalHandler
|
|
818 |
// -----------------------------------------------------------------------------
|
|
819 |
//
|
|
820 |
EXPORT_C void CLocalSystemInterface::InitSignalHandler()
|
|
821 |
{
|
|
822 |
if(iSignalsInitialized)
|
|
823 |
return;
|
|
824 |
|
|
825 |
// Create thread
|
|
826 |
iSignalHandlerThread.Create(KNullDesC,sSignalHandler,KDefaultStackSize,NULL,this);
|
|
827 |
// Raise priority
|
|
828 |
iSignalHandlerThread.SetPriority(EPriorityAbsoluteHigh);
|
|
829 |
iSignalHandlerThread.Resume();
|
|
830 |
|
|
831 |
iSignalInitSemaphore.Wait();
|
|
832 |
return;
|
|
833 |
}
|
|
834 |
|
|
835 |
// -----------------------------------------------------------------------------
|
|
836 |
// CLocalSystemInterface::EnsureSignalsInitialized
|
|
837 |
// -----------------------------------------------------------------------------
|
|
838 |
//
|
|
839 |
TInt CLocalSystemInterface::EnsureSignalsInitialized()
|
|
840 |
{
|
|
841 |
return KErrNone;
|
|
842 |
}
|
|
843 |
|
|
844 |
// -----------------------------------------------------------------------------
|
|
845 |
// CLocalSystemInterface::SigWaitInternal
|
|
846 |
// -----------------------------------------------------------------------------
|
|
847 |
//
|
|
848 |
TInt CLocalSystemInterface::SigWaitInternal(TUint64 aWaitSet,TSignalMessage* aMsg,TInt aTimeout,TBool aTimeCheckFailed)
|
|
849 |
{
|
|
850 |
if(aWaitSet == 0)
|
|
851 |
return KErrArgument;
|
|
852 |
|
|
853 |
TInt lArrayIdx = 0,lSignalIdx = 1;
|
|
854 |
while(lSignalIdx <= SIGRTMAX)
|
|
855 |
{
|
|
856 |
if(SIG_SIGNAL_PRESENT_IN_SIGSET(lSignalIdx,aWaitSet) && lSignalIdx != SIGKILL && lSignalIdx != SIGSTOP)
|
|
857 |
{
|
|
858 |
TSignalMessage lTmpMsg;
|
|
859 |
|
|
860 |
lTmpMsg.mType = TSignalMessage::ESignal;
|
|
861 |
lTmpMsg.mSignal = lSignalIdx;
|
|
862 |
iBlockedSAMutex.Wait();
|
|
863 |
lArrayIdx = iBlockedSigArray.Find(lTmpMsg,TSignalMessage::SignalMatchBySigNum);
|
|
864 |
iBlockedSAMutex.Signal();
|
|
865 |
if(lArrayIdx != KErrNotFound)
|
|
866 |
{
|
|
867 |
if(aMsg)
|
|
868 |
{
|
|
869 |
aMsg->mType = TSignalMessage::ESignal;
|
|
870 |
iBlockedSAMutex.Wait();
|
|
871 |
aMsg->mSignal = iBlockedSigArray[lArrayIdx].mSignal;
|
|
872 |
iBlockedSAMutex.Signal();
|
|
873 |
}
|
|
874 |
iBlockedSAMutex.Wait();
|
|
875 |
iBlockedSigArray.Remove(lArrayIdx);
|
|
876 |
iBlockedSAMutex.Signal();
|
|
877 |
return KErrNone;
|
|
878 |
}
|
|
879 |
|
|
880 |
lTmpMsg.mType = TSignalMessage::ESignalValuePair;
|
|
881 |
lTmpMsg.mSigVal.mSignal = lSignalIdx;
|
|
882 |
iBlockedSAMutex.Wait();
|
|
883 |
lArrayIdx = iBlockedSigArray.Find(lTmpMsg,TSignalMessage::SigValMatchBySigNum);
|
|
884 |
iBlockedSAMutex.Signal();
|
|
885 |
if(lArrayIdx != KErrNotFound)
|
|
886 |
{
|
|
887 |
if(aMsg)
|
|
888 |
{
|
|
889 |
aMsg->mType = TSignalMessage::ESignalValuePair;
|
|
890 |
iBlockedSAMutex.Wait();
|
|
891 |
aMsg->mSigVal.mSignal = iBlockedSigArray[lArrayIdx].mSigVal.mSignal;
|
|
892 |
aMsg->mSigVal.mValue = iBlockedSigArray[lArrayIdx].mSigVal.mValue;
|
|
893 |
iBlockedSAMutex.Signal();
|
|
894 |
}
|
|
895 |
iBlockedSAMutex.Wait();
|
|
896 |
iBlockedSigArray.Remove(lArrayIdx);
|
|
897 |
iBlockedSAMutex.Signal();
|
|
898 |
return KErrNone;
|
|
899 |
}
|
|
900 |
|
|
901 |
lTmpMsg.mType = TSignalMessage::ERtTimerSignal;
|
|
902 |
lTmpMsg.mRtSignal.mSignal = lSignalIdx;
|
|
903 |
iBlockedSAMutex.Wait();
|
|
904 |
lArrayIdx = iBlockedSigArray.Find(lTmpMsg,TSignalMessage::SigValMatchBySigNum);
|
|
905 |
iBlockedSAMutex.Signal();
|
|
906 |
if(lArrayIdx != KErrNotFound)
|
|
907 |
{
|
|
908 |
if(aMsg)
|
|
909 |
{
|
|
910 |
aMsg->mType = TSignalMessage::ERtTimerSignal;
|
|
911 |
iBlockedSAMutex.Wait();
|
|
912 |
aMsg->mRtSignal.mSignal = iBlockedSigArray[lArrayIdx].mRtSignal.mSignal;
|
|
913 |
iBlockedSAMutex.Signal();
|
|
914 |
}
|
|
915 |
iBlockedSAMutex.Wait();
|
|
916 |
iBlockedSigArray.Remove(lArrayIdx);
|
|
917 |
iBlockedSAMutex.Signal();
|
|
918 |
return KErrNone;
|
|
919 |
}
|
|
920 |
}
|
|
921 |
lSignalIdx++;
|
|
922 |
}
|
|
923 |
|
|
924 |
if(aTimeCheckFailed)
|
|
925 |
return KErrGeneral;
|
|
926 |
|
|
927 |
TSignalMessage lMsg;
|
|
928 |
TSignalWaiter lWaiter(aWaitSet,&lMsg);
|
|
929 |
|
|
930 |
iSignalWaiterMutex.Wait();
|
|
931 |
RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
|
|
932 |
iSignalWaiterArray.Append(lWaiter);
|
|
933 |
User::SwitchHeap(oldHeap);
|
|
934 |
|
|
935 |
iSignalWaiterMutex.Signal();
|
|
936 |
if(aTimeout > 0)
|
|
937 |
{
|
|
938 |
TInt lRetVal = lWaiter.iSigWaitSemaphore.Wait(aTimeout);
|
|
939 |
if(lRetVal != KErrNone)
|
|
940 |
{
|
|
941 |
// Timed out
|
|
942 |
TSignalWaiter lTempWaiter(0,0);
|
|
943 |
TInt lIdx;
|
|
944 |
iSignalWaiterMutex.Wait();
|
|
945 |
lIdx = iSignalWaiterArray.Find(lTempWaiter,TSignalWaiter::MatchByThreadId);
|
|
946 |
if(lIdx != KErrNotFound)
|
|
947 |
{
|
|
948 |
oldHeap = User::SwitchHeap(iPrivateHeap);
|
|
949 |
iSignalWaiterArray.Remove(lIdx);
|
|
950 |
User::SwitchHeap(oldHeap);
|
|
951 |
}
|
|
952 |
iSignalWaiterMutex.Signal();
|
|
953 |
return KErrTimedOut;
|
|
954 |
}
|
|
955 |
}
|
|
956 |
else
|
|
957 |
lWaiter.iSigWaitSemaphore.Wait();
|
|
958 |
|
|
959 |
TSignalWaiter lTempWaiter(0,0);
|
|
960 |
TInt lIdx = 0;
|
|
961 |
iSignalWaiterMutex.Wait();
|
|
962 |
lIdx = iSignalWaiterArray.Find(lTempWaiter,TSignalWaiter::MatchByThreadId);
|
|
963 |
if(lIdx != KErrNotFound)
|
|
964 |
{
|
|
965 |
oldHeap = User::SwitchHeap(iPrivateHeap);
|
|
966 |
iSignalWaiterArray.Remove(lIdx);
|
|
967 |
User::SwitchHeap(oldHeap);
|
|
968 |
}
|
|
969 |
iSignalWaiterMutex.Signal();
|
|
970 |
|
|
971 |
if(lMsg.mType == TSignalMessage::ESignal)
|
|
972 |
{
|
|
973 |
aMsg->mType = TSignalMessage::ESignal;
|
|
974 |
aMsg->mSignal = lMsg.mSignal;
|
|
975 |
}
|
|
976 |
else if(lMsg.mType == TSignalMessage::ESignalValuePair)
|
|
977 |
{
|
|
978 |
aMsg->mType = TSignalMessage::ESignalValuePair;
|
|
979 |
aMsg->mSigVal.mSignal = lMsg.mSigVal.mSignal;
|
|
980 |
aMsg->mSigVal.mValue = lMsg.mSigVal.mValue;
|
|
981 |
}
|
|
982 |
else if(lMsg.mType == TSignalMessage::ERtTimerSignal)
|
|
983 |
{
|
|
984 |
aMsg->mType = TSignalMessage::ERtTimerSignal;
|
|
985 |
aMsg->mRtSignal.mSignal = lMsg.mRtSignal.mSignal;
|
|
986 |
}
|
|
987 |
else
|
|
988 |
{
|
|
989 |
return KErrGeneral;
|
|
990 |
}
|
|
991 |
return KErrNone;
|
|
992 |
}
|
|
993 |
|
|
994 |
// -----------------------------------------------------------------------------
|
|
995 |
// CLocalSystemInterface::RegisterExitNotification
|
|
996 |
// -----------------------------------------------------------------------------
|
|
997 |
//
|
|
998 |
void CLocalSystemInterface::RegisterExitNotification(TProcessId aPid)
|
|
999 |
{
|
|
1000 |
TSignalMessage lMsg;
|
|
1001 |
lMsg.mType = TSignalMessage::EWaitOnChild;
|
|
1002 |
lMsg.mPid = aPid.Id();
|
|
1003 |
TBuf8<KSigMsgLength> lMsgBuf;
|
|
1004 |
lMsg.Marshall(lMsgBuf);
|
|
1005 |
iSignalWritePipe.Write(lMsgBuf,KSigMsgLength);
|
|
1006 |
return;
|
|
1007 |
}
|
|
1008 |
|
|
1009 |
// -----------------------------------------------------------------------------
|
|
1010 |
// CLocalSystemInterface::InitializeSigHandlers
|
|
1011 |
// -----------------------------------------------------------------------------
|
|
1012 |
//
|
|
1013 |
void CLocalSystemInterface::InitializeSignalHandlers()
|
|
1014 |
{
|
|
1015 |
iSigHandlerMutex.CreateLocal();
|
|
1016 |
iAlarmTimer.CreateLocal(); // what should be done if fails
|
|
1017 |
iIsTimerActive = EFalse;
|
|
1018 |
}
|
|
1019 |
|
|
1020 |
// -----------------------------------------------------------------------------
|
|
1021 |
// CLocalSystemInterface::HandleSignal
|
|
1022 |
// -----------------------------------------------------------------------------
|
|
1023 |
//
|
|
1024 |
void CLocalSystemInterface::HandleSignal(TSignalMessage& aMsg,TBool aIsDequeued)
|
|
1025 |
{
|
|
1026 |
TUint8 lSigNum = 0;
|
|
1027 |
|
|
1028 |
if(aMsg.mType == TSignalMessage::ESignal)
|
|
1029 |
lSigNum = aMsg.mSignal;
|
|
1030 |
else if(aMsg.mType == TSignalMessage::ERtTimerSignal)
|
|
1031 |
lSigNum = aMsg.mRtSignal.mSignal;
|
|
1032 |
else
|
|
1033 |
lSigNum = aMsg.mSigVal.mSignal;
|
|
1034 |
|
|
1035 |
if(lSigNum <= 0 || lSigNum > SIGRTMAX)
|
|
1036 |
return;
|
|
1037 |
|
|
1038 |
if(SIG_SIGNAL_PRESENT_IN_SIGSET(lSigNum,iSigMask) && !aIsDequeued)
|
|
1039 |
{
|
|
1040 |
TInt lIdx = 0;
|
|
1041 |
TSignalMessage lTmpMsg;
|
|
1042 |
|
|
1043 |
lTmpMsg.mType = aMsg.mType;
|
|
1044 |
if(aMsg.mType == TSignalMessage::ESignal)
|
|
1045 |
{
|
|
1046 |
lTmpMsg.mSignal = aMsg.mSignal;
|
|
1047 |
iBlockedSAMutex.Wait();
|
|
1048 |
lIdx = iBlockedSigArray.Find(lTmpMsg,TSignalMessage::SignalMatchBySigNum);
|
|
1049 |
iBlockedSAMutex.Signal();
|
|
1050 |
if(lIdx == KErrNotFound || lSigNum >= SIGRTMIN)
|
|
1051 |
{
|
|
1052 |
lTmpMsg.mType = TSignalMessage::ESignal;
|
|
1053 |
lTmpMsg.mSignal = aMsg.mSignal;
|
|
1054 |
iBlockedSAMutex.Wait();
|
|
1055 |
iBlockedSigArray.Append(lTmpMsg);
|
|
1056 |
iBlockedSAMutex.Signal();
|
|
1057 |
}
|
|
1058 |
}
|
|
1059 |
else if(aMsg.mType == TSignalMessage::ESignalValuePair)
|
|
1060 |
{
|
|
1061 |
lTmpMsg.mSigVal.mSignal = aMsg.mSigVal.mSignal;
|
|
1062 |
lTmpMsg.mSigVal.mValue = aMsg.mSigVal.mValue;
|
|
1063 |
iBlockedSAMutex.Wait();
|
|
1064 |
iBlockedSigArray.Append(lTmpMsg);
|
|
1065 |
iBlockedSAMutex.Signal();
|
|
1066 |
}
|
|
1067 |
else if(aMsg.mType == TSignalMessage::ERtTimerSignal)
|
|
1068 |
{
|
|
1069 |
lTmpMsg.mSignal = aMsg.mRtSignal.mSignal;
|
|
1070 |
iBlockedSAMutex.Wait();
|
|
1071 |
lIdx = iBlockedSigArray.Find(lTmpMsg,TSignalMessage::SignalMatchBySigNum);
|
|
1072 |
iBlockedSAMutex.Signal();
|
|
1073 |
if(lIdx == KErrNotFound || lSigNum >= SIGRTMIN)
|
|
1074 |
{
|
|
1075 |
lTmpMsg.mType = TSignalMessage::ERtTimerSignal;
|
|
1076 |
lTmpMsg.mRtSignal.mSignal = aMsg.mRtSignal.mSignal;
|
|
1077 |
iBlockedSAMutex.Wait();
|
|
1078 |
iBlockedSigArray.Append(lTmpMsg);
|
|
1079 |
iBlockedSAMutex.Signal();
|
|
1080 |
}
|
|
1081 |
}
|
|
1082 |
|
|
1083 |
return;
|
|
1084 |
}
|
|
1085 |
else
|
|
1086 |
{
|
|
1087 |
SuspendOtherThreads();// suspend all other threads
|
|
1088 |
TUint32 lSigVal = 0;
|
|
1089 |
TSignalHandler lCurHandler = 0;
|
|
1090 |
TSignalAction lCurAction = 0;
|
|
1091 |
|
|
1092 |
if(aMsg.mType == TSignalMessage::ESignal)
|
|
1093 |
lSigNum = aMsg.mSignal;
|
|
1094 |
else if(aMsg.mType == TSignalMessage::ESignalValuePair)
|
|
1095 |
{
|
|
1096 |
lSigNum = aMsg.mSigVal.mSignal;
|
|
1097 |
lSigVal = aMsg.mSigVal.mValue;
|
|
1098 |
}
|
|
1099 |
else if(aMsg.mType == TSignalMessage::ERtTimerSignal)
|
|
1100 |
{
|
|
1101 |
lSigNum = aMsg.mRtSignal.mSignal;
|
|
1102 |
#ifdef SYMBIAN_OE_LIBRT
|
|
1103 |
//reset the overrun count before calling the handler/action.
|
|
1104 |
ResetOverrun(aMsg.mRtSignal.mTimerId);
|
|
1105 |
#endif //SYMBIAN_OE_LIBRT
|
|
1106 |
}
|
|
1107 |
else
|
|
1108 |
{
|
|
1109 |
ResumeOtherThreads();
|
|
1110 |
return;
|
|
1111 |
}
|
|
1112 |
iSigHandlerMutex.Wait();
|
|
1113 |
lCurHandler = iSigActions[lSigNum -1].iSigHandler;
|
|
1114 |
lCurAction = iSigActions[lSigNum-1].iSigAction;
|
|
1115 |
|
|
1116 |
if(lCurAction)
|
|
1117 |
{
|
|
1118 |
siginfo_t lsiginfo;
|
|
1119 |
lsiginfo.si_signo = lSigNum;
|
|
1120 |
lsiginfo.si_value.sival_int = lSigVal;
|
|
1121 |
lCurAction(lSigNum,&lsiginfo,(void*)0); // setting context as 0
|
|
1122 |
}
|
|
1123 |
else
|
|
1124 |
{
|
|
1125 |
if(lCurHandler == SIG_DFL)
|
|
1126 |
{
|
|
1127 |
CallDefaultHandler(lSigNum);
|
|
1128 |
}
|
|
1129 |
else if(lCurHandler != SIG_IGN)
|
|
1130 |
{
|
|
1131 |
lCurHandler(lSigNum);
|
|
1132 |
}
|
|
1133 |
}
|
|
1134 |
ResumeOtherThreads();// resume all other threads
|
|
1135 |
}
|
|
1136 |
|
|
1137 |
if(iSigActions[lSigNum -1].iSigFlags & SA_RESETHAND)
|
|
1138 |
{
|
|
1139 |
iSigActions[lSigNum -1].iSigHandler = SIG_DFL;
|
|
1140 |
}
|
|
1141 |
iSigHandlerMutex.Signal();
|
|
1142 |
|
|
1143 |
return;
|
|
1144 |
}
|
|
1145 |
|
|
1146 |
// -----------------------------------------------------------------------------
|
|
1147 |
// sig_exit
|
|
1148 |
// -----------------------------------------------------------------------------
|
|
1149 |
//
|
|
1150 |
static void sig_exit()
|
|
1151 |
{
|
|
1152 |
Backend()->Exit(0); // Check if clean exit or terminate is to be done
|
|
1153 |
return;
|
|
1154 |
}
|
|
1155 |
|
|
1156 |
// -----------------------------------------------------------------------------
|
|
1157 |
// CLocalSystemInterface::CallDefaultHandler
|
|
1158 |
// -----------------------------------------------------------------------------
|
|
1159 |
//
|
|
1160 |
void CLocalSystemInterface::CallDefaultHandler(int aSigNum)
|
|
1161 |
{
|
|
1162 |
if(aSigNum < 1 || aSigNum > SIGRTMAX)
|
|
1163 |
return;
|
|
1164 |
|
|
1165 |
switch(aSigNum)
|
|
1166 |
{
|
|
1167 |
case SIGTERM:
|
|
1168 |
case SIGKILL:
|
|
1169 |
case SIGALRM:
|
|
1170 |
case SIGPIPE:
|
|
1171 |
sig_exit();
|
|
1172 |
break;
|
|
1173 |
case SIGQUIT:
|
|
1174 |
default:
|
|
1175 |
// SIG_IGN - Do nothing;
|
|
1176 |
break;
|
|
1177 |
}
|
|
1178 |
return;
|
|
1179 |
}
|
|
1180 |
|
|
1181 |
// -----------------------------------------------------------------------------
|
|
1182 |
// CLocalSystemInterface::SuspendOtherThreads
|
|
1183 |
// -----------------------------------------------------------------------------
|
|
1184 |
//
|
|
1185 |
_LIT(KThreadFormatString,"*");
|
|
1186 |
|
|
1187 |
TInt CLocalSystemInterface::SuspendOtherThreads()
|
|
1188 |
{
|
|
1189 |
TFileName lProcessName = RProcess().FileName();
|
|
1190 |
TBuf<256> lThreadNameString;
|
|
1191 |
TFullName lThreadName;
|
|
1192 |
|
|
1193 |
#ifdef SYMBIAN_OE_LIBRT
|
|
1194 |
TBool lFoundTimerServ = EFalse;
|
|
1195 |
#endif
|
|
1196 |
|
|
1197 |
TParsePtr lParser(lProcessName);
|
|
1198 |
TPtrC lName = lParser.NameAndExt();
|
|
1199 |
|
|
1200 |
|
|
1201 |
lThreadNameString.Append(lName);
|
|
1202 |
lThreadNameString.Append(KThreadFormatString);
|
|
1203 |
|
|
1204 |
TFindThread lFindPattern(lThreadNameString);
|
|
1205 |
TInt lRetVal = KErrNone;
|
|
1206 |
|
|
1207 |
while(lRetVal == KErrNone)
|
|
1208 |
{
|
|
1209 |
lRetVal = lFindPattern.Next(lThreadName);
|
|
1210 |
if(lRetVal == KErrNone)
|
|
1211 |
{
|
|
1212 |
#ifdef SYMBIAN_OE_LIBRT
|
|
1213 |
if(!lFoundTimerServ && (lThreadName.Match(_L("*LibrtTimerServ")) != KErrNotFound))
|
|
1214 |
{
|
|
1215 |
lFoundTimerServ = ETrue;
|
|
1216 |
continue;
|
|
1217 |
}
|
|
1218 |
#endif
|
|
1219 |
RThread lThread;
|
|
1220 |
RProcess lProcess;
|
|
1221 |
if(lThread.Open(lThreadName) == KErrNone)
|
|
1222 |
{
|
|
1223 |
lThread.Process(lProcess);
|
|
1224 |
if( (lProcess.Id() == RProcess().Id()) &&
|
|
1225 |
(lThread.Id() != RThread().Id()) )
|
|
1226 |
lThread.Suspend();
|
|
1227 |
lThread.Close();
|
|
1228 |
}
|
|
1229 |
}
|
|
1230 |
}
|
|
1231 |
|
|
1232 |
return KErrNone;
|
|
1233 |
}
|
|
1234 |
|
|
1235 |
// -----------------------------------------------------------------------------
|
|
1236 |
// CLocalSystemInterface::ResumeOtherThreads
|
|
1237 |
// -----------------------------------------------------------------------------
|
|
1238 |
//
|
|
1239 |
TInt CLocalSystemInterface::ResumeOtherThreads()
|
|
1240 |
{
|
|
1241 |
TFileName lProcessName = RProcess().FileName();
|
|
1242 |
TBuf<256> lThreadNameString;
|
|
1243 |
TFullName lThreadName;
|
|
1244 |
#ifdef SYMBIAN_OE_LIBRT
|
|
1245 |
TBool lFoundTimerServ = EFalse;
|
|
1246 |
#endif
|
|
1247 |
TParsePtr lParser(lProcessName);
|
|
1248 |
TPtrC lName = lParser.NameAndExt();
|
|
1249 |
|
|
1250 |
|
|
1251 |
lThreadNameString.Append(lName);
|
|
1252 |
lThreadNameString.Append(KThreadFormatString);
|
|
1253 |
|
|
1254 |
TFindThread lFindPattern(lThreadNameString);
|
|
1255 |
TInt lRetVal = KErrNone;
|
|
1256 |
|
|
1257 |
while(lRetVal == KErrNone)
|
|
1258 |
{
|
|
1259 |
lRetVal = lFindPattern.Next(lThreadName);
|
|
1260 |
if(lRetVal == KErrNone)
|
|
1261 |
{
|
|
1262 |
#ifdef SYMBIAN_OE_LIBRT
|
|
1263 |
if(!lFoundTimerServ && (lThreadName.Match(_L("*LibrtTimerServ")) != KErrNotFound))
|
|
1264 |
{
|
|
1265 |
lFoundTimerServ = ETrue;
|
|
1266 |
continue;
|
|
1267 |
}
|
|
1268 |
#endif
|
|
1269 |
RThread lThread;
|
|
1270 |
RProcess lProcess;
|
|
1271 |
if(lThread.Open(lThreadName) == KErrNone)
|
|
1272 |
{
|
|
1273 |
lThread.Process(lProcess);
|
|
1274 |
if( (lProcess.Id() == RProcess().Id()) &&
|
|
1275 |
(lThread.Id() != RThread().Id()) )
|
|
1276 |
lThread.Resume();
|
|
1277 |
lThread.Close();
|
|
1278 |
}
|
|
1279 |
}
|
|
1280 |
}
|
|
1281 |
|
|
1282 |
return KErrNone;
|
|
1283 |
}
|
|
1284 |
|
|
1285 |
#endif // SYMBIAN_OE_POSIX_SIGNALS
|
|
1286 |
|
|
1287 |
// -----------------------------------------------------------------------------
|
|
1288 |
// CLocalSystemInterface::fcntl
|
|
1289 |
// Implementation for fcntl
|
|
1290 |
// -----------------------------------------------------------------------------
|
|
1291 |
//
|
|
1292 |
int CLocalSystemInterface::fcntl (int aFid, int aCmd, long anArg, int& anErrno)
|
|
1293 |
{
|
|
1294 |
return iFids.fcntl(aFid, aCmd, anArg, anErrno);
|
|
1295 |
}
|
|
1296 |
|
|
1297 |
|
|
1298 |
int CLocalSystemInterface::fchmod (int fd , mode_t perms, int& anErrno)
|
|
1299 |
{
|
|
1300 |
CFileDescBase *f = NULL;
|
|
1301 |
|
|
1302 |
TInt err = iFids.At(fd, f);
|
|
1303 |
|
|
1304 |
if(!err)
|
|
1305 |
{
|
|
1306 |
switch(perms & (S_IWUSR | S_IRUSR ))
|
|
1307 |
{
|
|
1308 |
case S_IRUSR | S_IWUSR :
|
|
1309 |
case S_IWUSR :
|
|
1310 |
{
|
|
1311 |
err = f->SetAtt(0, KEntryAttReadOnly);
|
|
1312 |
break;
|
|
1313 |
}
|
|
1314 |
case S_IRUSR :
|
|
1315 |
{
|
|
1316 |
err = f->SetAtt(KEntryAttReadOnly, 0);
|
|
1317 |
break;
|
|
1318 |
}
|
|
1319 |
default :
|
|
1320 |
{
|
|
1321 |
err = KErrArgument;
|
|
1322 |
break;
|
|
1323 |
}
|
|
1324 |
}
|
|
1325 |
}
|
|
1326 |
return MapError(err, anErrno);
|
|
1327 |
}
|
|
1328 |
|
|
1329 |
// Synchronous layer over CFileTable asynchronous routines
|
|
1330 |
int CLocalSystemInterface::read (int fid, char* buf, unsigned long len, int& anErrno)
|
|
1331 |
{
|
|
1332 |
CFileDescBase* f=0;
|
|
1333 |
TBool patchErr = EFalse;
|
|
1334 |
|
|
1335 |
TInt err=iFids.Asynch(fid,f);
|
|
1336 |
if (!err)
|
|
1337 |
{
|
|
1338 |
//if the file is WRONLY then return Error here
|
|
1339 |
TUint flgs = f->Fcntl(fid, F_GETFL);
|
|
1340 |
if ((flgs & O_ACCMODE) == O_WRONLY)
|
|
1341 |
{
|
|
1342 |
anErrno = EBADF;
|
|
1343 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
|
1344 |
return -1;
|
|
1345 |
}
|
|
1346 |
|
|
1347 |
TRequestStatus readStatus;
|
|
1348 |
TRequestStatus timerStatus(KRequestPending);
|
|
1349 |
RTimer theTimer;
|
|
1350 |
TBool timerRunning = EFalse;
|
|
1351 |
|
|
1352 |
TPtr8 ptr((TText8 *)buf, len);
|
|
1353 |
|
|
1354 |
if (f->TimedRead())
|
|
1355 |
{
|
|
1356 |
TTimeIntervalMicroSeconds32 timeout(f->TimeoutValue()*1000);
|
|
1357 |
theTimer.CreateLocal();
|
|
1358 |
theTimer.After(timerStatus, timeout);
|
|
1359 |
timerRunning = ETrue;
|
|
1360 |
}
|
|
1361 |
|
|
1362 |
//If its console based, fid = {0, 1, 2 }
|
|
1363 |
if( fid >= 0 && fid <= 2 )
|
|
1364 |
{
|
|
1365 |
f->SetFid(fid);
|
|
1366 |
}
|
|
1367 |
|
|
1368 |
f->Read(ptr, readStatus);
|
|
1369 |
|
|
1370 |
User::WaitForRequest(readStatus, timerStatus);
|
|
1371 |
|
|
1372 |
if (timerRunning)
|
|
1373 |
{
|
|
1374 |
if (timerStatus.Int() != KRequestPending)
|
|
1375 |
{
|
|
1376 |
//cancel the read and wait for it
|
|
1377 |
f->ReadCancel();
|
|
1378 |
patchErr = ETrue; //report this as a timeout not a cancel!!
|
|
1379 |
User::WaitForRequest(readStatus);
|
|
1380 |
}
|
|
1381 |
else
|
|
1382 |
{
|
|
1383 |
//if the timer was in operation
|
|
1384 |
//cancel the timer
|
|
1385 |
theTimer.Cancel();
|
|
1386 |
User::WaitForRequest(timerStatus);
|
|
1387 |
}
|
|
1388 |
theTimer.Close();
|
|
1389 |
}
|
|
1390 |
|
|
1391 |
err=f->ReadCompletion(ptr, readStatus.Int());
|
|
1392 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
|
1393 |
if (err>0)
|
|
1394 |
return err;
|
|
1395 |
else if( (f->Attributes() & KPipeFd )|| (fid == 0))
|
|
1396 |
{
|
|
1397 |
// if EOF is reached in case of pipes or stdin
|
|
1398 |
// TODO: Verify that this check is valid for console or comm-based stdin?
|
|
1399 |
if(err == KErrEof)
|
|
1400 |
{
|
|
1401 |
MapError(err,anErrno);
|
|
1402 |
return 0;
|
|
1403 |
}
|
|
1404 |
}
|
|
1405 |
else if( f->Type()==CFileDescBase::ESocketDesc || f->Type()==CFileDescBase::EFileSocketDesc)
|
|
1406 |
{
|
|
1407 |
// if EOF is reached for the Socket return 0
|
|
1408 |
if(err == KErrEof)
|
|
1409 |
{
|
|
1410 |
return 0;
|
|
1411 |
}
|
|
1412 |
if(err == KErrDisconnected)
|
|
1413 |
{
|
|
1414 |
err = ECONNRESET;
|
|
1415 |
}
|
|
1416 |
}
|
|
1417 |
}
|
|
1418 |
if (patchErr)
|
|
1419 |
err = ETIMEDOUT;
|
|
1420 |
|
|
1421 |
return MapError(err,anErrno);
|
|
1422 |
}
|
|
1423 |
|
|
1424 |
int CLocalSystemInterface::write (int fid, const char* buf, unsigned long len, int& anErrno)
|
|
1425 |
{
|
|
1426 |
CFileDescBase* f=0;
|
|
1427 |
TInt err=iFids.Asynch(fid,f);
|
|
1428 |
if (!err)
|
|
1429 |
{
|
|
1430 |
TRequestStatus status;
|
|
1431 |
TPtr8 ptr((TText8 *)buf, len, len);
|
|
1432 |
|
|
1433 |
//If its console based, fid = {0, 1, 2 }
|
|
1434 |
if( fid >= 0 && fid <= 2 )
|
|
1435 |
{
|
|
1436 |
f->SetFid(fid);
|
|
1437 |
}
|
|
1438 |
|
|
1439 |
TUint flgs = f->Fcntl(fid, F_GETFL);
|
|
1440 |
|
|
1441 |
if((flgs & O_ACCMODE) == O_RDONLY)
|
|
1442 |
{
|
|
1443 |
anErrno = EBADF;
|
|
1444 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
|
1445 |
return -1;
|
|
1446 |
}
|
|
1447 |
f->Write(ptr,status);
|
|
1448 |
User::WaitForRequest(status);
|
|
1449 |
err=f->WriteCompletion(ptr, status.Int());
|
|
1450 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
|
1451 |
if (err > 0)
|
|
1452 |
return err;
|
|
1453 |
if((f->Type() == CFileDescBase::EFileSocketDesc || f->Type() == CFileDescBase::ESocketDesc) && err == KErrDisconnected)
|
|
1454 |
{
|
|
1455 |
err = ECONNRESET;
|
|
1456 |
}
|
|
1457 |
}
|
|
1458 |
return MapError(err,anErrno);
|
|
1459 |
}
|
|
1460 |
|
|
1461 |
int CLocalSystemInterface::recvfrom (int fid, char* buf, unsigned long len, int flags, struct sockaddr* from, unsigned long* fromsize, int& anErrno)
|
|
1462 |
{
|
|
1463 |
CFileDescBase* f=0;
|
|
1464 |
TInt err=iFids.Asynch(fid,f);
|
|
1465 |
if (!err)
|
|
1466 |
{
|
|
1467 |
TRequestStatus status;
|
|
1468 |
TPtr8 ptr((TText8 *)buf, len);
|
|
1469 |
struct sockaddr tmpAddr;
|
|
1470 |
TUSockAddr addr(&tmpAddr);
|
|
1471 |
f->RecvFrom(ptr,addr,flags,status);
|
|
1472 |
User::WaitForRequest(status);
|
|
1473 |
TInt ret=0;
|
|
1474 |
err=f->CompletionStatus(ret, status.Int());
|
|
1475 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
|
1476 |
if (err==0)
|
|
1477 |
{
|
|
1478 |
if(f->Type() == CFileSocketDesc::EFileSocketDesc)
|
|
1479 |
{
|
|
1480 |
((CFileSocketDesc*)f)->GetLocalSockAddrByPort((sockaddr_un*)from,fromsize,addr.Port());
|
|
1481 |
}
|
|
1482 |
else
|
|
1483 |
{
|
|
1484 |
addr.Get(from,fromsize);
|
|
1485 |
}
|
|
1486 |
|
|
1487 |
return ptr.Length();
|
|
1488 |
}
|
|
1489 |
}
|
|
1490 |
if(err == KErrDisconnected)
|
|
1491 |
{
|
|
1492 |
anErrno = ECONNRESET;
|
|
1493 |
return -1;
|
|
1494 |
}
|
|
1495 |
if (err == KErrWouldBlock)
|
|
1496 |
{
|
|
1497 |
return MapError(EAGAIN, anErrno);
|
|
1498 |
}
|
|
1499 |
else
|
|
1500 |
{
|
|
1501 |
return MapError(err,anErrno);
|
|
1502 |
}
|
|
1503 |
}
|
|
1504 |
|
|
1505 |
int CLocalSystemInterface::sendto (int fid, const char* buf, unsigned long len, int flags, struct sockaddr* to, unsigned long tosize, int& anErrno)
|
|
1506 |
{
|
|
1507 |
CFileDescBase* f=0;
|
|
1508 |
TInt err=iFids.Asynch(fid,f);
|
|
1509 |
if (!err)
|
|
1510 |
{
|
|
1511 |
TRequestStatus status;
|
|
1512 |
TPtr8 ptr((TText8 *)buf, len, len);
|
|
1513 |
TInt bytesSent = 0;
|
|
1514 |
f->SendTo(ptr,to,tosize,flags,status);
|
|
1515 |
User::WaitForRequest(status);
|
|
1516 |
err=f->CompletionStatus(bytesSent, status.Int());
|
|
1517 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
|
1518 |
if (err==0)
|
|
1519 |
{
|
|
1520 |
return bytesSent;
|
|
1521 |
}
|
|
1522 |
}
|
|
1523 |
if (err == KErrNotReady)
|
|
1524 |
{
|
|
1525 |
anErrno = EPIPE;
|
|
1526 |
return -1;
|
|
1527 |
}
|
|
1528 |
if(err == KErrDisconnected)
|
|
1529 |
{
|
|
1530 |
anErrno = ECONNRESET;
|
|
1531 |
return -1;
|
|
1532 |
}
|
|
1533 |
|
|
1534 |
// A Hack to convert KErrTooBig to EMSGSIZE for this API.
|
|
1535 |
// For any KErrTooBig, MapError will convert it to EFAULT.
|
|
1536 |
if (err == KErrTooBig)
|
|
1537 |
{
|
|
1538 |
anErrno = EAGAIN;
|
|
1539 |
return -1;
|
|
1540 |
}
|
|
1541 |
return MapError(err,anErrno);
|
|
1542 |
}
|
|
1543 |
|
|
1544 |
int CLocalSystemInterface::fsync (int fid, int& anErrno)
|
|
1545 |
{
|
|
1546 |
CFileDescBase* f=0;
|
|
1547 |
TInt err=iFids.Asynch(fid,f);
|
|
1548 |
if (!err)
|
|
1549 |
{
|
|
1550 |
TRequestStatus status;
|
|
1551 |
f->Sync(status);
|
|
1552 |
User::WaitForRequest(status);
|
|
1553 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
|
1554 |
err=status.Int();
|
|
1555 |
}
|
|
1556 |
return MapError(err,anErrno);
|
|
1557 |
}
|
|
1558 |
|
|
1559 |
int CLocalSystemInterface::shutdown (int fid, int how, int& anErrno)
|
|
1560 |
{
|
|
1561 |
CFileDescBase* f=0;
|
|
1562 |
TInt err=iFids.Asynch(fid,f);
|
|
1563 |
if (!err)
|
|
1564 |
{
|
|
1565 |
TRequestStatus status;
|
|
1566 |
f->Shutdown(how,status);
|
|
1567 |
User::WaitForRequest(status);
|
|
1568 |
err=status.Int();
|
|
1569 |
// SOS does not allow to RSocket::Shutdown() immediately.
|
|
1570 |
if (err == KErrNotSupported)
|
|
1571 |
{
|
|
1572 |
err = 0;
|
|
1573 |
}
|
|
1574 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
|
1575 |
}
|
|
1576 |
return MapError(err,anErrno);
|
|
1577 |
}
|
|
1578 |
|
|
1579 |
int CLocalSystemInterface::connect (int fid, const struct sockaddr* addr, unsigned long size, int& anErrno)
|
|
1580 |
{
|
|
1581 |
CFileDescBase* f=0;
|
|
1582 |
TInt err=iFids.Asynch(fid,f);
|
|
1583 |
TInt mapErr = err;
|
|
1584 |
|
|
1585 |
if(!err)
|
|
1586 |
{
|
|
1587 |
// Check if a connection request is already in progress
|
|
1588 |
// for a non-blocking socket.
|
|
1589 |
if(f->GetConnectionProgress())
|
|
1590 |
{
|
|
1591 |
// Poll to see if the connect() is completed
|
|
1592 |
err = f->Poll( EReadyForWriting );
|
|
1593 |
|
|
1594 |
// The above Poll is common for all descriptors.
|
|
1595 |
// In case of socket-descriptors, Poll will either return "KErrNone"
|
|
1596 |
// or any of the requested events. To check for Poll error in case of
|
|
1597 |
// socket-descriptors, "iPollErr" should be checked.
|
|
1598 |
if( (err < 0) || (f->iPollErr < 0) ) //Error in poll
|
|
1599 |
(err < 0) ? (mapErr = err):(mapErr = f->iPollErr);
|
|
1600 |
else if( err == 0 ) //Connect still in progress
|
|
1601 |
mapErr = EALREADY;
|
|
1602 |
else if( err & EReadyForWriting ) //Connect has completed
|
|
1603 |
f->SetConnectionProgress(EFalse);
|
|
1604 |
}
|
|
1605 |
|
|
1606 |
if(!mapErr)
|
|
1607 |
{
|
|
1608 |
TRequestStatus status;
|
|
1609 |
f->Connect(addr,size,status);
|
|
1610 |
err=status.Int();
|
|
1611 |
|
|
1612 |
if (err == KErrWouldBlock)
|
|
1613 |
{
|
|
1614 |
f->SetConnectionProgress(ETrue);
|
|
1615 |
mapErr = EINPROGRESS;
|
|
1616 |
}
|
|
1617 |
else if(err == KErrAlreadyExists)
|
|
1618 |
{
|
|
1619 |
mapErr = EISCONN;
|
|
1620 |
}
|
|
1621 |
else
|
|
1622 |
mapErr = err;
|
|
1623 |
}
|
|
1624 |
|
|
1625 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
|
1626 |
}
|
|
1627 |
|
|
1628 |
return MapError(mapErr, anErrno);
|
|
1629 |
|
|
1630 |
}
|
|
1631 |
|
|
1632 |
//
|
|
1633 |
// The CSocketDesc performing the Accept is responsible for creating the new CSocketDesc
|
|
1634 |
//
|
|
1635 |
int CLocalSystemInterface::accept (int fid, struct sockaddr *addr, size_t *size, int& anErrno)
|
|
1636 |
{
|
|
1637 |
|
|
1638 |
size_t addrlen = 0;
|
|
1639 |
if (addr && !size)
|
|
1640 |
{
|
|
1641 |
anErrno = EINVAL;
|
|
1642 |
return -1;
|
|
1643 |
}
|
|
1644 |
else if (size)
|
|
1645 |
{
|
|
1646 |
addrlen = *size;
|
|
1647 |
}
|
|
1648 |
|
|
1649 |
TUSockAddr address((TAny*)addr, addrlen);
|
|
1650 |
/* Accept implementations that use the TUSockAddr* param, first need to assert address.iError == 0 */
|
|
1651 |
|
|
1652 |
CFileDescBase* f = 0;
|
|
1653 |
TInt err=iFids.Asynch(fid,f);
|
|
1654 |
if (!err)
|
|
1655 |
{
|
|
1656 |
CFileDescBase* newf=0;
|
|
1657 |
int fd=iFids.Reserve();
|
|
1658 |
if (fd>=0)
|
|
1659 |
{
|
|
1660 |
TRequestStatus status;
|
|
1661 |
//Acquire the Lock before issuing a request to the server and release it later
|
|
1662 |
iSSLock.Wait();
|
|
1663 |
|
|
1664 |
RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
|
|
1665 |
//coverity[alloc_fn]
|
|
1666 |
f->Accept(newf,status,iSs, &address);
|
|
1667 |
User::SwitchHeap(oldHeap);
|
|
1668 |
|
|
1669 |
iSSLock.Signal();
|
|
1670 |
User::WaitForRequest(status);
|
|
1671 |
//coverity[leave_without_push]
|
|
1672 |
f->Close(); // balances the Dup() in CFileTable::Asynch()
|
|
1673 |
err=status.Int();
|
|
1674 |
if (!err)
|
|
1675 |
{
|
|
1676 |
err=iFids.Attach(fd,newf);
|
|
1677 |
if (!err)
|
|
1678 |
return fd;
|
|
1679 |
newf->Close();
|
|
1680 |
}
|
|
1681 |
else if(newf != NULL)
|
|
1682 |
{
|
|
1683 |
//coverity[leave_without_push]
|
|
1684 |
newf->Close();
|
|
1685 |
}
|
|
1686 |
iFids.Attach(fd,0); // cancel the reservation
|
|
1687 |
}
|
|
1688 |
//coverity[memory_leak]
|
|
1689 |
}
|
|
1690 |
if (err == KErrNotReady)
|
|
1691 |
{
|
|
1692 |
return MapError(EINVAL,anErrno);
|
|
1693 |
}
|
|
1694 |
else if (err == KErrWouldBlock)
|
|
1695 |
{
|
|
1696 |
return MapError(EWOULDBLOCK, anErrno);
|
|
1697 |
}
|
|
1698 |
else
|
|
1699 |
{
|
|
1700 |
return MapError(err,anErrno);
|
|
1701 |
}
|
|
1702 |
}
|
|
1703 |
|
|
1704 |
int CLocalSystemInterface::ioctl (int fid, int cmd, void* param, int& anErrno)
|
|
1705 |
{
|
|
1706 |
TRequestStatus ioctlStatus;
|
|
1707 |
TInt err=ioctl(fid,cmd,param,ioctlStatus,anErrno);
|
|
1708 |
if (err==KErrNone)
|
|
1709 |
{
|
|
1710 |
User::WaitForRequest(ioctlStatus);
|
|
1711 |
err=ioctl_complete(fid,cmd,param,ioctlStatus,anErrno);
|
|
1712 |
}
|
|
1713 |
return err;
|
|
1714 |
}
|
|
1715 |
|
|
1716 |
// C++ version of asynchronous ioctl
|
|
1717 |
|
|
1718 |
int CLocalSystemInterface::ioctl (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno)
|
|
1719 |
{
|
|
1720 |
CFileDescBase* f=0;
|
|
1721 |
TInt err=iFids.Asynch(fid,f);
|
|
1722 |
if (!err)
|
|
1723 |
{
|
|
1724 |
f->Ioctl(cmd,param,aStatus);
|
|
1725 |
f->Close(); // balances the Dup() in CFileTable::Asynch() - live dangerously!
|
|
1726 |
}
|
|
1727 |
return MapError(err,anErrno);
|
|
1728 |
}
|
|
1729 |
|
|
1730 |
int CLocalSystemInterface::ioctl_complete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno)
|
|
1731 |
{
|
|
1732 |
return iFids.ioctlcomplete(fid,cmd,param,aStatus,anErrno);
|
|
1733 |
}
|
|
1734 |
|
|
1735 |
#ifdef __SYMBIAN_COMPILE_UNUSED__
|
|
1736 |
int CLocalSystemInterface::ioctl_cancel (int fid, int& anErrno)
|
|
1737 |
{
|
|
1738 |
return iFids.ioctlcancel(fid,anErrno);
|
|
1739 |
}
|
|
1740 |
#endif //__SYMBIAN_COMPILE_UNUSED__
|
|
1741 |
|
|
1742 |
|
|
1743 |
int CLocalSystemInterface::pipe(int fildes[2], int& anErrno )
|
|
1744 |
{
|
|
1745 |
return iFids.pipe(fildes, anErrno);
|
|
1746 |
}
|
|
1747 |
|
|
1748 |
int CLocalSystemInterface::mkfifo(const wchar_t *pathName, mode_t mode, int& anErrno )
|
|
1749 |
{
|
|
1750 |
return iFids.mkfifo(pathName, mode, anErrno, iFs);
|
|
1751 |
}
|
|
1752 |
|
|
1753 |
int CLocalSystemInterface::link(const wchar_t *oldpathName, const wchar_t *newpathName, int& anErrno )
|
|
1754 |
{
|
|
1755 |
return iFids.link(oldpathName, newpathName, anErrno, iFs);
|
|
1756 |
}
|
|
1757 |
|
|
1758 |
int CLocalSystemInterface::unlink(const wchar_t *pathName, int& anErrno )
|
|
1759 |
{
|
|
1760 |
return iFids.unlink(iFs, pathName, anErrno);
|
|
1761 |
}
|
|
1762 |
|
|
1763 |
int CLocalSystemInterface::select(int maxfd, fd_set* readfds,fd_set* writefds,
|
|
1764 |
fd_set* exceptfds, struct timeval* tvptr, int& anErrno)
|
|
1765 |
{
|
|
1766 |
// select is nothing but eselect without any TRequestStatus array
|
|
1767 |
return eselect(maxfd,readfds,writefds,exceptfds,tvptr,0,NULL,anErrno);
|
|
1768 |
}
|
|
1769 |
// -----------------------------------------------------------------------------
|
|
1770 |
// CLocalSystemInterface::aselect
|
|
1771 |
// -----------------------------------------------------------------------------
|
|
1772 |
//
|
|
1773 |
int CLocalSystemInterface::aselect(int maxfd, fd_set *readfds, fd_set *writefds,
|
|
1774 |
fd_set *exceptfds, struct timeval *tvptr, TRequestStatus* requeststatus,
|
|
1775 |
int& anErrno)
|
|
1776 |
{
|
|
1777 |
// Create a seperate thread to handle the aselect
|
|
1778 |
return CreateaselectThread(maxfd, readfds, writefds, exceptfds, tvptr,
|
|
1779 |
requeststatus,anErrno);
|
|
1780 |
}
|
|
1781 |
// -----------------------------------------------------------------------------
|
|
1782 |
// CLocalSystemInterface::aselect
|
|
1783 |
// -----------------------------------------------------------------------------
|
|
1784 |
//
|
|
1785 |
int CLocalSystemInterface::cancelaselect(TRequestStatus* requeststatus,int& anErrno,int performcleanup)
|
|
1786 |
{
|
|
1787 |
iASelectLock.Wait();
|
|
1788 |
// Search for the aselect request entry in the aselect request array
|
|
1789 |
for ( TInt i=0; i<iASelectRequest.Count(); i++ )
|
|
1790 |
{
|
|
1791 |
if( (iASelectRequest[i].iRequestStatus == requeststatus) || performcleanup )
|
|
1792 |
{
|
|
1793 |
// The specified request exists
|
|
1794 |
RThread threadHandle;
|
|
1795 |
// Open a handle to the service thread
|
|
1796 |
TInt res = threadHandle.Open(iASelectRequest[i].iThreadId,EOwnerThread);
|
|
1797 |
if( res == KErrNone )
|
|
1798 |
{
|
|
1799 |
// Kill the service thread
|
|
1800 |
threadHandle.Kill(KErrCancel);
|
|
1801 |
threadHandle.Close();
|
|
1802 |
if( !performcleanup )
|
|
1803 |
{
|
|
1804 |
// Complete the request with KErrcancel
|
|
1805 |
User::RequestComplete(iASelectRequest[i].iRequestStatus,KErrCancel);
|
|
1806 |
}
|
|
1807 |
// Switch to backend heap
|
|
1808 |
RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
|
|
1809 |
// Remove the request details from the array
|
|
1810 |
iASelectRequest.Remove(i);
|
|
1811 |
// Switch back to old heap
|
|
1812 |
User::SwitchHeap(oldHeap);
|
|
1813 |
if( !performcleanup )
|
|
1814 |
{
|
|
1815 |
iASelectLock.Signal();
|
|
1816 |
return MapError(KErrNone, anErrno);
|
|
1817 |
}
|
|
1818 |
}
|
|
1819 |
else
|
|
1820 |
{
|
|
1821 |
if( !performcleanup )
|
|
1822 |
{
|
|
1823 |
iASelectLock.Signal();
|
|
1824 |
// unable to open a handle to the service thread
|
|
1825 |
return MapError(res, anErrno);
|
|
1826 |
}
|
|
1827 |
}
|
|
1828 |
}
|
|
1829 |
}
|
|
1830 |
iASelectLock.Signal();
|
|
1831 |
// No request found with the specified TRequestStatus object
|
|
1832 |
if( !performcleanup )
|
|
1833 |
{
|
|
1834 |
return MapError(KErrNotFound, anErrno);
|
|
1835 |
}
|
|
1836 |
else
|
|
1837 |
{
|
|
1838 |
return MapError(KErrNone, anErrno);
|
|
1839 |
}
|
|
1840 |
}
|
|
1841 |
// -----------------------------------------------------------------------------
|
|
1842 |
// CLocalSystemInterface::ASelectRequest
|
|
1843 |
// -----------------------------------------------------------------------------
|
|
1844 |
//
|
|
1845 |
RArray<TASelectRequest>& CLocalSystemInterface::ASelectRequest()
|
|
1846 |
{
|
|
1847 |
// Return a reference to the array
|
|
1848 |
return iASelectRequest;
|
|
1849 |
}
|
|
1850 |
// -----------------------------------------------------------------------------
|
|
1851 |
// CLocalSystemInterface::ASelectLock
|
|
1852 |
// -----------------------------------------------------------------------------
|
|
1853 |
//
|
|
1854 |
RFastLock& CLocalSystemInterface::ASelectLock()
|
|
1855 |
{
|
|
1856 |
// Return a reference to the array
|
|
1857 |
return iASelectLock;
|
|
1858 |
}
|
|
1859 |
// -----------------------------------------------------------------------------
|
|
1860 |
// CLocalSystemInterface::eselect
|
|
1861 |
// -----------------------------------------------------------------------------
|
|
1862 |
//
|
|
1863 |
int CLocalSystemInterface::eselect(int maxfd, fd_set *readfds, fd_set *writefds,
|
|
1864 |
fd_set *exceptfds, struct timeval *tvptr, int arraycount,
|
|
1865 |
TRequestStatus* waitarray,int& anErrno)
|
|
1866 |
{
|
|
1867 |
unsigned long timeout = 0;
|
|
1868 |
if (tvptr)
|
|
1869 |
{
|
|
1870 |
if (tvptr->tv_sec < 0 || tvptr->tv_usec < 0)
|
|
1871 |
{
|
|
1872 |
anErrno = EINVAL;
|
|
1873 |
return -1;
|
|
1874 |
}
|
|
1875 |
// converting to micro seconds
|
|
1876 |
timeout = KConvertToMicroSecond * tvptr->tv_sec + tvptr->tv_usec;
|
|
1877 |
}
|
|
1878 |
|
|
1879 |
// validate maxfd
|
|
1880 |
if (maxfd < 0 || maxfd > FD_SETSIZE)
|
|
1881 |
{
|
|
1882 |
anErrno = EINVAL;
|
|
1883 |
return -1;
|
|
1884 |
}
|
|
1885 |
// maxfd should not be more than OPEN_MAX
|
|
1886 |
if(maxfd > OPEN_MAX)
|
|
1887 |
{
|
|
1888 |
maxfd = OPEN_MAX;
|
|
1889 |
}
|
|
1890 |
|
|
1891 |
if (!readfds && !writefds && !exceptfds && ((arraycount == 0) || (waitarray == NULL)) )
|
|
1892 |
{
|
|
1893 |
if (tvptr)
|
|
1894 |
{
|
|
1895 |
// select is being used as a better resolution timer
|
|
1896 |
User::After(timeout);
|
|
1897 |
anErrno = ETIMEDOUT;
|
|
1898 |
return 0;
|
|
1899 |
}
|
|
1900 |
// hang forever? - according to spec, until interuppted by signal
|
|
1901 |
TRequestStatus req = KRequestPending;
|
|
1902 |
User::WaitForRequest(req);
|
|
1903 |
}
|
|
1904 |
|
|
1905 |
fd_set retreadfds;
|
|
1906 |
fd_set retwritefds;
|
|
1907 |
fd_set retexceptfds;
|
|
1908 |
FD_ZERO(&retreadfds);
|
|
1909 |
FD_ZERO(&retwritefds);
|
|
1910 |
FD_ZERO(&retexceptfds);
|
|
1911 |
|
|
1912 |
// Intially perform synchronous non-blocking polls to see if any of the
|
|
1913 |
// input file descriptors are ready for read/write/error conditions.
|
|
1914 |
// In the meantime also determine, how many TRequestStatus objects we will
|
|
1915 |
// need for the next async run.
|
|
1916 |
CFileDescBase* fdesc = NULL;
|
|
1917 |
TInt nDescriptorsSet = 0;
|
|
1918 |
TInt numReqs = 0;
|
|
1919 |
TInt err = 0;
|
|
1920 |
|
|
1921 |
for (int i = 0; i < maxfd; ++i)
|
|
1922 |
{
|
|
1923 |
TUint events = 0;
|
|
1924 |
if (readfds && FD_ISSET(i, readfds))
|
|
1925 |
{
|
|
1926 |
events = EReadyForReading;
|
|
1927 |
}
|
|
1928 |
if (writefds && FD_ISSET(i, writefds))
|
|
1929 |
{
|
|
1930 |
events |= EReadyForWriting;
|
|
1931 |
}
|
|
1932 |
if (exceptfds && FD_ISSET(i, exceptfds))
|
|
1933 |
{
|
|
1934 |
events |= EAnyException;
|
|
1935 |
}
|
|
1936 |
if (!events)
|
|
1937 |
{
|
|
1938 |
continue;
|
|
1939 |
}
|
|
1940 |
if (iFids.At(i, fdesc) != KErrNone)
|
|
1941 |
{
|
|
1942 |
// Bad input file descriptor
|
|
1943 |
anErrno = EBADF;
|
|
1944 |
return -1;
|
|
1945 |
}
|
|
1946 |
// Poll on this descriptor
|
|
1947 |
err = fdesc->Poll(events);
|
|
1948 |
if (err < 0)
|
|
1949 |
{
|
|
1950 |
if(err == KErrNotSupported)
|
|
1951 |
{
|
|
1952 |
// continue if a write event is being set on the read end of pipe or vice-versa
|
|
1953 |
continue;
|
|
1954 |
}
|
|
1955 |
// An error - we should return
|
|
1956 |
return MapError(err, anErrno);
|
|
1957 |
}
|
|
1958 |
else
|
|
1959 |
{
|
|
1960 |
if (err & EReadyForReading)
|
|
1961 |
{
|
|
1962 |
FD_SET(i, &retreadfds);
|
|
1963 |
++nDescriptorsSet;
|
|
1964 |
}
|
|
1965 |
if (err & EReadyForWriting)
|
|
1966 |
{
|
|
1967 |
FD_SET(i, &retwritefds);
|
|
1968 |
++nDescriptorsSet;
|
|
1969 |
}
|
|
1970 |
if (err & EAnyException)
|
|
1971 |
{
|
|
1972 |
FD_SET(i, &retexceptfds);
|
|
1973 |
++nDescriptorsSet;
|
|
1974 |
}
|
|
1975 |
++numReqs;
|
|
1976 |
}
|
|
1977 |
}
|
|
1978 |
|
|
1979 |
if (nDescriptorsSet || (tvptr && timeout == 0))
|
|
1980 |
{
|
|
1981 |
// Some of the descriptors are ready for requested operations. Return.
|
|
1982 |
if (readfds)
|
|
1983 |
{
|
|
1984 |
FD_COPY(&retreadfds, readfds);
|
|
1985 |
}
|
|
1986 |
if (writefds)
|
|
1987 |
{
|
|
1988 |
FD_COPY(&retwritefds, writefds);
|
|
1989 |
}
|
|
1990 |
if (exceptfds)
|
|
1991 |
{
|
|
1992 |
FD_COPY(&retexceptfds, exceptfds);
|
|
1993 |
}
|
|
1994 |
return nDescriptorsSet;
|
|
1995 |
}
|
|
1996 |
|
|
1997 |
if (numReqs == 0 && ((arraycount == 0) || (waitarray == NULL)) )
|
|
1998 |
{
|
|
1999 |
if (tvptr)
|
|
2000 |
{
|
|
2001 |
User::After(timeout);
|
|
2002 |
anErrno = ETIMEDOUT;
|
|
2003 |
return 0;
|
|
2004 |
}
|
|
2005 |
// hang forever? - according to spec, until interuppted by signal
|
|
2006 |
TRequestStatus req = KRequestPending;
|
|
2007 |
User::WaitForRequest(req);
|
|
2008 |
}
|
|
2009 |
|
|
2010 |
// Now prepare to issue the asynchronous requests.
|
|
2011 |
TRequestStatus** reqarray;
|
|
2012 |
TRequestStatus* reqobjarray;
|
|
2013 |
|
|
2014 |
// Create the array of TRequestStatus objects
|
|
2015 |
reqobjarray = (TRequestStatus *) Alloc((numReqs + (timeout ? 1 : 0)) * sizeof(TRequestStatus));
|
|
2016 |
if (!reqobjarray)
|
|
2017 |
{
|
|
2018 |
anErrno = ENOMEM;
|
|
2019 |
return -1;
|
|
2020 |
}
|
|
2021 |
|
|
2022 |
reqarray = (TRequestStatus **) Alloc((numReqs+arraycount + (timeout ? 1 : 0)) * sizeof(TRequestStatus*));
|
|
2023 |
if (!reqarray)
|
|
2024 |
{
|
|
2025 |
Free(reqobjarray);
|
|
2026 |
anErrno = ENOMEM;
|
|
2027 |
return -1;
|
|
2028 |
}
|
|
2029 |
|
|
2030 |
// Append all the created TRequestStatus objects to the array
|
|
2031 |
for (int i = 0; i<numReqs; i++)
|
|
2032 |
{
|
|
2033 |
reqarray[i] = &reqobjarray[i];
|
|
2034 |
}
|
|
2035 |
|
|
2036 |
// Append the array of TRequestStatus passed in waitarray to the array
|
|
2037 |
for (int i = numReqs, j=0; i<numReqs+arraycount; i++, j++)
|
|
2038 |
{
|
|
2039 |
reqarray[i] = &waitarray[j];
|
|
2040 |
}
|
|
2041 |
|
|
2042 |
if (timeout)
|
|
2043 |
{
|
|
2044 |
// Append the TRequestStatus used for timer to the array
|
|
2045 |
reqarray[numReqs+arraycount] = &reqobjarray[numReqs];
|
|
2046 |
}
|
|
2047 |
|
|
2048 |
TInt *reqfds = (TInt *)Alloc(numReqs * sizeof(TInt));
|
|
2049 |
if (!reqfds)
|
|
2050 |
{
|
|
2051 |
Free(reqarray);
|
|
2052 |
Free(reqobjarray);
|
|
2053 |
anErrno = ENOMEM;
|
|
2054 |
return -1;
|
|
2055 |
}
|
|
2056 |
|
|
2057 |
// Reset numReqs. We will use it to keep track of how many objects in the
|
|
2058 |
// reqarray are valid requests.
|
|
2059 |
numReqs = 0;
|
|
2060 |
|
|
2061 |
// Used to detect one request gathered when this code reaches WaitForNReqs
|
|
2062 |
TBool onedown = EFalse;
|
|
2063 |
|
|
2064 |
// define the RTimer here to work-around a GCC warning
|
|
2065 |
RTimer timer;
|
|
2066 |
if (timeout)
|
|
2067 |
{
|
|
2068 |
// Create the timer to handle the timeout
|
|
2069 |
err = timer.CreateLocal();
|
|
2070 |
if (err != KErrNone)
|
|
2071 |
{
|
|
2072 |
Free(reqarray);
|
|
2073 |
Free(reqobjarray);
|
|
2074 |
Free(reqfds);
|
|
2075 |
return MapError(err, anErrno);
|
|
2076 |
}
|
|
2077 |
}
|
|
2078 |
|
|
2079 |
// Start processing requested-for events
|
|
2080 |
for (int i = 0; i < maxfd; ++i)
|
|
2081 |
{
|
|
2082 |
TUint events = 0;
|
|
2083 |
|
|
2084 |
if (readfds && FD_ISSET(i, readfds))
|
|
2085 |
{
|
|
2086 |
events = EReadyForReading;
|
|
2087 |
}
|
|
2088 |
|
|
2089 |
if (writefds && FD_ISSET(i, writefds))
|
|
2090 |
{
|
|
2091 |
events |= EReadyForWriting;
|
|
2092 |
}
|
|
2093 |
|
|
2094 |
if (exceptfds && FD_ISSET(i, exceptfds))
|
|
2095 |
{
|
|
2096 |
events |= EAnyException;
|
|
2097 |
}
|
|
2098 |
|
|
2099 |
if (!events)
|
|
2100 |
{
|
|
2101 |
continue;
|
|
2102 |
}
|
|
2103 |
|
|
2104 |
if (iFids.At(i, fdesc) == KErrNone)
|
|
2105 |
{
|
|
2106 |
fdesc->TweakWatchedEvents(events);
|
|
2107 |
err = fdesc->NotifyActivity(events, *reqarray[numReqs], timeout);
|
|
2108 |
if (err == KErrCompletion)
|
|
2109 |
{
|
|
2110 |
// No async call was issued. Try a Poll
|
|
2111 |
TInt ready = fdesc->Poll(events);
|
|
2112 |
if (ready & EReadyForReading)
|
|
2113 |
{
|
|
2114 |
FD_SET(i, &retreadfds);
|
|
2115 |
++nDescriptorsSet;
|
|
2116 |
}
|
|
2117 |
if (ready & EReadyForWriting)
|
|
2118 |
{
|
|
2119 |
FD_SET(i, &retwritefds);
|
|
2120 |
++nDescriptorsSet;
|
|
2121 |
}
|
|
2122 |
if (ready & EAnyException)
|
|
2123 |
{
|
|
2124 |
FD_SET(i, &retexceptfds);
|
|
2125 |
++nDescriptorsSet;
|
|
2126 |
}
|
|
2127 |
break;
|
|
2128 |
}
|
|
2129 |
else if (err != KErrNone)
|
|
2130 |
{
|
|
2131 |
// Notification registration failed. Cleanup and return.
|
|
2132 |
nDescriptorsSet = MapError(err, anErrno);
|
|
2133 |
break;
|
|
2134 |
}
|
|
2135 |
else
|
|
2136 |
{
|
|
2137 |
// Issued an asynchronus request. Increment valid requests count.
|
|
2138 |
reqfds[numReqs++] = i;
|
|
2139 |
}
|
|
2140 |
}
|
|
2141 |
}
|
|
2142 |
|
|
2143 |
if (err != KErrNone)
|
|
2144 |
{
|
|
2145 |
if (timeout)
|
|
2146 |
{
|
|
2147 |
timer.Close();
|
|
2148 |
}
|
|
2149 |
for(TInt i= 0; i < numReqs; i++)
|
|
2150 |
{
|
|
2151 |
if (iFids.At(reqfds[i], fdesc) != KErrNone)
|
|
2152 |
{
|
|
2153 |
continue;
|
|
2154 |
}
|
|
2155 |
fdesc->CancelNotify();
|
|
2156 |
}
|
|
2157 |
goto bailout;
|
|
2158 |
}
|
|
2159 |
|
|
2160 |
if (timeout)
|
|
2161 |
{
|
|
2162 |
timer.After(*reqarray[numReqs+arraycount], timeout);
|
|
2163 |
// Wait for any request to complete
|
|
2164 |
CLocalSystemInterface::WaitForNRequest(*reqarray, numReqs+arraycount+1);
|
|
2165 |
if( (*reqarray[numReqs+arraycount]).Int() == KRequestPending)
|
|
2166 |
{
|
|
2167 |
// The timer hasn't fired yet.
|
|
2168 |
timer.Cancel();
|
|
2169 |
}
|
|
2170 |
else
|
|
2171 |
{
|
|
2172 |
anErrno = ETIMEDOUT;
|
|
2173 |
}
|
|
2174 |
timer.Close();
|
|
2175 |
// No need to set onedown to True as numReqs does not include the Timer request
|
|
2176 |
}
|
|
2177 |
else
|
|
2178 |
{
|
|
2179 |
CLocalSystemInterface::WaitForNRequest(*reqarray, numReqs+arraycount);
|
|
2180 |
// Completion Status of one request has been gathered
|
|
2181 |
onedown = ETrue;
|
|
2182 |
}
|
|
2183 |
|
|
2184 |
for (int i = 0; i < numReqs; ++i)
|
|
2185 |
{
|
|
2186 |
if (iFids.At(reqfds[i], fdesc) != KErrNone)
|
|
2187 |
{
|
|
2188 |
continue;
|
|
2189 |
}
|
|
2190 |
|
|
2191 |
if ( (*reqarray[i]).Int() != KRequestPending )
|
|
2192 |
{
|
|
2193 |
TInt readyevents = fdesc->TweakReadyEvents((*reqarray[i]).Int());
|
|
2194 |
if (readfds && FD_ISSET(reqfds[i], readfds) && (readyevents & EReadyForReading) )
|
|
2195 |
{
|
|
2196 |
FD_SET(reqfds[i], &retreadfds);
|
|
2197 |
++nDescriptorsSet;
|
|
2198 |
}
|
|
2199 |
if(writefds && FD_ISSET(reqfds[i], writefds) && (readyevents & EReadyForWriting) )
|
|
2200 |
{
|
|
2201 |
FD_SET(reqfds[i], &retwritefds);
|
|
2202 |
++nDescriptorsSet;
|
|
2203 |
}
|
|
2204 |
if(exceptfds && FD_ISSET(reqfds[i], exceptfds) && (readyevents & EAnyException))
|
|
2205 |
{
|
|
2206 |
FD_SET(reqfds[i], &retexceptfds);
|
|
2207 |
++nDescriptorsSet;
|
|
2208 |
}
|
|
2209 |
}
|
|
2210 |
else
|
|
2211 |
{
|
|
2212 |
//Cancel all other requests.
|
|
2213 |
fdesc->CancelNotify();
|
|
2214 |
}
|
|
2215 |
}
|
|
2216 |
|
|
2217 |
if (readfds)
|
|
2218 |
{
|
|
2219 |
FD_COPY(&retreadfds, readfds);
|
|
2220 |
}
|
|
2221 |
|
|
2222 |
if (writefds)
|
|
2223 |
{
|
|
2224 |
FD_COPY(&retwritefds, writefds);
|
|
2225 |
}
|
|
2226 |
|
|
2227 |
if (exceptfds)
|
|
2228 |
{
|
|
2229 |
FD_COPY(&retexceptfds, exceptfds);
|
|
2230 |
}
|
|
2231 |
|
|
2232 |
bailout:
|
|
2233 |
|
|
2234 |
if (onedown && numReqs)
|
|
2235 |
{
|
|
2236 |
--numReqs;
|
|
2237 |
}
|
|
2238 |
// consume all completed/cancelled requests
|
|
2239 |
while(numReqs--)
|
|
2240 |
{
|
|
2241 |
User::WaitForAnyRequest();
|
|
2242 |
}
|
|
2243 |
|
|
2244 |
Free(reqarray);
|
|
2245 |
Free(reqobjarray);
|
|
2246 |
Free(reqfds);
|
|
2247 |
return nDescriptorsSet;
|
|
2248 |
}
|
|
2249 |
|
|
2250 |
|
|
2251 |
|
|
2252 |
// -----------------------------------------------------------------------------
|
|
2253 |
// CLocalSystemInterface::system
|
|
2254 |
// -----------------------------------------------------------------------------
|
|
2255 |
//
|
|
2256 |
int CLocalSystemInterface::system(const wchar_t* aCmd, const wchar_t* aCmdArg, int& anErrno)
|
|
2257 |
{
|
|
2258 |
return iFids.system(aCmd, aCmdArg, anErrno);
|
|
2259 |
}
|
|
2260 |
|
|
2261 |
// -----------------------------------------------------------------------------
|
|
2262 |
// CLocalSystemInterface::posix_spawn
|
|
2263 |
// -----------------------------------------------------------------------------
|
|
2264 |
//
|
|
2265 |
int CLocalSystemInterface::posix_spawn(int* pid, const wchar_t* wpath,
|
|
2266 |
const posix_spawn_file_actions_t* file_actions,
|
|
2267 |
const posix_spawnattr_t* attrp,
|
|
2268 |
const wchar_t* wargs,
|
|
2269 |
wchar_t** wenvp)
|
|
2270 |
{
|
|
2271 |
return iFids.posix_spawn(pid, wpath, file_actions, attrp, wargs, wenvp);
|
|
2272 |
}
|
|
2273 |
|
|
2274 |
#ifdef SYMBIAN_OE_POSIX_SIGNALS
|
|
2275 |
// -----------------------------------------------------------------------------
|
|
2276 |
// CLocalSystemInterface::kill
|
|
2277 |
// -----------------------------------------------------------------------------
|
|
2278 |
//
|
|
2279 |
int CLocalSystemInterface::kill(pid_t pid, int sig , int& anErrno)
|
|
2280 |
{
|
|
2281 |
EnsureSignalsInitialized();
|
|
2282 |
|
|
2283 |
if(!iSignalsInitialized)
|
|
2284 |
{
|
|
2285 |
anErrno = ENOTSUP;
|
|
2286 |
return -1;
|
|
2287 |
}
|
|
2288 |
|
|
2289 |
TInt err = KErrArgument;
|
|
2290 |
TProcessId lPid(pid);
|
|
2291 |
RProcess lTargetProcess;
|
|
2292 |
|
|
2293 |
if(pid <= 0)
|
|
2294 |
{
|
|
2295 |
anErrno = ENOTSUP;
|
|
2296 |
return -1;
|
|
2297 |
}
|
|
2298 |
|
|
2299 |
if(lTargetProcess.Open(lPid) != KErrNone)
|
|
2300 |
{
|
|
2301 |
anErrno = ESRCH;
|
|
2302 |
return -1;
|
|
2303 |
}
|
|
2304 |
else
|
|
2305 |
{
|
|
2306 |
lTargetProcess.Close();
|
|
2307 |
}
|
|
2308 |
|
|
2309 |
if(sig == 0)
|
|
2310 |
{
|
|
2311 |
return MapError(KErrNone, anErrno);
|
|
2312 |
}
|
|
2313 |
|
|
2314 |
if(sig < 1 || sig > SIGRTMAX)
|
|
2315 |
{
|
|
2316 |
return MapError(err, anErrno); // check for linux return value. standard says != 0
|
|
2317 |
}
|
|
2318 |
|
|
2319 |
err = iSignalSession.SendSignal(pid,sig);
|
|
2320 |
return MapError(err, anErrno);
|
|
2321 |
}
|
|
2322 |
|
|
2323 |
// -----------------------------------------------------------------------------
|
|
2324 |
// CLocalSystemInterface::raise
|
|
2325 |
// -----------------------------------------------------------------------------
|
|
2326 |
//
|
|
2327 |
int CLocalSystemInterface::raise(int sig , int& anErrno)
|
|
2328 |
{
|
|
2329 |
EnsureSignalsInitialized();
|
|
2330 |
|
|
2331 |
if(!iSignalsInitialized)
|
|
2332 |
{
|
|
2333 |
anErrno = ENOTSUP;
|
|
2334 |
return -1;
|
|
2335 |
}
|
|
2336 |
|
|
2337 |
TInt err = KErrArgument;
|
|
2338 |
if(sig < 1 || sig > SIGRTMAX)
|
|
2339 |
{
|
|
2340 |
return MapError(err, anErrno); // check for linux return value. standard says != 0
|
|
2341 |
}
|
|
2342 |
// mutex protect
|
|
2343 |
TSignalMessage lMsg;
|
|
2344 |
lMsg.mType = TSignalMessage::ESignal;
|
|
2345 |
lMsg.mSignal = (TUint8)sig;
|
|
2346 |
TBuf8<KSigMsgLength> lMsgBuf;
|
|
2347 |
lMsg.Marshall(lMsgBuf);
|
|
2348 |
|
|
2349 |
err = iSignalWritePipe.Write(lMsgBuf,KSigMsgLength);
|
|
2350 |
if(err >= 0)
|
|
2351 |
return MapError(KErrNone,anErrno);
|
|
2352 |
else
|
|
2353 |
return MapError(err, anErrno);
|
|
2354 |
}
|
|
2355 |
|
|
2356 |
// -----------------------------------------------------------------------------
|
|
2357 |
// CLocalSystemInterface::sigqueue
|
|
2358 |
// -----------------------------------------------------------------------------
|
|
2359 |
//
|
|
2360 |
int CLocalSystemInterface::sigqueue(pid_t pid, int sig, const union sigval val, int& anErrno)
|
|
2361 |
{
|
|
2362 |
EnsureSignalsInitialized();
|
|
2363 |
|
|
2364 |
if(!iSignalsInitialized)
|
|
2365 |
{
|
|
2366 |
anErrno = ENOTSUP;
|
|
2367 |
return -1;
|
|
2368 |
}
|
|
2369 |
|
|
2370 |
TInt err = KErrArgument;
|
|
2371 |
|
|
2372 |
TProcessId lPid(pid);
|
|
2373 |
RProcess lTargetProcess;
|
|
2374 |
if(lTargetProcess.Open(lPid) != KErrNone)
|
|
2375 |
{
|
|
2376 |
anErrno = ESRCH;
|
|
2377 |
return -1;
|
|
2378 |
}
|
|
2379 |
else
|
|
2380 |
{
|
|
2381 |
lTargetProcess.Close();
|
|
2382 |
}
|
|
2383 |
|
|
2384 |
if(sig == 0)
|
|
2385 |
{
|
|
2386 |
return MapError(KErrNone, anErrno);
|
|
2387 |
}
|
|
2388 |
|
|
2389 |
if(sig < 1 || sig > SIGRTMAX)
|
|
2390 |
{
|
|
2391 |
return MapError(err, anErrno); // check for linux return value. standard says != 0
|
|
2392 |
}
|
|
2393 |
|
|
2394 |
err = iSignalSession.SendSignalValue(pid,sig,val.sival_int);
|
|
2395 |
return MapError(KErrNone, anErrno);
|
|
2396 |
}
|
|
2397 |
|
|
2398 |
// -----------------------------------------------------------------------------
|
|
2399 |
// CLocalSystemInterface::sigfillset
|
|
2400 |
// -----------------------------------------------------------------------------
|
|
2401 |
//
|
|
2402 |
int CLocalSystemInterface::sigfillset(sigset_t *set, int& anErrno)
|
|
2403 |
{
|
|
2404 |
if(!iSignalsInitialized)
|
|
2405 |
{
|
|
2406 |
anErrno = ENOTSUP;
|
|
2407 |
return -1;
|
|
2408 |
}
|
|
2409 |
|
|
2410 |
if(set == 0)
|
|
2411 |
return MapError(KErrArgument, anErrno);
|
|
2412 |
|
|
2413 |
SIG_FILL_SIGSET(*set);
|
|
2414 |
|
|
2415 |
return MapError(KErrNone, anErrno);
|
|
2416 |
}
|
|
2417 |
|
|
2418 |
|
|
2419 |
// -----------------------------------------------------------------------------
|
|
2420 |
// CLocalSystemInterface::sigaddset
|
|
2421 |
// -----------------------------------------------------------------------------
|
|
2422 |
//
|
|
2423 |
int CLocalSystemInterface::sigaddset(sigset_t *set, int signo, int& anErrno)
|
|
2424 |
{
|
|
2425 |
if(!iSignalsInitialized)
|
|
2426 |
{
|
|
2427 |
anErrno = ENOTSUP;
|
|
2428 |
return -1;
|
|
2429 |
}
|
|
2430 |
|
|
2431 |
if(signo < 1 || signo > SIGRTMAX || set == 0)
|
|
2432 |
return MapError(KErrArgument, anErrno);
|
|
2433 |
|
|
2434 |
SIG_ADD_SIGNAL_TO_SET(signo,*set);
|
|
2435 |
|
|
2436 |
return MapError(KErrNone, anErrno);
|
|
2437 |
}
|
|
2438 |
|
|
2439 |
// -----------------------------------------------------------------------------
|
|
2440 |
// CLocalSystemInterface::sigdelset
|
|
2441 |
// -----------------------------------------------------------------------------
|
|
2442 |
//
|
|
2443 |
int CLocalSystemInterface::sigdelset(sigset_t *set, int signo, int& anErrno)
|
|
2444 |
{
|
|
2445 |
if(!iSignalsInitialized)
|
|
2446 |
{
|
|
2447 |
anErrno = ENOTSUP;
|
|
2448 |
return -1;
|
|
2449 |
}
|
|
2450 |
|
|
2451 |
if(signo < 1 || signo > SIGRTMAX || set == 0)
|
|
2452 |
return MapError(KErrArgument, anErrno);
|
|
2453 |
|
|
2454 |
SIG_REMOVE_SIGNAL_FROM_SET(signo,*set);
|
|
2455 |
|
|
2456 |
return MapError(KErrNone, anErrno);
|
|
2457 |
}
|
|
2458 |
|
|
2459 |
// -----------------------------------------------------------------------------
|
|
2460 |
// CLocalSystemInterface::sigismember
|
|
2461 |
// -----------------------------------------------------------------------------
|
|
2462 |
//
|
|
2463 |
int CLocalSystemInterface::sigismember(const sigset_t *set, int signo, int& anErrno)
|
|
2464 |
{
|
|
2465 |
if(!iSignalsInitialized)
|
|
2466 |
{
|
|
2467 |
anErrno = ENOTSUP;
|
|
2468 |
return -1;
|
|
2469 |
}
|
|
2470 |
|
|
2471 |
if(signo < 1 || signo > SIGRTMAX || set == 0)
|
|
2472 |
return MapError(KErrArgument, anErrno);
|
|
2473 |
|
|
2474 |
if(SIG_SIGNAL_PRESENT_IN_SIGSET(signo,*set))
|
|
2475 |
return 1;
|
|
2476 |
else
|
|
2477 |
return 0;
|
|
2478 |
}
|
|
2479 |
|
|
2480 |
// -----------------------------------------------------------------------------
|
|
2481 |
// CLocalSystemInterface::sigandset
|
|
2482 |
// -----------------------------------------------------------------------------
|
|
2483 |
//
|
|
2484 |
int CLocalSystemInterface::sigandset(sigset_t * set, const sigset_t * left, const sigset_t * right, int& anErrno)
|
|
2485 |
{
|
|
2486 |
if(!iSignalsInitialized)
|
|
2487 |
{
|
|
2488 |
anErrno = ENOTSUP;
|
|
2489 |
return -1;
|
|
2490 |
}
|
|
2491 |
|
|
2492 |
if(set == 0 || left == 0 || right == 0)
|
|
2493 |
return MapError(KErrArgument, anErrno);
|
|
2494 |
|
|
2495 |
*set = *left & *right;
|
|
2496 |
|
|
2497 |
return MapError(KErrNone, anErrno);
|
|
2498 |
}
|
|
2499 |
|
|
2500 |
// -----------------------------------------------------------------------------
|
|
2501 |
// CLocalSystemInterface::sigorset
|
|
2502 |
// -----------------------------------------------------------------------------
|
|
2503 |
//
|
|
2504 |
int CLocalSystemInterface::sigorset(sigset_t * set, const sigset_t * left, const sigset_t * right, int& anErrno)
|
|
2505 |
{
|
|
2506 |
if(!iSignalsInitialized)
|
|
2507 |
{
|
|
2508 |
anErrno = ENOTSUP;
|
|
2509 |
return -1;
|
|
2510 |
}
|
|
2511 |
|
|
2512 |
if(set == 0 || left == 0 || right == 0)
|
|
2513 |
return MapError(KErrArgument, anErrno);
|
|
2514 |
|
|
2515 |
*set = *left | *right;
|
|
2516 |
|
|
2517 |
return MapError(KErrNone, anErrno);
|
|
2518 |
}
|
|
2519 |
|
|
2520 |
// -----------------------------------------------------------------------------
|
|
2521 |
// CLocalSystemInterface::sigisemptyset
|
|
2522 |
// -----------------------------------------------------------------------------
|
|
2523 |
//
|
|
2524 |
int CLocalSystemInterface::sigisemptyset(const sigset_t * set, int& anErrno)
|
|
2525 |
{
|
|
2526 |
if(!iSignalsInitialized)
|
|
2527 |
{
|
|
2528 |
anErrno = ENOTSUP;
|
|
2529 |
return -1;
|
|
2530 |
}
|
|
2531 |
|
|
2532 |
if(set == 0)
|
|
2533 |
return MapError(KErrArgument, anErrno);
|
|
2534 |
|
|
2535 |
anErrno = 0;
|
|
2536 |
if(SIG_ISEMPTY_SIGSET(*set))
|
|
2537 |
return 1;
|
|
2538 |
else
|
|
2539 |
return 0;
|
|
2540 |
}
|
|
2541 |
|
|
2542 |
// -----------------------------------------------------------------------------
|
|
2543 |
// CLocalSystemInterface::sigemptyset
|
|
2544 |
// -----------------------------------------------------------------------------
|
|
2545 |
//
|
|
2546 |
int CLocalSystemInterface::sigemptyset(sigset_t * set, int& anErrno)
|
|
2547 |
{
|
|
2548 |
if(!iSignalsInitialized)
|
|
2549 |
{
|
|
2550 |
anErrno = ENOTSUP;
|
|
2551 |
return -1;
|
|
2552 |
}
|
|
2553 |
|
|
2554 |
if(set == 0)
|
|
2555 |
return MapError(KErrArgument, anErrno);
|
|
2556 |
|
|
2557 |
SIG_EMPTY_SIGSET(*set);
|
|
2558 |
return MapError(KErrNone, anErrno);
|
|
2559 |
}
|
|
2560 |
|
|
2561 |
// -----------------------------------------------------------------------------
|
|
2562 |
// CLocalSystemInterface::sigprocmask
|
|
2563 |
// -----------------------------------------------------------------------------
|
|
2564 |
//
|
|
2565 |
int CLocalSystemInterface::sigprocmask(int how, const sigset_t *set, sigset_t *oset, int& anErrno)
|
|
2566 |
{
|
|
2567 |
if(!iSignalsInitialized)
|
|
2568 |
{
|
|
2569 |
anErrno = ENOTSUP;
|
|
2570 |
return -1;
|
|
2571 |
}
|
|
2572 |
|
|
2573 |
EnsureSignalsInitialized();
|
|
2574 |
|
|
2575 |
TUint64 lOldMask = iSigMask;
|
|
2576 |
TBool lIsUnblocked = EFalse;
|
|
2577 |
|
|
2578 |
if(oset)
|
|
2579 |
{
|
|
2580 |
*oset = (sigset_t)iSigMask;
|
|
2581 |
}
|
|
2582 |
|
|
2583 |
if(set)
|
|
2584 |
{
|
|
2585 |
switch(how)
|
|
2586 |
{
|
|
2587 |
case SIG_BLOCK:
|
|
2588 |
iSigMask |= (TUint64)*set;
|
|
2589 |
break;
|
|
2590 |
case SIG_SETMASK:
|
|
2591 |
iSigMask = (TUint64)*set;
|
|
2592 |
lIsUnblocked = ETrue;
|
|
2593 |
break;
|
|
2594 |
case SIG_UNBLOCK:
|
|
2595 |
iSigMask &= ~(TUint64)*set;
|
|
2596 |
lIsUnblocked = ETrue;
|
|
2597 |
break;
|
|
2598 |
default:
|
|
2599 |
return MapError(KErrArgument, anErrno);
|
|
2600 |
}
|
|
2601 |
}
|
|
2602 |
|
|
2603 |
// unsetting the bits of signals that cannot be blocked
|
|
2604 |
// no error is to be thrown in this case
|
|
2605 |
SIG_REMOVE_SIGNAL_FROM_SET(SIGKILL,iSigMask);
|
|
2606 |
SIG_REMOVE_SIGNAL_FROM_SET(SIGSTOP,iSigMask);
|
|
2607 |
|
|
2608 |
if(lIsUnblocked)
|
|
2609 |
{
|
|
2610 |
TUint64 lDiffSet = (lOldMask & (~iSigMask));
|
|
2611 |
if(lDiffSet != 0)
|
|
2612 |
{
|
|
2613 |
TInt lIdx = 0;
|
|
2614 |
for(lIdx = 1;lIdx <= SIGRTMAX;lIdx++)
|
|
2615 |
{
|
|
2616 |
if(SIG_SIGNAL_PRESENT_IN_SIGSET(lIdx,lDiffSet))
|
|
2617 |
{
|
|
2618 |
TSignalMessage lMsg;
|
|
2619 |
lMsg.mType = TSignalMessage::EDequeueSignal;
|
|
2620 |
lMsg.mSignal = (TUint8)lIdx;
|
|
2621 |
TBuf8<KSigMsgLength> lMsgBuf;
|
|
2622 |
lMsg.Marshall(lMsgBuf);
|
|
2623 |
iSignalWritePipe.Write(lMsgBuf,KSigMsgLength);
|
|
2624 |
|
|
2625 |
}
|
|
2626 |
}
|
|
2627 |
// scan and dequeue
|
|
2628 |
}
|
|
2629 |
}
|
|
2630 |
|
|
2631 |
return MapError(KErrNone, anErrno);
|
|
2632 |
}
|
|
2633 |
|
|
2634 |
// -----------------------------------------------------------------------------
|
|
2635 |
// CLocalSystemInterface::sighold
|
|
2636 |
// -----------------------------------------------------------------------------
|
|
2637 |
//
|
|
2638 |
int CLocalSystemInterface::sighold(int signo, int& anErrno)
|
|
2639 |
{
|
|
2640 |
if(!iSignalsInitialized)
|
|
2641 |
{
|
|
2642 |
anErrno = ENOTSUP;
|
|
2643 |
return -1;
|
|
2644 |
}
|
|
2645 |
|
|
2646 |
EnsureSignalsInitialized();
|
|
2647 |
|
|
2648 |
if(signo < 1 || signo > SIGRTMAX)
|
|
2649 |
return MapError(KErrArgument, anErrno);
|
|
2650 |
|
|
2651 |
SIG_ADD_SIGNAL_TO_SET(signo,iSigMask);
|
|
2652 |
SIG_REMOVE_SIGNAL_FROM_SET(SIGKILL,iSigMask);
|
|
2653 |
SIG_REMOVE_SIGNAL_FROM_SET(SIGSTOP,iSigMask);
|
|
2654 |
|
|
2655 |
return MapError(KErrNone, anErrno);
|
|
2656 |
}
|
|
2657 |
|
|
2658 |
// -----------------------------------------------------------------------------
|
|
2659 |
// CLocalSystemInterface::sigrelse
|
|
2660 |
// -----------------------------------------------------------------------------
|
|
2661 |
//
|
|
2662 |
int CLocalSystemInterface::sigrelse(int signo, int& anErrno)
|
|
2663 |
{
|
|
2664 |
if(!iSignalsInitialized)
|
|
2665 |
{
|
|
2666 |
anErrno = ENOTSUP;
|
|
2667 |
return -1;
|
|
2668 |
}
|
|
2669 |
|
|
2670 |
EnsureSignalsInitialized();
|
|
2671 |
TUint64 lPrevMask = iSigMask;
|
|
2672 |
|
|
2673 |
if(signo < 1 || signo > SIGRTMAX)
|
|
2674 |
return MapError(KErrArgument, anErrno);
|
|
2675 |
|
|
2676 |
SIG_REMOVE_SIGNAL_FROM_SET(signo,iSigMask);
|
|
2677 |
|
|
2678 |
if(lPrevMask != iSigMask)
|
|
2679 |
{
|
|
2680 |
TSignalMessage lMsg;
|
|
2681 |
lMsg.mType = TSignalMessage::EDequeueSignal;
|
|
2682 |
lMsg.mSignal = (TUint8)signo;
|
|
2683 |
TBuf8<KSigMsgLength> lMsgBuf;
|
|
2684 |
lMsg.Marshall(lMsgBuf);
|
|
2685 |
iSignalWritePipe.Write(lMsgBuf,KSigMsgLength);
|
|
2686 |
}
|
|
2687 |
|
|
2688 |
return MapError(KErrNone, anErrno);
|
|
2689 |
}
|
|
2690 |
|
|
2691 |
// -----------------------------------------------------------------------------
|
|
2692 |
// CLocalSystemInterface::sigpause
|
|
2693 |
// -----------------------------------------------------------------------------
|
|
2694 |
//
|
|
2695 |
int CLocalSystemInterface::sigpause(int signo, int& anErrno)
|
|
2696 |
{
|
|
2697 |
if(!iSignalsInitialized)
|
|
2698 |
{
|
|
2699 |
anErrno = ENOTSUP;
|
|
2700 |
return -1;
|
|
2701 |
}
|
|
2702 |
|
|
2703 |
EnsureSignalsInitialized();
|
|
2704 |
|
|
2705 |
TUint64 lPrevMask = iSigMask;
|
|
2706 |
TUint64 lWaitSet = 0;
|
|
2707 |
TSignalMessage lMsg;
|
|
2708 |
|
|
2709 |
if(signo < 1 || signo > SIGRTMAX)
|
|
2710 |
return MapError(KErrArgument, anErrno);
|
|
2711 |
|
|
2712 |
SIG_REMOVE_SIGNAL_FROM_SET(signo,iSigMask);
|
|
2713 |
SIG_ADD_SIGNAL_TO_SET(signo,lWaitSet);
|
|
2714 |
|
|
2715 |
SigWaitInternal(lWaitSet,&lMsg,0);
|
|
2716 |
|
|
2717 |
iSigMask = lPrevMask;
|
|
2718 |
|
|
2719 |
HandleSignal(lMsg,ETrue);
|
|
2720 |
|
|
2721 |
anErrno = EINTR;
|
|
2722 |
return -1;
|
|
2723 |
}
|
|
2724 |
|
|
2725 |
// -----------------------------------------------------------------------------
|
|
2726 |
// CLocalSystemInterface::sigwait
|
|
2727 |
// -----------------------------------------------------------------------------
|
|
2728 |
//
|
|
2729 |
int CLocalSystemInterface::sigwait(const sigset_t *set, int *sig, int& anErrno)
|
|
2730 |
{
|
|
2731 |
if(!iSignalsInitialized)
|
|
2732 |
{
|
|
2733 |
return ENOTSUP;
|
|
2734 |
}
|
|
2735 |
|
|
2736 |
EnsureSignalsInitialized();
|
|
2737 |
|
|
2738 |
anErrno = anErrno; // to supress unused arg warning. sigwait doesn't set errno, it returns it.
|
|
2739 |
|
|
2740 |
if(set == 0)
|
|
2741 |
return EINVAL;
|
|
2742 |
|
|
2743 |
if(SIG_ISEMPTY_SIGSET(*set))
|
|
2744 |
return EINVAL;
|
|
2745 |
|
|
2746 |
TUint64 lTemp = *set;
|
|
2747 |
SIG_REMOVE_SIGNAL_FROM_SET(SIGKILL,lTemp);
|
|
2748 |
SIG_REMOVE_SIGNAL_FROM_SET(SIGSTOP,lTemp);
|
|
2749 |
if(lTemp == 0 && !SIG_ISEMPTY_SIGSET(set))
|
|
2750 |
return 0;
|
|
2751 |
|
|
2752 |
TInt lRetVal = KErrNone;
|
|
2753 |
TSignalMessage lMsg;
|
|
2754 |
lRetVal = SigWaitInternal((TUint64)*set,&lMsg,0);
|
|
2755 |
if(lRetVal == KErrNone)
|
|
2756 |
{
|
|
2757 |
if(lMsg.mType == TSignalMessage::ESignal)
|
|
2758 |
{
|
|
2759 |
if(sig)
|
|
2760 |
*sig = lMsg.mSignal;
|
|
2761 |
}
|
|
2762 |
else if(lMsg.mType == TSignalMessage::ESignalValuePair)
|
|
2763 |
{
|
|
2764 |
if(sig)
|
|
2765 |
*sig = lMsg.mSigVal.mSignal;
|
|
2766 |
}
|
|
2767 |
else if(lMsg.mType == TSignalMessage::ERtTimerSignal)
|
|
2768 |
{
|
|
2769 |
if(sig)
|
|
2770 |
*sig = lMsg.mRtSignal.mSignal;
|
|
2771 |
}
|
|
2772 |
}
|
|
2773 |
else
|
|
2774 |
{
|
|
2775 |
return EINVAL;
|
|
2776 |
}
|
|
2777 |
return 0;
|
|
2778 |
}
|
|
2779 |
|
|
2780 |
// -----------------------------------------------------------------------------
|
|
2781 |
// CLocalSystemInterface::sigtimedwait
|
|
2782 |
// -----------------------------------------------------------------------------
|
|
2783 |
//
|
|
2784 |
int CLocalSystemInterface::sigtimedwait(const sigset_t *set,
|
|
2785 |
siginfo_t *info, const struct timespec *timeout, int& anErrno)
|
|
2786 |
{
|
|
2787 |
if(!iSignalsInitialized)
|
|
2788 |
{
|
|
2789 |
anErrno = ENOTSUP;
|
|
2790 |
return -1;
|
|
2791 |
}
|
|
2792 |
|
|
2793 |
TBool lTimeCheckFailed = EFalse;
|
|
2794 |
|
|
2795 |
EnsureSignalsInitialized();
|
|
2796 |
|
|
2797 |
if(set == 0 || timeout == 0)
|
|
2798 |
{
|
|
2799 |
anErrno = EINVAL;
|
|
2800 |
return -1;
|
|
2801 |
}
|
|
2802 |
|
|
2803 |
if(SIG_ISEMPTY_SIGSET(*set))
|
|
2804 |
{
|
|
2805 |
anErrno = EINVAL;
|
|
2806 |
return -1;
|
|
2807 |
}
|
|
2808 |
|
|
2809 |
if(timeout->tv_sec == 0 && timeout->tv_nsec == 0)
|
|
2810 |
{
|
|
2811 |
anErrno = EINVAL;
|
|
2812 |
return -1;
|
|
2813 |
}
|
|
2814 |
|
|
2815 |
if( (timeout->tv_sec*1000*1000 > 0x7FFFFFFF) || // 0x7FFFFFFF (maximum positive value of int32)
|
|
2816 |
(timeout->tv_sec < 0) ||
|
|
2817 |
(timeout->tv_nsec >= 1000000000) ||
|
|
2818 |
(timeout->tv_nsec < 0) )
|
|
2819 |
{
|
|
2820 |
lTimeCheckFailed = ETrue;
|
|
2821 |
}
|
|
2822 |
|
|
2823 |
TUint64 lTemp = *set;
|
|
2824 |
SIG_REMOVE_SIGNAL_FROM_SET(SIGKILL,lTemp);
|
|
2825 |
SIG_REMOVE_SIGNAL_FROM_SET(SIGSTOP,lTemp);
|
|
2826 |
if(lTemp == 0 && !SIG_ISEMPTY_SIGSET(set))
|
|
2827 |
return 0;
|
|
2828 |
|
|
2829 |
TInt lTimeout = timeout->tv_sec*1000*1000 + timeout->tv_nsec/1000;
|
|
2830 |
if(lTimeout < 0)
|
|
2831 |
{
|
|
2832 |
lTimeCheckFailed = ETrue;
|
|
2833 |
}
|
|
2834 |
|
|
2835 |
TInt lRetVal = KErrNone;
|
|
2836 |
TInt lSigNum = 0;
|
|
2837 |
TSignalMessage lMsg;
|
|
2838 |
|
|
2839 |
lRetVal = SigWaitInternal((TUint64)*set,&lMsg,lTimeout,lTimeCheckFailed);
|
|
2840 |
|
|
2841 |
if(lRetVal == KErrNone)
|
|
2842 |
{
|
|
2843 |
if(lMsg.mType == TSignalMessage::ESignal)
|
|
2844 |
{
|
|
2845 |
lSigNum = lMsg.mSignal;
|
|
2846 |
if(info)
|
|
2847 |
{
|
|
2848 |
info->si_signo = lSigNum;
|
|
2849 |
info->si_value.sival_int = 0;
|
|
2850 |
}
|
|
2851 |
}
|
|
2852 |
else if(lMsg.mType == TSignalMessage::ESignalValuePair)
|
|
2853 |
{
|
|
2854 |
lSigNum = lMsg.mSigVal.mSignal;
|
|
2855 |
if(info)
|
|
2856 |
{
|
|
2857 |
info->si_signo = lSigNum;
|
|
2858 |
info->si_value.sival_int = (int)lMsg.mSigVal.mValue;
|
|
2859 |
}
|
|
2860 |
}
|
|
2861 |
else if(lMsg.mType == TSignalMessage::ERtTimerSignal)
|
|
2862 |
{
|
|
2863 |
lSigNum = lMsg.mRtSignal.mSignal;
|
|
2864 |
if(info)
|
|
2865 |
{
|
|
2866 |
info->si_signo = lSigNum;
|
|
2867 |
info->si_value.sival_int = 0;
|
|
2868 |
}
|
|
2869 |
}
|
|
2870 |
}
|
|
2871 |
else if (lRetVal == KErrTimedOut)
|
|
2872 |
{
|
|
2873 |
anErrno = EAGAIN;
|
|
2874 |
return -1;
|
|
2875 |
}
|
|
2876 |
else
|
|
2877 |
{
|
|
2878 |
anErrno = EINVAL;
|
|
2879 |
return -1;
|
|
2880 |
}
|
|
2881 |
return lSigNum;
|
|
2882 |
}
|
|
2883 |
|
|
2884 |
// -----------------------------------------------------------------------------
|
|
2885 |
// CLocalSystemInterface::sigwaitinfo
|
|
2886 |
// -----------------------------------------------------------------------------
|
|
2887 |
//
|
|
2888 |
int CLocalSystemInterface::sigwaitinfo(const sigset_t *set, siginfo_t *info, int& anErrno)
|
|
2889 |
{
|
|
2890 |
if(!iSignalsInitialized)
|
|
2891 |
{
|
|
2892 |
anErrno = ENOTSUP;
|
|
2893 |
return -1;
|
|
2894 |
}
|
|
2895 |
|
|
2896 |
EnsureSignalsInitialized();
|
|
2897 |
|
|
2898 |
if(set == 0)
|
|
2899 |
{
|
|
2900 |
anErrno = EINVAL;
|
|
2901 |
return -1;
|
|
2902 |
}
|
|
2903 |
|
|
2904 |
if(SIG_ISEMPTY_SIGSET(*set))
|
|
2905 |
{
|
|
2906 |
anErrno = EINVAL;
|
|
2907 |
return -1;
|
|
2908 |
}
|
|
2909 |
|
|
2910 |
TUint64 lTemp = *set;
|
|
2911 |
SIG_REMOVE_SIGNAL_FROM_SET(SIGKILL,lTemp);
|
|
2912 |
SIG_REMOVE_SIGNAL_FROM_SET(SIGSTOP,lTemp);
|
|
2913 |
if(lTemp == 0 && !SIG_ISEMPTY_SIGSET(set))
|
|
2914 |
return 0;
|
|
2915 |
|
|
2916 |
TInt lRetVal = KErrNone;
|
|
2917 |
TInt lSigNum = 0;
|
|
2918 |
TSignalMessage lMsg;
|
|
2919 |
|
|
2920 |
lRetVal = SigWaitInternal((TUint64)*set,&lMsg,0);
|
|
2921 |
|
|
2922 |
if(lRetVal == KErrNone)
|
|
2923 |
{
|
|
2924 |
if(lMsg.mType == TSignalMessage::ESignal)
|
|
2925 |
{
|
|
2926 |
lSigNum = lMsg.mSignal;
|
|
2927 |
if(info)
|
|
2928 |
{
|
|
2929 |
info->si_signo = lSigNum;
|
|
2930 |
info->si_value.sival_int = 0;
|
|
2931 |
}
|
|
2932 |
}
|
|
2933 |
else if(lMsg.mType == TSignalMessage::ESignalValuePair)
|
|
2934 |
{
|
|
2935 |
lSigNum = lMsg.mSigVal.mSignal;
|
|
2936 |
if(info)
|
|
2937 |
{
|
|
2938 |
info->si_signo = lSigNum;
|
|
2939 |
info->si_value.sival_int = (int)lMsg.mSigVal.mValue;
|
|
2940 |
}
|
|
2941 |
}
|
|
2942 |
else if(lMsg.mType == TSignalMessage::ERtTimerSignal)
|
|
2943 |
{
|
|
2944 |
lSigNum = lMsg.mRtSignal.mSignal;
|
|
2945 |
if(info)
|
|
2946 |
{
|
|
2947 |
info->si_signo = lSigNum;
|
|
2948 |
info->si_value.sival_int = 0;
|
|
2949 |
}
|
|
2950 |
}
|
|
2951 |
else
|
|
2952 |
{
|
|
2953 |
anErrno = EINVAL;
|
|
2954 |
return -1;
|
|
2955 |
}
|
|
2956 |
}
|
|
2957 |
|
|
2958 |
return lSigNum;
|
|
2959 |
}
|
|
2960 |
|
|
2961 |
// -----------------------------------------------------------------------------
|
|
2962 |
// CLocalSystemInterface::sigaction
|
|
2963 |
// -----------------------------------------------------------------------------
|
|
2964 |
//
|
|
2965 |
int CLocalSystemInterface::sigaction(int aSigNum, const struct sigaction *act, struct sigaction *oact, int& anErrno)
|
|
2966 |
{
|
|
2967 |
if(!iSignalsInitialized)
|
|
2968 |
{
|
|
2969 |
anErrno = ENOTSUP;
|
|
2970 |
return -1;
|
|
2971 |
}
|
|
2972 |
|
|
2973 |
EnsureSignalsInitialized();
|
|
2974 |
|
|
2975 |
if(aSigNum < 1 || aSigNum > SIGRTMAX || aSigNum == SIGKILL || aSigNum == SIGSTOP)
|
|
2976 |
{
|
|
2977 |
return MapError(KErrArgument,anErrno);
|
|
2978 |
}
|
|
2979 |
|
|
2980 |
if(act && (act->sa_flags & (SA_NOCLDSTOP | SA_ONSTACK | SA_RESTART| SA_NOCLDWAIT))) //Whar abt SA_NODEFER
|
|
2981 |
{
|
|
2982 |
anErrno = ENOTSUP;
|
|
2983 |
return -1;
|
|
2984 |
}
|
|
2985 |
|
|
2986 |
iSigHandlerMutex.Wait();
|
|
2987 |
if(oact)
|
|
2988 |
{
|
|
2989 |
if( (iSigActions[aSigNum-1].iSigFlags & SA_SIGINFO)
|
|
2990 |
&& iSigActions[aSigNum-1].iSigAction)
|
|
2991 |
{
|
|
2992 |
oact->sa_flags = iSigActions[aSigNum-1].iSigFlags;
|
|
2993 |
oact->sa_sigaction = iSigActions[aSigNum-1].iSigAction;
|
|
2994 |
}
|
|
2995 |
else
|
|
2996 |
{
|
|
2997 |
oact->sa_flags = iSigActions[aSigNum-1].iSigFlags;
|
|
2998 |
oact->sa_handler = iSigActions[aSigNum-1].iSigHandler;
|
|
2999 |
}
|
|
3000 |
}
|
|
3001 |
|
|
3002 |
if(act)
|
|
3003 |
{
|
|
3004 |
if(act->sa_flags & SA_SIGINFO)
|
|
3005 |
{
|
|
3006 |
iSigActions[aSigNum-1].iSigAction = act->sa_sigaction;
|
|
3007 |
iSigActions[aSigNum-1].iSigFlags = act->sa_flags;
|
|
3008 |
}
|
|
3009 |
else
|
|
3010 |
{
|
|
3011 |
iSigActions[aSigNum-1].iSigHandler = act->sa_handler;
|
|
3012 |
iSigActions[aSigNum-1].iSigAction = 0;
|
|
3013 |
iSigActions[aSigNum-1].iSigFlags = act->sa_flags;
|
|
3014 |
}
|
|
3015 |
}
|
|
3016 |
iSigHandlerMutex.Signal();
|
|
3017 |
|
|
3018 |
return MapError(KErrNone,anErrno);
|
|
3019 |
|
|
3020 |
}
|
|
3021 |
|
|
3022 |
// -----------------------------------------------------------------------------
|
|
3023 |
// CLocalSystemInterface::sigset
|
|
3024 |
// -----------------------------------------------------------------------------
|
|
3025 |
//
|
|
3026 |
TSignalHandler CLocalSystemInterface::sigset(int aSigNum, TSignalHandler disp, int& anErrno)
|
|
3027 |
{
|
|
3028 |
if(!iSignalsInitialized)
|
|
3029 |
{
|
|
3030 |
anErrno = ENOTSUP;
|
|
3031 |
return SIG_ERR;
|
|
3032 |
}
|
|
3033 |
|
|
3034 |
TUint64 lOldMask = iSigMask;
|
|
3035 |
EnsureSignalsInitialized();
|
|
3036 |
|
|
3037 |
if(aSigNum < 1 || aSigNum > SIGRTMAX || aSigNum == SIGKILL || aSigNum == SIGSTOP)
|
|
3038 |
{
|
|
3039 |
anErrno = EINVAL;
|
|
3040 |
return SIG_ERR;
|
|
3041 |
}
|
|
3042 |
TSignalHandler lOldHandler = iSigActions[aSigNum-1].iSigHandler;
|
|
3043 |
|
|
3044 |
if(disp == SIG_HOLD)
|
|
3045 |
{
|
|
3046 |
SIG_ADD_SIGNAL_TO_SET(aSigNum,iSigMask);
|
|
3047 |
}
|
|
3048 |
else
|
|
3049 |
{
|
|
3050 |
iSigHandlerMutex.Wait();
|
|
3051 |
iSigActions[aSigNum-1].iSigHandler = disp;
|
|
3052 |
iSigActions[aSigNum-1].iSigAction = 0;
|
|
3053 |
iSigActions[aSigNum-1].iSigFlags = 0;
|
|
3054 |
iSigHandlerMutex.Signal();
|
|
3055 |
SIG_REMOVE_SIGNAL_FROM_SET(aSigNum,iSigMask);
|
|
3056 |
}
|
|
3057 |
|
|
3058 |
if(SIG_SIGNAL_PRESENT_IN_SIGSET(aSigNum,lOldMask))
|
|
3059 |
return SIG_HOLD;
|
|
3060 |
else
|
|
3061 |
return lOldHandler;
|
|
3062 |
}
|
|
3063 |
|
|
3064 |
// -----------------------------------------------------------------------------
|
|
3065 |
// CLocalSystemInterface::bsd_signal
|
|
3066 |
// -----------------------------------------------------------------------------
|
|
3067 |
//
|
|
3068 |
TSignalHandler CLocalSystemInterface::bsd_signal(int aSigNum, TSignalHandler aFunc,int& anErrno)
|
|
3069 |
{
|
|
3070 |
return signal(aSigNum,aFunc,anErrno);
|
|
3071 |
}
|
|
3072 |
|
|
3073 |
// -----------------------------------------------------------------------------
|
|
3074 |
// CLocalSystemInterface::signal
|
|
3075 |
// -----------------------------------------------------------------------------
|
|
3076 |
//
|
|
3077 |
TSignalHandler CLocalSystemInterface::signal(int aSigNum, TSignalHandler aFunc,int& anErrno)
|
|
3078 |
{
|
|
3079 |
if(!iSignalsInitialized)
|
|
3080 |
{
|
|
3081 |
anErrno = ENOTSUP;
|
|
3082 |
return SIG_ERR;
|
|
3083 |
}
|
|
3084 |
|
|
3085 |
EnsureSignalsInitialized();
|
|
3086 |
|
|
3087 |
if(aSigNum < 1 || aSigNum > SIGRTMAX || aSigNum == SIGKILL || aSigNum == SIGSTOP)
|
|
3088 |
{
|
|
3089 |
anErrno = EINVAL;
|
|
3090 |
return SIG_ERR;
|
|
3091 |
}
|
|
3092 |
|
|
3093 |
iSigHandlerMutex.Wait();
|
|
3094 |
TSignalHandler lOldHandler = iSigActions[aSigNum-1].iSigHandler;
|
|
3095 |
iSigActions[aSigNum-1].iSigHandler = aFunc;
|
|
3096 |
iSigActions[aSigNum-1].iSigAction = 0;
|
|
3097 |
iSigActions[aSigNum-1].iSigFlags = 0;
|
|
3098 |
iSigHandlerMutex.Signal();
|
|
3099 |
return lOldHandler;
|
|
3100 |
}
|
|
3101 |
|
|
3102 |
// -----------------------------------------------------------------------------
|
|
3103 |
// CLocalSystemInterface::sigignore
|
|
3104 |
// -----------------------------------------------------------------------------
|
|
3105 |
//
|
|
3106 |
int CLocalSystemInterface::sigignore(int aSigNum, int& anErrno)
|
|
3107 |
{
|
|
3108 |
if(!iSignalsInitialized)
|
|
3109 |
{
|
|
3110 |
anErrno = ENOTSUP;
|
|
3111 |
return -1;
|
|
3112 |
}
|
|
3113 |
|
|
3114 |
EnsureSignalsInitialized();
|
|
3115 |
|
|
3116 |
if(aSigNum < 1 || aSigNum > SIGRTMAX || aSigNum == SIGKILL || aSigNum == SIGSTOP)
|
|
3117 |
{
|
|
3118 |
anErrno = EINVAL;
|
|
3119 |
return -1;
|
|
3120 |
}
|
|
3121 |
|
|
3122 |
iSigHandlerMutex.Wait();
|
|
3123 |
iSigActions[aSigNum-1].iSigHandler = SIG_IGN;
|
|
3124 |
iSigActions[aSigNum-1].iSigAction = 0;
|
|
3125 |
iSigActions[aSigNum-1].iSigFlags = 0;
|
|
3126 |
iSigHandlerMutex.Signal();
|
|
3127 |
return 0;
|
|
3128 |
}
|
|
3129 |
// -----------------------------------------------------------------------------
|
|
3130 |
// CLocalSystemInterface::sigpending
|
|
3131 |
// -----------------------------------------------------------------------------
|
|
3132 |
//
|
|
3133 |
int CLocalSystemInterface::sigpending(sigset_t *set,int& anErrno)
|
|
3134 |
{
|
|
3135 |
if(!iSignalsInitialized)
|
|
3136 |
{
|
|
3137 |
anErrno = ENOTSUP;
|
|
3138 |
return -1;
|
|
3139 |
}
|
|
3140 |
|
|
3141 |
EnsureSignalsInitialized();
|
|
3142 |
|
|
3143 |
if(set == 0)
|
|
3144 |
{
|
|
3145 |
anErrno = EFAULT;
|
|
3146 |
return -1;
|
|
3147 |
}
|
|
3148 |
|
|
3149 |
SIG_EMPTY_SIGSET(*set);
|
|
3150 |
|
|
3151 |
TInt lIdx = 0;
|
|
3152 |
|
|
3153 |
for(lIdx = 0;lIdx < iBlockedSigArray.Count(); lIdx++)
|
|
3154 |
{
|
|
3155 |
TUint8 lSigNum = 0;
|
|
3156 |
if(iBlockedSigArray[lIdx].mType == TSignalMessage::ESignal)
|
|
3157 |
lSigNum = iBlockedSigArray[lIdx].mSignal;
|
|
3158 |
else if(iBlockedSigArray[lIdx].mType == TSignalMessage::ESignalValuePair)
|
|
3159 |
lSigNum = iBlockedSigArray[lIdx].mSigVal.mSignal;
|
|
3160 |
else if(iBlockedSigArray[lIdx].mType == TSignalMessage::ERtTimerSignal)
|
|
3161 |
lSigNum = iBlockedSigArray[lIdx].mRtSignal.mSignal;
|
|
3162 |
SIG_ADD_SIGNAL_TO_SET(lSigNum,*set);
|
|
3163 |
}
|
|
3164 |
|
|
3165 |
return MapError(KErrNone,anErrno);
|
|
3166 |
}
|
|
3167 |
|
|
3168 |
// -----------------------------------------------------------------------------
|
|
3169 |
// CLocalSystemInterface::alarm
|
|
3170 |
// -----------------------------------------------------------------------------
|
|
3171 |
//
|
|
3172 |
unsigned int CLocalSystemInterface::alarm(unsigned int seconds)
|
|
3173 |
{
|
|
3174 |
if(!iSignalsInitialized)
|
|
3175 |
{
|
|
3176 |
return 0;
|
|
3177 |
}
|
|
3178 |
|
|
3179 |
EnsureSignalsInitialized();
|
|
3180 |
|
|
3181 |
TTime lCurrentTime;
|
|
3182 |
TTimeIntervalSeconds lTimeLapse;
|
|
3183 |
|
|
3184 |
unsigned int lTimeLeft = 0;
|
|
3185 |
|
|
3186 |
if(iIsTimerActive)
|
|
3187 |
{
|
|
3188 |
lCurrentTime.HomeTime();
|
|
3189 |
lCurrentTime.SecondsFrom(iAlarmStartTime,lTimeLapse);
|
|
3190 |
lTimeLeft = iCurrentTimeout - lTimeLapse.Int();
|
|
3191 |
if((int)lTimeLeft < 0)
|
|
3192 |
lTimeLeft = 0;
|
|
3193 |
}
|
|
3194 |
|
|
3195 |
iCurrentTimeout = seconds;
|
|
3196 |
TSignalMessage lMsg;
|
|
3197 |
lMsg.mType = TSignalMessage::EAlarmRegistration;
|
|
3198 |
lMsg.mTimeOut = seconds;
|
|
3199 |
TBuf8<KSigMsgLength> lMsgBuf;
|
|
3200 |
lMsg.Marshall(lMsgBuf);
|
|
3201 |
iSignalWritePipe.Write(lMsgBuf,KSigMsgLength);
|
|
3202 |
|
|
3203 |
return lTimeLeft;
|
|
3204 |
}
|
|
3205 |
|
|
3206 |
|
|
3207 |
#ifdef SYMBIAN_OE_LIBRT
|
|
3208 |
// -----------------------------------------------------------------------------
|
|
3209 |
// CLocalSystemInterface::FindTimer
|
|
3210 |
// -----------------------------------------------------------------------------
|
|
3211 |
//
|
|
3212 |
EXPORT_C TInt CLocalSystemInterface::FindTimer(const TInt& aTimerId)
|
|
3213 |
{
|
|
3214 |
iTimerOverrunsMutex.Wait();
|
|
3215 |
|
|
3216 |
TInt lIndex = KErrNotFound;
|
|
3217 |
TInt lTimerCnt = iTimerOverruns.Count();
|
|
3218 |
for(TInt lIdx = 0; lIdx < lTimerCnt; lIdx++)
|
|
3219 |
{
|
|
3220 |
if(iTimerOverruns[lIdx].iTimerId == aTimerId)
|
|
3221 |
{
|
|
3222 |
lIndex = lIdx;
|
|
3223 |
break;
|
|
3224 |
}
|
|
3225 |
}
|
|
3226 |
|
|
3227 |
iTimerOverrunsMutex.Signal();
|
|
3228 |
return lIndex;
|
|
3229 |
}
|
|
3230 |
|
|
3231 |
// -----------------------------------------------------------------------------
|
|
3232 |
// CLocalSystemInterface::AddTimer
|
|
3233 |
// -----------------------------------------------------------------------------
|
|
3234 |
//
|
|
3235 |
EXPORT_C TInt CLocalSystemInterface::AddTimer(const TInt& aTimerId)
|
|
3236 |
{
|
|
3237 |
TInt err;
|
|
3238 |
if (FindTimer(aTimerId) >= 0)
|
|
3239 |
{
|
|
3240 |
err = KErrNone;
|
|
3241 |
}
|
|
3242 |
else
|
|
3243 |
{
|
|
3244 |
TOverrun lOverrun(aTimerId);
|
|
3245 |
iTimerOverrunsMutex.Wait();
|
|
3246 |
RHeap* oHeap = User::SwitchHeap(iPrivateHeap);
|
|
3247 |
err = iTimerOverruns.Append(lOverrun);
|
|
3248 |
User::SwitchHeap(oHeap);
|
|
3249 |
if(!err)
|
|
3250 |
{
|
|
3251 |
iTimerOverruns[iTimerOverruns.Count()-1].iTimerId = aTimerId;
|
|
3252 |
}
|
|
3253 |
|
|
3254 |
iTimerOverrunsMutex.Signal();
|
|
3255 |
}
|
|
3256 |
|
|
3257 |
return err;
|
|
3258 |
}
|
|
3259 |
|
|
3260 |
// -----------------------------------------------------------------------------
|
|
3261 |
// CLocalSystemInterface::DeleteTimer
|
|
3262 |
// -----------------------------------------------------------------------------
|
|
3263 |
//
|
|
3264 |
EXPORT_C TInt CLocalSystemInterface::DeleteTimer(const TInt& aTimerId)
|
|
3265 |
{
|
|
3266 |
TInt lRet = FindTimer(aTimerId);
|
|
3267 |
if(lRet >= 0)
|
|
3268 |
{
|
|
3269 |
iTimerOverrunsMutex.Wait();
|
|
3270 |
RHeap* oHeap = User::SwitchHeap(iPrivateHeap);
|
|
3271 |
iTimerOverruns.Remove(lRet);
|
|
3272 |
User::SwitchHeap(oHeap);
|
|
3273 |
iTimerOverrunsMutex.Signal();
|
|
3274 |
|
|
3275 |
return KErrNone;
|
|
3276 |
}
|
|
3277 |
|
|
3278 |
return lRet;
|
|
3279 |
}
|
|
3280 |
|
|
3281 |
// -----------------------------------------------------------------------------
|
|
3282 |
// CLocalSystemInterface::IncrementOverrun
|
|
3283 |
// -----------------------------------------------------------------------------
|
|
3284 |
//
|
|
3285 |
EXPORT_C TInt CLocalSystemInterface::IncrementOverrun(const TInt& aTimerId)
|
|
3286 |
{
|
|
3287 |
TInt lRet = FindTimer(aTimerId);
|
|
3288 |
if(lRet >= 0)
|
|
3289 |
{
|
|
3290 |
iTimerOverrunsMutex.Wait();
|
|
3291 |
iTimerOverruns[lRet].Overruns++;
|
|
3292 |
iTimerOverrunsMutex.Signal();
|
|
3293 |
return iTimerOverruns[lRet].Overruns;
|
|
3294 |
}
|
|
3295 |
|
|
3296 |
return lRet;
|
|
3297 |
}
|
|
3298 |
|
|
3299 |
// -----------------------------------------------------------------------------
|
|
3300 |
// CLocalSystemInterface::ResetOverrun
|
|
3301 |
// -----------------------------------------------------------------------------
|
|
3302 |
//
|
|
3303 |
EXPORT_C TInt CLocalSystemInterface::ResetOverrun(const TInt& aTimerId)
|
|
3304 |
{
|
|
3305 |
TInt lRet = FindTimer(aTimerId);
|
|
3306 |
if(lRet >= 0)
|
|
3307 |
{
|
|
3308 |
iTimerOverrunsMutex.Wait();
|
|
3309 |
iTimerOverruns[lRet].Overruns = 0;
|
|
3310 |
iTimerOverrunsMutex.Signal();
|
|
3311 |
return KErrNone;
|
|
3312 |
}
|
|
3313 |
|
|
3314 |
return KErrNotFound;
|
|
3315 |
|
|
3316 |
}
|
|
3317 |
|
|
3318 |
// -----------------------------------------------------------------------------
|
|
3319 |
// CLocalSystemInterface::Overrun
|
|
3320 |
// -----------------------------------------------------------------------------
|
|
3321 |
//
|
|
3322 |
EXPORT_C TInt CLocalSystemInterface::Overrun(const TInt& aTimerId)
|
|
3323 |
{
|
|
3324 |
TInt lRet = FindTimer(aTimerId);
|
|
3325 |
if(lRet >= 0)
|
|
3326 |
{
|
|
3327 |
return iTimerOverruns[lRet].Overruns;
|
|
3328 |
}
|
|
3329 |
|
|
3330 |
return KErrNotFound;
|
|
3331 |
}
|
|
3332 |
|
|
3333 |
// -----------------------------------------------------------------------------
|
|
3334 |
// CLocalSystemInterface::RaiseTimerSignal
|
|
3335 |
// -----------------------------------------------------------------------------
|
|
3336 |
//
|
|
3337 |
EXPORT_C TInt CLocalSystemInterface::RaiseTimerSignal(int sig, int timerid)
|
|
3338 |
{
|
|
3339 |
EnsureSignalsInitialized();
|
|
3340 |
|
|
3341 |
TInt err = KErrArgument;
|
|
3342 |
if(sig < 1 || sig > SIGRTMAX)
|
|
3343 |
{
|
|
3344 |
return err;
|
|
3345 |
}
|
|
3346 |
// mutex protect
|
|
3347 |
TSignalMessage lMsg;
|
|
3348 |
lMsg.mType = TSignalMessage::ERtTimerSignal;
|
|
3349 |
lMsg.mRtSignal.mSignal = (TUint8)sig;
|
|
3350 |
lMsg.mRtSignal.mTimerId = timerid;
|
|
3351 |
TBuf8<KSigMsgLength> lMsgBuf;
|
|
3352 |
lMsg.Marshall(lMsgBuf);
|
|
3353 |
|
|
3354 |
err = iSignalWritePipe.WriteBlocking(lMsgBuf,KSigMsgLength);
|
|
3355 |
if(err >= 0)
|
|
3356 |
return KErrNone;
|
|
3357 |
|
|
3358 |
return err;
|
|
3359 |
}
|
|
3360 |
|
|
3361 |
#endif //SYMBIAN_OE_LIBRT
|
|
3362 |
|
|
3363 |
#endif // SYMBIAN_OE_POSIX_SIGNALS
|
|
3364 |
|
|
3365 |
// -----------------------------------------------------------------------------
|
|
3366 |
// CLocalSystemInterface::GetDirName
|
|
3367 |
// Implementation for GetDirName
|
|
3368 |
// This will return the name of the directory corresponding to the aFid
|
|
3369 |
// This wont set any error code in case of error.
|
|
3370 |
// Returns the name on success else NULL
|
|
3371 |
// -----------------------------------------------------------------------------
|
|
3372 |
//
|
|
3373 |
const wchar_t* CLocalSystemInterface::GetDirName (int aFid)
|
|
3374 |
{
|
|
3375 |
//Get the CFileDescBase at the index aFid
|
|
3376 |
CFileDescBase* desc = NULL;
|
|
3377 |
TInt err = iFids.At(aFid, desc);
|
|
3378 |
if ( !err )
|
|
3379 |
{
|
|
3380 |
//Cast it back to CDirectoryDesc
|
|
3381 |
CDirectoryDesc* dirDesc = static_cast<CDirectoryDesc*> (desc);
|
|
3382 |
return dirDesc->GetDirName();
|
|
3383 |
}
|
|
3384 |
return (const wchar_t*)NULL;
|
|
3385 |
}
|
|
3386 |
|
|
3387 |
// -----------------------------------------------------------------------------
|
|
3388 |
// CLocalSystemInterface::Truncate
|
|
3389 |
// Implementation for Truncate
|
|
3390 |
// This will Truncate a file represented by aFid
|
|
3391 |
// Returns the success/error code on completion
|
|
3392 |
// -----------------------------------------------------------------------------
|
|
3393 |
//
|
|
3394 |
EXPORT_C int CLocalSystemInterface::Truncate(int aFid, off_t anOffset, int& anErrno)
|
|
3395 |
{
|
|
3396 |
TInt err = KErrArgument;
|
|
3397 |
#if defined(SYMBIAN_OE_LARGE_FILE_SUPPORT) && !defined(SYMBIAN_OE_NO_LFS)
|
|
3398 |
off_t offset = anOffset;
|
|
3399 |
#else
|
|
3400 |
TInt offset = (TInt)anOffset;
|
|
3401 |
#endif //SYMBIAN_OE_LARGE_FILE_SUPPORT && !SYMBIAN_OE_NO_LFS
|
|
3402 |
//Proceed only if offset is non-negetive number
|
|
3403 |
if ( offset >= 0 )
|
|
3404 |
{//Get the CFileDescBase at the index aFid
|
|
3405 |
CFileDescBase* desc = NULL;
|
|
3406 |
err = iFids.At(aFid, desc);
|
|
3407 |
if ( !err )
|
|
3408 |
{
|
|
3409 |
err = desc->Truncate(offset);
|
|
3410 |
if( err == KErrAccessDenied )
|
|
3411 |
{
|
|
3412 |
//Ensure that, it will set errno as EINVAL
|
|
3413 |
err = KErrArgument;
|
|
3414 |
}
|
|
3415 |
}
|
|
3416 |
}
|
|
3417 |
|
|
3418 |
return MapError(err, anErrno);
|
|
3419 |
}
|
|
3420 |
|
|
3421 |
// -----------------------------------------------------------------------------
|
|
3422 |
// CLocalSystemInterface::GetDesc
|
|
3423 |
// Implementation for GetDesc
|
|
3424 |
// This will return the CFileDescBase object corresponding to aFid
|
|
3425 |
// -----------------------------------------------------------------------------
|
|
3426 |
//
|
|
3427 |
EXPORT_C CFileDescBase* CLocalSystemInterface::GetDesc(int aFid)
|
|
3428 |
{
|
|
3429 |
CFileDescBase* fileDesc = NULL;
|
|
3430 |
//coverity[unchecked_value]
|
|
3431 |
iFids.At(aFid, fileDesc);
|
|
3432 |
return fileDesc;
|
|
3433 |
}
|
|
3434 |
|
|
3435 |
// -----------------------------------------------------------------------------
|
|
3436 |
// CLocalSystemInterface::FileSession
|
|
3437 |
// This will return the file session
|
|
3438 |
// -----------------------------------------------------------------------------
|
|
3439 |
//
|
|
3440 |
EXPORT_C RFs& CLocalSystemInterface::FileSession()
|
|
3441 |
{
|
|
3442 |
return iFs;
|
|
3443 |
}
|
|
3444 |
|
|
3445 |
// -----------------------------------------------------------------------------
|
|
3446 |
// CLocalSystemInterface::CommServSession
|
|
3447 |
// This will return the communication server session
|
|
3448 |
// -----------------------------------------------------------------------------
|
|
3449 |
//
|
|
3450 |
RCommServ& CLocalSystemInterface::CommServSession()
|
|
3451 |
{
|
|
3452 |
return iCs;
|
|
3453 |
}
|
|
3454 |
|
|
3455 |
// -----------------------------------------------------------------------------
|
|
3456 |
// CLocalSystemInterface::SockServSession
|
|
3457 |
// This will return the socket server session
|
|
3458 |
// -----------------------------------------------------------------------------
|
|
3459 |
//
|
|
3460 |
RSocketServ& CLocalSystemInterface::SockServSession()
|
|
3461 |
{
|
|
3462 |
return iSs;
|
|
3463 |
}
|
|
3464 |
|
|
3465 |
// -----------------------------------------------------------------------------
|
|
3466 |
// CLocalSystemInterface::Alloc
|
|
3467 |
// Dynamic Memory related APIs
|
|
3468 |
// Allocates memory in the private heap
|
|
3469 |
// -----------------------------------------------------------------------------
|
|
3470 |
//
|
|
3471 |
EXPORT_C void* CLocalSystemInterface::Alloc(size_t aNBytes)
|
|
3472 |
{
|
|
3473 |
return iPrivateHeap->AllocZ(aNBytes);
|
|
3474 |
}
|
|
3475 |
|
|
3476 |
// -----------------------------------------------------------------------------
|
|
3477 |
// CLocalSystemInterface::ReAlloc
|
|
3478 |
// Dynamic Memory related APIs
|
|
3479 |
// Allocates memory in the private heap
|
|
3480 |
// -----------------------------------------------------------------------------
|
|
3481 |
//
|
|
3482 |
EXPORT_C void* CLocalSystemInterface::ReAlloc(void* aPtr, size_t aNBytes)
|
|
3483 |
{
|
|
3484 |
return iPrivateHeap->ReAlloc(aPtr, aNBytes);
|
|
3485 |
}
|
|
3486 |
|
|
3487 |
// -----------------------------------------------------------------------------
|
|
3488 |
// CLocalSystemInterface::Free
|
|
3489 |
// Dynamic Memory related APIs
|
|
3490 |
// Frees memory in the private heap
|
|
3491 |
// -----------------------------------------------------------------------------
|
|
3492 |
//
|
|
3493 |
EXPORT_C void CLocalSystemInterface::Free(void* aPtr)
|
|
3494 |
{
|
|
3495 |
iPrivateHeap->Free(aPtr);
|
|
3496 |
}
|
|
3497 |
|
|
3498 |
|
|
3499 |
// -----------------------------------------------------------------------------
|
|
3500 |
// CLocalSystemInterface::AllocTLD
|
|
3501 |
// Dynamic Memory related APIs
|
|
3502 |
// Allocates memory for the thread's TLD and cleans up TLD of dead threads
|
|
3503 |
// -----------------------------------------------------------------------------
|
|
3504 |
//
|
|
3505 |
EXPORT_C void* CLocalSystemInterface::AllocTLD(TInt aSize)
|
|
3506 |
{
|
|
3507 |
// Allocate memory for reent structure on private heap
|
|
3508 |
void* ptr = iPrivateHeap->AllocZ(aSize);
|
|
3509 |
|
|
3510 |
iTLDListLock.Wait();
|
|
3511 |
RHeap* oheap = User::SwitchHeap(iPrivateHeap);
|
|
3512 |
|
|
3513 |
TThreadId caller = RThread().Id();
|
|
3514 |
RThread thrd;
|
|
3515 |
|
|
3516 |
TInt idx = -1;
|
|
3517 |
|
|
3518 |
TInt tcount = iTLDInfoList.Count();
|
|
3519 |
|
|
3520 |
for (int i = 0; i < tcount; ++i)
|
|
3521 |
{
|
|
3522 |
TTLDInfo& tldinf = iTLDInfoList[i];
|
|
3523 |
|
|
3524 |
TInt ptrcount = tldinf.iPtrs.Count();
|
|
3525 |
|
|
3526 |
if (!ptrcount)
|
|
3527 |
{
|
|
3528 |
// This slot has already been freed. Save here?
|
|
3529 |
idx = i;
|
|
3530 |
continue;
|
|
3531 |
}
|
|
3532 |
|
|
3533 |
TInt err = thrd.Open(tldinf.iTid);
|
|
3534 |
|
|
3535 |
if (err != KErrNone || thrd.ExitType() != EExitPending)
|
|
3536 |
{
|
|
3537 |
// This thread is dead. Bury it.
|
|
3538 |
for (int j = 0; j < ptrcount; ++j)
|
|
3539 |
{
|
|
3540 |
iPrivateHeap->FreeZ(tldinf.iPtrs[j]);
|
|
3541 |
}
|
|
3542 |
|
|
3543 |
(tldinf.iPtrs).Reset();
|
|
3544 |
|
|
3545 |
// this slot can be reused. Save here?
|
|
3546 |
idx = i;
|
|
3547 |
}
|
|
3548 |
else
|
|
3549 |
{
|
|
3550 |
// Points to a live thread
|
|
3551 |
if (tldinf.iTid == caller)
|
|
3552 |
{
|
|
3553 |
// This is the calling thread. We must save the TLD ptr here
|
|
3554 |
idx = i;
|
|
3555 |
}
|
|
3556 |
}
|
|
3557 |
}
|
|
3558 |
|
|
3559 |
// Only if the initial allocation succeded
|
|
3560 |
if (ptr != NULL)
|
|
3561 |
{
|
|
3562 |
// No free slot. No cleaned-up slots.
|
|
3563 |
if (idx == -1)
|
|
3564 |
{
|
|
3565 |
iTLDInfoList.Append(TTLDInfo(caller, ptr));
|
|
3566 |
}
|
|
3567 |
else
|
|
3568 |
{
|
|
3569 |
// Wouldn't hurt even if it is already set
|
|
3570 |
iTLDInfoList[idx].iTid = caller;
|
|
3571 |
iTLDInfoList[idx].iPtrs.Append(ptr);
|
|
3572 |
}
|
|
3573 |
}
|
|
3574 |
|
|
3575 |
User::SwitchHeap(oheap);
|
|
3576 |
iTLDListLock.Signal();
|
|
3577 |
|
|
3578 |
return ptr;
|
|
3579 |
}
|
|
3580 |
|
|
3581 |
// -----------------------------------------------------------------------------
|
|
3582 |
// CLocalSystemInterface::Heap
|
|
3583 |
//Return the private Heap memory
|
|
3584 |
// -----------------------------------------------------------------------------
|
|
3585 |
//
|
|
3586 |
EXPORT_C RHeap* CLocalSystemInterface::Heap()
|
|
3587 |
{
|
|
3588 |
return iPrivateHeap;
|
|
3589 |
}
|
|
3590 |
|
|
3591 |
// -----------------------------------------------------------------------------
|
|
3592 |
// CLocalSystemInterface::CommsSessionLock
|
|
3593 |
//Return the Comms Server Lock
|
|
3594 |
// -----------------------------------------------------------------------------
|
|
3595 |
//
|
|
3596 |
RFastLock& CLocalSystemInterface::CommsSessionLock()
|
|
3597 |
{
|
|
3598 |
return iCSLock;
|
|
3599 |
}
|
|
3600 |
|
|
3601 |
// -----------------------------------------------------------------------------
|
|
3602 |
// CLocalSystemInterface::CommsSessionLock
|
|
3603 |
//Return reference to file table
|
|
3604 |
// -----------------------------------------------------------------------------
|
|
3605 |
//
|
|
3606 |
const CFileTable& CLocalSystemInterface::FileTable() const
|
|
3607 |
{
|
|
3608 |
return iFids;
|
|
3609 |
}
|
|
3610 |
|
|
3611 |
// ---------------------------------------------------------------------------------
|
|
3612 |
// CLocalSystemInterface::WaitForNRequest
|
|
3613 |
// Wait for any one of the input asynchronous requests to complete
|
|
3614 |
// Used in lieu of User::WaitForNRequest because of need to support pre-Argus builds
|
|
3615 |
// ---------------------------------------------------------------------------------
|
|
3616 |
//
|
|
3617 |
void CLocalSystemInterface::WaitForNRequest(TRequestStatus aStatusArray[], TInt aNum)
|
|
3618 |
{
|
|
3619 |
if (aNum)
|
|
3620 |
{
|
|
3621 |
// used to keep count of requests we have not been asked to wait for
|
|
3622 |
TInt nOther = -1;
|
|
3623 |
TBool done = EFalse;
|
|
3624 |
|
|
3625 |
do
|
|
3626 |
{
|
|
3627 |
++nOther;
|
|
3628 |
User::WaitForAnyRequest();
|
|
3629 |
for (TInt i = 0; i < aNum; ++i)
|
|
3630 |
{
|
|
3631 |
if (aStatusArray[i].Int() != KRequestPending)
|
|
3632 |
{
|
|
3633 |
done = ETrue;
|
|
3634 |
break;
|
|
3635 |
}
|
|
3636 |
}
|
|
3637 |
} while (!done);
|
|
3638 |
|
|
3639 |
if (nOther)
|
|
3640 |
{
|
|
3641 |
// Adjust the thread's signal semaphore to account for the requests
|
|
3642 |
// we were not asked to wait for.
|
|
3643 |
RThread thrd;
|
|
3644 |
for (TInt i = 0; i < nOther; ++i)
|
|
3645 |
{
|
|
3646 |
thrd.RequestSignal();
|
|
3647 |
}
|
|
3648 |
}
|
|
3649 |
}
|
|
3650 |
}
|
|
3651 |
/*
|
|
3652 |
CLocalSystemInterface::AddToDirList
|
|
3653 |
Appends Open Directory handle to a RPointerArray array and retuns 0
|
|
3654 |
*/
|
|
3655 |
|
|
3656 |
int CLocalSystemInterface::AddToDirList(DIR *aDir)
|
|
3657 |
{
|
|
3658 |
RHeap* oheap = User::SwitchHeap(iPrivateHeap);
|
|
3659 |
TInt ret = iOpenDirList.Append(aDir);
|
|
3660 |
User::SwitchHeap(oheap);
|
|
3661 |
return ret;
|
|
3662 |
}
|
|
3663 |
|
|
3664 |
|
|
3665 |
/*
|
|
3666 |
CLocalSystemInterface::RemoveFromDirList
|
|
3667 |
Remove the Directory handle from the array and closes the array.
|
|
3668 |
*/
|
|
3669 |
|
|
3670 |
int CLocalSystemInterface::RemoveDirFromList(DIR* aDir)
|
|
3671 |
{
|
|
3672 |
|
|
3673 |
TInt ret = iOpenDirList.Find(aDir);
|
|
3674 |
if(ret != KErrNotFound)
|
|
3675 |
{
|
|
3676 |
RHeap* oheap = User::SwitchHeap(iPrivateHeap);
|
|
3677 |
iOpenDirList.Remove(ret);
|
|
3678 |
User::SwitchHeap(oheap);
|
|
3679 |
}
|
|
3680 |
return ret;
|
|
3681 |
}
|
|
3682 |
|
|
3683 |
|
|
3684 |
|
|
3685 |
/*
|
|
3686 |
TBool CLocalSystemInterface::ValidateInDirList
|
|
3687 |
Validates the Directory handle with the array and returns ETrue upon success
|
|
3688 |
else returns EFalse.
|
|
3689 |
*/
|
|
3690 |
|
|
3691 |
int CLocalSystemInterface::FindInDirList(DIR* aDir)
|
|
3692 |
{
|
|
3693 |
return(iOpenDirList.Find(aDir));
|
|
3694 |
}
|
|
3695 |
|
|
3696 |
//
|
|
3697 |
//int CLocalSystemInterface::SetEcho(int aFd, TBool aEcho, int& aErrno)
|
|
3698 |
//
|
|
3699 |
//Set the echo flag of the suppported console abstractions matching
|
|
3700 |
//the given fd.
|
|
3701 |
//
|
|
3702 |
int CLocalSystemInterface::SetEcho(int aFd, TUint8 aEcho, int& aErrno)
|
|
3703 |
{
|
|
3704 |
return iFids.SetEcho(aFd, aEcho, aErrno);
|
|
3705 |
}
|
|
3706 |
|
|
3707 |
// -----------------------------------------------------------------------------
|
|
3708 |
// CLocalSystemInterface::ReadRecordFromIapTableL
|
|
3709 |
//
|
|
3710 |
// Helper function to read a record from the IAP table
|
|
3711 |
// -----------------------------------------------------------------------------
|
|
3712 |
//
|
|
3713 |
void CLocalSystemInterface::ReadRecordFromIapTableL(CCommsDbTableView* aView, TAccessPointRecord &aRecord)
|
|
3714 |
{
|
|
3715 |
aView->ReadUintL(TPtrC(COMMDB_ID), aRecord.iId);
|
|
3716 |
aView->ReadTextL(TPtrC(COMMDB_NAME), aRecord.iName);
|
|
3717 |
aView->ReadUintL(TPtrC(IAP_BEARER), aRecord.iBearer);
|
|
3718 |
aView->ReadUintL(TPtrC(IAP_NETWORK), aRecord.iNetwork);
|
|
3719 |
}
|
|
3720 |
|
|
3721 |
// -----------------------------------------------------------------------------
|
|
3722 |
// CLocalSystemInterface::GetConnectionPreferencesL
|
|
3723 |
//
|
|
3724 |
// Get the connection preferences from an IAP name.
|
|
3725 |
// -----------------------------------------------------------------------------
|
|
3726 |
//
|
|
3727 |
TInt CLocalSystemInterface::GetConnectionPreferencesL(TBuf<KCommsDbSvrMaxColumnNameLength> aIapName,
|
|
3728 |
TCommDbConnPref &aConnPref)
|
|
3729 |
{
|
|
3730 |
TInt err = KErrNone;
|
|
3731 |
|
|
3732 |
//Open the database and create the IAP view.
|
|
3733 |
CCommsDatabase *iApDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
|
|
3734 |
CleanupStack::PushL(iApDb);
|
|
3735 |
iApDb->ShowHiddenRecords();
|
|
3736 |
//The following pushes the view onto the cleanup stack
|
|
3737 |
CCommsDbTableView *view = iApDb->OpenTableLC(TPtrC(IAP));
|
|
3738 |
|
|
3739 |
//Iterate through the records to find the matching entry
|
|
3740 |
TAccessPointRecord apRecord;
|
|
3741 |
err = view->GotoFirstRecord();
|
|
3742 |
while (err == KErrNone)
|
|
3743 |
{
|
|
3744 |
//The following function will leave in case of error
|
|
3745 |
ReadRecordFromIapTableL(view, apRecord);
|
|
3746 |
if (aIapName == apRecord.iName)
|
|
3747 |
break;
|
|
3748 |
|
|
3749 |
err = view->GotoNextRecord();
|
|
3750 |
}
|
|
3751 |
|
|
3752 |
CleanupStack::PopAndDestroy(); //Free the view
|
|
3753 |
CleanupStack::PopAndDestroy(iApDb); //Free the db itself
|
|
3754 |
|
|
3755 |
if(err != KErrNone) //Record not found
|
|
3756 |
return KErrNotFound;
|
|
3757 |
|
|
3758 |
aConnPref.SetIapId(apRecord.iId);
|
|
3759 |
aConnPref.SetNetId(apRecord.iNetwork);
|
|
3760 |
aConnPref.SetBearerSet(apRecord.iBearer);
|
|
3761 |
aConnPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
|
|
3762 |
aConnPref.SetDirection(ECommDbConnectionDirectionUnknown);
|
|
3763 |
|
|
3764 |
return KErrNone;
|
|
3765 |
}
|
|
3766 |
|
|
3767 |
// -----------------------------------------------------------------------------
|
|
3768 |
// CLocalSystemInterface::RestartDefConnection
|
|
3769 |
//
|
|
3770 |
// Helper function for the setdefaultif() API to restart the
|
|
3771 |
// default RConnection with the new settings.
|
|
3772 |
// -----------------------------------------------------------------------------
|
|
3773 |
//
|
|
3774 |
TInt CLocalSystemInterface::StartDefConnection()
|
|
3775 |
{
|
|
3776 |
//Close the connection and re-open it with the new preferences
|
|
3777 |
if(iDefConnection.SubSessionHandle() != 0)
|
|
3778 |
iDefConnection.Close();
|
|
3779 |
|
|
3780 |
TInt err = iDefConnection.Open(iSs);
|
|
3781 |
if( err != KErrNone )
|
|
3782 |
return err;
|
|
3783 |
|
|
3784 |
err = iDefConnection.Start(*iDefConnPref);
|
|
3785 |
if( err != KErrNone )
|
|
3786 |
iDefConnection.Close();
|
|
3787 |
|
|
3788 |
return err;
|
|
3789 |
}
|
|
3790 |
|
|
3791 |
// -----------------------------------------------------------------------------
|
|
3792 |
// CLocalSystemInterface::setdefaultif
|
|
3793 |
//
|
|
3794 |
// Set the default interface for network operations
|
|
3795 |
// -----------------------------------------------------------------------------
|
|
3796 |
//
|
|
3797 |
int CLocalSystemInterface::setdefaultif(const struct ifreq* aIfReq)
|
|
3798 |
{
|
|
3799 |
//If the argument is NULL, close the existing connection
|
|
3800 |
if(aIfReq == NULL )
|
|
3801 |
{
|
|
3802 |
// Obtain lock on the iDefConnection
|
|
3803 |
iDefConnLock.Wait();
|
|
3804 |
if(iDefConnection.SubSessionHandle() != 0)
|
|
3805 |
iDefConnection.Close();
|
|
3806 |
if( iDefConnPref )
|
|
3807 |
{
|
|
3808 |
switch( iDefConnPref->ExtensionId() )
|
|
3809 |
{
|
|
3810 |
case TConnPref::EConnPrefSnap:
|
|
3811 |
{
|
|
3812 |
RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
|
|
3813 |
delete (TCommSnapPref*)iDefConnPref;
|
|
3814 |
// Switch back to old heap
|
|
3815 |
User::SwitchHeap(oldHeap);
|
|
3816 |
iDefConnPref = NULL;
|
|
3817 |
}
|
|
3818 |
break;
|
|
3819 |
|
|
3820 |
case TConnPref::EConnPrefCommDb:
|
|
3821 |
{
|
|
3822 |
RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
|
|
3823 |
delete (TCommDbConnPref*)iDefConnPref;
|
|
3824 |
// Switch back to old heap
|
|
3825 |
User::SwitchHeap(oldHeap);
|
|
3826 |
iDefConnPref = NULL;
|
|
3827 |
}
|
|
3828 |
break;
|
|
3829 |
|
|
3830 |
default:
|
|
3831 |
{
|
|
3832 |
iDefConnLock.Signal();
|
|
3833 |
// Unknown type of Connection Pref
|
|
3834 |
return KErrUnknown;
|
|
3835 |
}
|
|
3836 |
}
|
|
3837 |
}
|
|
3838 |
// Release lock on the iDefConnection
|
|
3839 |
iDefConnLock.Signal();
|
|
3840 |
return KErrNone;
|
|
3841 |
}
|
|
3842 |
|
|
3843 |
TPtrC8 namePtr((TText8*)aIfReq->ifr_name);
|
|
3844 |
TBuf<KCommsDbSvrMaxColumnNameLength> name;
|
|
3845 |
TInt err = CnvUtfConverter::ConvertToUnicodeFromUtf8(name,namePtr);
|
|
3846 |
if( err != KErrNone )
|
|
3847 |
return err;
|
|
3848 |
|
|
3849 |
if( iDefConnPref )
|
|
3850 |
{
|
|
3851 |
switch( iDefConnPref->ExtensionId() )
|
|
3852 |
{
|
|
3853 |
case TConnPref::EConnPrefSnap:
|
|
3854 |
{
|
|
3855 |
RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
|
|
3856 |
delete (TCommSnapPref*)iDefConnPref;
|
|
3857 |
// Switch back to old heap
|
|
3858 |
User::SwitchHeap(oldHeap);
|
|
3859 |
iDefConnPref = NULL;
|
|
3860 |
}
|
|
3861 |
break;
|
|
3862 |
|
|
3863 |
case TConnPref::EConnPrefCommDb:
|
|
3864 |
{
|
|
3865 |
RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
|
|
3866 |
delete (TCommDbConnPref*)iDefConnPref;
|
|
3867 |
// Switch back to old heap
|
|
3868 |
User::SwitchHeap(oldHeap);
|
|
3869 |
iDefConnPref = NULL;
|
|
3870 |
}
|
|
3871 |
break;
|
|
3872 |
|
|
3873 |
default:
|
|
3874 |
{
|
|
3875 |
// Unknown type of Connection Pref
|
|
3876 |
return KErrUnknown;
|
|
3877 |
}
|
|
3878 |
}
|
|
3879 |
}
|
|
3880 |
|
|
3881 |
// If the interface name is an empty string, the SNAP id is to be set
|
|
3882 |
if(name.Length() == 0)
|
|
3883 |
{
|
|
3884 |
// Switch to backend heap
|
|
3885 |
RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
|
|
3886 |
iDefConnPref = new TCommSnapPref;
|
|
3887 |
// Switch back to old heap
|
|
3888 |
User::SwitchHeap(oldHeap);
|
|
3889 |
if( iDefConnPref == NULL )
|
|
3890 |
{
|
|
3891 |
return KErrNoMemory;
|
|
3892 |
}
|
|
3893 |
TCommSnapPref* snapprefptr = (TCommSnapPref*)iDefConnPref;
|
|
3894 |
snapprefptr->SetSnap(aIfReq->ifr_ifru.snap_id);
|
|
3895 |
return KErrNone;
|
|
3896 |
}
|
|
3897 |
else //Set the IAP name
|
|
3898 |
{
|
|
3899 |
CTrapCleanup *cleanupStack = NULL;
|
|
3900 |
//Create a clean up stack if it is not existing.
|
|
3901 |
if(User::TrapHandler() == NULL)
|
|
3902 |
{
|
|
3903 |
cleanupStack = CTrapCleanup::New(); //This will be deleted after use
|
|
3904 |
if(cleanupStack == NULL)
|
|
3905 |
return KErrNoMemory;
|
|
3906 |
}
|
|
3907 |
|
|
3908 |
// Switch to backend heap
|
|
3909 |
RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
|
|
3910 |
iDefConnPref = new TCommDbConnPref;
|
|
3911 |
// Switch back to old heap
|
|
3912 |
User::SwitchHeap(oldHeap);
|
|
3913 |
if( iDefConnPref == NULL )
|
|
3914 |
{
|
|
3915 |
if( cleanupStack != NULL )
|
|
3916 |
delete cleanupStack;
|
|
3917 |
return KErrNoMemory;
|
|
3918 |
}
|
|
3919 |
TRAP(err, (err = GetConnectionPreferencesL(name,*(TCommDbConnPref*)iDefConnPref)))
|
|
3920 |
|
|
3921 |
if( cleanupStack != NULL )
|
|
3922 |
delete cleanupStack;
|
|
3923 |
|
|
3924 |
return err;
|
|
3925 |
}
|
|
3926 |
}
|
|
3927 |
|
|
3928 |
// -----------------------------------------------------------------------------
|
|
3929 |
// CLocalSystemInterface::GetDefaultConnection
|
|
3930 |
//
|
|
3931 |
// Function to get the default connection instance from backend.
|
|
3932 |
// The caller should check the handle before using the instance.
|
|
3933 |
// -----------------------------------------------------------------------------
|
|
3934 |
//
|
|
3935 |
RConnection& CLocalSystemInterface::GetDefaultConnection()
|
|
3936 |
{
|
|
3937 |
// If GetDefaultConnection is called without calling
|
|
3938 |
// setdefaultif then the connection is not started
|
|
3939 |
// Obtain lock on the iDefConnection
|
|
3940 |
iDefConnLock.Wait();
|
|
3941 |
if(iDefConnection.SubSessionHandle() == 0)
|
|
3942 |
{
|
|
3943 |
// iDefConnPref should not be NULL for starting the connection
|
|
3944 |
if( iDefConnPref )
|
|
3945 |
{
|
|
3946 |
StartDefConnection();
|
|
3947 |
}
|
|
3948 |
}
|
|
3949 |
// Release lock on the iDefConnection
|
|
3950 |
iDefConnLock.Signal();
|
|
3951 |
return iDefConnection;
|
|
3952 |
}
|
|
3953 |
|
|
3954 |
// -----------------------------------------------------------------------------
|
|
3955 |
// CLocalSystemInterface::GetSessionPath
|
|
3956 |
//
|
|
3957 |
// Retrieves the cached session path from the backend
|
|
3958 |
// -----------------------------------------------------------------------------
|
|
3959 |
//
|
|
3960 |
TInt CLocalSystemInterface::GetSessionPath(TDes& aPath)
|
|
3961 |
{
|
|
3962 |
if(aPath.MaxLength() < iSessionPath.Length())
|
|
3963 |
return KErrArgument;
|
|
3964 |
|
|
3965 |
iSessionPathLock.Wait();
|
|
3966 |
aPath.Copy(iSessionPath);
|
|
3967 |
iSessionPathLock.Signal();
|
|
3968 |
return KErrNone;
|
|
3969 |
}
|
|
3970 |
|
|
3971 |
// -----------------------------------------------------------------------------
|
|
3972 |
// CLocalSystemInterface::SaveSessionPath
|
|
3973 |
//
|
|
3974 |
// Caches the session path in the backend
|
|
3975 |
// -----------------------------------------------------------------------------
|
|
3976 |
//
|
|
3977 |
TInt CLocalSystemInterface::SaveSessionPath(const TDesC& aPath)
|
|
3978 |
{
|
|
3979 |
if(aPath.Length() > KMaxFileName)
|
|
3980 |
return KErrArgument;
|
|
3981 |
|
|
3982 |
iSessionPathLock.Wait();
|
|
3983 |
iSessionPath.Copy(aPath);
|
|
3984 |
iSessionPathLock.Signal();
|
|
3985 |
|
|
3986 |
return KErrNone;
|
|
3987 |
}
|
|
3988 |
// -----------------------------------------------------------------------------
|
|
3989 |
// handleASelect(TAny* aPtr);
|
|
3990 |
// This function is called to handle aselect, aselect is implemented by
|
|
3991 |
// running select on a different thread, this function is the thread function
|
|
3992 |
// that is used for implementing aselect
|
|
3993 |
// -----------------------------------------------------------------------------
|
|
3994 |
//
|
|
3995 |
TInt CLocalSystemInterface::handleaselect(TAny* aPtr)
|
|
3996 |
{
|
|
3997 |
int errval;
|
|
3998 |
// Call select, when it returns signal the TRequestStatus
|
|
3999 |
// Extract request info
|
|
4000 |
TaselectRequestInfo *requestInfo = (TaselectRequestInfo *)aPtr;
|
|
4001 |
RArray<TASelectRequest>& selectRequest = Backend()->ASelectRequest();
|
|
4002 |
RFastLock& selectLock = Backend()->ASelectLock();
|
|
4003 |
// Call select
|
|
4004 |
TInt nDesReady = Backend()->select(requestInfo->iMaxFd, requestInfo->iReadFds,requestInfo->iWriteFds,requestInfo->iExceptFds, requestInfo->itvptr,errval);
|
|
4005 |
// Open the main thread, this is required to signal it after processing
|
|
4006 |
RThread mainThread;
|
|
4007 |
TInt err = mainThread.Open(requestInfo->iId,EOwnerProcess);
|
|
4008 |
if( err == KErrNone )
|
|
4009 |
{
|
|
4010 |
for ( TInt i=0; i<selectRequest.Count(); i++ )
|
|
4011 |
{
|
|
4012 |
if( selectRequest[i].iRequestStatus == requestInfo->iRequestStatus )
|
|
4013 |
{
|
|
4014 |
// Acquire a lock on the iSelectRequest object
|
|
4015 |
selectLock.Wait();
|
|
4016 |
// Switch to backend heap
|
|
4017 |
RHeap* oldHeap = User::SwitchHeap(Backend()->Heap());
|
|
4018 |
selectRequest.Remove(i);
|
|
4019 |
// Switch back to old heap
|
|
4020 |
User::SwitchHeap(oldHeap);
|
|
4021 |
// Release the lock
|
|
4022 |
selectLock.Signal();
|
|
4023 |
break;
|
|
4024 |
}
|
|
4025 |
}
|
|
4026 |
// Check if select has failed
|
|
4027 |
if( nDesReady == -1 )
|
|
4028 |
{
|
|
4029 |
// There is an error, we need to propogate the errno
|
|
4030 |
// Convert errno to negative value
|
|
4031 |
errval = errval * -1;
|
|
4032 |
mainThread.RequestComplete(requestInfo->iRequestStatus,errval);
|
|
4033 |
}
|
|
4034 |
else
|
|
4035 |
{
|
|
4036 |
// Complete the request on the main thread and the TRequestStatus specified
|
|
4037 |
// in the requestInfo
|
|
4038 |
mainThread.RequestComplete(requestInfo->iRequestStatus,nDesReady);
|
|
4039 |
}
|
|
4040 |
mainThread.Close();
|
|
4041 |
}
|
|
4042 |
// Release the memory used for the TASelectRequestInfo
|
|
4043 |
Backend()->Free(aPtr);
|
|
4044 |
return KErrNone;
|
|
4045 |
}
|
|
4046 |
|
|
4047 |
// -----------------------------------------------------------------------------
|
|
4048 |
// CLocalSystemInterface::CreateASelectThread
|
|
4049 |
// -----------------------------------------------------------------------------
|
|
4050 |
//
|
|
4051 |
TInt CLocalSystemInterface::CreateaselectThread(int maxfd, fd_set* readfds, fd_set* writefds,
|
|
4052 |
fd_set* exceptfds, struct timeval* tvptr,
|
|
4053 |
TRequestStatus* requeststatus, int& anErrno)
|
|
4054 |
{
|
|
4055 |
// Create a aselect request holder, this will be destroyed by the new thread#
|
|
4056 |
// after processing
|
|
4057 |
TaselectRequestInfo *requestInfo = (TaselectRequestInfo* )Backend()->Alloc(sizeof(TaselectRequestInfo));
|
|
4058 |
// request info will be null if dynamic creation fails
|
|
4059 |
if( !requestInfo )
|
|
4060 |
{
|
|
4061 |
anErrno = ENOMEM;
|
|
4062 |
return -1;
|
|
4063 |
}
|
|
4064 |
// Set the aselect request parameters
|
|
4065 |
RThread currentThread;
|
|
4066 |
requestInfo->iId = currentThread.Id();
|
|
4067 |
currentThread.Close();
|
|
4068 |
// Fill the request struct
|
|
4069 |
requestInfo->iMaxFd = maxfd;
|
|
4070 |
requestInfo->iReadFds = readfds;
|
|
4071 |
requestInfo->iWriteFds = writefds;
|
|
4072 |
requestInfo->iExceptFds = exceptfds;
|
|
4073 |
requestInfo->itvptr = tvptr;
|
|
4074 |
requestInfo->iRequestStatus = requeststatus;
|
|
4075 |
*(requestInfo->iRequestStatus) = KRequestPending;
|
|
4076 |
RThread thread;
|
|
4077 |
// We create an anonymous thread
|
|
4078 |
TInt err = thread.Create(KNullDesC, CLocalSystemInterface::handleaselect, 4096, KMinHeapSize,
|
|
4079 |
256*KMinHeapSize, requestInfo);
|
|
4080 |
if ( err != KErrNone )
|
|
4081 |
{
|
|
4082 |
anErrno = ENOMEM;
|
|
4083 |
return -1;
|
|
4084 |
}
|
|
4085 |
|
|
4086 |
// Create a aselect request object
|
|
4087 |
TASelectRequest aselectrequest;
|
|
4088 |
// retrive the service thread handle
|
|
4089 |
aselectrequest.iThreadId = thread.Id();
|
|
4090 |
// Store the TRequestStatus used for the request
|
|
4091 |
aselectrequest.iRequestStatus = requeststatus;
|
|
4092 |
// Obtain the lock
|
|
4093 |
iASelectLock.Wait();
|
|
4094 |
// Switch to backend heap
|
|
4095 |
RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
|
|
4096 |
// Append to the array
|
|
4097 |
iASelectRequest.Append(aselectrequest);
|
|
4098 |
// Switch back to old heap
|
|
4099 |
User::SwitchHeap(oldHeap);
|
|
4100 |
// Release the lock
|
|
4101 |
iASelectLock.Signal();
|
|
4102 |
// Execute the thread
|
|
4103 |
thread.Resume();
|
|
4104 |
// Close the handle
|
|
4105 |
thread.Close();
|
|
4106 |
return MapError(KErrNone, anErrno);
|
|
4107 |
}
|
|
4108 |
|