[Cluster-devel] conga/ricci/common Makefile sys_util.c sys_util.h

rmccabe at sourceware.org rmccabe at sourceware.org
Sun Sep 9 18:20:01 UTC 2007


CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe at sourceware.org	2007-09-09 18:20:00

Modified files:
	ricci/common   : Makefile 
Added files:
	ricci/common   : sys_util.c sys_util.h 

Log message:
	Some utility functions for use later

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/sys_util.c.diff?cvsroot=cluster&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/sys_util.h.diff?cvsroot=cluster&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/Makefile.diff?cvsroot=cluster&r1=1.11&r2=1.12

/cvs/cluster/conga/ricci/common/sys_util.c,v  -->  standard output
revision 1.1
--- conga/ricci/common/sys_util.c
+++ -	2007-09-09 18:20:01.099958000 +0000
@@ -0,0 +1,106 @@
+/*
+** Copyright (C) Red Hat, Inc. 2007
+**
+** This program is free software; you can redistribute it and/or modify it
+** under the terms of the GNU General Public License version 2 as published
+** by the Free Software Foundation.
+**
+** This program is distributed in the hope that it will be useful, but
+** WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** General Public License for more details.
+**
+** 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,
+** MA 02139, USA.
+**
+** Author: Ryan McCabe <rmccabe at redhat.com>
+*/
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+
+uint32_t page_size;
+
+ssize_t read_restart(int fd, void *buf, size_t len) {
+	void *buf_orig = buf;
+
+	while (len > 0) {
+		size_t ret = read(fd, buf, len);
+		if (ret < 0) {
+			if (errno == EINTR || errno == EAGAIN)
+				continue;
+			return -errno;
+		}
+		if (ret == 0)
+			return -EPIPE;
+
+		buf += ret;
+		len -= (size_t) ret;
+	}
+	return (ssize_t) (buf - buf_orig);
+}
+
+ssize_t write_restart(int fd, const void *buf, size_t len) {
+	const void *buf_orig = buf;
+
+	while (len > 0) {
+		size_t ret = write(fd, buf, len);
+		if (ret < 0) {
+			if (errno == EINTR || errno == EAGAIN)
+				continue;
+			return -errno;
+		}
+		if (ret == 0)
+			return -EPIPE;
+
+		buf += ret;
+		len -= (size_t) ret;
+	}
+	return (ssize_t) (buf - buf_orig);
+}
+
+void *mallock(size_t len) {
+	size_t rounded_len;
+
+	if (!page_size) {
+		int ret = sysconf(_SC_PAGESIZE);
+		if (ret <= 0)
+			return NULL;
+		page_size = (uint32_t) ret;
+	}
+
+	/* Round up to the next multiple of the page size */
+	rounded_len = (len + (page_size - 1)) & -page_size;
+
+	void *ret = malloc(rounded_len);
+	if (ret == NULL)
+		return ret;
+
+	if (mlock(ret, rounded_len) != 0) {
+		free(ret);
+		return NULL;
+	}
+
+	return ret;
+}
+
+int mdallock(void *mem, size_t len) {
+	int ret;
+	size_t rounded_len;
+
+	rounded_len = (len + (page_size - 1)) & -page_size;
+	memset(mem, 0, len);
+	ret = munlock(mem, rounded_len);
+	if (ret != 0)
+		ret = -errno;
+
+	free(mem);
+	return ret;
+}
/cvs/cluster/conga/ricci/common/sys_util.h,v  -->  standard output
revision 1.1
--- conga/ricci/common/sys_util.h
+++ -	2007-09-09 18:20:01.187476000 +0000
@@ -0,0 +1,30 @@
+/*
+** Copyright (C) Red Hat, Inc. 2007
+**
+** This program is free software; you can redistribute it and/or modify it
+** under the terms of the GNU General Public License version 2 as published
+** by the Free Software Foundation.
+**
+** This program is distributed in the hope that it will be useful, but
+** WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** General Public License for more details.
+**
+** 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,
+** MA 02139, USA.
+**
+** Author: Ryan McCabe <rmccabe at redhat.com>
+*/
+
+#ifndef __CONGA_SYS_UTIL_H
+#define __CONGA_SYS_UTIL_H
+
+ssize_t read_restart(int fd, void *buf, size_t len);
+ssize_t write_restart(int fd, const void *buf, size_t len);
+
+void *mallock(size_t len);
+void *mdallock(void *, size_t len);
+
+#endif
--- conga/ricci/common/Makefile	2007/09/07 19:07:21	1.11
+++ conga/ricci/common/Makefile	2007/09/09 18:20:00	1.12
@@ -32,9 +32,10 @@
 	Logger.o \
 	Variable.o \
 	Random.o \
+	Module.o \
 	daemon_init.o \
 	base64.o \
-	Module.o
+	sys_util.o
 
 INCLUDE += 
 CXXFLAGS +=




More information about the Cluster-devel mailing list