Skip to content
This repository has been archived by the owner on Nov 19, 2022. It is now read-only.

Detect *BSDs as supporting libc as well. #68

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ir-soeasycorp
Copy link

Modified fastcgi server to be able to use native (and local sockets) with *BSDs as well. I tested it on FreeBSD with lighttpd & local socket and it works as expected.

@@ -266,8 +266,33 @@ unsafe public void Run (object state)
static UnmanagedSocket ()
{
try {
string os = File.ReadAllText("/proc/sys/kernel/ostype");
supports_libc = os.StartsWith ("Linux");
string uname;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ir-soeasycorp
Copy link
Author

I didn't know about this call, however after checking it now there is never mentioned any guarantee about member order within structure (and that MonoDevelop example obviously assumes that sysname is first member, otherwise casting it to string wouldn't work) - I have no clue if across different unices you can safely assume that sysname is always first member of structure?
Check comment in the very same code https://github.com/mono/monodevelop/blob/7c51ae11c323d429c10acd22169373927217198f/main/src/core/Mono.Texteditor/Mono.TextEditor/Platform.cs#L53

@Therzok
Copy link

Therzok commented Oct 16, 2014

Actually, you're right. Good point there.

@miniBill
Copy link
Contributor

On the other hand uname is a POSIX standard

@ir-soeasycorp
Copy link
Author

I am not sure, but actually maybe it would make sense to have something in essence similar to your idea:

try {
    s = socket(PF_LOCAL, SOCK_STREAM, 0);
    close(s);
    supports_local_sockets = true;
}
catch {
    supports_local_sockets = false;
}

(with similar detection for every type of sockets) since idea of all this is anyway to check if "native" sockets are available through libc - but again maybe uname idea is easier to maintain and understand

@akoeplinger
Copy link
Member

I like your idea of "feature detection", would this be a big change to make?

@ir-soeasycorp
Copy link
Author

No, it would be easy to implement, however I have doubts:
PRO:

  • It would automatically detect if OS it is running on supports sockets, so instead of having hardcoded Linux and BSDs you immediately have it running on Solaris, HP-UX and bunch of others

CONS:

  • if for some reason detection fails, it is much more obvious to add one more || uname == "CoolOS" than discovering where this failed

@akoeplinger
Copy link
Member

if for some reason detection fails..

I suppose if socket(PF_LOCAL, SOCK_STREAM, 0) fails for some reason, there's not a good chance it'll work anyway, or?

@ir-soeasycorp
Copy link
Author

Hehehe, you have point there - I was more thinking like this (according to my experience with mono) - quite often on freebsd some functions fail because of missing mapping between system libs and names used by mono (since it is not the same as in linux) - with uname way it is clear that you enforced using of native sockets and then if needed you could later investigate further problems (easier path for somebody not familiar with this code).

I would say in general best way to approach this would be along these lines:

try {
    s = socket(PF_LOCAL, SOCK_STREAM, 0);
    close(s);
    supports_local_sockets = true;
}
catch {
    LogWhyItFailed();
    supports_local_sockets = false;
}

So if somebody with write access agrees to that I could implement it :-)

@akoeplinger
Copy link
Member

@grendello what do you think?

@grendello
Copy link
Member

I think we should have specific checks for the systems we know for sure work fine (Linux, OS X) using their native mechanisms. Start with consulting Environment.OSVersion to see if we're on Unix or OS/X (since it's supported directly in PlatformID). If we're not, no local sockets obviously. If OS/X, we're done. If Unix, go to check if there's the /proc filesystem, make sure it's Linux. If not, fall back to the libc syscall for detection of local socket support.

@ir-soeasycorp
Copy link
Author

That sounds overcomplicated to me without any real benefit (if libc call works why would we care what OS is behind (OSX, BeOS, or HP-UX) - it is its socket functionality we care about). Btw, is there any unix that doesn't support bsd sockets? Since they are part of posix anyway, maybe it makes more sense simply to enable it for all Unix (obviously that would leave any exotic OS with socket support (Haiku for example) unsupported)?
I know windows also supports socket api but have no clue if fastcgi-server was meant to run on windows?

@ir-soeasycorp
Copy link
Author

Btw, not strictly related to this one, would it be too complicated to patch mono not to drop requests in processing on application updates (similar way like you would normally write fastcgi app in C (signal it to stop accepting new requests and die, and have web server start new version of application for new requests))?
Do you think that would be something useful to have (I know I would like it)?

@miniBill
Copy link
Contributor

As a reply to the "not dropping requests" idea: I think you could patch mono-fpm to do that with a moderate effort.

Base automatically changed from master to main March 15, 2021 16:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants