svn commit: r218041 - head/sbin/hastd

Mikolaj Golub to.my.trociny at gmail.com
Sun Feb 6 23:55:09 UTC 2011


On Fri, 28 Jan 2011 21:48:15 +0000 (UTC) Pawel Jakub Dawidek wrote:

 PJD> Author: pjd
 PJD> Date: Fri Jan 28 21:48:15 2011
 PJD> New Revision: 218041
 PJD> URL: http://svn.freebsd.org/changeset/base/218041

 PJD> Log:
 PJD>   Add function to close all unneeded descriptors after fork(2).
 PJD>   
 PJD>   MFC after:        1 week

 PJD> Modified:
 PJD>   head/sbin/hastd/hastd.c
 PJD>   head/sbin/hastd/hastd.h

 PJD> Modified: head/sbin/hastd/hastd.c
 PJD> ==============================================================================
 PJD> --- head/sbin/hastd/hastd.c        Fri Jan 28 21:36:01 2011        (r218040)
 PJD> +++ head/sbin/hastd/hastd.c        Fri Jan 28 21:48:15 2011        (r218041)
 PJD> @@ -1,6 +1,6 @@
 PJD>  /*-
 PJD>   * Copyright (c) 2009-2010 The FreeBSD Foundation
 PJD> - * Copyright (c) 2010 Pawel Jakub Dawidek <pjd at FreeBSD.org>
 PJD> + * Copyright (c) 2010-2011 Pawel Jakub Dawidek <pjd at FreeBSD.org>
 PJD>   * All rights reserved.
 PJD>   *
 PJD>   * This software was developed by Pawel Jakub Dawidek under sponsorship from
 PJD> @@ -93,6 +93,32 @@ g_gate_load(void)
 PJD>          }
 PJD>  }
 PJD>  
 PJD> +void
 PJD> +descriptors_cleanup(struct hast_resource *res)
 PJD> +{
 PJD> +        struct hast_resource *tres;
 PJD> +
 PJD> +        TAILQ_FOREACH(tres, &cfg->hc_resources, hr_next) {
 PJD> +                if (tres == res) {
 PJD> +                        PJDLOG_VERIFY(res->hr_role == HAST_ROLE_SECONDARY ||
 PJD> +                            (res->hr_remotein == NULL &&
 PJD> +                             res->hr_remoteout == NULL));
 PJD> +                        continue;
 PJD> +                }
 PJD> +                if (tres->hr_remotein != NULL)
 PJD> +                        proto_close(tres->hr_remotein);
 PJD> +                if (tres->hr_remoteout != NULL)
 PJD> +                        proto_close(tres->hr_remoteout);

I think tres->hr_ctrl, hr_event, and hr_conn should be closed here too (like
in the attached patch). Otherwise descriptor assertion will fail in primary if
you have more than one resource, on the second resource.

 PJD> +        }
 PJD> +        if (cfg->hc_controlin != NULL)
 PJD> +                proto_close(cfg->hc_controlin);
 PJD> +        proto_close(cfg->hc_controlconn);
 PJD> +        proto_close(cfg->hc_listenconn);
 PJD> +        (void)pidfile_close(pfh);
 PJD> +        hook_fini();
 PJD> +        pjdlog_fini();
 PJD> +}
 PJD> +
 PJD>  static void
 PJD>  child_exit_log(unsigned int pid, int status)
 PJD>  {

 PJD> Modified: head/sbin/hastd/hastd.h
 PJD> ==============================================================================
 PJD> --- head/sbin/hastd/hastd.h        Fri Jan 28 21:36:01 2011        (r218040)
 PJD> +++ head/sbin/hastd/hastd.h        Fri Jan 28 21:48:15 2011        (r218041)
 PJD> @@ -43,6 +43,8 @@ extern const char *cfgpath;
 PJD>  extern bool sigexit_received;
 PJD>  extern struct pidfh *pfh;
 PJD>  
 PJD> +void descriptors_cleanup(struct hast_resource *res);
 PJD> +
 PJD>  void hastd_primary(struct hast_resource *res);
 PJD>  void hastd_secondary(struct hast_resource *res, struct nv *nvin);
 PJD>  
 PJD> _______________________________________________
 PJD> svn-src-all at freebsd.org mailing list
 PJD> http://lists.freebsd.org/mailman/listinfo/svn-src-all
 PJD> To unsubscribe, send any mail to "svn-src-all-unsubscribe at freebsd.org"

-- 
Mikolaj Golub

-------------- next part --------------
A non-text attachment was scrubbed...
Name: hastd.c.descriptors_cleanup.patch
Type: text/x-patch
Size: 609 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/svn-src-all/attachments/20110206/c704d8da/hastd.c.descriptors_cleanup.bin


More information about the svn-src-all mailing list