forktcpservicer.c (1362B)
1 /************************************************************************* 2 * This file is part of Crosroads 1.23, a load balancer and fail over 3 * utility for TCP. Copyright (c) Karel Kubat, distributed under GPL. 4 * Visit http://crossroads.e-tunity.com for information. 5 *************************************************************************/ 6 #include "crossroads.h" 7 8 int fork_tcp_servicer (int to_backend) { 9 int pid, i; 10 11 if ( (pid = fork()) < 0 ) 12 /* Fork failure */ 13 error ("Service %s: failed to fork: %s", 14 activeservice->name, strerror(errno)); 15 else if (pid) { 16 /* Parent branch */ 17 msg ("Service %s: communications will be handled by pid %d", 18 activeservice->name, pid); 19 return (pid); 20 } else { 21 /* Child branch: here we will serve the socket pair. 22 * We want to catch interrupts, but not die. */ 23 for (i = 0; relevant_sigs[i]; i++) 24 signal (relevant_sigs[i], interrupt); 25 26 /* Forked for the second time... */ 27 program_stage = stage_serving; 28 29 if (to_backend > 0) 30 set_program_title ("Service %s: serving %s to %s", 31 client_ip, 32 activeservice->name, 33 activeservice->backend [current_backend].name); 34 else 35 set_program_title ("Service %s: serving %s", 36 client_ip, 37 activeservice->name); 38 return (0); 39 } 40 41 /* To satisfy the prototype... */ 42 return (0); 43 }