Cruft: stop creating /usr/local/share/nls directories

2023-10-24 Thread Christian Weisgerber
The /usr/local/share/nls tree for localized message catalogs has
barely ever been used throughout the whole history of the ports
tree.  The main user was shells/tcsh and that stopped four years
ago.  Now, a single port is left that installs a single file there.

I would like to stop creating those directories by default in
mtree/4.4BSD.dist and the ports tree infrastructure.

Separate patches for src and ports attached.

OK?

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de
---
commit 44bc262d8170b10e6949c2836a820b7fee533de4 (local)
from: Christian Weisgerber 
date: Tue Oct 24 14:09:57 2023 UTC
 
 do not create /usr/local/share/nls and subdirectories by default
 
 The share/nls/ paths are unused.
 
diff 85c70083e85910ddc7626ad658e5652c024b844a 44bc262d8170b10e6949c2836a820b7fee533de4
commit - 85c70083e85910ddc7626ad658e5652c024b844a
commit + 44bc262d8170b10e6949c2836a820b7fee533de4
blob - e72a9aa77292f4533044e3d97d6462141f8dfea3
blob + e3ce8a743046f036830fa1c4824ba426cad23ed6
--- etc/mtree/4.4BSD.dist
+++ etc/mtree/4.4BSD.dist
@@ -318,82 +318,6 @@ usr
 misc
 ..
 
-# ./usr/local/share/nls
-nls
-C
-..
-da_DK.ISO_8859-1
-..
-de_AT.ISO_8859-1
-..
-de_CH.ISO_8859-1
-..
-de_DE.ISO_8859-1
-..
-el_GR.ISO_8859-7
-..
-en_AU.ISO_8859-1
-..
-en_CA.ISO_8859-1
-..
-en_GB.ISO_8859-1
-..
-en_US.ISO_8859-1
-..
-es_ES.ISO_8859-1
-..
-et_EE.ISO-8859-1
-..
-fi_FI.ISO_8859-1
-..
-fr_BE.ISO_8859-1
-..
-fr_CA.ISO_8859-1
-..
-fr_CH.ISO_8859-1
-..
-fr_FR.ISO_8859-1
-..
-hr_HR.ISO_8859-2
-..
-is_IS.ISO_8859-1
-..
-it_CH.ISO_8859-1
-..
-it_IT.ISO_8859-1
-..
-ja_JP.EUC
-..
-ko_KR.EUC
-..
-lt_LN.ASCII
-..
-lt_LN.ISO_8859-1
-..
-lt_LN.ISO_8859-2
-..
-nl_BE.ISO_8859-1
-..
-nl_NL.ISO_8859-1
-..
-no_NO.ISO_8859-1
-..
-pl_PL.ISO_8859-2
-..
-pt_PT.ISO_8859-1
-..
-ru_RU.CP866
-..
-ru_RU.ISO_8859-5
-..
-ru_RU.KOI8-R
-..
-sv_SE.ISO_8859-1
-..
-uk_UA.KOI8-U
-..
-..
-
 # ./usr/local/share/pkgconfig
 pkgconfig
 ..

---
commit f51da98f32c02018f7547f68db21d3c6ad474d99 (local)
from: Christian Weisgerber 
date: Tue Oct 24 14:49:39 2023 UTC
 
 do not create the ${PREFIX}/share/nls directory tree by default
 
 The share/nls directories have been barely ever used throughout the
 27-year history of the ports tree.  Let the single port that still
 installs a file there create the directory itself.
 
