pike.git
/
NT
/
tools
/
sprshd
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/NT/tools/sprshd:1:
#!/usr/local/bin/pike inherit Stdio.Port;
+
#if !constant(Stdio.PROP_IPC)
+
#define NO_IPC
+
#endif
+
// Bugfix for some older versions of Pike.. string combine_path(string s, string ... rest) { for(int e=0;e<sizeof(rest);e++) { if(sscanf(rest[e],"%*[a-zA-Z]:%*s")==2) { s=rest[e]; }else{ s=predef::combine_path(s,rest[e]);
pike.git/NT/tools/sprshd:62:
{ proc->wait(); if(io) { io->close("rw"); io->close(); destruct(io); } }
+
#ifdef WINE
+
void my_proxy(Stdio.File from, Stdio.File to)
+
{
+
while(string s=from->read(128,1))
+
if(to->write(s)!=strlen(s))
+
return;
+
+
}
+
#endif
+
void handle_incoming_connection(object(Stdio.File) io) { object p; sscanf(io->read(4),"%4c",int args); string *cmd=allocate(args); for(int e=0;e<args;e++) { sscanf(io->read(4),"%4c",int len); cmd[e]=io->read(len); } object pi=Stdio.File();
-
#
if
constant(Stdio.PROP
_IPC
)
-
object p2=pi->pipe(Stdio.PROP_IPC);
-
#else
+
#
ifdef
NO
_IPC
object p2=pi->pipe();
-
+
#else
+
object p2=pi->pipe(Stdio.PROP_IPC);
#endif string dir=cmd[0]; cmd=cmd[1..]; write("Doing "+cmd*" "+"\n"); switch(lower_case(cmd[0])) { case "mkdir": {
pike.git/NT/tools/sprshd:137:
case "getenv": { string s=getenv(cmd[1])+"\n"; io->write(sprintf("%4c%s",strlen(s),s)); io->write(sprintf("%4c",0)); io->write(sprintf("%4c",0)); break; } default:
+
#ifdef WINE
+
{
+
werror("Proxying.....\n");
+
object p3=Stdio.File();
+
#ifdef NO_IPC
+
object p4=p3->pipe();
+
#else
+
object p4=p3->pipe(Stdio.PROP_IPC);
+
#endif
+
thread_create(my_proxy,io,p4);
+
io=p3;
+
}
+
#endif
+
mixed err=catch { p=Process.create_process(cmd, ([
-
+
#ifndef WINE
"stdin":io, "stdout":p2, "stderr":p2,
-
+
#endif
"cwd":dir, ])); }; destruct(p2); if(!err) {
-
#
if
!constant(Stdio.PROP
_IPC
)
+
#
ifdef
NO
_IPC
thread_create(monitor,p2,p); #endif while(1) { string s=pi->read(1000,1); if(!s || !strlen(s)) break; io->write(sprintf("%4c%s",strlen(s),s)); } io->write(sprintf("%4c",0)); io->write(sprintf("%4c",p->wait())); }else{
-
+
werror(master()->describe_backtrace(err));
destruct(p2); io->write(sprintf("%4c",0)); io->write(sprintf("%4c",69)); } } io->close("w"); destruct(io); }
-
+
void handle_connections(string *hosts)
+
{
+
while(1)
+
{
+
if(object io=accept())
+
{
+
sscanf(io->query_address(),"%s ",string ip);
+
if(search(hosts, ip)==-1)
+
{
+
destruct(io);
+
continue;
+
}
+
thread_create(handle_incoming_connection,io);
+
}else{
+
werror("Accept failed "+errno()+"\n");
+
}
+
}
+
}
+
int main(int argc, string *argv) {
-
+
#ifdef WINE
+
werror("Running in WINE mode.\n");
+
#endif
if(argc<2) { werror("Usage: sprshd <port> <hosts to accept connections from>\n"); exit(1); } if(!bind((int)argv[1])) { werror("Failed to bind port.\n"); exit(1); }
pike.git/NT/tools/sprshd:202:
mixed tmp=gethostbyname(argv[e]); if(!tmp) { werror("Gethostbyname("+argv[e]+") failed.\n"); exit(1); } hosts+=tmp[1]; } write("Ready ("+version()+").\n");
-
while(1)
-
{
-
if
(
object io=accept(
)
)
-
{
-
sscanf
(
io->query_address(),
"
%s
"
,string ip
);
-
if(search(hosts, ip)==
-1
)
-
{
-
destruct
(
io
);
-
continue
;
+
+
#ifdef
WINE
+
thread_create
(
handle_connections,hosts
)
;
+
werror
("
main
returning...\n
");
+
return
-1
;
+
#else
+
handle_connection
(
hosts
);
+
return
0
;
+
#endif
}
-
thread_create(handle_incoming_connection,io);
-
}else{
-
werror("Accept failed "+errno()+"\n");
-
}
-
}
-
}
+