I have the following idea but don’t know how to implement it.
One C script sends a string to another C script using pipes. After that, the latter script forwards that string to Putty via UART1.
These are the C files that can already communicate with each other:
I just want to be sure I’ve understood what you described.
So you have a single app running on the module (written in C) that can communicate with another script written in Python (not installed on the module) using a pipe?
I am looking for a way of communicating between two separate apps using pipes.
Or is there generally no possibility for two apps to communicate via pipes?
Is it possible to have two separate C scripts communicate via pipes in one single app though?
I don’t see why two apps shouldn’t be able to communicate using a named pipe. You would have to take care that they have the right permissions if sandboxed.
I don’t know any specific examples. But the named pipe is accessed just like a file. My C application does the writing and the python does the reading. You could have two C applications one writing and one reading.
It would be best to test one application at a time, you could just run cat from the shell to test the writing and reading apps separately.
I just made two apps, one that sends a string and another one that should receive it.
The pipe, which I have created under /home/root/, is accessed in both of these files inside the the open function.
root@swi-mdm9x28-wp:~# ls
fifo
// send.c
#include "legato.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/select.h>
#include <sys/types.h>
#include <errno.h>
#include <time.h>
#define BUF 20
int main();
COMPONENT_INIT{
LE_INFO("#####Inside send COMPONENT_INIT.#####");
main();
}
int main(){
char message[BUF] = "####Test message####";
int fd = open("/home/root/fifo", O_WRONLY);
LE_INFO("##### SEND Just opened the fifo.##### %d", fd);
if (fd == -1){
printf("fd ==1\n");
LE_INFO("##### SEND: opening the fifo has failed.#####");
return 1;
}
if(write(fd, &message, strlen(message)) == -1){
LE_INFO("##### SEND: writing the message has failed.#####");
return 2;
}
LE_INFO("%s", message);
printf("This message was sent: %s\n", message);
close(fd);
return 0;
}
//recv.c
#include "legato.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/select.h>
#include <sys/types.h>
#include <errno.h>
#include <time.h>
#define BUF 40
int main();
COMPONENT_INIT{
LE_INFO("#####Inside recv COMPONENT_INIT.#####");
main();
}
int main(){
char message[BUF];
int fd = open("/home/root/fifo", O_RDONLY);
LE_INFO("#####Just opened the fifo.##### %d", fd);
if (fd == -1){
printf("fd ==1\n");
LE_INFO("##### RECV: opening the fifo has failed.#####");
return 1;
}
if(read(fd, &message, BUF) == -1){
LE_INFO("##### RECV: receiving the message has failed.#####");
return 2;
}
printf("Received this message: %s\n", message);
LE_INFO("%s", message);
close(fd);
return 0;
}
Unfortunately, I get the following error message when starting the send app:
Oct 27 14:46:46 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c app_Create() 3207 | Creating app 'pipesSend'
Oct 27 14:46:46 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | proc.c GetFaultAction() 323 | No fault action specified for process 'pipesSend'. Assuming 'ignore'.
Oct 27 14:46:46 swi-mdm9x28-wp user.warn Legato: -WRN- | supervisor[833]/supervisor T=main | proc.c GetWatchdogAction() 359 | pipesSend watchdogAction '' in proc section
Oct 27 14:46:46 swi-mdm9x28-wp user.warn Legato: -WRN- | supervisor[833]/supervisor T=main | proc.c GetWatchdogAction() 359 | pipesSend watchdogAction '' in proc section
Oct 27 14:46:46 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c app_Start() 3420 | Starting app 'pipesSend'
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c CreateFileLink() 2104 | Created file link '/dev/log' to '/legato/systems/current/appsWriteable/pipesSend/dev/log'.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c CreateFileLink() 2104 | Created file link '/dev/null' to '/legato/systems/current/appsWriteable/pipesSend/dev/null'.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c CreateFileLink() 2104 | Created file link '/dev/zero' to '/legato/systems/current/appsWriteable/pipesSend/dev/zero'.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c CreateFileLink() 2104 | Created file link '/legato/systems/current/lib/liblegato.so' to '/legato/systems/current/appsWriteable/pipesSend/lib/liblegato.so'.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c CreateFileLink() 2104 | Created file link '/lib/ld-linux.so.3' to '/legato/systems/current/appsWriteable/pipesSend/lib/ld-linux.so.3'.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c CreateFileLink() 2104 | Created file link '/lib/libc.so.6' to '/legato/systems/current/appsWriteable/pipesSend/lib/libc.so.6'.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c CreateFileLink() 2104 | Created file link '/lib/libpthread.so.0' to '/legato/systems/current/appsWriteable/pipesSend/lib/libpthread.so.0'.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c CreateFileLink() 2104 | Created file link '/lib/librt.so.1' to '/legato/systems/current/appsWriteable/pipesSend/lib/librt.so.1'.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c CreateFileLink() 2104 | Created file link '/lib/libdl.so.2' to '/legato/systems/current/appsWriteable/pipesSend/lib/libdl.so.2'.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c CreateFileLink() 2104 | Created file link '/lib/libgcc_s.so.1' to '/legato/systems/current/appsWriteable/pipesSend/lib/libgcc_s.so.1'.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c CreateFileLink() 2104 | Created file link '/lib/libm.so.6' to '/legato/systems/current/appsWriteable/pipesSend/lib/libm.so.6'.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c CreateFileLink() 2104 | Created file link '/usr/lib/libstdc++.so.6' to '/legato/systems/current/appsWriteable/pipesSend/lib/libstdc++.so.6'.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c CreateFileLink() 2104 | Created file link '/legato/systems/current/apps/pipesSend/read-only/lib/libComponent_pipesSendComponent.so' to '/legato/systems/current/appsWriteable/pip
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c CreateFileLink() 2104 | Created file link '/legato/systems/current/apps/pipesSend/read-only/bin/pipesSend' to '/legato/systems/current/appsWriteable/pipesSend/bin/pipesSend'.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c CreateTmpFs() 1738 | Mounted tmpfs at /legato/systems/current/appsWriteable/pipesSend/tmp.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c CreateFileLink() 2104 | Created file link '/tmp/legato/serviceDirectoryServer' to '/legato/systems/current/appsWriteable/pipesSend/tmp/legato/serviceDirectoryServer'.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | app.c CreateFileLink() 2104 | Created file link '/tmp/legato/serviceDirectoryClient' to '/legato/systems/current/appsWriteable/pipesSend/tmp/legato/serviceDirectoryClient'.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxCoreDumpFileBytes to value 102400.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxFileBytes to value 102400.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxLockedMemoryBytes to value 8192.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxFileDescriptors to value 256.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxMQueueBytes to value 512.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxThreads to value 20.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxQueuedSignals to value 100.
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[833]/supervisor T=main | proc.c proc_Start() 1390 | Starting process 'pipesSend' with pid 6771
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | supervisor[6771]/supervisor T=main | proc.c proc_Start() 1355 | Execing 'pipesSend'
Oct 27 13:46:47 swi-mdm9x28-wp user.debug Legato: DBUG | _UNKNOWN_[6771]/framework T=unknown | LE_FILENAME InitPool() 295 | Memory pool name 'framework.hashMap_refPathIteratorMap' is truncated to 'framework.hashMap_refPathIterat'
Oct 27 13:46:47 swi-mdm9x28-wp user.debug Legato: DBUG | _UNKNOWN_[6771]/framework T=main | LE_FILENAME InitPool() 295 | Memory pool name 'framework.hashMap_refEventHandlers' is truncated to 'framework.hashMap_refEventHandl'
Oct 27 13:46:47 swi-mdm9x28-wp user.debug Legato: DBUG | _UNKNOWN_[6771]/framework T=main | LE_FILENAME InitPool() 295 | Memory pool name 'framework.hashMap_refDefault Timer SafeRe' is truncated to 'framework.hashMap_refDefault Ti'
Oct 27 13:46:47 swi-mdm9x28-wp user.debug Legato: DBUG | _UNKNOWN_[6771]/framework T=main | LE_FILENAME InitPool() 295 | Memory pool name 'framework.MessagingClientInterfaces' is truncated to 'framework.MessagingClientInterf'
Oct 27 13:46:47 swi-mdm9x28-wp user.debug Legato: DBUG | _UNKNOWN_[6771]/framework T=main | LE_FILENAME InitPool() 295 | Memory pool name 'framework.hashMap_refHandlersRef' is truncated to 'framework.hashMap_refHandlersRe'
Oct 27 13:46:47 swi-mdm9x28-wp user.debug Legato: DBUG | _UNKNOWN_[6771]/framework T=main | LE_FILENAME InitPool() 295 | Memory pool name 'framework.hashMap_MessagingServices' is truncated to 'framework.hashMap_MessagingServ'
Oct 27 13:46:47 swi-mdm9x28-wp user.debug Legato: DBUG | _UNKNOWN_[6771]/framework T=main | LE_FILENAME InitPool() 295 | Memory pool name 'framework.hashMap_MessagingClients' is truncated to 'framework.hashMap_MessagingClie'
Oct 27 13:46:47 swi-mdm9x28-wp user.debug Legato: DBUG | _UNKNOWN_[6771]/framework T=main | LE_FILENAME InitPool() 295 | Memory pool name 'framework.PipelineSIGCHLD-reports' is truncated to 'framework.PipelineSIGCHLD-repor'
Oct 27 13:46:47 swi-mdm9x28-wp user.debug Legato: DBUG | _UNKNOWN_[6771]/framework T=main | LE_FILENAME fs_Init() 840 | FS prefix path "/data/le_fs/"
Oct 27 13:46:47 swi-mdm9x28-wp user.debug Legato: DBUG | _UNKNOWN_[6771]/framework T=main | LE_FILENAME InitPool() 295 | Memory pool name 'framework.hashMap_refFsFileRefMap' is truncated to 'framework.hashMap_refFsFileRefM'
Oct 27 13:46:47 swi-mdm9x28-wp user.debug Legato: DBUG | _UNKNOWN_[6771]/framework T=main | LE_FILENAME rand_Init() 71 | getrandom function: 0xb6d61150
Oct 27 13:46:47 swi-mdm9x28-wp user.debug Legato: DBUG | _UNKNOWN_[6771]/framework T=main | LE_FILENAME le_mem_ForceAlloc() 833 | Memory pool 'framework.DestructorObjs' overflowed. Expanded to 1 blocks.
Oct 27 13:46:47 swi-mdm9x28-wp user.debug Legato: DBUG | _UNKNOWN_[6771]/<invalid> T=main | _componentMain.c _pipesSendComponent_Init() 26 | Initializing pipesSendComponent component library.
Oct 27 13:46:47 swi-mdm9x28-wp user.debug Legato: DBUG | pipesSend[6771]/framework T=main | LE_FILENAME InitPool() 295 | Memory pool name 'framework.msgs-LogControlProtocol' is truncated to 'framework.msgs-LogControlProtoc'
Oct 27 13:46:47 swi-mdm9x28-wp user.debug Legato: DBUG | pipesSend[6771]/framework T=main | LE_FILENAME le_mem_ForceAlloc() 833 | Memory pool 'framework.SigMonitor' overflowed. Expanded to 1 blocks.
Oct 27 13:46:47 swi-mdm9x28-wp user.debug Legato: DBUG | pipesSend[6771]/framework T=main | LE_FILENAME le_mem_ForceAlloc() 833 | Memory pool 'framework.SigHandler' overflowed. Expanded to 1 blocks.
Oct 27 13:46:47 swi-mdm9x28-wp user.debug Legato: DBUG | pipesSend[6771]/pipesSend_exe T=main | _main.c main() 60 | == Starting Event Processing Loop ==
Oct 27 13:46:47 swi-mdm9x28-wp user.info Legato: INFO | pipesSend[6771]/pipesSendComponent T=main | send.c _pipesSendComponent_COMPONENT_INIT() 19 | #####Inside send COMPONENT_INIT.#####
Oct 27 13:46:47 swi-mdm9x28-wp user.info Legato: INFO | pipesSend[6771]/pipesSendComponent T=main | send.c main() 27 | ##### SEND Just opened the fifo.##### -1
Oct 27 14:46:47 swi-mdm9x28-wp user.info Legato: INFO | pipesSend[6771] | fd ==1
Oct 27 13:46:47 swi-mdm9x28-wp user.info Legato: INFO | pipesSend[6771]/pipesSendComponent T=main | send.c main() 31 | ##### SEND: opening the fifo has failed.#####
Oct 27 14:46:47 swi-mdm9x28-wp user.notice kernel: [ 2880.270866] audit: type=1400 audit(1603806407.102:9): lsm=SMACK fn=smack_inode_getattr action=denied subject="app.pipesSend" object="admin" requested=r pid=6771 comm="pipesSend" path="pipe:[24224]" dev="pipefs" ino=24224
So, it looks like the fifo cannot be opened.
root@swi-mdm9x28-wp:~# ls -l
prwxrwxrwx 1 root root 0 Oct 27 10:44 fifo
You can’t use absolute path in a sandboxed application. Try putting “sandboxed: false” in your adef, you can then use absolute paths. After you get it working you can go back to sandboxed, you will use the file name as just “fifo” and you will need to add a directory assignment for /home/root in your .adef .
Our Python script creates the pipe, apparently it does not need to set SMACK permissions to access the pipe after this. Note the Python script runs from root. SMACK permissions on the pipe are set by the Python script for the Legato application which runs sandboxed.
It appears to me that SMACK permissions would be needed on the directory if the pipe is created by a sandboxed application.