{"id":806673,"url":"http://patchwork.ozlabs.org/api/1.0/patches/806673/?format=json","project":{"id":41,"url":"http://patchwork.ozlabs.org/api/1.0/projects/41/?format=json","name":"GNU C Library","link_name":"glibc","list_id":"libc-alpha.sourceware.org","list_email":"libc-alpha@sourceware.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<CALoOobNv3GUJEatKp-36VuepLbbpjqgmfKngkwY2hD_nPfhJ8w@mail.gmail.com>","date":"2017-08-28T17:16:55","name":"Extend tst-{atexit,at_quick_exit,cxa_atexit,onexit} to verify inheritance across fork","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"10c17498bc812eeece98691fda329dd440a2b85c","submitter":{"id":6128,"url":"http://patchwork.ozlabs.org/api/1.0/people/6128/?format=json","name":"Paul Pluzhnikov","email":"ppluzhnikov@google.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/glibc/patch/CALoOobNv3GUJEatKp-36VuepLbbpjqgmfKngkwY2hD_nPfhJ8w@mail.gmail.com/mbox/","series":[{"id":222,"url":"http://patchwork.ozlabs.org/api/1.0/series/222/?format=json","date":"2017-08-28T17:16:55","name":"Extend tst-{atexit,at_quick_exit,cxa_atexit,onexit} to verify inheritance across fork","version":1,"mbox":"http://patchwork.ozlabs.org/series/222/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/806673/checks/","tags":{},"headers":{"Return-Path":"<libc-alpha-return-83792-incoming=patchwork.ozlabs.org@sourceware.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list libc-alpha@sourceware.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=sourceware.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=libc-alpha-return-83792-incoming=patchwork.ozlabs.org@sourceware.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tsecure) header.d=sourceware.org header.i=@sourceware.org\n\theader.b=\"xxIldFwJ\"; dkim-atps=neutral","sourceware.org; auth=none"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xgz3v5tHRz9s7M\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 29 Aug 2017 03:17:47 +1000 (AEST)","(qmail 6667 invoked by alias); 28 Aug 2017 17:17:40 -0000","(qmail 5981 invoked by uid 89); 28 Aug 2017 17:17:38 -0000"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:mime-version:from:date:message-id:subject:to\n\t:content-type; q=dns; s=default; b=YBctBZLlRMn2HvvNZErYqrevvWmXi\n\tx2Lptc4P2wi1IqLN+L4FJaoovvcpgpfVSqtvqhNQS/ug5eqWb+8r8HbdIgM+bQOP\n\tIMpw5AkGdUXpiLuKkmtJfCTlHmdnt3SPBWCHCcQaU744GAvkjSUUnCPuuyDEw9ZZ\n\tC5AkmpQyMmIHM4=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id\n\t:list-unsubscribe:list-subscribe:list-archive:list-post\n\t:list-help:sender:mime-version:from:date:message-id:subject:to\n\t:content-type; s=default; bh=Bf7mbx59LrqNRFkebJJmFT3jQZg=; b=xxI\n\tldFwJ04wBIqkNrPgrEyS8kqvdnSbCg1UwqX0bha8EX2rJIWjLWahkRJp4s75U3Oe\n\tSVnUc99sp4ysIVO+hJxWlOyaDnD7VGrGD7RTMJ10OUKLiGpEA0rW5msOVGFRoQwu\n\tOOkEOLol0Bm0ESu8MuCh2QIfuHTauy9e8BxnV9oc=","Mailing-List":"contact libc-alpha-help@sourceware.org; run by ezmlm","Precedence":"bulk","List-Id":"<libc-alpha.sourceware.org>","List-Unsubscribe":"<mailto:libc-alpha-unsubscribe-incoming=patchwork.ozlabs.org@sourceware.org>","List-Subscribe":"<mailto:libc-alpha-subscribe@sourceware.org>","List-Archive":"<http://sourceware.org/ml/libc-alpha/>","List-Post":"<mailto:libc-alpha@sourceware.org>","List-Help":"<mailto:libc-alpha-help@sourceware.org>,\n\t<http://sourceware.org/ml/#faqs>","Sender":"libc-alpha-owner@sourceware.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-25.4 required=5.0 tests=AWL, BAYES_00,\n\tGIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3,\n\tRCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD,\n\tSPF_PASS autolearn=ham version=3.3.2 spammy=registrations,\n\t9640, 2120","X-HELO":"mail-ua0-f176.google.com","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:from:date:message-id:subject:to;\n\tbh=l3ocmsvJfQxZ15lKwu1r278Z2K0QgcR6o8jnOnQ7ix8=;\n\tb=eBU3RZJcOQ4hrDL4IPd1vuDxqRzGJzOGnrIqXEtzad2I05RqEbrp0+FyUOmwsGPQ2p\n\tM+iZboFwfSsVO07q639ItYE5agcJZmydUhc1U/OKfIhAv3DgPHNGSghOHvOmWgcCpG6I\n\twGlOAoicOLRtJ+/JdV3g+822P8fOWz2SD94ZWpo4S3ttF4NWUYv79dniu6QGDp+lWnqV\n\tpVzmj1n5Jb9dQpBynWKmHdvldEW1OO/rmGx2WR2HuVDX+j7EiMfvjoQvDlfoNtpgdqbX\n\ta2q1R08rgfMwBXrJtzEf8Fa+vpmwBYkc5DlNvtHhjhQVzKDvlv+00H5WlUDzuGeafoD5\n\tqtBA==","X-Gm-Message-State":"AHYfb5jzoPJQb0qM+DkrYN+FIbeB+mUJBUQpMrzVr194oj9SY6MNT4wZ\n\txrC3sBP22maMZxCakei3g6nCtJnV4ssBoKMwEg==","X-Google-Smtp-Source":"ADKCNb7oFUkbsoAGdtJQu2NRWO9v6WZp3c+kPmxYWqv/fQgPy/EShUXquEUq5qD2V/ulG7REE/4xg9l8BvAgTYLbf9k=","X-Received":"by 10.176.23.84 with SMTP id k20mr854618uaf.130.1503940646393;\n\tMon, 28 Aug 2017 10:17:26 -0700 (PDT)","MIME-Version":"1.0","From":"Paul Pluzhnikov <ppluzhnikov@google.com>","Date":"Mon, 28 Aug 2017 10:16:55 -0700","Message-ID":"<CALoOobNv3GUJEatKp-36VuepLbbpjqgmfKngkwY2hD_nPfhJ8w@mail.gmail.com>","Subject":"[PATCH] Extend tst-{atexit, at_quick_exit, cxa_atexit,\n\tonexit} to verify inheritance across fork","To":"GLIBC Devel <libc-alpha@sourceware.org>","Content-Type":"multipart/mixed; boundary=\"f403043620f200a9ac0557d378d1\""},"content":"Greetings,\n\nAttached patch implements one of the TODOs in stdlib/tst-atexit-common.c\n\n\n2017-08-28  Paul Pluzhnikov  <ppluzhnikov@google.com>\n\n        * stdlib/tst-atexit-common.c (do_test): Test handler inheritance\n        by child.","diff":"diff --git a/stdlib/tst-atexit-common.c b/stdlib/tst-atexit-common.c\nindex 262235a478..99b00bf3aa 100644\n--- a/stdlib/tst-atexit-common.c\n+++ b/stdlib/tst-atexit-common.c\n@@ -21,11 +21,20 @@\n #include <stdlib.h>\n #include <string.h>\n #include <unistd.h>\n+#include <sys/wait.h>\n \n #define MAX_ATEXIT 20  /* Large enough for current set of invocations.  */\n static char crumbs[MAX_ATEXIT];\n static int next_slot = 0;\n \n+/* Helper: flush stdout and _exit.  */\n+static void\n+_exit_with_flush (int code)\n+{\n+  fflush (stdout);\n+  _exit (code);\n+}\n+\n static void\n fn0 (void)\n {\n@@ -60,11 +69,11 @@ fn_final (void)\n   const char expected[] = \"3021121130211\";\n \n   if (strcmp (crumbs, expected) == 0)\n-    _exit (0);\n+    _exit_with_flush (0);\n \n   printf (\"crumbs:   %s\\n\", crumbs);\n   printf (\"expected: %s\\n\", expected);\n-  _exit (1);\n+  _exit_with_flush (1);\n }\n \n /* This is currently just a basic test to verify that exit handlers execute\n@@ -72,8 +81,7 @@ fn_final (void)\n \n    TODO: Additional tests that we should do:\n    1. POSIX says we need to support at least ATEXIT_MAX\n-   2. Verify that fork'd child inherit the registrations of the parent.\n-   3. ...  */\n+   2. ...  */\n \n static int\n do_test (void)\n@@ -88,6 +96,40 @@ do_test (void)\n   ATEXIT (fn1);\n   ATEXIT (fn3);\n \n+  /* Verify that handlers registered above are inherited across fork.  */\n+  const pid_t child = fork ();\n+  switch (child)\n+    {\n+    case -1:\n+      printf (\"fork: %m\\n\");\n+      _exit_with_flush (3);\n+    case 0:  /* Child.  */\n+      break;\n+    default:\n+      {\n+\tint status;\n+\tconst pid_t exited = waitpid (child, &status, 0);\n+\tif (child != exited)\n+\t  {\n+\t    printf (\"unexpected child: %d, expected %d\\n\", exited, child);\n+\t    _exit_with_flush (4);\n+\t  }\n+\tif (status != 0)\n+\t  {\n+\t    if (WIFEXITED (status))\n+\t      printf (\"unexpected exit status %d from child %d\\n\",\n+\t\t      WEXITSTATUS (status), child);\n+\t    else if (WIFSIGNALED (status))\n+\t      printf (\"unexpected signal %d from child %d\\n\",\n+\t\t      WTERMSIG (status), child);\n+\t    else\n+\t      printf (\"unexpected status %d from child %d\\n\", status, child);\n+\t    _exit_with_flush (5);\n+\t  }\n+      }\n+      break;\n+    }\n+\n   EXIT (2);  /* If we see this exit code, fn_final must have not worked.  */\n }\n \n","prefixes":[]}