diff --git a/agent/Makefile b/agent/Makefile index 8838eea..3cbfa29 100644 --- a/agent/Makefile +++ b/agent/Makefile @@ -27,6 +27,10 @@ $(EXECUTABLE): $(OBJECTS) @echo ' CC $@' @$(CC) $(CCFLAGS) -c $< -o $@ +debug: CCFLAGS = -O0 -g -Q +debug: $(SOURCES) $(EXECUTABLE) + @echo ' Compiling debug with $(CCFLAGS)' + clean: rm -rf $(OBJECTS) $(EXECUTABLE) diff --git a/agent/agent.c b/agent/agent.c index f1ccb2a..5c2521b 100644 --- a/agent/agent.c +++ b/agent/agent.c @@ -201,3 +201,4 @@ int main(int count, char *strings[]) close(server); /* close socket */ SSL_CTX_free(ctx); /* release context */ } + diff --git a/agent/job.c b/agent/job.c index f170f9b..056a457 100644 --- a/agent/job.c +++ b/agent/job.c @@ -5,6 +5,7 @@ #include "job.h" #include #include +#include struct job_t { long id; @@ -144,9 +145,11 @@ void* get_memory(void *args) freepages = sysconf(_SC_AVPHYS_PAGES); job->buf.meta.len = sprintf( (char*)job->buf.chunk.data, "%ld / %ld (MB)", - (freepages * pagesize) / 1048576 /* 1024*1024 */, - (pages * pagesize) / 1048576 ); + ((pages - freepages) * pagesize) / 1048576 /* 1024*1024 */, + (pages * pagesize) / 1048576 ); SSL_write(job->ssl, &job->buf, sizeof(struct msg)); job->slot = FREE; - return 0; + //return 0; + pthread_detach(pthread_self()); + pthread_exit(NULL); } diff --git a/enum_codes b/enum_codes index 74e07ff..31ecdb8 100644 --- a/enum_codes +++ b/enum_codes @@ -12,4 +12,4 @@ 202:CONF_DIR_PERM_INSECURE:"Insecure global permissions for /etc/rmps. Should be 0770!" 203:CONF_FILE_GID_INSECURE:"Insecure group for /etc/rmps/rmps.conf. Should be 'rmps'!" 204:CONF_FILE_UID_INSECURE:"Insecure owner for /etc/rmps/rmps.conf. Should be 'root'!" -205:CONF_FILE_PERM_INSECURE:"Insecure global permissions /etc/rmps/rmps.conf". Shold be 0660!" +205:CONF_FILE_PERM_INSECURE:"Insecure global permissions /etc/rmps/rmps.conf. Shold be 0660!" diff --git a/log_trace.c b/log_trace.c index c2af75f..ecea6bd 100644 --- a/log_trace.c +++ b/log_trace.c @@ -15,8 +15,12 @@ static void open_logs(void) { if ((fderr = fopen(conf.rmps.errlog, "a")) == NULL) fderr = stderr; + else + setvbuf(fderr, NULL, _IOLBF, 0); if ((fdout = fopen(conf.rmps.logfile, "a")) == NULL) fdout = stdout; + else + setvbuf(fdout, NULL, _IOLBF, 0); } void log_ssl(void) @@ -65,7 +69,6 @@ void log_trace(LOG_LEVEL lvl, char *fmt, ... ) va_start(list, fmt); vfprintf(fp, fmt_with_pfx, list); - fflush(fp); va_end(list); } } diff --git a/rmps.c b/rmps.c index 3a7854c..784f0f3 100644 --- a/rmps.c +++ b/rmps.c @@ -82,6 +82,7 @@ static void set_env(void) sigaction(SIGHUP, &new_sigaction, NULL); /* catch hangup signal */ sigaction(SIGTERM, &new_sigaction, NULL); /* catch term signal */ sigaction(SIGINT, &new_sigaction, NULL); /* catch interrupt signal */ + signal(SIGPIPE, SIG_IGN); /* prevent crashing from bad writes */ } static void daemonize(const char *rundir) @@ -222,9 +223,9 @@ static SSL_CTX* init_server_ctx(const char *cipherlist) return ctx; } -/*---------------------------------------------------------------------*/ -/*--- LoadCertificates - load from files. ---*/ -/*---------------------------------------------------------------------*/ +/*-------------------------------------------*/ +/*--- LoadCertificates - load from files. ---*/ +/*-------------------------------------------*/ void load_certificates(SSL_CTX* ctx, const char *certfile, const char *keyfile, const char *cafile) { diff --git a/thread_pool.c b/thread_pool.c index 2a50439..ce53d34 100644 --- a/thread_pool.c +++ b/thread_pool.c @@ -41,7 +41,6 @@ static void show_certs(SSL *ssl) static void* servlet(void *args) /* Serve the connection -- threadable */ { struct msg buf; - char reply[2048]; int bytes, ret; //unsigned short job[MAXJOBS] = { 0 }; struct agent_args *agent = (struct agent_args*)args; @@ -56,7 +55,7 @@ static void* servlet(void *args) /* Serve the connection -- threadable */ show_certs(agent->ssl); do { buf.meta.type = GET_MEMORY; - //sleep(1); + sleep(1); SSL_write(agent->ssl, &buf, sizeof(buf)); bytes = SSL_read(agent->ssl, &buf, sizeof(buf)); if (bytes > 0) { @@ -66,20 +65,19 @@ static void* servlet(void *args) /* Serve the connection -- threadable */ agent->ip ); continue; } - //buf.chunk.data[bytes] = 0; log_trace(VERBOSE, "Client msg: \"%s\"", buf.chunk.data); - SSL_write(agent->ssl, buf.chunk.data, buf.meta.len); /* send reply */ + /* TODO: Insert msg handler here */ + continue; } if (SSL_get_shutdown(agent->ssl) == SSL_RECEIVED_SHUTDOWN) log_trace(VERBOSE, "SSL_RECEIVED_SHUTDOWN from agent [%s]", agent->ip); else { log_trace(VERBOSE, "Client didn't send data! SSL error below:"); - log_ssl(); - sprintf(reply, "%s", "Where's the data, m8?"); - /* TODO: We crash here if we Ctrl + C the client, check why */ - //SSL_write(agent->ssl, reply, strlen(reply)); + //log_ssl(); /* We actually don't have anything to log from SSL */ + sprintf((char*)buf.chunk.data, "%s", "Where's the data, m8?"); + SSL_write(agent->ssl, &buf, sizeof(struct msg)); } log_trace(INFO, "Agent [%s] disconnected.", agent->ip); } while (bytes);