2013-01-10 22:39:57 +01:00
|
|
|
/****************************************************************************
|
2021-05-08 20:33:52 +02:00
|
|
|
* apps/examples/posix_spawn/spawn_main.c
|
2013-01-10 22:39:57 +01:00
|
|
|
*
|
2020-04-11 20:13:56 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2013-01-10 22:39:57 +01:00
|
|
|
*
|
2020-04-11 20:13:56 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-01-10 22:39:57 +01:00
|
|
|
*
|
2020-04-11 20:13:56 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2013-01-10 22:39:57 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/compiler.h>
|
|
|
|
|
|
|
|
#include <sys/mount.h>
|
2018-03-16 15:51:49 +01:00
|
|
|
#include <sys/boardctl.h>
|
2013-01-10 22:39:57 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2020-06-15 08:02:49 +02:00
|
|
|
#include <malloc.h>
|
2013-01-10 22:39:57 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <spawn.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2016-07-20 22:02:41 +02:00
|
|
|
#include <nuttx/drivers/ramdisk.h>
|
2019-12-10 15:39:22 +01:00
|
|
|
#include <nuttx/symtab.h>
|
2013-01-10 22:39:57 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2015-10-02 22:06:11 +02:00
|
|
|
* Pre-processor Definitions
|
2013-01-10 22:39:57 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Check configuration. This is not all of the configuration settings that
|
|
|
|
* are required -- only the more obvious.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_BINFMT_DISABLE
|
|
|
|
# error "The binary loader is disabled (CONFIG_BINFMT_DISABLE)!"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_ELF
|
|
|
|
# error "You must select CONFIG_ELF in your configuration file"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_FS_ROMFS
|
|
|
|
# error "You must select CONFIG_FS_ROMFS in your configuration file"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_DISABLE_MOUNTPOINT
|
|
|
|
# error "You must not disable mountpoints via CONFIG_DISABLE_MOUNTPOINT in your configuration file"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_BINFMT_DISABLE
|
|
|
|
# error "You must not disable loadable modules via CONFIG_BINFMT_DISABLE in your configuration file"
|
|
|
|
#endif
|
|
|
|
|
2021-08-01 08:59:37 +02:00
|
|
|
#ifndef CONFIG_BOARDCTL
|
|
|
|
# error "This configuration requires CONFIG_BOARDCTL"
|
2018-03-16 15:51:49 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_BOARDCTL_APP_SYMTAB
|
|
|
|
# error "You must enable the symobol table interface with CONFIG_BOARDCTL_APP_SYMTAB"
|
|
|
|
#endif
|
|
|
|
|
2013-01-10 22:39:57 +01:00
|
|
|
/* Describe the ROMFS file system */
|
|
|
|
|
|
|
|
#define SECTORSIZE 512
|
|
|
|
#define NSECTORS(b) (((b)+SECTORSIZE-1)/SECTORSIZE)
|
|
|
|
#define MOUNTPT "/mnt/romfs"
|
|
|
|
|
2021-05-08 20:33:52 +02:00
|
|
|
#ifndef CONFIG_EXAMPLES_POSIXSPAWN_DEVMINOR
|
|
|
|
# define CONFIG_EXAMPLES_POSIXSPAWN_DEVMINOR 0
|
2013-01-10 22:39:57 +01:00
|
|
|
#endif
|
|
|
|
|
2021-05-08 20:33:52 +02:00
|
|
|
#ifndef CONFIG_EXAMPLES_POSIXSPAWN_DEVPATH
|
|
|
|
# define CONFIG_EXAMPLES_POSIXSPAWN_DEVPATH "/dev/ram0"
|
2013-01-10 22:39:57 +01:00
|
|
|
#endif
|
|
|
|
|
2020-04-11 20:56:24 +02:00
|
|
|
/* If CONFIG_DEBUG_FEATURES is enabled, use info/err instead of printf so
|
|
|
|
* that the output will be synchronous with the debug output.
|
2013-01-10 22:39:57 +01:00
|
|
|
*/
|
|
|
|
|
2020-05-04 12:52:59 +02:00
|
|
|
#ifdef CONFIG_DEBUG_FEATURES
|
|
|
|
# define message _info
|
|
|
|
# define errmsg _err
|
2013-01-10 22:39:57 +01:00
|
|
|
#else
|
2020-05-04 12:52:59 +02:00
|
|
|
# define message printf
|
|
|
|
# define errmsg printf
|
2013-01-10 22:39:57 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static unsigned int g_mminitial; /* Initial memory usage */
|
|
|
|
static unsigned int g_mmstep; /* Memory Usage at beginning of test step */
|
|
|
|
|
|
|
|
static const char delimiter[] =
|
2020-04-11 20:56:24 +02:00
|
|
|
"**************************************"
|
|
|
|
"**************************************";
|
2013-01-11 17:53:44 +01:00
|
|
|
static const char g_data[] = "testdata.txt";
|
2013-01-10 22:39:57 +01:00
|
|
|
|
|
|
|
static char fullpath[128];
|
|
|
|
|
2021-06-15 20:55:57 +02:00
|
|
|
static char * const g_hello_argv[5] =
|
2020-04-11 20:56:24 +02:00
|
|
|
{
|
2021-06-13 08:10:24 +02:00
|
|
|
"hello", "Argument 1", "Argument 2", "Argument 3", NULL
|
2020-04-11 20:56:24 +02:00
|
|
|
};
|
2013-01-11 17:53:44 +01:00
|
|
|
|
2021-06-15 20:55:57 +02:00
|
|
|
static char * const g_redirect_argv[2] =
|
|
|
|
{
|
|
|
|
"redirect", NULL
|
|
|
|
};
|
|
|
|
|
2013-01-10 22:39:57 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Symbols from Auto-Generated Code
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-05-14 05:32:35 +02:00
|
|
|
extern const unsigned char romfs_img[];
|
|
|
|
extern const unsigned int romfs_img_len;
|
|
|
|
|
2018-07-15 00:36:25 +02:00
|
|
|
extern const struct symtab_s g_spawn_exports[];
|
|
|
|
extern const int g_spawn_nexports;
|
2013-01-10 22:39:57 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mm_update
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void mm_update(FAR unsigned int *previous, FAR const char *msg)
|
|
|
|
{
|
|
|
|
struct mallinfo mmcurrent;
|
|
|
|
|
|
|
|
/* Get the current memory usage */
|
|
|
|
|
|
|
|
mmcurrent = mallinfo();
|
|
|
|
|
|
|
|
/* Show the change from the previous time */
|
|
|
|
|
|
|
|
printf("\nMemory Usage %s:\n", msg);
|
|
|
|
printf(" Before: %8u After: %8u Change: %8d\n",
|
2020-04-11 20:56:24 +02:00
|
|
|
*previous, mmcurrent.uordblks,
|
|
|
|
(int)mmcurrent.uordblks - (int)*previous);
|
2013-01-10 22:39:57 +01:00
|
|
|
|
|
|
|
/* Set up for the next test */
|
|
|
|
|
|
|
|
*previous = mmcurrent.uordblks;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mm_initmonitor
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void mm_initmonitor(void)
|
|
|
|
{
|
|
|
|
struct mallinfo mmcurrent;
|
|
|
|
|
|
|
|
mmcurrent = mallinfo();
|
|
|
|
|
|
|
|
g_mminitial = mmcurrent.uordblks;
|
|
|
|
g_mmstep = mmcurrent.uordblks;
|
|
|
|
|
|
|
|
printf("Initial memory usage: %d\n", mmcurrent.uordblks);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: testheader
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void testheader(FAR const char *progname)
|
|
|
|
{
|
|
|
|
message("\n%s\n* Executing %s\n%s\n\n", delimiter, progname, delimiter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: spawn_main
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-06 17:23:23 +02:00
|
|
|
int main(int argc, FAR char *argv[])
|
2013-01-10 22:39:57 +01:00
|
|
|
{
|
2018-03-16 15:51:49 +01:00
|
|
|
struct boardioc_symtab_s symdesc;
|
2013-01-10 22:39:57 +01:00
|
|
|
posix_spawn_file_actions_t file_actions;
|
|
|
|
posix_spawnattr_t attr;
|
|
|
|
FAR const char *filepath;
|
|
|
|
pid_t pid;
|
|
|
|
int ret;
|
2021-05-08 20:33:52 +02:00
|
|
|
struct boardioc_romdisk_s desc;
|
2013-01-10 22:39:57 +01:00
|
|
|
|
|
|
|
/* Initialize the memory monitor */
|
|
|
|
|
|
|
|
mm_initmonitor();
|
|
|
|
|
|
|
|
/* Create a ROM disk for the ROMFS filesystem */
|
|
|
|
|
2021-05-08 20:33:52 +02:00
|
|
|
desc.minor = CONFIG_EXAMPLES_POSIXSPAWN_DEVMINOR; /* Minor device number of the ROM disk. */
|
|
|
|
desc.nsectors = NSECTORS(romfs_img_len); /* The number of sectors in the ROM disk */
|
|
|
|
desc.sectsize = SECTORSIZE; /* The size of one sector in bytes */
|
|
|
|
desc.image = (FAR uint8_t *)romfs_img; /* File system image */
|
|
|
|
|
2020-04-11 20:56:24 +02:00
|
|
|
message("Registering romdisk at /dev/ram%d\n",
|
2021-05-08 20:33:52 +02:00
|
|
|
CONFIG_EXAMPLES_POSIXSPAWN_DEVMINOR);
|
|
|
|
|
|
|
|
ret = boardctl(BOARDIOC_ROMDISK, (uintptr_t)&desc);
|
2020-04-11 20:56:24 +02:00
|
|
|
|
2013-01-10 22:39:57 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2021-05-08 20:33:52 +02:00
|
|
|
errmsg("ERROR: romdisk_register failed: %s\n", strerror(errno));
|
2013-01-10 22:39:57 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
mm_update(&g_mmstep, "after romdisk_register");
|
|
|
|
|
|
|
|
/* Mount the file system */
|
|
|
|
|
|
|
|
message("Mounting ROMFS filesystem at target=%s with source=%s\n",
|
2021-05-08 20:33:52 +02:00
|
|
|
MOUNTPT, CONFIG_EXAMPLES_POSIXSPAWN_DEVPATH);
|
2013-01-10 22:39:57 +01:00
|
|
|
|
2021-05-08 20:33:52 +02:00
|
|
|
ret = mount(CONFIG_EXAMPLES_POSIXSPAWN_DEVPATH, MOUNTPT, "romfs",
|
2020-04-11 20:56:24 +02:00
|
|
|
MS_RDONLY, NULL);
|
2013-01-10 22:39:57 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2021-05-08 20:33:52 +02:00
|
|
|
errmsg("ERROR: mount(%s,%s,romfs) failed: %s\n",
|
|
|
|
CONFIG_EXAMPLES_POSIXSPAWN_DEVPATH, MOUNTPT, strerror(errno));
|
2013-01-10 22:39:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
mm_update(&g_mmstep, "after mount");
|
|
|
|
|
|
|
|
/* Does the system support the PATH variable? Has the PATH variable
|
|
|
|
* already been set? If YES and NO, then set the PATH variable to
|
|
|
|
* the ROMFS mountpoint.
|
|
|
|
*/
|
|
|
|
|
2021-08-01 09:28:27 +02:00
|
|
|
#if defined(CONFIG_LIBC_ENVPATH) && !defined(CONFIG_PATH_INITIAL)
|
2020-01-02 13:09:50 +01:00
|
|
|
setenv("PATH", MOUNTPT, 1);
|
2013-01-10 22:39:57 +01:00
|
|
|
#endif
|
|
|
|
|
2018-03-16 15:51:49 +01:00
|
|
|
/* Make sure that we are using our symbol tablee */
|
2013-01-10 22:39:57 +01:00
|
|
|
|
2018-07-15 00:36:25 +02:00
|
|
|
symdesc.symtab = (FAR struct symtab_s *)g_spawn_exports; /* Discard 'const' */
|
|
|
|
symdesc.nsymbols = g_spawn_nexports;
|
2020-01-02 13:09:50 +01:00
|
|
|
boardctl(BOARDIOC_APP_SYMTAB, (uintptr_t)&symdesc);
|
2013-01-10 22:39:57 +01:00
|
|
|
|
2020-04-11 20:56:24 +02:00
|
|
|
/**************************************************************************
|
2013-01-11 17:53:44 +01:00
|
|
|
* Case 1: Simple program with arguments
|
2020-04-11 20:56:24 +02:00
|
|
|
**************************************************************************/
|
2013-01-11 17:53:44 +01:00
|
|
|
|
2018-03-16 15:51:49 +01:00
|
|
|
/* Output a separator so that we can clearly discriminate the output of
|
2013-01-11 17:53:44 +01:00
|
|
|
* this program from the others.
|
|
|
|
*/
|
|
|
|
|
2021-06-15 20:55:57 +02:00
|
|
|
testheader(g_hello_argv[0]);
|
2013-01-11 17:53:44 +01:00
|
|
|
|
|
|
|
/* Initialize the attributes file actions structure */
|
|
|
|
|
|
|
|
ret = posix_spawn_file_actions_init(&file_actions);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
2016-06-11 22:49:55 +02:00
|
|
|
errmsg("ERROR: posix_spawn_file_actions_init failed: %d\n", ret);
|
2013-01-11 17:53:44 +01:00
|
|
|
}
|
2018-03-16 19:18:26 +01:00
|
|
|
|
2013-01-11 17:53:44 +01:00
|
|
|
posix_spawn_file_actions_dump(&file_actions);
|
|
|
|
|
|
|
|
ret = posix_spawnattr_init(&attr);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
2016-06-11 22:49:55 +02:00
|
|
|
errmsg("ERROR: posix_spawnattr_init failed: %d\n", ret);
|
2013-01-11 17:53:44 +01:00
|
|
|
}
|
2018-03-16 19:18:26 +01:00
|
|
|
|
2013-01-11 17:53:44 +01:00
|
|
|
posix_spawnattr_dump(&attr);
|
|
|
|
|
|
|
|
mm_update(&g_mmstep, "after file_action/attr init");
|
|
|
|
|
|
|
|
/* If the binary loader does not support the PATH variable, then
|
|
|
|
* create the full path to the executable program. Otherwise,
|
|
|
|
* use the relative path so that the binary loader will have to
|
|
|
|
* search the PATH variable to find the executable.
|
|
|
|
*/
|
|
|
|
|
2021-08-01 09:28:27 +02:00
|
|
|
#ifdef CONFIG_LIBC_ENVPATH
|
2021-06-15 20:55:57 +02:00
|
|
|
filepath = g_hello_argv[0];
|
2013-01-11 17:53:44 +01:00
|
|
|
#else
|
2021-06-15 20:55:57 +02:00
|
|
|
snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_hello_argv[0]);
|
2013-01-11 17:53:44 +01:00
|
|
|
filepath = fullpath;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Execute the program */
|
|
|
|
|
|
|
|
mm_update(&g_mmstep, "before posix_spawn");
|
|
|
|
|
2021-06-15 20:55:57 +02:00
|
|
|
ret = posix_spawn(&pid, filepath, &file_actions,
|
|
|
|
&attr, g_hello_argv, NULL);
|
2013-01-11 17:53:44 +01:00
|
|
|
if (ret != 0)
|
|
|
|
{
|
2016-06-11 22:49:55 +02:00
|
|
|
errmsg("ERROR: posix_spawn failed: %d\n", ret);
|
2013-01-11 17:53:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sleep(4);
|
|
|
|
mm_update(&g_mmstep, "after posix_spawn");
|
|
|
|
|
2018-03-16 19:18:26 +01:00
|
|
|
/* Free attributes and file actions */
|
2013-01-11 17:53:44 +01:00
|
|
|
|
|
|
|
ret = posix_spawn_file_actions_destroy(&file_actions);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
2016-06-11 22:49:55 +02:00
|
|
|
errmsg("ERROR: posix_spawn_file_actions_destroy failed: %d\n", ret);
|
2013-01-11 17:53:44 +01:00
|
|
|
}
|
2018-03-16 19:18:26 +01:00
|
|
|
|
2013-01-11 17:53:44 +01:00
|
|
|
posix_spawn_file_actions_dump(&file_actions);
|
|
|
|
|
|
|
|
ret = posix_spawnattr_destroy(&attr);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
2016-06-11 22:49:55 +02:00
|
|
|
errmsg("ERROR: posix_spawnattr_destroy failed: %d\n", ret);
|
2013-01-11 17:53:44 +01:00
|
|
|
}
|
2018-03-16 19:18:26 +01:00
|
|
|
|
2013-01-11 17:53:44 +01:00
|
|
|
posix_spawnattr_dump(&attr);
|
|
|
|
|
|
|
|
mm_update(&g_mmstep, "after file_action/attr destruction");
|
|
|
|
|
2020-04-11 20:56:24 +02:00
|
|
|
/**************************************************************************
|
2013-01-11 20:08:51 +01:00
|
|
|
* Case 2: Simple program with redirection of stdin to a file input
|
2020-04-11 20:56:24 +02:00
|
|
|
**************************************************************************/
|
2013-01-11 17:53:44 +01:00
|
|
|
|
2018-03-16 15:51:49 +01:00
|
|
|
/* Output a separator so that we can clearly discriminate the output of
|
2013-01-10 22:39:57 +01:00
|
|
|
* this program from the others.
|
|
|
|
*/
|
|
|
|
|
2021-06-15 20:55:57 +02:00
|
|
|
testheader(g_redirect_argv[0]);
|
2013-01-10 22:39:57 +01:00
|
|
|
|
|
|
|
/* Initialize the attributes file actions structure */
|
|
|
|
|
|
|
|
ret = posix_spawn_file_actions_init(&file_actions);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
2016-06-11 22:49:55 +02:00
|
|
|
errmsg("ERROR: posix_spawn_file_actions_init failed: %d\n", ret);
|
2013-01-10 22:39:57 +01:00
|
|
|
}
|
2018-03-16 19:18:26 +01:00
|
|
|
|
2013-01-11 17:53:44 +01:00
|
|
|
posix_spawn_file_actions_dump(&file_actions);
|
2013-01-10 22:39:57 +01:00
|
|
|
|
|
|
|
ret = posix_spawnattr_init(&attr);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
2016-06-11 22:49:55 +02:00
|
|
|
errmsg("ERROR: posix_spawnattr_init failed: %d\n", ret);
|
2013-01-10 22:39:57 +01:00
|
|
|
}
|
2018-03-16 19:18:26 +01:00
|
|
|
|
2013-01-11 17:53:44 +01:00
|
|
|
posix_spawnattr_dump(&attr);
|
2013-01-10 22:39:57 +01:00
|
|
|
|
2013-01-11 00:06:23 +01:00
|
|
|
mm_update(&g_mmstep, "after file_action/attr init");
|
|
|
|
|
2013-01-10 22:39:57 +01:00
|
|
|
/* Set up to close stdin (0) and open testdata.txt as the program input */
|
|
|
|
|
|
|
|
ret = posix_spawn_file_actions_addclose(&file_actions, 0);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
2016-06-11 22:49:55 +02:00
|
|
|
errmsg("ERROR: posix_spawn_file_actions_addclose failed: %d\n", ret);
|
2013-01-10 22:39:57 +01:00
|
|
|
}
|
2018-03-16 19:18:26 +01:00
|
|
|
|
2013-01-11 17:53:44 +01:00
|
|
|
posix_spawn_file_actions_dump(&file_actions);
|
2013-01-10 22:39:57 +01:00
|
|
|
|
2013-01-11 17:53:44 +01:00
|
|
|
snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_data);
|
2020-04-11 20:56:24 +02:00
|
|
|
ret = posix_spawn_file_actions_addopen(&file_actions, 0, fullpath,
|
|
|
|
O_RDONLY, 0644);
|
2013-01-10 22:39:57 +01:00
|
|
|
if (ret != 0)
|
|
|
|
{
|
2016-06-11 22:49:55 +02:00
|
|
|
errmsg("ERROR: posix_spawn_file_actions_addopen failed: %d\n", ret);
|
2013-01-10 22:39:57 +01:00
|
|
|
}
|
2018-03-16 19:18:26 +01:00
|
|
|
|
2013-01-11 17:53:44 +01:00
|
|
|
posix_spawn_file_actions_dump(&file_actions);
|
2014-04-14 00:24:28 +02:00
|
|
|
|
2013-01-11 00:06:23 +01:00
|
|
|
mm_update(&g_mmstep, "after adding file_actions");
|
|
|
|
|
2013-01-10 22:39:57 +01:00
|
|
|
/* If the binary loader does not support the PATH variable, then
|
|
|
|
* create the full path to the executable program. Otherwise,
|
|
|
|
* use the relative path so that the binary loader will have to
|
|
|
|
* search the PATH variable to find the executable.
|
|
|
|
*/
|
|
|
|
|
2021-08-01 09:28:27 +02:00
|
|
|
#ifdef CONFIG_LIBC_ENVPATH
|
2021-06-15 20:55:57 +02:00
|
|
|
filepath = g_redirect_argv[0];
|
2013-01-10 22:39:57 +01:00
|
|
|
#else
|
2021-06-15 20:55:57 +02:00
|
|
|
snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_redirect_argv[0]);
|
2013-01-10 22:39:57 +01:00
|
|
|
filepath = fullpath;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Execute the program */
|
|
|
|
|
|
|
|
mm_update(&g_mmstep, "before posix_spawn");
|
|
|
|
|
2021-06-15 20:55:57 +02:00
|
|
|
ret = posix_spawn(&pid, filepath, &file_actions,
|
|
|
|
&attr, g_redirect_argv, NULL);
|
2013-01-10 22:39:57 +01:00
|
|
|
if (ret != 0)
|
|
|
|
{
|
2016-06-11 22:49:55 +02:00
|
|
|
errmsg("ERROR: posix_spawn failed: %d\n", ret);
|
2013-01-10 22:39:57 +01:00
|
|
|
}
|
|
|
|
|
2013-01-11 17:53:44 +01:00
|
|
|
sleep(2);
|
2013-01-10 22:39:57 +01:00
|
|
|
mm_update(&g_mmstep, "after posix_spawn");
|
|
|
|
|
2020-02-23 05:51:44 +01:00
|
|
|
/* Free attributes and file actions */
|
2013-01-11 17:53:44 +01:00
|
|
|
|
|
|
|
ret = posix_spawn_file_actions_destroy(&file_actions);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
2016-06-11 22:49:55 +02:00
|
|
|
errmsg("ERROR: posix_spawn_file_actions_destroy failed: %d\n", ret);
|
2013-01-11 17:53:44 +01:00
|
|
|
}
|
2020-04-11 20:56:24 +02:00
|
|
|
|
2013-01-11 17:53:44 +01:00
|
|
|
posix_spawn_file_actions_dump(&file_actions);
|
|
|
|
|
|
|
|
ret = posix_spawnattr_destroy(&attr);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
2016-06-11 22:49:55 +02:00
|
|
|
errmsg("ERROR: posix_spawnattr_destroy failed: %d\n", ret);
|
2013-01-11 17:53:44 +01:00
|
|
|
}
|
2020-04-11 20:56:24 +02:00
|
|
|
|
2013-01-11 17:53:44 +01:00
|
|
|
posix_spawnattr_dump(&attr);
|
|
|
|
|
|
|
|
mm_update(&g_mmstep, "after file_action/attr destruction");
|
|
|
|
|
2013-01-10 22:39:57 +01:00
|
|
|
/* Clean-up */
|
|
|
|
|
|
|
|
mm_update(&g_mmstep, "End-of-Test");
|
|
|
|
return 0;
|
|
|
|
}
|