diff 16cf88f8fc810c890a483bf6ef62386b8610f8bd f51da98f32c02018f7547f68db21d3c6ad474d99
commit - 16cf88f8fc810c890a483bf6ef62386b8610f8bd
commit + f51da98f32c02018f7547f68db21d3c6ad474d99
blob - a189b247f6abf8b457c66bc4986770be81f639fe
blob + 32347397d0c4912d3b015aef226b9d2b652ac086
--- infrastructure/mk/bsd.port.mk
+++ infrastructure/mk/bsd.port.mk
@@ -2018,7 +2018,6 @@ _wrap_install_commands += ${_PBUILD} install -m ${BINM
 _cat = {cat1,cat2,cat3,cat3f,cat3p,cat4,cat5,cat6,cat7,cat8,cat9,catl,catn}
 _man = ${_cat:S/cat/man/g}
 _treebase = ${WRKINST}${LOCALBASE}
-_nls = ${_treebase}/share/nls
 _FAKE_TREE_LIST = \
 	${WRKINST}${BASESYSCONFDIR}/{firmware,rc.d} \
 	${_treebase}/bin \
@@ -2035,18 +2034,6 @@ _FAKE_TREE_LIST = \
 	${_treebase}/sbin \
 	${_treebase}/share/{dict,examples,misc,pkgconfig,skel} \
 	${_treebase}/share/doc/pkg-readmes \
-	${_nls}/{C,da_DK.ISO_8859-1,de_AT.ISO_8859-1,de_CH.ISO_8859-1} \
-	${_nls}/{de_DE.ISO_8859-1,el_GR.ISO_8859-7,en_AU.ISO_8859-1} \
-	${_nls}/{en_CA.ISO_8859-1,en_GB.ISO_8859-1,en_US.ISO_8859-1} \
-	${_nls}/{es_ES.ISO_8859-1,et_EE.ISO-8859-1,fi_FI.ISO_8859-1} \
-	${_nls}/{fr_BE.ISO_8859-1,fr_CA.ISO_8859-1,fr_CH.ISO_8859-1} \
-	${_nls}/fr_FR.ISO_8859-1 \
-	${_nls}/{hr_HR.ISO_8859-2,is_IS.ISO_8859-1,it_CH.ISO_8859-1} \
-	${_nls}/{it_IT.ISO_8859-1,ja_JP.EUC,ko_KR.EUC,l

List tracepoints directly in kdump.1

2023-09-28 Thread Christian Weisgerber
It's always the same:
* foobar doesn't behave as expected
* I ktrace foobar
* I run kdump... too much information.
* I check the kdump(1) man page, since I can't remember which letter
  represents which tracepoint.
* "See the -t option of ktrace(1) for the meaning of the letters."

Sigh.  Yes, duplication is evil, yada, yada, but would it really
be so bad to also list the tracepoints directly in kdump.1 instead
of pointing to ktrace.1?

---
commit 6537a30531732808760afdc5dcd7331aeb9d7618 (local)
from: Christian Weisgerber 
date: Thu Sep 28 16:46:15 2023 UTC
 
 list tracepoints directly in kdump.1 instead of pointing to ktrace.1
 
diff 1cd585e18a4dcd40dd8e9c339b74dc79fd0856e2 
6537a30531732808760afdc5dcd7331aeb9d7618
commit - 1cd585e18a4dcd40dd8e9c339b74dc79fd0856e2
commit + 6537a30531732808760afdc5dcd7331aeb9d7618
blob - 936c630a1096cec78204ac075c6df83a2744e8e2
blob + 5f073e48510388f26cf5c0c1b66d360dc3332364
--- usr.bin/kdump/kdump.1
+++ usr.bin/kdump/kdump.1
@@ -100,13 +100,38 @@ Display absolute timestamps for each entry (seconds si
 If both options are specified, display timestamps relative to trace start.
 .It Fl t Ar trstr
 Select which tracepoints to display.
-The argument can contain one or more of the letters
-.Cm cinpstuxX+ .
-See the
-.Fl t
-option of
-.Xr ktrace 1
-for the meaning of the letters.
+The argument can contain one or more of the following letters.
+By default all trace points except for
+.Cm X
+are enabled.
+.Pp
+.Bl -tag -width flag -offset indent -compact
+.It Cm c
+trace system calls
+.It Cm i
+trace I/O
+.It Cm n
+trace namei translations
+.It Cm p
+trace violation of
+.Xr pledge 2
+restrictions
+.It Cm s
+trace signal processing
+.It Cm t
+trace various structures
+.It Cm u
+trace user data coming from
+.Xr utrace 2
+.It Cm x
+trace argument vector in
+.Xr execve 2
+.It Cm X
+trace environment in
+.Xr execve 2
+.It Cm +
+trace the default points
+.El
 .It Fl u Ar label
 Display
 .Xr utrace 2

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: tcp sync cache signed use counter

2023-09-04 Thread Christian Weisgerber
Alexander Bluhm:

> Variable scs_use is basically counting packet insertions to syn
> cache, so I would prefer type long to exclude overflow on fast
> machines.  With the current limits int should be enough, but long
> does not hurt.

But long is the same size as int.  On our 32-bit archs.  Or are
those inherently so slow that this doesn't matter for them?

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: installer: always create new softraid volume

2023-08-07 Thread Christian Weisgerber
Klemens Nanni:

> If the root disk contains a valid CRYPTO volume, bioctl(8) by default
> unlocks that instead of creating a new one.
> 
> Use `-C force' to prevent reuse of old volumes,

Yes, I like this.  During testing I ran into the case where it
re-used an existing crypto volume and I thought to myself, "hmm,
this is probably not what a user would expect".

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Installer: use $(

2023-05-23 Thread Christian Weisgerber
This replaces "$(cat file)" with the ksh construct "$(/dev/null)

unchanged, since it would require

{ local var=$(<$HTTP_SEC); } 2>/dev/null

which is sufficiently opaque that I'm not sure it's an improvement.


--- distrib/miniroot/install.sub
+++ distrib/miniroot/install.sub
@@ -77,7 +77,7 @@ wait_cgiinfo() {
local _l _s _key _val
 
if [ -f /tmp/cgipid ]; then
-   wait "$(cat /tmp/cgipid)" 2>/dev/null
+   wait "$(/dev/null
rm -f /tmp/cgipid
fi
 
@@ -2650,7 +2650,7 @@ start_cgiinfo() {
(
sleep 12;
if [ -f /tmp/cgipid ]; then
-   kill -INT -"$(cat /tmp/cgipid)" >/dev/null 2>&1
+   kill -INT -"$(/dev/null 2>&1
# wait will be done by wait_cgiinfo
fi
) &
@@ -3449,7 +3449,7 @@ do_upgrade() {
# Perform final steps common to both an install and an upgrade.
finish_up
if [ -f /tmp/wdpid ]; then
-   kill -KILL "$(cat /tmp/wdpid)" 2>/dev/null
+   kill -KILL "$(/dev/null
# do not bother waiting
rm -f /tmp/wdpid
fi
@@ -3480,7 +3480,7 @@ reset_watchdog() {
 reset_watchdog() {
local _pid
if [ -f /tmp/wdpid ]; then
-   _pid=$(cat /tmp/wdpid)
+   _pid=$(/dev/null
wait $_pid 2>/dev/null
rm -f /tmp/wdpid
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: seperate LRO/TSO flags

2023-05-13 Thread Christian Weisgerber
Jan Klemkow:

> This diff introduces separate flags for TCP offloading.  We split this
> into LRO (large receive offloading) and TSO (TCP segmentation
> offloading).  Thus, we are able to turn it on/off separately.

Wait, why do we even have a knob for TSO?

We specifically decided not to have a knob for checksum offloading,
because it should just work out of the box, and if it doesn't, then
it should be disabled by the driver.  It should not be the admin's
task to figure out if the implementation is broken and to fiddle
with the knobs (hi, FreeBSD!).

I would assume that line of thinking extends to TSO.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



llvm15: Implement support for PT_OPENBSD_NOBTCFI in lld(1)

2023-04-21 Thread Christian Weisgerber
Mark Kettenis:

> CVSROOT:  /cvs
> Module name:  src
> Changes by:   kette...@cvs.openbsd.org2023/04/19 10:04:33
> 
> Modified files:
>   gnu/llvm/lld/ELF: Config.h Driver.cpp Writer.cpp 
>   gnu/llvm/llvm/include/llvm/BinaryFormat: ELF.h 
>   gnu/llvm/llvm/tools/llvm-objdump: ELFDump.cpp 
>   gnu/llvm/llvm/tools/llvm-readobj: ELFDumper.cpp 
> 
> Log message:
> Implement support for PT_OPENBSD_NOBTCFI in lld(1).  This can be set using
> the -z nobtcfi option.

This also needs a tweak to apply to LLVM 15:

---
commit 072b0a41d978c446342c34a7a901579f460f80d2 (llvm15)
from: Christian Weisgerber 
date: Fri Apr 21 21:25:24 2023 UTC
 
 Implement support for PT_OPENBSD_NOBTCFI in lld(1).  This can be set using
 the -z nobtcfi option.
 
 ok deraadt@
 
diff 0822bbb9df762f449d710cd2fa18c491bc31 
072b0a41d978c446342c34a7a901579f460f80d2
commit - 0822bbb9df762f449d710cd2fa18c491bc31
commit + 072b0a41d978c446342c34a7a901579f460f80d2
blob - 7e6da4dfb40ed4c6208bef8d3305ba712d55b899
blob + 642773d87ab4eecf109bbcbc4233f9e72430c98d
--- gnu/llvm/lld/ELF/Config.h
+++ gnu/llvm/lld/ELF/Config.h
@@ -250,6 +250,7 @@ struct Configuration {
   bool zInitfirst;
   bool zInterpose;
   bool zKeepTextSectionPrefix;
+  bool zNoBtCfi;
   bool zNodefaultlib;
   bool zNodelete;
   bool zNodlopen;
blob - c6a9a53a8d9c9938e2c389249d78bbddc3829429
blob + 1b5e617d1f3a9f8e36c612a63d655f8975ace70b
--- gnu/llvm/lld/ELF/Driver.cpp
+++ gnu/llvm/lld/ELF/Driver.cpp
@@ -473,6 +473,7 @@ constexpr const char *knownZFlags[] = {
 "keep-text-section-prefix",
 "lazy",
 "muldefs",
+"nobtcfi",
 "nocombreloc",
 "nocopyreloc",
 "nodefaultlib",
@@ -1258,6 +1259,7 @@ static void readConfigs(opt::InputArgList ) {
   config->zInterpose = hasZOption(args, "interpose");
   config->zKeepTextSectionPrefix = getZFlag(
   args, "keep-text-section-prefix", "nokeep-text-section-prefix", false);
+  config->zNoBtCfi = hasZOption(args, "nobtcfi");
   config->zNodefaultlib = hasZOption(args, "nodefaultlib");
   config->zNodelete = hasZOption(args, "nodelete");
   config->zNodlopen = hasZOption(args, "nodlopen");
blob - cd237088be76ab4780cf74acb7123be883308fba
blob + 52f65f260c4cf72a7e6a4b43c8a6c52bc50ca30f
--- gnu/llvm/lld/ELF/Writer.cpp
+++ gnu/llvm/lld/ELF/Writer.cpp
@@ -2438,6 +2438,11 @@ SmallVector Writer::createPhdrs(
   if (config->zWxneeded)
 addHdr(PT_OPENBSD_WXNEEDED, PF_X);
 
+  // PT_OPENBSD_NOBTCFI is an OpenBSD-specific header to mark that the
+  // executable is expected to violate branch-target CFI checks.
+  if (config->zNoBtCfi)
+addHdr(PT_OPENBSD_NOBTCFI, PF_X);
+
   if (OutputSection *cmd = findSection(".note.gnu.property", partNo))
 addHdr(PT_GNU_PROPERTY, PF_R)->add(cmd);
 
blob - ad0612dcc2747fb88e4d05213e1d9b1931cee2ea
blob + eedb59c4925aaeb97e6e1474fb455124bd24fda8
--- gnu/llvm/llvm/include/llvm/BinaryFormat/ELF.h
+++ gnu/llvm/llvm/include/llvm/BinaryFormat/ELF.h
@@ -1380,6 +1380,7 @@ enum {
   PT_OPENBSD_MUTABLE = 0x65a3dbe5,   // Like bss, but not immutable.
   PT_OPENBSD_RANDOMIZE = 0x65a3dbe6, // Fill with random data.
   PT_OPENBSD_WXNEEDED = 0x65a3dbe7,  // Program does W^X violations.
+  PT_OPENBSD_NOBTCFI = 0x65a3dbe8,   // Do not enforce branch target CFI
   PT_OPENBSD_BOOTDATA = 0x65a41be6,  // Section for boot arguments.
 
   // ARM program header types.
blob - b98b45e3015a11ecc51a0d99f6e8ac75fb8ede35
blob + a07e29874f9445d2369ffd6560f711b62470ba81
--- gnu/llvm/llvm/tools/llvm-objdump/ELFDump.cpp
+++ gnu/llvm/llvm/tools/llvm-objdump/ELFDump.cpp
@@ -253,6 +253,9 @@ static void printProgramHeaders(const ELFFile 
 case ELF::PT_OPENBSD_MUTABLE:
   outs() << "OPENBSD_MUTABLE ";
   break;
+case ELF::PT_OPENBSD_NOBTCFI:
+  outs() << "OPENBSD_NOBTCFI ";
+  break;
 case ELF::PT_OPENBSD_RANDOMIZE:
   outs() << "OPENBSD_RANDOMIZE ";
   break;
blob - 5f84e6bf2d9219f7792a67c59453349ce77b43c3
blob + bfc42b42eafdc2c629b0a173393a3b6c69ad6486
--- gnu/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ gnu/llvm/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -1414,6 +1414,7 @@ static StringRef segmentTypeToString(unsigned Arch, un
 LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_MUTABLE);
 LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_RANDOMIZE);
 LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_WXNEEDED);
+LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_NOBTCFI);
 LLVM_READOBJ_ENUM_CASE(ELF, PT_OPENBSD_BOOTDATA);
   default:
 return "";

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: plt section in kernel due to endbr64

2023-04-21 Thread Christian Weisgerber
Alexander Bluhm:

> After enabling -fcf-protection=branch for the kernel, we have a new
> .plt section in the kernel.  It was not there before.

Same issue in userland: At least /usr/lib/crt0.o and /usr/lib/crtbegin.o
have grown .plt and .note.gnu.property sections and some tools
(ld.bfd?) don't like it, as shown by corresponding ports build
failures.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



llvm15: Make -mbranch-protection=bti the default

2023-04-18 Thread Christian Weisgerber
Mark Kettenis:

> CVSROOT:  /cvs
> Module name:  src
> Changes by:   kette...@cvs.openbsd.org2023/04/17 12:10:26
> 
> Modified files:
>   gnu/llvm/clang/lib/Driver/ToolChains: Clang.cpp 
> 
> Log message:
> Make -mbranch-protection=bti the default on OpenBSD.

LLVM 15 reshuffled some code, so the change above no longer applies
there.  Here's my attempt to add it:

---
commit d80c4bf3bc72f631512bdaa922cc31d46a07257b (llvm15)
from: Christian Weisgerber 
date: Mon Apr 17 22:33:20 2023 UTC
 
 llvm: Make -mbranch-protection=bti the default on OpenBSD.
 
diff f0fc5537edb677b1573883cbb90bfbfe54440790 
d80c4bf3bc72f631512bdaa922cc31d46a07257b
commit - f0fc5537edb677b1573883cbb90bfbfe54440790
commit + d80c4bf3bc72f631512bdaa922cc31d46a07257b
blob - 8c27644576624ffcb1242d848a9684fa16b7744c
blob + 903e477bb0e466763e5ba8e1156d763986310c81
--- gnu/llvm/clang/lib/Driver/ToolChains/Clang.cpp
+++ gnu/llvm/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1671,15 +1671,19 @@ static void CollectARMPACBTIOptions(const ToolChain 
 
 static void CollectARMPACBTIOptions(const ToolChain , const ArgList ,
 ArgStringList , bool isAArch64) {
+  const llvm::Triple  = TC.getEffectiveTriple();
+
   const Arg *A = isAArch64
  ? Args.getLastArg(options::OPT_msign_return_address_EQ,
options::OPT_mbranch_protection_EQ)
  : Args.getLastArg(options::OPT_mbranch_protection_EQ);
-  if (!A)
+  if (!A) {
+if (isAArch64 && Triple.isOSOpenBSD())
+  CmdArgs.push_back("-mbranch-target-enforce");
 return;
+  }
 
   const Driver  = TC.getDriver();
-  const llvm::Triple  = TC.getEffectiveTriple();
   if (!(isAArch64 || (Triple.isArmT32() && Triple.isArmMClass(
 D.Diag(diag::warn_incompatible_branch_protection_option)
 << Triple.getArchName();

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: [installer] default answer to "Is the disk partition already mounted?"

2023-04-06 Thread Christian Weisgerber
On 2023-04-05, Klemens Nanni  wrote:

>> In conversation with Klemens (kn@) new iteration has been born, it
>> follows to what Omar (op@) has suggested - we're not trying to change
>> the default answer for all cases, since no one complained for all these
>> years, but just flip default for installation mode, which should save
>> some keystrokes and back-and-forth movement for novice users.
>
> Feeback?
> This is OK kn if anyone wants to commit, else I'll take OKs.

We need to consider
(1) mode: install, upgrade
(2) medium: installXX, other

installXX.img and .iso carry the sets, and people who choose this
medium typically want to use the sets from the medium.  Other media
need to access external sets.  The question only comes up once
people have already chosen "Location of sets? disk".  Counter-
intuitively, using the sets included on installXX requires manual
mounting, so "no".

I arrive at this matrix of mode/medium, [default] answer, and
typically required answer:

install upgrade
installXX   [yes] no[yes] no
other   [yes] no[yes] yes

The install/other case is likely rare.  The upgrade/other case is
common for developers who have built a release for testing purposes
and want to install it.  I think I changed the default to "yes" in
2017 exactly because upgrade/other was by far the dominant case for
developers.  (Note that this was also before sysupgrade.)

Flipping the default for installation mode produces this matrix:

install upgrade
installXX   [no] no [yes] no
other   [no] no [yes] yes

I guess that's better?  It still presents the wrong default to
people who want to upgrade a machine without network access from a
USB stick.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



installer: remove obsolete libLLVM.so.[0-6].0

2023-03-08 Thread Christian Weisgerber
The installer deletes obsolete libLLVM.so versions during an upgrade.
However, a number of libLLVM.so versions have come and gone and the
installer hasn't been synced.  We're now at .7.0, so delete all the
earlier ones.

ok?

---
remove obsolete libLLVM.so.[0-6].0 during upgrade

diff 4e440c72920f8bfbe8fe8a752bd5eafff5c4c644 
8593f3cca4c3f1bbac0f69172c991145b5bead7f
commit - 4e440c72920f8bfbe8fe8a752bd5eafff5c4c644
commit + 8593f3cca4c3f1bbac0f69172c991145b5bead7f
blob - 954feb267763c40f0761fc1144ea5a6f4f47574f
blob + 3a276cf34810970279dbc514330cfddcba00968b
--- distrib/miniroot/install.sub
+++ distrib/miniroot/install.sub
@@ -1761,7 +1761,7 @@ install_files() {
if [[ $MODE == upgrade ]]; then
if isin base$VERSION.tgz $_get_sets; then
rm -f /mnt/usr/share/relink/usr/lib/*
-   rm -rf /mnt/usr/lib/libLLVM.so.[012].0
+   rm -rf /mnt/usr/lib/libLLVM.so.[0-6].0
rm -rf /mnt/usr/libdata/perl5
fi
if isin comp$VERSION.tgz $_get_sets; then

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: refactor mbuf parsing on driver level

2023-02-06 Thread Christian Weisgerber
Jan Klemkow:

> > igc(4) has very similar code, but I don't have access to a machine
> > with that hardware.
> 
> Send me an ssh-key and I give you access to this machine:

Alternatively, here's the diff, so other people can test it.

diff a0c537a1c9d84e98322b55d8f71438a147aaa7c4 
7d976644b87094d08f478fb087be35b91d2e38a7
commit - a0c537a1c9d84e98322b55d8f71438a147aaa7c4
commit + 7d976644b87094d08f478fb087be35b91d2e38a7
blob - a904d43c66b767b162b7602f2ef35fa5dc6dae4f
blob + c172c137bf82cea95f6f7c0524cd7e72ced18018
--- sys/dev/pci/if_igc.c
+++ sys/dev/pci/if_igc.c
@@ -2002,17 +2002,14 @@ igc_tx_ctx_setup(struct tx_ring *txr, struct mbuf *mp,
 igc_tx_ctx_setup(struct tx_ring *txr, struct mbuf *mp, int prod,
 uint32_t *olinfo_status)
 {
+   struct ether_extracted ext;
struct igc_adv_tx_context_desc *txdesc;
-   struct ether_header *eh = mtod(mp, struct ether_header *);
-   struct mbuf *m;
uint32_t type_tucmd_mlhl = 0;
uint32_t vlan_macip_lens = 0;
uint32_t iphlen;
-   int hoff;
int off = 0;
-   uint8_t ipproto;
 
-   vlan_macip_lens |= (sizeof(*eh) << IGC_ADVTXD_MACLEN_SHIFT);
+   vlan_macip_lens |= (sizeof(*ext.eh) << IGC_ADVTXD_MACLEN_SHIFT);
 
/*
 * In advanced descriptors the vlan tag must
@@ -2029,62 +2026,41 @@ igc_tx_ctx_setup(struct tx_ring *txr, struct mbuf *mp,
 #endif
 #endif
 
-   switch (ntohs(eh->ether_type)) {
-   case ETHERTYPE_IP: {
-   struct ip *ip;
+   ether_extract_headers(mp, );
 
-   m = m_getptr(mp, sizeof(*eh), );
-   KASSERT(m != NULL && m->m_len - hoff >= sizeof(*ip));
-   ip = (struct ip *)(mtod(m, caddr_t) + hoff);
+   if (ext.ip4) {
+   iphlen = ext.ip4->ip_hl << 2;
 
-   iphlen = ip->ip_hl << 2;
-   ipproto = ip->ip_p;
-
type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_IPV4;
if (ISSET(mp->m_pkthdr.csum_flags, M_IPV4_CSUM_OUT)) {
*olinfo_status |= IGC_TXD_POPTS_IXSM << 8;
off = 1;
}
-
-   break;
-   }
 #ifdef INET6
-   case ETHERTYPE_IPV6: {
-   struct ip6_hdr *ip6;
+   } else if (ext.ip6) {
+   iphlen = sizeof(*ext.ip6);
 
-   m = m_getptr(mp, sizeof(*eh), );
-   KASSERT(m != NULL && m->m_len - hoff >= sizeof(*ip6));
-   ip6 = (struct ip6_hdr *)(mtod(m, caddr_t) + hoff);
-
-   iphlen = sizeof(*ip6);
-   ipproto = ip6->ip6_nxt;
-
type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_IPV6;
-   break;
-   }
 #endif
-   default:
+   } else {
return 0;
}
 
vlan_macip_lens |= iphlen;
type_tucmd_mlhl |= IGC_ADVTXD_DCMD_DEXT | IGC_ADVTXD_DTYP_CTXT;
 
-   switch (ipproto) {
-   case IPPROTO_TCP:
+   if (ext.tcp) {
type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_L4T_TCP;
if (ISSET(mp->m_pkthdr.csum_flags, M_TCP_CSUM_OUT)) {
*olinfo_status |= IGC_TXD_POPTS_TXSM << 8;
off = 1;
}
-   break;
-   case IPPROTO_UDP:
+   } else if (ext.udp) {
type_tucmd_mlhl |= IGC_ADVTXD_TUCMD_L4T_UDP;
if (ISSET(mp->m_pkthdr.csum_flags, M_UDP_CSUM_OUT)) {
*olinfo_status |= IGC_TXD_POPTS_TXSM << 8;
off = 1;
}
-   break;
}
 
if (off == 0)

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: refactor mbuf parsing on driver level

2023-02-06 Thread Christian Weisgerber
Christian Weisgerber:

> I also switched over em(4) to this and have successfully used it
> for a full 30-hour package build on the four amd64 ports machines
> with their I350 interfaces.  Additionally, I've done some IPv6
> testing at home over an I210.

ok for this?

igc(4) has very similar code, but I don't have access to a machine
with that hardware.

> diff f8646d27d4041e5f595c04e17a876f12600deea7 
> f3f95d0cc0957a2f1e961cace4c3c9dd869e8c9e
> commit - f8646d27d4041e5f595c04e17a876f12600deea7
> commit + f3f95d0cc0957a2f1e961cace4c3c9dd869e8c9e
> blob - c840377f0a3f1ef3c3e3072657698d8085ffd3a0
> blob + 523ed5b0a18718c50bb30e2995d293fa1d2199a6
> --- sys/dev/pci/if_em.c
> +++ sys/dev/pci/if_em.c
> @@ -2398,12 +2398,11 @@ em_tx_ctx_setup(struct em_queue *que, struct mbuf *mp,
>  em_tx_ctx_setup(struct em_queue *que, struct mbuf *mp, u_int head,
>  u_int32_t *olinfo_status, u_int32_t *cmd_type_len)
>  {
> + struct ether_extracted ext;
>   struct e1000_adv_tx_context_desc *TD;
> - struct ether_header *eh = mtod(mp, struct ether_header *);
> - struct mbuf *m;
>   uint32_t vlan_macip_lens = 0, type_tucmd_mlhl = 0, mss_l4len_idx = 0;
> - int off = 0, hoff;
> - uint8_t ipproto, iphlen;
> + int off = 0;
> + uint8_t iphlen;
>  
>   *olinfo_status = 0;
>   *cmd_type_len = 0;
> @@ -2418,44 +2417,26 @@ em_tx_ctx_setup(struct em_queue *que, struct mbuf *mp,
>   }
>  #endif
>  
> - vlan_macip_lens |= (sizeof(*eh) << E1000_ADVTXD_MACLEN_SHIFT);
> - 
> - switch (ntohs(eh->ether_type)) {
> - case ETHERTYPE_IP: {
> - struct ip *ip;
> + ether_extract_headers(mp, );
>  
> - m = m_getptr(mp, sizeof(*eh), );
> - ip = (struct ip *)(mtod(m, caddr_t) + hoff);
> + vlan_macip_lens |= (sizeof(*ext.eh) << E1000_ADVTXD_MACLEN_SHIFT);
>  
> - iphlen = ip->ip_hl << 2;
> - ipproto = ip->ip_p;
> + if (ext.ip4) {
> + iphlen = ext.ip4->ip_hl << 2;
>  
>   type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_IPV4;
>   if (ISSET(mp->m_pkthdr.csum_flags, M_IPV4_CSUM_OUT)) {
>   *olinfo_status |= E1000_TXD_POPTS_IXSM << 8;
>   off = 1;
>   }
> -
> - break;
> - }
>  #ifdef INET6
> - case ETHERTYPE_IPV6: {
> - struct ip6_hdr *ip6;
> + } else if (ext.ip6) {
> + iphlen = sizeof(*ext.ip6);
>  
> - m = m_getptr(mp, sizeof(*eh), );
> - ip6 = (struct ip6_hdr *)(mtod(m, caddr_t) + hoff);
> -
> - iphlen = sizeof(*ip6);
> - ipproto = ip6->ip6_nxt;
> -
>   type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_IPV6;
> - break;
> - }
>  #endif
> - default:
> + } else {
>   iphlen = 0;
> - ipproto = 0;
> - break;
>   }
>  
>   *cmd_type_len |= E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_IFCS;
> @@ -2464,21 +2445,18 @@ em_tx_ctx_setup(struct em_queue *que, struct mbuf *mp,
>   vlan_macip_lens |= iphlen;
>   type_tucmd_mlhl |= E1000_ADVTXD_DCMD_DEXT | E1000_ADVTXD_DTYP_CTXT;
>  
> - switch (ipproto) {
> - case IPPROTO_TCP:
> + if (ext.tcp) {
>   type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_TCP;
>   if (ISSET(mp->m_pkthdr.csum_flags, M_TCP_CSUM_OUT)) {
>   *olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
>   off = 1;
>   }
> - break;
> - case IPPROTO_UDP:
> + } else if (ext.udp) {
>   type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_UDP;
>   if (ISSET(mp->m_pkthdr.csum_flags, M_UDP_CSUM_OUT)) {
>   *olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
>   off = 1;
>   }
> - break;
>   }
>  
>   if (!off)
> 

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: refactor mbuf parsing on driver level

2023-02-05 Thread Christian Weisgerber
Jan Klemkow:

> > >  - I turned the KASSERTS to returns.
> > >  - Check if the mbuf is large enough for an ether header.
> > >  - additionally #ifdef'd INET6 around the ip6_hdr in the new struct
> > 
> > For non-initial fragments of TCP/UDP packets, ether_extract_headers()
> > will create ext.tcp/ext.udp pointers that do not point to a protocol
> > header.  Should there be a check to exclude fragments?
> 
> yes.  bluhm also suggested this solution to me.

ok naddy@

For ix(4), this has been running fine for the last six hours on the
ports build cluster's NFS server while package builds are ongoing.

I also switched over em(4) to this and have successfully used it
for a full 30-hour package build on the four amd64 ports machines
with their I350 interfaces.  Additionally, I've done some IPv6
testing at home over an I210.

diff f8646d27d4041e5f595c04e17a876f12600deea7 
f3f95d0cc0957a2f1e961cace4c3c9dd869e8c9e
commit - f8646d27d4041e5f595c04e17a876f12600deea7
commit + f3f95d0cc0957a2f1e961cace4c3c9dd869e8c9e
blob - c840377f0a3f1ef3c3e3072657698d8085ffd3a0
blob + 523ed5b0a18718c50bb30e2995d293fa1d2199a6
--- sys/dev/pci/if_em.c
+++ sys/dev/pci/if_em.c
@@ -2398,12 +2398,11 @@ em_tx_ctx_setup(struct em_queue *que, struct mbuf *mp,
 em_tx_ctx_setup(struct em_queue *que, struct mbuf *mp, u_int head,
 u_int32_t *olinfo_status, u_int32_t *cmd_type_len)
 {
+   struct ether_extracted ext;
struct e1000_adv_tx_context_desc *TD;
-   struct ether_header *eh = mtod(mp, struct ether_header *);
-   struct mbuf *m;
uint32_t vlan_macip_lens = 0, type_tucmd_mlhl = 0, mss_l4len_idx = 0;
-   int off = 0, hoff;
-   uint8_t ipproto, iphlen;
+   int off = 0;
+   uint8_t iphlen;
 
*olinfo_status = 0;
*cmd_type_len = 0;
@@ -2418,44 +2417,26 @@ em_tx_ctx_setup(struct em_queue *que, struct mbuf *mp,
}
 #endif
 
-   vlan_macip_lens |= (sizeof(*eh) << E1000_ADVTXD_MACLEN_SHIFT);
-   
-   switch (ntohs(eh->ether_type)) {
-   case ETHERTYPE_IP: {
-   struct ip *ip;
+   ether_extract_headers(mp, );
 
-   m = m_getptr(mp, sizeof(*eh), );
-   ip = (struct ip *)(mtod(m, caddr_t) + hoff);
+   vlan_macip_lens |= (sizeof(*ext.eh) << E1000_ADVTXD_MACLEN_SHIFT);
 
-   iphlen = ip->ip_hl << 2;
-   ipproto = ip->ip_p;
+   if (ext.ip4) {
+   iphlen = ext.ip4->ip_hl << 2;
 
type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_IPV4;
if (ISSET(mp->m_pkthdr.csum_flags, M_IPV4_CSUM_OUT)) {
*olinfo_status |= E1000_TXD_POPTS_IXSM << 8;
off = 1;
}
-
-   break;
-   }
 #ifdef INET6
-   case ETHERTYPE_IPV6: {
-   struct ip6_hdr *ip6;
+   } else if (ext.ip6) {
+   iphlen = sizeof(*ext.ip6);
 
-   m = m_getptr(mp, sizeof(*eh), );
-   ip6 = (struct ip6_hdr *)(mtod(m, caddr_t) + hoff);
-
-   iphlen = sizeof(*ip6);
-   ipproto = ip6->ip6_nxt;
-
type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_IPV6;
-   break;
-   }
 #endif
-   default:
+   } else {
iphlen = 0;
-   ipproto = 0;
-   break;
}
 
*cmd_type_len |= E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_IFCS;
@@ -2464,21 +2445,18 @@ em_tx_ctx_setup(struct em_queue *que, struct mbuf *mp,
vlan_macip_lens |= iphlen;
type_tucmd_mlhl |= E1000_ADVTXD_DCMD_DEXT | E1000_ADVTXD_DTYP_CTXT;
 
-   switch (ipproto) {
-   case IPPROTO_TCP:
+   if (ext.tcp) {
type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_TCP;
if (ISSET(mp->m_pkthdr.csum_flags, M_TCP_CSUM_OUT)) {
*olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
off = 1;
}
-   break;
-   case IPPROTO_UDP:
+   } else if (ext.udp) {
type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_UDP;
if (ISSET(mp->m_pkthdr.csum_flags, M_UDP_CSUM_OUT)) {
*olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
off = 1;
}
-   break;
}
 
if (!off)

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: refactor mbuf parsing on driver level

2023-01-31 Thread Christian Weisgerber
Jan Klemkow:

>  - I turned the KASSERTS to returns.
>  - Check if the mbuf is large enough for an ether header.
>  - additionally #ifdef'd INET6 around the ip6_hdr in the new struct

For non-initial fragments of TCP/UDP packets, ether_extract_headers()
will create ext.tcp/ext.udp pointers that do not point to a protocol
header.  Should there be a check to exclude fragments?

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: Double underlining and strikeout console patch

2023-01-30 Thread Christian Weisgerber
Crystal Kolipe:

> Here is the latest version of the double underline and strikeout parts of my
> console patchset.

I'm sorry, but I gotta ask: Who or what uses something like this??

Offhand, I don't even know if xterm can do it.  If you want this
kind of typographic detail, shouldn't you be using a graphics canvas
rather than a character-cell terminal?

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: refactor mbuf parsing on driver level

2023-01-27 Thread Christian Weisgerber
Vitaliy Makkoveev:

> The ether_extract_headers() diff was reverted, because is wrong for the
> cases other than tcp/udp/icmp. We need to fix it and recommit again
> before continue.

I think (TCP or) UDP fragments are the problem.  Fragments don't have
the protocol header but will still end up here:

case IPPROTO_UDP:
m = m_getptr(m, hoff + hlen, );
KASSERT(m != NULL && m->m_len - hoff >= sizeof(*ext->udp));
ext->udp = (struct udphdr *)(mtod(m, caddr_t) + hoff);
break;

If a tail fragment is too short, it will trigger the KASSERT().

Previously, this wasn't a problem, because if there was such a
KASSERT() as in ixl(4), it was behind a M_*_CSUM_OUT check, and we
never set those flags for fragments.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: refactor mbuf parsing on driver level

2023-01-26 Thread Christian Weisgerber
Jan Klemkow:

> we have several drivers which have to parse the content of mbufs.  This
> diff suggest a central parsing function for this.  Thus, we can reduce
> redundant code.
> 
> I just start with ix(4) and ixl(4) because it was easy to test for me.
> But, this could also improve em(4), igc(4), ale(4) and oce(4).

Here's the corresponding change for em(4).
This only affects 82575, 82576, i350, and i210.
Tested on i210.

ok?

 consolidate mbuf header parsing on device driver layer
 
 M  sys/dev/pci/if_em.c  |  12+  34-

1 file changed, 12 insertions(+), 34 deletions(-)

diff 7c601e62aaac9d63b4ccf68f98d354af760b41a9 
1c186b4a689624833baafe23d82bb535c4d5ad93
commit - 7c601e62aaac9d63b4ccf68f98d354af760b41a9
commit + 1c186b4a689624833baafe23d82bb535c4d5ad93
blob - 581c9fc2647dfed3e8514ab40b2a30885f63d752
blob + 8f25ef5cc5f18c4540aa5b44df9bad1e64d375bd
--- sys/dev/pci/if_em.c
+++ sys/dev/pci/if_em.c
@@ -2398,12 +2398,11 @@ em_tx_ctx_setup(struct em_queue *que, struct mbuf *mp,
 em_tx_ctx_setup(struct em_queue *que, struct mbuf *mp, u_int head,
 u_int32_t *olinfo_status, u_int32_t *cmd_type_len)
 {
+   struct ether_extracted ext;
struct e1000_adv_tx_context_desc *TD;
-   struct ether_header *eh = mtod(mp, struct ether_header *);
-   struct mbuf *m;
uint32_t vlan_macip_lens = 0, type_tucmd_mlhl = 0, mss_l4len_idx = 0;
-   int off = 0, hoff;
-   uint8_t ipproto, iphlen;
+   int off = 0;
+   uint8_t iphlen;
 
*olinfo_status = 0;
*cmd_type_len = 0;
@@ -2418,44 +2417,26 @@ em_tx_ctx_setup(struct em_queue *que, struct mbuf *mp,
}
 #endif
 
-   vlan_macip_lens |= (sizeof(*eh) << E1000_ADVTXD_MACLEN_SHIFT);
-   
-   switch (ntohs(eh->ether_type)) {
-   case ETHERTYPE_IP: {
-   struct ip *ip;
+   ether_extract_headers(mp, );
 
-   m = m_getptr(mp, sizeof(*eh), );
-   ip = (struct ip *)(mtod(m, caddr_t) + hoff);
+   vlan_macip_lens |= (sizeof(*ext.eh) << E1000_ADVTXD_MACLEN_SHIFT);
 
-   iphlen = ip->ip_hl << 2;
-   ipproto = ip->ip_p;
+   if (ext.ip4) {
+   iphlen = ext.ip4->ip_hl << 2;
 
type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_IPV4;
if (ISSET(mp->m_pkthdr.csum_flags, M_IPV4_CSUM_OUT)) {
*olinfo_status |= E1000_TXD_POPTS_IXSM << 8;
off = 1;
}
-
-   break;
-   }
 #ifdef INET6
-   case ETHERTYPE_IPV6: {
-   struct ip6_hdr *ip6;
+   } else if (ext.ip6) {
+   iphlen = sizeof(*ext.ip6);
 
-   m = m_getptr(mp, sizeof(*eh), );
-   ip6 = (struct ip6_hdr *)(mtod(m, caddr_t) + hoff);
-
-   iphlen = sizeof(*ip6);
-   ipproto = ip6->ip6_nxt;
-
type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_IPV6;
-   break;
-   }
 #endif
-   default:
+   } else {
iphlen = 0;
-   ipproto = 0;
-   break;
}
 
*cmd_type_len |= E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_IFCS;
@@ -2464,21 +2445,18 @@ em_tx_ctx_setup(struct em_queue *que, struct mbuf *mp,
vlan_macip_lens |= iphlen;
type_tucmd_mlhl |= E1000_ADVTXD_DCMD_DEXT | E1000_ADVTXD_DTYP_CTXT;
 
-   switch (ipproto) {
-   case IPPROTO_TCP:
+   if (ext.tcp) {
type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_TCP;
if (ISSET(mp->m_pkthdr.csum_flags, M_TCP_CSUM_OUT)) {
*olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
off = 1;
}
-   break;
-   case IPPROTO_UDP:
+   } else if (ext.udp) {
type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_UDP;
if (ISSET(mp->m_pkthdr.csum_flags, M_UDP_CSUM_OUT)) {
*olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
off = 1;
}
-   break;
}
 
if (!off)

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: sparc64: don't install %TICK timecounter on UltraSPARC IIe

2022-12-10 Thread Christian Weisgerber
Scott Cheloha:

> The UltraSPARC IIe's %TICK register has a variable frequency.
> miod@ confirmed that the problem is real.

Indeed, I remember clocking down the Blade 100 with apm(8).

Somebody with access to the hardware might want to adapt the NetBSD
code that adds timecounter support for the STICK register.
Unfortunately it can't be read from userland.

> ok?

I don't have a sparc64 to test, but this makes sense.
ok naddy@

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: Unlock minherit(2)

2022-12-02 Thread Christian Weisgerber
Klemens Nanni:

> This has been running fine through regress and daily usage on my X230 driver
> for months, incl. selected ports builds.
> 
> Feedback? Objection? Tests? OK?

The only user of minherit() in base appears to be libc's arc4random.

I successfully ran a full amd64 package bulk build with this.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: ixv(4): porting Virtual Function driver for Intel 82599 series.

2022-11-20 Thread Christian Weisgerber
Yuichiro NAITO:

> +static void
> +ixv_set_multi(struct ix_softc *sc)
> +{
[...]
> + if ((ifp->if_flags & IFF_PROMISC) == 0 && ac->ac_multirangecnt <= 0 &&
> +   ac->ac_multicnt <= MAX_NUM_MULTICAST_ADDRESSES) {
> + ETHER_FIRST_MULTI(step, >arpcom, enm);
> + while (enm != NULL) {
> + bcopy(enm->enm_addrlo,
> +   [mcnt * IXGBE_ETH_LENGTH_OF_ADDRESS],
> +   IXGBE_ETH_LENGTH_OF_ADDRESS);
> + mcnt++;
> +
> + ETHER_NEXT_MULTI(step, enm);
> + }
> +
> + update_ptr = mta;
> + sc->hw.mac.ops.update_mc_addr_list(>hw, update_ptr, mcnt,
> +ixv_mc_array_itr, TRUE);
> + }
> +
> +} /* ixv_set_multi */

This doesn't look right.
There is no handling of ac->ac_multirangecnt > 0 or
mcnt >= MAX_NUM_MULTICAST_ADDRESSES.

Compare ixgb_set_multi() in if_ixgb.c.

> +int32_t ixgbe_update_mc_addr_list_vf(struct ixgbe_hw *hw, uint8_t 
> *mc_addr_list,
> +  uint32_t mc_addr_count, ixgbe_mc_addr_itr 
> next,
> +  bool clear)
> +{
[...]
> + /* Each entry in the list uses 1 16 bit word.  We have 30
> +  * 16 bit words available in our HW msg buffer (minus 1 for the
> +  * msg type).  That's 30 hash values if we pack 'em right.  If
> +  * there are more than 30 MC addresses to add then punt the
> +  * extras for now and then add code to handle more than 30 later.
> +  * It would be unusual for a server to request that many multi-cast
> +  * addresses except for in large enterprise network environments.
> +  */
> +
> + DEBUGOUT1("MC Addr Count = %d\n", mc_addr_count);
> +
> + cnt = (mc_addr_count > 30) ? 30 : mc_addr_count;

Should MAX_NUM_MULTICAST_ADDRESSES simply be set to 30?

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: Please test: unlock mprotect/mmap/munmap

2022-11-08 Thread Christian Weisgerber
Martin Pieuchot:

> These 3 syscalls should now be ready to run w/o KERNEL_LOCK().  This
> will reduce contention a lot.  I'd be happy to hear from test reports
> on many architectures and possible workloads.

This survived a full amd64 package build.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: ksh: PROMPT_COMMAND

2022-08-03 Thread Christian Weisgerber
Damien Miller:

> bash has a PROMPT_COMMAND that allows a command to be executed before
> each PS1 prompt is displayed. I've found this useful on occasion, so
> this is the same thing for ksh(1).

PS1 is evaluated each time the prompt is displayed.  You can put a
command in $() in there.

PROMPT_COMMAND seems redundant.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: [v3] amd64: simplify TSC sync testing

2022-07-06 Thread Christian Weisgerber
Scott Cheloha:

> > kern.timecounter.tick=1
> > kern.timecounter.timestepwarnings=0
> > kern.timecounter.hardware=i8254
> > kern.timecounter.choice=i8254(0) tsc(-1000) acpihpet0(1000) acpitimer0(1000)
> 
> This is expected behavior with the patch.
> 
> cpu0's TSC is way out of sync with every
> other CPU's TSC, so the TSC is marked
> as a bad timecounter and a different one is
> chosen.

Shouldn't it pick acpihpet0 then?

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



X11 startup scripts: sync ssh key list

2022-06-19 Thread Christian Weisgerber
The X11 session startup files for xenodm and xinit share the same
snippet which checks if any of the default ssh private key files
exist, and if so, starts ssh-agent and runs ssh-add.

The list of key files is outdated.  SSH1 "identity" is gone, and
"id_ecdsa_sk" and "id_ed25519_sk" have been added for FIDO-based
keys.  The patch below updates the list and rephrases the shell
code a bit.

I have tested the xenodm Xsession script.

ok?

diff c65268ffd62e66b859aaf782a75cfa2f086925cb /usr/xenocara
blob - 1a1b6ab21ddb00673ddb17d7fb5f855ad21aa461
file + app/xenodm/config/Xsession.in
--- app/xenodm/config/Xsession.in
+++ app/xenodm/config/Xsession.in
@@ -23,18 +23,22 @@ else
 fi
 
 # if we have private ssh key(s), start ssh-agent and add the key(s)
-id1=$HOME/.ssh/identity
-id2=$HOME/.ssh/id_dsa
-id3=$HOME/.ssh/id_rsa
-id4=$HOME/.ssh/id_ecdsa
-id5=$HOME/.ssh/id_ed25519
-if [ -z "$SSH_AGENT_PID" ];
+if [ -z "$SSH_AGENT_PID" ] && [ -x /usr/bin/ssh-agent ]
 then
-   if [ -x /usr/bin/ssh-agent ] && [ -f $id1 -o -f $id2 -o -f $id3 -o -f 
$id4 -o -f $id5 ];
-   then
-   eval `ssh-agent -s`
-   ssh-add < /dev/null
-   fi
+   for keyfile in \
+   "$HOME/.ssh/id_rsa" \
+   "$HOME/.ssh/id_ecdsa" \
+   "$HOME/.ssh/id_ecdsa_sk" \
+   "$HOME/.ssh/id_ed25519" \
+   "$HOME/.ssh/id_ed25519_sk" \
+   "$HOME/.ssh/id_dsa"
+   do
+   if [ -f "$keyfile" ]; then
+   eval `ssh-agent -s`
+   ssh-add < /dev/null
+   break
+   fi
+   done
 fi
 
 do_exit() {
blob - 4c9c3ae8aae50e3fe43f02aa1fb13b72712cbb64
file + app/xinit/xinitrc.cpp
--- app/xinit/xinitrc.cpp
+++ app/xinit/xinitrc.cpp
@@ -41,19 +41,23 @@ if [ -f "$usermodmap" ]; then
 fi
 
 XCOMM if we have private ssh key(s), start ssh-agent and add the key(s)
-id1=$HOME/.ssh/identity
-id2=$HOME/.ssh/id_dsa
-id3=$HOME/.ssh/id_rsa
-id4=$HOME/.ssh/id_ecdsa
-id5=$HOME/.ssh/id_ed25519
 
-if [ -z "$SSH_AGENT_PID" ];
+if [ -z "$SSH_AGENT_PID" ] && [ -x /usr/bin/ssh-agent ]
 then
-   if [ -x /usr/bin/ssh-agent ] && [ -f $id1 -o -f $id2 -o -f $id3 -o -f 
$id4 -o -f $id5 ];
-   then
-   eval `ssh-agent -s`
-   ssh-add < /dev/null
-   fi
+   for keyfile in \
+   "$HOME/.ssh/id_rsa" \
+   "$HOME/.ssh/id_ecdsa" \
+   "$HOME/.ssh/id_ecdsa_sk" \
+   "$HOME/.ssh/id_ed25519" \
+   "$HOME/.ssh/id_ed25519_sk" \
+   "$HOME/.ssh/id_dsa"
+   do
+   if [ -f "$keyfile" ]; then
+   eval `ssh-agent -s`
+   ssh-add < /dev/null
+   break
+   fi
+   done
 fi
 
 XCOMM start some nice programs
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: obsolete dump options syntax

2022-06-02 Thread Christian Weisgerber
Jan Stary:

> http://cvsweb.netbsd.org/bsdweb.cgi/src/sbin/dump/main.c.diff?r1=1.4=1.5=h
> "Use getopt(3), with obsolete() from restore(8) for backward compatibility."
> 
> So it's restore(8); I write "restore rf" myself.
> Is this it? Does that still need to be supported by dump(8)?

The same "bundled flags" syntax is supported by dump(8), restore(8),
tar(1), and ar(1).

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: ssh-keygen(1): resident fido2 keys

2022-05-01 Thread Christian Weisgerber
Florian Obser:

> Sounds reasonable, this adds the FIDO section and moves the -O bits in.
> The wording is inspired by / copied from the 8.2 release notes and the
> CERTIFICATES section.

I think that makes sense.

s/token/authenticator/g

We standardized on "FIDO authenticator" some time ago, because
"token" is already used for % expansion, and "security key" was
confusing.  "Authenticator" is also the official term used in the
FIDO standard.

... I see some instances of "FIDO token" already slipped in over
the last months, but that needs to be fixed.

> Maybe you have text for DESCRIPTION?
> Not sure what to do about -K, maybe
>   see
>   .Sx FIDO
>   for details.

"... for more information."?

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



arm64: constify miscellaneous pin and clock tables

2022-04-16 Thread Christian Weisgerber
So I did "objdump -t bsd | fgrep 'O .data' | sort -k5r" on arm64.
Oh my.

The diff below constifies a myriad of pin, clock, etc. tables.
This is all very mechanical.  An arm64 GENERIC.MP kernel still
builds and boots with this.

OK?
 
M  sys/dev/fdt/amlclock.c
M  sys/dev/fdt/amlpinctrl.c
M  sys/dev/fdt/axppmic.c
M  sys/dev/fdt/bd718x7.c
M  sys/dev/fdt/hiclock.c
M  sys/dev/fdt/hitemp.c
M  sys/dev/fdt/imxccm.c
M  sys/dev/fdt/imxccm_clocks.h
M  sys/dev/fdt/imxsrc.c
M  sys/dev/fdt/mvpinctrl.c
M  sys/dev/fdt/mvpinctrl_pins.h
M  sys/dev/fdt/mvtemp.c
M  sys/dev/fdt/rkclock.c
M  sys/dev/fdt/rkpinctrl.c
M  sys/dev/fdt/rkpmic.c
M  sys/dev/fdt/rktemp.c
M  sys/dev/fdt/sxiccmu.c
M  sys/dev/fdt/sxiccmu_clocks.h
M  sys/dev/fdt/sxipio.c
M  sys/dev/fdt/sxipio_pins.h
M  sys/dev/ic/imxiicvar.h

diff 1258159c23de129a92e61d9298f34d98b4b5be29 
5f4acf3c29cf6656bcd1b87f26aad6cec8a72d21
blob - 9c26eec4407b5c58d3797d382d9978c395d6a100
blob + 6a8071eadb0fdadb2b4406090c1d07a02d2e5d87
--- sys/dev/fdt/amlclock.c
+++ sys/dev/fdt/amlclock.c
@@ -117,7 +117,7 @@ struct amlclock_gate {
uint8_t bit;
 };
 
-struct amlclock_gate aml_g12a_gates[] = {
+const struct amlclock_gate aml_g12a_gates[] = {
[G12A_I2C] = { HHI_GCLK_MPEG0, 9 },
[G12A_SD_EMMC_A] = { HHI_GCLK_MPEG0, 24 },
[G12A_SD_EMMC_B] = { HHI_GCLK_MPEG0, 25 },
@@ -139,7 +139,7 @@ struct amlclock_softc {
int sc_node;
uint32_tsc_g12b;
 
-   struct amlclock_gate*sc_gates;
+   const struct amlclock_gate *sc_gates;
int sc_ngates;
 
struct clock_device sc_cd;
blob - d03c0146d6d73d51730813125ac5259b4b20c371
blob + 4508166611b9aac1c9fd4d04810cfdf2a282f504
--- sys/dev/fdt/amlpinctrl.c
+++ sys/dev/fdt/amlpinctrl.c
@@ -162,7 +162,7 @@ struct aml_pin_group {
const char *function;
 };
 
-struct aml_gpio_bank aml_g12a_gpio_banks[] = {
+const struct aml_gpio_bank aml_g12a_gpio_banks[] = {
/* BOOT */
{ BOOT_0, 16,
  PERIPHS_PIN_MUX_0 - PERIPHS_PIN_MUX_0, 0,
@@ -226,7 +226,7 @@ struct aml_gpio_bank aml_g12a_gpio_banks[] = {
{ }
 };
 
-struct aml_pin_group aml_g12a_pin_groups[] = {
+const struct aml_pin_group aml_g12a_pin_groups[] = {
/* GPIOZ */
{ "i2c0_sda_z0", GPIOZ_0, 4, "i2c0" },
{ "i2c0_sck_z1", GPIOZ_1, 4, "i2c0" },
@@ -292,7 +292,7 @@ struct aml_pin_group aml_g12a_pin_groups[] = {
{ }
 };
 
-struct aml_gpio_bank aml_g12a_ao_gpio_banks[] = {
+const struct aml_gpio_bank aml_g12a_ao_gpio_banks[] = {
/* GPIOAO */
{ GPIOAO_0, 12,
  AO_RTI_PINMUX_0 - AO_RTI_PINMUX_0, 0,
@@ -316,7 +316,7 @@ struct aml_gpio_bank aml_g12a_ao_gpio_banks[] = {
{ }
 };
 
-struct aml_pin_group aml_g12a_ao_pin_groups[] = {
+const struct aml_pin_group aml_g12a_ao_pin_groups[] = {
/* GPIOAO */
{ "uart_ao_a_tx", GPIOAO_0, 1, "uart_ao_a" },
{ "uart_ao_a_rx", GPIOAO_1, 1, "uart_ao_a" },
@@ -347,8 +347,8 @@ struct amlpinctrl_softc {
bus_space_handle_t  sc_ds_ioh;
int sc_nobias;
 
-   struct aml_gpio_bank*sc_gpio_banks;
-   struct aml_pin_group*sc_pin_groups;
+   const struct aml_gpio_bank *sc_gpio_banks;
+   const struct aml_pin_group *sc_pin_groups;
 
struct gpio_controller  sc_gc;
 };
@@ -481,10 +481,10 @@ amlpinctrl_attach(struct device *parent, struct device
gpio_controller_register(>sc_gc);
 }
 
-struct aml_gpio_bank *
+const struct aml_gpio_bank *
 amlpinctrl_lookup_bank(struct amlpinctrl_softc *sc, uint32_t pin)
 {
-   struct aml_gpio_bank *bank;
+   const struct aml_gpio_bank *bank;
 
for (bank = sc->sc_gpio_banks; bank->num_pins > 0; bank++) {
if (pin >= bank->first_pin &&
@@ -495,10 +495,10 @@ amlpinctrl_lookup_bank(struct amlpinctrl_softc *sc, ui
return NULL;
 }
 
-struct aml_pin_group *
+const struct aml_pin_group *
 amlpinctrl_lookup_group(struct amlpinctrl_softc *sc, const char *name)
 {
-   struct aml_pin_group *group;
+   const struct aml_pin_group *group;
 
for (group = sc->sc_pin_groups; group->name; group++) {
if (strcmp(name, group->name) == 0)
@@ -512,8 +512,8 @@ void
 amlpinctrl_config_func(struct amlpinctrl_softc *sc, const char *name,
 const char *function, int bias, int ds)
 {
-   struct aml_pin_group *group;
-   struct aml_gpio_bank *bank;
+   const struct aml_pin_group *group;
+   const struct aml_gpio_bank *bank;
bus_addr_t off;
uint32_t pin;
uint32_t reg;
@@ -640,7 +640,7 @@ void
 amlpinctrl_config_pin(void *cookie, uint32_t *cells, int config)
 {
struct amlpinctrl_softc *sc = cookie;
-   struct aml_gpio_bank *bank;
+   const struct aml_gpio_bank *bank;
bus_addr_t off;
uint32_t pin = cells[0];
uint32_t flags = cells[1];
@@ -678,7 +678,7 @@ int
 amlpinctrl_get_pin(void *cookie, uint32_t *cells)
 {
struct 

Re: ddb: simplify "machine" command handling

2022-04-11 Thread Christian Weisgerber
Christian Weisgerber:

> This will allow constifying the ddb command tables in a subsequent
> step.

And here's that boring follow-up diff.


M  sys/arch/alpha/alpha/db_interface.c
M  sys/arch/amd64/amd64/db_interface.c
M  sys/arch/arm/arm/db_interface.c
M  sys/arch/arm64/arm64/db_interface.c
M  sys/arch/i386/i386/db_interface.c
M  sys/arch/m88k/m88k/db_interface.c
M  sys/arch/mips64/mips64/db_machdep.c
M  sys/arch/powerpc/ddb/db_interface.c
M  sys/arch/powerpc64/powerpc64/db_interface.c
M  sys/arch/riscv64/riscv64/db_interface.c
M  sys/arch/sh/sh/db_interface.c
M  sys/arch/sparc64/sparc64/db_interface.c
M  sys/ddb/db_command.c
M  sys/ddb/db_command.h

diff c5fcb00219e59f5bbd0cb5171af7fe5d01f0a0c3 
6e95eec92a4f984cd0aff5dd99dd725920c1f1b6
blob - 7e9ce6cc9803586260886d5c16ff2e1219cc2c77
blob + 3f5056966aa3b44d3d4cdc1113256fc05c528026
--- sys/arch/alpha/alpha/db_interface.c
+++ sys/arch/alpha/alpha/db_interface.c
@@ -85,7 +85,7 @@ db_regs_t ddb_regs;
 void   db_mach_cpu(db_expr_t, int, db_expr_t, char *);
 #endif
 
-struct db_command db_machine_command_table[] = {
+const struct db_command db_machine_command_table[] = {
 #if defined(MULTIPROCESSOR)
{ "ddbcpu", db_mach_cpu,0,  NULL },
 #endif
blob - b12b9c48cf147c1525c19e11fac84b35b02bc19f
blob + bd57af87e871b65736c5f4afa8c4f3f98b9bef5c
--- sys/arch/amd64/amd64/db_interface.c
+++ sys/arch/amd64/amd64/db_interface.c
@@ -394,7 +394,7 @@ x86_ipi_db(struct cpu_info *ci)
 #endif /* MULTIPROCESSOR */
 
 #if NACPI > 0
-struct db_command db_acpi_cmds[] = {
+const struct db_command db_acpi_cmds[] = {
{ "disasm", db_acpi_disasm, CS_OWN, NULL },
{ "showval",db_acpi_showval,CS_OWN, NULL },
{ "tree",   db_acpi_tree,   0,  NULL },
@@ -403,7 +403,7 @@ struct db_command db_acpi_cmds[] = {
 };
 #endif /* NACPI > 0 */
 
-struct db_command db_machine_command_table[] = {
+const struct db_command db_machine_command_table[] = {
 #ifdef MULTIPROCESSOR
{ "cpuinfo",db_cpuinfo_cmd, 0,  0 },
{ "startcpu",   db_startproc_cmd,   0,  0 },
blob - 719da88249590509dabb734794daedc7c2a3dd61
blob + bcc0cad7ce3f7c7c180b99d7aaa43b9d6c554738
--- sys/arch/arm/arm/db_interface.c
+++ sys/arch/arm/arm/db_interface.c
@@ -340,7 +340,7 @@ db_enter(void)
asm(".word  0xe7ff");
 }
 
-struct db_command db_machine_command_table[] = {
+const struct db_command db_machine_command_table[] = {
{ "frame",  db_show_frame_cmd,  0, NULL },
 #ifdef ARM32_DB_COMMANDS
ARM32_DB_COMMANDS,
blob - 1645b49186bed36130ffd73a933e45f8f9fc5e18
blob + cb7ecd25005541d590f94cf07152154d3340ade5
--- sys/arch/arm64/arm64/db_interface.c
+++ sys/arch/arm64/arm64/db_interface.c
@@ -469,7 +469,7 @@ db_stopcpu(int cpu)
 }
 #endif
 
-struct db_command db_machine_command_table[] = {
+const struct db_command db_machine_command_table[] = {
 #ifdef MULTIPROCESSOR
{ "cpuinfo",db_cpuinfo_cmd, 0,  NULL },
{ "startcpu",   db_startproc_cmd,   0,  NULL },
blob - 1807bc890744e4f32ef839e73e5647fd5488b901
blob + be2562e3a816dc0d8579275de6fc373458f5fb3e
--- sys/arch/i386/i386/db_interface.c
+++ sys/arch/i386/i386/db_interface.c
@@ -314,7 +314,7 @@ db_ddbproc_cmd(db_expr_t addr, int have_addr, db_expr_
 #endif /* MULTIPROCESSOR */
 
 #if NACPI > 0
-struct db_command db_acpi_cmds[] = {
+const struct db_command db_acpi_cmds[] = {
{ "disasm", db_acpi_disasm, CS_OWN, NULL },
{ "showval",db_acpi_showval,CS_OWN, NULL },
{ "tree",   db_acpi_tree,   0,  NULL },
@@ -323,7 +323,7 @@ struct db_command db_acpi_cmds[] = {
 };
 #endif /* NACPI > 0 */
 
-struct db_command db_machine_command_table[] = {
+const struct db_command db_machine_command_table[] = {
{ "sysregs",db_sysregs_cmd, 0,  0 },
 #ifdef MULTIPROCESSOR
{ "cpuinfo",db_cpuinfo_cmd, 0,  0 },
blob - 55d5e5ba78719c954c4d6d1f5ffa9083e941a932
blob + eab0352da587873642a701debbbc0c00e8f19052
--- sys/arch/m88k/m88k/db_interface.c
+++ sys/arch/m88k/m88k/db_interface.c
@@ -654,7 +654,7 @@ m88k_db_cpu_cmd(db_expr_t addr, int have_addr, db_expr
 /* COMMAND TABLE / INIT */
 //
 
-struct db_command db_machine_command_table[] = {
+const struct db_command db_machine_command_table[] = {
 #ifdef MULTIPROCESSOR
{ "ddbcpu", m88k_db_cpu_cmd,0,  NULL },
 #endif
blob - 2c7d67c597c2a237420af198985aaa20781f124e
blob + b5f2651c9dccdc3281ea43496bc68a8a86a73d26
--- sys/arch/mips64/mips64/db_machdep.c
+++ sys/arch/mips64/mips64/db_machdep.c
@@ -492,7 +492,7 @@ db_dump_tlb_cmd(db_expr_t addr, int have_addr, db_expr
 }
 
 
-struct db_command db_machine_command_table[] = {
+const struct db_command db_machi

ddb: simplify "machine" command handling

2022-04-10 Thread Christian Weisgerber
Most of our architectures implement a "machine" command as a MD
extension in ddb(4).

Currently that is handled in this way:
* A define is placed in a MD header.
* The MI ddb code checks for the define, creates an incomplete
  entry in the command table, and provides an initialization function.
* MD code calls this function to patch a pointer to the MD sub-command
  into the MI command table.

I guess it made sense in 1990?

We can simplify this:
Define a consistently named db_machine_command_table[] across all
archs that implement the MD "machine" command and hook this into
the main command table instead of patching it at runtime.

Most archs already use the name db_machine_command_table[].

This will allow constifying the ddb command tables in a subsequent
step.

I have tested amd64, arm64, and i386.

Comments, ok?

M  sys/arch/alpha/alpha/db_interface.c
M  sys/arch/amd64/amd64/db_interface.c
M  sys/arch/arm/arm/db_interface.c
M  sys/arch/arm64/arm64/db_interface.c
M  sys/arch/i386/i386/db_interface.c
M  sys/arch/m88k/m88k/db_interface.c
M  sys/arch/mips64/mips64/db_machdep.c
M  sys/arch/powerpc/ddb/db_interface.c
M  sys/arch/powerpc64/powerpc64/db_interface.c
M  sys/arch/riscv64/riscv64/db_interface.c
M  sys/arch/sh/sh/db_interface.c
M  sys/arch/sparc64/sparc64/db_interface.c
M  sys/ddb/db_command.c
M  sys/ddb/db_command.h

diff 7e559a9c431834a0b3471b1fa86985ca220b83ba 
c5fcb00219e59f5bbd0cb5171af7fe5d01f0a0c3
blob - fd83cb898bcddb466570b0c531b0b34171a1363f
blob + 7e9ce6cc9803586260886d5c16ff2e1219cc2c77
--- sys/arch/alpha/alpha/db_interface.c
+++ sys/arch/alpha/alpha/db_interface.c
@@ -527,5 +527,4 @@ db_mach_cpu(db_expr_t addr, int have_addr, db_expr_t c
 void
 db_machine_init()
 {
-   db_machine_commands_install(db_machine_command_table);
 }
blob - 186fb4d83fb4d5f849e88297c311f37eaf4638c6
blob + b12b9c48cf147c1525c19e11fac84b35b02bc19f
--- sys/arch/amd64/amd64/db_interface.c
+++ sys/arch/amd64/amd64/db_interface.c
@@ -422,10 +422,7 @@ db_machine_init(void)
 {
 #ifdef MULTIPROCESSOR
int i;
-#endif
 
-   db_machine_commands_install(db_machine_command_table);
-#ifdef MULTIPROCESSOR
for (i = 0; i < MAXCPUS; i++) {
if (cpu_info[i] != NULL)
cpu_info[i]->ci_ddb_paused = CI_DDB_RUNNING;
blob - a8d7805cd6f73e9d281b448e8bb03fb77e210df2
blob + 719da88249590509dabb734794daedc7c2a3dd61
--- sys/arch/arm/arm/db_interface.c
+++ sys/arch/arm/arm/db_interface.c
@@ -378,8 +378,6 @@ db_machine_init(void)
 */
db_uh.uh_handler = db_trapper;
install_coproc_handler_static(0, _uh);
-
-   db_machine_commands_install(db_machine_command_table);
 }
 
 u_int
blob - ed28376be206f5eb55ae034981680025b2717513
blob + 1645b49186bed36130ffd73a933e45f8f9fc5e18
--- sys/arch/arm64/arm64/db_interface.c
+++ sys/arch/arm64/arm64/db_interface.c
@@ -499,10 +499,7 @@ db_machine_init(void)
 {
 #ifdef MULTIPROCESSOR
int i;
-#endif
 
-   db_machine_commands_install(db_machine_command_table);
-#ifdef MULTIPROCESSOR
for (i = 0; i < MAXCPUS; i++) {
if (cpu_info[i] != NULL)
cpu_info[i]->ci_ddb_paused = CI_DDB_RUNNING;
blob - b4c6a02021c944ddea37cb8add864ee1f65a454b
blob + 1807bc890744e4f32ef839e73e5647fd5488b901
--- sys/arch/i386/i386/db_interface.c
+++ sys/arch/i386/i386/db_interface.c
@@ -342,10 +342,7 @@ db_machine_init(void)
 {
 #ifdef MULTIPROCESSOR
int i;
-#endif /* MULTIPROCESSOR */
 
-   db_machine_commands_install(db_machine_command_table);
-#ifdef MULTIPROCESSOR
for (i = 0; i < MAXCPUS; i++) {
if (cpu_info[i] != NULL)
cpu_info[i]->ci_ddb_paused = CI_DDB_RUNNING;
blob - 4d540ea2ad0e5b2d0b8a3c15837309bfe5f8db8c
blob + 55d5e5ba78719c954c4d6d1f5ffa9083e941a932
--- sys/arch/m88k/m88k/db_interface.c
+++ sys/arch/m88k/m88k/db_interface.c
@@ -654,7 +654,7 @@ m88k_db_cpu_cmd(db_expr_t addr, int have_addr, db_expr
 /* COMMAND TABLE / INIT */
 //
 
-struct db_command db_machine_cmds[] = {
+struct db_command db_machine_command_table[] = {
 #ifdef MULTIPROCESSOR
{ "ddbcpu", m88k_db_cpu_cmd,0,  NULL },
 #endif
@@ -671,7 +671,6 @@ struct db_command db_machine_cmds[] = {
 void
 db_machine_init()
 {
-   db_machine_commands_install(db_machine_cmds);
 #ifdef MULTIPROCESSOR
__mp_lock_init(_mp_lock);
 #endif
blob - bbdf2462b57e310bb79ee1890d7a5495f9487226
blob + 2c7d67c597c2a237420af198985aaa20781f124e
--- sys/arch/mips64/mips64/db_machdep.c
+++ sys/arch/mips64/mips64/db_machdep.c
@@ -492,7 +492,7 @@ db_dump_tlb_cmd(db_expr_t addr, int have_addr, db_expr
 }
 
 
-struct db_command mips_db_command_table[] = {
+struct db_command db_machine_command_table[] = {
{ "tlb",db_dump_tlb_cmd,0,  NULL },
{ "trap",   db_trap_trace_cmd,  0,  NULL },
 #ifdef MULTIPROCESSOR
@@ -510,10 +510,7 @@ db_machine_init(void)
extern char *ssym;
 #ifdef MULTIPROCESSOR

Re: [ouex]hci(4), dwctwo(4): constify bus/pipe method tables

2022-04-10 Thread Christian Weisgerber
Marcus Glocker:

> > This constifies the bus method and pipe method tables in our USB
> > host controller drivers.
> 
> dwctwo(4) also exists on arm64.

Oops, right.  That arch I have.

The USB host controller drivers also have another set of tables to
emulate the root hub.  I have extended the diff to constify those
as well.  xhci(4) and dwctwo(4) were already (partially) done.

The *_devd descriptor template poses a problem, because its idVendor
member is modified before the descriptor is memcpy()'ed into a
transmit buffer.  The copy can be truncated, so reordering the
operations would lead to much ugliness.  I have introduced a temporary
variable at the cost of another copy.  The code already does this
for the *_hubd descriptor.

The NetBSD author of dwctwo(4) also ran into this problem, but
didn't solve it, simply never setting idVendor, for which there is
also no ready source absent a PCI bus attachment.  I _think_ the
FreeBSD code for all host controllers doesn't bother setting idVendor
either, so that may be another solution.

Comments, okays?

diff refs/heads/master refs/heads/usb
blob - 9b9d1635f902afef00a4111dfba8f86d13f74b4e
blob + 64dea91909ed4f77f7f24c61dd1c09809d27d031
--- sys/dev/usb/dwc2/dwc2.c
+++ sys/dev/usb/dwc2/dwc2.c
@@ -146,7 +146,7 @@ dwc2_free_bus_bandwidth(struct dwc2_hsotg *hsotg, u16 
 
 #define DWC2_INTR_ENDPT 1
 
-STATIC struct usbd_bus_methods dwc2_bus_methods = {
+STATIC const struct usbd_bus_methods dwc2_bus_methods = {
.open_pipe =dwc2_open,
.dev_setaddr =  dwc2_setaddr,
.soft_intr =dwc2_softintr,
@@ -155,7 +155,7 @@ STATIC struct usbd_bus_methods dwc2_bus_methods = {
.freex =dwc2_freex,
 };
 
-STATIC struct usbd_pipe_methods dwc2_root_ctrl_methods = {
+STATIC const struct usbd_pipe_methods dwc2_root_ctrl_methods = {
.transfer = dwc2_root_ctrl_transfer,
.start =dwc2_root_ctrl_start,
.abort =dwc2_root_ctrl_abort,
@@ -164,7 +164,7 @@ STATIC struct usbd_pipe_methods dwc2_root_ctrl_methods
.done = dwc2_root_ctrl_done,
 };
 
-STATIC struct usbd_pipe_methods dwc2_root_intr_methods = {
+STATIC const struct usbd_pipe_methods dwc2_root_intr_methods = {
.transfer = dwc2_root_intr_transfer,
.start =dwc2_root_intr_start,
.abort =dwc2_root_intr_abort,
@@ -173,7 +173,7 @@ STATIC struct usbd_pipe_methods dwc2_root_intr_methods
.done = dwc2_root_intr_done,
 };
 
-STATIC struct usbd_pipe_methods dwc2_device_ctrl_methods = {
+STATIC const struct usbd_pipe_methods dwc2_device_ctrl_methods = {
.transfer = dwc2_device_ctrl_transfer,
.start =dwc2_device_ctrl_start,
.abort =dwc2_device_ctrl_abort,
@@ -182,7 +182,7 @@ STATIC struct usbd_pipe_methods dwc2_device_ctrl_metho
.done = dwc2_device_ctrl_done,
 };
 
-STATIC struct usbd_pipe_methods dwc2_device_intr_methods = {
+STATIC const struct usbd_pipe_methods dwc2_device_intr_methods = {
.transfer = dwc2_device_intr_transfer,
.start =dwc2_device_intr_start,
.abort =dwc2_device_intr_abort,
@@ -191,7 +191,7 @@ STATIC struct usbd_pipe_methods dwc2_device_intr_metho
.done = dwc2_device_intr_done,
 };
 
-STATIC struct usbd_pipe_methods dwc2_device_bulk_methods = {
+STATIC const struct usbd_pipe_methods dwc2_device_bulk_methods = {
.transfer = dwc2_device_bulk_transfer,
.start =dwc2_device_bulk_start,
.abort =dwc2_device_bulk_abort,
@@ -200,7 +200,7 @@ STATIC struct usbd_pipe_methods dwc2_device_bulk_metho
.done = dwc2_device_bulk_done,
 };
 
-STATIC struct usbd_pipe_methods dwc2_device_isoc_methods = {
+STATIC const struct usbd_pipe_methods dwc2_device_isoc_methods = {
.transfer = dwc2_device_isoc_transfer,
.start =dwc2_device_isoc_start,
.abort =dwc2_device_isoc_abort,
@@ -681,7 +681,6 @@ dwc2_root_ctrl_start(struct usbd_xfer *xfer)
switch (value) {
case C(0, UDESC_DEVICE):
l = min(len, USB_DEVICE_DESCRIPTOR_SIZE);
-// USETW(dwc2_devd.idVendor, sc->sc_id_vendor);
memcpy(buf, _devd, l);
buf += l;
len -= l;
blob - 350580c00b30f8edcfd5edf8ad8d1734624462c6
blob + 834e97310fb06a73bc569a943e4b0e7906c136d5
--- sys/dev/usb/ehci.c
+++ sys/dev/usb/ehci.c
@@ -218,7 +218,7 @@ voidehci_dump_exfer(struct ehci_xfer *);
 
 #define EHCI_INTR_ENDPT 1
 
-struct usbd_bus_methods ehci_bus_methods = {
+const struct usbd_bus_methods ehci_bus_methods = {
.open_pipe = ehci_open,
.dev_setaddr = ehci_setaddr,
.soft_intr = ehci_softintr,
@@ -227,7 +227,7 @@ struct usbd_bus_methods ehci_bus_methods = {
.freex = ehci_freex,
 };
 
-struct usbd_pipe_methods ehci_root_ctrl_methods = {
+const struct 

Constify SCSI adapter entry points

2022-04-09 Thread Christian Weisgerber
This constifies the SCSI adapter entry points (struct scsi_adapter).
It reaches into some archs I don't have...

ok?

M  sys/arch/luna88k/dev/mb89352.c
M  sys/arch/luna88k/dev/mb89352var.h
M  sys/arch/luna88k/dev/spc.c
M  sys/arch/sparc64/dev/vdsk.c
M  sys/dev/ata/atascsi.c
M  sys/dev/atapiscsi/atapiscsi.c
M  sys/dev/ic/aac.c
M  sys/dev/ic/adv.c
M  sys/dev/ic/adw.c
M  sys/dev/ic/aic6360.c
M  sys/dev/ic/aic79xx_openbsd.c
M  sys/dev/ic/aic7xxx_openbsd.c
M  sys/dev/ic/ami.c
M  sys/dev/ic/cac.c
M  sys/dev/ic/ciss.c
M  sys/dev/ic/gdt_common.c
M  sys/dev/ic/mfi.c
M  sys/dev/ic/mpi.c
M  sys/dev/ic/ncr53c9x.c
M  sys/dev/ic/nvme.c
M  sys/dev/ic/oosiop.c
M  sys/dev/ic/osiop.c
M  sys/dev/ic/qla.c
M  sys/dev/ic/qlw.c
M  sys/dev/ic/siop.c
M  sys/dev/ic/twe.c
M  sys/dev/ic/uha.c
M  sys/dev/isa/wds.c
M  sys/dev/pci/arc.c
M  sys/dev/pci/iha_pci.c
M  sys/dev/pci/ips.c
M  sys/dev/pci/mfii.c
M  sys/dev/pci/mpii.c
M  sys/dev/pci/qle.c
M  sys/dev/pci/trm_pci.c
M  sys/dev/pci/vmwpvs.c
M  sys/dev/pv/hvs.c
M  sys/dev/pv/vioblk.c
M  sys/dev/pv/vioscsi.c
M  sys/dev/pv/xbf.c
M  sys/dev/sdmmc/sdmmc_scsi.c
M  sys/dev/softraid.c
M  sys/dev/usb/umass_scsi.c
M  sys/dev/vscsi.c
M  sys/scsi/mpath.c
M  sys/scsi/scsiconf.h

diff 0dbbfe957ecc14f6850205ad3b966d242dbc9b06 
e79b7c31603b0e0aea1909e2874ee6cfb95925f8
blob - 450ebece88b74eef5c577c13d0553f041cddd5dc
blob + 77f9a760254025a3c99124b3d1134bc62ddafb9e
--- sys/arch/luna88k/dev/mb89352.c
+++ sys/arch/luna88k/dev/mb89352.c
@@ -190,7 +190,7 @@ do { \
 
 void
 /* spc_attach(sc) */
-spc_attach(struct spc_softc *sc, struct scsi_adapter *adapter)
+spc_attach(struct spc_softc *sc, const struct scsi_adapter *adapter)
 {
struct scsibus_attach_args saa;
SPC_TRACE(("spc_attach  "));
blob - 0df2bc6358fd58265c14c9630c76b955f446e97d
blob + 9dae1aba0a773754f7ae6abcc8a2ce6c19138c81
--- sys/arch/luna88k/dev/mb89352var.h
+++ sys/arch/luna88k/dev/mb89352var.h
@@ -203,7 +203,7 @@ extern int spc_debug; /* SPC_SHOWSTART|SPC_SHOWMISC|SP
 #define SPC_TRACE(s)   SPC_PRINT(SPC_SHOWTRACE, s)
 #define SPC_START(s)   SPC_PRINT(SPC_SHOWSTART, s)
 
-void   spc_attach(struct spc_softc *, struct scsi_adapter *);
+void   spc_attach(struct spc_softc *, const struct scsi_adapter *);
 intspc_intr(void *);
 intspc_find(bus_space_tag_t, bus_space_handle_t, int);
 void   spc_init(struct spc_softc *);
blob - 91113f2ee10328c10059bb45920218fd965ffcac
blob + c19244983341f7a75ccd28844766cc117a9b9eb7
--- sys/arch/luna88k/dev/spc.c
+++ sys/arch/luna88k/dev/spc.c
@@ -59,7 +59,7 @@ struct cfdriver spc_cd = {
NULL, "spc", DV_DULL
 };
 
-struct scsi_adapter spc_switch = {
+const struct scsi_adapter spc_switch = {
spc_scsi_cmd, NULL, NULL, NULL, NULL
 };
 
blob - 8c3c41b06799e36244b4223db776e99ffccf7ed8
blob + 509cca15b3034c1f375ff48cc378df3e5c623134
--- sys/arch/sparc64/dev/vdsk.c
+++ sys/arch/sparc64/dev/vdsk.c
@@ -179,7 +179,7 @@ struct cfdriver vdsk_cd = {
 
 void   vdsk_scsi_cmd(struct scsi_xfer *);
 
-struct scsi_adapter vdsk_switch = {
+const struct scsi_adapter vdsk_switch = {
vdsk_scsi_cmd, NULL, NULL, NULL, NULL
 };
 
blob - 19f61480e83314afe9d58d24b52e1b1d7e64ea93
blob + f338ff373175501361455ce4e38d9fa006d9b403
--- sys/dev/ata/atascsi.c
+++ sys/dev/ata/atascsi.c
@@ -94,7 +94,7 @@ int   atascsi_probe(struct scsi_link *);
 void   atascsi_free(struct scsi_link *);
 
 /* template */
-struct scsi_adapter atascsi_switch = {
+const struct scsi_adapter atascsi_switch = {
atascsi_cmd, NULL, atascsi_probe, atascsi_free, NULL
 };
 
blob - 622d1687499d2a455a0b95fccc24e3c64739a029
blob + 743369f1edaad1f7c7fbcd3464073f0517ff2e55
--- sys/dev/atapiscsi/atapiscsi.c
+++ sys/dev/atapiscsi/atapiscsi.c
@@ -156,7 +156,7 @@ struct atapiscsi_softc {
 int   wdc_atapi_ioctl(struct scsi_link *, u_long, caddr_t, int);
 void  wdc_atapi_send_cmd(struct scsi_xfer *sc_xfer);
 
-static struct scsi_adapter atapiscsi_switch = {
+static const struct scsi_adapter atapiscsi_switch = {
wdc_atapi_send_cmd, NULL, NULL, NULL, wdc_atapi_ioctl
 };
 
blob - fe91366547e96750c389547cd0e9eec188efec4a
blob + 7805cba76f42c4468062ff97efcdcc12ec8f6c56
--- sys/dev/ic/aac.c
+++ sys/dev/ic/aac.c
@@ -129,7 +129,7 @@ struct cfdriver aac_cd = {
NULL, "aac", DV_DULL
 };
 
-struct scsi_adapter aac_switch = {
+const struct scsi_adapter aac_switch = {
aac_scsi_cmd, NULL, NULL, NULL, NULL
 };
 
blob - 3ee97dfee35ce2429e09a887a953c2b7fe966c5a
blob + 0233d7c24eaf996027a4c7297496a1b806bf800e
--- sys/dev/ic/adv.c
+++ sys/dev/ic/adv.c
@@ -81,7 +81,7 @@ struct cfdriver adv_cd = {
 };
 
 
-struct scsi_adapter adv_switch = {
+const struct scsi_adapter adv_switch = {
adv_scsi_cmd, NULL, NULL, NULL, NULL
 };
 
blob - 60dfe556e10dcec2ee9a35e11b1c5ed72dcc5416
blob + dbf7e632768d4821ed24def1ead1359416248251
--- sys/dev/ic/adw.c
+++ sys/dev/ic/adw.c
@@ -82,7 +82,7 @@ struct cfdriver adw_cd = {
NULL, "adw", DV_DULL
 };
 
-struct scsi_adapter adw_switch = {
+const struct scsi_adapter adw_switch = 

atascsi: constify method tables

2022-04-08 Thread Christian Weisgerber
This constifies the method tables used by the atascsi framework and
the ahci(4) and sili(4) drivers.

ok?
 
diff 9939c0709df17eb9b8160ad1561241ed2c4b8922 
83fd09f48cb0df5e29a782b651c4210e90f90b00
blob - 46c681203e8e39e25167f98907a2ecc848e9d1a4
blob + 19f61480e83314afe9d58d24b52e1b1d7e64ea93
--- sys/dev/ata/atascsi.c
+++ sys/dev/ata/atascsi.c
@@ -42,7 +42,7 @@ struct atascsi {
 
struct atascsi_host_port **as_host_ports;
 
-   struct atascsi_methods  *as_methods;
+   const struct atascsi_methods *as_methods;
struct scsi_adapter as_switch;
struct scsibus_softc*as_scsibus;
 
blob - a992001e82c39dbc9305141c08264956e890348b
blob + bf39ea0667b241a5cfc1118ed3890d2d6cf967f6
--- sys/dev/ata/atascsi.h
+++ sys/dev/ata/atascsi.h
@@ -374,7 +374,7 @@ struct atascsi_methods {
 struct atascsi_attach_args {
void*aaa_cookie;
 
-   struct atascsi_methods  *aaa_methods;
+   const struct atascsi_methods *aaa_methods;
void(*aaa_minphys)(struct buf *,
struct scsi_link *);
int aaa_nports;
blob - 571b29c29c4bd1113fca3314b6cf50f95db89bd0
blob + 46bf2f4526aa772461a011abe35a837c0d8ef300
--- sys/dev/ic/ahci.c
+++ sys/dev/ic/ahci.c
@@ -160,7 +160,7 @@ struct ata_xfer *   ahci_ata_get_xfer(void *, int);
 void   ahci_ata_put_xfer(struct ata_xfer *);
 void   ahci_ata_cmd(struct ata_xfer *);
 
-struct atascsi_methods ahci_atascsi_methods = {
+const struct atascsi_methods ahci_atascsi_methods = {
ahci_ata_probe,
ahci_ata_free,
ahci_ata_get_xfer,
blob - b2df117d41b126204e110facccb6dc7050dea347
blob + fecd665bfe4f985c244fc281e861cf62ebef615b
--- sys/dev/ic/sili.c
+++ sys/dev/ic/sili.c
@@ -202,7 +202,7 @@ voidsili_simulate_error(struct 
sili_ccb *ccb,
int *need_restart, int *err_port);
 #endif
 
-struct atascsi_methods sili_atascsi_methods = {
+const struct atascsi_methods sili_atascsi_methods = {
sili_ata_probe,
sili_ata_free,
sili_ata_get_xfer,

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



uoak*(4): constify method tables

2022-04-08 Thread Christian Weisgerber
This constifies the method tables in the OAK USB sensor drivers.
Bycatch from the ucom changes.

ok?
 
diff b29fcdeeb3e7dfaa7565194eb526a7ece255a8a8 
9939c0709df17eb9b8160ad1561241ed2c4b8922
blob - 789cef98e6a9a4d88bbb19b33e1801396618c591
blob + 511c0e62aec982253cdf4b27ae2af3e020cc6f9f
--- sys/dev/usb/uoak.h
+++ sys/dev/usb/uoak.h
@@ -133,7 +133,7 @@ struct uoak_softc {
struct uoak_config   sc_config[OAK_TARGET_MAXTYPES];
 
/* device specific methods */
-   struct uoak_methods  *sc_methods;
+   const struct uoak_methods *sc_methods;
 };
 
 
blob - d04fd5c5823740d5071c611c07f0dbe6249f6dfc
blob + 1ce4d75968d1031d4a610fd0535e46491874cd63
--- sys/dev/usb/uoaklux.c
+++ sys/dev/usb/uoaklux.c
@@ -96,7 +96,7 @@ const struct cfattach uoaklux_ca = {
uoaklux_detach,
 };
 
-struct uoak_methods uoaklux_methods = {
+const struct uoak_methods uoaklux_methods = {
uoaklux_dev_print,
uoaklux_dev_setting
 };
blob - 0257f4ee36873f494ad336150b26a3d51aa302e9
blob + ad54d29cdaf560cbc7120d846ee416bb59204b6f
--- sys/dev/usb/uoakrh.c
+++ sys/dev/usb/uoakrh.c
@@ -99,7 +99,7 @@ const struct cfattach uoakrh_ca = {
uoakrh_detach,
 };
 
-struct uoak_methods uoakrh_methods = {
+const struct uoak_methods uoakrh_methods = {
uoakrh_dev_print,
uoakrh_dev_setting
 };
blob - 011f5c858aa4c9b5d39a472a10eae7e05ba7148c
blob + 9f53491997ad6c1f3487079aca808a3046d2fb37
--- sys/dev/usb/uoakv.c
+++ sys/dev/usb/uoakv.c
@@ -100,7 +100,7 @@ const struct cfattach uoakv_ca = {
 
 };
 
-struct uoak_methods uoakv_methods = {
+const struct uoak_methods uoakv_methods = {
uoakv_dev_print,
uoakv_dev_setting
 };

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



ucom(4): constify method tables in USB serial drivers

2022-04-08 Thread Christian Weisgerber
This constifies the ucom method tables in the USB serial adapter
drivers, i.e., moves another kilobyte of function pointers into
read-only space.

ok?

diff 4df278d953b03573222cb39b422e005d4701614e 
b29fcdeeb3e7dfaa7565194eb526a7ece255a8a8
blob - 0f5d4bed40c58062bd043d0366485629d59c53cd
blob + bb96ad9ba3263b2647683d45bbb429ee0821c66e
--- sys/dev/usb/moscom.c
+++ sys/dev/usb/moscom.c
@@ -145,7 +145,7 @@ int moscom_param(void *, int, struct termios *);
 intmoscom_open(void *, int);
 intmoscom_cmd(struct moscom_softc *, int, int);
 
-struct ucom_methods moscom_methods = {
+const struct ucom_methods moscom_methods = {
NULL,
moscom_set,
moscom_param,
blob - 10b5df793ce6c39a343cedc1b375831fd7111fa9
blob + 02460365a0dbdd5f7dea9adb18da1667f224a2cb
--- sys/dev/usb/uark.c
+++ sys/dev/usb/uark.c
@@ -72,7 +72,7 @@ int   uark_param(void *, int, struct termios *);
 void   uark_break(void *, int, int);
 intuark_cmd(struct uark_softc *, uint16_t, uint16_t);
 
-struct ucom_methods uark_methods = {
+const struct ucom_methods uark_methods = {
uark_get_status,
uark_set,
uark_param,
blob - 1ca8871433d18ee8f427b1d25179e04e57e01c74
blob + 537ce7248f148f73e7343eaa041e15de8ec3eac6
--- sys/dev/usb/ubsa.c
+++ sys/dev/usb/ubsa.c
@@ -178,7 +178,7 @@ void ubsa_databits(struct ubsa_softc *, tcflag_t);
 void ubsa_stopbits(struct ubsa_softc *, tcflag_t);
 void ubsa_flow(struct ubsa_softc *, tcflag_t, tcflag_t);
 
-struct ucom_methods ubsa_methods = {
+const struct ucom_methods ubsa_methods = {
ubsa_get_status,
ubsa_set,
ubsa_param,
blob - 654b891542c81e1728ff9c49813441fe2da45048
blob + c8582f320d5756565f5b0e0398f7a91c4496d415
--- sys/dev/usb/uchcom.c
+++ sys/dev/usb/uchcom.c
@@ -215,7 +215,7 @@ int uchcom_match(struct device *, void *, void *);
 void   uchcom_attach(struct device *, struct device *, void *);
 intuchcom_detach(struct device *, int);
 
-struct ucom_methods uchcom_methods = {
+const struct ucom_methods uchcom_methods = {
uchcom_get_status,
uchcom_set,
uchcom_param,
blob - 8a4482fac9b511186211a5c3c83421da3db249b8
blob + 90fa0e99d53283b3d05b62d506a8bc0265698550
--- sys/dev/usb/ucom.c
+++ sys/dev/usb/ucom.c
@@ -102,7 +102,7 @@ struct ucom_softc {
struct usbd_pipe*sc_ipipe;  /* hid interrupt input pipe */
struct usbd_pipe*sc_opipe;  /* hid interrupt pipe */
 
-   struct ucom_methods *sc_methods;
+   const struct ucom_methods *sc_methods;
void*sc_parent;
int sc_portno;
 
blob - 216725b439b347c9acc33a5ff3c46a6ac1a49aea
blob + 321eed5ce3d61e64ed374b74f0555941e4a61f6b
--- sys/dev/usb/ucomvar.h
+++ sys/dev/usb/ucomvar.h
@@ -93,7 +93,7 @@ struct ucom_attach_args {
const char *info;   /* attach message */
struct usbd_device *device;
struct usbd_interface *iface;
-   struct ucom_methods *methods;
+   const struct ucom_methods *methods;
void *arg;
 };
 
blob - 4136a4752bd02d1ff2baf1665825a5b88339a782
blob + 9d17df368adb089ba19af989396808651720f271
--- sys/dev/usb/ucrcom.c
+++ sys/dev/usb/ucrcom.c
@@ -36,7 +36,7 @@ struct ucrcom_softc {
struct device   *sc_subdev;
 };
 
-struct ucom_methods ucrcom_methods = { NULL };
+const struct ucom_methods ucrcom_methods = { NULL };
 
 int ucrcom_match(struct device *, void *, void *);
 void ucrcom_attach(struct device *, struct device *, void *);
blob - cd1feaeedc005b29b1ec3b15388d0ea4fb3578e7
blob + d3bd683db41e947ada0caf3db8e8a5ea1caaa8bd
--- sys/dev/usb/ucycom.c
+++ sys/dev/usb/ucycom.c
@@ -129,7 +129,7 @@ voiducycom_close(void *, int);
 void   ucycom_write(void *, int, u_char *, u_char *, u_int32_t *);
 void   ucycom_read(void *, int, u_char **, u_int32_t *);
 
-struct ucom_methods ucycom_methods = {
+const struct ucom_methods ucycom_methods = {
NULL, /* ucycom_get_status, */
ucycom_set,
ucycom_param,
blob - fb7b8ae8621207b77e449e1461ad0fab764f1378
blob + 2e3f33863d4e3f91459a29a3bff05c585fdba167
--- sys/dev/usb/uftdi.c
+++ sys/dev/usb/uftdi.c
@@ -100,7 +100,7 @@ voiduftdi_break(void *sc, int portno, int onoff);
 intuftdi_8u232am_getrate(speed_t speed, int *rate);
 intuftdi_2232h_getrate(speed_t speed, int *rate);
 
-struct ucom_methods uftdi_methods = {
+const struct ucom_methods uftdi_methods = {
uftdi_get_status,
uftdi_set,
uftdi_param,
blob - 7ab16eb894ec27b7ad3e4c4783b342cffcd273c1
blob + dc2321ebfc86883ca67de5f913e3c6acc7eb4434
--- sys/dev/usb/uipaq.c
+++ sys/dev/usb/uipaq.c
@@ -94,7 +94,7 @@ void  uipaq_rts(struct uipaq_softc *sc, int onoff);
 void   uipaq_break(struct uipaq_softc* sc, int onoff);
 
 
-struct ucom_methods uipaq_methods = {
+const struct ucom_methods uipaq_methods = {
NULL,
uipaq_set,
NULL,
blob - be42faf696ebae3710e7aafe33a77481e28c9cfa
blob + 

[ouex]hci(4), dwctwo(4): constify bus/pipe method tables

2022-04-08 Thread Christian Weisgerber
This constifies the bus method and pipe method tables in our USB
host controller drivers.

dwctwo(4) only exists on octeon, which I don't have access to.
Could somebody check that it builds?

ok?
 
diff b5489662588c813212f71c840fa931535322293d 
4df278d953b03573222cb39b422e005d4701614e
blob - 9b9d1635f902afef00a4111dfba8f86d13f74b4e
blob + 531b5ce59fdf62019b590df2868d57cc88912f31
--- sys/dev/usb/dwc2/dwc2.c
+++ sys/dev/usb/dwc2/dwc2.c
@@ -146,7 +146,7 @@ dwc2_free_bus_bandwidth(struct dwc2_hsotg *hsotg, u16 
 
 #define DWC2_INTR_ENDPT 1
 
-STATIC struct usbd_bus_methods dwc2_bus_methods = {
+STATIC const struct usbd_bus_methods dwc2_bus_methods = {
.open_pipe =dwc2_open,
.dev_setaddr =  dwc2_setaddr,
.soft_intr =dwc2_softintr,
@@ -155,7 +155,7 @@ STATIC struct usbd_bus_methods dwc2_bus_methods = {
.freex =dwc2_freex,
 };
 
-STATIC struct usbd_pipe_methods dwc2_root_ctrl_methods = {
+STATIC const struct usbd_pipe_methods dwc2_root_ctrl_methods = {
.transfer = dwc2_root_ctrl_transfer,
.start =dwc2_root_ctrl_start,
.abort =dwc2_root_ctrl_abort,
@@ -164,7 +164,7 @@ STATIC struct usbd_pipe_methods dwc2_root_ctrl_methods
.done = dwc2_root_ctrl_done,
 };
 
-STATIC struct usbd_pipe_methods dwc2_root_intr_methods = {
+STATIC const struct usbd_pipe_methods dwc2_root_intr_methods = {
.transfer = dwc2_root_intr_transfer,
.start =dwc2_root_intr_start,
.abort =dwc2_root_intr_abort,
@@ -173,7 +173,7 @@ STATIC struct usbd_pipe_methods dwc2_root_intr_methods
.done = dwc2_root_intr_done,
 };
 
-STATIC struct usbd_pipe_methods dwc2_device_ctrl_methods = {
+STATIC const struct usbd_pipe_methods dwc2_device_ctrl_methods = {
.transfer = dwc2_device_ctrl_transfer,
.start =dwc2_device_ctrl_start,
.abort =dwc2_device_ctrl_abort,
@@ -182,7 +182,7 @@ STATIC struct usbd_pipe_methods dwc2_device_ctrl_metho
.done = dwc2_device_ctrl_done,
 };
 
-STATIC struct usbd_pipe_methods dwc2_device_intr_methods = {
+STATIC const struct usbd_pipe_methods dwc2_device_intr_methods = {
.transfer = dwc2_device_intr_transfer,
.start =dwc2_device_intr_start,
.abort =dwc2_device_intr_abort,
@@ -191,7 +191,7 @@ STATIC struct usbd_pipe_methods dwc2_device_intr_metho
.done = dwc2_device_intr_done,
 };
 
-STATIC struct usbd_pipe_methods dwc2_device_bulk_methods = {
+STATIC const struct usbd_pipe_methods dwc2_device_bulk_methods = {
.transfer = dwc2_device_bulk_transfer,
.start =dwc2_device_bulk_start,
.abort =dwc2_device_bulk_abort,
@@ -200,7 +200,7 @@ STATIC struct usbd_pipe_methods dwc2_device_bulk_metho
.done = dwc2_device_bulk_done,
 };
 
-STATIC struct usbd_pipe_methods dwc2_device_isoc_methods = {
+STATIC const struct usbd_pipe_methods dwc2_device_isoc_methods = {
.transfer = dwc2_device_isoc_transfer,
.start =dwc2_device_isoc_start,
.abort =dwc2_device_isoc_abort,
blob - 350580c00b30f8edcfd5edf8ad8d1734624462c6
blob + 77c170f164432f7df92fe7dcd64b5df9fd079dd9
--- sys/dev/usb/ehci.c
+++ sys/dev/usb/ehci.c
@@ -218,7 +218,7 @@ voidehci_dump_exfer(struct ehci_xfer *);
 
 #define EHCI_INTR_ENDPT 1
 
-struct usbd_bus_methods ehci_bus_methods = {
+const struct usbd_bus_methods ehci_bus_methods = {
.open_pipe = ehci_open,
.dev_setaddr = ehci_setaddr,
.soft_intr = ehci_softintr,
@@ -227,7 +227,7 @@ struct usbd_bus_methods ehci_bus_methods = {
.freex = ehci_freex,
 };
 
-struct usbd_pipe_methods ehci_root_ctrl_methods = {
+const struct usbd_pipe_methods ehci_root_ctrl_methods = {
.transfer = ehci_root_ctrl_transfer,
.start = ehci_root_ctrl_start,
.abort = ehci_root_ctrl_abort,
@@ -235,7 +235,7 @@ struct usbd_pipe_methods ehci_root_ctrl_methods = {
.done = ehci_root_ctrl_done,
 };
 
-struct usbd_pipe_methods ehci_root_intr_methods = {
+const struct usbd_pipe_methods ehci_root_intr_methods = {
.transfer = ehci_root_intr_transfer,
.start = ehci_root_intr_start,
.abort = ehci_root_intr_abort,
@@ -243,7 +243,7 @@ struct usbd_pipe_methods ehci_root_intr_methods = {
.done = ehci_root_intr_done,
 };
 
-struct usbd_pipe_methods ehci_device_ctrl_methods = {
+const struct usbd_pipe_methods ehci_device_ctrl_methods = {
.transfer = ehci_device_ctrl_transfer,
.start = ehci_device_ctrl_start,
.abort = ehci_device_ctrl_abort,
@@ -251,7 +251,7 @@ struct usbd_pipe_methods ehci_device_ctrl_methods = {
.done = ehci_device_ctrl_done,
 };
 
-struct usbd_pipe_methods ehci_device_intr_methods = {
+const struct usbd_pipe_methods ehci_device_intr_methods = {
.transfer = ehci_device_intr_transfer,
.start = ehci_device_intr_start,
.abort = 

esm(4/i386), it(4): constify sensor tables

2022-04-08 Thread Christian Weisgerber
This constifies the tables of two unrelated sensor drivers:
esm(4/i386) and it(4).

ok?

diff d6a09d27ff49886a6b6f4bd1f7d89c0f90a64b40 refs/heads/const
blob - 0a734dc971d9402e738d08d014555c8afb95827b
blob + e8a4e5eeadcdcfd23c1dd525470e70522272676b
--- sys/arch/i386/i386/esm.c
+++ sys/arch/i386/i386/esm.c
@@ -68,7 +68,7 @@ enum esm_sensor_type {
  * map esm sensor types to kernel sensor types.
  * keep this in sync with the esm_sensor_type enum above.
  */
-enum sensor_type esm_typemap[] = {
+const enum sensor_type esm_typemap[] = {
SENSOR_INTEGER,
SENSOR_INDICATOR,
SENSOR_TEMP,
@@ -149,7 +149,7 @@ voidesm_refresh(void *);
 intesm_get_devmap(struct esm_softc *, int, struct esm_devmap *);
 void   esm_devmap(struct esm_softc *, struct esm_devmap *);
 void   esm_make_sensors(struct esm_softc *, struct esm_devmap *,
-   struct esm_sensor_map *, int);
+   const struct esm_sensor_map *, int);
 intesm_thresholds(struct esm_softc *, struct esm_devmap *,
struct esm_sensor *);
 
@@ -536,7 +536,7 @@ esm_get_devmap(struct esm_softc *sc, int dev, struct e
return (0);
 }
 
-struct esm_sensor_map esm_sensors_esm2[] = {
+const struct esm_sensor_map esm_sensors_esm2[] = {
{ ESM_S_UNKNOWN,0,  "Motherboard" },
{ ESM_S_TEMP,   0,  "CPU 1" },
{ ESM_S_TEMP,   0,  "CPU 2" },
@@ -604,7 +604,7 @@ struct esm_sensor_map esm_sensors_esm2[] = {
{ ESM_S_UNKNOWN,0,  "PS Over Temp" }
 };
 
-struct esm_sensor_map esm_sensors_backplane[] = {
+const struct esm_sensor_map esm_sensors_backplane[] = {
{ ESM_S_UNKNOWN,0,  "Backplane" },
{ ESM_S_UNKNOWN,0,  "Backplane Control" },
{ ESM_S_TEMP,   0,  "Backplane Top" },
@@ -639,7 +639,7 @@ struct esm_sensor_map esm_sensors_backplane[] = {
{ ESM_S_VOLTS,  0,  "Backplane +3.3V" },
 };
 
-struct esm_sensor_map esm_sensors_powerunit[] = {
+const struct esm_sensor_map esm_sensors_powerunit[] = {
{ ESM_S_UNKNOWN,0,  "Power Unit" },
{ ESM_S_VOLTSx10,   0,  "Power Supply 1 +5V" },
{ ESM_S_VOLTSx10,   0,  "Power Supply 1 +12V" },
@@ -698,7 +698,7 @@ struct esm_sensor_map esm_sensors_powerunit[] = {
 void
 esm_devmap(struct esm_softc *sc, struct esm_devmap *devmap)
 {
-   struct esm_sensor_map   *sensor_map = NULL;
+   const struct esm_sensor_map *sensor_map = NULL;
const char  *name = NULL, *fname = NULL;
int mapsize = 0;
 
@@ -828,7 +828,7 @@ esm_devmap(struct esm_softc *sc, struct esm_devmap *de
 
 void
 esm_make_sensors(struct esm_softc *sc, struct esm_devmap *devmap,
-struct esm_sensor_map *sensor_map, int mapsize)
+const struct esm_sensor_map *sensor_map, int mapsize)
 {
struct esm_smb_req  req;
struct esm_smb_resp resp;
blob - 9cdce94a36e88fb46230424e35e0ef1d9c3a8878
blob + 2b8109ca2fa617f88eb012b0dcd0fd040c01
--- sys/dev/isa/it.c
+++ sys/dev/isa/it.c
@@ -70,7 +70,7 @@ int it_wdog_cb(void *, int);
 #define RFACT(x, y)(RFACT_NONE * ((x) + (y)) / (y))
 
 
-struct {
+const struct {
enum sensor_typetype;
const char  *desc;
 } it_sensors[IT_EC_NUMSENSORS] = {
@@ -102,7 +102,7 @@ struct {
 };
 
 /* rfact values for voltage sensors */
-int it_vrfact[IT_VOLT_COUNT] = {
+const int it_vrfact[IT_VOLT_COUNT] = {
RFACT_NONE, /* VCORE_A  */
RFACT_NONE, /* VCORE_A  */
RFACT_NONE, /* +3.3V*/
@@ -114,12 +114,12 @@ int it_vrfact[IT_VOLT_COUNT] = {
RFACT_NONE  /* VBAT */
 };
 
-int it_fan_regs[] = {
+const int it_fan_regs[] = {
IT_EC_FAN_TAC1, IT_EC_FAN_TAC2, IT_EC_FAN_TAC3,
IT_EC_FAN_TAC4_LSB, IT_EC_FAN_TAC5_LSB
 };
 
-int it_fan_ext_regs[] = {
+const int it_fan_ext_regs[] = {
IT_EC_FAN_EXT_TAC1, IT_EC_FAN_EXT_TAC2, IT_EC_FAN_EXT_TAC3,
IT_EC_FAN_TAC4_MSB, IT_EC_FAN_TAC5_MSB
 };
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



lm, uguru, fins, wbenv: constify sensor tables

2022-04-07 Thread Christian Weisgerber
This constifies the sensor tables of the lm(4), uguru(4), fins(4), and
wbenv(4) drivers, which all share the same basic design.

ok?

diff refs/heads/master refs/heads/const_sensors
blob - a813447ec9521a2a11a8b1f5daa38b881da007c1
blob + 3a1b2bfdc2b1d92d62f3b156479ad0ff5b57e463
--- sys/dev/i2c/w83l784r.c
+++ sys/dev/i2c/w83l784r.c
@@ -80,14 +80,14 @@ struct wbenv_softc {
 
struct ksensor sc_sensors[WBENV_MAX_SENSORS];
struct ksensordev sc_sensordev;
-   struct wbenv_sensor *sc_wbenv_sensors;
+   const struct wbenv_sensor *sc_wbenv_sensors;
int sc_numsensors;
 };
 
 intwbenv_match(struct device *, void *, void *);
 void   wbenv_attach(struct device *, struct device *, void *);
 
-void   wbenv_setup_sensors(struct wbenv_softc *, struct wbenv_sensor *);
+void   wbenv_setup_sensors(struct wbenv_softc *, const struct wbenv_sensor *);
 void   wbenv_refresh(void *);
 
 void   w83l784r_refresh_volt(struct wbenv_softc *, int);
@@ -108,7 +108,7 @@ struct cfdriver wbenv_cd = {
NULL, "wbenv", DV_DULL
 };
 
-struct wbenv_sensor w83l784r_sensors[] =
+const struct wbenv_sensor w83l784r_sensors[] =
 {
{ "VCore", SENSOR_VOLTS_DC, W83L784R_VCORE, w83l784r_refresh_volt, 
RFACT_NONE },
{ "VBAT", SENSOR_VOLTS_DC, W83L784R_VBAT, w83l784r_refresh_volt, 
RFACT(232, 99) },
@@ -123,7 +123,7 @@ struct wbenv_sensor w83l784r_sensors[] =
{ NULL }
 };
 
-struct wbenv_sensor w83l785r_sensors[] =
+const struct wbenv_sensor w83l785r_sensors[] =
 {
{ "VCore", SENSOR_VOLTS_DC, W83L784R_VCORE, w83l785r_refresh_volt, 
RFACT_NONE },
{ "+2.5V", SENSOR_VOLTS_DC, W83L785R_2_5V, w83l785r_refresh_volt, 
RFACT(100, 100) },
@@ -137,7 +137,7 @@ struct wbenv_sensor w83l785r_sensors[] =
{ NULL }
 };
 
-struct wbenv_sensor w83l785ts_l_sensors[] =
+const struct wbenv_sensor w83l785ts_l_sensors[] =
 {
{ "", SENSOR_TEMP, W83L784R_TEMP1, wbenv_refresh_temp },
 
@@ -236,7 +236,7 @@ wbenv_attach(struct device *parent, struct device *sel
 }
 
 void
-wbenv_setup_sensors(struct wbenv_softc *sc, struct wbenv_sensor *sensors)
+wbenv_setup_sensors(struct wbenv_softc *sc, const struct wbenv_sensor *sensors)
 {
int i;
 
blob - 88538623a7a7681f9cee6206fe48770a41b700ab
blob + be17af240b07da9bd1168d748354440d763a0419
--- sys/dev/ic/lm78.c
+++ sys/dev/ic/lm78.c
@@ -51,7 +51,7 @@ int  lm_match(struct lm_softc *);
 int  wb_match(struct lm_softc *);
 int  def_match(struct lm_softc *);
 
-void lm_setup_sensors(struct lm_softc *, struct lm_sensor *);
+void lm_setup_sensors(struct lm_softc *, const struct lm_sensor *);
 void lm_refresh(void *);
 
 void lm_refresh_sensor_data(struct lm_softc *);
@@ -74,13 +74,13 @@ struct lm_chip {
int (*chip_match)(struct lm_softc *);
 };
 
-struct lm_chip lm_chips[] = {
+const struct lm_chip lm_chips[] = {
{ wb_match },
{ lm_match },
{ def_match } /* Must be last */
 };
 
-struct lm_sensor lm78_sensors[] = {
+const struct lm_sensor lm78_sensors[] = {
/* Voltage */
{ "VCore A", SENSOR_VOLTS_DC, 0, 0x20, lm_refresh_volt, RFACT_NONE },
{ "VCore B", SENSOR_VOLTS_DC, 0, 0x21, lm_refresh_volt, RFACT_NONE },
@@ -101,7 +101,7 @@ struct lm_sensor lm78_sensors[] = {
{ NULL }
 };
 
-struct lm_sensor w83627hf_sensors[] = {
+const struct lm_sensor w83627hf_sensors[] = {
/* Voltage */
{ "VCore A", SENSOR_VOLTS_DC, 0, 0x20, lm_refresh_volt, RFACT_NONE },
{ "VCore B", SENSOR_VOLTS_DC, 0, 0x21, lm_refresh_volt, RFACT_NONE },
@@ -133,7 +133,7 @@ struct lm_sensor w83627hf_sensors[] = {
  * need special treatment, also because the reference voltage is 2.048 V
  * instead of the traditional 3.6 V.
  */
-struct lm_sensor w83627ehf_sensors[] = {
+const struct lm_sensor w83627ehf_sensors[] = {
/* Voltage */
{ "VCore", SENSOR_VOLTS_DC, 0, 0x20, lm_refresh_volt, RFACT_NONE / 2},
{ "+12V", SENSOR_VOLTS_DC, 0, 0x21, lm_refresh_volt, RFACT(56, 10) / 2 
},
@@ -163,7 +163,7 @@ struct lm_sensor w83627ehf_sensors[] = {
  * w83627dhg is almost identical to w83627ehf, except that 
  * it has 9 instead of 10 voltage sensors
  */
-struct lm_sensor w83627dhg_sensors[] = {
+const struct lm_sensor w83627dhg_sensors[] = {
/* Voltage */
{ "VCore", SENSOR_VOLTS_DC, 0, 0x20, lm_refresh_volt, RFACT_NONE / 2},
{ "+12V", SENSOR_VOLTS_DC, 0, 0x21, lm_refresh_volt, RFACT(56, 10) / 2 
},
@@ -188,7 +188,7 @@ struct lm_sensor w83627dhg_sensors[] = {
{ NULL }
 };
 
-struct lm_sensor nct6776f_sensors[] = {
+const struct lm_sensor nct6776f_sensors[] = {
/* Voltage */
{ "VCore", SENSOR_VOLTS_DC, 0, 0x20, lm_refresh_volt, RFACT_NONE / 2},
{ "+12V", SENSOR_VOLTS_DC, 0, 0x21, lm_refresh_volt, RFACT(56, 10) / 2 
},
@@ -216,7 +216,7 @@ struct lm_sensor nct6776f_sensors[] = {
 };
 
 /* NCT6779D */
-struct lm_sensor nct6779d_sensors[] = {
+const struct lm_sensor nct6779d_sensors[] = {
/* Voltage */
{ "VCore", 

Constify ifmedia descriptions

2022-04-07 Thread Christian Weisgerber
This constifies the ifmedia description tables, both in the kernel
(yes, I did a test compile with option IFMEDIA_DEBUG) and one
straggler in userland.

ok?

diff 3c78bc9451ce7ce927aaecc9f8e5113de7023a9c /usr/src
blob - 0ef67c56edd8be741533ccba974c11f198887b32
file + sbin/ifconfig/ifconfig.c
--- sbin/ifconfig/ifconfig.c
+++ sbin/ifconfig/ifconfig.c
@@ -3062,7 +3062,7 @@ const struct ifmedia_description ifm_type_descriptions
 const struct ifmedia_description ifm_subtype_descriptions[] =
 IFM_SUBTYPE_DESCRIPTIONS;
 
-struct ifmedia_description ifm_mode_descriptions[] =
+const struct ifmedia_description ifm_mode_descriptions[] =
 IFM_MODE_DESCRIPTIONS;
 
 const struct ifmedia_description ifm_option_descriptions[] =
blob - e71f433cfa6b61350625308c1328bb8e288e9dd5
file + sys/net/if_media.c
--- sys/net/if_media.c
+++ sys/net/if_media.c
@@ -393,7 +393,7 @@ ifmedia_delete_instance(struct ifmedia *ifm, uint64_t 
  * Compute the interface `baudrate' from the media, for the interface
  * metrics (used by routing daemons).
  */
-struct ifmedia_baudrate ifmedia_baudrate_descriptions[] =
+const struct ifmedia_baudrate ifmedia_baudrate_descriptions[] =
 IFM_BAUDRATE_DESCRIPTIONS;
 
 uint64_t
@@ -413,13 +413,13 @@ ifmedia_baudrate(uint64_t mword)
 
 #ifdef IFMEDIA_DEBUG
 
-struct ifmedia_description ifm_type_descriptions[] =
+const struct ifmedia_description ifm_type_descriptions[] =
 IFM_TYPE_DESCRIPTIONS;
 
-struct ifmedia_description ifm_subtype_descriptions[] =
+const struct ifmedia_description ifm_subtype_descriptions[] =
 IFM_SUBTYPE_DESCRIPTIONS;
 
-struct ifmedia_description ifm_option_descriptions[] =
+const struct ifmedia_description ifm_option_descriptions[] =
 IFM_OPTION_DESCRIPTIONS;
 
 /*
@@ -428,7 +428,7 @@ struct ifmedia_description ifm_option_descriptions[] =
 static void
 ifmedia_printword(uint64_t ifmw)
 {
-   struct ifmedia_description *desc;
+   const struct ifmedia_description *desc;
uint64_t seen_option = 0;
 
/* Print the top-level interface type. */
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



wscons: const-ify font encoding tables

2022-04-04 Thread Christian Weisgerber
You'd think that the kernel font bitmaps are a primary example of
data that could be read-only... and you'd be wrong.

The font encoding tables however are indeed constant as far as I can
tell.  The diff below marks them as such.  NetBSD has the same.

ok?

diff e8186ba8726c14dfc3512467cc2bc0b2ae1a3fdb 
c899115edffe4038f3d32db09d2986467ad3aa5a
blob - 7b6df0924cc0f109d62e7fda235625adf54d5667
blob + 7354a996595496b0fef0c324d878367c2a19feb9
--- sys/dev/wsfont/wsfont.c
+++ sys/dev/wsfont/wsfont.c
@@ -630,23 +630,23 @@ wsfont_unlock(int cookie)
  */
 
 struct wsfont_level1_glyphmap {
-   struct wsfont_level2_glyphmap **level2;
+   const struct wsfont_level2_glyphmap **level2;
int base;   /* High byte for first level2 entry */
int size;   /* Number of level2 entries */
 };
 
 struct wsfont_level2_glyphmap {
-   int base;   /* Low byte for first character */
-   int size;   /* Number of characters */
-   void *chars;/* Pointer to character number entries  */
-   int width;  /* Size of each entry in bytes (1,2,4)  */
+   int base;   /* Low byte for first character */
+   int size;   /* Number of characters */
+   const void *chars;  /* Pointer to character number entries  */
+   int width;  /* Size of each entry in bytes (1,2,4)  */
 };
 
 /*
  * IBM 437 maps
  */
 
-static u_int8_t
+static const u_int8_t
 ibm437_chars_0[] = {
 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
@@ -706,7 +706,7 @@ ibm437_chars_37[] = {
254
 };
 
-static struct wsfont_level2_glyphmap
+static const struct wsfont_level2_glyphmap
 ibm437_level2_0 = { 0, 256, ibm437_chars_0, 1 },
 ibm437_level2_1 = { 146, 1, ibm437_chars_1, 1 },
 ibm437_level2_3 = { 147, 50, ibm437_chars_3, 1 },
@@ -715,7 +715,7 @@ ibm437_level2_34 = { 5, 97, ibm437_chars_34, 1 },
 ibm437_level2_35 = { 16, 18, ibm437_chars_35, 1 },
 ibm437_level2_37 = { 0, 161, ibm437_chars_37, 1 };
 
-static struct wsfont_level2_glyphmap *ibm437_level1[] = {
+static const struct wsfont_level2_glyphmap *ibm437_level1[] = {
_level2_0, _level2_1, NULL, _level2_3,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
@@ -728,7 +728,7 @@ static struct wsfont_level2_glyphmap *ibm437_level1[] 
NULL, _level2_37
 };
 
-static struct wsfont_level1_glyphmap encodings[] = {
+static const struct wsfont_level1_glyphmap encodings[] = {
/* WSDISPLAY_FONTENC_ISO */
{ NULL, 0, 0 },
/* WSDISPLAY_FONTENC_IBM */
@@ -749,9 +749,9 @@ wsfont_map_unichar(struct wsdisplay_font *font, int c)
 #if !defined(SMALL_KERNEL)
if (font->encoding >= 0 && font->encoding < nitems(encodings)) {
int hi = (c >> 8), lo = c & 255;
-   struct wsfont_level1_glyphmap *map1 =
+   const struct wsfont_level1_glyphmap *map1 =
[font->encoding];
-   struct wsfont_level2_glyphmap *map2;
+   const struct wsfont_level2_glyphmap *map2;
 
hi -= map1->base;
 
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



ftp.1: fix editing mishap

2022-03-27 Thread Christian Weisgerber
It appears that in revision 1.85 of usr.bin/ftp/ftp.1 a sentence
fragment was accidentally not removed.

OK?

Index: usr.bin/ftp/ftp.1
===
RCS file: /cvs/src/usr.bin/ftp/ftp.1,v
retrieving revision 1.122
diff -u -p -r1.122 ftp.1
--- usr.bin/ftp/ftp.1   2 Feb 2021 12:58:42 -   1.122
+++ usr.bin/ftp/ftp.1   27 Mar 2022 19:12:31 -
@@ -759,9 +759,6 @@ and
 .Ic nmap
 settings.
 .Pp
-If the
-.Fl c
-flag is specified then
 The options are as follows:
 .Bl -tag -width Ds
 .It Fl c
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: Power-up cc --print-file-name for .so names

2022-02-20 Thread Christian Weisgerber
Mark Kettenis:

> There is a scenario where this goes wrong.  If a shared library lacks
> a DT_SONAME entry, the library filename is used to generate the
> DT_NEEDED entries.  But I would consider such a shared library broken
> and we fixed base a lng time ago.  Some care has to be taken when
> adding the symlinks to shared libraries in ports.  But I'm sure the
> package management stuff could check that shared libraries in ports
> have a DT_SONAME entry.

We never proceeded to clean that up in ports.

I just extracted all packages from the latest amd64 snapshot, and
out of a total of 3551 shared libraries, 593 do not have a SONAME.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: ypldap: fix -Wunused-but-set-variable warnings

2022-02-05 Thread Christian Weisgerber
Christian Weisgerber:

> usr.sbin/ypldap: fix -Wunused-but-set-variable warnings
> 
> * "wrlen" has been write-only since the code was imported.
> * Removing "dns_pid" replicates ntpd/ntp.c 1.122 (aece4353519f).
> * yp_check() looks like unfinished code.  Rather than removing it
>   we can ifdef it out.
> 
> ok?

Anybody?
The commit history of ypldap does not suggest a single responsible
person I could pin down.

> M  usr.sbin/ypldap/entries.c
> M  usr.sbin/ypldap/ldapclient.c
> M  usr.sbin/ypldap/yp.c
> 
> diff 34d4cced9a849c8319a25fd1cc1a7567223349c3 
> 5cdc3b04d0d3c70c2a9f0393913a5fdf64c11021
> blob - 3e2cc672786cad83caac1a22dfd2516c3ae9a3eb
> blob + b7394892eafe85bb1e8b9bb8e8cfdcc6658606f3
> --- usr.sbin/ypldap/entries.c
> +++ usr.sbin/ypldap/entries.c
> @@ -38,7 +38,6 @@
>  void
>  flatten_entries(struct env *env)
>  {
> - size_t   wrlen;
>   size_t   len;
>   char*linep;
>   char*endp;
> @@ -54,7 +53,6 @@ flatten_entries(struct env *env)
>*
>* An extra octet is alloced to make space for an additional NUL.
>*/
> - wrlen = env->sc_user_line_len;
>   if ((linep = calloc(1, env->sc_user_line_len + 1)) == NULL) {
>   /*
>* XXX: try allocating a smaller chunk of memory
> @@ -76,7 +74,6 @@ flatten_entries(struct env *env)
>   free(ue->ue_line);
>   ue->ue_line = endp;
>   endp += len;
> - wrlen -= len;
>  
>   /*
>* To save memory strdup(3) the netid_line which originally used
> @@ -92,7 +89,6 @@ flatten_entries(struct env *env)
>   env->sc_user_lines = linep;
>   log_debug("done pushing users");
>  
> - wrlen = env->sc_group_line_len;
>   if ((linep = calloc(1, env->sc_group_line_len + 1)) == NULL) {
>   /*
>* XXX: try allocating a smaller chunk of memory
> @@ -113,7 +109,6 @@ flatten_entries(struct env *env)
>   free(ge->ge_line);
>   ge->ge_line = endp;
>   endp += len;
> - wrlen -= len;
>   }
>   env->sc_group_lines = linep;
>   log_debug("done pushing groups");
> blob - 473986a8c5ed2449844e78cab034c6736b4a0e0f
> blob + 96e502ded7e3a3428a70411e628a988b4713fa90
> --- usr.sbin/ypldap/ldapclient.c
> +++ usr.sbin/ypldap/ldapclient.c
> @@ -357,7 +357,7 @@ client_shutdown(void)
>  pid_t
>  ldapclient(int pipe_main2client[2])
>  {
> - pid_tpid, dns_pid;
> + pid_tpid;
>   int  pipe_dns[2];
>   struct passwd   *pw;
>   struct event ev_sigint;
> @@ -382,7 +382,7 @@ ldapclient(int pipe_main2client[2])
>  
>   if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_dns) == -1)
>   fatal("socketpair");
> - dns_pid = ypldap_dns(pipe_dns, pw);
> + ypldap_dns(pipe_dns, pw);
>   close(pipe_dns[1]);
>  
>  #ifndef DEBUG
> blob - 84b5d59102057003557b1478af1b643b5aebdc69
> blob + 02a654e1daf2087889afc61630c30c02c6492156
> --- usr.sbin/ypldap/yp.c
> +++ usr.sbin/ypldap/yp.c
> @@ -268,12 +268,14 @@ yp_dispatch(struct svc_req *req, SVCXPRT *trans)
>  int
>  yp_check(struct svc_req *req)
>  {
> +#ifdef notyet
>   struct sockaddr_in  *caller;
>  
>   caller = svc_getcaller(req->rq_xprt);
>   /*
>* We might want to know who we allow here.
>*/
> +#endif
>   return (0);
>  }
>  

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Summary of remaining "set but not used" warnings

2022-01-29 Thread Christian Weisgerber
First up, note that clang 13 does not produce those
"variable foo set but not used" warnings by default.
They need to be enabled by -Wunused-but-set-variable
or, more typically, as part of -Wall.

Here are the remaining warnings seen in a "make build":

bin/ksh required arguments to macros
libexec/spamd   ifdef'ed out error handling
usr.bin/cvs unfinished code
usr.sbin/vmdarguments to debugging macros

Third-party code:

gnu/lib/libcxxabi
sbin/unwind/libunbound
gnu/usr.bin/clang
gnu/usr.bin/binutils
gnu/usr.bin/binutils-2.17
gnu/usr.bin/perl

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



ypldap: fix -Wunused-but-set-variable warnings

2022-01-29 Thread Christian Weisgerber
usr.sbin/ypldap: fix -Wunused-but-set-variable warnings

* "wrlen" has been write-only since the code was imported.
* Removing "dns_pid" replicates ntpd/ntp.c 1.122 (aece4353519f).
* yp_check() looks like unfinished code.  Rather than removing it
  we can ifdef it out.

ok?
 
M  usr.sbin/ypldap/entries.c
M  usr.sbin/ypldap/ldapclient.c
M  usr.sbin/ypldap/yp.c

diff 34d4cced9a849c8319a25fd1cc1a7567223349c3 
5cdc3b04d0d3c70c2a9f0393913a5fdf64c11021
blob - 3e2cc672786cad83caac1a22dfd2516c3ae9a3eb
blob + b7394892eafe85bb1e8b9bb8e8cfdcc6658606f3
--- usr.sbin/ypldap/entries.c
+++ usr.sbin/ypldap/entries.c
@@ -38,7 +38,6 @@
 void
 flatten_entries(struct env *env)
 {
-   size_t   wrlen;
size_t   len;
char*linep;
char*endp;
@@ -54,7 +53,6 @@ flatten_entries(struct env *env)
 *
 * An extra octet is alloced to make space for an additional NUL.
 */
-   wrlen = env->sc_user_line_len;
if ((linep = calloc(1, env->sc_user_line_len + 1)) == NULL) {
/*
 * XXX: try allocating a smaller chunk of memory
@@ -76,7 +74,6 @@ flatten_entries(struct env *env)
free(ue->ue_line);
ue->ue_line = endp;
endp += len;
-   wrlen -= len;
 
/*
 * To save memory strdup(3) the netid_line which originally used
@@ -92,7 +89,6 @@ flatten_entries(struct env *env)
env->sc_user_lines = linep;
log_debug("done pushing users");
 
-   wrlen = env->sc_group_line_len;
if ((linep = calloc(1, env->sc_group_line_len + 1)) == NULL) {
/*
 * XXX: try allocating a smaller chunk of memory
@@ -113,7 +109,6 @@ flatten_entries(struct env *env)
free(ge->ge_line);
ge->ge_line = endp;
endp += len;
-   wrlen -= len;
}
env->sc_group_lines = linep;
log_debug("done pushing groups");
blob - 473986a8c5ed2449844e78cab034c6736b4a0e0f
blob + 96e502ded7e3a3428a70411e628a988b4713fa90
--- usr.sbin/ypldap/ldapclient.c
+++ usr.sbin/ypldap/ldapclient.c
@@ -357,7 +357,7 @@ client_shutdown(void)
 pid_t
 ldapclient(int pipe_main2client[2])
 {
-   pid_tpid, dns_pid;
+   pid_tpid;
int  pipe_dns[2];
struct passwd   *pw;
struct event ev_sigint;
@@ -382,7 +382,7 @@ ldapclient(int pipe_main2client[2])
 
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_dns) == -1)
fatal("socketpair");
-   dns_pid = ypldap_dns(pipe_dns, pw);
+   ypldap_dns(pipe_dns, pw);
close(pipe_dns[1]);
 
 #ifndef DEBUG
blob - 84b5d59102057003557b1478af1b643b5aebdc69
blob + 02a654e1daf2087889afc61630c30c02c6492156
--- usr.sbin/ypldap/yp.c
+++ usr.sbin/ypldap/yp.c
@@ -268,12 +268,14 @@ yp_dispatch(struct svc_req *req, SVCXPRT *trans)
 int
 yp_check(struct svc_req *req)
 {
+#ifdef notyet
struct sockaddr_in  *caller;
 
caller = svc_getcaller(req->rq_xprt);
/*
 * We might want to know who we allow here.
 */
+#endif
return (0);
 }
 

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



tcpdump: fix -Wunused-but-set-variable warning

2022-01-29 Thread Christian Weisgerber
usr.sbin/tcpdump: fix -Wunused-but-set-variable warning

All "infile" handling was moved into priv_exec() when tcpdump was
priviledge separated.  The options are scanned both in priv_exec()
and in main(), so the empty case needs to remain in the latter.

ok?
 
M  usr.sbin/tcpdump/tcpdump.c

diff 812c6fb40ad70885ec0ec3a47d5ae49a0c43371d 
34d4cced9a849c8319a25fd1cc1a7567223349c3
blob - e0b6a4b318a21ba0c344204b7673dac3ca5dd657
blob + 50e793f63fab6e9aba2964e3a1c5eac289e06e08
--- usr.sbin/tcpdump/tcpdump.c
+++ usr.sbin/tcpdump/tcpdump.c
@@ -208,7 +208,7 @@ main(int argc, char **argv)
 {
int cnt = -1, op, i;
bpf_u_int32 localnet, netmask;
-   char *cp, *infile = NULL, *RFileName = NULL;
+   char *cp, *RFileName = NULL;
char ebuf[PCAP_ERRBUF_SIZE], *WFileName = NULL;
pcap_handler printer;
struct bpf_program *fcode;
@@ -285,7 +285,6 @@ main(int argc, char **argv)
break;
 
case 'F':
-   infile = optarg;
break;
 
case 'i':

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Remove unused variable from _asr_strdname(), print_dname()

2022-01-18 Thread Christian Weisgerber
remove unused variable from all copies of _asr_strdname() and print_dname()

This also fixes -Wunused-but-set-variable warnings warnings in smtpd
and smtpctl.  The code was imported with asr and then copied around.

ok?
 
M  lib/libc/asr/asr.c
M  regress/lib/libc/asr/bin/res_mkquery.c
M  regress/lib/libc/asr/bin/res_query.c
M  usr.sbin/smtpd/unpack_dns.c

diff dd8cb0714181f660d0f6f501ce5d7c09e7204a5f 
643c10a8541a41ff6f22d0b0ea6d3ded75b1e2b2
blob - 7cbf6aab5c9a7e5a36e3e1708fedef9fd0874821
blob + 5a40edf5caca600968dae7629988b687b5f15c35
--- lib/libc/asr/asr.c
+++ lib/libc/asr/asr.c
@@ -853,7 +853,7 @@ _asr_strdname(const char *_dname, char *buf, size_t ma
 {
const unsigned char *dname = _dname;
char*res;
-   size_t   left, n, count;
+   size_t   left, count;
 
if (_dname[0] == 0) {
strlcpy(buf, ".", max);
@@ -862,7 +862,7 @@ _asr_strdname(const char *_dname, char *buf, size_t ma
 
res = buf;
left = max - 1;
-   for (n = 0; dname[0] && left; n += dname[0]) {
+   while (dname[0] && left) {
count = (dname[0] < (left - 1)) ? dname[0] : (left - 1);
memmove(buf, dname + 1, count);
dname += dname[0] + 1;
blob - b32f471cdff9998ccd613f9c705207e9d17051e5
blob + 1228e5abc927df98ad26cc2ebdb431bd1a907f7e
--- regress/lib/libc/asr/bin/res_mkquery.c
+++ regress/lib/libc/asr/bin/res_mkquery.c
@@ -296,7 +296,7 @@ print_dname(const char *_dname, char *buf, size_t max)
 {
const unsigned char *dname = _dname;
char*res;
-   size_t   left, n, count;
+   size_t   left, count;
 
if (_dname[0] == 0) {
strlcpy(buf, ".", max);
@@ -305,7 +305,7 @@ print_dname(const char *_dname, char *buf, size_t max)
 
res = buf;
left = max - 1;
-   for (n = 0; dname[0] && left; n += dname[0]) {
+   while (dname[0] && left) {
count = (dname[0] < (left - 1)) ? dname[0] : (left - 1);
memmove(buf, dname + 1, count);
dname += dname[0] + 1;
blob - ca95a89a7ccdb300ca060589bf77203712306e54
blob + 1309a5724014c9d2e8f8352e12ba80db03b0be89
--- regress/lib/libc/asr/bin/res_query.c
+++ regress/lib/libc/asr/bin/res_query.c
@@ -332,7 +332,7 @@ print_dname(const char *_dname, char *buf, size_t max)
 {
const unsigned char *dname = _dname;
char*res;
-   size_t   left, n, count;
+   size_t   left, count;
 
if (_dname[0] == 0) {
strlcpy(buf, ".", max);
@@ -341,7 +341,7 @@ print_dname(const char *_dname, char *buf, size_t max)
 
res = buf;
left = max - 1;
-   for (n = 0; dname[0] && left; n += dname[0]) {
+   while (dname[0] && left) {
count = (dname[0] < (left - 1)) ? dname[0] : (left - 1);
memmove(buf, dname + 1, count);
dname += dname[0] + 1;
blob - fd7ec6ba6e0b745cb04a151994bcb5a51db110ae
blob + 848d2be321d82a14a9da83f4f034924592377862
--- usr.sbin/smtpd/unpack_dns.c
+++ usr.sbin/smtpd/unpack_dns.c
@@ -195,7 +195,7 @@ print_dname(const char *_dname, char *buf, size_t max)
 {
const unsigned char *dname = _dname;
char*res;
-   size_t   left, n, count;
+   size_t   left, count;
 
if (_dname[0] == 0) {
(void)strlcpy(buf, ".", max);
@@ -204,7 +204,7 @@ print_dname(const char *_dname, char *buf, size_t max)
 
res = buf;
left = max - 1;
-   for (n = 0; dname[0] && left; n += dname[0]) {
+   while (dname[0] && left) {
count = (dname[0] < (left - 1)) ? dname[0] : (left - 1);
memmove(buf, dname + 1, count);
dname += dname[0] + 1;

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



usr.sbin/rad: fix -Wunused-but-set-variable warning

2022-01-17 Thread Christian Weisgerber
usr.sbin/rad: fix -Wunused-but-set-variable warning

Trivial removal of unused variable.
 
M  usr.sbin/rad/frontend.c

diff c9fb0989c5128843af76d1ecd08c6f483f233307 
1779a21799642d5916a407f0cea6255b101c055c
blob - e6f6ae0419ab1662ebb2e8cdd17c07a82d1b87f9
blob + afddc245017e4576571e89b17f3655d352dc1d0f
--- usr.sbin/rad/frontend.c
+++ usr.sbin/rad/frontend.c
@@ -1222,10 +1222,7 @@ void
 build_leaving_packet(struct ra_iface *ra_iface)
 {
struct nd_router_advert  ra;
-   size_t   len;
 
-   len = sizeof(ra);
-
memset(, 0, sizeof(ra));
 
ra.nd_ra_type = ND_ROUTER_ADVERT;

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



usr.sbin/ospf6ctl: fix -Wunused-but-set-variable warning

2022-01-17 Thread Christian Weisgerber
usr.sbin/ospf6ctl: fix -Wunused-but-set-variable warning

Maybe this is uncompleted code, but I think we can remove it for
the time being.
 
M  usr.sbin/ospf6ctl/ospf6ctl.c

diff a992977b148f5fd9d4e3b9af9aeccac488edfa7a 
c9fb0989c5128843af76d1ecd08c6f483f233307
blob - fa1dc2cfd77369dc6964a6f18f6b562aa6598e5d
blob + 0b943bd96a7c01981563c172c524f70b4a7bd66e
--- usr.sbin/ospf6ctl/ospf6ctl.c
+++ usr.sbin/ospf6ctl/ospf6ctl.c
@@ -1179,9 +1179,7 @@ print_ospf_rtr_flags(u_int8_t opts)
 int
 show_rib_detail_msg(struct imsg *imsg)
 {
-   static struct in_addrarea_id;
struct ctl_rt   *rt;
-   struct area *area;
char*dstnet;
static u_int8_t  lasttype;
 
@@ -1250,8 +1248,6 @@ show_rib_detail_msg(struct imsg *imsg)
}
break;
case IMSG_CTL_AREA:
-   area = imsg->data;
-   area_id = area->id;
break;
case IMSG_CTL_END:
printf("\n");

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



usr.sbin/ospf6d: fix -Wunused-but-set-variable warnings

2022-01-17 Thread Christian Weisgerber
usr.sbin/ospf6d: fix -Wunused-but-set-variable warnings

merge_config() sets "rchange", but doesn't use it.  Comparing the
code to osfpd/ospfd.c makes me think that's an omission.  Either
way it seems odd that the two code bases differ here.

rde_summary_update() is incomplete.  We can simply #ifdef out the
unused variables.  The lack of indentation or braces following an
"else" is not pretty.  I don't know if we want to fix that up.
 
M  usr.sbin/ospf6d/ospf6d.c
M  usr.sbin/ospf6d/rde.c

diff 436bb480188bab67f704c5f9fcbcf0478db9c100 
a992977b148f5fd9d4e3b9af9aeccac488edfa7a
blob - b1193eaf336b9f5aa6a3b076efe4080881829152
blob + af22bd43781a4eaa32b5454fe8fa4fc9992f0b4b
--- usr.sbin/ospf6d/ospf6d.c
+++ usr.sbin/ospf6d/ospf6d.c
@@ -738,7 +738,7 @@ merge_config(struct ospfd_conf *conf, struct ospfd_con
if_start(conf, iface);
}
}
-   if (a->dirty) {
+   if (a->dirty || rchange) {
a->dirty = 0;
orig_rtr_lsa(LIST_FIRST(>iface_list)->area);
}
blob - f4a047206ec2c2e6d2550562560d5933825fb39d
blob + 4c43bb9296fef10f6d8f9e6a63fcc76e16fe5de9
--- usr.sbin/ospf6d/rde.c
+++ usr.sbin/ospf6d/rde.c
@@ -1249,8 +1249,10 @@ void
 rde_summary_update(struct rt_node *rte, struct area *area)
 {
struct vertex   *v = NULL;
-//XXX  struct lsa  *lsa;
+#if 0 /* XXX */
+   struct lsa  *lsa;
u_int16_ttype = 0;
+#endif
 
/* first check if we actually need to announce this route */
if (!(rte->d_type == DT_NET || rte->flags & OSPF_RTR_E))
@@ -1271,13 +1273,13 @@ rde_summary_update(struct rt_node *rte, struct area *a
/* TODO inter-area network route stuff */
/* TODO intra-area stuff -- condense LSA ??? */
 
+#if 0 /* XXX a lot todo */
if (rte->d_type == DT_NET) {
type = LSA_TYPE_INTER_A_PREFIX;
} else if (rte->d_type == DT_RTR) {
type = LSA_TYPE_INTER_A_ROUTER;
} else
 
-#if 0 /* XXX a lot todo */
/* update lsa but only if it was changed */
v = lsa_find(area, type, rte->prefix.s_addr, rde_router_id());
lsa = orig_sum_lsa(rte, area, type, rte->invalid);

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



usr.sbin/eigrpd: fix -Wunused-but-set-variable warning

2022-01-16 Thread Christian Weisgerber
usr.sbin/eigrpd: fix -Wunused-but-set-variable warning
 
M  usr.sbin/eigrpd/rde_dual.c

diff 41bbcfa017d9537de08312789d0087c674ce4732 
77e83947795bf5b53aef72070d7630a825b52c1f
blob - f1ed306e1371896676cf45b26e102af5e4d77b36
blob + 9465250934a6b1a5f6d565a13d32c4c450786670
--- usr.sbin/eigrpd/rde_dual.c
+++ usr.sbin/eigrpd/rde_dual.c
@@ -1048,11 +1048,9 @@ rde_last_reply(struct rt_node *rn)
struct eigrp*eigrp = rn->eigrp;
struct eigrp_route  *successor;
struct rde_nbr  *old_successor;
-   uint32_t old_fdistance;
struct rinfo ri;
 
old_successor = rn->successor.nbr;
-   old_fdistance = rn->successor.fdistance;
 
switch (rn->state) {
case DUAL_STA_ACTIVE0:

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



usr.sbin/dvmrpctl: fix -Wunused-but-set-variable warning

2022-01-16 Thread Christian Weisgerber
usr.sbin/dvmrpctl: fix -Wunused-but-set-variable warning

This looks like /* not yet implemented */, but the companion functions
show_rib_detail_msg() and show_mfc_detail_msg() are equally empty.
 
M  usr.sbin/dvmrpctl/dvmrpctl.c

diff 4bd575d8630c92f404211d2c625b200ac28213b9 
41bbcfa017d9537de08312789d0087c674ce4732
blob - 1b06d2bd134200716094881258b254877a1bf5d1
blob + ab02e0bb29b038ddaad26a49f43ba567d43770bc
--- usr.sbin/dvmrpctl/dvmrpctl.c
+++ usr.sbin/dvmrpctl/dvmrpctl.c
@@ -515,11 +515,8 @@ print_dvmrp_options(u_int8_t opts)
 int
 show_nbr_detail_msg(struct imsg *imsg)
 {
-   struct ctl_nbr  *nbr;
-
switch (imsg->hdr.type) {
case IMSG_CTL_SHOW_NBR:
-   nbr = imsg->data;
break;
case IMSG_CTL_END:
printf("\n");

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



usr.sbin/dhcpd: fix -Wunused-but-set-variable warning

2022-01-16 Thread Christian Weisgerber
usr.sbin/dhcpd: fix -Wunused-but-set-variable warning

I think this should be fine as strtonum() will catch any errors.
 
M  usr.sbin/dhcpd/parse.c

diff 5ce17aab12dafb0a17452c4e0e86b29d89d83d13 
4bd575d8630c92f404211d2c625b200ac28213b9
blob - 5b719219d00046e02e932796a78dc14ceddaa109
blob + 28334a443547ac7de98e80b4ca493429bfd60b09
--- usr.sbin/dhcpd/parse.c
+++ usr.sbin/dhcpd/parse.c
@@ -293,9 +293,8 @@ parse_lease_time(FILE *cfile, time_t *timep)
const char *errstr;
char *val;
uint32_t value;
-   int token;
 
-   token = next_token(, cfile);
+   next_token(, cfile);
 
value = strtonum(val, 0, UINT32_MAX, );
if (errstr) {

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



usr.bin/mg: fix -Wunused-but-set-variable warnings

2022-01-16 Thread Christian Weisgerber
usr.bin/mg: fix -Wunused-but-set-variable warnings

* strtonum() is only called to verify that a string is numerical, the
  return value is unused.
* inlist is no longer used after the code was refactored.

OK?
 
M  usr.bin/mg/interpreter.c

diff 6e5c342a53c05496c18849837c67b7dc05ce3792 
5ce17aab12dafb0a17452c4e0e86b29d89d83d13
blob - 320b4089849fb28a0b1ee4ff0db2542da902d56e
blob + f3a4310dfe01138c77e624877eefa92d29feb039
--- usr.bin/mg/interpreter.c
+++ usr.bin/mg/interpreter.c
@@ -492,9 +492,8 @@ multiarg(char *cmdp, char *argbuf, int numparams)
 
if (!doregex(regs, argp)) {
const char *errstr;
-   int iters;
 
-   iters = strtonum(argp, 0, INT_MAX, );
+   strtonum(argp, 0, INT_MAX, );
if (errstr != NULL)
return (dobeep_msgs("Var not found:",
argp));
@@ -628,7 +627,7 @@ expandvals(char *cmdp, char *valp, char *bp)
char*argp, *endp, *p, *v, *s = " ";
char*regs;
int  spc, cnt;
-   int  inlist, sizof, fin, inquote;
+   int  sizof, fin, inquote;
 
/* now find the first argument */
p = skipwhite(valp);
@@ -637,7 +636,7 @@ expandvals(char *cmdp, char *valp, char *bp)
return (dobeep_msg("strlcpy error"));
argp = argbuf;
spc = 1; /* initially fake a space so we find first argument */
-   inlist = fin = inquote = cnt = spc = 0;
+   fin = inquote = cnt = spc = 0;
 
for (p = argbuf; *p != '\0'; p++) {
if (*(p + 1) == '\0')
@@ -693,9 +692,8 @@ expandvals(char *cmdp, char *valp, char *bp)
continue;
} else {
const char *errstr;
-   int iters;
 
-   iters = strtonum(argp, 0, INT_MAX, );
+   strtonum(argp, 0, INT_MAX, );
if (errstr != NULL)
return (dobeep_msgs("Var not found:",
argp));

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



sbin/isakmpd: fix -Wunused-but-set-variable warnings

2022-01-15 Thread Christian Weisgerber
sbin/isakmpd: fix -Wunused-but-set-variable warnings

The one in pf_key_v2.c could use an extra set of eyes, but I don't
think there are any side effects.
 
M  sbin/isakmpd/ipsec.c
M  sbin/isakmpd/pf_key_v2.c
M  sbin/isakmpd/udp_encap.c
M  sbin/isakmpd/x509.c

diff ce1a8a9dca08dd7e01f71dfff05f1e4f4ed3bb7e 
7c5dd09ecd1ff078b868c9ab52aac9754cde7761
blob - 3954c5670aec76c08146272f2ab6e9038aa79c82
blob + 272b3657e8bdcf303f046d2641d11ad67f912fc2
--- sbin/isakmpd/ipsec.c
+++ sbin/isakmpd/ipsec.c
@@ -2090,7 +2090,6 @@ ipsec_decode_id(char *buf, size_t size, u_int8_t *id, 
 {
int id_type;
char   *addr = 0, *mask = 0;
-   u_int32_t  *idp;
 
if (id) {
if (!isakmpform) {
@@ -2102,7 +2101,6 @@ ipsec_decode_id(char *buf, size_t size, u_int8_t *id, 
id_len += ISAKMP_GEN_SZ;
}
id_type = GET_ISAKMP_ID_TYPE(id);
-   idp = (u_int32_t *) (id + ISAKMP_ID_DATA_OFF);
switch (id_type) {
case IPSEC_ID_IPV4_ADDR:
util_ntoa(, AF_INET, id + ISAKMP_ID_DATA_OFF);
blob - 04e867dedaf62dba9e3b1fc6702528432e53f243
blob + 302bcb52ee20cef9abb7ccc4fd052fcbd6486ea9
--- sbin/isakmpd/pf_key_v2.c
+++ sbin/isakmpd/pf_key_v2.c
@@ -2310,8 +2310,6 @@ pf_key_v2_acquire(struct pf_key_v2_msg *pmsg)
struct sadb_x_policy policy;
struct sadb_address *dst = 0, *src = 0;
struct sockaddr *dstaddr, *srcaddr = 0;
-   struct sadb_comb *scmb = 0;
-   struct sadb_prop *sprp = 0;
struct sadb_ident *srcident = 0, *dstident = 0;
chardstbuf[ADDRESS_MAX], srcbuf[ADDRESS_MAX], *peer = 0;
charconfname[120], *conn = 0;
@@ -2354,11 +2352,6 @@ pf_key_v2_acquire(struct pf_key_v2_msg *pmsg)
if (ext)
src = ext->seg;
 
-   ext = pf_key_v2_find_ext(pmsg, SADB_EXT_PROPOSAL);
-   if (ext) {
-   sprp = ext->seg;
-   scmb = (struct sadb_comb *) (sprp + 1);
-   }
ext = pf_key_v2_find_ext(pmsg, SADB_EXT_IDENTITY_SRC);
if (ext)
srcident = ext->seg;
blob - ae20f98fadadebfd1467ab99ba6527d3a2c236b6
blob + 1eef9e00b5c26ae4222a6c3f95b7d47ccf9d2bb8
--- sbin/isakmpd/udp_encap.c
+++ sbin/isakmpd/udp_encap.c
@@ -227,7 +227,7 @@ udp_encap_create(char *name)
 {
struct virtual_transport *v;
struct udp_transport*u;
-   struct transport*rv, *t;
+   struct transport*rv;
struct sockaddr *dst, *addr;
struct conf_list*addr_list = 0;
struct conf_list_node   *addr_node;
@@ -303,7 +303,6 @@ udp_encap_create(char *name)
rv = 0;
goto ret;
}
-   t = (struct transport *)v;
rv = udp_clone(v->encap, dst);
if (rv)
rv->vtbl = _encap_transport_vtbl;
blob - 4ccaf0728756f61db4dfb57d59d718b92e446f71
blob + a4cc6d7ca7325cfb71977a627e779d8d42e07396
--- sbin/isakmpd/x509.c
+++ sbin/isakmpd/x509.c
@@ -680,7 +680,7 @@ x509_read_crls_from_dir(X509_STORE *ctx, char *name)
struct stat sb;
charfullname[PATH_MAX];
charfile[PATH_MAX];
-   int fd, off, size;
+   int fd;
 
if (strlen(name) >= sizeof fullname - 1) {
log_print("x509_read_crls_from_dir: directory name too long");
@@ -695,8 +695,6 @@ x509_read_crls_from_dir(X509_STORE *ctx, char *name)
return 0;
}
strlcpy(fullname, name, sizeof fullname);
-   off = strlen(fullname);
-   size = sizeof fullname - off;
 
while ((fd = monitor_readdir(file, sizeof file)) != -1) {
LOG_DBG((LOG_CRYPTO, 60, "x509_read_crls_from_dir: reading "

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



sbin/pfctl: fix -Wunused-but-set-variable warning

2022-01-15 Thread Christian Weisgerber
sbin/pfctl: fix -Wunused-but-set-variable warning
 
M  sbin/pfctl/pfctl_optimize.c

diff 7c5dd09ecd1ff078b868c9ab52aac9754cde7761 
6e5c342a53c05496c18849837c67b7dc05ce3792
blob - 1ab170a832dd183a2895774549ff93896803039a
blob + 5736a0d7b0ba04afeed855daa61fc6b5ef3894e4
--- sbin/pfctl/pfctl_optimize.c
+++ sbin/pfctl/pfctl_optimize.c
@@ -789,7 +789,6 @@ block_feedback(struct pfctl *pf, struct superblock *bl
 {
TAILQ_HEAD( , pf_opt_rule) queue;
struct pf_opt_rule *por1, *por2;
-   u_int64_t total_count = 0;
struct pf_rule a, b;
 
 
@@ -799,8 +798,6 @@ block_feedback(struct pfctl *pf, struct superblock *bl
 */
TAILQ_FOREACH(por1, >sb_profiled_block->sb_rules, por_entry) {
comparable_rule(, >por_rule, DC);
-   total_count += por1->por_rule.packets[0] +
-   por1->por_rule.packets[1];
TAILQ_FOREACH(por2, >sb_rules, por_entry) {
if (por2->por_profile_count)
continue;

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



lib/libfuse: fix -Wunused-but-set-variable warning

2022-01-15 Thread Christian Weisgerber
Since the switch to LLVM 13, there are a number of compiler warnings
in base about variables that are assigned to but never used.  Let's
start picking the low-hanging fruit, ok?

lib/libfuse: fix -Wunused-but-set-variable warning
 
M  lib/libfuse/fuse_opt.c

diff 926818cffbbacfeb5685fa0f8e104986608d1a29 
ce1a8a9dca08dd7e01f71dfff05f1e4f4ed3bb7e
blob - 38bf34a7d157a543ee47f18bf350cb9183ab9803
blob + 26dcecd3e2486ad1f833bfee0827a2bd5406e068
--- lib/libfuse/fuse_opt.c
+++ lib/libfuse/fuse_opt.c
@@ -190,10 +190,9 @@ parse_opt(const struct fuse_opt *o, const char *opt, v
 fuse_opt_proc_t f, struct fuse_args *arg)
 {
const char *val;
-   int keyval, ret, found;
+   int ret, found;
size_t sep;
 
-   keyval = 0;
found = 0;
 
for(; o != NULL && o->templ; o++) {
@@ -205,11 +204,9 @@ parse_opt(const struct fuse_opt *o, const char *opt, v
val = opt;
 
/* check key=value or -p n */
-   if (o->templ[sep] == '=') {
-   keyval = 1;
+   if (o->templ[sep] == '=')
val = [sep + 1];
-   } else if (o->templ[sep] == ' ') {
-   keyval = 1;
+   else if (o->templ[sep] == ' ') {
if (sep == strlen(opt)) {
/* ask for next arg to be included */
return (IFUSE_OPT_NEED_ANOTHER_ARG);

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: unlock mmap(2) for anonymous mappings

2022-01-13 Thread Christian Weisgerber
Klemens Nanni:

> > > Now this is clearly a "slow" path.  I don't think there is any reason
> > > not to put all the code in that if (uvw_wxabort) block under the
> > > kernel lock.  For now I think making access to ps_wxcounter atomic is
> > > just too fine grained.
> > 
> > Right.  Lock the whole block.
> 
> Thanks everyone, here's the combined diff for that.
-snip-

FWIW, I ran an amd64 package bulk build with this.  No problems.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: Rework UNIX sockets locking to be fine grained

2021-12-02 Thread Christian Weisgerber
Vitaliy Makkoveev:

> Include missing "sys/refcnt.h" header to unpcb.h to fix libkvm and
> netstat(1) build. No functional changes.

I ran an amd64 package bulk build with this, four ncpu=4 machines.
No problems.

(Other than for dpb's ssh connection multiplexing, I don't think
Unix domain sockets or FIFOs are really used by this workload,
though.)

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: Variable type fix in parse.y (all of them)

2021-10-12 Thread Christian Weisgerber
Christian Weisgerber:

> Here's another attempt, incorporating millert's feedback and adding
> a few more casts:

Any interest in this or not worth the churn and I should drop it?

> Index: bin/chio/parse.y
> ===
> RCS file: /cvs/src/bin/chio/parse.y,v
> retrieving revision 1.23
> diff -u -p -r1.23 parse.y
> --- bin/chio/parse.y  15 Oct 2020 19:42:56 -  1.23
> +++ bin/chio/parse.y  2 Oct 2021 19:42:06 -
> @@ -179,9 +179,9 @@ lookup(char *s)
>  
>  #define MAXPUSHBACK  128
>  
> -u_char   *parsebuf;
> +char *parsebuf;
>  int   parseindex;
> -u_charpushback_buffer[MAXPUSHBACK];
> +char  pushback_buffer[MAXPUSHBACK];
>  int   pushback_index = 0;
>  
>  int
> @@ -192,7 +192,7 @@ lgetc(int quotec)
>   if (parsebuf) {
>   /* Read character from the parsebuffer instead of input. */
>   if (parseindex >= 0) {
> - c = parsebuf[parseindex++];
> + c = (unsigned char)parsebuf[parseindex++];
>   if (c != '\0')
>   return (c);
>   parsebuf = NULL;
> @@ -201,7 +201,7 @@ lgetc(int quotec)
>   }
>  
>   if (pushback_index)
> - return (pushback_buffer[--pushback_index]);
> + return ((unsigned char)pushback_buffer[--pushback_index]);
>  
>   if (quotec) {
>   if ((c = getc(file->stream)) == EOF) {
> @@ -242,10 +242,10 @@ lungetc(int c)
>   if (parseindex >= 0)
>   return (c);
>   }
> - if (pushback_index < MAXPUSHBACK-1)
> - return (pushback_buffer[pushback_index++] = c);
> - else
> + if (pushback_index + 1 >= MAXPUSHBACK)
>   return (EOF);
> + pushback_buffer[pushback_index++] = c;
> + return (c);
>  }
>  
>  int
> @@ -272,8 +272,8 @@ findeol(void)
>  int
>  yylex(void)
>  {
> - u_char   buf[8096];
> - u_char  *p;
> + char buf[8096];
> + char*p;
>   int  quotec, next, c;
>   int  token;
>  
> @@ -353,8 +353,8 @@ yylex(void)
>   } else {
>  nodigits:
>   while (p > buf + 1)
> - lungetc(*--p);
> - c = *--p;
> + lungetc((unsigned char)*--p);
> + c = (unsigned char)*--p;
>   if (c == '-')
>   return (c);
>   }
> Index: sbin/dhcpleased/parse.y
> ===
> RCS file: /cvs/src/sbin/dhcpleased/parse.y,v
> retrieving revision 1.4
> diff -u -p -r1.4 parse.y
> --- sbin/dhcpleased/parse.y   20 Sep 2021 11:46:22 -  1.4
> +++ sbin/dhcpleased/parse.y   2 Oct 2021 19:17:33 -
> @@ -463,10 +463,10 @@ findeol(void)
>  int
>  yylex(void)
>  {
> - unsigned charbuf[8096];
> - unsigned char   *p, *val;
> - int  quotec, next, c;
> - int  token;
> + char buf[8096];
> + char*p, *val;
> + int  quotec, next, c;
> + int  token;
>  
>  top:
>   p = buf;
> @@ -502,7 +502,7 @@ top:
>   p = val + strlen(val) - 1;
>   lungetc(DONE_EXPAND);
>   while (p >= val) {
> - lungetc(*p);
> + lungetc((unsigned char)*p);
>   p--;
>   }
>   lungetc(START_EXPAND);
> @@ -578,8 +578,8 @@ top:
>   } else {
>  nodigits:
>   while (p > buf + 1)
> - lungetc(*--p);
> - c = *--p;
> + lungetc((unsigned char)*--p);
> + c = (unsigned char)*--p;
>   if (c == '-')
>   return (c);
>   }
> Index: sbin/iked/parse.y
> ===
> RCS file: /cvs/src/sbin/iked/parse.y,v
> retrieving revision 1.132
> diff -u -p -r1.132 parse.y
> --- sbin/iked/parse.y 18 Sep 2021 16:45:52 -  1.132
> +++ sbin/iked/parse.y 2 Oct 2021 19:07:12 -
> @@ -1510,10 +1510,10 @@ findeol(void)
>  int
>  yylex(void)
>  {
> - unsigned charbuf[8096];
> - unsigned char   *p, *val;
> - int  quotec, next, c;
> - int  token;
> + char buf[8096];
> + char*p, *val;
> + int  quotec, next, c;
> + int  token;
>  
>  top:
>

Re: Variable type fix in parse.y (all of them)

2021-10-02 Thread Christian Weisgerber
Here's another attempt, incorporating millert's feedback and adding
a few more casts:

Index: bin/chio/parse.y
===
RCS file: /cvs/src/bin/chio/parse.y,v
retrieving revision 1.23
diff -u -p -r1.23 parse.y
--- bin/chio/parse.y15 Oct 2020 19:42:56 -  1.23
+++ bin/chio/parse.y2 Oct 2021 19:42:06 -
@@ -179,9 +179,9 @@ lookup(char *s)
 
 #define MAXPUSHBACK128
 
-u_char *parsebuf;
+char   *parsebuf;
 int parseindex;
-u_char  pushback_buffer[MAXPUSHBACK];
+charpushback_buffer[MAXPUSHBACK];
 int pushback_index = 0;
 
 int
@@ -192,7 +192,7 @@ lgetc(int quotec)
if (parsebuf) {
/* Read character from the parsebuffer instead of input. */
if (parseindex >= 0) {
-   c = parsebuf[parseindex++];
+   c = (unsigned char)parsebuf[parseindex++];
if (c != '\0')
return (c);
parsebuf = NULL;
@@ -201,7 +201,7 @@ lgetc(int quotec)
}
 
if (pushback_index)
-   return (pushback_buffer[--pushback_index]);
+   return ((unsigned char)pushback_buffer[--pushback_index]);
 
if (quotec) {
if ((c = getc(file->stream)) == EOF) {
@@ -242,10 +242,10 @@ lungetc(int c)
if (parseindex >= 0)
return (c);
}
-   if (pushback_index < MAXPUSHBACK-1)
-   return (pushback_buffer[pushback_index++] = c);
-   else
+   if (pushback_index + 1 >= MAXPUSHBACK)
return (EOF);
+   pushback_buffer[pushback_index++] = c;
+   return (c);
 }
 
 int
@@ -272,8 +272,8 @@ findeol(void)
 int
 yylex(void)
 {
-   u_char   buf[8096];
-   u_char  *p;
+   char buf[8096];
+   char*p;
int  quotec, next, c;
int  token;
 
@@ -353,8 +353,8 @@ yylex(void)
} else {
 nodigits:
while (p > buf + 1)
-   lungetc(*--p);
-   c = *--p;
+   lungetc((unsigned char)*--p);
+   c = (unsigned char)*--p;
if (c == '-')
return (c);
}
Index: sbin/dhcpleased/parse.y
===
RCS file: /cvs/src/sbin/dhcpleased/parse.y,v
retrieving revision 1.4
diff -u -p -r1.4 parse.y
--- sbin/dhcpleased/parse.y 20 Sep 2021 11:46:22 -  1.4
+++ sbin/dhcpleased/parse.y 2 Oct 2021 19:17:33 -
@@ -463,10 +463,10 @@ findeol(void)
 int
 yylex(void)
 {
-   unsigned charbuf[8096];
-   unsigned char   *p, *val;
-   int  quotec, next, c;
-   int  token;
+   char buf[8096];
+   char*p, *val;
+   int  quotec, next, c;
+   int  token;
 
 top:
p = buf;
@@ -502,7 +502,7 @@ top:
p = val + strlen(val) - 1;
lungetc(DONE_EXPAND);
while (p >= val) {
-   lungetc(*p);
+   lungetc((unsigned char)*p);
p--;
}
lungetc(START_EXPAND);
@@ -578,8 +578,8 @@ top:
} else {
 nodigits:
while (p > buf + 1)
-   lungetc(*--p);
-   c = *--p;
+   lungetc((unsigned char)*--p);
+   c = (unsigned char)*--p;
if (c == '-')
return (c);
}
Index: sbin/iked/parse.y
===
RCS file: /cvs/src/sbin/iked/parse.y,v
retrieving revision 1.132
diff -u -p -r1.132 parse.y
--- sbin/iked/parse.y   18 Sep 2021 16:45:52 -  1.132
+++ sbin/iked/parse.y   2 Oct 2021 19:07:12 -
@@ -1510,10 +1510,10 @@ findeol(void)
 int
 yylex(void)
 {
-   unsigned charbuf[8096];
-   unsigned char   *p, *val;
-   int  quotec, next, c;
-   int  token;
+   char buf[8096];
+   char*p, *val;
+   int  quotec, next, c;
+   int  token;
 
 top:
p = buf;
@@ -1549,7 +1549,7 @@ top:
p = val + strlen(val) - 1;
lungetc(DONE_EXPAND);
while (p >= val) {
-   lungetc(*p);
+   lungetc((unsigned char)*p);
p--;
}
lungetc(START_EXPAND);
@@ -1625,8 +1625,8 @@ top:
} else {
 nodigits:
while (p > buf + 1)
-   lungetc(*--p);
-   c = *--p;
+   lungetc((unsigned char)*--p);
+   c = (unsigned char)*--p;
if (c == 

Re: Variable type fix in parse.y (all of them)

2021-09-30 Thread Christian Weisgerber
Todd C. Miller:

> On Thu, 30 Sep 2021 21:37:06 +0200, Christian Weisgerber wrote:
> 
> > Unfortunately that also affects the parsebuf/pushback_buffer complex
> > used in some parser.y files.
> 
> That would require a few extra casts but it is straightforward.

E.g. like this?

Index: bin/chio/parse.y
===
RCS file: /cvs/src/bin/chio/parse.y,v
retrieving revision 1.23
diff -u -p -r1.23 parse.y
--- bin/chio/parse.y15 Oct 2020 19:42:56 -  1.23
+++ bin/chio/parse.y30 Sep 2021 20:13:12 -
@@ -179,9 +179,9 @@ lookup(char *s)
 
 #define MAXPUSHBACK128
 
-u_char *parsebuf;
+char   *parsebuf;
 int parseindex;
-u_char  pushback_buffer[MAXPUSHBACK];
+charpushback_buffer[MAXPUSHBACK];
 int pushback_index = 0;
 
 int
@@ -192,7 +192,7 @@ lgetc(int quotec)
if (parsebuf) {
/* Read character from the parsebuffer instead of input. */
if (parseindex >= 0) {
-   c = parsebuf[parseindex++];
+   c = (unsigned char)parsebuf[parseindex++];
if (c != '\0')
return (c);
parsebuf = NULL;
@@ -201,7 +201,7 @@ lgetc(int quotec)
}
 
if (pushback_index)
-   return (pushback_buffer[--pushback_index]);
+   return ((unsigned char)pushback_buffer[--pushback_index]);
 
if (quotec) {
if ((c = getc(file->stream)) == EOF) {
@@ -243,7 +243,7 @@ lungetc(int c)
return (c);
}
if (pushback_index < MAXPUSHBACK-1)
-   return (pushback_buffer[pushback_index++] = c);
+   return (unsigned char)(pushback_buffer[pushback_index++] = c);
else
return (EOF);
 }
@@ -272,8 +272,8 @@ findeol(void)
 int
 yylex(void)
 {
-   u_char   buf[8096];
-   u_char  *p;
+   char buf[8096];
+   char*p;
int  quotec, next, c;
int  token;
 
@@ -353,8 +353,8 @@ yylex(void)
} else {
 nodigits:
while (p > buf + 1)
-   lungetc(*--p);
-   c = *--p;
+   lungetc((unsigned char)*--p);
+   c = (unsigned char)*--p;
if (c == '-')
return (c);
}

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: Variable type fix in parse.y (all of them)

2021-09-30 Thread Christian Weisgerber
Todd C. Miller:

>   lungetc((u_char)*p);
>   ...
>   c = (u_char)*--p;
> 
> Since we use casts sparingly, when they are present they indicate
> something you need to pay attention to.  That is not the case when
> we simply change the type.

Unfortunately that also affects the parsebuf/pushback_buffer complex
used in some parser.y files.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: Variable type fix in parse.y (all of them)

2021-09-30 Thread Christian Weisgerber
Christian Weisgerber:

> The oft-copied parse.y code declares some variables as "unsigned char *"
> but passes them to functions that take "char *" arguments and doesn't
> make any use of the unsigned property.

While I'm here...

>  int
>  yylex(void)
>  {
> - u_char   buf[8096];
> - u_char  *p;
> + char buf[8096];
> + char*p;

Is there any significance to that number 8096?  It suspiciously
looks like somebody mixed up the powers of two 4096 and 8192.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Variable type fix in parse.y (all of them)

2021-09-29 Thread Christian Weisgerber
The oft-copied parse.y code declares some variables as "unsigned char *"
but passes them to functions that take "char *" arguments and doesn't
make any use of the unsigned property.

For OpenBSD's clang, -Wpointer-sign has been disabled by default,
but when that code is built elsewhere, the compiler will complain.
I noticed and fixed this for Got and millert@ suggested that it
should be applied to all copies of parse.y in OpenBSD, so here we
go.

OK?

Index: bin/chio/parse.y
===
RCS file: /cvs/src/bin/chio/parse.y,v
retrieving revision 1.23
diff -u -p -r1.23 parse.y
--- bin/chio/parse.y15 Oct 2020 19:42:56 -  1.23
+++ bin/chio/parse.y29 Sep 2021 18:32:58 -
@@ -179,9 +179,9 @@ lookup(char *s)
 
 #define MAXPUSHBACK128
 
-u_char *parsebuf;
+char   *parsebuf;
 int parseindex;
-u_char  pushback_buffer[MAXPUSHBACK];
+charpushback_buffer[MAXPUSHBACK];
 int pushback_index = 0;
 
 int
@@ -272,8 +272,8 @@ findeol(void)
 int
 yylex(void)
 {
-   u_char   buf[8096];
-   u_char  *p;
+   char buf[8096];
+   char*p;
int  quotec, next, c;
int  token;
 
Index: sbin/dhcpleased/parse.y
===
RCS file: /cvs/src/sbin/dhcpleased/parse.y,v
retrieving revision 1.4
diff -u -p -r1.4 parse.y
--- sbin/dhcpleased/parse.y 20 Sep 2021 11:46:22 -  1.4
+++ sbin/dhcpleased/parse.y 29 Sep 2021 18:14:01 -
@@ -463,10 +463,10 @@ findeol(void)
 int
 yylex(void)
 {
-   unsigned charbuf[8096];
-   unsigned char   *p, *val;
-   int  quotec, next, c;
-   int  token;
+   char buf[8096];
+   char*p, *val;
+   int  quotec, next, c;
+   int  token;
 
 top:
p = buf;
Index: sbin/iked/parse.y
===
RCS file: /cvs/src/sbin/iked/parse.y,v
retrieving revision 1.132
diff -u -p -r1.132 parse.y
--- sbin/iked/parse.y   18 Sep 2021 16:45:52 -  1.132
+++ sbin/iked/parse.y   29 Sep 2021 18:16:23 -
@@ -1510,10 +1510,10 @@ findeol(void)
 int
 yylex(void)
 {
-   unsigned charbuf[8096];
-   unsigned char   *p, *val;
-   int  quotec, next, c;
-   int  token;
+   char buf[8096];
+   char*p, *val;
+   int  quotec, next, c;
+   int  token;
 
 top:
p = buf;
Index: sbin/ipsecctl/parse.y
===
RCS file: /cvs/src/sbin/ipsecctl/parse.y,v
retrieving revision 1.179
diff -u -p -r1.179 parse.y
--- sbin/ipsecctl/parse.y   29 Dec 2020 19:50:03 -  1.179
+++ sbin/ipsecctl/parse.y   29 Sep 2021 18:33:54 -
@@ -1054,9 +1054,9 @@ lookup(char *s)
 
 #define MAXPUSHBACK128
 
-u_char *parsebuf;
+char   *parsebuf;
 int parseindex;
-u_char  pushback_buffer[MAXPUSHBACK];
+charpushback_buffer[MAXPUSHBACK];
 int pushback_index = 0;
 
 int
@@ -1148,8 +1148,8 @@ findeol(void)
 int
 yylex(void)
 {
-   u_char   buf[8096];
-   u_char  *p, *val;
+   char buf[8096];
+   char*p, *val;
int  quotec, next, c;
int  token;
 
Index: sbin/pfctl/parse.y
===
RCS file: /cvs/src/sbin/pfctl/parse.y,v
retrieving revision 1.709
diff -u -p -r1.709 parse.y
--- sbin/pfctl/parse.y  1 Feb 2021 00:31:04 -   1.709
+++ sbin/pfctl/parse.y  29 Sep 2021 18:23:47 -
@@ -5170,8 +5170,8 @@ findeol(void)
 int
 yylex(void)
 {
-   u_char   buf[8096];
-   u_char  *p, *val;
+   char buf[8096];
+   char*p, *val;
int  quotec, next, c;
int  token;
 
Index: sbin/unwind/parse.y
===
RCS file: /cvs/src/sbin/unwind/parse.y,v
retrieving revision 1.27
diff -u -p -r1.27 parse.y
--- sbin/unwind/parse.y 31 Aug 2021 20:18:03 -  1.27
+++ sbin/unwind/parse.y 29 Sep 2021 18:25:04 -
@@ -557,10 +557,10 @@ findeol(void)
 int
 yylex(void)
 {
-   unsigned charbuf[8096];
-   unsigned char   *p, *val;
-   int  quotec, next, c;
-   int  token;
+   char buf[8096];
+   char*p, *val;
+   int  quotec, next, c;
+   int  token;
 
 top:
p = buf;
Index: usr.sbin/acme-client/parse.y
===
RCS file: /cvs/src/usr.sbin/acme-client/parse.y,v
retrieving revision 1.42
diff -u -p -r1.42 parse.y
--- usr.sbin/acme-client/parse.y14 Sep 2020 16:00:17 -  1.42
+++ usr.sbin/acme-client/parse.y29 Sep 2021 18:28:10 -
@@ -594,8 +594,8 @@ findeol(void)
 int
 yylex(void)
 {
-   u_char   buf[8096];
-   u_char  *p, *val;
+   char buf[8096];
+   char*p, *val;
int  quotec, next, c;

Re: fresh prompt after Ctrl-C in cdio(1)

2021-08-12 Thread Christian Weisgerber
Ingo Schwarze:

> deraadt@ recently pointed out to me in private mail that it is good
> for usability if interactive programs providing line editing
> functionality are consistent what they do with Ctrl-C, ideally
> discard the current input line and provide a fresh prompt.
> 
> So i propose to do the same in cdio(1), which currently just exits
> on Ctrl-C.
> 
> OK?

That looks correct and works fine for me.  ok naddy@

(I still have a USB CD drive and I use it from time to time to play
audio CDs with cdio.  I had completely forgotten that cdio supports
editline, though.  The cdio interactive mode is pretty useless since
interrupting a running command aborts the program.)

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



scp: tweak man page for -3 by default

2021-08-10 Thread Christian Weisgerber
scp: tweak documentation and error message for -3 by default
 
Now that the -3 option is enabled by default, flip the documentation
and an error message from "requires -3" to "blocked by -R".

OK?
 
diff 453220bf36dcff10addeceb44e98f71bfeddcd53 
f457be8f3b007fb662dd10fb565ab79b602109f5
blob - 972269af7f61d7643a68fbcfa1e7a6a9b7d207e1
blob + b8d969ef781d4ef665f82dbc1a10d20e0da6e307
--- usr.bin/ssh/scp.1
+++ usr.bin/ssh/scp.1
@@ -67,10 +67,10 @@ as host specifiers.
 .Pp
 When copying between two remote hosts, if the URI format is used, a
 .Ar port
-may only be specified on the
+cannot be specified on the
 .Ar target
 if the
-.Fl 3
+.Fl R
 option is used.
 .Pp
 The options are as follows:
@@ -260,7 +260,7 @@ The program must understand
 options.
 .It Fl s
 Use the SFTP protocol for file transfers instead of the legacy SCP protocol.
-Using SFTP provides avoids invoking a shell on the remote side and provides
+Using SFTP avoids invoking a shell on the remote side and provides
 more predictable filename handling, as the SCP protocol
 relied on the remote shell for expanding
 .Xr glob 3
blob - ce133d87af2fff873e3202cecde7d91c6c94171f
blob + 7ee66c26bce50a4bf6e0132fddb41a7850f26e83
--- usr.bin/ssh/scp.c
+++ usr.bin/ssh/scp.c
@@ -1063,7 +1063,7 @@ toremote(int argc, char **argv, enum scp_mode_e mode, 
if (tport != -1 && tport != SSH_DEFAULT_PORT) {
/* This would require the remote support URIs */
fatal("target port not supported with two "
-   "remote hosts without the -3 option");
+   "remote hosts and the -R option");
}
 
freeargs();

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: scp(1) changes in snaps

2021-08-07 Thread Christian Weisgerber
"Theo de Raadt":

> 2) With very long names, it truncates the end of the path. This is less useful
> information.  Imagine a copy operation with multiple files being transferred,
> one of them is huge and surprisingly long, but you cannot identify which one
> because all the truncated long paths are the same.
> 
> 3) (old) scp and rsync show the path only component only.

Oh, I hadn't even realized that this affects the way _all_ source
file paths are displayed, whether remote or local, whether originally
specified with absolute or relative path.

Path width is limited to 44 characters in a normal 80-char terminal.

$ echo -n /usr/ports/distfiles/ |wc  
   0   1  21
$ echo -n /usr/ports/logs/amd64/paths/ |wc 
   0   1  28

> So I think the path-component-only scheme is better, and this should 
> change.

Yes, please.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: scp(1) changes in snaps

2021-08-06 Thread Christian Weisgerber
Damien Miller:

> Just a head-up: snaps currently contain a set of changes[1] to
> make scp(1) use the SFTP protocol by default.

> Please report any incompatibilities or bugs that you encounter here
> (tech@), to bugs@ or to openssh@.

An obvious cosmetic difference is that relative paths are prefixed
with the home directory of the remote source in the progress bar:

$ scp lorvorc:foo /dev/null
/home/naddy/foo   100% 4099 1.6MB/s   00:00
$ scp -O lorvorc:foo /dev/null
foo   100% 4099 3.7MB/s   00:00

I don't know if we care.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: Avoid shifting of a negative value in sys_adjfreq()

2021-05-30 Thread Christian Weisgerber
Visa Hankala:

> However, wouldn't it be better if the code avoided the
> situation, for example by defining ADJFREQ_MIN as the negative
> of ADJFREQ_MAX?

Indeed it would.  ok naddy@

> --- kern/kern_time.c  23 Dec 2020 20:45:02 -  1.151
> +++ kern/kern_time.c  30 May 2021 15:38:09 -
> @@ -396,7 +396,7 @@ sys_settimeofday(struct proc *p, void *v
>  }
>  
>  #define ADJFREQ_MAX (5LL << 32)
> -#define ADJFREQ_MIN (-5LL << 32)
> +#define ADJFREQ_MIN (-ADJFREQ_MAX)
>  
>  int
>  sys_adjfreq(struct proc *p, void *v, register_t *retval)
> 

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: shell manpage tweaks wrt getopt

2021-05-01 Thread Christian Weisgerber
Marc Espie:

> I would also actually be fairly happy if we changed drastically the way
> sh(1) and ksh(1) look. To me, sh(1) should be the (more or less) standard
> shell documentation, AND ksh(1) should contain the differences/extensions.

I think that is a terrible idea.  Historically the tcsh(1) man page
was like this: only document the extensions to csh, point to csh(1)
for the rest.

This only makes sense for people who already fully know the base
man page.  If you don't, you now have to go back and forth between
two man pages to figure out things.

Eventually, the tcsh man page was overhauled and now describes the
whole shell, which was a huge improvement in my book.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: shell manpage tweaks wrt getopt

2021-05-01 Thread Christian Weisgerber
Jason McIntyre:

> - i'm ok with the getopt.1 and ksh.1 parts
> - i'm not ok with the addition to sh.1
> 
> no one has really given a good reason why they think it should go into
> sh.1. i've given a few why i think it should not.

My understanding is that sh.1 is a subset of ksh.1, describing the
POSIX-standardized functionality.  Am I wrong?

ksh.1 has very little in the way of examples, but I think figuring
out the correct getopts idiom is difficult enough to warrant an
example.

The problem is that if I'm trying to write a portable shell script,
I will refer to sh.1.  I will not check ksh.1 for examples.

But since you are the principal author of sh.1, I'm certainly
deferring to your judgment.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



switchd genmap.sh: getopt -> getopts

2021-04-30 Thread Christian Weisgerber
In this auxiliary script, replace the deprecated getopt with getopts.
There is no pressing reason to do so, but let's stop perpetuating
an obsolete idiom.

ok?

Index: usr.sbin/switchd/genmap.sh
===
RCS file: /cvs/src/usr.sbin/switchd/genmap.sh,v
retrieving revision 1.6
diff -u -p -r1.6 genmap.sh
--- usr.sbin/switchd/genmap.sh  18 Nov 2016 16:49:35 -  1.6
+++ usr.sbin/switchd/genmap.sh  30 Apr 2021 20:56:22 -
@@ -21,34 +21,26 @@ INPUT=""
 HEADER=""
 DESCR=0
 
-args=`getopt di:o:h:t:m: $*`
-
-if [ $? -ne 0 ]; then
-   echo "usage: $0 [-d] -i input -h header -t token [-m mapfile]"
-   exit 1
-fi
-
-set -- $args
-while [ $# -ne 0 ]; do
-   case "$1" in
-   -d)
-   DESCR=1; shift;
+while getopts di:h:t:m: name; do
+   case $name in
+   d)
+   DESCR=1
;;
-   -i)
-   INPUT="$2"; shift; shift;
+   i)
+   INPUT=$OPTARG
;;
-   -h)
-   HEADER="$2"; shift; shift;
+   h)
+   HEADER=$OPTARG
;;
-   -t)
-   TOKEN="$2"; shift; shift;
+   t)
+   TOKEN=$OPTARG
;;
-   -m)
-   MAPFILE="$2"; shift; shift;
+   m)
+   MAPFILE=$OPTARG
;;
-   --)
-   shift;
-   break
+   ?)
+   echo "usage: $0 [-d] -i input -h header -t token [-m mapfile]"
+   exit 1
;;
esac
 done
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: shell manpage tweaks wrt getopt

2021-04-30 Thread Christian Weisgerber
Marc Espie:

> Until a patch from naddy, I wasn't even aware of getopts in sh(1)

Let's start the discussion with this instead.

This puts the deprecation notice in getopt.1 in a prominent place,
and uses the same snippet in sh.1 and ksh.1.

Index: bin/ksh/ksh.1
===
RCS file: /cvs/src/bin/ksh/ksh.1,v
retrieving revision 1.214
diff -u -p -r1.214 ksh.1
--- bin/ksh/ksh.1   11 Mar 2021 07:04:12 -  1.214
+++ bin/ksh/ksh.1   30 Apr 2021 14:40:52 -
@@ -3219,6 +3219,25 @@ resetting
 .Ev OPTIND ,
 may lead to unexpected results.
 .Pp
+The following code fragment shows how one might process the arguments
+for a command that can take the option
+.Fl a
+and the option
+.Fl o ,
+which requires an argument.
+.Bd -literal -offset indent
+while getopts ao: name
+do
+   case $name in
+   a)  flag=1 ;;
+   o)  oarg=$OPTARG ;;
+   ?)  echo "Usage: ..."; exit 2 ;;
+   esac
+done
+shift $(($OPTIND - 1))
+echo "Non-option arguments: " "$@"
+.Ed
+.Pp
 .It Xo
 .Ic hash
 .Op Fl r
Index: bin/ksh/sh.1
===
RCS file: /cvs/src/bin/ksh/sh.1,v
retrieving revision 1.152
diff -u -p -r1.152 sh.1
--- bin/ksh/sh.122 May 2019 15:23:23 -  1.152
+++ bin/ksh/sh.130 Apr 2021 14:45:22 -
@@ -508,6 +508,25 @@ is a colon,
 .Ev OPTARG
 is set to the unsupported option,
 otherwise an error message is displayed.
+.Pp
+The following code fragment shows how one might process the arguments
+for a command that can take the option
+.Fl a
+and the option
+.Fl o ,
+which requires an argument.
+.Bd -literal -offset indent
+while getopts ao: name
+do
+   case $name in
+   a)  flag=1 ;;
+   o)  oarg=$OPTARG ;;
+   ?)  echo "Usage: ..."; exit 2 ;;
+   esac
+done
+shift $(($OPTIND - 1))
+echo "Non-option arguments: " "$@"
+.Ed
 .It Ic hash Op Fl r | Ar utility
 Add
 .Ar utility
Index: usr.bin/getopt/getopt.1
===
RCS file: /cvs/src/usr.bin/getopt/getopt.1,v
retrieving revision 1.19
diff -u -p -r1.19 getopt.1
--- usr.bin/getopt/getopt.1 16 Mar 2018 16:58:26 -  1.19
+++ usr.bin/getopt/getopt.1 30 Apr 2021 14:25:17 -
@@ -14,6 +14,13 @@
 .Ar optstring
 .Va $*
 .Sh DESCRIPTION
+The
+.Nm
+utility cannot handle option arguments containing whitespace;
+consider using the standard
+.Ic getopts
+shell built-in instead.
+.Pp
 .Nm
 is used to break up options in command lines for easy parsing by
 shell procedures, and to check for legal options.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: Unlock top part of uvm_fault()

2021-04-24 Thread Christian Weisgerber
Christian Weisgerber:

> > Diff below remove the KERNEL_LOCK()/UNLOCK() dance from uvm_fault() for
> > both amd64 and sparc64.  That means the kernel lock will only be taken
> > for lower faults and some amap/anon code will now run without it.
> 
> I ran an amd64 bulk build with this diff on top of 6.9.

PS: 4 machines, 4 cores each (Xeon CPU E3-1270 v6, HTT disabled)

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: Unlock top part of uvm_fault()

2021-04-23 Thread Christian Weisgerber
Martin Pieuchot:

> Diff below remove the KERNEL_LOCK()/UNLOCK() dance from uvm_fault() for
> both amd64 and sparc64.  That means the kernel lock will only be taken
> for lower faults and some amap/anon code will now run without it.
> 
> I'd be interested to have this tested and see how much does that impact
> the build time of packages.

I ran an amd64 bulk build with this diff on top of 6.9.

That succeeded.  No crashes, no ill effects.
The impact on the build time was neglibible.  From 24 hours 20-something
minutes down to 24 hours 12 minutes (1 sample).

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: quiz: Fix multi-line questions (trailing newline)

2021-03-10 Thread Christian Weisgerber
Todd C. Miller:

> I don't think your use of qlen is safe since it is initialized
> to zero.  Specifically, it looks like "qp->q_text[qlen - 1]"
> would be an out of bounds read.  Should qlen be initialized
> to strlen(qp->q_text) if qp->q_text != NULL?

Right.  Next iteration:

Index: quiz.c
===
RCS file: /cvs/src/games/quiz/quiz.c,v
retrieving revision 1.30
diff -u -p -r1.30 quiz.c
--- quiz.c  24 Aug 2018 11:14:49 -  1.30
+++ quiz.c  10 Mar 2021 20:04:37 -
@@ -48,7 +48,6 @@ static QE qlist;
 static int catone, cattwo, tflag;
 static u_int qsize;
 
-char   *appdstr(char *, const char *, size_t);
 voiddowncase(char *);
 voidget_cats(char *, char *);
 voidget_file(const char *);
@@ -110,7 +109,8 @@ get_file(const char *file)
 {
FILE *fp;
QE *qp;
-   size_t len;
+   ssize_t len;
+   size_t qlen, size;
char *lp;
 
if ((fp = fopen(file, "r")) == NULL)
@@ -123,26 +123,36 @@ get_file(const char *file)
 */
qp = 
qsize = 0;
-   while ((lp = fgetln(fp, )) != NULL) {
+   lp = NULL;
+   size = 0;
+   while ((len = getline(, , fp)) != -1) {
if (lp[len - 1] == '\n')
-   --len;
+   lp[--len] = '\0';
+   if (qp->q_text)
+   qlen = strlen(qp->q_text);
if (qp->q_text && qp->q_text[0] != '\0' &&
-   qp->q_text[strlen(qp->q_text) - 1] == '\\')
-   qp->q_text = appdstr(qp->q_text, lp, len);
-   else {
+   qp->q_text[qlen - 1] == '\\') {
+   qp->q_text[--qlen] = '\0';
+   qlen += len;
+   qp->q_text = realloc(qp->q_text, qlen + 1);
+   if (qp->q_text == NULL)
+   errx(1, "realloc");
+   strlcat(qp->q_text, lp, qlen + 1);
+   } else {
if ((qp->q_next = malloc(sizeof(QE))) == NULL)
errx(1, "malloc");
qp = qp->q_next;
-   if ((qp->q_text = malloc(len + 1)) == NULL)
-   errx(1, "malloc");
-   /* lp may not be zero-terminated; cannot use strlcpy */
-   strncpy(qp->q_text, lp, len);
-   qp->q_text[len] = '\0';
+   qp->q_text = strdup(lp);
+   if (qp->q_text == NULL)
+   errx(1, "strdup");
qp->q_asked = qp->q_answered = FALSE;
qp->q_next = NULL;
++qsize;
}
}
+   free(lp);
+   if (ferror(fp))
+   err(1, "getline");
(void)fclose(fp);
 }
 
@@ -316,32 +326,6 @@ next_cat(const char *s)
esc = 0;
break;
}
-}
-
-char *
-appdstr(char *s, const char *tp, size_t len)
-{
-   char *mp;
-   const char *sp;
-   int ch;
-   char *m;
-
-   if ((m = malloc(strlen(s) + len + 1)) == NULL)
-   errx(1, "malloc");
-   for (mp = m, sp = s; (*mp++ = *sp++) != '\0'; )
-   ;
-   --mp;
-   if (*(mp - 1) == '\\')
-   --mp;
-
-   while ((ch = *mp++ = *tp++) && ch != '\n')
-   ;
-   if (*(mp - 2) == '\\')
-   mp--;
-   *mp = '\0';
-
-   free(s);
-   return (m);
 }
 
 void
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: quiz: Fix multi-line questions (trailing newline)

2021-03-09 Thread Christian Weisgerber
Alex Karle:

> Looking deeper, there is a bug in quiz(6) for datfiles with multi-line
> answers.
> 
> Specifically, the following quiz.db line:
> 
> foo:\
> bar
> 
> Is parsed into "foo:bar\n", which made it impossible to get right (since
> the comparison was expecting a newline). This is a result of a bug in
> quiz.c's appdstr(qp->q_text, lp, len), which copies the trailing newline
> after "bar" (in lp) into q_text.
[...]
> That said, it seemed cleaner to modify the code to use getline(3) over
> fgetln(3), which guarantees each iteration of the loop is a single line
> and null-terminated, enabling the newline truncation in the loop and
> allowing the use of strlcpy(3). This patch implements that fix.
> 
> One can verify the bug(fix) by:
> 
> $ cat < /tmp/qtest
> foo1:bar
> foo2:\\
> bar
> foo3:\\
> ba\\
> r
> EOF
> $ echo "/tmp/qtest:test:lines" > /tmp/qindex
> 
> # answer 'bar' to each question
> $ quiz -i /tmp/qindex test lines # fails
> $ /usr/obj/games/quiz/quiz -i /tmp/qindex test lines # succeeds

Thanks a lot for figuring this out!  I finally got around to looking
at your patch.  Once we have nul-terminated lines, appdstr() can
be replaced with realloc() and strlcat().

This could use another pair of eyes.

OK?

Index: quiz.c
===
RCS file: /cvs/src/games/quiz/quiz.c,v
retrieving revision 1.30
diff -u -p -r1.30 quiz.c
--- quiz.c  24 Aug 2018 11:14:49 -  1.30
+++ quiz.c  9 Mar 2021 20:38:20 -
@@ -48,7 +48,6 @@ static QE qlist;
 static int catone, cattwo, tflag;
 static u_int qsize;
 
-char   *appdstr(char *, const char *, size_t);
 voiddowncase(char *);
 voidget_cats(char *, char *);
 voidget_file(const char *);
@@ -110,7 +109,8 @@ get_file(const char *file)
 {
FILE *fp;
QE *qp;
-   size_t len;
+   ssize_t len;
+   size_t qlen, size;
char *lp;
 
if ((fp = fopen(file, "r")) == NULL)
@@ -123,26 +123,35 @@ get_file(const char *file)
 */
qp = 
qsize = 0;
-   while ((lp = fgetln(fp, )) != NULL) {
+   qlen = 0;
+   lp = NULL;
+   size = 0;
+   while ((len = getline(, , fp)) != -1) {
if (lp[len - 1] == '\n')
-   --len;
+   lp[--len] = '\0';
if (qp->q_text && qp->q_text[0] != '\0' &&
-   qp->q_text[strlen(qp->q_text) - 1] == '\\')
-   qp->q_text = appdstr(qp->q_text, lp, len);
-   else {
+   qp->q_text[qlen - 1] == '\\') {
+   qp->q_text[--qlen] = '\0';
+   qp->q_text = realloc(qp->q_text, qlen + len + 1);
+   if (qp->q_text == NULL)
+   errx(1, "realloc");
+   qlen = strlcat(qp->q_text, lp, qlen + len + 1);
+   } else {
if ((qp->q_next = malloc(sizeof(QE))) == NULL)
errx(1, "malloc");
qp = qp->q_next;
-   if ((qp->q_text = malloc(len + 1)) == NULL)
-   errx(1, "malloc");
-   /* lp may not be zero-terminated; cannot use strlcpy */
-   strncpy(qp->q_text, lp, len);
-   qp->q_text[len] = '\0';
+   qp->q_text = strdup(lp);
+   if (qp->q_text == NULL)
+   errx(1, "strdup");
+   qlen = strlen(qp->q_text);
qp->q_asked = qp->q_answered = FALSE;
qp->q_next = NULL;
++qsize;
}
}
+   free(lp);
+   if (ferror(fp))
+   err(1, "getline");
(void)fclose(fp);
 }
 
@@ -316,32 +325,6 @@ next_cat(const char *s)
esc = 0;
break;
}
-}
-
-char *
-appdstr(char *s, const char *tp, size_t len)
-{
-   char *mp;
-   const char *sp;
-   int ch;
-   char *m;
-
-   if ((m = malloc(strlen(s) + len + 1)) == NULL)
-   errx(1, "malloc");
-   for (mp = m, sp = s; (*mp++ = *sp++) != '\0'; )
-   ;
-   --mp;
-   if (*(mp - 1) == '\\')
-   --mp;
-
-   while ((ch = *mp++ = *tp++) && ch != '\n')
-   ;
-   if (*(mp - 2) == '\\')
-   mp--;
-   *mp = '\0';
-
-   free(s);
-   return (m);
 }
 
 void
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: ftp: make use of getline(3)

2021-02-14 Thread Christian Weisgerber
Christian Weisgerber:

> > Make use of getline(3) in ftp(1).
> > 
> > Replace fparseln(3) with getline(3).  This removes the only use
> > of libutil.a(fparseln.o) from the ramdisk.
> > Replace a complicated fgetln(3) idiom with the much simpler getline(3).
> 
> OK?

ping?

I've been fetching distfiles with it, and I also built a bsd.rd and
performed a http install with it.

Index: distrib/special/ftp/Makefile
===
RCS file: /cvs/src/distrib/special/ftp/Makefile,v
retrieving revision 1.14
diff -u -p -r1.14 Makefile
--- distrib/special/ftp/Makefile16 May 2019 12:44:17 -  1.14
+++ distrib/special/ftp/Makefile29 Jan 2021 18:05:46 -
@@ -6,7 +6,4 @@ PROG=   ftp
 SRCS=  fetch.c ftp.c main.c small.c util.c
 .PATH: ${.CURDIR}/../../../usr.bin/ftp
 
-LDADD+=-lutil
-DPADD+=${LIBUTIL}
-
 .include 
Index: usr.bin/ftp/Makefile
===
RCS file: /cvs/src/usr.bin/ftp/Makefile,v
retrieving revision 1.34
diff -u -p -r1.34 Makefile
--- usr.bin/ftp/Makefile27 Jan 2021 22:27:41 -  1.34
+++ usr.bin/ftp/Makefile29 Jan 2021 17:57:31 -
@@ -8,8 +8,8 @@ PROG=   ftp
 SRCS=  cmds.c cmdtab.c complete.c cookie.c domacro.c fetch.c ftp.c \
list.c main.c ruserpass.c small.c stringlist.c util.c
 
-LDADD+=-ledit -lcurses -lutil -ltls -lssl -lcrypto
-DPADD+=${LIBEDIT} ${LIBCURSES} ${LIBUTIL} ${LIBTLS} ${LIBSSL} 
${LIBCRYPTO}
+LDADD+=-ledit -lcurses -ltls -lssl -lcrypto
+DPADD+=${LIBEDIT} ${LIBCURSES} ${LIBTLS} ${LIBSSL} ${LIBCRYPTO}
 
 #COPTS+= -Wall -Wconversion -Wstrict-prototypes -Wmissing-prototypes
 
Index: usr.bin/ftp/cookie.c
===
RCS file: /cvs/src/usr.bin/ftp/cookie.c,v
retrieving revision 1.9
diff -u -p -r1.9 cookie.c
--- usr.bin/ftp/cookie.c16 May 2019 12:44:17 -  1.9
+++ usr.bin/ftp/cookie.c6 Feb 2021 16:23:32 -
@@ -58,10 +58,10 @@ void
 cookie_load(void)
 {
field_t  field;
-   size_t   len;
time_t   date;
char*line;
-   char*lbuf;
+   char*lbuf = NULL;
+   size_t   lbufsize = 0;
char*param;
const char  *estr;
FILE*fp;
@@ -75,19 +75,9 @@ cookie_load(void)
if (fp == NULL)
err(1, "cannot open cookie file %s", cookiefile);
date = time(NULL);
-   lbuf = NULL;
-   while ((line = fgetln(fp, )) != NULL) {
-   if (line[len - 1] == '\n') {
-   line[len - 1] = '\0';
-   --len;
-   } else {
-   if ((lbuf = malloc(len + 1)) == NULL)
-   err(1, NULL);
-   memcpy(lbuf, line, len);
-   lbuf[len] = '\0';
-   line = lbuf;
-   }
-   line[strcspn(line, "\r")] = '\0';
+   while (getline(, , fp) != -1) {
+   line = lbuf;
+   line[strcspn(line, "\r\n")] = '\0';
 
line += strspn(line, " \t");
if ((*line == '#') || (*line == '\0')) {
Index: usr.bin/ftp/fetch.c
===
RCS file: /cvs/src/usr.bin/ftp/fetch.c,v
retrieving revision 1.200
diff -u -p -r1.200 fetch.c
--- usr.bin/ftp/fetch.c 2 Feb 2021 12:58:42 -   1.200
+++ usr.bin/ftp/fetch.c 2 Feb 2021 13:59:09 -
@@ -56,7 +56,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
@@ -76,7 +75,6 @@ static void   aborthttp(int);
 static charhextochar(const char *);
 static char*urldecode(const char *);
 static char*recode_credentials(const char *_userinfo);
-static char*ftp_readline(FILE *, size_t *);
 static voidftp_close(FILE **, struct tls **, int *);
 static const char *sockerror(struct tls *);
 #ifdef SMALL
@@ -330,6 +328,7 @@ url_get(const char *origline, const char
off_t hashbytes;
const char *errstr;
ssize_t len, wlen;
+   size_t bufsize;
char *proxyhost = NULL;
 #ifndef NOSSL
char *sslpath = NULL, *sslhost = NULL;
@@ -805,12 +804,13 @@ noslash:
free(buf);
 #endif /* !NOSSL */
buf = NULL;
+   bufsize = 0;
 
if (fflush(fin) == EOF) {
warnx("Writing HTTP request: %s", sockerror(tls));
goto cleanup_url_get;
}
-   if ((buf = ftp_readline(fin, )) == NULL) {
+   if ((len = getline(, , fin)) == -1) {
warnx("Receiving HTTP reply: %s", sockerror(tls));
goto cleanup_url_get;
}
@@ -885,11 +885,10 @@ noslash:
/*
 * Read the rest of the header.
 */
-   fr

Re: ftp: make use of getline(3)

2021-02-06 Thread Christian Weisgerber
Christian Weisgerber:

> Make use of getline(3) in ftp(1).
> 
> Replace fparseln(3) with getline(3).  This removes the only use
> of libutil.a(fparseln.o) from the ramdisk.
> Replace a complicated fgetln(3) idiom with the much simpler getline(3).

New diff that fixes a bug I introduced in cookie loading.

OK?

Index: distrib/special/ftp/Makefile
===
RCS file: /cvs/src/distrib/special/ftp/Makefile,v
retrieving revision 1.14
diff -u -p -r1.14 Makefile
--- distrib/special/ftp/Makefile16 May 2019 12:44:17 -  1.14
+++ distrib/special/ftp/Makefile29 Jan 2021 18:05:46 -
@@ -6,7 +6,4 @@ PROG=   ftp
 SRCS=  fetch.c ftp.c main.c small.c util.c
 .PATH: ${.CURDIR}/../../../usr.bin/ftp
 
-LDADD+=-lutil
-DPADD+=${LIBUTIL}
-
 .include 
Index: usr.bin/ftp/Makefile
===
RCS file: /cvs/src/usr.bin/ftp/Makefile,v
retrieving revision 1.34
diff -u -p -r1.34 Makefile
--- usr.bin/ftp/Makefile27 Jan 2021 22:27:41 -  1.34
+++ usr.bin/ftp/Makefile29 Jan 2021 17:57:31 -
@@ -8,8 +8,8 @@ PROG=   ftp
 SRCS=  cmds.c cmdtab.c complete.c cookie.c domacro.c fetch.c ftp.c \
list.c main.c ruserpass.c small.c stringlist.c util.c
 
-LDADD+=-ledit -lcurses -lutil -ltls -lssl -lcrypto
-DPADD+=${LIBEDIT} ${LIBCURSES} ${LIBUTIL} ${LIBTLS} ${LIBSSL} 
${LIBCRYPTO}
+LDADD+=-ledit -lcurses -ltls -lssl -lcrypto
+DPADD+=${LIBEDIT} ${LIBCURSES} ${LIBTLS} ${LIBSSL} ${LIBCRYPTO}
 
 #COPTS+= -Wall -Wconversion -Wstrict-prototypes -Wmissing-prototypes
 
Index: usr.bin/ftp/cookie.c
===
RCS file: /cvs/src/usr.bin/ftp/cookie.c,v
retrieving revision 1.9
diff -u -p -r1.9 cookie.c
--- usr.bin/ftp/cookie.c16 May 2019 12:44:17 -  1.9
+++ usr.bin/ftp/cookie.c6 Feb 2021 16:23:32 -
@@ -58,10 +58,10 @@ void
 cookie_load(void)
 {
field_t  field;
-   size_t   len;
time_t   date;
char*line;
-   char*lbuf;
+   char*lbuf = NULL;
+   size_t   lbufsize = 0;
char*param;
const char  *estr;
FILE*fp;
@@ -75,19 +75,9 @@ cookie_load(void)
if (fp == NULL)
err(1, "cannot open cookie file %s", cookiefile);
date = time(NULL);
-   lbuf = NULL;
-   while ((line = fgetln(fp, )) != NULL) {
-   if (line[len - 1] == '\n') {
-   line[len - 1] = '\0';
-   --len;
-   } else {
-   if ((lbuf = malloc(len + 1)) == NULL)
-   err(1, NULL);
-   memcpy(lbuf, line, len);
-   lbuf[len] = '\0';
-   line = lbuf;
-   }
-   line[strcspn(line, "\r")] = '\0';
+   while (getline(, , fp) != -1) {
+   line = lbuf;
+   line[strcspn(line, "\r\n")] = '\0';
 
line += strspn(line, " \t");
if ((*line == '#') || (*line == '\0')) {
Index: usr.bin/ftp/fetch.c
===
RCS file: /cvs/src/usr.bin/ftp/fetch.c,v
retrieving revision 1.200
diff -u -p -r1.200 fetch.c
--- usr.bin/ftp/fetch.c 2 Feb 2021 12:58:42 -   1.200
+++ usr.bin/ftp/fetch.c 2 Feb 2021 13:59:09 -
@@ -56,7 +56,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 
@@ -76,7 +75,6 @@ static void   aborthttp(int);
 static charhextochar(const char *);
 static char*urldecode(const char *);
 static char*recode_credentials(const char *_userinfo);
-static char*ftp_readline(FILE *, size_t *);
 static voidftp_close(FILE **, struct tls **, int *);
 static const char *sockerror(struct tls *);
 #ifdef SMALL
@@ -330,6 +328,7 @@ url_get(const char *origline, const char
off_t hashbytes;
const char *errstr;
ssize_t len, wlen;
+   size_t bufsize;
char *proxyhost = NULL;
 #ifndef NOSSL
char *sslpath = NULL, *sslhost = NULL;
@@ -805,12 +804,13 @@ noslash:
free(buf);
 #endif /* !NOSSL */
buf = NULL;
+   bufsize = 0;
 
if (fflush(fin) == EOF) {
warnx("Writing HTTP request: %s", sockerror(tls));
goto cleanup_url_get;
}
-   if ((buf = ftp_readline(fin, )) == NULL) {
+   if ((len = getline(, , fin)) == -1) {
warnx("Receiving HTTP reply: %s", sockerror(tls));
goto cleanup_url_get;
}
@@ -885,11 +885,10 @@ noslash:
/*
 * Read the rest of the header.
 */
-   free(buf);
filesize = -1;
 
for (;;) {
-   if ((buf = ftp_rea

disklabel: make use of getline(3)

2021-01-31 Thread Christian Weisgerber
Replace fgetln(3) with getline(3).

Since getline() returns a C string, we don't need to carry around
the length separately.

OK?

Index: sbin/disklabel/editor.c
===
RCS file: /cvs/src/sbin/disklabel/editor.c,v
retrieving revision 1.364
diff -u -p -r1.364 editor.c
--- sbin/disklabel/editor.c 31 Jan 2021 14:18:44 -  1.364
+++ sbin/disklabel/editor.c 31 Jan 2021 14:35:03 -
@@ -172,7 +172,7 @@ voidzero_partitions(struct disklabel *)
 u_int64_t max_partition_size(struct disklabel *, int);
 void   display_edit(struct disklabel *, char);
 void   psize(u_int64_t sz, char unit, struct disklabel *lp);
-char   *get_token(char **, size_t *);
+char   *get_token(char **);
 intapply_unit(double, u_char, u_int64_t *);
 intparse_sizespec(const char *, double *, char **);
 intparse_sizerange(char *, u_int64_t *, u_int64_t *);
@@ -2331,8 +2331,8 @@ void
 parse_autotable(char *filename)
 {
FILE*cfile;
-   size_t   len;
-   char*buf, *t;
+   size_t   bufsize = 0;
+   char*buf = NULL, *t;
uint idx = 0, pctsum = 0;
struct space_allocation *sa;
 
@@ -2342,7 +2342,7 @@ parse_autotable(char *filename)
err(1, NULL);
alloc_table_nitems = 1;
 
-   while ((buf = fgetln(cfile, )) != NULL) {
+   while (getline(, , cfile) != -1) {
if ((alloc_table[0].table = reallocarray(alloc_table[0].table,
idx + 1, sizeof(*sa))) == NULL)
err(1, NULL);
@@ -2350,13 +2350,13 @@ parse_autotable(char *filename)
memset(sa, 0, sizeof(*sa));
idx++;
 
-   if ((sa->mp = get_token(, )) == NULL ||
+   if ((sa->mp = get_token()) == NULL ||
(sa->mp[0] != '/' && strcmp(sa->mp, "swap")))
errx(1, "%s: parse error on line %u", filename, idx);
-   if ((t = get_token(, )) == NULL ||
+   if ((t = get_token()) == NULL ||
parse_sizerange(t, >minsz, >maxsz) == -1)
errx(1, "%s: parse error on line %u", filename, idx);
-   if ((t = get_token(, )) != NULL &&
+   if ((t = get_token()) != NULL &&
parse_pct(t, >rate) == -1)
errx(1, "%s: parse error on line %u", filename, idx);
if (sa->minsz > sa->maxsz)
@@ -2367,29 +2367,27 @@ parse_autotable(char *filename)
if (pctsum > 100)
errx(1, "%s: sum of extra space allocation > 100%%", filename);
alloc_table[0].sz = idx;
+   free(buf);
fclose(cfile);
 }
 
 char *
-get_token(char **s, size_t *len)
+get_token(char **s)
 {
char*p, *r;
size_t   tlen = 0;
 
p = *s;
-   while (*len > 0 && !isspace((u_char)**s)) {
+   while (**s != '\0' && !isspace((u_char)**s)) {
(*s)++;
-   (*len)--;
tlen++;
}
if (tlen == 0)
return (NULL);
 
/* eat whitespace */
-   while (*len > 0 && isspace((u_char)**s)) {
+   while (isspace((u_char)**s))
(*s)++;
-   (*len)--;
-   }
 
if ((r = strndup(p, tlen)) == NULL)
err(1, NULL);
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



fdisk: make use of getline(3)

2021-01-30 Thread Christian Weisgerber
Replace fgetln(3) with getline(3).

OK?

Index: sbin/fdisk/misc.c
===
RCS file: /cvs/src/sbin/fdisk/misc.c,v
retrieving revision 1.63
diff -u -p -r1.63 misc.c
--- sbin/fdisk/misc.c   3 Jul 2019 03:24:01 -   1.63
+++ sbin/fdisk/misc.c   30 Jan 2021 16:48:36 -
@@ -64,20 +64,18 @@ unit_lookup(char *units)
 int
 string_from_line(char *buf, size_t buflen)
 {
-   char *line;
-   size_t sz;
+   static char *line;
+   static size_t sz;
+   ssize_t len;
 
-   line = fgetln(stdin, );
-   if (line == NULL)
+   len = getline(, , stdin);
+   if (len == -1)
return (1);
 
-   if (line[sz - 1] == '\n')
-   sz--;
-   if (sz >= buflen)
-   sz = buflen - 1;
+   if (line[len - 1] == '\n')
+   line[len - 1] = '\0';
 
-   memcpy(buf, line, sz);
-   buf[sz] = '\0';
+   strlcpy(buf, line, buflen);
 
return (0);
 }
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



disklabel: pointer deref fix

2021-01-29 Thread Christian Weisgerber
Fix a pointer dereference in disklabel(8).

This looks like somebody wrote *s[0] in place of (*s)[0].
Which in this case happens to be equivalent, but it still looks
wrong.

OK?

Index: sbin/disklabel/editor.c
===
RCS file: /cvs/src/sbin/disklabel/editor.c,v
retrieving revision 1.363
diff -u -p -U6 -r1.363 editor.c
--- sbin/disklabel/editor.c 19 Nov 2019 06:20:37 -  1.363
+++ sbin/disklabel/editor.c 29 Jan 2021 23:50:24 -
@@ -2374,22 +2374,22 @@ char *
 get_token(char **s, size_t *len)
 {
char*p, *r;
size_t   tlen = 0;
 
p = *s;
-   while (*len > 0 && !isspace((u_char)*s[0])) {
+   while (*len > 0 && !isspace((u_char)**s)) {
(*s)++;
(*len)--;
tlen++;
}
if (tlen == 0)
return (NULL);
 
/* eat whitespace */
-   while (*len > 0 && isspace((u_char)*s[0])) {
+   while (*len > 0 && isspace((u_char)**s)) {
(*s)++;
(*len)--;
}
 
if ((r = strndup(p, tlen)) == NULL)
err(1, NULL);
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



sed: make use of getline(3)

2021-01-29 Thread Christian Weisgerber
Replace fgetln(3) with getline(3) in sed.

The mf_fgets() part is from Johann Oskarsson for Illumos/FreeBSD.

Passes our sed regression tests.

OK?

Index: usr.bin/sed/main.c
===
RCS file: /cvs/src/usr.bin/sed/main.c,v
retrieving revision 1.41
diff -u -p -r1.41 main.c
--- usr.bin/sed/main.c  13 Oct 2020 06:07:54 -  1.41
+++ usr.bin/sed/main.c  29 Jan 2021 23:12:23 -
@@ -252,15 +252,9 @@ again:
goto again;
}
case ST_FILE:
-   if ((p = fgetln(f, )) != NULL) {
+   if (getline(outbuf, outsize, f) != -1) {
+   p = *outbuf;
linenum++;
-   if (len >= *outsize) {
-   free(*outbuf);
-   *outsize = ROUNDLEN(len + 1);
-   *outbuf = xmalloc(*outsize);
-   }
-   memcpy(*outbuf, p, len);
-   (*outbuf)[len] = '\0';
if (linenum == 1 && p[0] == '#' && p[1] == 'n')
nflag = 1;
return (*outbuf);
@@ -344,7 +338,8 @@ mf_fgets(SPACE *sp, enum e_spflag spflag
struct stat sb;
size_t len;
char dirbuf[PATH_MAX];
-   char *p;
+   static char *p;
+   static size_t psize;
int c, fd;
static int firstfile;
 
@@ -429,13 +424,13 @@ mf_fgets(SPACE *sp, enum e_spflag spflag
 * We are here only when infile is open and we still have something
 * to read from it.
 *
-* Use fgetln so that we can handle essentially infinite input data.
-* Can't use the pointer into the stdio buffer as the process space
-* because the ungetc() can cause it to move.
+* Use getline() so that we can handle essentially infinite input
+* data.  The p and psize are static so each invocation gives
+* getline() the same buffer which is expanded as needed.
 */
-   p = fgetln(infile, );
-   if (ferror(infile))
-   error(FATAL, "%s: %s", fname, strerror(errno ? errno : EIO));
+   len = getline(, , infile);
+   if ((ssize_t)len == -1)
+   error(FATAL, "%s: %s", fname, strerror(errno));
if (len != 0 && p[len - 1] == '\n') {
sp->append_newline = 1;
len--;
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: ftp: make use of getline(3)

2021-01-29 Thread Christian Weisgerber
Hiltjo Posthuma:

> > @@ -75,19 +74,8 @@ cookie_load(void)
> > if (fp == NULL)
> > err(1, "cannot open cookie file %s", cookiefile);
> > date = time(NULL);
> > -   lbuf = NULL;
> > -   while ((line = fgetln(fp, )) != NULL) {
> > -   if (line[len - 1] == '\n') {
> > -   line[len - 1] = '\0';
> > -   --len;
> > -   } else {
> > -   if ((lbuf = malloc(len + 1)) == NULL)
> > -   err(1, NULL);
> > -   memcpy(lbuf, line, len);
> > -   lbuf[len] = '\0';
> > -   line = lbuf;
> > -   }
> > -   line[strcspn(line, "\r")] = '\0';
> > +   while (getline(, , fp) != -1) {
> > +   line[strcspn(line, "\r\n")] = '\0';
> >  
> 
> getline returns the number of characters read including the delimeter. This
> size could be used to '\0' terminate the string instead of a strcspn() call.

A strcspn() call is already there.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



ftp: make use of getline(3)

2021-01-29 Thread Christian Weisgerber
Make use of getline(3) in ftp(1).

Replace fparseln(3) with getline(3).  This removes the only use
of libutil.a(fparseln.o) from the ramdisk.
Replace a complicated fgetln(3) idiom with the much simpler getline(3).

OK?

Index: distrib/special/ftp/Makefile
===
RCS file: /cvs/src/distrib/special/ftp/Makefile,v
retrieving revision 1.14
diff -u -p -r1.14 Makefile
--- distrib/special/ftp/Makefile16 May 2019 12:44:17 -  1.14
+++ distrib/special/ftp/Makefile29 Jan 2021 18:05:46 -
@@ -6,7 +6,4 @@ PROG=   ftp
 SRCS=  fetch.c ftp.c main.c small.c util.c
 .PATH: ${.CURDIR}/../../../usr.bin/ftp
 
-LDADD+=-lutil
-DPADD+=${LIBUTIL}
-
 .include 
Index: usr.bin/ftp/Makefile
===
RCS file: /cvs/src/usr.bin/ftp/Makefile,v
retrieving revision 1.34
diff -u -p -r1.34 Makefile
--- usr.bin/ftp/Makefile27 Jan 2021 22:27:41 -  1.34
+++ usr.bin/ftp/Makefile29 Jan 2021 17:57:31 -
@@ -8,8 +8,8 @@ PROG=   ftp
 SRCS=  cmds.c cmdtab.c complete.c cookie.c domacro.c fetch.c ftp.c \
list.c main.c ruserpass.c small.c stringlist.c util.c
 
-LDADD+=-ledit -lcurses -lutil -ltls -lssl -lcrypto
-DPADD+=${LIBEDIT} ${LIBCURSES} ${LIBUTIL} ${LIBTLS} ${LIBSSL} 
${LIBCRYPTO}
+LDADD+=-ledit -lcurses -ltls -lssl -lcrypto
+DPADD+=${LIBEDIT} ${LIBCURSES} ${LIBTLS} ${LIBSSL} ${LIBCRYPTO}
 
 #COPTS+= -Wall -Wconversion -Wstrict-prototypes -Wmissing-prototypes
 
Index: usr.bin/ftp/cookie.c
===
RCS file: /cvs/src/usr.bin/ftp/cookie.c,v
retrieving revision 1.9
diff -u -p -r1.9 cookie.c
--- usr.bin/ftp/cookie.c16 May 2019 12:44:17 -  1.9
+++ usr.bin/ftp/cookie.c29 Jan 2021 16:07:56 -
@@ -58,10 +58,9 @@ void
 cookie_load(void)
 {
field_t  field;
-   size_t   len;
time_t   date;
-   char*line;
-   char*lbuf;
+   char*line = NULL;
+   size_t   linesize = 0;
char*param;
const char  *estr;
FILE*fp;
@@ -75,19 +74,8 @@ cookie_load(void)
if (fp == NULL)
err(1, "cannot open cookie file %s", cookiefile);
date = time(NULL);
-   lbuf = NULL;
-   while ((line = fgetln(fp, )) != NULL) {
-   if (line[len - 1] == '\n') {
-   line[len - 1] = '\0';
-   --len;
-   } else {
-   if ((lbuf = malloc(len + 1)) == NULL)
-   err(1, NULL);
-   memcpy(lbuf, line, len);
-   lbuf[len] = '\0';
-   line = lbuf;
-   }
-   line[strcspn(line, "\r")] = '\0';
+   while (getline(, , fp) != -1) {
+   line[strcspn(line, "\r\n")] = '\0';
 
line += strspn(line, " \t");
if ((*line == '#') || (*line == '\0')) {
@@ -172,7 +160,7 @@ cookie_load(void)
} else
TAILQ_INSERT_TAIL(, ck, entry);
}
-   free(lbuf);
+   free(line);
fclose(fp);
 }
 
Index: usr.bin/ftp/fetch.c
===
RCS file: /cvs/src/usr.bin/ftp/fetch.c,v
retrieving revision 1.199
diff -u -p -r1.199 fetch.c
--- usr.bin/ftp/fetch.c 1 Jan 2021 17:39:54 -   1.199
+++ usr.bin/ftp/fetch.c 29 Jan 2021 17:57:58 -
@@ -56,7 +56,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #ifndef NOSSL
@@ -75,7 +74,6 @@ static void   aborthttp(int);
 static charhextochar(const char *);
 static char*urldecode(const char *);
 static char*recode_credentials(const char *_userinfo);
-static char*ftp_readline(FILE *, size_t *);
 static voidftp_close(FILE **, struct tls **, int *);
 static const char *sockerror(struct tls *);
 #ifdef SMALL
@@ -329,6 +327,7 @@ url_get(const char *origline, const char
off_t hashbytes;
const char *errstr;
ssize_t len, wlen;
+   size_t bufsize;
char *proxyhost = NULL;
 #ifndef NOSSL
char *sslpath = NULL, *sslhost = NULL;
@@ -790,12 +789,13 @@ noslash:
free(buf);
 #endif /* !NOSSL */
buf = NULL;
+   bufsize = 0;
 
if (fflush(fin) == EOF) {
warnx("Writing HTTP request: %s", sockerror(tls));
goto cleanup_url_get;
}
-   if ((buf = ftp_readline(fin, )) == NULL) {
+   if ((len = getline(, , fin)) == -1) {
warnx("Receiving HTTP reply: %s", sockerror(tls));
goto cleanup_url_get;
}
@@ -867,11 +867,10 @@ noslash:
/*
 * Read the rest of the header.
 */
-   free(buf);
filesize = -1;
 
for (;;) {
-   if ((buf = 

Re: getopt.3 bugs section

2021-01-09 Thread Christian Weisgerber
Edgar Pettijohn:

> In the BUGS section for the getopt(3) manual it mentions not using
> single digits for options. I know spamd uses -4 and -6 there are
> probably others. Should they be changed? Or is the manual mistaken?

You misunderstand.  The manual warns against the use of digits to
pass numerical arguments.  This usage exists in some historical
cases, e.g. "nice -10" where <10> is the number 10.

The use of digits as flags characters, like -4 or -6 to indicate
IPv4 or IPv6, is perfectly fine.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: Rename SIMPLEQ_ to STAILQ_, diff 1/7

2020-12-28 Thread Christian Weisgerber
Denis Fondras:

> This diff renames SIMPLEQ_* to STAILQ_* in /usr/src/sys/sys to unify with 
> FreeBSD and Linux.
> 
> I added aliases at the end of queue.h to avoid breaking base too much. they 
> will
> be removed as soon as diff 2,3,4,5,6,7 are commited.
> 
> net/sniproxy has a patch to define STAILQ_*, it may be removed later.

I applied diffs 1 and 2 and did a "make includes" to ensure that
_all_ header files were switched over to STAILQ.  I then ran a
package bulk build on amd64.

There were seven build failures.  Except for sniproxy those are all
programs developed on OpenBSD that use SIMPLEQ:

audio/morseplayer
devel/got
mail/pop3d
net/adsuck
net/oicb
net/sniproxy
x11/spectrwm

sniproxy breaks because the renamed s/SIMPLEQ/STAILQ/ macros lack
STAILQ_REMOVE().

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: Rename SIMPLEQ_ to STAILQ_, diff 1/7

2020-12-26 Thread Christian Weisgerber
Theo de Raadt:

> What is lacking in this converstation is the justification.
> Why?

Providing STAILQ in OpenBSD will simplify porting to OpenBSD.
(Reality check: There is one port affected by this.)

Switching OpenBSD to STAILQ will simplify porting from OpenBSD.
(There are three or four FreeBSD ports affected by this.)

Having both SIMPLEQ and STAILQ will cause no disruption, but means
providing two APIs that are identical except for their name.

This appears to be a post-Berkeley divergence; 4.4BSD has neither
in .

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: Rename SIMPLEQ_ to STAILQ_, diff 1/7

2020-12-26 Thread Christian Weisgerber
Denis Fondras:

> This diff renames SIMPLEQ_* to STAILQ_* in /usr/src/sys/sys to unify with 
> FreeBSD and Linux.
> 
> I added aliases at the end of queue.h to avoid breaking base too much. they 
> will
> be removed as soon as diff 2,3,4,5,6,7 are commited.

We'll need to run a ports bulk build without the aliases.  (I can
do that.) There will be some breakage.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



libcurses: --enable-const

2020-12-12 Thread Christian Weisgerber
ncurses has a configure option that adds a few more consts to its
headers by way of the NCURSES_CONST define.  Starting with version
6.0, this has become the default.  OpenBSD is still on ncurses 5.7,
but FreeBSD and I guess most Linux distributions have moved on.
I suggest we also enable the additional consts.  This eliminates
compiler warnings when sharing code with other platforms.

The diff below has successfully gone through a release build on
amd64, as well as a full amd64 package build.

OK?

Index: lib/libcurses/curses.h
===
RCS file: /cvs/src/lib/libcurses/curses.h,v
retrieving revision 1.61
diff -u -p -r1.61 curses.h
--- lib/libcurses/curses.h  6 Sep 2010 17:26:17 -   1.61
+++ lib/libcurses/curses.h  9 Dec 2020 22:56:31 -
@@ -101,7 +101,7 @@
  * doing so makes it incompatible with other implementations of X/Open Curses.
  */
 #undef  NCURSES_CONST
-#define NCURSES_CONST /*nothing*/
+#define NCURSES_CONST const
 
 #undef NCURSES_INLINE
 #define NCURSES_INLINE inline
Index: lib/libcurses/term.h
===
RCS file: /cvs/src/lib/libcurses/term.h,v
retrieving revision 1.15
diff -u -p -r1.15 term.h
--- lib/libcurses/term.h14 Nov 2015 23:56:49 -  1.15
+++ lib/libcurses/term.h9 Dec 2020 23:03:46 -
@@ -68,7 +68,7 @@ extern "C" {
  */
 
 #undef  NCURSES_CONST
-#define NCURSES_CONST /*nothing*/
+#define NCURSES_CONST const
 
 #undef  NCURSES_SBOOL
 #define NCURSES_SBOOL signed char
Index: lib/libcurses/termcap.h
===
RCS file: /cvs/src/lib/libcurses/termcap.h,v
retrieving revision 1.10
diff -u -p -r1.10 termcap.h
--- lib/libcurses/termcap.h 10 Dec 2013 20:33:51 -  1.10
+++ lib/libcurses/termcap.h 9 Dec 2020 23:03:54 -
@@ -62,7 +62,7 @@ extern "C"
 #include 
 
 #undef  NCURSES_CONST 
-#define NCURSES_CONST /*nothing*/ 
+#define NCURSES_CONST const
 
 #undef  NCURSES_OSPEED 
 #define NCURSES_OSPEED int 
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: rpki-client: use strndup instead of malloc + memcpy

2020-12-03 Thread Christian Weisgerber
Claudio Jeker:

> In tal_parse() use strndup() to create the tal descr instead of the more
> complex malloc, memcpy version. Result is the same but the strndup version
> is a lot nicer.

Yes, but...

> --- tal.c 11 Oct 2020 12:39:25 -  1.22
> +++ tal.c 3 Dec 2020 12:00:25 -
> @@ -198,10 +198,8 @@ tal_parse(const char *fn, char *buf)
>   dlen = strlen(d);
>   if (strcasecmp(d + dlen - 4, ".tal") == 0)
>   dlen -= 4;

That looks like a potential out-of-bounds access.  Are we guaranteed
that dlen >= 4 here?

> - if ((p->descr = malloc(dlen + 1)) == NULL)
> + if ((p->descr = strndup(d, dlen)) == NULL)
>   err(1, NULL);
> - memcpy(p->descr, d, dlen);
> - p->descr[dlen] = '\0';
>  
>   return p;
>  }

ok

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: powerpc lld fix

2020-11-15 Thread Christian Weisgerber
Mark Kettenis:

> What would the impact on ports of disabling base-gcc be on powerpc?

None.

$ cd /usr/ports
$ make ARCH=macppc MACHINE_ARCH=powerpc show=CHOSEN_COMPILER |grep -B1 base-gcc
$ 

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



basename(3) should have non-const arg, says POSIX

2020-10-19 Thread Christian Weisgerber
[Picking this up again after a month:]

Our basename(3) and dirname(3) take a const argument:

  char*basename(const char *);
  char*dirname(const char *);

POSIX says otherwise...

  char *basename(char *path);
  char *dirname(char *path);

... and explicitly says the functions may modify the input string.


Our functions were const-ified in 1999 by espie@:

  proper const semantics for dirname & basename.
  (this follows FreeBSD and Linux. Single Unix 2 is still illogical)

Well, four years ago, FreeBSD finally switched to the POSIX prototypes
https://svnweb.freebsd.org/base/head/include/libgen.h?revision=303451=markup
and in fact now has an implementation that modifies the string.

Linux (GNU libc) has a bizarro solution where you get a const basename()
and no dirname() if you just include , but POSIX basename()
and dirname() if you instead or also include .

This is a portability trap.  Code written on OpenBSD may not be
prepared for basename() or dirname() to splat a '\0' into the input
string, despite the warning in the man page.  This is not hypothetical.
Both Got and OpenCVS have fallen victim to the unportable assumption.


The patch below aligns the function prototypes with POSIX.  All
resulting warnings "passing 'const char *' to parameter of type
'char *' discards qualifiers" in the base system have been cleaned
up.  It successfully passes "make release".  For good measure I'm
also running a package bulk build with it as we speak.

OK?


Index: include/libgen.h
===
RCS file: /cvs/src/include/libgen.h,v
retrieving revision 1.9
diff -u -p -r1.9 libgen.h
--- include/libgen.h25 Jan 2019 00:19:25 -  1.9
+++ include/libgen.h11 Sep 2020 20:41:34 -
@@ -22,8 +22,8 @@
 #include 
 
 __BEGIN_DECLS
-char   *basename(const char *);
-char   *dirname(const char *);
+char   *basename(char *);
+char   *dirname(char *);
 __END_DECLS
 
 #endif /* _LIBGEN_H_ */
Index: lib/libc/gen/basename.3
===
RCS file: /cvs/src/lib/libc/gen/basename.3,v
retrieving revision 1.24
diff -u -p -r1.24 basename.3
--- lib/libc/gen/basename.3 25 Jan 2019 00:19:25 -  1.24
+++ lib/libc/gen/basename.3 11 Sep 2020 20:46:30 -
@@ -23,7 +23,7 @@
 .Sh SYNOPSIS
 .In libgen.h
 .Ft char *
-.Fn basename "const char *path"
+.Fn basename "char *path"
 .Sh DESCRIPTION
 The
 .Fn basename
Index: lib/libc/gen/basename.c
===
RCS file: /cvs/src/lib/libc/gen/basename.c,v
retrieving revision 1.16
diff -u -p -r1.16 basename.c
--- lib/libc/gen/basename.c 25 Jan 2019 00:19:25 -  1.16
+++ lib/libc/gen/basename.c 11 Sep 2020 20:43:13 -
@@ -22,7 +22,7 @@
 #include 
 
 char *
-basename(const char *path)
+basename(char *path)
 {
static char bname[PATH_MAX];
size_t len;
Index: lib/libc/gen/dirname.3
===
RCS file: /cvs/src/lib/libc/gen/dirname.3,v
retrieving revision 1.23
diff -u -p -r1.23 dirname.3
--- lib/libc/gen/dirname.3  8 Mar 2019 17:33:23 -   1.23
+++ lib/libc/gen/dirname.3  11 Sep 2020 20:47:08 -
@@ -23,7 +23,7 @@
 .Sh SYNOPSIS
 .In libgen.h
 .Ft char *
-.Fn dirname "const char *path"
+.Fn dirname "char *path"
 .Sh DESCRIPTION
 The
 .Fn dirname
Index: lib/libc/gen/dirname.c
===
RCS file: /cvs/src/lib/libc/gen/dirname.c,v
retrieving revision 1.16
diff -u -p -r1.16 dirname.c
--- lib/libc/gen/dirname.c  25 Jan 2019 00:19:25 -  1.16
+++ lib/libc/gen/dirname.c  11 Sep 2020 20:43:34 -
@@ -24,7 +24,7 @@
 /* A slightly modified copy of this file exists in libexec/ld.so */
 
 char *
-dirname(const char *path)
+dirname(char *path)
 {
static char dname[PATH_MAX];
size_t len;
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



arm64 ddb: decode "udf" instruction

2020-10-19 Thread Christian Weisgerber
This decodes the UDF ("permanently undefined") instruction in ddb's
arm64 disassembler.  The particular immediate16 format appears to
be unique to this instruction.

OK?  Or don't bother?

Index: arch/arm64/arm64/disasm.c
===
RCS file: /cvs/src/sys/arch/arm64/arm64/disasm.c,v
retrieving revision 1.2
diff -u -p -r1.2 disasm.c
--- arch/arm64/arm64/disasm.c   11 Sep 2020 09:27:10 -  1.2
+++ arch/arm64/arm64/disasm.c   19 Oct 2020 16:17:55 -
@@ -3107,6 +3107,11 @@ OP4FUNC(op_tbz, b5, b40, imm14, Rt)
PRINTF("\n");
 }
 
+OP1FUNC(op_udf, imm16)
+{
+   PRINTF("udf\t#0x%"PRIx64"\n", imm16);
+}
+
 OP4FUNC(op_udiv, sf, Rm, Rn, Rd)
 {
PRINTF("udiv\t%s, %s, %s\n",
@@ -3668,6 +3673,8 @@ struct insn_info {
{{ 5,16}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}}
 #define FMT_IMM16_LL   \
{{ 5,16}, { 0, 2}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}}
+#define FMT_IMM16_UDF  \
+   {{ 0,16}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}}
 #define FMT_OP0_OP1_CRN_CRM_OP2_RT \
{{19, 2}, {16, 3}, {12, 4}, { 8, 4}, { 5, 3}, { 0, 5}, { 0, 0}, { 0, 0}}
 #define FMT_IMM7_RT2_RN_RT \
@@ -3786,6 +3793,7 @@ static const struct insn_info insn_table
  { 0xd800, 0xdac1, FMT_Z_M_RN_RD,   op_pacia },
  { 0xcc00, 0x4e284800, FMT_M_D_RN_RD,   op_simd_aes },
  { 0x8c00, 0x5e280800, FMT_OP3_RN_RD,   op_simd_sha_reg2 },
+ { 0x, 0x, FMT_IMM16_UDF,   op_udf },
  { 0xfff8f01f, 0xd500401f, FMT_OP1_CRM_OP2, op_msr_imm },
  { 0xfff8, 0xd508, FMT_OP1_CRN_CRM_OP2_RT,  op_sys },
  { 0xfff8, 0xd528, FMT_OP1_CRN_CRM_OP2_RT,  op_sysl },
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



arm64, armv7: proper illegal instruction

2020-10-19 Thread Christian Weisgerber
Belatedly, ARM has taken a slice of the reserved opcode space and
assigned it as a properly defined illegal instruction, udf #imm16.
(Armv8 Architecture Reference Manual, edition F.c, section C6.2.335).
Clang already knows about it.

We really should use this instead of picking something ad-hoc out
of the opcode space.

I have verified that this builds on arm64, produces a SIGILL in
userland, and drops me into ddb in the kernel.

armv7 has an equivalent instruction.  kettenis@ confirms it builds
and SIGILLs there.

OK?

Index: lib/csu/aarch64/md_init.h
===
RCS file: /cvs/src/lib/csu/aarch64/md_init.h,v
retrieving revision 1.9
diff -u -p -r1.9 md_init.h
--- lib/csu/aarch64/md_init.h   15 Oct 2020 16:30:21 -  1.9
+++ lib/csu/aarch64/md_init.h   19 Oct 2020 11:57:02 -
@@ -115,5 +115,5 @@
"   svc #0  \n" \
"   dsb nsh \n" \
"   isb \n" \
-   "   .word 0xa000f7f0 /* illegal */  \n" \
+   "   udf #0  \n" \
".previous");
Index: lib/csu/arm/md_init.h
===
RCS file: /cvs/src/lib/csu/arm/md_init.h,v
retrieving revision 1.16
diff -u -p -r1.16 md_init.h
--- lib/csu/arm/md_init.h   15 Oct 2020 16:30:23 -  1.16
+++ lib/csu/arm/md_init.h   19 Oct 2020 13:23:00 -
@@ -159,5 +159,5 @@
"   swi #0  \n" \
"   dsb nsh \n" \
"   isb \n" \
-   "   .word 0xa000f7f0 /* illegal */  \n" \
+   "   udf #0  \n" \
".previous");
Index: lib/libc/arch/aarch64/sys/tfork_thread.S
===
RCS file: /cvs/src/lib/libc/arch/aarch64/sys/tfork_thread.S,v
retrieving revision 1.5
diff -u -p -r1.5 tfork_thread.S
--- lib/libc/arch/aarch64/sys/tfork_thread.S18 Oct 2020 14:28:16 -  
1.5
+++ lib/libc/arch/aarch64/sys/tfork_thread.S19 Oct 2020 11:59:32 -
@@ -43,6 +43,6 @@ ENTRY(__tfork_thread)
mov x0, x3
blr x2
SYSTRAP(__threxit)
-   .word   0xa000f7f0  /* illegal on all cpus? */
+   udf #0
.cfi_endproc
 END(__tfork_thread)
Index: lib/libc/arch/arm/sys/tfork_thread.S
===
RCS file: /cvs/src/lib/libc/arch/arm/sys/tfork_thread.S,v
retrieving revision 1.5
diff -u -p -r1.5 tfork_thread.S
--- lib/libc/arch/arm/sys/tfork_thread.S18 Oct 2020 14:28:17 -  
1.5
+++ lib/libc/arch/arm/sys/tfork_thread.S19 Oct 2020 13:23:35 -
@@ -37,5 +37,5 @@ ENTRY(__tfork_thread)
mov pc, r2
nop
SYSTRAP(__threxit)
-   .word   0xa000f7f0  /* illegal on all cpus? */
+   udf #0
 END(__tfork_thread)
Index: sys/arch/arm/arm/sigcode.S
===
RCS file: /cvs/src/sys/arch/arm/arm/sigcode.S,v
retrieving revision 1.9
diff -u -p -r1.9 sigcode.S
--- sys/arch/arm/arm/sigcode.S  13 Mar 2020 08:46:50 -  1.9
+++ sys/arch/arm/arm/sigcode.S  19 Oct 2020 13:23:55 -
@@ -72,7 +72,7 @@ _C_LABEL(esigcode):
 
.globl  sigfill
 sigfill:
-   .word   0xa000f7f0  /* illegal on all cpus? */
+   udf #0
 esigfill:
 
.data
Index: sys/arch/arm64/arm64/locore.S
===
RCS file: /cvs/src/sys/arch/arm64/arm64/locore.S,v
retrieving revision 1.31
diff -u -p -r1.31 locore.S
--- sys/arch/arm64/arm64/locore.S   13 Mar 2020 00:14:38 -  1.31
+++ sys/arch/arm64/arm64/locore.S   19 Oct 2020 12:02:23 -
@@ -366,7 +366,7 @@ _C_LABEL(esigcode):
 
.globl  sigfill
 sigfill:
-   .word   0xa000f7f0  /* FIXME: illegal on all cpus? */
+   udf #0
 esigfill:
 
.data
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Non-const basename: usr.bin/cvs

2020-10-16 Thread Christian Weisgerber
Accommodate POSIX basename(3) that takes a non-const parameter and
may modify the string buffer.

There were only two compiler warnings about discarded const, but
there are numerous instances where the code assumes non-POSIX
semantics for basename() and dirname().  Given that there is at
least a FreeBSD port of OpenCVS, cleaning this up is more than
cosmetic.

This could definitely use proofreading.

I chose __func__ (otherwise not used anywhere) over breaking an overly
long "function_" "name" into parts like that.

OK?

Index: usr.bin/cvs/admin.c
===
RCS file: /cvs/src/usr.bin/cvs/admin.c,v
retrieving revision 1.68
diff -u -p -r1.68 admin.c
--- usr.bin/cvs/admin.c 1 Jun 2017 08:08:24 -   1.68
+++ usr.bin/cvs/admin.c 16 Oct 2020 21:14:05 -
@@ -246,12 +246,17 @@ cvs_admin_local(struct cvs_file *cf)
struct cvs_file *ocf;
struct rcs_access *acp;
int ofd;
-   char *d, *f, fpath[PATH_MAX], repo[PATH_MAX];
+   char *d, dbuf[PATH_MAX], *f, fbuf[PATH_MAX];
+   char fpath[PATH_MAX], repo[PATH_MAX];
 
-
-   if ((f = basename(oldfilename)) == NULL)
+   if (strlcpy(fbuf, oldfilename, sizeof(fbuf)) >= sizeof(fbuf))
+   fatal("cvs_admin_local: truncation");
+   if ((f = basename(fbuf)) == NULL)
fatal("cvs_admin_local: basename failed");
-   if ((d = dirname(oldfilename)) == NULL)
+
+   if (strlcpy(dbuf, oldfilename, sizeof(dbuf)) >= sizeof(dbuf))
+   fatal("cvs_admin_local: truncation");
+   if ((d = dirname(dbuf)) == NULL)
fatal("cvs_admin_local: dirname failed");
 
cvs_get_repository_path(d, repo, PATH_MAX);
Index: usr.bin/cvs/checkout.c
===
RCS file: /cvs/src/usr.bin/cvs/checkout.c,v
retrieving revision 1.171
diff -u -p -r1.171 checkout.c
--- usr.bin/cvs/checkout.c  1 Jun 2017 08:08:24 -   1.171
+++ usr.bin/cvs/checkout.c  16 Oct 2020 21:46:33 -
@@ -239,7 +239,7 @@ checkout_check_repository(int argc, char
struct module_checkout *mc;
struct cvs_ignpat *ip;
struct cvs_filelist *fl, *nxt;
-   char repo[PATH_MAX], fpath[PATH_MAX], *f[1];
+   char repo[PATH_MAX], fpath[PATH_MAX], path[PATH_MAX], *f[1];
 
build_dirs = print_stdout ? 0 : 1;
 
@@ -329,14 +329,25 @@ checkout_check_repository(int argc, char
cr.flags = flags;
 
if (!(mc->mc_flags & MODULE_ALIAS)) {
+   if (strlcpy(path, fl->file_path,
+   sizeof(path)) >= sizeof(path))
+   fatal("%s: truncation",
+   __func__);
module_repo_root =
-   xstrdup(dirname(fl->file_path));
+   xstrdup(dirname(path));
d = wdir;
+   if (strlcpy(path, fl->file_path,
+   sizeof(path)) >= sizeof(path))
+   fatal("%s: truncation",
+   __func__);
(void)xsnprintf(fpath, sizeof(fpath),
-   "%s/%s", d,
-   basename(fl->file_path));
+   "%s/%s", d, basename(path));
} else {
-   d = dirname(wdir);
+   if (strlcpy(path, wdir,
+   sizeof(path)) >= sizeof(path))
+   fatal("%s: truncation",
+   __func__);
+   d = dirname(path);
strlcpy(fpath, fl->file_path,
sizeof(fpath));
}
@@ -387,7 +398,7 @@ checkout_check_repository(int argc, char
 static int
 checkout_classify(const char *repo, const char *arg)
 {
-   char *d, *f, fpath[PATH_MAX];
+   char *d, dbuf[PATH_MAX], *f, fbuf[PATH_MAX], fpath[PATH_MAX];
struct stat sb;
 
if (stat(repo, ) == 0) {
@@ -395,8 +406,13 @@ checkout_classify(const char *repo, cons
return CVS_DIR;
}
 
-   d = dirname(repo);
-   f = basename(repo);
+   if (strlcpy(dbuf, repo, sizeof(dbuf)) >= sizeof(dbuf))
+   fatal("checkout_classify: truncation");
+   d = 

Non-const basename: usr.bin/ftp

2020-10-15 Thread Christian Weisgerber
Accommodate POSIX basename(3) that takes a non-const parameter and
may modify the string buffer.

I've tried to follow the conventions of the existing code.

ok?

Index: usr.bin/ftp/fetch.c
===
RCS file: /cvs/src/usr.bin/ftp/fetch.c,v
retrieving revision 1.197
diff -u -p -r1.197 fetch.c
--- usr.bin/ftp/fetch.c 4 Jul 2020 11:23:35 -   1.197
+++ usr.bin/ftp/fetch.c 15 Oct 2020 21:14:28 -
@@ -192,7 +192,7 @@ file_get(const char *path, const char *o
int  fd, out = -1, rval = -1, save_errno;
volatile sig_t   oldintr, oldinti;
const char  *savefile;
-   char*buf = NULL, *cp;
+   char*buf = NULL, *cp, *pathbuf = NULL;
const size_t buflen = 128 * 1024;
off_thashbytes;
ssize_t  len, wlen;
@@ -215,8 +215,12 @@ file_get(const char *path, const char *o
else {
if (path[strlen(path) - 1] == '/')  /* Consider no file */
savefile = NULL;/* after dir invalid. */
-   else
-   savefile = basename(path);
+   else {
+   pathbuf = strdup(path);
+   if (pathbuf == NULL)
+   errx(1, "Can't allocate memory for filename");
+   savefile = basename(pathbuf);
+   }
}
 
if (EMPTYSTRING(savefile)) {
@@ -294,6 +298,7 @@ file_get(const char *path, const char *o
 
 cleanup_copy:
free(buf);
+   free(pathbuf);
if (out >= 0 && out != fileno(stdout))
close(out);
close(fd);
@@ -315,6 +320,7 @@ url_get(const char *origline, const char
int isunavail = 0, retryafter = -1;
struct addrinfo hints, *res0, *res;
const char *savefile;
+   char *pathbuf = NULL;
char *proxyurl = NULL;
char *credentials = NULL, *proxy_credentials = NULL;
int fd = -1, out = -1;
@@ -412,8 +418,12 @@ noslash:
else {
if (path[strlen(path) - 1] == '/')  /* Consider no file */
savefile = NULL;/* after dir invalid. */
-   else
-   savefile = basename(path);
+   else {
+   pathbuf = strdup(path);
+   if (pathbuf == NULL)
+   errx(1, "Can't allocate memory for filename");
+   savefile = basename(pathbuf);
+   }
}
 
if (EMPTYSTRING(savefile)) {
@@ -1106,6 +1116,7 @@ cleanup_url_get:
if (out >= 0 && out != fileno(stdout))
close(out);
free(buf);
+   free(pathbuf);
free(proxyhost);
free(proxyurl);
free(newline);
Index: usr.bin/ftp/util.c
===
RCS file: /cvs/src/usr.bin/ftp/util.c,v
retrieving revision 1.93
diff -u -p -r1.93 util.c
--- usr.bin/ftp/util.c  6 Jul 2020 17:11:29 -   1.93
+++ usr.bin/ftp/util.c  15 Oct 2020 21:31:55 -
@@ -763,7 +763,7 @@ progressmeter(int flag, const char *file
off_t cursize, abbrevsize;
double elapsed;
int ratio, barlength, i, remaining, overhead = 30;
-   char buf[512];
+   char buf[512], *filenamebuf;
 
if (flag == -1) {
clock_gettime(CLOCK_MONOTONIC, );
@@ -782,11 +782,13 @@ progressmeter(int flag, const char *file
ratio = MAXIMUM(ratio, 0);
ratio = MINIMUM(ratio, 100);
if (!verbose && flag == -1) {
-   filename = basename(filename);
-   if (filename != NULL) {
+   filenamebuf = strdup(filename);
+   filename = basename(filenamebuf);
+   if (filenamebuf != NULL && filename != NULL) {
free(title);
title = strdup(filename);
}
+   free(filenamebuf);
}
 
buf[0] = 0;
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Non-const basename: usr.sbin/vmd, usr.sbin/vmctl

2020-10-14 Thread Christian Weisgerber
Accommodate POSIX basename(3) that takes a non-const parameter and
may in fact modify the string buffer.

The file is built by vmd and vmctl.

I'm uncertain if we want a truncation check here.  Both in vmd and
vmctl, the path has been validated by a previous open(), but given
the code complexity, do we want to rely on this?


Index: usr.sbin/vmd/vioqcow2.c
===
RCS file: /cvs/src/usr.sbin/vmd/vioqcow2.c,v
retrieving revision 1.13
diff -u -p -r1.13 vioqcow2.c
--- usr.sbin/vmd/vioqcow2.c 10 Jan 2019 19:21:02 -  1.13
+++ usr.sbin/vmd/vioqcow2.c 14 Oct 2020 20:57:31 -
@@ -145,6 +145,7 @@ virtio_qcow2_init(struct virtio_backing 
 ssize_t
 virtio_qcow2_get_base(int fd, char *path, size_t npath, const char *dpath)
 {
+   char dpathbuf[PATH_MAX];
char expanded[PATH_MAX];
struct qcheader header;
uint64_t backingoff;
@@ -186,7 +187,8 @@ virtio_qcow2_get_base(int fd, char *path
return -1;
}
} else {
-   s = dirname(dpath);
+   strlcpy(dpathbuf, dpath, sizeof(dpathbuf));
+   s = dirname(dpathbuf);
if (snprintf(expanded, sizeof(expanded),
"%s/%s", s, path) >= (int)sizeof(expanded)) {
log_warnx("path too long: %s/%s", s, path);
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Non-const basename: usr.bin/rcs

2020-10-14 Thread Christian Weisgerber
Accommodate POSIX basename(3) that takes a non-const parameter and
may in fact modify the string buffer.

ok?

Index: usr.bin/rcs/rlog.c
===
RCS file: /cvs/src/usr.bin/rcs/rlog.c,v
retrieving revision 1.74
diff -u -p -r1.74 rlog.c
--- usr.bin/rcs/rlog.c  16 Oct 2016 13:35:51 -  1.74
+++ usr.bin/rcs/rlog.c  14 Oct 2020 20:18:55 -
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -348,7 +349,7 @@ rlog_select_daterev(RCSFILE *rcsfile, ch
 static void
 rlog_file(const char *fname, RCSFILE *file)
 {
-   char numb[RCS_REV_BUFSZ];
+   char fnamebuf[PATH_MAX], numb[RCS_REV_BUFSZ];
u_int nrev;
struct rcs_sym *sym;
struct rcs_access *acp;
@@ -364,7 +365,10 @@ rlog_file(const char *fname, RCSFILE *fi
} else
nrev = file->rf_ndelta;
 
-   if ((workfile = basename(fname)) == NULL)
+   if (strlcpy(fnamebuf, fname, sizeof(fnamebuf)) >= sizeof(fnamebuf))
+   errx(1, "rlog_file: truncation");
+
+   if ((workfile = basename(fnamebuf)) == NULL)
err(1, "basename");
 
/*
-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



  1   2   3   4   5   6   >