All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dave@treblig.org>
To: Alejandro Colomar <alx@kernel.org>
Cc: linux-man@vger.kernel.org
Subject: Re: [PATCH] man/man3/pthread_attr_init.3: Replace errc
Date: Wed, 20 Aug 2025 14:10:28 +0000	[thread overview]
Message-ID: <aKXXVO6VdrhXkidS@gallifrey> (raw)
In-Reply-To: <7r2bs3ccxjzex3atdkcutdn6rzqmjsczqucodyk3rgfsnevqun@i3szklptbqjf>

* Alejandro Colomar (alx@kernel.org) wrote:
> Hi Dave,

Hi Alex,

> On Wed, Aug 20, 2025 at 02:27:25AM +0100, dave@treblig.org wrote:
> > From: "Dr. David Alan Gilbert" <dave@treblig.org>
> > 
> > The pthread_attr_init.3 example uses 'errc' to exit on an error
> > printing the error code.  However, 'errc' is a BSDism that Linux
> > doesn't (and has never?) have.

> Libbsd provides a compatbility layer to provide errc(3bsd) on Linux (and
> many POSIX systems).  libbsd is available in many distros (in Debian,
> you should install libbsd-dev).  BTW, it would be nice if glibc decided
> to pick this API eventually.

To use that we'd still need to change to:
       #include <bsd/err.h>
and tell people to link with -lbsd

TBH using BSD only things in a Linux manpage with a _GNU_SOURCE define
seems odd.  The err()/errc()/errx() family of calls seems to be pretty
obscure, most [linux] people I checked with had never used them.
But at least err/errx are in normal glibc.

Dave

