2935{
2936 if (false)
2937 {
2938 error:
2939 perror("Failed to send targets to server");
2940 exit(EXIT_FAILURE);
2941 }
2942 if (targets.empty()) exit(EXIT_SUCCESS);
2944
2945
2946#ifdef WINDOWS
2947 struct sockaddr_in socket_addr;
2948 socket_fd = socket(AF_INET, SOCK_STREAM, 0);
2950 socket_addr.sin_family = AF_INET;
2951 socket_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
2953 if (connect(
socket_fd, (
struct sockaddr *)&socket_addr,
sizeof(sockaddr_in)))
2954 goto error;
2955#else
2956 struct sockaddr_un socket_addr;
2958 if (len >= sizeof(socket_addr.sun_path) - 1) exit(EXIT_FAILURE);
2959 socket_fd = socket(AF_UNIX, SOCK_STREAM, 0);
2961 socket_addr.sun_family = AF_UNIX;
2963 if (connect(
socket_fd, (
struct sockaddr *)&socket_addr,
sizeof(socket_addr.sun_family) + len))
2964 goto error;
2965#ifdef MACOSX
2966 int set_option = 1;
2967 if (setsockopt(
socket_fd, SOL_SOCKET, SO_NOSIGPIPE, &set_option,
sizeof(set_option)))
2968 goto error;
2969#endif
2970#endif
2971
2972
2973 char *id = getenv("REMAKE_JOB_ID");
2974 int job_id = id ? atoi(id) : -1;
2975 if (send(
socket_fd, (
char *)&job_id,
sizeof(job_id), MSG_NOSIGNAL) !=
sizeof(job_id))
2976 goto error;
2977
2978
2979 for (string_list::const_iterator i = targets.begin(),
2980 i_end = targets.end(); i != i_end; ++i)
2981 {
2982 DEBUG_open <<
"Sending target " << *i <<
"... ";
2983 std::string s = 'T' + *i;
2984 ssize_t len = s.length() + 1;
2985 if (send(
socket_fd, s.c_str(), len, MSG_NOSIGNAL) != len)
2986 goto error;
2987 }
2988
2989
2990 for (variable_map::const_iterator i =
variables.begin(),
2991 i_end =
variables.end(); i != i_end; ++i)
2992 {
2993 DEBUG_open <<
"Sending variable " << i->first <<
"... ";
2994 std::string s = 'V' + i->first;
2995 ssize_t len = s.length() + 1;
2996 if (send(
socket_fd, s.c_str(), len, MSG_NOSIGNAL) != len)
2997 goto error;
2998 for (string_list::const_iterator j = i->second.begin(),
2999 j_end = i->second.end(); j != j_end; ++j)
3000 {
3001 std::string s = 'W' + *j;
3002 len = s.length() + 1;
3003 if (send(
socket_fd, s.c_str(), len, MSG_NOSIGNAL) != len)
3004 goto error;
3005 }
3006 }
3007
3008
3009 char result = 0;
3010 if (send(
socket_fd, &result, 1, MSG_NOSIGNAL) != 1)
goto error;
3011 if (recv(
socket_fd, &result, 1, 0) != 1) exit(EXIT_FAILURE);
3012 exit(result ? EXIT_SUCCESS : EXIT_FAILURE);
3013}
static variable_map variables
static char * socket_name
static socket_t socket_fd