version 1.1, 1999/11/23 19:27:17
|
version 1.2, 1999/12/01 18:49:27
|
Line 1
|
Line 1
|
#include "lonnet.h" |
|
#include <stdio.h> |
#include <stdio.h> |
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <sys/socket.h> |
#include <linux/un.h> |
#include <sys/un.h> |
|
#include <time.h> |
|
#include "lonnet.h" |
|
|
/*lonnet.c (by Guy Albertelli); based on lonnet.pm by Gerd Kortemeyer*/ |
/*lonnet.c (by Guy Albertelli); based on lonnet.pm by Gerd Kortemeyer*/ |
|
|
Line 80 char *subreply (char* cmd, char* server)
|
Line 80 char *subreply (char* cmd, char* server)
|
|
|
if (length > UNIX_PATH_MAX) { |
if (length > UNIX_PATH_MAX) { |
fprintf(stderr,"Path to socket too long:%d\n",length); |
fprintf(stderr,"Path to socket too long:%d\n",length); |
sprintf(answer,"Path to socket too long:%d\n",length); |
sprintf(answer,"con_lost",length); |
return answer; |
return answer; |
} |
} |
|
|
Line 92 char *subreply (char* cmd, char* server)
|
Line 92 char *subreply (char* cmd, char* server)
|
if (bind (sockFD, (struct sockaddr *) &lonc, |
if (bind (sockFD, (struct sockaddr *) &lonc, |
strlen(lonc.sun_path) + sizeof(lonc.sun_family))) { |
strlen(lonc.sun_path) + sizeof(lonc.sun_family))) { |
fprintf(stderr,"Bind failed to %s\n",peerfile); |
fprintf(stderr,"Bind failed to %s\n",peerfile); |
sprintf(answer,"Bind failed to %s\n",peerfile); |
sprintf(answer,"con_lost",peerfile); |
return answer; |
return answer; |
} |
} |
|
|
Line 120 char *subreply (char* cmd, char* server)
|
Line 120 char *subreply (char* cmd, char* server)
|
char * reply (char *cmd,char *server) { |
char * reply (char *cmd,char *server) { |
char *answer=NULL; |
char *answer=NULL; |
answer=subreply(cmd,server); |
answer=subreply(cmd,server); |
if (strcmp(answer,"con_lost")) { |
if (strcmp(answer,"con_lost")==0) { |
free(answer); |
free(answer); |
answer=subreply(cmd,server); |
answer=subreply(cmd,server); |
} |
} |
return answer; |
return answer; |
} |
} |
|
|
/* |
char * critical(char* cmd, char* server) { |
sub subreply { |
char *answer,*buf; |
my ($cmd,$server)=@_; |
answer = reply(cmd,server); |
my $peerfile="$perlvar{'lonSockDir'}/$server"; |
if (strcmp(answer,"con_lost")==0) { |
my $client=IO::Socket::UNIX->new(Peer =>"$peerfile", |
/*no connection, the perl version attempts reconnect, I'll just save |
Type => SOCK_STREAM, |
the message for loncron to send */ |
Timeout => 10) |
time_t now=time(NULL); |
or return "con_lost"; |
char middlename[MAX_BUFFER_SIZE]; /* string fromed from the cmd to |
print $client "$cmd\n"; |
make a uniqueish filename */ |
my $answer=<$client>; |
char filename[MAX_BUFFER_SIZE],*wcmd,*tempbuf; |
chomp($answer); |
int found=0,i,j; |
if (!$answer) { $answer="con_lost"; } |
|
return $answer; |
sprintf(filename,"%s/delayed/%d.%s.XXXXXX",lonSockDir,now,server); |
} |
outfile=mkstemp(filename); |
|
fprintf(outfile,"%s:%s\n",server,cmd); |
# ------------------------------------------------------ Critical communication |
fflush(outfile); |
sub critical { |
fclose(outfile); |
my ($cmd,$server)=@_; |
/* check to make sure it really did write the message */ |
&senddelayed($server); |
outfile=fopen(filename,"r"); |
my $answer=reply($cmd,$server); |
wcmd=fullread(outfile); |
if ($answer eq 'con_lost') { |
tempbuf=(char*)malloc(strlen(server)+1+strlen(cmd)+2); |
my $pingreply=reply('ping',$server); |
sprintf(tempbuf,"%s:%s\n",server,cmd); |
&reconlonc("$perlvar{'lonSockDir'}/$server"); |
if (strcmp(tempbuf,wcmd)==0) { |
my $pongreply=reply('pong',$server); |
buf=(char*)malloc(strlen(wcmd)+strlen(filename)+MAX_BUFFER_LENGTH); |
&logthis("Ping/Pong for $server: $pingreply/$pongreply"); |
sprintf(buf,"Connection buffer %s: %s",filename,cmd); |
$answer=reply($cmd,$server); |
logthis(buf); |
if ($answer eq 'con_lost') { |
free(buf); |
my $now=time; |
buf=(char*)malloc(strlen(server)+strlen(cmd)+MAX_BUFFER_LENGTH); |
my $middlename=$cmd; |
sprintf(buf,"D:%s:%s",server,cmd); |
$middlename=~s/\W//g; |
logperm(buf); |
my $dfilename= |
free(buf); |
"$perlvar{'lonSockDir'}/delayed/$now.$middlename.$server"; |
} else { |
{ |
buf=(char*)malloc(strlen(wcmd)+strlen(filename)+MAX_BUFFER_LENGTH); |
my $dfh; |
sprintf(buf,"CRITICAL CONNECTION FAILED: %s %s",server,cmd); |
if ($dfh=Apache::File->new(">$dfilename")) { |
logthis(buf); |
print $dfh "$server:$cmd\n"; |
free(buf); |
} |
buf=(char*)malloc(strlen(server)+strlen(cmd)+MAX_BUFFER_LENGTH); |
} |
sprintf(buf,"F:%s:%s",server,cmd); |
sleep 2; |
logperm(buf); |
my $wcmd=''; |
free(buf); |
{ |
|
my $dfh; |
|
if ($dfh=Apache::File->new("$dfilename")) { |
|
$wcmd=<$dfh>; |
|
} |
|
} |
|
chomp($wcmd); |
|
if ($wcmd eq "$server:$cmd") { |
|
&logthis("Connection buffer $dfilename: $cmd"); |
|
&logperm("D:$server:$cmd"); |
|
return 'con_delayed'; |
|
} else { |
|
&logthis("CRITICAL CONNECTION FAILED: $server $cmd"); |
|
&logperm("F:$server:$cmd"); |
|
return 'con_failed'; |
|
} |
|
} |
|
} |
} |
return $answer; |
} |
|
return answer; |
} |
} |
*/ |
|
|
|
/* need |
/* need |
- logthis |
- logthis |
- logperm |
- logperm |
- reconlonc, maybe, don't absolutely need to make critical reconnect |
- fullread |
*/ |
*/ |
|
|
int main() { |
int main() { |