Comments (1)
The cmdline
is a string before parsing (received directly from the plo
in the syspage
):
"Xdummyfs Ximxrt-multi Xpsh Xspawn_test;1 Xspawn_test;2 Xspawn_test;3 Xspawn_test;4 Xspawn_test;5 "
after parsing, the memory content looks like this:
Xdummyfs\0Ximxrt-multi\0Xpsh\0Xspawn_test\0Xspawn_test\0Xspawn_test\0Xspawn_test\0Xspawn_test\0
but whileis being parsed each of the cmdline
item is scanned through prog=syspage->progs
list and compared with prog->cmdline
. This is a serious problem if cmdline
contains multiple programs with the same name, with different or same arguments or without arguments at all. As in the example in the problem description (see screenshots above), these five commands with arguments: spawn_test;1
, spawn_test;2
,spawn_test;3
, spawn_test;4
,spawn_test;5
, lead to 25 processes spawned… what !?
Take a close look at the block with hal_strcmp()
if-statement inside the loop:
Lines 97 to 105 in 54c5d2c
What it actually does, for each processed cmdline
item, it scans through prog=syspage->progs
, and if cmdline+1
matches the prog->cmdline
spawns a single process (for now I'm omitting the performance of this scan loop), it's even worse when the same program name appears more than once (this is the topic of an issue), leads to multiple processes spawned to ^2
As a redesign of the syspage
is not the subject of this issue, the temporary solution is to somehow mark the already spawned prog->cmdine
program, to be skipped in next syspage->progs
loop scan.
Not judging the solution itself, the below temporary hack seems to work:
u32 skips = 0; /* bit index */
In plo
the MAX_PROGRAMS_NB
is set to 32 so uint32
is ok here, though rootfs-less
projects should not go above the limit if so it is a sign to have rootfs
, with which we agree, I suppose.
for (prog = syspage->progs, i = 0; i < syspage->progssz; i++, prog++) {
if (!(skips & (1u << i)) && !hal_strcmp(cmdline + 1, prog->cmdline)) {
skips |= 1u << i;
argv[0] = prog->cmdline;
res = proc_syspageSpawn(prog, vm_getSharedMap(prog), prog->cmdline, argv);
if (res < 0) {
lib_printf("main: failed to spawn %s (%d)\n", argv[0], res);
}
break;
}
}
The result is as expected:
So, if there are better solutions that You guys have let's discuss them or if You agree with the presented approach let me prepare PR and commit.
from phoenix-rtos-kernel.
Related Issues (20)
- armv7: Compilation error, missing RAM_SIZE HOT 2
- programs_decode: fix for QEMU cpio parsing can cause unathorized access HOT 4
- riscv64: Changing the method of system timer setting.
- riscv64: Changing implementation of dtb parsing to handle big dtb's. HOT 1
- riscv64: Adding detection of PLIC interrupt controller to use it only when it is present HOT 1
- Adding io mapping functionality in HAL initialization (before pmap_init).
- riscv64: Adding support for latest qemu. HOT 3
- ia32: Adding APIC support to handle properly interrupt redistribution on SMP architectures. HOT 2
- Adding full suport of multiple memory maps on NOMMU arcthitectures.
- Correcting message passing mechanism to let it be aware on memory objects.
- Disabling interrupts in proc_fork()?
- Error compiling kernel TARGET=ia32-generic HOT 1
- armv7m: Signals don't work.
- HAL: armv7m: Missing break HOT 1
- Structure with __attribute__((packed)) in ARM HOT 6
- lib/printf: alignment doesn't work
- lib/strtoul: base = 0 doesn't work correctly
- Checking if namelen is negative in posix_gethostname() and posix_sethostname() functions HOT 2
- klog: offs_t type in structures HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phoenix-rtos-kernel.