chesterpolo / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

CRASHES on ANDROID #217

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create a test cgi
2. try to execute it

What is the expected output? What do you see instead?
a simple hello

What version of the product are you using? On what operating system?
latest

Please provide any additional information below.
The cgi script:
#!/system/xbin/sh

echo "Content-Type: text/plain"
echo
echo "Hello"

the command line:
mongoose -p 80 -d yes

It works normally when browsing..
As soon as I run test.cgi... BOOM.
It crashes the phone and outputs a 14k garbage file.

Any clues?

Original issue reported on code.google.com by zibree on 3 Jan 2011 at 1:38

GoogleCodeExporter commented 9 years ago
Can you describe how you have compiled Mongoose for android.
Building applications for Android/Linux requires the use of a cross-compiler 
tool
chain from CodeSourcery or You can also use Android NDK.
Problem may be in the dynamic linking process if you have used the 
cross-compiler.

Original comment by gallina....@gmail.com on 25 Jan 2011 at 5:37

GoogleCodeExporter commented 9 years ago
A friend of mine managed to use another android device libpthread and it worked.
So I think it's the embedded pthread in androind 2.2 that have a problem with 
mongoose.
Mini httpd seems not to be affected by this problem.

Also: If I create a custom cgi bin in C, everything works.
So the problem is with mongoose >> pthread >> "toolbox" (which is a sort of 
busybox).

I compiled it normally using the Android NDK:

$ /toolchain/bin/arm-linux-androideabi-gcc mongoose.c main.c -o mongoose

$ file mongoose
mongoose: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (
uses shared libs), not stripped

Original comment by zibree on 25 Jan 2011 at 5:59

GoogleCodeExporter commented 9 years ago
Nope.. the problem is not in dynamic linking but in the way pthread is 
implemented in android devices.

The nice thing is that it doesn't just crash the app but it crashes all the 
phone :)

Original comment by zibree on 25 Jan 2011 at 6:00

GoogleCodeExporter commented 9 years ago
According to the zibree reports:
“the problem is not in dynamic linking but in the way pthread is implemented 
in android devices.”
thrue!!
“It works normally when browsing..
As soon as I run test.cgi... BOOM.”

I think that dipends on the Handle_CGI_Request() at line 2835 av mongoose.c
this method call SpawnProcess() at line 1209 and at line 1217 there is the real 
problem
fork().

Dianne Hackborn one af the Android framework engineer`s said:
“Please don't use fork().  If you need multiple processes  you should use 
the platform's facilities through android:processes attributes in the manifest. 
“

Why?

Because the pthread implementation appears to be completely new and developed 
by Google specifically for Android. It is, quite deliberately, not a complete 
implementation of pthreads. It implements those features necessary to support 
threads in the Dalvik JVM, and only selectively thereafter.

At last according to the Issue 11393 of the Android projekt:
“the pthread kernel_id of the main thread is broken in Android because the 
kernel id is not adjusted after a fork.”

“A friend of mine managed to use another android device libpthread and it 
worked.”

Sorry but  I could’t find  any nice way around  the fork problem  on Android.
It would be nice to see the code of your friend. 

Original comment by gallina....@gmail.com on 26 Jan 2011 at 6:53

GoogleCodeExporter commented 9 years ago
Is there a solution for this CGI problem.  I have seen Mongoose implimented on 
Android with webkey app, although this needs to be rooted. Also is there any 
chance of providing an apk.

Original comment by simwa...@googlemail.com on 21 Jan 2012 at 6:02

GoogleCodeExporter commented 9 years ago
please have a look at 

https://github.com/valenok/mongoose/issues/9

for a fix for this CGI problem...

Original comment by h.koe...@science-computing.de on 23 Aug 2012 at 7:30

GoogleCodeExporter commented 9 years ago
Submitted 
https://github.com/valenok/mongoose/commit/c92d7c3bc8c6d9c15424711bed198b8a43bba
a58

Original comment by valenok on 25 Aug 2012 at 9:24