From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 815E8C282DD for ; Thu, 9 Jan 2020 17:08:22 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 30D382067D for ; Thu, 9 Jan 2020 17:08:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="Nkup5GPd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 30D382067D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ipbHe-00060w-33; Thu, 09 Jan 2020 17:07:46 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ipbHc-00060r-7s for xen-devel@lists.xenproject.org; Thu, 09 Jan 2020 17:07:44 +0000 X-Inumbo-ID: 878e3034-3302-11ea-a985-bc764e2007e4 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 878e3034-3302-11ea-a985-bc764e2007e4; Thu, 09 Jan 2020 17:07:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1578589655; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to; bh=1yQMvLrk4kxv6Fd9ocGTXp8LgOHA1ssvBto9o3Du7fU=; b=Nkup5GPdNIuPARtdzF+j/oR7M7blnWqUYcRwj3cie0WRvp8BkuuSh/WD 3rUt14jVPDI/ex/W0MyZrbZFGHJeLf8AbpWtAw+bvgI0z9Om3pVuDx07D H9o0eyieeWc2uXuNbTjLoqnsl4vDBI0T0e3GLgHWddAp1klzv3NZfsAn4 s=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: ZvXMI5IEKd24N1q3flLNPtVmnv2aovwmv9Q7qfcrKcKUF8ew1qcRrC0g8htfRtIMAfTShnxM2X utzuGv8ozWA8sLpq0WBUUWCdbUMUH/PtB4X4XKpXE7AmhbgA3gX4IAy5iGHDsp4St2LKTQmG9K qqAmEamaauHXMlfBD2AE0JeDdhri9RgznMsSlFBPfDJJjq3iH7LaMpnt0jnkM0PGvJYYG1eZ7U VRQGSA0shEy+YFPJUHLg4o4oVB5mLrEX9Ywk1R4SW1I9Z72+fkxuo3hBarsOElTR6pN3iohua7 +Z8= X-SBRS: 2.7 X-MesageID: 11073294 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,414,1571716800"; d="c'?scan'208";a="11073294" To: References: <20200109121227.949665-1-george.dunlap@citrix.com> <20200109121227.949665-2-george.dunlap@citrix.com> From: George Dunlap Openpgp: preference=signencrypt Autocrypt: addr=george.dunlap@citrix.com; prefer-encrypt=mutual; keydata= mQINBFPqG+MBEACwPYTQpHepyshcufo0dVmqxDo917iWPslB8lauFxVf4WZtGvQSsKStHJSj 92Qkxp4CH2DwudI8qpVbnWCXsZxodDWac9c3PordLwz5/XL41LevEoM3NWRm5TNgJ3ckPA+J K5OfSK04QtmwSHFP3G/SXDJpGs+oDJgASta2AOl9vPV+t3xG6xyfa2NMGn9wmEvvVMD44Z7R W3RhZPn/NEZ5gaJhIUMgTChGwwWDOX0YPY19vcy5fT4bTIxvoZsLOkLSGoZb/jHIzkAAznug Q7PPeZJ1kXpbW9EHHaUHiCD9C87dMyty0N3TmWfp0VvBCaw32yFtM9jUgB7UVneoZUMUKeHA fgIXhJ7I7JFmw3J0PjGLxCLHf2Q5JOD8jeEXpdxugqF7B/fWYYmyIgwKutiGZeo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ZGxZ9W22yfw5uThSHQ4y09wRWAIYvhJsKnPGGC2KDxFvtz5 4pYYNe8Icy4bwsxcgbaSFaRh+mYtts6wE9VzyJvyfTqbe8VrvE+3InG5rrlNn51AO6M4Wv20 iFEgYanJXfhicl0WCQrHyTLfdB5p1w+072CL8uryHQVfD0FcDe+J/wl3bmYze+aD1SlPzFoI MaSIXKejC6oh6DAT4rvU8kMAbX90T834Mvbc3jplaWorNJEwjAH/r+v877AI9Vsmptis+rni JwUissjRbcdlkKBisoUZRPmxQeUifxUpqgulZcYwbEC/a49+WvbaYUriaDLHzg9xisijHwD2 yWV8igBeg+cmwnk0mPz8tIVvwi4lICAgXob7HZiaqKnwaDXs4LiS4vdG5s/ElnE3rIc87yru 24n3ypeDZ6f5LkdqL1UNp5/0Aqbr3EiN7/ina4YVyscy9754l944kyHnnMRLVykg0v+kakj0 h0RJ5LbfLAMM8M52KIA3y14g0Fb7kHLcOUMVcgfQ3PrN6chtC+5l6ouDIlSLR3toxH8Aam7E rIFfe2Dk+lD9A9BVd2rfoHA= Message-ID: <471b37ec-3401-91c3-1a6e-508c065beb4f@citrix.com> Date: Thu, 9 Jan 2020 17:07:31 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20200109121227.949665-2-george.dunlap@citrix.com> Content-Type: multipart/mixed; boundary="------------519163A99AE3FE0EC7A8B8B6" Content-Language: en-US Subject: Re: [Xen-devel] [PATCH v2 2/2] libxl: Add new "notify-only" childproc mode X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony Perard , Ian Jackson , Nick Rosbrook , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" --------------519163A99AE3FE0EC7A8B8B6 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit On 1/9/20 12:12 PM, George Dunlap wrote: > libxl needs to be able to know when processes it forks have completed. > > At the moment, libxl has two basic mode (with some variations). In > one mode -- libxl_sigchld_owner_libxl* -- libxl sets up its own > SIGCHLD signal handler, and also handles the event loop that allows > libxl to safely block until the child in question is finished (using a > self-pipe for the SIGCHLD handler to notify the waiters that it's time > to look for reaped children). > > In the other mode, libxl does not set up the SIGCHLD handler, nor does > it do anything with processing the event loop; it expects the library > caller to handle the event loop itself. > > The golang runtime manages its own processes, and thus must use > SIGCHLD itself; and it has an easy way for other users to get SIGCHLD > notifications. However, because its event loop is hidden away behind > abstractions, it's not easy to hook into; and there's no need -- the > golang runtime assumes that C function calls may block, and handles > everything behind the scenes. FWIW, attached is a C program that behaves as I think golang would behave, which hangs in `mainloop` mode. It's actually got two modes: Run it without any arguments, and it will run in "default" mode (not setting up a SIGCHLD nor setting childproc_mode); run with at least one argument (whatever it is), it will run in `mainloop` mode, and hang after the second SIGCHLD event. -George --------------519163A99AE3FE0EC7A8B8B6 Content-Type: text/x-csrc; name="xltest_sigchld_main.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="xltest_sigchld_main.c" #include #include #include #include #include #include #include #include #include char * malloc_copy(const char *src) { int len = strlen(src); char * dst = malloc(strlen(src)+1); strncpy(dst, src, len); return dst; } libxl_ctx *ctx; int self_pipe_wakeup(int fd) { /* Called from signal handlers, so needs to be async-signal-safe */ static const char buf[1] = ""; for (;;) { int r = write(fd, buf, 1); if (r==1) return 0; assert(r==-1); if (errno == EINTR) continue; if (errno == EWOULDBLOCK) return 0; if (!errno) abort(); return errno; } } int self_pipe_eatall(int fd) { char buf[256]; for (;;) { int r = read(fd, buf, sizeof(buf)); if (r == sizeof(buf)) continue; if (r >= 0) return 0; assert(r == -1); if (errno == EINTR) continue; if (errno == EWOULDBLOCK) return 0; assert(errno); return errno; } } int sigchld_selfpipe[2]; static void *sigchld_helper(void *fd) { struct pollfd pfd; int r; pfd.fd = (int)(unsigned long)fd; pfd.events = POLLIN | POLLHUP; while (true) { // Wait for a sigchld on [0] fprintf(stderr, "Waiting for self-pipe\n"); r = poll(&pfd, 1, -1); if (r < 0) { if (errno == EINTR) continue; perror("poll"); return NULL; } if (pfd.revents == POLLHUP) { fprintf(stderr, "Received POLLHUP, closing helper\n"); return NULL; } fprintf(stderr, "Self-pipe received, calling libxl_childproc_sigchld_occurred\n"); self_pipe_eatall(pfd.fd); libxl_childproc_sigchld_occurred(ctx); } return NULL; } static void sigchld_handler(int signo) { // Signal on pipe [1] fprintf(stderr, "SIGCHLD received, self-signaling\n"); self_pipe_wakeup(sigchld_selfpipe[1]); } void setup_sigchld(void) { struct sigaction ours, old; pthread_t t; int i, flags, r; // Get self-signal pipe if (pipe(sigchld_selfpipe) < 0) { perror("Failed to create a pipe"); exit(1); } r = pthread_create(&t, NULL, sigchld_helper, (void *)(unsigned long)sigchld_selfpipe[0]); if (r < 0) { perror("Creating helper thread"); exit(1); } // Make non-blocking for (i = 0; i < 2; i++) { int fd = sigchld_selfpipe[i]; flags = fcntl(fd, F_GETFL); if (flags == -1) { perror("Getting block flags"); exit(1); } flags |= O_NONBLOCK; r = fcntl(fd, F_SETFL, flags); if (flags == -1) { perror("Setting pipe non-blocking"); exit(1); } } memset(&ours,0,sizeof(ours)); ours.sa_handler = sigchld_handler; sigemptyset(&ours.sa_mask); ours.sa_flags = SA_NOCLDSTOP | SA_RESTART; r = sigaction(SIGCHLD, &ours, &old); assert(!r); } int main(int argc, char * argv[]) { int rc; xentoollog_logger_stdiostream * xtl; libxl_domain_config cconfig; uint32_t domid; bool mainloop = false; if (argc > 1) mainloop=true; if (mainloop) setup_sigchld(); xtl = xtl_createlogger_stdiostream(stderr, XTL_DEBUG, 0); rc = libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, (xentoollog_logger*)xtl); if (rc) { fprintf(stderr, "Getting libxl_ctx: %d", rc); exit(1); } if (mainloop) { libxl_childproc_hooks *cp = malloc(sizeof(*cp)); cp->chldowner = libxl_sigchld_owner_mainloop; libxl_childproc_setmode(ctx, cp, NULL); } libxl_domain_config_init(&cconfig); libxl_domain_build_info_init_type(&cconfig.b_info, LIBXL_DOMAIN_TYPE_PV); cconfig.c_info.type = LIBXL_DOMAIN_TYPE_PV; cconfig.c_info.name = malloc_copy("c6-01"); cconfig.b_info.max_vcpus = 4; cconfig.b_info.max_memkb = 2048*1024; cconfig.b_info.target_memkb = 2048*1024; cconfig.on_crash = LIBXL_ACTION_ON_SHUTDOWN_DESTROY; cconfig.b_info.bootloader = malloc_copy("pygrub"); cconfig.num_disks = 1; cconfig.disks = malloc(sizeof(libxl_device_disk)); libxl_device_disk_init(cconfig.disks); cconfig.disks[0].vdev = malloc_copy("hda"); cconfig.disks[0].format = LIBXL_DISK_FORMAT_RAW; cconfig.disks[0].pdev_path = malloc_copy("/images/c6-01.raw"); cconfig.disks[0].readwrite = 1; cconfig.num_nics = 1; cconfig.nics = malloc(sizeof(libxl_device_nic)); libxl_device_nic_init(cconfig.nics); rc = libxl_domain_create_new(ctx, &cconfig, &domid, NULL, NULL); if (rc) { fprintf(stderr, "Creating domain: %d", rc); exit(1); } printf("Created domain with id %d", domid); libxl_domain_config_dispose(&cconfig); if (mainloop) { close(sigchld_selfpipe[1]); close(sigchld_selfpipe[0]); } return 0; } --------------519163A99AE3FE0EC7A8B8B6 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcKaHR0cHM6Ly9saXN0 cy54ZW5wcm9qZWN0Lm9yZy9tYWlsbWFuL2xpc3RpbmZvL3hlbi1kZXZlbA== --------------519163A99AE3FE0EC7A8B8B6--