genericopenlibs/openenvcore/backend/src/corebackend/localif.cpp
changeset 18 47c74d1534e1
parent 0 e4d67989cc36
child 22 ddc455616bd6
equal deleted inserted replaced
0:e4d67989cc36 18:47c74d1534e1
    29 #include <sys/un.h>
    29 #include <sys/un.h>
    30 #include "sysif.h"
    30 #include "sysif.h"
    31 #include "fdesc.h"
    31 #include "fdesc.h"
    32 #include "ltime.h"
    32 #include "ltime.h"
    33 #include "lposix.h"
    33 #include "lposix.h"
       
    34 #include "systemspecialfilercg.h"
       
    35 #include "link.h"
    34 #ifdef SYMBIAN_OE_POSIX_SIGNALS
    36 #ifdef SYMBIAN_OE_POSIX_SIGNALS
    35 #include <stdlib.h>
    37 #include <stdlib.h>
    36 #include <signal.h>
    38 #include <signal.h>
    37 #include "tsignalmessage.h"
    39 #include "tsignalmessage.h"
    38 #endif // SYMBIAN_OE_POSIX_SIGNALS
    40 #endif // SYMBIAN_OE_POSIX_SIGNALS
   163 			err |=  iASelectLock.CreateLocal();
   165 			err |=  iASelectLock.CreateLocal();
   164 	        //Protect the iDefConnection from concurrent GetDefaultConnection calls
   166 	        //Protect the iDefConnection from concurrent GetDefaultConnection calls
   165 	        err |= iDefConnLock.CreateLocal();
   167 	        err |= iDefConnLock.CreateLocal();
   166 			}
   168 			}
   167 
   169 
       
   170         if(err == KErrNone)
       
   171             {
       
   172             err = iTzServer.Connect();
       
   173             if(!err)
       
   174                 {
       
   175                 err = iTzServer.ShareAuto();
       
   176                 }
       
   177             }
       
   178 
       
   179 
   168 		//Panic if any of the above operation returns with error
   180 		//Panic if any of the above operation returns with error
   169 		if (err)
   181 		if (err)
   170 			{
   182 			{
   171 			User::Panic(KEstlibInit, err);
   183 			User::Panic(KEstlibInit, err);
   172 			}
   184 			}
   173 
   185 
   174 		iCleanup.StorePtrs(iPrivateHeap, &iFs, &iSs, &iCs, &iSSLock, &iCSLock);
   186 		iCleanup.StorePtrs(iPrivateHeap, &iFs, &iSs, &iCs, &iSSLock, &iCSLock, &iTzServer);
   175 		
   187 		
   176 		// No connection settings by default
   188 		// No connection settings by default
   177 		iDefConnPref = NULL;
   189 		iDefConnPref = NULL;
   178 		}
   190 		}
   179 
   191 
   284 // -----------------------------------------------------------------------------
   296 // -----------------------------------------------------------------------------
   285 //
   297 //
   286 void CLocalSystemInterface::Exit(int code)
   298 void CLocalSystemInterface::Exit(int code)
   287 	{
   299 	{
   288 #ifdef SYMBIAN_OE_POSIX_SIGNALS
   300 #ifdef SYMBIAN_OE_POSIX_SIGNALS
       
   301     TRequestStatus status = KRequestPending;
       
   302     iSignalHandlerThread.Logon(status);
   289 	iSignalLoopRunning = EFalse;
   303 	iSignalLoopRunning = EFalse;
       
   304 	iSignalHandlerThread.RequestSignal();
       
   305 	User::WaitForRequest(status);
   290 #endif
   306 #endif
   291 
       
   292 	iFids.Close();
   307 	iFids.Close();
   293 	User::SetCritical(User::EProcessPermanent);
   308 	User::SetCritical(User::EProcessPermanent);
   294 	User::Exit(code);
   309 	User::Exit(code);
   295 	}
   310 	}
   296 
   311 
   315 	{
   330 	{
   316 	return PosixFilesystem::mkdir(iFs, aPath, perms, anErrno);
   331 	return PosixFilesystem::mkdir(iFs, aPath, perms, anErrno);
   317 	}
   332 	}
   318 
   333 
   319 int CLocalSystemInterface::stat (const wchar_t* name, struct stat *st, int& anErrno)
   334 int CLocalSystemInterface::stat (const wchar_t* name, struct stat *st, int& anErrno)
   320 	{
   335     {
   321 	return PosixFilesystem::stat(iFs, name, st, anErrno);
   336     const wchar_t* filename;
   322 	}
   337     // This needs to be zero terminated
       
   338     TBuf<KMaxFileName> inputName;
       
   339     TUint pathAtt = 0;
       
   340     TInt err = GetFullFile(inputName,(const TText16*)name,iFs);
       
   341     if( !err )
       
   342         {
       
   343         TInt err = iFs.Att(inputName,pathAtt);
       
   344         if ( (err == KErrNone) && (pathAtt & KEntryAttDir) )
       
   345             {                    
       
   346             inputName.Append(_L("\\"));            
       
   347             }
       
   348         filename = (wchar_t*)inputName.PtrZ();
       
   349         }
       
   350     // try to stat anyway
       
   351     else
       
   352         {
       
   353         inputName.Copy((const TText16*)name);
       
   354         filename = (wchar_t*)inputName.PtrZ();
       
   355         }
       
   356     TSpecialFileType fileType;
       
   357     struct SLinkInfo enBuf;
       
   358     // Check the type of file
       
   359     fileType = _SystemSpecialFileBasedFilePath(filename, err, iFs);
       
   360     // If it is a symbolic link, follow the link
       
   361     // If _SystemSpecialFileBasedFilePath fails, treat it as normal file
       
   362     // and try to proceed
       
   363     if( fileType == EFileTypeSymLink && err == KErrNone )
       
   364         {
       
   365         err = _ReadSysSplFile(filename, (char*)&enBuf, sizeof(struct SLinkInfo), anErrno, iFs);
       
   366         if (err == KErrNone)
       
   367             {
       
   368             filename = (wchar_t*)enBuf.iParentPath;
       
   369             }
       
   370         else
       
   371             {
       
   372             // errno is already set by _ReadSysSplFile
       
   373             return -1;
       
   374             }
       
   375         }
       
   376     else if ( fileType != EFileGeneralError && err != KErrNone )
       
   377         {
       
   378         return MapError(err,anErrno);
       
   379         }
       
   380     return PosixFilesystem::statbackend(iFs, filename, st, anErrno);
       
   381     }
       
   382 
       
   383 int CLocalSystemInterface::lstat (const wchar_t* name, struct stat *st, int& anErrno)
       
   384     {
       
   385     return PosixFilesystem::statbackend(iFs, name, st, anErrno);
       
   386     }
   323 
   387 
   324 int CLocalSystemInterface::utime (const wchar_t* name, const struct utimbuf *filetimes, int& anErrno)
   388 int CLocalSystemInterface::utime (const wchar_t* name, const struct utimbuf *filetimes, int& anErrno)
   325 	{
   389 	{
   326 	return PosixFilesystem::utime(iFs, name, filetimes, anErrno);
   390 	return PosixFilesystem::utime(iFs, name, filetimes, anErrno);
   327 	}
   391 	}
   528 	if(lRetVal != KErrNone)
   592 	if(lRetVal != KErrNone)
   529 		{
   593 		{
   530 		iSignalInitSemaphore.Signal();
   594 		iSignalInitSemaphore.Signal();
   531 		return lRetVal;
   595 		return lRetVal;
   532 		}
   596 		}
   533 
   597 	
       
   598 	/* Closing the end of the pipe that's been sent to the server */
       
   599 	iSignalWritePipe.Close();
       
   600 	
   534 	iSignalsInitialized = ETrue;
   601 	iSignalsInitialized = ETrue;
   535 	iSignalInitSemaphore.Signal();
   602 	iSignalInitSemaphore.Signal();
   536 	iSignalLoopRunning = ETrue;
   603 	iSignalLoopRunning = ETrue;
   537 	iPipeReadStatus = KRequestPending;
   604 	iPipeReadStatus = KRequestPending;
   538 	iSignalReadPipe.NotifyDataAvailable(iPipeReadStatus);
   605 	iSignalReadPipe.NotifyDataAvailable(iPipeReadStatus);
   539 	while(iSignalLoopRunning)
   606 	while(iSignalLoopRunning)
   540 		{
   607 		{
   541 		User::WaitForAnyRequest();
   608 		User::WaitForAnyRequest();
       
   609 		if(iSignalLoopRunning == false) {
       
   610             break;
       
   611 		}
   542 		// Check if it is a pipe read
   612 		// Check if it is a pipe read
   543 		if(iPipeReadStatus != KRequestPending)
   613 		if(iPipeReadStatus != KRequestPending)
   544 			{
   614 			{
   545 			if(iPipeReadStatus == KErrNone)
   615 			if(iPipeReadStatus == KErrNone)
   546 				{
   616 				{
   695 		}
   765 		}
   696 	if(iPipeReadStatus == KRequestPending)
   766 	if(iPipeReadStatus == KRequestPending)
   697 		{
   767 		{
   698 		iSignalReadPipe.CancelDataAvailable();
   768 		iSignalReadPipe.CancelDataAvailable();
   699 		}
   769 		}
       
   770 	iSignalReadPipe.Close();
       
   771 	
   700 	if(iAlarmStatus == KRequestPending)
   772 	if(iAlarmStatus == KRequestPending)
   701 		{
   773 		{
   702 		iAlarmTimer.Cancel();
   774 		iAlarmTimer.Cancel();
   703 		}
   775 		}
   704 	TInt lCounterIdx = 0;
   776 	TInt lCounterIdx = 0;
   708 			{
   780 			{
   709 			RProcess lProcess;
   781 			RProcess lProcess;
   710 			if(lProcess.Open(TProcessId(iChildWaiterArray[lCounterIdx].iWaiterPid)) == KErrNone)
   782 			if(lProcess.Open(TProcessId(iChildWaiterArray[lCounterIdx].iWaiterPid)) == KErrNone)
   711 				{
   783 				{
   712 				lProcess.LogonCancel(iChildWaiterArray[lCounterIdx].iWaiterStatus);
   784 				lProcess.LogonCancel(iChildWaiterArray[lCounterIdx].iWaiterStatus);
   713 				}
   785 				lProcess.Close();
   714 			}
   786 				}
   715 		}
   787 			}
   716 
   788 		}                                                                             
       
   789 	iSignalSession.Close();
   717 	return KErrNone;
   790 	return KErrNone;
   718 	}
   791 	}
   719 
   792 
   720 static TInt sSignalHandler(TAny* aData)
   793 static TInt sSignalHandler(TAny* aData)
   721 	{
   794 	{
  1598 			err=status.Int();
  1671 			err=status.Int();
  1599 			if (!err)
  1672 			if (!err)
  1600 				{
  1673 				{
  1601 				err=iFids.Attach(fd,newf);
  1674 				err=iFids.Attach(fd,newf);
  1602 				if (!err)
  1675 				if (!err)
  1603 					return fd;
  1676 					return fd;				
  1604 				delete newf;
  1677 				newf->Close();
  1605 				}
  1678 				}
  1606 			else if(newf != NULL)
  1679 			else if(newf != NULL)
  1607 				{
  1680 				{
  1608 				//coverity[leave_without_push]
  1681 				//coverity[leave_without_push]
  1609 				delete newf;
  1682 				newf->Close();
  1610 				}
  1683 				}
  1611 			iFids.Attach(fd,0);	// cancel the reservation
  1684 			iFids.Attach(fd,0);	// cancel the reservation
  1612 			}
  1685 			}
  1613 		//coverity[memory_leak]
  1686 		//coverity[memory_leak]
  1614 		}
  1687 		}