Now that we have a common library for Hail, an opportunity opens to trim
some duplication, such as stc_readport. It even had a comment about it.
Note that we leave cld_readport in the API for a few weeks, while I get
my tabled trees and RPMs in order. Unfortunately we routinely neglect
to set specific version in RPM headers (e.g. no Requires: cld = 0.8.2).
Also, get rid of g_file_get_contents. Talk about pointless: it requires
caller to free memory, and it's not like code is any more compact or
easier to understand.
Signed-off-by: Pete Zaitcev zait...@redhat.com
---
chunkd/config.c |4 +--
include/chunkc.h |2 -
include/cld_common.h |3 +-
lib/chunkdc.c| 29 --
lib/common.c | 36 +++--
test/chunkd/auth.c |3 +-
test/chunkd/basic-object.c |3 +-
test/chunkd/cp.c |3 +-
test/chunkd/get-part.c |3 +-
test/chunkd/it-works.c |3 +-
test/chunkd/large-object.c |3 +-
test/chunkd/lotsa-objects.c |3 +-
test/chunkd/nop.c|3 +-
test/chunkd/selfcheck-unit.c |3 +-
test/cld/basic-io.c |2 -
test/cld/basic-session.c |2 -
test/cld/lock-file.c |2 -
17 files changed, 46 insertions(+), 61 deletions(-)
commit 56536e377f30a130f621beaa22dd90cb10e29d45
Author: Pete Zaitcev zait...@yahoo.com
Date: Tue Oct 26 13:39:50 2010 -0600
hail_readport.
diff --git a/chunkd/config.c b/chunkd/config.c
index 4c58768..c74e641 100644
--- a/chunkd/config.c
+++ b/chunkd/config.c
@@ -239,11 +239,11 @@ static void cfg_elm_end_cld(struct config_context *cc)
*/
if (cc-cld_port_file) {
int port;
- if ((port = cld_readport(cc-cld_port_file)) = 0) {
+ if ((port = hail_readport(cc-cld_port_file)) = 0) {
applog(LOG_INFO, Waiting for CLD PortFile %s,
cc-cld_port_file);
sleep(2);
- while ((port = cld_readport(cc-cld_port_file)) = 0)
+ while ((port = hail_readport(cc-cld_port_file)) = 0)
sleep(3);
applog(LOG_INFO, Using CLD port %u, port);
}
diff --git a/include/chunkc.h b/include/chunkc.h
index e3c2bb7..e9b6003 100644
--- a/include/chunkc.h
+++ b/include/chunkc.h
@@ -112,8 +112,6 @@ extern bool stc_check_status(struct st_client *stc,
extern struct st_keylist *stc_keys(struct st_client *stc);
-extern int stc_readport(const char *fname);
-
static inline void *stc_get_inlinez(struct st_client *stc,
const char *key,
size_t *len)
diff --git a/include/cld_common.h b/include/cld_common.h
index 8c11601..3ac18c6 100644
--- a/include/cld_common.h
+++ b/include/cld_common.h
@@ -64,7 +64,8 @@ static inline void cld_timer_init(struct cld_timer *timer,
const char *name,
extern unsigned long long cld_sid2llu(const uint8_t *sid);
extern void cld_rand64(void *p);
extern const char *cld_errstr(enum cle_err_codes ecode);
-extern int cld_readport(const char *fname);
+extern int cld_readport(const char *fname);/* deprecated */
+extern int hail_readport(const char *fname);
/*** Validate the HMAC signature of a byte buffer.
*
diff --git a/lib/chunkdc.c b/lib/chunkdc.c
index bebf87b..02cf850 100644
--- a/lib/chunkdc.c
+++ b/lib/chunkdc.c
@@ -1303,32 +1303,3 @@ void stc_init(void)
srand(time(NULL) ^ getpid()); // for cld_rand64 et.al.
}
-/*
- * Read a port number from a port file, return the value or negative error.
- * A 100% copy of cld_readport for now, but permits us not to link libcldc.
- */
-int stc_readport(const char *fname)
-{
- enum { LEN = 11 };
- char buf[LEN+1];
- long port;
- int fd;
- int rc;
-
- if ((fd = open(fname, O_RDONLY)) == -1)
- return -errno;
- rc = read(fd, buf, LEN);
- close(fd);
- if (rc 0)
- return -errno;
- if (rc == 0)
- return -EPIPE;
- buf[rc] = 0;
-
- port = strtol(buf, NULL, 10);
- if (port = 0 || port = 65636)
- return -EDOM;
-
- return (int)port;
-}
-
diff --git a/lib/common.c b/lib/common.c
index 30bc6dd..60b120d 100644
--- a/lib/common.c
+++ b/lib/common.c
@@ -81,27 +81,33 @@ const char *cld_errstr(enum cle_err_codes ecode)
/*
* Read a port number from a port file, return the value or negative error.
*/
-int cld_readport(const char *fname)
+int hail_readport(const char *fname)
{
+ enum { LEN = 11 };
+ char buf[LEN+1];
long port;
- gchar *buf;
- GError *err = NULL;
- gsize len;
-
- if (!g_file_get_contents(fname, buf, len, err)) {
- int ret = -1000 - err-code;
- g_error_free(err);
- return ret;
-