Skip to contentSkip to conversation

conga/ricci/common Logger.cpp Makefile Module. ...

Cluster-devel [email protected] 1 participant 1 message Aug 31, 2007

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2007-08-31 04:57:37

Modified files:
ricci/common : Logger.cpp Makefile Module.cpp Network.cpp
Random.cpp ServerSocket.cpp Thread.cpp Time.cpp Variable.cpp XML.cpp daemon_init.c signals.c utils.cpp

Log message:
More cleanup

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/Logger.cpp.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/Makefile.diff?cvsroot=cluster&r1=1.9&r2=1.10
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/Module.cpp.diff?cvsroot=cluster&r1=1.6&r2=1.7
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/Network.cpp.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/Random.cpp.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/ServerSocket.cpp.diff?cvsroot=cluster&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/Thread.cpp.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/Time.cpp.diff?cvsroot=cluster&r1=1.5&r2=1.6
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/Variable.cpp.diff?cvsroot=cluster&r1=1.8&r2=1.9
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/XML.cpp.diff?cvsroot=cluster&r1=1.10&r2=1.11
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/daemon_init.c.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/signals.c.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/utils.cpp.diff?cvsroot=cluster&r1=1.9&r2=1.10

ricci/common/Logger.cpp +98 -91
@@ -1,5 +1,5 @@
 /*
-  Copyright Red Hat, Inc. 2005
+  Copyright Red Hat, Inc. 2005-2007
 
   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
@@ -13,7 +13,7 @@
 
   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to the
-  Free Software Foundation, Inc.,  675 Mass Ave, Cambridge, 
+  Free Software Foundation, Inc.,  675 Mass Ave, Cambridge,
   MA 02139, USA.
 */
 /*
@@ -38,139 +38,146 @@
 
 static counting_auto_ptr<Logger> logger(new Logger());
 
-
 Logger::Logger() :
-  _fd(-1),
-  _domain_c(NULL)
+	_fd(-1),
+	_domain_c(NULL)
 {}
 
-Logger::Logger(const String& filepath, 
-	       const String& domain, 
-	       LogLevel level) :
-  _level(level)
-{
-  const char* c_str = domain.c_str();
-  const char* path_c = filepath.c_str();
-  
-  _domain_c = (char*) malloc(domain.size()+1);
-  if (_domain_c == NULL)
-    throw String("Logger::Logger(): malloc() failed");
-  strcpy(_domain_c, c_str);
-  
-  _fd = open(path_c, 
-	     O_CREAT|O_WRONLY|O_APPEND, 
-	     S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
-  if (_fd == -1) {
-    free(_domain_c);
-    throw String("Logger::Logger(): open() failed");
-  }
+Logger::Logger(	const String& filepath,
+				const String& domain,
+				LogLevel level) :
+	_level(level)
+{
+	const char *c_str = domain.c_str();
+	const char *path_c = filepath.c_str();
+
+	_domain_c = (char *) malloc(domain.size() + 1);
+	if (_domain_c == NULL)
+		throw String("Logger::Logger(): malloc() failed");
+	strcpy(_domain_c, c_str);
+
+	_fd = open(path_c, O_CREAT | O_WRONLY | O_APPEND, 0640);
+	if (_fd == -1) {
+		free(_domain_c);
+		throw String("Logger::Logger(): open() failed");
+	}
 }
 
 Logger::Logger(int fd, const String& domain, LogLevel level) :
-  _fd(fd),
-  _level(level)
+	_fd(fd),
+	_level(level)
 {
-  const char* c_str = domain.c_str();
-  
-  _domain_c = (char*) malloc(domain.size()+1);
-  if (_domain_c == NULL) {
-    close_fd();
-    throw String("Logger::Logger(): malloc() failed");
-  }
-  strcpy(_domain_c, c_str);
+	const char *c_str = domain.c_str();
+
+	_domain_c = (char *) malloc(domain.size() + 1);
+	if (_domain_c == NULL) {
+		close_fd();
+		throw String("Logger::Logger(): malloc() failed");
+	}
+	strcpy(_domain_c, c_str);
 }
 
 void
 Logger::close_fd()
 {
-  if (_fd > -1)
-    fsync(_fd);
-  if (_fd > 2) {
-    int e;
-    do {
-      e = close(_fd);
-    } while (e == -1 && (errno == EINTR));
-    _fd = -1;
-  }
+	if (_fd > -1)
+		fsync(_fd);
+
+	if (_fd > 2) {
+		int e;
+		do {
+			e = close(_fd);
+		} while (e == -1 && (errno == EINTR));
+		_fd = -1;
+	}
 }
 
 Logger::~Logger()
 {
-  close_fd();
-  free(_domain_c);
+	close_fd();
+	free(_domain_c);
 }
 
-void 
+void
 Logger::log(const String& msg, LogLevel level)
 {
-  log_sigsafe(msg.c_str(), level);
+	log_sigsafe(msg.c_str(), level);
 }
 
-void 
-Logger::log_sigsafe(const char* msg, LogLevel level)
+void
+Logger::log_sigsafe(const char *msg, LogLevel level)
 {
-  if (_fd > 0 && _level & level) {
-    char time[64];
-    time_t t = time_sec();
-    ctime_r(&t, time);
-    time[sizeof(time)-1] = 0;
-    for (int i=0; time[i]; i++)
-      if (time[i] == '\n') {
-	time[i] = 0;
-	break;
-      }
-    
-    char m[2048];
-    if (_fd > 2 && (_domain_c != NULL))
-      snprintf(m, sizeof(m), "%s %s: %s\n", time, _domain_c, msg);
-    else
-      snprintf(m, sizeof(m), "%s: %s\n", time, msg);
-    m[sizeof(m)-1] = 0;
-    
-    int l, e;
-    for (l=0; m[l]; l++) ;
-    do {
-      e = write(_fd, m, l);
-    } while (e == -1 && errno == EINTR);
-  }
+	if (_fd > 0 && (_level & level)) {
+		char time[64];
+		time_t t = time_sec();
+		char *p;
+		int ret;
+
+		ctime_r(&t, time);
+		time[sizeof(time) - 1] = '\0';
+
+		p = strchr(time, '\n');
+		if (p != NULL)
+			*p = '\0';		
+
+		char m[4096] = { 0, };
+		if (_fd > 2 && _domain_c != NULL)
+			ret = snprintf(m, sizeof(m), "%s %s: %s\n", time, _domain_c, msg);
+		else
+			ret = snprintf(m, sizeof(m), "%s: %s\n", time, msg);
+
+		if (ret < 0 || (size_t) ret >= sizeof(m)) {
+			m[sizeof(m) - 1] = '\0';
+			ret = strlen(m);
+		}
+
+		while (ret > 0) {
+			ssize_t w = write(_fd, m, ret);
+			if (w < 0) {
+				if (errno == EINTR)
+					continue;
+				break;
+			}
+			ret -= w;
+		}
+	}
 }
-  
 
 
 // ### helper functions ###
 
-String 
+String
 operator+ (const String& s, int i)
 {
-  char buff[128];
-  snprintf(buff, sizeof(buff), "%d", i);
-  return s + buff;
+	char buff[128];
+	snprintf(buff, sizeof(buff), "%d", i);
+	return s + buff;
 }
 
-String 
+String
 operator+ (int i, const String& s)
 {
-  char buff[128];
-  snprintf(buff, sizeof(buff), "%d", i);
-  return String(buff) + s;
+	char buff[128];
+	snprintf(buff, sizeof(buff), "%d", i);
+	return String(buff) + s;
 }
 
-void 
+void
 log(const String& msg, LogLevel level)
 {
-  logger->log(msg, level);
+	logger->log(msg, level);
 }
 
-void 
+void
 log_sigsafe(const char* msg, LogLevel level)
 {
-  logger->log_sigsafe(msg, level);
+	logger->log_sigsafe(msg, level);
 }
 
-void 
+void
 set_logger(counting_auto_ptr<Logger> l)
 {
-  if (l.get() == NULL)
-    l = counting_auto_ptr<Logger>(new Logger());
-  logger = l;
+	if (l.get() == NULL)
+		l = counting_auto_ptr<Logger>(new Logger());
+	logger = l;
 }
ricci/common/Makefile +13 -13
@@ -1,14 +1,15 @@
-################################################################################################################################################################
+################################################################################
 ##
-##  Copyright (C) 2005 Red Hat, Inc.  All rights reserved.
+## Copyright (C) 2005-2007 Red Hat, Inc. All rights reserved.
 ##
-##  This copyrighted material is made available to anyone wishing to use,
-##  modify, copy, or redistribute it subject to the terms and conditions
-##  of the GNU General Public License v.2.
+## This copyrighted material is made available to anyone wishing to use,
+## modify, copy, or redistribute it subject to the terms and conditions
+## of the GNU General Public License v.2.
 ##
-##############################################################################################################################################################
+################################################################################
 
 top_srcdir=..
+
 UNINSTALL = ${top_srcdir}/scripts/uninstall.pl
 
 include ${top_srcdir}/make/defines.mk
@@ -16,7 +17,8 @@
 
 #TARGET = main
 
-OBJECTS = Except.o \
+OBJECTS = \
+	Except.o \
 	executils.o \
 	signals.o \
 	Thread.o \
@@ -35,12 +37,10 @@
 	base64.o \
 	Module.o
 
-
-INCLUDE     += 
-CXXFLAGS    += 
-CFLAGS      += 
-LDFLAGS     += 
-
+INCLUDE += 
+CXXFLAGS +=
+CFLAGS += 
+LDFLAGS += 
 
 all: $(OBJECTS) 
 
ricci/common/Module.cpp +173 -178

435 lines not on this page · raw message

ricci/common/Network.cpp +43 -42

107 lines not on this page · raw message

ricci/common/Random.cpp +24 -15
@@ -1,5 +1,5 @@
 /*
-  Copyright Red Hat, Inc. 2005
+  Copyright Red Hat, Inc. 2005-2007
 
   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
@@ -13,7 +13,7 @@
 
   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to the
-  Free Software Foundation, Inc.,  675 Mass Ave, Cambridge, 
+  Free Software Foundation, Inc.,  675 Mass Ave, Cambridge,
   MA 02139, USA.
 */
 /*
@@ -25,24 +25,33 @@
 #include "Mutex.h"
 #include "Time.h"
 
+#include <unistd.h>
 #include <stdlib.h>
+#include <fcntl.h>
 #include "String.h"
 
-
 static Mutex mutex;
-static unsigned int seed = 0;
-
+static uint32_t seed = 0;
 
-int 
+int
 random_generator(int min, int max)
 {
-  MutexLocker l(mutex);
-  if (!seed)
-    seed = time_mil();
-  
-  int range = max - min;
-  if (range <= 5)
-    throw String("random_generate(min, max): range too small");
-  
-  return (int) (min + range * ((double) rand_r(&seed))/RAND_MAX);
+	MutexLocker l(mutex);
+
+	int fd = open("/dev/urandom", O_RDONLY);
+	if (fd > 0) {
+		ssize_t ret = read(fd, &seed, sizeof(seed));
+		close(fd);
+		if (ret > 0 && (size_t) ret != sizeof(seed))
+			seed = 0;
+	}
+
+	if (!seed)
+		seed = time_mil();
+
+	int range = max - min;
+	if (range <= 5)
+		throw String("random_generate(min, max): range too small");
+
+	return (int) (min + range * ((double) rand_r(&seed)) / RAND_MAX);
 }
ricci/common/ServerSocket.cpp +104 -102

243 lines not on this page · raw message

ricci/common/Thread.cpp +54 -53

146 lines not on this page · raw message

ricci/common/Time.cpp +31 -25

86 lines not on this page · raw message

ricci/common/Variable.cpp +564 -512

1,274 lines not on this page · raw message

ricci/common/XML.cpp +171 -175

354 lines not on this page · raw message

ricci/common/daemon_init.c +4 -4

Lines of this file are not shown. View the raw message.

ricci/common/signals.c +8 -10

Lines of this file are not shown. View the raw message.

ricci/common/utils.cpp +193 -192

385 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.