/[escript]/release/5.2/tools/overlord/overlord.cpp
ViewVC logotype

Contents of /release/5.2/tools/overlord/overlord.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6692 - (show annotations)
Mon Jun 25 02:31:06 2018 UTC (3 years, 2 months ago) by jfenwick
File size: 1964 byte(s)
Fix

1 /*****************************************************************************
2 *
3 * Copyright (c) 2003-2018 by The University of Queensland
4 * http://www.uq.edu.au
5 *
6 * Primary Business: Queensland, Australia
7 * Licensed under the Apache License, version 2.0
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11 * Development 2012-2013 by School of Earth Sciences
12 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
13 *
14 *****************************************************************************/
15
16 #include <stdlib.h>
17 #include <unistd.h>
18 #include <stdio.h>
19 #include <string.h>
20 #include <errno.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
23 #include <arpa/inet.h>
24
25 int main(int argc, char **argv) {
26 int key = 0, port = 0, sfd = 0;
27 FILE *escript = NULL;
28 struct sockaddr_in sa;
29
30 if (argc < 4) {
31 fprintf(stderr, "Missing minimum arguments: %s port key cmd [args]\n",
32 argv[0]);
33 return 1;
34 }
35 key = atoi(argv[2]);
36 port = atoi(argv[1]);
37
38
39 sa.sin_family = AF_INET;
40 sa.sin_port = htons(port);
41 sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
42 memset(sa.sin_zero, '\0', sizeof(sa.sin_zero));
43
44 sfd = socket(PF_INET, SOCK_STREAM, 0);
45 if (sfd < 0) {
46 perror("overlord socket creation failed");
47 return 1;
48 }
49
50 if (connect(sfd, (struct sockaddr*)&sa, sizeof(sa)) < 0) {
51 perror("overlord connect() call failed");
52 return 1;
53 }
54
55 escript = fdopen(sfd, "w");
56 if (escript == NULL) {
57 perror("overlord failed to open file descriptor for writes");
58 return 1;
59 }
60 if (fwrite(&key, sizeof(int), 1, escript) != 1) {
61 fprintf(stderr, "overlord failed to initialise communication with escript\n");
62 return 1;
63 }
64
65 fflush(escript);
66 execvp(argv[3], argv+3);
67 perror("overlord exec failed");
68 return 1;
69 }
70

  ViewVC Help
Powered by ViewVC 1.1.26