aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet_testbed_mpi_spawn.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/gnunet_testbed_mpi_spawn.c')
-rw-r--r--src/testbed/gnunet_testbed_mpi_spawn.c63
1 files changed, 15 insertions, 48 deletions
diff --git a/src/testbed/gnunet_testbed_mpi_spawn.c b/src/testbed/gnunet_testbed_mpi_spawn.c
index 54b1fdf72..01cbd6576 100644
--- a/src/testbed/gnunet_testbed_mpi_spawn.c
+++ b/src/testbed/gnunet_testbed_mpi_spawn.c
@@ -171,37 +171,6 @@ child_death_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
171} 171}
172 172
173 173
174/**
175 * Callback function invoked for each interface found.
176 *
177 * @param cls NULL
178 * @param name name of the interface (can be NULL for unknown)
179 * @param isDefault is this presumably the default interface
180 * @param addr address of this interface (can be NULL for unknown or unassigned)
181 * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned)
182 * @param netmask the network mask (can be NULL for unknown or unassigned))
183 * @param addrlen length of the address
184 * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
185 */
186static int
187addr_proc (void *cls, const char *name, int isDefault,
188 const struct sockaddr *addr,
189 const struct sockaddr *broadcast_addr,
190 const struct sockaddr *netmask, socklen_t addrlen)
191{
192 const struct sockaddr_in *in_addr;
193 char *ipaddr;
194
195 if (sizeof (struct sockaddr_in) != addrlen)
196 return GNUNET_OK;
197 in_addr = (const struct sockaddr_in *) addr;
198 if (NULL == (ipaddr = inet_ntoa (in_addr->sin_addr)))
199 return GNUNET_OK;
200 GNUNET_array_append (our_addrs, num_addrs, GNUNET_strdup (ipaddr));
201 return GNUNET_OK;
202}
203
204
205static void 174static void
206destroy_hosts(struct GNUNET_TESTBED_Host **hosts, unsigned int nhosts) 175destroy_hosts(struct GNUNET_TESTBED_Host **hosts, unsigned int nhosts)
207{ 176{
@@ -229,11 +198,10 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
229 const struct GNUNET_CONFIGURATION_Handle *null_cfg; 198 const struct GNUNET_CONFIGURATION_Handle *null_cfg;
230 const char *host_ip; 199 const char *host_ip;
231 char *tmpdir; 200 char *tmpdir;
201 char *hostname;
202 size_t hostname_len;
232 unsigned int nhosts; 203 unsigned int nhosts;
233 unsigned int host_cnt; 204
234 unsigned int addr_cnt;
235
236 GNUNET_OS_network_interfaces_list (&addr_proc, NULL);
237 if (0 == num_addrs) 205 if (0 == num_addrs)
238 { 206 {
239 GNUNET_break (0); 207 GNUNET_break (0);
@@ -248,26 +216,25 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
248 ret = GNUNET_SYSERR; 216 ret = GNUNET_SYSERR;
249 return; 217 return;
250 } 218 }
251 for (host_cnt = 0; host_cnt < nhosts; host_cnt++) 219 hostname_len = GNUNET_OS_get_hostname_max_length ();
220 hostname = GNUNET_malloc (hostname_len);
221 if (0 != gethostname (hostname, hostname_len))
252 { 222 {
253 host_ip = GNUNET_TESTBED_host_get_hostname (hosts[host_cnt]); 223 LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot get hostname. Exiting\n");
254 for (addr_cnt = 0; addr_cnt < num_addrs; addr_cnt++) 224 GNUNET_free (hostname);
255 if (0 == strcmp (host_ip, our_addrs[addr_cnt])) 225 destroy_hosts (hosts, nhosts);
256 goto proceed; 226 ret = GNUNET_SYSERR;
227 return;
257 } 228 }
258 GNUNET_break (0); 229 if (NULL == strstr (GNUNET_TESTBED_host_get_hostname (hosts[0]), hostname))
259 ret = GNUNET_SYSERR;
260 destroy_hosts (hosts, nhosts);
261 return;
262
263 proceed:
264 destroy_hosts (hosts, nhosts);
265 if (0 != host_cnt)
266 { 230 {
267 LOG_DEBUG ("Exiting as we are not the lowest host\n"); 231 LOG_DEBUG ("Exiting as we are not the lowest host\n");
232 GNUNET_free (hostname);
268 ret = GNUNET_OK; 233 ret = GNUNET_OK;
269 return; 234 return;
270 } 235 }
236 GNUNET_free (hostname);
237 destroy_hosts (hosts, nhosts);
271 tmpdir = getenv ("TMPDIR"); 238 tmpdir = getenv ("TMPDIR");
272 if (NULL == tmpdir) 239 if (NULL == tmpdir)
273 tmpdir = getenv ("TMP"); 240 tmpdir = getenv ("TMP");