remove duplicated stc_readport
PATCH 1/1 remove duplicated stc_readport
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.
--- 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 <[email protected]> Date: Tue Oct 26 13:39:50 2010 -0600
hail_readport.
chunkd/config.c +2 -2
@@ -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); }
include/chunkc.h +0 -2
@@ -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)
include/cld_common.h +2 -1
@@ -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. *
lib/chunkdc.c +0 -29
@@ -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; -} -
lib/common.c +21 -15
@@ -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); +} +
test/chunkd/auth.c +2 -1
@@ -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);
test/chunkd/basic-object.c +2 -1
@@ -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);
test/chunkd/cp.c +2 -1
@@ -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);
test/chunkd/get-part.c +2 -1
@@ -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);
test/chunkd/it-works.c +2 -1
@@ -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);
test/chunkd/large-object.c +2 -1
@@ -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);
test/chunkd/lotsa-objects.c +2 -1
@@ -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);
test/chunkd/nop.c +2 -1
@@ -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);
test/chunkd/selfcheck-unit.c +2 -1
@@ -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 );/*
test/cld/basic-io.c +1 -1
@@ -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 )
test/cld/basic-session.c +1 -1
@@ -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 )
test/cld/lock-file.c +1 -1
@@ -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 )
Jeff Garzik
AppliedQuoted 7 lines · Pete Zaitcev
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_readportin 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).
Quoted 5 lines
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<[email protected]>
applied
it would be nice if a follow-up patch moved the hail_readport() definition into a more generic, not-CLD-specific header such as include/hail.h[1]
Jeff
[1] which doesn't exist yet. maybe we could rename hail_log.h to hail.h, and make hail.h a dumping ground for hail-generic items.
Quoted 6 lines · On Tue, 26 Oct 2010 17:33:13 -0400 Jeff Garzik <[email protected]> wrote:
it would be nice if a follow-up patch moved the
hail_readport()definition into a more generic, not-CLD-specific header such as include/hail.h[1][1] which doesn't exist yet. maybe we could rename
hail_log.htohail.h, and makehail.ha dumping ground for hail-generic items.
Maybe. It sounds like a good idea. But it's also a slippery slope. I would rather have you look at it, when you have a moment.
Also, how do I post a patch that renames a file? Just ask "git show" and send whatever comes out?
-- Pete
Quoted 7 lines · Pete Zaitcev
Quoted 3 lines · On Tue, 26 Oct 2010 17:33:13 -0400 Jeff Garzik<[email protected]> wrote:
it would be nice if a follow-up patch moved the
hail_readport()definition into a more generic, not-CLD-specific header such as include/hail.h[1]
Quoted 8 lines
Quoted 2 lines
[1] which doesn't exist yet. maybe we could rename
hail_log.htohail.h, and makehail.ha dumping ground for hail-generic items.Maybe. It sounds like a good idea. But it's also a slippery slope. I would rather have you look at it, when you have a moment.
Also, how do I post a patch that renames a file? Just ask "git show" and send whatever comes out?
A patch that deletes a file and adds the file under a name is detected by git as a rename. Or you can post a 'git pull' request.
Jeff