Mikhail Karpov, le sam. 07 nov. 2026 19:00:09 +0700, a ecrit: > On Fri, 6 Nov 2026 18:34:24 Samuel Thibault wrote: > > > Ok, then you can use a local struct port_bucket* variable to store the > > pointer while you are unsure whether the function will succeed, and then > > either store to the global variable on success, or deallocate the bucket > > on failure. > > We can keep the check on pager_port_bucket by first saving the result of > ports_create_bucket into a static variable, tmp_port_bucket.
Why should that variable be static? static variables local to functions really pose maintainability issues. Samuel > If ports_create_bucket succeeds but pager_start_workers fails, we simply > refrain from assigning the value from tmp_port_bucket to pager_port_bucket. > This way, we avoid the need to create and deallocate a local variable. > > Thanks, > > -- > Mikhail Karpov > From 400a435bb2d3ed5887e356313ba117a928fb3597 Mon Sep 17 00:00:00 2001 > From: Mikhail Karpov <[email protected]> > Date: Sat, 7 Nov 2026 18:47:49 +0700 > Subject: [PATCH 4/4] Added check for ports_create_bucket in storeio/pager.c > > --- > storeio/pager.c | 32 +++++++++++++++++++++++++------- > 1 file changed, 25 insertions(+), 7 deletions(-) > > diff --git a/storeio/pager.c b/storeio/pager.c > index 7a26efa..70d2b94 100644 > --- a/storeio/pager.c > +++ b/storeio/pager.c > @@ -145,9 +145,10 @@ static struct port_bucket *pager_port_bucket = 0; > static struct pager_requests *pager_requests; > > /* Initialize paging for this device. */ > -static void > +static error_t > init_dev_paging (void) > { > + error_t err = 0; > if (! pager_port_bucket) > { > static pthread_mutex_t pager_global_lock = PTHREAD_MUTEX_INITIALIZER; > @@ -155,20 +156,35 @@ init_dev_paging (void) > pthread_mutex_lock (&pager_global_lock); > if (pager_port_bucket == NULL) > { > - error_t err; > - > - pager_port_bucket = ports_create_bucket (); > + static struct port_bucket *tmp_port_bucket = NULL; > + if (!tmp_port_bucket) > + { > + tmp_port_bucket = ports_create_bucket (); > + if (!tmp_port_bucket) > + { > + err = errno; > + error (0, err, "ports_create_bucket"); > + goto out; > + } > + } > > /* Start libpagers worker threads. */ > - err = pager_start_workers (pager_port_bucket, &pager_requests); > + err = pager_start_workers (tmp_port_bucket, &pager_requests); > if (err) > { > - errno = err; > error (0, err, "pager_start_workers"); > + goto out; > } > + > + pager_port_bucket = tmp_port_bucket; > + tmp_port_bucket = NULL; > } > + > + out: > pthread_mutex_unlock (&pager_global_lock); > } > + > + return err; > } > > void > @@ -229,7 +245,9 @@ dev_get_memory_object (struct dev *dev, vm_prot_t prot, > memory_object_t *memobj) > { > int created = 0; > > - init_dev_paging (); > + err = init_dev_paging (); > + if (err) > + return err; > > pthread_mutex_lock (&dev->pager_lock); > > -- > 2.43.0 > -- Samuel <A> sauf que le firewall bloque tout sauf internet -+- ben ouais, il bloque ipx/spx ! -+-
