diff options
Diffstat (limited to 'lib/os_mon/c_src')
-rw-r--r-- | lib/os_mon/c_src/Makefile.in | 10 | ||||
-rw-r--r-- | lib/os_mon/c_src/cpu_sup.c | 16 | ||||
-rw-r--r-- | lib/os_mon/c_src/memsup.c | 96 | ||||
-rw-r--r-- | lib/os_mon/c_src/win32sysinfo.c | 32 |
4 files changed, 43 insertions, 111 deletions
diff --git a/lib/os_mon/c_src/Makefile.in b/lib/os_mon/c_src/Makefile.in index 45dc01e993..e728e43a09 100644 --- a/lib/os_mon/c_src/Makefile.in +++ b/lib/os_mon/c_src/Makefile.in @@ -1,7 +1,7 @@ # # %CopyrightBegin% # -# Copyright Ericsson AB 1997-2011. All Rights Reserved. +# Copyright Ericsson AB 1997-2012. All Rights Reserved. # # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in @@ -63,14 +63,10 @@ ENTRY_OBJ=$(ERL_TOP)/erts/obj/$(TARGET)/port_entry.o PORT_ENTRY_POINT=erl_port_entry ENTRY_LDFLAGS=-entry:$(PORT_ENTRY_POINT) else -ifeq ($(findstring vxworks_simso,$(TARGET)),vxworks_simso) -PROGRAMS = -else PROGRAMS = \ memsup @os_mon_programs@ C_FILES= $(PROGRAMS:%=%.c) endif -endif TARGET_FILES= $(PROGRAMS:%=$(BINDIR)/%) @@ -127,14 +123,10 @@ $(OBJDIR)/memsup.o: memsup.h # ---------------------------------------------------- include $(ERL_TOP)/make/otp_release_targets.mk -ifeq ($(findstring vxworks_simso,$(TARGET)),vxworks_simso) -release_spec: -else release_spec: opt $(INSTALL_DIR) "$(RELSYSDIR)/src" $(INSTALL_DATA) $(C_FILES) "$(RELSYSDIR)/src" $(INSTALL_DIR) "$(RELSYSDIR)/priv/bin" $(INSTALL_PROGRAM) $(TARGET_FILES) "$(RELSYSDIR)/priv/bin" -endif release_docs_spec: diff --git a/lib/os_mon/c_src/cpu_sup.c b/lib/os_mon/c_src/cpu_sup.c index 9c5f9a6aa5..7372d5b0e8 100644 --- a/lib/os_mon/c_src/cpu_sup.c +++ b/lib/os_mon/c_src/cpu_sup.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1997-2011. All Rights Reserved. + * Copyright Ericsson AB 1997-2012. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -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); } diff --git a/lib/os_mon/c_src/memsup.c b/lib/os_mon/c_src/memsup.c index 078f20ff98..3a1a8e9444 100644 --- a/lib/os_mon/c_src/memsup.c +++ b/lib/os_mon/c_src/memsup.c @@ -31,7 +31,7 @@ * * This program is started from Erlang as follows, * - * Port = open_port({spawn, 'memsup'}, [{packet,1}]) for UNIX and VxWorks + * Port = open_port({spawn, 'memsup'}, [{packet,1}]) for UNIX * * Erlang sends one of the request condes defined in memsup.h and this program * answers in one of two ways: @@ -75,10 +75,6 @@ * that there is no process at the other end of the connection * having the connection open for writing (end-of-file). * - * COMPILING - * - * When the target is VxWorks the identifier VXWORKS must be defined for - * the preprocessor (usually by a -D option). */ #if defined(sgi) || defined(__sgi) || defined(__sgi__) @@ -90,9 +86,7 @@ #include <stddef.h> #include <stdlib.h> -#ifndef VXWORKS #include <unistd.h> -#endif #if (defined(__unix__) || defined(unix)) && !defined(USG) #include <sys/param.h> @@ -104,12 +98,6 @@ #include <time.h> #include <errno.h> -#ifdef VXWORKS -#include <vxWorks.h> -#include <ioLib.h> -#include <memLib.h> -#endif - #ifdef BSD4_4 #include <sys/types.h> #include <sys/sysctl.h> @@ -143,20 +131,8 @@ /* prototypes */ static void print_error(const char *,...); -#ifdef VXWORKS -extern int erl_mem_info_get(MEM_PART_STATS *); -#endif - -#ifdef VXWORKS -#define MAIN memsup -static MEM_PART_STATS latest; -static unsigned long latest_system_total; /* does not fit in the struct */ - -#else #define MAIN main -#endif - /* * example, we want procfs information, now give them something equivalent: @@ -282,16 +258,6 @@ send_tag(int value){ } } - -#ifdef VXWORKS -static void load_statistics(void){ - if(memPartInfoGet(memSysPartId,&latest) != OK) - memset(&latest,0,sizeof(latest)); - latest_system_total = latest.numBytesFree + latest.numBytesAlloc; - erl_mem_info_get(&latest); /* if it fails, latest is untouched */ -} -#endif - #ifdef BSD4_4 static int get_vmtotal(struct vmtotal *vt) { @@ -358,19 +324,6 @@ get_mem_procfs(memory_ext *me){ /* arch specific functions */ -#if defined(VXWORKS) -static int -get_extended_mem_vxwork(memory_ext *me) { - load_statistics(); - me->total = (latest.numBytesFree + latest.numBytesAlloc); - me->free = latest.numBytesFree; - me->pagesize = 1; - me->flag = F_MEM_TOTAL | F_MEM_FREE; - return 1; -} -#endif - - #if defined(__linux__) /* ifdef SYSINFO */ /* sysinfo does not include cached memory which is a problem. */ static int @@ -442,12 +395,8 @@ get_extended_mem_sgi(memory_ext *me) { static void get_extended_mem(memory_ext *me) { -/* vxworks */ -#if defined(VXWORKS) - if (get_extended_mem_vxworks(me)) return; - /* linux */ -#elif defined(__linux__) +#if defined(__linux__) if (get_mem_procfs(me)) return; if (get_extended_mem_sysinfo(me)) return; @@ -477,12 +426,7 @@ get_extended_mem(memory_ext *me) { static void get_basic_mem(unsigned long *tot, unsigned long *used, unsigned long *pagesize){ -#if defined(VXWORKS) - load_statistics(); - *tot = (latest.numBytesFree + latest.numBytesAlloc); - *used = latest.numBytesAlloc; - *pagesize = 1; -#elif defined(_SC_AVPHYS_PAGES) /* Does this exist on others than Solaris2? */ +#if defined(_SC_AVPHYS_PAGES) /* Does this exist on others than Solaris2? */ unsigned long avPhys, phys, pgSz; phys = sysconf(_SC_PHYS_PAGES); @@ -493,7 +437,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; @@ -557,17 +501,8 @@ extended_show_mem(void){ if (me.flag & F_SWAP_TOTAL) { send_tag(SWAP_TOTAL); send(me.total_swap, ps); } if (me.flag & F_SWAP_FREE) { send_tag(SWAP_FREE); send(me.free_swap, ps); } -#ifdef VXWORKS - send_tag(SM_SYSTEM_TOTAL); - send(latest_system_total, 1); - send_tag(SM_LARGEST_FREE); - send(latest.maxBlockSizeFree, 1); - send_tag(SM_NUMBER_OF_FREE); - send(latest.numBlocksFree, 1); -#else /* total is system total*/ if (me.flag & F_MEM_TOTAL) { send_tag(MEM_SYSTEM_TOTAL); send(me.total, ps); } -#endif send_tag(SHOW_SYSTEM_MEM_END); } @@ -582,7 +517,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; } @@ -603,19 +538,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; } } @@ -641,15 +576,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); } - - - - - diff --git a/lib/os_mon/c_src/win32sysinfo.c b/lib/os_mon/c_src/win32sysinfo.c index 2a155aae87..f02ae637b2 100644 --- a/lib/os_mon/c_src/win32sysinfo.c +++ b/lib/os_mon/c_src/win32sysinfo.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1997-2009. All Rights Reserved. + * Copyright Ericsson AB 1997-2012. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -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) { @@ -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); } @@ -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; @@ -248,7 +248,6 @@ message_loop() char cmd[512]; int res; - fprintf(stderr,"in message_loop\n"); /* Startup ACK. */ return_answer(OK); while (1) @@ -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){ @@ -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; } } @@ -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); +} |