Writing to external file from app

I am trying to write some data from an app to an external file.

I found this thread and post, but not sure what I am doing wrong…

Here is code…

static void Testle_pos_GetInfo
(
    void
)
{
    int32_t           latitude;
    int32_t           longitude;
    int32_t           altitude;
    int32_t           hAccuracy;
    int32_t           vAccuracy;
    uint16_t          year = 0;
    uint16_t          month = 0;
    uint16_t          day = 0;

    char *filename = "/home/root/myapp/gpsloc.txt";

    le_pos_FixState_t fixState;
    le_result_t       res;

     FILE *fp = fopen(filename,"w");

     if (fp == NULL)
      {        
          printf("Error opening the file %s", filename);
        //return -1;
      }
     
      fprintf(fp, "This is a test");
      fclose(fp);

    

    LE_ASSERT_OK(le_pos_GetFixState(&fixState));

I added this to the bottom of the adef file.

requires:
{
    dir:
    {
        [wx] /home/root/myapp  /home/root/
    }
}

Everything compiles and the app installs just fine.
Log output:

Jan 25 19:35:12 fx30s user.info Legato:  INFO | gpsAcquire[3963]/gpsAcquire T=main | gpsAcquire.c _gpsAcquire_COMPONENT_INIT() 66                                             9 | ======== Positioning Test started  ========
Jan 25 19:35:12 fx30s user.info Legato:  INFO | gpsAcquire[3963]/gpsAcquire T=main | gpsAcquire.c _gpsAcquire_COMPONENT_INIT() 67                                             5 | Get initial position

*************************  ERROR STARTS HERE *************************************************
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | PROCESS: 3963 ,TID 3963
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | SIGNAL: 11, ADDR (nil), AT 0xb6c832d8 SI_CODE 0x00000001
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | ILLEGAL ADDRESS (nil)
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | LEGATO VERSION
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | PROCESS COMMAND LINE
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | PROCESS MAP
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | BACKTRACE
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | PC at b6c832d8
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | LR at b6ec1dc0 [0xbee0fadc]
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | LR at b6e610a0 [0xbee0fb04]
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | LR at b6e6115c [0xbee0fb24]
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | LR at b6e42a0c [0xbee0fb3c]
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | LR at b6e621c0 [0xbee0fd5c]
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | LR at 00496d5c [0xbee0fd64]
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | LR at b6c3ebf8 [0xbee0fd8c]
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | r0  b6ee4098 r1  00000001 r2  0000000e r3  00000000 r4  0000000                                             0  r5  00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | r6  0000000e r7  00000004 r8  01d7d5d0 r9  b6e9e000 r10 004a800                                             0 cpsr 20070010
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | fp  bee0fadc ip  b6c832c4 sp  bee0fa60 lr  b6ec145c pc  b6c832d                                             8
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | STACK bee0fa60, FRAME bee0fadc
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0f9e0: 00000000 bee0fa00 00000000 06de90a5 b6ee4078 b6c31a3c                                              b6f29100 00000241
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fa00: 000001b6 00000001 00000000 00000000 01d7f798 b6ef811c                                              b6f264d0 00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fa20: 00000001 01d7d5d0 b6e9e000 004a8000 bee0fadc b6f08e80                                              b6f29588 00000001
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fa40: 00000001 00000000 00000004 b6c31a3c b6e9e000 b6ef8000                                              00000000 01d7d5d0
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fa60: b6ef8000 00000000 01d7d5d0 00000004 01d7d5d0 b6e9e000                                              004a8000 b6ec145c
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fa80: 00000000 00000000 00000000 00000000 00000001 000002a3                                              00000000 01d7d5d0
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0faa0: 00000004 01d7d5d0 0000e000 00000000 bee0fadc b6e65584                                              b6ee43e0 000002a3
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fac0: b6ee4368 bee0faec 00000000 b6ee405c 00000000 b6ef8000                                              bee0fb04 b6ec1dc0
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fae0: b6ee43e0 000002a3 b6ee4368 00000000 00000000 00000000                                              b6eaea1c b6eaea1c
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fb00: bee0fb24 b6e610a0 00000001 00000000 01d7d5d0 00000004                                              01d7d5d0 b6e9e000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fb20: bee0fb3c b6e6115c bee0fb60 bee0fb60 bee0fb50 00000004                                              bee0fd5c b6e42a0c
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fb40: 65b2b7f0 01d91f70 00000086 b6e2fa8c 00000001 bee0fbe4                                              00000000 00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fb60: aaaaaaab bee0fb74 b6d6306c 00000009 00000000 00000000                                              00000000 0000000c
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fb80: 00000023 00000013 00000019 00000000 0000007c 00000004                                              00000018 00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fba0: 00000000 b6d4b504 bee0fbc4 b6e8b24c b6e886b0 b6f268e0                                              bee0ffac 00000007
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fbc0: bee0fc18 00000001 bee0fd3c b6cf592c 00000001 bee0fbe0                                              00000000 b6e2b060
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fbe0: b6f283c8 00000001 b6f283c8 b6e2f02e b6e2a330 0000009c                                              00000000 b6f03040
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fc00: 00000001 b6e2a330 0000009c b6e2d920 b6f283c8 bee0fc5c                                              bee0fc58 bee0fc64
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fc20: 00000000 b6e2d920 b6e29970 0733f47b bee0fc58 b6e2f02e                                              b6e2a330 bee0fccc
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fc40: b6f2afa4 004e2000 aaaaaaab 01d91d0c e67e8f7b 00000009                                              00000000 00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fc60: 00000000 b6f28588 bee0fcd4 b6e2f02e bee0fccc 00000000                                              b6f283c8 e67e8f7b
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fc80: bee0fd2c b6f03b2c bee0fcd4 b6f2bad8 00000002 00000000                                              00000001 00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fca0: 00000001 b6f283c8 b6f28588 00000000 b6f2bb38 00000000                                              00000000 00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fcc0: 00000000 00000000 00000000 058dcb70 00000000 b6e2a330                                              b6f283c8 b6e2d210
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fce0: b6f283c8 00000000 00000000 00000000 00000000 b6e9e174                                              b6f264d0 00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fd00: 00000001 00000000 00000000 004a8000 bee0fd64 b6f08e80                                              00000000 00000001
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fd20: 00000001 00000000 00000001 b6e2a330 00000000 004a8000                                              00000000 00496a08
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fd40: 00000000 b6f0f3a4 01d91f70 00000000 00000001 00000000                                              bee0fd64 b6e621c0
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fd60: bee0fd8c 00496d5c 00496f78 0000003e 00496f48 00000000                                              bee0fee4 00000001
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fd80: 00000000 00496d80 00000000 b6c3ebf8 b6d61e3c bee0fee4                                              00000001 00496c64
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fda0: 6915f553 6136e373 00496d80 00000000 00496a08 00000000                                              00000000 00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fdc0: 004a8000 00000000 00000000 00000000 00000000 00000000                                              00000000 00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fde0: 00000000 00000000 00000000 00000000 00000000 00000000                                              00000000 00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fe00: 00000000 00000000 00000007 b6f29508 00000001 00000000                                              00000001 b6f2b978
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fe20: b6f2bb38 00000000 00000000 00000000 bee0feec b6e42670                                              b6ec1cc8 bee0feec
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fe40: b6eaec70 0177ff8e 00000000 b6c33cfc b6f29100 b6e60cdc                                              b6ec1cc8 00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fe60: bee0fe7c b6e62060 b6ef8000 004a8020 b6f264d0 00000000                                              00000001 00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fe80: 00000000 004a8000 00000000 b6f08e80 b6f29508 00000001                                              00000001 00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fea0: 00000000 b6c33cfc 00000000 00000000 00000000 00496a08                                              00000000 00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fec0: 00000000 00496a08 00000000 00000000 00000000 00496a4c                                              00496de4 b6f0997c
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0fee0: bee0fee4 bee0ffac 00000000 bee0ffb7 bee0ffca 00000000                                              00000021 befd4000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0ff00: 00000010 001fb0d6 00000006 00001000 00000011 00000064                                              00000003 00496034
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0ff20: 00000004 00000020 00000005 00000009 00000007 b6ef9000                                              00000008 00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0ff40: 00000009 00496a08 0000000b 00000409 0000000c 00000409                                              0000000d 00000409
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0ff60: 0000000e 00000409 00000017 00000000 00000019 bee0ff98                                              0000001a 00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0ff80: 0000001f bee0ffec 0000000f bee0ffa8 00000000 00000000                                              07ba87c1 d7f508c3
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0ffa0: 87e11c68 8060118e 006c3776 41737067 69757163 4c006572                                              4f4c5f45 454c5f47
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0ffc0: 3d4c4556 55424544 41500047 2f3d4854 2f727375 61636f6c                                              69622f6c 752f3a6e
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | bee0ffe0: 622f7273 2f3a6e69 006e6962 6e69622f 7370672f 75716341                                              00657269 00000000
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | [...]
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | Abort while dumping the stack and registers
Jan 25 13:35:12 fx30s user.err Legato: =ERR= | gpsAcquire[3963] | DONE
Jan 25 13:35:13 fx30s user.info Legato:  INFO | supervisor[1257]/supervisor T=main | proc.c proc_SigChildHandler() 2108 | Process                                              'gpsAcquire' (PID: 3963) has exited due to signal 11 (Segmentation fault).
Jan 25 13:35:13 fx30s user.info kernel: [ 1172.786173] gpsAcquire (3963) used greatest stack depth: 3908 bytes left
Jan 25 13:35:13 fx30s user.warn Legato: -WRN- | supervisor[1257]/supervisor T=main | app.c app_SigChildHandler() 4182 | Process '                                             gpsAcquire' in app 'gpsAcquire' faulted: Ignored.
Jan 25 13:35:13 fx30s user.info Legato:  INFO | supervisor[1257]/supervisor T=main | app.c app_StopComplete() 4881 | app 'gpsAcqu                                             ire' has stopped.
Jan 25 13:35:13 fx30s user.info Legato:  INFO | supervisor[1257]/supervisor T=main | apps.c DeactivateAppContainer() 374 | Applic                                             ation 'gpsAcquire' has stopped.

If I comment out all the code for opening the file, then the app runs just fine.

The post said to add that requires: block of code to the adef file, and you can access outside file, but it throws that error code from legato. I assume it is for unauthorized write request.

I also tried this solution that was posted in that thread…

root@fx30s:~/myapp# echo 2 > gpsloc.txt
root@fx30s:~/myapp# chmod o+w gpsloc.txt
root@fx30s:~/myapp# xattr set 'security.SMACK64' 'app.gpsAcquirerwx' gpsloc.txt
root@fx30s:~/myapp# xattr get gpsloc.txt
    name=security.SMACK64; value=app.gpsAcquirerwx
root@fx30s:~/myapp#

root@fx30s: app start gpsAcquire
root@fx30s:


When I try to write to file, still getting the same error as above

does it work with this hello7.rar?

I can confirm that hello7.rar did compile and download.
Then I ran the commands to listed (chmod, xattr set, xattr get, app start, cat file) and I can confirm that ‘hel’ was written to the second line of the file.

root@fx30s:/tmp# cat /tmp/hello.txt
hello_everybody
hel

I now will need to dig through hello7 to determine the differences between that code and mine and why this block does work, but mine keeps erroring out.

Thanks.

Does the file have to reside in the /tmp directory?

I was able to make your hello7 app work, but when I apply the same code in my app, I still get errors…

Jan 26 14:10:29 fx30s user.info Legato:  INFO | gpsAcquire[4068]/gpsAcquire T=main | gpsAcquire.c _gpsAcquire_COMPONENT_INIT() 727 | Get initial position
Jan 26 08:10:29 fx30s user.info Legato:  INFO | gpsAcquire[4068] |
Jan 26 08:10:29 fx30s user.info Legato:  INFO | gpsAcquire[4068] |  fopen() Error!!!
Jan 26 08:10:29 fx30s user.info Legato:  INFO | gpsAcquire[4068] |
Jan 26 08:10:29 fx30s user.info Legato:  INFO | gpsAcquire[4068] |  File opened successfully through fopen()
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | PROCESS: 4068 ,TID 4068
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | SIGNAL: 11, ADDR (nil), AT 0xb6cfa2d8 SI_CODE 0x00000001
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | ILLEGAL ADDRESS (nil)
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | LEGATO VERSION
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | PROCESS COMMAND LINE
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | PROCESS MAP
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | BACKTRACE
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | PC at b6cfa2d8
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | LR at b6f38e2c [0xbeda8adc]
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | LR at b6ed80a0 [0xbeda8b04]
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | LR at b6ed815c [0xbeda8b24]
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | LR at b6eb9a0c [0xbeda8b3c]
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | LR at b6ed91c0 [0xbeda8d5c]
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | LR at 00439d5c [0xbeda8d64]
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | LR at b6cb5bf8 [0xbeda8d8c]
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | r0  beda8a30 r1  00000001 r2  00000011 r3  00000000 r4  00000000  r5  00000000
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | r6  00000011 r7  00000004 r8  01d915d0 r9  b6f15000 r10 0044b000 cpsr 20070010
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | fp  beda8adc ip  b6cfa2c4 sp  beda89f0 lr  b6f3849c pc  b6cfa2d8
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | STACK beda89f0, FRAME beda8adc
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | beda8970: b6dda114 b6d0506c 00000001 06de90a5 0000002a b6ca8a3c b6fa0100 0000002a
Jan 26 08:10:29 fx30s user.err Legato: =ERR= | gpsAcquire[4068] | beda8990: b6dda114 b6d05e08 b6dd9b58 000005e8 01da6148 b6f6f11c b6f9d4d0 00000000

did you create the file before running the application?

did you use the following?


requires:
{
   
    file:
	{
	/tmp/hello.txt /
	}
}

Why don’t you just port the hello7.rar to your application?
This can save a lot of debug time.

Yes, I added that line and tried copying all of the code over and it still doesn’t work.

gpsAcquire.c

static void Testle_pos_GetInfo
(
    void
)
{
    int32_t           latitude;
    int32_t           longitude;
    int32_t           altitude;
    int32_t           hAccuracy;
    int32_t           vAccuracy;
//     uint32_t          hSpeed;
//     uint32_t          hSpeedAccuracy;
//     int32_t           vSpeed;
//     int32_t           vSpeedAccuracy;
//     uint32_t          heading;
//     uint32_t          headingAccuracy=0;
//     uint32_t          direction;
//     uint32_t          directionAccuracy=0;
    uint16_t          year = 0;
    uint16_t          month = 0;
    uint16_t          day = 0;
//     uint16_t          hours = 0;
//     uint16_t          minutes = 0;
//     uint16_t          seconds = 0;
//     uint16_t          milliseconds = 0;
    
    le_pos_FixState_t fixState;
    le_result_t       res;

    #define SIZE 1
    #define NUMELEM 5

    FILE* fd = NULL;
    char buff[100];
    memset(buff,0,sizeof(buff));

    fd = fopen("hello.txt","rw+");

    if(NULL == fd)
    {
        printf("\n fopen() Error!!!\n");
    }

    printf("\n File opened successfully through fopen()\n");

    char str[]="Hope this works!";
    fwrite(str,1,sizeof(str), fd);
//     if(SIZE*NUMELEM != fread(buff,SIZE,NUMELEM,fd))
//     {
//             printf("\n fread() failed\n");

//     }

//     printf("\n Some bytes successfully read through fread()\n");

//     printf("\n The bytes read are [%s]\n",buff);

//     if(0 != fseek(fd,11,SEEK_CUR))
//     {
//          printf("\n fseek() failed\n");

//     }

//     printf("\n fseek() successful\n");
//     buff[3]='\r';
//     buff[4]='\n';
    
//     if(SIZE*NUMELEM != fwrite(buff,SIZE,strlen(buff),fd))
//     {
//             printf("\n fwrite() failed\n");

//     }

    printf("\n fwrite() successful, data written to text file\n");

    fclose(fd);

    printf("\n File stream closed through fclose()\n");

gpsAcquire.adef

executables:
{
    gpsAcquire = ( gpsAcquire )
}
sandboxed: true
start: manual

processes:
{
    envVars:
    {
        LE_LOG_LEVEL = DEBUG
    }

    run:
    {
        (gpsAcquire)
    }
}


bindings:
{
    gpsAcquire.gpsAcquire.le_pos -> positioningService.le_pos
    gpsAcquire.gpsAcquire.le_posCtrl -> positioningService.le_posCtrl
    gpsAcquire.gpsAcquire.le_gnss -> positioningService.le_gnss
}

requires:
{
     file:
	 {
	 /tmp/hello.txt /
	 }
} 

it should not be that difficult to debug as you already have the working application…

you can copy everything to your component_init(), and then comment out all the GPS code.
If it works, then step by step to import the GPS code

yes, I understand, that is what I am trying to do. It is not failing on the GPS code, it is failing on the opening of the file.

I added that section to my adef code. I went through the steps of creating the hello.txt file and then xattr set, etc and then I run the application and it fails when opening the file.

I comment out all the new file opening/writing code from hello7 and the app works perfectly.

For some reason, I am not getting open access to the file, even though I have followed the directions the same for both programs.

Maybe you can do it in reverse direction, port the gpsapp code to the working hello7.rar

BTW, is it working fine for unsandboxed application?

for unsandboxed application, you should be able to read/write the file in the host environment

I think I finally was able to get it working. At least, I got it to write twice so far.

I have not tried unsandboxed app yet, as I haven’t read up on that.

Am I able to write to any directory or do I have to write to /tmp?
Also, can I move this code to a function or does it have to stay in the COMPONENT_INIT ?

You can create a file in /home/root , and the app should be able to access it

You can do some test on other function, right?

Ok. I was able to create a new file called hello.txt in my /home/root/myapp directory and it works fine.

If I create a new file called anything but hello.txt it fails…

If I change the fopen statement in c file and the adef reference to the new file name, it fails.
Change them back to hello.txt works everytime.

Is there a reference to hello.txt somewhere else that could be preventing the file opening?
I get an fopen error when not named hello.txt

I even tried copying the file and resetting the attr and it still fails.

I can copy hello.txt from /tmp to /home/root/myapp, then set xattr set, and it works fine.

cp hello.txt /home/root/myapp/hello.txt
root@fx30s:/tmp# cd /home/root/myapp
root@fx30s:~/myapp# xattr get hello.txt
    name=security.SMACK64; value=admin
root@fx30s:~/myapp# xattr set 'security.SMACK64' 'app.gpsAcquirerwx' hello.txt
root@fx30s:~/myapp# xattr get hello.txt
    name=security.SMACK64; value=app.gpsAcquirerwx

Change the Adef to the new location, Run the file, it runs fine.

If I copy the file to the new location with name change and then change xattr, it fails.

root@fx30s:/tmp# cp hello.txt /home/root/myapp/loc.txt
root@fx30s:/tmp# cd /home/root/myapp
root@fx30s:~/myapp# xattr get loc.txt
    name=security.SMACK64; value=admin
root@fx30s:~/myapp# xattr set 'security.SMACK64' 'app.gpsAcquirerwx' loc.txt
root@fx30s:~/myapp# xattr get loc.txt
    name=security.SMACK64; value=app.gpsAcquirerwx

Then change the c fopen loc.txt and the adef to loc.txt, recompile download, it fails.

Change it back to hello.txt, it works.

I have tried about 10 different filenames.
I have tried creating the file from scratch, I have tried copying hello.txt with a new name.
I am still set the chmod, attr set, everything. Only hello.txt works.

File permissions:

-rw-r--r--    1 root     root            21 Jan 26 11:09 hello.txt
-rw-r--r--    1 root     root            21 Jan 26 11:12 loc.txt
-rw-r--r--    1 root     root            21 Jan 26 11:36 tester.txt

root@fx30s:~/myapp# xattr get hello.txt
    name=security.SMACK64; value=app.gpsAcquirerwx
root@fx30s:~/myapp# xattr get tester.txt
    name=security.SMACK64; value=app.gpsAcquirerwx
root@fx30s:~/myapp# xattr get loc.txt
    name=security.SMACK64; value=app.gpsAcquirerwx

hello.txt works, tester.txt and gpsloc.txt fail, I cannot find anything wrong with the filenames.

UPDATE:
After more testing, I think what is happening is even though I am calling mkapp -t wp77xx gpsAcquire.def, since there is already an update and build folder in that directory, it is not re-building the app.

I just had a strange error, where even though my adef file was pointed to /home/root/myapp/hello.txt , it was actually reading and writing to /tmp/hello.txt

I rebooted VM and FX30, and then deleted all compilation folders and it went back to reading and writing the correct directory in the adef file: /home/root/myapp/hello.txt

did you change the .adef file?


requires:
{
   
    file:
	{
	/tmp/hello.txt /
	}
}

Yes , I was changing the adef file and the c file with the file location & filename (adef) and with filename, just like your example.

I had changed the code to write to /home/root/myapp/hello.txt and then tried several other file names (while changing the path in the adef and filename in both files.

I had started to try to write with fwrite and fprintf and it would not give me an error, but it also the file would not change. I finally changed the fwrite function output to something totally different and I kept re-downloading and testing, but I noticed on compile that it seemed like it was just doing a quick compile instead of compiling everything.
So I went back and checked /tmp/hello.txt, and I had two lines of output from my fwrite or fprintf commands that had over-written the hello everyone that was there at the beginning. So basically even though the adef showed in my VM to be in my home directory, it was still pointing to my /tmp directory.

So it seems to me that mkapp doesn’t do a full compile if you still have the *.update file and build folder in the directory. I deleted those two, recompiled (which did the whole compiling process) and then upon upload it was actually sending it back to /home/root/myapp/hello.txt

Just to update…

The error was definitely due to some kind of incomplete compiling when only small changes are made.

New procedure:
Make change to c file in VM
app remove appname from Putty
Delete build directory and update file
mkapp
install app
app start appname from Putty

Works every single time, doesn’t matter what directory it is in or the filename.