App access to /tmp

Hiya,

Is it possible for an app to get read and write access to the /tmp directory to store intermediate and volatile data files?

I’ve tried require:'ing the /tmp directory into my app in the adef file - both as sandboxed and unsandboxed.

I’ve also tried simply creating a file in /tmp as an unsandboxed application.

Nether method wrote to the system /tmp directory - they all seemed to create a tmp directory in the application’s /legato/…/appWritable/application/ directory (same place as bin, dev, lib etc are created.

Questions:

  1. is it possible for an app to write to the system /tmp area? If so, how?
  2. I can’t use the legato created tmp directory as it goes away if the application stops and restarts. Is there any other volatile file storage on the module that an app can write to?

ciao, Dave

Hi Dave,

May I ask which Legato/product you are using?

In my case, I can read/write to /tmp/test.txt whenever app is not run inside sandbox, as expected I don’t even need to specify in requires section.

Thx

Hi Lotam,

I’ve been testing against a WP7702 with Legato 18.05.1 installed.

I was also somewhat confused about not being able to write to /tmp in an unsandboxed app.

Quite literally, all my code does is the following:

#include "legato.h"
#include "interfaces.h"	/* include auto-generated api interfaces from Component.cdef */


COMPONENT_INIT
{
    LE_INFO( "tmpDirTest Init: Enter" );

    char template[128] = { 0 };
    int fd = -1;
    
    sprintf(template, "/tmp/mytmpXXXXXX");
    
    if ( -1 == (fd = mkstemp(template)) )
    {
        LE_WARN("mkstemp failed [%d:%m]", errno );
    }
    else
    {
        LE_INFO( "Opened [%s] as fd[%d]", template, fd );
        
        close( fd );
    }

    LE_INFO( "tmpDirTest Init: Exit" );
    
}

Can’t be much simpler than this …

But unsandboxed or not, it never creates the file in /tmp … but only in the app local tmp folder.

ciao, Dave

Hi Dave,

Thanks for the code snippet.
It works quite well on my WP77 18.05.1 as I marked “sandboxed: false” in .adef.

Below the .adef and test log:

executables:
{
helloWorld = ( helloComponent )
}

processes:
{
envVars:
{
LE_LOG_LEVEL = DEBUG
}

run:
{
    ( helloWorld )
}

}
sandboxed: false
start: manual

Test log:

root@swi-mdm9x28:~# legato version
18.05.1_aad562713e05df40ebc4a49c57fa8e97
root@swi-mdm9x28:~# ls -l /tmp/
drwx-----x 2 root root 120 Jan 6 00:37 legato
drwx------ 2 root root 80 Jan 6 00:37 pkgdwl
drw-r–r-- 2 root root 60 Jan 6 00:37 psm_socket
srwx------ 1 root root 0 Jan 6 00:37 sock0
srwxr-xr-x 1 root root 0 Jan 6 00:37 thermal_engi_ipc
root@swi-mdm9x28:~# logread -f &
root@swi-mdm9x28:~# app start helloWorld
root@swi-mdm9x28:~# Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | supervisor[699]/supervisor T=main | app.c app_Create() 2716 | Creating app ‘helloWorld’
Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | supervisor[699]/supervisor T=main | proc.c GetFaultAction() 323 | No fault action specified for process ‘helloWorld’. Assuming ‘ignore’.
Jan 6 00:39:25 swi-mdm9x28 user.warn Legato: -WRN- | supervisor[699]/supervisor T=main | proc.c GetWatchdogAction() 359 | helloWorld watchdogAction ‘’ in proc section
Jan 6 00:39:25 swi-mdm9x28 user.warn Legato: -WRN- | supervisor[699]/supervisor T=main | proc.c GetWatchdogAction() 359 | helloWorld watchdogAction ‘’ in proc section
Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | supervisor[699]/supervisor T=main | app.c CreateFileLink() 1605 | Created file link ‘/legato/systems/current/apps/helloWorld/read-only/lib/libComponent_helloComponent.so’ to '/legato/systems/current/appsWriteable/helloW
Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | supervisor[699]/supervisor T=main | app.c CreateFileLink() 1605 | Created file link ‘/legato/systems/current/apps/helloWorld/read-only/bin/helloWorld’ to ‘/legato/systems/current/appsWriteable/helloWorld/bin/helloWorld’
Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | supervisor[699]/supervisor T=main | app.c app_Start() 2915 | Starting app ‘helloWorld’
Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | supervisor[699]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxCoreDumpFileBytes to value 102400.
Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | supervisor[699]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxFileBytes to value 102400.
Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | supervisor[699]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxLockedMemoryBytes to value 8192.
Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | supervisor[699]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxFileDescriptors to value 256.
Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | supervisor[699]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxMQueueBytes to value 512.
Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | supervisor[699]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxThreads to value 20.
Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | supervisor[699]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxQueuedSignals to value 100.
Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | supervisor[699]/supervisor T=main | proc.c proc_Start() 1389 | Starting process ‘helloWorld’ with pid 1701
Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | supervisor[699]/supervisor T=main | supervisor.c SigChildHandler() 783 | Reaping unconfigured child process 1700.
Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | supervisor[1701]/supervisor T=main | proc.c proc_Start() 1354 | Execing ‘helloWorld’
Jan 6 00:39:25 swi-mdm9x28 user.debug Legato: DBUG | UNKNOWN[1701]/framework T=unknown | LE_FILENAME InitPool() 303 | Memory pool name ‘framework.hashMap_refPathIteratorMap’ is truncated to ‘framework.hashMap_refPathIterat’
Jan 6 00:39:25 swi-mdm9x28 user.debug Legato: DBUG | UNKNOWN[1701]/framework T=main | LE_FILENAME InitPool() 303 | Memory pool name ‘framework.hashMap_refEventHandlers’ is truncated to ‘framework.hashMap_refEventHandl’
Jan 6 00:39:25 swi-mdm9x28 user.debug Legato: DBUG | UNKNOWN[1701]/framework T=main | LE_FILENAME InitPool() 303 | Memory pool name ‘framework.hashMap_refDefault Timer SafeRe’ is truncated to ‘framework.hashMap_refDefault Ti’
Jan 6 00:39:25 swi-mdm9x28 user.debug Legato: DBUG | UNKNOWN[1701]/framework T=main | LE_FILENAME InitPool() 303 | Memory pool name ‘framework.MessagingClientInterfaces’ is truncated to ‘framework.MessagingClientInterf’
Jan 6 00:39:25 swi-mdm9x28 user.debug Legato: DBUG | UNKNOWN[1701]/framework T=main | LE_FILENAME InitPool() 303 | Memory pool name ‘framework.hashMap_refHandlersRef’ is truncated to ‘framework.hashMap_refHandlersRe’
Jan 6 00:39:25 swi-mdm9x28 user.debug Legato: DBUG | UNKNOWN[1701]/framework T=main | LE_FILENAME InitPool() 303 | Memory pool name ‘framework.hashMap_MessagingServices’ is truncated to ‘framework.hashMap_MessagingServ’
Jan 6 00:39:25 swi-mdm9x28 user.debug Legato: DBUG | UNKNOWN[1701]/framework T=main | LE_FILENAME InitPool() 303 | Memory pool name ‘framework.hashMap_MessagingClients’ is truncated to ‘framework.hashMap_MessagingClie’
Jan 6 00:39:25 swi-mdm9x28 user.debug Legato: DBUG | UNKNOWN[1701]/framework T=main | LE_FILENAME InitPool() 303 | Memory pool name ‘framework.PipelineSIGCHLD-reports’ is truncated to ‘framework.PipelineSIGCHLD-repor’
Jan 6 00:39:25 swi-mdm9x28 user.debug Legato: DBUG | UNKNOWN[1701]/framework T=main | LE_FILENAME fs_Init() 838 | FS prefix path “/data/le_fs/”
Jan 6 00:39:25 swi-mdm9x28 user.debug Legato: DBUG | UNKNOWN[1701]/framework T=main | LE_FILENAME InitPool() 303 | Memory pool name ‘framework.hashMap_refFsFileRefMap’ is truncated to ‘framework.hashMap_refFsFileRefM’
Jan 6 00:39:25 swi-mdm9x28 user.debug Legato: DBUG | UNKNOWN[1701]/framework T=main | LE_FILENAME le_mem_ForceAlloc() 841 | Memory pool ‘framework.DestructorObjs’ overflowed. Expanded to 1 blocks.
Jan 6 00:39:25 swi-mdm9x28 user.debug Legato: DBUG | UNKNOWN[1701]/ T=main | _componentMain.c _helloComponent_Init() 26 | Initializing helloComponent component library.
Jan 6 00:39:25 swi-mdm9x28 user.debug Legato: DBUG | helloWorld[1701]/framework T=main | LE_FILENAME InitPool() 303 | Memory pool name ‘framework.msgs-LogControlProtocol’ is truncated to ‘framework.msgs-LogControlProtoc’
Jan 6 00:39:25 swi-mdm9x28 user.debug Legato: DBUG | helloWorld[1701]/framework T=main | LE_FILENAME le_mem_ForceAlloc() 841 | Memory pool ‘framework.SigMonitor’ overflowed. Expanded to 1 blocks.
Jan 6 00:39:25 swi-mdm9x28 user.debug Legato: DBUG | helloWorld[1701]/framework T=main | LE_FILENAME le_mem_ForceAlloc() 841 | Memory pool ‘framework.SigHandler’ overflowed. Expanded to 1 blocks.
Jan 6 00:39:25 swi-mdm9x28 user.debug Legato: DBUG | helloWorld[1701]/helloWorld_exe T=main | _main.c main() 60 | == Starting Event Processing Loop ==
Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | helloWorld[1701]/helloComponent T=main | helloWorld.c _helloComponent_COMPONENT_INIT() 7 | tmpDirTest Init: Enter
Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | helloWorld[1701]/helloComponent T=main | helloWorld.c _helloComponent_COMPONENT_INIT() 20 | Opened [/tmp/mytmpkvmjRv] as fd[8]
Jan 6 00:39:25 swi-mdm9x28 user.info Legato: INFO | helloWorld[1701]/helloComponent T=main | helloWorld.c _helloComponent_COMPONENT_INIT() 25 | tmpDirTest Init: Exit

root@swi-mdm9x28:~# ls -l /tmp
drwx-----x 2 root root 120 Jan 6 00:37 legato
-rw------- 1 root root 0 Jan 6 00:39 mytmpkvmjRv
drwx------ 2 root root 80 Jan 6 00:37 pkgdwl
drw-r–r-- 2 root root 60 Jan 6 00:37 psm_socket
srwx------ 1 root root 0 Jan 6 00:37 sock0
srwxr-xr-x 1 root root 0 Jan 6 00:37 thermal_engi_ipc
-rw-r–r-- 1 root root 534 Jan 6 00:39 tmpfdbtable.txt
root@swi-mdm9x28:~#