3030#include "src/common/libutil/tstat.h"
3131#include "src/common/libutil/timestamp.h"
3232#include "src/common/libutil/errprintf.h"
33+ #include "src/common/libutil/errno_safe.h"
3334#include "src/common/libkvs/treeobj.h"
3435#include "src/common/libkvs/kvs_checkpoint.h"
3536#include "src/common/libkvs/kvs_txn_private.h"
@@ -328,7 +329,6 @@ static void getroot_completion (flux_future_t *f, void *arg)
328329 uint32_t owner ;
329330 const char * ref ;
330331 struct kvsroot * root ;
331- int save_errno ;
332332
333333 msg = flux_future_aux_get (f , "msg" );
334334 assert (msg );
@@ -361,7 +361,7 @@ static void getroot_completion (flux_future_t *f, void *arg)
361361 }
362362
363363 if (event_subscribe (ctx , ns ) < 0 ) {
364- save_errno = errno ;
364+ int save_errno = errno ;
365365 kvsroot_mgr_remove_root (ctx -> krm , ns );
366366 errno = save_errno ;
367367 flux_log_error (ctx -> h , "%s: event_subscribe" , __FUNCTION__ );
@@ -805,14 +805,13 @@ static int setroot_event_send (struct kvs_ctx *ctx,
805805{
806806 flux_msg_t * msg = NULL ;
807807 char * setroot_topic = NULL ;
808- int saved_errno , rc = -1 ;
808+ int rc = -1 ;
809809
810810 assert (ctx -> rank == 0 );
811811
812812 if (asprintf (& setroot_topic ,
813813 "kvs.namespace-%s-setroot" ,
814814 root -> ns_name ) < 0 ) {
815- saved_errno = errno ;
816815 flux_log_error (ctx -> h , "%s: asprintf" , __FUNCTION__ );
817816 goto done ;
818817 }
@@ -825,24 +824,17 @@ static int setroot_event_send (struct kvs_ctx *ctx,
825824 "names" , names ,
826825 "keys" , keys ,
827826 "owner" , root -> owner ))) {
828- saved_errno = errno ;
829827 flux_log_error (ctx -> h , "%s: flux_event_pack" , __FUNCTION__ );
830828 goto done ;
831829 }
832- if (flux_msg_set_private (msg ) < 0 ) {
833- saved_errno = errno ;
830+ if (flux_msg_set_private (msg ) < 0 )
834831 goto done ;
835- }
836- if (flux_send (ctx -> h , msg , 0 ) < 0 ) {
837- saved_errno = errno ;
832+ if (flux_send (ctx -> h , msg , 0 ) < 0 )
838833 goto done ;
839- }
840834 rc = 0 ;
841835done :
842- free ( setroot_topic );
836+ ERRNO_SAFE_WRAP ( free , setroot_topic );
843837 flux_msg_destroy (msg );
844- if (rc < 0 )
845- errno = saved_errno ;
846838 return rc ;
847839}
848840
@@ -853,10 +845,9 @@ static int error_event_send (struct kvs_ctx *ctx,
853845{
854846 flux_msg_t * msg = NULL ;
855847 char * error_topic = NULL ;
856- int saved_errno , rc = -1 ;
848+ int rc = -1 ;
857849
858850 if (asprintf (& error_topic , "kvs.namespace-%s-error" , ns ) < 0 ) {
859- saved_errno = errno ;
860851 flux_log_error (ctx -> h , "%s: asprintf" , __FUNCTION__ );
861852 goto done ;
862853 }
@@ -866,24 +857,17 @@ static int error_event_send (struct kvs_ctx *ctx,
866857 "namespace" , ns ,
867858 "names" , names ,
868859 "errnum" , errnum ))) {
869- saved_errno = errno ;
870860 flux_log_error (ctx -> h , "%s: flux_event_pack" , __FUNCTION__ );
871861 goto done ;
872862 }
873- if (flux_msg_set_private (msg ) < 0 ) {
874- saved_errno = errno ;
863+ if (flux_msg_set_private (msg ) < 0 )
875864 goto done ;
876- }
877- if (flux_send (ctx -> h , msg , 0 ) < 0 ) {
878- saved_errno = errno ;
865+ if (flux_send (ctx -> h , msg , 0 ) < 0 )
879866 goto done ;
880- }
881867 rc = 0 ;
882868done :
883- free ( error_topic );
869+ ERRNO_SAFE_WRAP ( free , error_topic );
884870 flux_msg_destroy (msg );
885- if (rc < 0 )
886- errno = saved_errno ;
887871 return rc ;
888872}
889873
@@ -2367,7 +2351,7 @@ static void start_root_remove (struct kvs_ctx *ctx, const char *ns)
23672351static int namespace_remove (struct kvs_ctx * ctx , const char * ns )
23682352{
23692353 flux_msg_t * msg = NULL ;
2370- int saved_errno , rc = -1 ;
2354+ int rc = -1 ;
23712355 char * topic = NULL ;
23722356
23732357 /* Namespace doesn't exist or is already in process of being
@@ -2377,32 +2361,23 @@ static int namespace_remove (struct kvs_ctx *ctx, const char *ns)
23772361 goto done ;
23782362 }
23792363
2380- if (asprintf (& topic , "kvs.namespace-%s-removed" , ns ) < 0 ) {
2381- saved_errno = errno ;
2364+ if (asprintf (& topic , "kvs.namespace-%s-removed" , ns ) < 0 )
23822365 goto cleanup ;
2383- }
23842366 if (!(msg = flux_event_pack (topic , "{ s:s }" , "namespace" , ns ))) {
2385- saved_errno = errno ;
23862367 flux_log_error (ctx -> h , "%s: flux_event_pack" , __FUNCTION__ );
23872368 goto cleanup ;
23882369 }
2389- if (flux_msg_set_private (msg ) < 0 ) {
2390- saved_errno = errno ;
2370+ if (flux_msg_set_private (msg ) < 0 )
23912371 goto cleanup ;
2392- }
2393- if (flux_send (ctx -> h , msg , 0 ) < 0 ) {
2394- saved_errno = errno ;
2372+ if (flux_send (ctx -> h , msg , 0 ) < 0 )
23952373 goto cleanup ;
2396- }
23972374
23982375 start_root_remove (ctx , ns );
23992376done :
24002377 rc = 0 ;
24012378cleanup :
24022379 flux_msg_destroy (msg );
2403- free (topic );
2404- if (rc < 0 )
2405- errno = saved_errno ;
2380+ ERRNO_SAFE_WRAP (free , topic );
24062381 return rc ;
24072382}
24082383
@@ -2932,12 +2907,11 @@ static int store_initial_rootdir (struct kvs_ctx *ctx, char *ref, int ref_len)
29322907 saved_errno = errno ;
29332908 ret = cache_remove_entry (ctx -> cache , ref );
29342909 assert (ret == 1 );
2910+ errno = saved_errno ;
29352911error :
2936- saved_errno = errno ;
2937- free (data );
2912+ ERRNO_SAFE_WRAP (free , data );
29382913 flux_future_destroy (f );
2939- json_decref (rootdir );
2940- errno = saved_errno ;
2914+ ERRNO_SAFE_WRAP (json_decref , rootdir );
29412915 return -1 ;
29422916}
29432917
0 commit comments