working aroind phobos limitations in musl

This commit is contained in:
Adam D. Ruppe 2019-10-06 12:23:07 -04:00
parent 76b50ad081
commit aa45fe8f54
1 changed files with 35 additions and 10 deletions

45
cgi.d
View File

@ -3102,28 +3102,29 @@ void cgiMainImpl(alias fun, CustomCgi = Cgi, long maxContentLength = defaultMaxC
version(with_addon_servers) version(with_addon_servers)
runWebsocketServer(); runWebsocketServer();
else else
writeln("Add-on servers not compiled in."); printf("Add-on servers not compiled in.");
return; return;
case "--session-server": case "--session-server":
version(with_addon_servers) version(with_addon_servers)
runSessionServer(); runSessionServer();
else else
writeln("Add-on servers not compiled in."); printf("Add-on servers not compiled in.");
return; return;
case "--event-server": case "--event-server":
version(with_addon_servers) version(with_addon_servers)
runEventServer(); runEventServer();
else else
writeln("Add-on servers not compiled in."); printf("Add-on servers not compiled in.");
return; return;
case "--timer-server": case "--timer-server":
version(with_addon_servers) version(with_addon_servers)
runTimerServer(); runTimerServer();
else else
writeln("Add-on servers not compiled in."); printf("Add-on servers not compiled in.");
return; return;
case "--timed-jobs": case "--timed-jobs":
import core.demangle; import core.demangle;
version(with_addon_servers_connections)
foreach(k, v; scheduledJobHandlers) foreach(k, v; scheduledJobHandlers)
writeln(k, "\t", demangle(k)); writeln(k, "\t", demangle(k));
return; return;
@ -3287,7 +3288,14 @@ void cgiMainImpl(alias fun, CustomCgi = Cgi, long maxContentLength = defaultMaxC
} catch(Throwable t) { } catch(Throwable t) {
// a construction error is either bad code or bad request; bad request is what it should be since this is bug free :P // a construction error is either bad code or bad request; bad request is what it should be since this is bug free :P
// anyway let's kill the connection // anyway let's kill the connection
stderr.writeln(t.toString()); version(CRuntime_Musl) {
// LockingTextWriter fails here
// so working around it
auto s = t.toString();
stderr.rawWrite(s);
stderr.rawWrite("\n");
} else
stderr.writeln(t.toString());
sendAll(ir.source, plainHttpError(false, "400 Bad Request", t)); sendAll(ir.source, plainHttpError(false, "400 Bad Request", t));
closeConnection = true; closeConnection = true;
break; break;
@ -3303,7 +3311,14 @@ void cgiMainImpl(alias fun, CustomCgi = Cgi, long maxContentLength = defaultMaxC
closeConnection = true; closeConnection = true;
} catch(Throwable t) { } catch(Throwable t) {
// a processing error can be recovered from // a processing error can be recovered from
stderr.writeln(t.toString); version(CRuntime_Musl) {
// LockingTextWriter fails here
// so working around it
auto s = t.toString();
stderr.rawWrite(s);
} else {
stderr.writeln(t.toString);
}
if(!handleException(cgi, t)) if(!handleException(cgi, t))
closeConnection = true; closeConnection = true;
} }
@ -3387,7 +3402,9 @@ void cgiMainImpl(alias fun, CustomCgi = Cgi, long maxContentLength = defaultMaxC
int status; int status;
while(-1 != wait(&status)) { while(-1 != wait(&status)) {
version(CRuntime_Musl) {} else {
import std.stdio; writeln("Process died ", status); import std.stdio; writeln("Process died ", status);
}
processCount--; processCount--;
goto reopen; goto reopen;
} }
@ -3500,10 +3517,18 @@ void cgiMainImpl(alias fun, CustomCgi = Cgi, long maxContentLength = defaultMaxC
cgi._outputFileHandle = GetStdHandle(STD_OUTPUT_HANDLE); cgi._outputFileHandle = GetStdHandle(STD_OUTPUT_HANDLE);
else static assert(0); else static assert(0);
} catch(Throwable t) { } catch(Throwable t) {
stderr.writeln(t.msg); version(CRuntime_Musl) {
// the real http server will probably handle this; // LockingTextWriter fails here
// most likely, this is a bug in Cgi. But, oh well. // so working around it
stdout.write(plainHttpError(true, "400 Bad Request", t)); auto s = t.toString();
stderr.rawWrite(s);
stdout.rawWrite(plainHttpError(true, "400 Bad Request", t));
} else {
stderr.writeln(t.msg);
// the real http server will probably handle this;
// most likely, this is a bug in Cgi. But, oh well.
stdout.write(plainHttpError(true, "400 Bad Request", t));
}
return; return;
} }
assert(cgi !is null); assert(cgi !is null);