Index | Thread | Search

From:
enh <enh@google.com>
Subject:
Re: PATCH: use sysconf(_SC_PAGESIZE) in bin/ps
To:
Theo de Raadt <deraadt@openbsd.org>
Cc:
Eric <eobsdbox@gmail.com>, tech@openbsd.org
Date:
Tue, 3 Feb 2026 22:02:05 -0800

Download raw body.

Thread
(i was genuinely surprised to see that that advice is on the openbsd
man page ... i assumed the OP had read the man7.org man pages which
are often overly prescriptive about stuff like this, but oddly they
_don't_ mention sysconf().)

On Tue, Feb 3, 2026 at 8:28 PM Theo de Raadt <deraadt@openbsd.org> wrote:
>
> There is no point in doing this.
>
> getpagesize() is never going away, because it has no risks.  This is
> not strcpy() or gets().
>
> Secondly, everyone despises hates sysconf.
>
> > Hello,
> >
> > The current version of ps(1) still uses the obsolete getpagesize()
> > function. Following the recommendation in getpagesize(3), this patch
> > migrates the code to sysconf(_SC_PAGESIZE).
> >
> > I have updated the 'pagesize' variable to a 'long' to match the
> > return type of sysconf() and ensure consistency in memory
> > calculations within the pgtok() macro.
> >
> > Tested on OpenBSD 7.8 x86_64.
> >
> > Index: bin/ps/extern.h
> > --- bin/ps/extern.h
> > +++ bin/ps/extern.h
> > @@ -38,7 +38,7 @@
> >
> >  extern struct varent var[];
> >  extern int eval;
> > -extern int pagesize;
> > +extern long pagesize;
> >  extern int termwidth;
> >  extern int totwidth;
> >
> > Index: bin/ps/ps.c
> > --- bin/ps/ps.c
> > +++ bin/ps/ps.c
> > @@ -58,7 +58,7 @@
> >
> >  struct varent var[];
> >  int    eval;
> > -int    pagesize;
> > +long    pagesize;
> >  int    termwidth;
> >  int    totwidth;
> >  int    needenv, needuser, oneline;
> > @@ -204,7 +204,9 @@
> >      if (setlocale(LC_CTYPE, "") == NULL)
> >          warnx("invalid locale");
> >
> > -    pagesize = getpagesize();
> > +    pagesize = sysconf(_SC_PAGESIZE);
> > +    if (pagesize == -1)
> > +        err(1, "sysconf _SC_PAGESIZE");
> >
> >      while ((ch = getopt(argc, argv, getoptstr)) != -1) {
> >          switch (ch) {
> >
>