From: rmccabe@sourceware.org <rmccabe@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] conga/ricci/common Makefile sys_util.c sys_util.h
Date: 9 Sep 2007 18:20:01 -0000 [thread overview]
Message-ID: <20070909182001.18536.qmail@sourceware.org> (raw)
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@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@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 +=
reply other threads:[~2007-09-09 18:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070909182001.18536.qmail@sourceware.org \
--to=rmccabe@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.