Skip to content

Commit

Permalink
Merge branch 'egil/change-os_mon-ports-error-messages/OTP-10161' into…
Browse files Browse the repository at this point in the history
… maint

* egil/change-os_mon-ports-error-messages/OTP-10161:
  os_mon: Elucidate port program error messages
  • Loading branch information
psyeugenic committed Jul 25, 2012
2 parents c0cb221 + 0da1a7b commit 9f6993f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 32 deletions.
14 changes: 12 additions & 2 deletions lib/os_mon/c_src/cpu_sup.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,18 @@ static void error(char* err_msg) {
* if we get error here we have trouble,
* silence unnecessary warnings
*/
if(write(FD_ERR, err_msg, strlen(err_msg)));
if(write(FD_ERR, "\n", 1));
char buffer[256] = "[os_mon] cpu supervisor port (cpu_sup): ";
int i = strlen(buffer), j = 0;
int n = strlen(err_msg);

while(i < 253 && j < n) {
buffer[i++] = err_msg[j++];
}
buffer[i++] = '\r';
buffer[i++] = '\n';

/* try to use one write only */
if(write(FD_ERR, buffer, i));
exit(-1);
}

Expand Down
25 changes: 11 additions & 14 deletions lib/os_mon/c_src/memsup.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ get_basic_mem(unsigned long *tot, unsigned long *used, unsigned long *pagesize){
#elif defined(__linux__) && !defined(_SC_AVPHYS_PAGES)
memory_ext me;
if (get_mem_procfs(&me) < 0) {
print_error("ProcFS read error.");
print_error("ProcFS read error");
exit(1);
}
*tot = me.total;
Expand Down Expand Up @@ -582,7 +582,7 @@ message_loop(int erlin_fd)
* Wait for command from Erlang
*/
if ((res = read(erlin_fd, &cmdLen, 1)) < 0) {
print_error("Error reading from Erlang.");
print_error("Error reading from Erlang");
return;
}

Expand All @@ -603,19 +603,19 @@ message_loop(int erlin_fd)
break;

case 0:
print_error("Erlang has closed.");
print_error("Erlang has closed");
return;

default:
print_error("Error reading from Erlang.");
print_error("Error reading from Erlang");
return;
} /* switch() */
} else { /* cmdLen != 1 */
print_error("Invalid command length (%d) received.", cmdLen);
print_error("Invalid command length (%d) received", cmdLen);
return;
}
} else { /* Erlang end closed */
print_error("Erlang has closed.");
print_error("Erlang has closed");
return;
}
}
Expand All @@ -641,15 +641,12 @@ static void
print_error(const char *format,...)
{
va_list args;
char buffer[256];

va_start(args, format);
fprintf(stderr, "%s: ", program_name);
vfprintf(stderr, format, args);
vsnprintf(buffer, 256, format, args);
va_end(args);
fprintf(stderr, " \n");
/* try to use one write only */
fprintf(stderr, "[os_mon] memory supervisor port (memsup): %s\r\n", buffer);
fflush(stderr);
}





30 changes: 14 additions & 16 deletions lib/os_mon/c_src/win32sysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ typedef BOOL (WINAPI *tfpGetDiskFreeSpaceEx)(LPCTSTR, PULARGE_INTEGER,PULARGE_IN

static tfpGetDiskFreeSpaceEx fpGetDiskFreeSpaceEx;

static void print_error(const char *msg);
static void
return_answer(char* value)
{
Expand All @@ -98,7 +99,7 @@ return_answer(char* value)

res = write(1,(char*) &bytes,1);
if (res != 1) {
fprintf(stderr,"win32sysinfo:Error writing to pipe");
print_error("Error writing to pipe");
exit(1);
}

Expand All @@ -107,9 +108,8 @@ return_answer(char* value)
while (left > 0)
{
res = write(1, value+bytes-left, left);
if (res <= 0)
{
fprintf(stderr,"win32sysinfo:Error writing to pipe");
if (res <= 0) {
print_error("Error writing to pipe");
exit(1);
}
left -= res;
Expand Down Expand Up @@ -248,7 +248,6 @@ message_loop()
char cmd[512];
int res;

fprintf(stderr,"in message_loop\n");
/* Startup ACK. */
return_answer(OK);
while (1)
Expand All @@ -257,12 +256,12 @@ message_loop()
* Wait for command from Erlang
*/
if ((res = read(0, &cmdLen, 1)) < 0) {
fprintf(stderr,"win32sysinfo:Error reading from Erlang.");
print_error("Error reading from Erlang");
return;
}

if (res != 1){ /* Exactly one byte read ? */
fprintf(stderr,"win32sysinfo:Erlang has closed.");
print_error("Erlang has closed");
return;
}
if ((res = read(0, &cmd, cmdLen)) == cmdLen){
Expand Down Expand Up @@ -291,11 +290,11 @@ message_loop()
return_answer("xEND");
}
else if (res == 0) {
fprintf(stderr,"win32sysinfo:Erlang has closed.");
print_error("Erlang has closed");
return;
}
else {
fprintf(stderr,"win32sysinfo:Error reading from Erlang.");
print_error("Error reading from Erlang");
return;
}
}
Expand All @@ -309,10 +308,9 @@ int main(int argc, char ** argv){
message_loop();
return 0;
}







static void
print_error(const char *msg) {
/* try to use one write only */
fprintf(stderr, "[os_mon] win32 supervisor port (win32sysinfo): %s\r\n", msg);
fflush(stderr);
}

0 comments on commit 9f6993f

Please sign in to comment.