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 <zaitcev@xxxxxxxxxx> --- 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 <zaitcev@xxxxxxxxx> 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; - } - - if (len == 0) { - g_free(buf); + 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); - g_free(buf); if (port <= 0 || port >= 65636) return -EDOM; return (int)port; } + +int cld_readport(const char *fname) +{ + return hail_readport(fname); +} + diff --git a/test/chunkd/auth.c b/test/chunkd/auth.c index 4545366..7aa30d5 100644 --- a/test/chunkd/auth.c +++ b/test/chunkd/auth.c @@ -27,6 +27,7 @@ #include <string.h> #include <locale.h> #include <chunkc.h> +#include <cld_common.h> #include "test.h" static void test(bool do_encrypt) @@ -43,7 +44,7 @@ static void test(bool do_encrypt) size_t len = 0; void *mem; - port = stc_readport(TEST_PORTFILE); + port = hail_readport(TEST_PORTFILE); OK(port > 0); stc1 = stc_new(TEST_HOST, port, TEST_USER, TEST_USER_KEY, do_encrypt); diff --git a/test/chunkd/basic-object.c b/test/chunkd/basic-object.c index d60a2f0..6502a90 100644 --- a/test/chunkd/basic-object.c +++ b/test/chunkd/basic-object.c @@ -26,6 +26,7 @@ #include <time.h> #include <string.h> #include <locale.h> +#include <cld_common.h> #include <chunkc.h> #include "test.h" @@ -41,7 +42,7 @@ static void test(bool do_encrypt) size_t len = 0; void *mem; - port = stc_readport(TEST_PORTFILE); + port = hail_readport(TEST_PORTFILE); OK(port > 0); stc = stc_new(TEST_HOST, port, TEST_USER, TEST_USER_KEY, do_encrypt); diff --git a/test/chunkd/cp.c b/test/chunkd/cp.c index 85f61c4..306af0a 100644 --- a/test/chunkd/cp.c +++ b/test/chunkd/cp.c @@ -26,6 +26,7 @@ #include <time.h> #include <string.h> #include <locale.h> +#include <cld_common.h> #include <chunkc.h> #include "test.h" @@ -42,7 +43,7 @@ static void test(bool do_encrypt) size_t len = 0; void *mem; - port = stc_readport(TEST_PORTFILE); + port = hail_readport(TEST_PORTFILE); OK(port > 0); stc = stc_new(TEST_HOST, port, TEST_USER, TEST_USER_KEY, do_encrypt); diff --git a/test/chunkd/get-part.c b/test/chunkd/get-part.c index 44d1d45..bbc9ebf 100644 --- a/test/chunkd/get-part.c +++ b/test/chunkd/get-part.c @@ -26,6 +26,7 @@ #include <time.h> #include <string.h> #include <locale.h> +#include <cld_common.h> #include <chunkc.h> #include "test.h" @@ -47,7 +48,7 @@ static void test(bool do_encrypt) size_t len = 0; void *mem; - port = stc_readport(TEST_PORTFILE); + port = hail_readport(TEST_PORTFILE); OK(port > 0); stc = stc_new(TEST_HOST, port, TEST_USER, TEST_USER_KEY, do_encrypt); diff --git a/test/chunkd/it-works.c b/test/chunkd/it-works.c index e660c71..fcca63f 100644 --- a/test/chunkd/it-works.c +++ b/test/chunkd/it-works.c @@ -26,6 +26,7 @@ #include <time.h> #include <string.h> #include <locale.h> +#include <cld_common.h> #include <chunkc.h> #include "test.h" @@ -35,7 +36,7 @@ static void test(bool ssl) int port; bool rcb; - port = stc_readport(TEST_PORTFILE); + port = hail_readport(TEST_PORTFILE); OK(port > 0); stc = stc_new(TEST_HOST, port, TEST_USER, TEST_USER_KEY, ssl); diff --git a/test/chunkd/large-object.c b/test/chunkd/large-object.c index 70dc135..802ff9a 100644 --- a/test/chunkd/large-object.c +++ b/test/chunkd/large-object.c @@ -27,6 +27,7 @@ #include <time.h> #include <string.h> #include <locale.h> +#include <cld_common.h> #include <chunkc.h> #include "test.h" @@ -108,7 +109,7 @@ static void test(bool do_encrypt) memset(data, 0xdeadbeef, sizeof(data)); - port = stc_readport(TEST_PORTFILE); + port = hail_readport(TEST_PORTFILE); OK(port > 0); stc = stc_new(TEST_HOST, port, TEST_USER, TEST_USER_KEY, do_encrypt); diff --git a/test/chunkd/lotsa-objects.c b/test/chunkd/lotsa-objects.c index 4780410..60be01b 100644 --- a/test/chunkd/lotsa-objects.c +++ b/test/chunkd/lotsa-objects.c @@ -27,6 +27,7 @@ #include <time.h> #include <string.h> #include <locale.h> +#include <cld_common.h> #include <chunkc.h> #include "test.h" @@ -47,7 +48,7 @@ static void test(int n_objects, bool do_encrypt) char *k; struct timeval ta, tb; - port = stc_readport(TEST_PORTFILE); + port = hail_readport(TEST_PORTFILE); OK(port > 0); stc = stc_new(TEST_HOST, port, TEST_USER, TEST_USER_KEY, do_encrypt); diff --git a/test/chunkd/nop.c b/test/chunkd/nop.c index 0cf629d..5a89955 100644 --- a/test/chunkd/nop.c +++ b/test/chunkd/nop.c @@ -27,6 +27,7 @@ #include <time.h> #include <string.h> #include <locale.h> +#include <cld_common.h> #include <chunkc.h> #include "test.h" @@ -42,7 +43,7 @@ static void test(int n_nops, bool do_encrypt) int i; struct timeval ta, tb; - port = stc_readport(TEST_PORTFILE); + port = hail_readport(TEST_PORTFILE); OK(port > 0); stc = stc_new(TEST_HOST, port, TEST_USER, TEST_USER_KEY, do_encrypt); diff --git a/test/chunkd/selfcheck-unit.c b/test/chunkd/selfcheck-unit.c index aa66b30..4d4b10a 100644 --- a/test/chunkd/selfcheck-unit.c +++ b/test/chunkd/selfcheck-unit.c @@ -27,6 +27,7 @@ #include <fcntl.h> #include <unistd.h> #include <glib.h> +#include <cld_common.h> #include <chunk-private.h> #include <chunkc.h> #include "test.h" @@ -233,7 +234,7 @@ int main(int argc, char *argv[]) OK(buf); memset(buf, 0x55, BUFLEN); - port = stc_readport(TEST_PORTFILE); + port = hail_readport(TEST_PORTFILE); OK(port > 0); /* diff --git a/test/cld/basic-io.c b/test/cld/basic-io.c index 25b63a1..e32472b 100644 --- a/test/cld/basic-io.c +++ b/test/cld/basic-io.c @@ -118,7 +118,7 @@ int main(int argc, char *argv[]) g_thread_init(NULL); ncld_init(); - port = cld_readport(TEST_PORTFILE_CLD); + port = hail_readport(TEST_PORTFILE_CLD); if (port < 0) return 1; if (port == 0) diff --git a/test/cld/basic-session.c b/test/cld/basic-session.c index 88ac9fe..2be5ea6 100644 --- a/test/cld/basic-session.c +++ b/test/cld/basic-session.c @@ -38,7 +38,7 @@ int main (int argc, char *argv[]) g_thread_init(NULL); ncld_init(); - port = cld_readport(TEST_PORTFILE_CLD); + port = hail_readport(TEST_PORTFILE_CLD); if (port < 0) return port; if (port == 0) diff --git a/test/cld/lock-file.c b/test/cld/lock-file.c index ea5075d..aa46576 100644 --- a/test/cld/lock-file.c +++ b/test/cld/lock-file.c @@ -52,7 +52,7 @@ int main (int argc, char *argv[]) g_thread_init(NULL); ncld_init(); - port = cld_readport(TEST_PORTFILE_CLD); + port = hail_readport(TEST_PORTFILE_CLD); if (port < 0) return port; if (port == 0) -- To unsubscribe from this list: send the line "unsubscribe hail-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html