> 
> Have a lovely day!
> Alex
> 
> > Replace it by 'errx' with a strerror() call.
> > 
> > Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
> > ---
> >  man/man3/pthread_attr_init.3 | 31 ++++++++++++++++---------------
> >  1 file changed, 16 insertions(+), 15 deletions(-)
> > 
> > diff --git a/man/man3/pthread_attr_init.3 b/man/man3/pthread_attr_init.3
> > index e9058b8fe..9d0783e54 100644
> > --- a/man/man3/pthread_attr_init.3
> > +++ b/man/man3/pthread_attr_init.3
> > @@ -153,6 +153,7 @@ .SS Program source
> >  #include <pthread.h>
> >  #include <stdio.h>
> >  #include <stdlib.h>
> > +#include <string.h>
> >  #include <unistd.h>
> >  \&
> >  static void
> > @@ -165,7 +166,7 @@ .SS Program source
> >  \&
> >      s = pthread_attr_getdetachstate(attr, &i);
> >      if (s != 0)
> > -        errc(EXIT_FAILURE, s, "pthread_attr_getdetachstate");
> > +        errx(EXIT_FAILURE, "pthread_attr_getdetachstate: %s", strerror(s));
> >      printf("%sDetach state        = %s\[rs]n", prefix,
> >             (i == PTHREAD_CREATE_DETACHED) ? "PTHREAD_CREATE_DETACHED" :
> >             (i == PTHREAD_CREATE_JOINABLE) ? "PTHREAD_CREATE_JOINABLE" :
> > @@ -173,7 +174,7 @@ .SS Program source
> >  \&
> >      s = pthread_attr_getscope(attr, &i);
> >      if (s != 0)
> > -        errc(EXIT_FAILURE, s, "pthread_attr_getscope");
> > +        errx(EXIT_FAILURE, "pthread_attr_getscope: %s", strerror(s));
> >      printf("%sScope               = %s\[rs]n", prefix,
> >             (i == PTHREAD_SCOPE_SYSTEM)  ? "PTHREAD_SCOPE_SYSTEM" :
> >             (i == PTHREAD_SCOPE_PROCESS) ? "PTHREAD_SCOPE_PROCESS" :
> > @@ -181,7 +182,7 @@ .SS Program source
> >  \&
> >      s = pthread_attr_getinheritsched(attr, &i);
> >      if (s != 0)
> > -        errc(EXIT_FAILURE, s, "pthread_attr_getinheritsched");
> > +        errx(EXIT_FAILURE, "pthread_attr_getinheritsched: %s", strerror(s));
> >      printf("%sInherit scheduler   = %s\[rs]n", prefix,
> >             (i == PTHREAD_INHERIT_SCHED)  ? "PTHREAD_INHERIT_SCHED" :
> >             (i == PTHREAD_EXPLICIT_SCHED) ? "PTHREAD_EXPLICIT_SCHED" :
> > @@ -189,7 +190,7 @@ .SS Program source
> >  \&
> >      s = pthread_attr_getschedpolicy(attr, &i);
> >      if (s != 0)
> > -        errc(EXIT_FAILURE, s, "pthread_attr_getschedpolicy");
> > +        errx(EXIT_FAILURE, "pthread_attr_getschedpolicy: %s", strerror(s));
> >      printf("%sScheduling policy   = %s\[rs]n", prefix,
> >             (i == SCHED_OTHER) ? "SCHED_OTHER" :
> >             (i == SCHED_FIFO)  ? "SCHED_FIFO" :
> > @@ -198,17 +199,17 @@ .SS Program source
> >  \&
> >      s = pthread_attr_getschedparam(attr, &sp);
> >      if (s != 0)
> > -        errc(EXIT_FAILURE, s, "pthread_attr_getschedparam");
> > +        errx(EXIT_FAILURE, "pthread_attr_getschedparam: %s", strerror(s));
> >      printf("%sScheduling priority = %d\[rs]n", prefix, sp.sched_priority);
> >  \&
> >      s = pthread_attr_getguardsize(attr, &v);
> >      if (s != 0)
> > -        errc(EXIT_FAILURE, s, "pthread_attr_getguardsize");
> > +        errx(EXIT_FAILURE, "pthread_attr_getguardsize: %s", strerror(s));
> >      printf("%sGuard size          = %zu bytes\[rs]n", prefix, v);
> >  \&
> >      s = pthread_attr_getstack(attr, &stkaddr, &v);
> >      if (s != 0)
> > -        errc(EXIT_FAILURE, s, "pthread_attr_getstack");
> > +        errx(EXIT_FAILURE, "pthread_attr_getstack: %s", strerror(s));
> >      printf("%sStack address       = %p\[rs]n", prefix, stkaddr);
> >      printf("%sStack size          = %#zx bytes\[rs]n", prefix, v);
> >  }
> > @@ -225,7 +226,7 @@ .SS Program source
> >  \&
> >      s = pthread_getattr_np(pthread_self(), &gattr);
> >      if (s != 0)
> > -        errc(EXIT_FAILURE, s, "pthread_getattr_np");
> > +        errx(EXIT_FAILURE, "pthread_getattr_np: %s", strerror(s));
> >  \&
> >      printf("Thread attributes:\[rs]n");
> >      display_pthread_attr(&gattr, "\[rs]t");
> > @@ -255,37 +256,37 @@ .SS Program source
> >  \&
> >          s = pthread_attr_init(&attr);
> >          if (s != 0)
> > -            errc(EXIT_FAILURE, s, "pthread_attr_init");
> > +            errx(EXIT_FAILURE, "pthread_attr_init: %s", strerror(s));
> >  \&
> >          s = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
> >          if (s != 0)
> > -            errc(EXIT_FAILURE, s, "pthread_attr_setdetachstate");
> > +            errx(EXIT_FAILURE, "pthread_attr_setdetachstate: %s", strerror(s));
> >  \&
> >          s = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
> >          if (s != 0)
> > -            errc(EXIT_FAILURE, s, "pthread_attr_setinheritsched");
> > +            errx(EXIT_FAILURE, "pthread_attr_setinheritsched: %s", strerror(s));
> >  \&
> >          stack_size = strtoul(argv[1], NULL, 0);
> >  \&
> >          s = posix_memalign(&sp, sysconf(_SC_PAGESIZE), stack_size);
> >          if (s != 0)
> > -            errc(EXIT_FAILURE, s, "posix_memalign");
> > +            errx(EXIT_FAILURE, "posix_memalign: %s", strerror(s));
> >  \&
> >          printf("posix_memalign() allocated at %p\[rs]n", sp);
> >  \&
> >          s = pthread_attr_setstack(&attr, sp, stack_size);
> >          if (s != 0)
> > -            errc(EXIT_FAILURE, s, "pthread_attr_setstack");
> > +            errx(EXIT_FAILURE, "pthread_attr_setstack: %s", strerror(s));
> >      }
> >  \&
> >      s = pthread_create(&thr, attrp, &thread_start, NULL);
> >      if (s != 0)
> > -        errc(EXIT_FAILURE, s, "pthread_create");
> > +        errx(EXIT_FAILURE, "pthread_create: %s", strerror(s));
> >  \&
> >      if (attrp != NULL) {
> >          s = pthread_attr_destroy(attrp);
> >          if (s != 0)
> > -            errc(EXIT_FAILURE, s, "pthread_attr_destroy");
> > +            errx(EXIT_FAILURE, "pthread_attr_destroy: %s", strerror(s));
> >      }
> >  \&
> >      pause();    /* Terminates when other thread calls exit() */
> > -- 
> > 2.50.1
> > 
> 
> -- 
> <https://www.alejandro-colomar.es/>


-- 
 -----Open up your eyes, open up your mind, open up your code -------   
/ Dr. David Alan Gilbert    |       Running GNU/Linux       | Happy  \ 
\        dave @ treblig.org |                               | In Hex /
 \ _________________________|_____ http://www.treblig.org   |_______/

  reply	other threads:[~2025-08-20 14:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-20  1:27 [PATCH] man/man3/pthread_attr_init.3: Replace errc dave
2025-08-20  8:12 ` Alejandro Colomar
2025-08-20 14:10   ` Dr. David Alan Gilbert [this message]
2025-08-20 15:52     ` Alejandro Colomar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aKXXVO6VdrhXkidS@gallifrey \
    --to=dave@treblig.org \
    --cc=alx@kernel.org \
    --cc=linux-man@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.