Skip to content

Commit c5f0400

Browse files
committed
[dmucs] Send empty notifications in the error cases.
1 parent 1fe8982 commit c5f0400

1 file changed

Lines changed: 44 additions & 19 deletions

File tree

dmucs/dmucs/monitor.cc

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,12 @@ main(int argc, char *argv[])
120120
(char *) clientPortStr.str().c_str());
121121
if (!client_sock) {
122122
fprintf(stderr, "Could not open client: %s\n", strerror(errno));
123-
Sclose(client_sock);
123+
Sclose(client_sock);
124+
#if __APPLE__
125+
NSMutableDictionary* Hosts = [NSMutableDictionary new];
126+
NSDistributedNotificationCenter* Notifier = [NSDistributedNotificationCenter defaultCenter];
127+
[Notifier postNotificationName:@"dmucsMonitorHosts" object:@"DMUCS" userInfo:Hosts options:(NSUInteger)NSNotificationPostToAllSessions];
128+
#endif
124129
sleep();
125130
continue;
126131
}
@@ -130,6 +135,11 @@ main(int argc, char *argv[])
130135
if (Sgets(resultStr, RESULT_MAX_SIZE, client_sock) == NULL) {
131136
fprintf(stderr, "Got error from reading socket.\n");
132137
Sclose(client_sock);
138+
#if __APPLE__
139+
NSMutableDictionary* Hosts = [NSMutableDictionary new];
140+
NSDistributedNotificationCenter* Notifier = [NSDistributedNotificationCenter defaultCenter];
141+
[Notifier postNotificationName:@"dmucsMonitorHosts" object:@"DMUCS" userInfo:Hosts options:(NSUInteger)NSNotificationPostToAllSessions];
142+
#endif
133143
return -1;
134144
}
135145
DMUCS_DEBUG((stderr, "monitor: got -->%s<--\n", resultStr));
@@ -232,29 +242,36 @@ parseResults(const char *resultStr)
232242
instr.ignore(); // eat ':'
233243
instr >> ipstr >> state >> ldAvg1 >> ldAvg5 >> ldAvg10;
234244
std::string hostname = ipstr;
235-
236-
unsigned int addr = inet_addr(ipstr.c_str());
237-
struct hostent *he = gethostbyaddr((char *)&addr, sizeof(addr),
238-
AF_INET);
239-
if (he) {
240-
hostname = he->h_name;
241-
}
242-
else {
243-
hostname = ipstr;
244-
}
245+
246+
unsigned int addr = inet_addr(ipstr.c_str());
247+
struct hostent *he = gethostbyaddr((char *)&addr,
248+
sizeof(addr), AF_INET);
249+
struct in_addr ip;
250+
if(!he && inet_aton(ipstr.c_str(), &ip))
251+
{
252+
he = gethostbyaddr((char *)&ip,
253+
sizeof(ip), AF_INET);
254+
}
255+
if (he) {
256+
hostname = he->h_name;
257+
}
258+
else {
259+
hostname = ipstr;
260+
}
245261

246262
/*
247263
* We collect each hostname based on its state, and add it
248264
* to an output string.
249265
*/
250266

251267
#if __APPLE__
268+
NSString* IPAddr = [NSString stringWithUTF8String: ipstr.c_str()];
252269
NSString* HostName = [NSString stringWithUTF8String: hostname.c_str()];
253270
NSNumber* StatusNum = [NSNumber numberWithInt:(int)state];
254271
NSNumber* ldAvg1_ = [NSNumber numberWithFloat:ldAvg1];
255272
NSNumber* ldAvg5_ = [NSNumber numberWithFloat:ldAvg5];
256273
NSNumber* ldAvg10_ = [NSNumber numberWithFloat:ldAvg10];
257-
NSMutableDictionary* Info = [NSMutableDictionary dictionaryWithObjectsAndKeys:HostName, @"HostName", StatusNum, @"Status", ldAvg1_, @"LoadAvg1", ldAvg5_, @"LoadAvg5", ldAvg10_, @"LoadAvg10", nil];
274+
NSMutableDictionary* Info = [NSMutableDictionary dictionaryWithObjectsAndKeys:IPAddr, @"IP", HostName, @"HostName", StatusNum, @"Status", ldAvg1_, @"LoadAvg1", ldAvg5_, @"LoadAvg5", ldAvg10_, @"LoadAvg10", nil];
258275
[Hosts setValue:Info forKey:HostName];
259276
#endif
260277

@@ -296,15 +313,23 @@ parseResults(const char *resultStr)
296313
linestr >> numCpus;
297314
linestr.ignore(); // eat ' '
298315

316+
299317
unsigned int addr = inet_addr(ipName);
300318
struct hostent *he = gethostbyaddr((char *)&addr,
301-
sizeof(addr), AF_INET);
302-
std::string hname;
303-
if (he == NULL) {
304-
hname = ipName;
305-
} else {
306-
hname = he->h_name;
307-
}
319+
sizeof(addr), AF_INET);
320+
struct in_addr ip;
321+
if(!he && inet_aton(ipName, &ip))
322+
{
323+
he = gethostbyaddr((char *)&ip,
324+
sizeof(ip), AF_INET);
325+
}
326+
327+
std::string hname;
328+
if (he == NULL) {
329+
hname = ipName;
330+
} else {
331+
hname = he->h_name;
332+
}
308333

309334
#if __APPLE__
310335
NSString* HostName = [NSString stringWithUTF8String: hname.c_str()];

0 commit comments

Comments
 (0)