Bug 196844 - [patch][doc] Add EXAMPLES section to kqueue(2) man page
Summary: [patch][doc] Add EXAMPLES section to kqueue(2) man page
Status: Closed FIXED
Alias: None
Product: Documentation
Classification: Unclassified
Component: Books & Articles (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-doc (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-18 18:43 UTC by Fernando Apesteguía
Modified: 2022-04-13 06:06 UTC (History)
4 users (show)

See Also:


Attachments
patch to kqueue(2) man page (1.44 KB, patch)
2015-01-18 18:43 UTC, Fernando Apesteguía
no flags Details | Diff
patch to kqueue(2) man page (1.39 KB, patch)
2016-04-24 18:26 UTC, Fernando Apesteguía
no flags Details | Diff
Remove EV_ONESHOT (1.23 KB, text/x-csrc)
2016-04-26 12:27 UTC, Konstantin Belousov
no flags Details
Fix EXAMPLE in kqueue.2 (845 bytes, patch)
2022-04-11 18:47 UTC, Fernando Apesteguía
no flags Details | Diff
Patch with escape sequence properly escaped. (846 bytes, patch)
2022-04-12 06:29 UTC, Fernando Apesteguía
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fernando Apesteguía freebsd_committer freebsd_triage 2015-01-18 18:43:31 UTC
Created attachment 151802 [details]
patch to kqueue(2) man page

The attached patch adds an EXAMPLE to kqueue(2) man page. I truly think examples are a good ay to improve our documentation.

I tried to follow style(9) but I probably missed something
Comment 1 Benedict Reuschling freebsd_committer freebsd_triage 2016-04-24 12:50:19 UTC
I've created a review for it (but forgot to include the submitter). Here is the link:
https://reviews.freebsd.org/D6082

Can the PR submitter address the comments and provide a new patch to this PR? Thanks!
Comment 2 Fernando Apesteguía freebsd_committer freebsd_triage 2016-04-24 15:49:07 UTC
(In reply to Benedict Reuschling from comment #1)
I had completely forgotten about this patch...

I will have a look at it and send a new version.

Thanks!
Comment 3 Fernando Apesteguía freebsd_committer freebsd_triage 2016-04-24 18:26:34 UTC
Created attachment 169639 [details]
patch to kqueue(2) man page

Patch against the 10.3 version of the manpage.

I addressed the comments in phabricator but the one about using EV_ONESHOT and re-arming the event. I don't fully understand what kib@ means. It seems natural to me and easy to understand since only one event is returned and also it is removed after it is consumed. But as I say I don't fully understand what he means.
Comment 4 Konstantin Belousov freebsd_committer freebsd_triage 2016-04-26 12:26:50 UTC
(In reply to fernando.apesteguia from comment #3)
I mean that EV_ONESHOT is excessive when you continuously poll for the same event.  It causes useless work for re-registering the event for each iteration.

I updated the code by removing the EV_ONESHOT (EV_CLEAR is needed because the vnode events are level-triggered), and also did misc. style cleanups.
Comment 5 Konstantin Belousov freebsd_committer freebsd_triage 2016-04-26 12:27:38 UTC
Created attachment 169715 [details]
Remove EV_ONESHOT
Comment 6 Fernando Apesteguía freebsd_committer freebsd_triage 2016-04-26 16:17:40 UTC
(In reply to Konstantin Belousov from comment #4)
OK, I see.

Thanks.
Comment 7 Benedict Reuschling freebsd_committer freebsd_triage 2016-05-01 17:50:25 UTC
Updated the review, integrating kib's latest patch.
Comment 8 commit-hook freebsd_committer freebsd_triage 2016-05-01 18:09:42 UTC
A commit references this bug:

Author: bcr
Date: Sun May  1 18:09:35 UTC 2016
New revision: 298893
URL: https://svnweb.freebsd.org/changeset/base/298893

Log:
  Provide an example to the kqueue man page, showing
  a basic usage example.  Although it is an
  untypical example for the use of kqueue, it is
  better than nothing and should get people started.

  PR:			196844
  Submitted by:		fernando.apesteguia@gmail.com
  Reviewed by:		kib
  Approved by:		kib
  MFC after:		5 days
  Differential Revision:	https://reviews.freebsd.org/D6082

Changes:
  head/lib/libc/sys/kqueue.2
Comment 9 commit-hook freebsd_committer freebsd_triage 2016-05-06 17:56:06 UTC
A commit references this bug:

Author: bcr
Date: Fri May  6 17:55:11 UTC 2016
New revision: 299190
URL: https://svnweb.freebsd.org/changeset/base/299190

Log:
  MFC r298893:
  Provide an example to the kqueue man page, showing
  a basic usage example.  Although it is an
  untypical example for the use of kqueue, it is
  better than nothing and should get people started.

  PR:		196844
  Submitted by:	fernando.apesteguia@gmail.com
  Reviewed by:	kib
  Approved by:	kib
  Differential Revision:  https://reviews.freebsd.org/D6082

Changes:
_U  stable/10/
  stable/10/lib/libc/sys/kqueue.2
Comment 10 Benedict Reuschling freebsd_committer freebsd_triage 2016-05-06 17:57:10 UTC
MFC is done. Thanks for your patches, everyone! PR closed.
Comment 11 Eugene Grosbein freebsd_committer freebsd_triage 2022-04-11 10:56:32 UTC
Re-opening this old PR because of a bug in the example: it evaluates (event.flags & EV_ERROR) for "changelist" argument being "const" and unchanged by system call.

The documentation bug needs to be fixed.
Comment 12 Pau Amma 2022-04-11 14:20:40 UTC
(In reply to Eugene Grosbein from comment #11)

*stares at kevent(2) for a while*

So the first kevent call should be ret = kevent(kq, &event, 1, &tevent, 1, NULL); and the test should be for tevent.flags & EV_ERROR instead of event? Would that correct the problem?
Comment 13 Eugene Grosbein freebsd_committer freebsd_triage 2022-04-11 14:25:58 UTC
(In reply to PauAmma from comment #12)

It depends on what kind of example we want here.
Comment 14 Fernando Apesteguía freebsd_committer freebsd_triage 2022-04-11 17:59:25 UTC
Hi Eugene,

You are right. That "event" passed as "changelits" will never change. We could remove the check altogether since we are checking the return value of the syscall. It does not add any value.

Or do you have a different thing in mind?
Comment 15 Eugene Grosbein freebsd_committer freebsd_triage 2022-04-11 18:11:08 UTC
(In reply to Fernando Apesteguía from comment #14)

Yes, remove it. Maybe re-add later to the next call that returns events.
Comment 16 Fernando Apesteguía freebsd_committer freebsd_triage 2022-04-11 18:47:09 UTC
Created attachment 233152 [details]
Fix EXAMPLE in kqueue.2

mandoc -Tlint and igor clean.
Comment 17 Pau Amma 2022-04-12 03:29:03 UTC
Comment on attachment 233152 [details]
Fix EXAMPLE in kqueue.2

>-	    printf("Something was written in '%s'\en", argv[1]);
>-	}
>+	    if (tevent.flags & EV_ERROR)
>+		errx(EXIT_FAILURE, "Event error: %s", strerror(event.data));
>+	    else
>+		printf("Something was written in '%s'\n", argv[1]);

\en, since this is a manual page, not a C source file.
Comment 18 Fernando Apesteguía freebsd_committer freebsd_triage 2022-04-12 06:29:59 UTC
Created attachment 233158 [details]
Patch with escape sequence properly escaped.

Thanks for catching that.
Comment 19 Pau Amma 2022-04-12 21:19:59 UTC
(In reply to Fernando Apesteguía from comment #18)
LGTM now.
Comment 20 Fernando Apesteguía freebsd_committer freebsd_triage 2022-04-13 05:27:16 UTC
Cool.

FYI, I'm not an src committer. I will need explicit approval from some src developer or member of manpages@. We can do it in this PR, no need to create a review.

Cheers.
Comment 21 Eugene Grosbein freebsd_committer freebsd_triage 2022-04-13 05:48:07 UTC
(In reply to Fernando Apesteguía from comment #20)

Approved.
Comment 22 commit-hook freebsd_committer freebsd_triage 2022-04-13 06:05:24 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e07b0c12ba6435421ceb7dd028402d5cbfc1f1dd

commit e07b0c12ba6435421ceb7dd028402d5cbfc1f1dd
Author:     Fernando Apesteguía <fernape@FreeBSD.org>
AuthorDate: 2022-04-11 18:40:28 +0000
Commit:     Fernando Apesteguía <fernape@FreeBSD.org>
CommitDate: 2022-04-13 06:01:58 +0000

    [patch][doc] Fix EXAMPLE in kqueue(2)

    The error control was not properly implemented. "changelist" is const, hence
    event.flags is never changed by the syscall.

    PR:     196844
    Reported by:    eugen@
    Reviewed by:    PauAmma <pauamma@gundo.com>
    Approved by:    eugen@
    Fixes:  8c231786f01b9f8614e2fe5b47196db1caa7a772

 lib/libc/sys/kqueue.2 | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
Comment 23 Fernando Apesteguía freebsd_committer freebsd_triage 2022-04-13 06:06:39 UTC
Committed,

Thank you both.