modify p-client child return value

This commit is contained in:
ubuntu201711081 2020-12-04 10:13:56 +00:00
parent aaeba28fb8
commit 50eb6f4cf7

View File

@ -266,6 +266,7 @@ int main(int argc, const char *argv[]){
int fd, pid; int fd, pid;
char ip_buf[INET_ADDRSTRLEN]; char ip_buf[INET_ADDRSTRLEN];
const char * msg; const char * msg;
int retval = 0;
if((csock = accept(sock, (struct sockaddr *)&client_addr,&client_addr_len)) < 0){ if((csock = accept(sock, (struct sockaddr *)&client_addr,&client_addr_len)) < 0){
free(buf); free(buf);
perror("accept error"); perror("accept error");
@ -276,13 +277,14 @@ int main(int argc, const char *argv[]){
pid = fork(); pid = fork();
if(pid == 0){ if(pid == 0){
if((fd = read_request(csock,buf,bufsize)) > 0){ if((fd = read_request(csock,buf,bufsize)) > 0){
send_response(csock,fd,buf,bufsize); retval = send_response(csock,fd,buf,bufsize);
close(fd); close(fd);
} }
else retval = fd;
if(close(csock) < 0) if(close(csock) < 0)
perror("csock close error"); perror("csock close error");
free(buf); free(buf);
return 0; return retval;
} }
} }
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)