<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en" style="--code-editor-font: var(--default-mono-font, "GitLab Mono"), JetBrains Mono, Menlo, DejaVu Sans Mono, Liberation Mono, Consolas, Ubuntu Mono, Courier New, andale mono, lucida console, monospace;">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title>
GitLab
</title>

<style data-premailer="ignore" type="text/css">
a { color: #1068bf; }
</style>

<style>img {
max-width: 100%; height: auto;
}
body {
font-size: .875rem;
}
body {
-webkit-text-shadow: hsla(0,0%,100%,.01) 0 0 1px;
}
body {
font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"; font-size: inherit;
}
</style>
</head>
<body style="font-size: inherit; -webkit-text-shadow: hsla(0,0%,100%,.01) 0 0 1px; font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";">
<div class="content">

<p class="details" style="font-style: italic; color: #626168;">
Issue created by <a href="https://gitlab.rtems.org/sngwkim915">Sang Woo Kim</a>: <a href="https://gitlab.rtems.org/rtems/pkg/rtems-libbsd/-/work_items/102">#102</a>
</p>
<div class="md" style="position: relative; z-index: 1; color: #3a383f; word-wrap: break-word;">
<h2 id="user-content-summary" dir="auto" style="margin-top: 0px; margin-bottom: 10px;" align="initial">Summary<a href="#summary" aria-label="Link to heading 'Summary'" data-heading-content="Summary" class="anchor" style="margin-top: 0px;"></a>
</h2>
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial">Two things remain in the area <a href="https://gitlab.rtems.org/rtems/pkg/rtems-libbsd/-/work_items/41" title="Socket close fails when using kqueue" class="gfm gfm-issue" data-original="#41" data-link="false" data-link-reference="false" data-issue="29067" data-project="13" data-iid="41" data-namespace-path="rtems/pkg/rtems-libbsd" data-project-path="rtems/pkg/rtems-libbsd" data-issue-type="issue" data-container="body" data-placement="top" data-reference-type="issue" style="margin-top: 0px;">#41 (closed)</a> / <a href="https://gitlab.rtems.org/rtems/pkg/rtems-libbsd/-/work_items/42" title="Socket close fails when using kqueue" class="gfm gfm-issue" data-original="#42" data-link="false" data-link-reference="false" data-issue="29068" data-project="13" data-iid="42" data-namespace-path="rtems/pkg/rtems-libbsd" data-project-path="rtems/pkg/rtems-libbsd" data-issue-type="issue" data-container="body" data-placement="top" data-reference-type="issue">#42 (closed)</a> / <a href="https://gitlab.rtems.org/rtems/pkg/rtems-libbsd/-/work_items/43" title="Socket close fails when using kqueue" class="gfm gfm-issue" data-original="#43" data-link="false" data-link-reference="false" data-issue="29069" data-project="13" data-iid="43" data-namespace-path="rtems/pkg/rtems-libbsd" data-project-path="rtems/pkg/rtems-libbsd" data-issue-type="issue" data-container="body" data-placement="top" data-reference-type="issue">#43 (closed)</a> closed, both on the current <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">7-freebsd-14</code> and <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">6-freebsd-14</code>. Found by reading the code while working on <a href="https://gitlab.rtems.org/rtems/pkg/rtems-libbsd/-/work_items/101" title="dup() and fcntl(F_DUPFD) fail with ENXIO for libbsd descriptors" class="gfm gfm-issue" data-original="#101" data-link="false" data-link-reference="false" data-issue="29858" data-project="13" data-iid="101" data-namespace-path="rtems/pkg/rtems-libbsd" data-project-path="rtems/pkg/rtems-libbsd" data-issue-type="issue" data-container="body" data-placement="top" data-reference-type="issue">#101</a>, not by a failing test.</p>
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial"><code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0px; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">50d0f16d</code> (<a href="https://gitlab.rtems.org/rtems/pkg/rtems-libbsd/-/merge_requests/70" title="sys/kern/kern_event.c: Fix kqueue double hold" class="gfm gfm-merge_request" data-original="!70" data-link="false" data-link-reference="false" data-merge-request="1279" data-project="13" data-project-path="rtems/pkg/rtems-libbsd" data-iid="70" data-container="body" data-placement="top" data-reference-type="merge_request">!70 (merged)</a>) drops the hold only when <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">fget()</code> succeeds:</p>
<div class="gl-relative markdown-code-block js-markdown-code">
<pre data-canonical-lang="c" class="code highlight js-syntax-highlight language-c" v-pre="true" style="display: block; font-size: 14px; color: #3a383f; line-height: 1.6em; overflow-x: auto; border-radius: .25rem; position: relative; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: break-all; word-wrap: break-word; background-color: #fbfafd; margin: 0px 0 1rem; padding: 12px; border: 1px solid #dcdcde;"><code style="font-size: inherit; color: inherit; word-wrap: normal; word-break: keep-all; background-color: inherit; border-radius: .25rem; white-space: pre; margin-top: 0px; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; overflow-wrap: normal; padding: unset;"><span id="LC1" class="line" lang="c" style="margin-top: 0px;"><span class="k" style="margin-top: 0px;">if</span> <span class="p">(</span><span class="n">iop</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span></span>
<span id="LC2" class="line" lang="c">        <span class="n" style="margin-top: 0px;">error</span> <span class="o">=</span> <span class="n">fget</span><span class="p">(</span><span class="n">td</span><span class="p">,</span> <span class="n">ffd</span><span class="p">,</span> <span class="o">&</span><span class="n">cap_event_rights</span><span class="p">,</span> <span class="o">&</span><span class="n">fp</span><span class="p">);</span></span>
<span id="LC3" class="line" lang="c">        <span class="k" style="margin-top: 0px;">if</span> <span class="p">(</span><span class="o">!</span><span class="n">error</span><span class="p">)</span> <span class="p">{</span></span>
<span id="LC4" class="line" lang="c">                <span class="n" style="margin-top: 0px;">rtems_bsd_libio_iop_drop</span><span class="p">(</span><span class="n">kev</span><span class="o">-></span><span class="n">ident</span><span class="p">);</span></span>
<span id="LC5" class="line" lang="c">        <span class="p" style="margin-top: 0px;">}</span></span>
<span id="LC6" class="line" lang="c"><span class="p" style="margin-top: 0px;">}</span></span></code></pre>
<copy-code></copy-code><insert-code-snippet></insert-code-snippet>
</div>
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial"><code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0px; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">rtems_bsd_libio_iop_hold(kev->ident, &iop)</code> has already taken the reference by then, whatever <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">fget()</code> does next, so a failing <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">fget()</code> leaks it and the descriptor can never be closed — <a href="https://gitlab.rtems.org/rtems/pkg/rtems-libbsd/-/work_items/41" title="Socket close fails when using kqueue" class="gfm gfm-issue" data-original="#41" data-link="false" data-link-reference="false" data-issue="29067" data-project="13" data-iid="41" data-namespace-path="rtems/pkg/rtems-libbsd" data-project-path="rtems/pkg/rtems-libbsd" data-issue-type="issue" data-container="body" data-placement="top" data-reference-type="issue">#41 (closed)</a>'s symptom on a narrower path. The drop belongs outside the <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">if</code>.</p>
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial">Second, <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0px; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">closefp_impl()</code> passes <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">knote_fdclose()</code> a BSD descriptor, but <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">kqueue_register()</code> indexes a knote by the identifier the caller passed, which for a libbsd descriptor is the libio one. It misses the closing file's knotes, leaving the reference they hold on <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">fp</code>, and drops the knotes of whichever unrelated libio descriptor has that number. This is only observable once a file can have more than one descriptor, so it comes with <a href="https://gitlab.rtems.org/rtems/pkg/rtems-libbsd/-/work_items/101" title="dup() and fcntl(F_DUPFD) fail with ENXIO for libbsd descriptors" class="gfm gfm-issue" data-original="#101" data-link="false" data-link-reference="false" data-issue="29858" data-project="13" data-iid="101" data-namespace-path="rtems/pkg/rtems-libbsd" data-project-path="rtems/pkg/rtems-libbsd" data-issue-type="issue" data-container="body" data-placement="top" data-reference-type="issue">#101</a>.</p>
<p dir="auto" style="color: #3a383f; margin: 0px 0px 1rem;" align="initial"><code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0px; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">testsuite/selectpollkqueue01</code> passes on <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">arm/xilinx_zynq_a9_qemu</code> before and after this change with identical output, so it says nothing about <a href="https://gitlab.rtems.org/rtems/pkg/rtems-libbsd/-/work_items/69" title="libbsd kqueue TCP peer close/reset notifications appear to be lost, maybe due to absence of NOTE_EOF?" class="gfm gfm-issue" data-original="#69" data-link="false" data-link-reference="false" data-issue="29356" data-project="13" data-iid="69" data-namespace-path="rtems/pkg/rtems-libbsd" data-project-path="rtems/pkg/rtems-libbsd" data-issue-type="issue" data-container="body" data-placement="top" data-reference-type="issue">#69</a> either way.</p>
<p dir="auto" style="color: #3a383f; margin: 0px;" align="initial">Fix: <a href="https://github.com/physwkim/rtems-libbsd/commit/92df493d1e5418da8c4bdda8dc2c40dabb2bc616" rel="nofollow noreferrer noopener" target="_blank" style="margin-top: 0px;">7-freebsd-14</a> · <a href="https://github.com/physwkim/rtems-libbsd/commit/d27be17071d3183be8f15979c0b104c0fb9e45e7" rel="nofollow noreferrer noopener" target="_blank">6-freebsd-14</a> · <a href="https://github.com/physwkim/rtems-libbsd/commit/6cef9d5992b42eea2eca9180dda72de6c16a4d76" rel="nofollow noreferrer noopener" target="_blank">6-freebsd-12</a></p>
</div>

</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #626168;">

<br>
<a href="https://gitlab.rtems.org/rtems/pkg/rtems-libbsd/-/work_items/102">View it on GitLab</a>.
<br>
You're receiving this email because of your account on <a target="_blank" rel="noopener noreferrer" href="https://gitlab.rtems.org">gitlab.rtems.org</a>. <a href="https://gitlab.rtems.org/-/sent_notifications/4-ap3pcitxyafpq7vlydkz85dks-k/unsubscribe" target="_blank" rel="noopener noreferrer">Unsubscribe</a> from this thread · <a href="https://gitlab.rtems.org/-/profile/notifications" target="_blank" rel="noopener noreferrer" class="mng-notif-link">Manage all notifications</a> · <a href="https://gitlab.rtems.org/help" target="_blank" rel="noopener noreferrer" class="help-link">Help</a>
<span style="color: transparent; font-size: 0; display: none; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0;">
Notification message regarding https://gitlab.rtems.org/rtems/pkg/rtems-libbsd/-/work_items/102 at 1785221184
</span>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Work item","url":"https://gitlab.rtems.org/rtems/pkg/rtems-libbsd/-/work_items/102"}}</script>


</p>
</div>
</body>
</html>