Hi,

Thanks for the review!

On Tue, 17 Dec 2024 at 19:21, Andres Freund <and...@anarazel.de> wrote:
>
> Hi,
>
> On 2024-11-12 11:38:11 +0300, Nazir Bilal Yavuz wrote:
> > On Fri, 1 Nov 2024 at 21:44, Andres Freund <and...@anarazel.de> wrote:
> > > > +    CCACHE_DIR: /tmp/ccache_dir
> > > > +
> > > > +    PATH: /usr/sbin:$PATH
> > > > +
> > > > +    # Postgres interprets LANG as a 'en_US.UTF-8' but it is 'C', then
> > >
> > > What does "Postgres interprets LANG as a 'en_US.UTF-8'" mean?
> >
> > It was because initdb was failing on NetBSD when the LANG and LC_ALL
> > is not set to C. I rephrased the comment and moved this under NetBSD
> > task.
>
> Do you happen to have a reference to the failure?  The environment variables +
> the exact error message would be good.  Kinda feels like that shouldn't
> happen with a default netbsd install.

This was already discussed upthread. Would you like more information?

> > > > +  matrix:
> > > > +    - name: NetBSD - 10 - Meson
> > > > +      only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || 
> > > > $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*netbsd.*'
> > > > +      env:
> > > > +        IMAGE_FAMILY: pg-ci-netbsd-postgres
> > > > +        INCLUDE_DIRS: -Dextra_lib_dirs=/usr/pkg/lib 
> > > > -Dextra_include_dirs=/usr/pkg/include
> > > > +      <<: *netbsd_task_template
> > > > +
> > > > +    - name: OpenBSD - 7 - Meson
> > > > +      only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || 
> > > > $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*openbsd.*'
> > > > +      env:
> > > > +        IMAGE_FAMILY: pg-ci-openbsd-postgres
> > > > +        INCLUDE_DIRS: -Dextra_include_dirs=/usr/local/include 
> > > > -Dextra_lib_dirs=/usr/local/lib
> > > > +        UUID: -Duuid=e2fs
> > >
> > > Shouldn't something be added to PKG_CONFIG_PATH / --pkg-config-path?
> >
> > I don't think so. Both OSes are able to find pkgconfig at
> > '/usr/pkg/bin/pkg-config'. Am I missing something?
>
> --pkg-config-path is about the the path to pkg-config files, not the path to
> the pkg-config binary. If set we shouldn't need the
> extra_lib_dirs/extra_include_dirs, I think.

Yes, my bad. Done.

> > > Right now you don't seem to be collecting core files - but you're still
> > > enabling them via ulimit -c unlimited.  At least we shouldn't use ulimit 
> > > -c
> > > unlimited without collecting core files, but it'd probably be better to 
> > > add
> > > support for collecting core files. Shouldn't be too hard.
> >
> > Done. I separated this patch to make review easier.
>
> +1
>
>
>
> > From cbea598b11e85b5c7090ca8e9cc05c35f0359f54 Mon Sep 17 00:00:00 2001
> > From: Nazir Bilal Yavuz <byavu...@gmail.com>
> > Date: Thu, 7 Nov 2024 15:48:31 +0300
> > Subject: [PATCH v2 1/3] Fix meson could not find bsd_auth.h
> >
> > bsd_auth.h file needs to be compiled together with the 'sys/types.h' as
> > it has missing type definitions.
> >
> > See synopsis at https://man.openbsd.org/authenticate.3
> > ---
> >  meson.build | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/meson.build b/meson.build
> > index 5b0510cef78..84107955d5d 100644
> > --- a/meson.build
> > +++ b/meson.build
> > @@ -551,7 +551,8 @@ test_c_args = cppflags + cflags
> >  bsd_authopt = get_option('bsd_auth')
> >  bsd_auth = not_found_dep
> >  if cc.check_header('bsd_auth.h', required: bsd_authopt,
> > -    args: test_c_args, include_directories: postgres_inc)
> > +    args: test_c_args, prefix: '#include <sys/types.h>',
> > +    include_directories: postgres_inc)
> >    cdata.set('USE_BSD_AUTH', 1)
> >    bsd_auth = declare_dependency()
> >  endif
> > --
>
> Was about to apply that, but then started to wonder if we don't need the same
> for configure? And it sure looks like that has the same problem?
>
> Which also confuses me some, at some point this presumably worked?

This too was discussed upthread. Please let me know if you need more
information.

> > From cd5bb66a55e5226b543f5b7db9128cfa48e338e3 Mon Sep 17 00:00:00 2001
> > From: Nazir Bilal Yavuz <byavu...@gmail.com>
> > Date: Mon, 11 Nov 2024 13:23:22 +0300
> > Subject: [PATCH v2 2/3] Add NetBSD and OpenBSD tasks to the Postgres CI
> >
> > NetBSD and OpenBSD Postgres CI images are generated [1] but their tasks
> > are not added to the upstream Postgres yet. This patch adds them.
> >
> > Note: These tasks will be triggered manually to save CI credits but a
> > related line is commented out for now to trigger CFBot.
> >
> > Author: Nazir Bilal Yavuz <byavu...@gmail.com>
> >
> > [1] https://github.com/anarazel/pg-vm-images
> > ---
> >  .cirrus.tasks.yml | 84 +++++++++++++++++++++++++++++++++++++++++++++++
> >  .cirrus.yml       | 10 ++++++
> >  2 files changed, 94 insertions(+)
> >
> > diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
> > index fc413eb11ef..f338af902aa 100644
> > --- a/.cirrus.tasks.yml
> > +++ b/.cirrus.tasks.yml
> > @@ -213,6 +213,90 @@ task:
> >      cores_script: src/tools/ci/cores_backtrace.sh freebsd /tmp/cores
> >
> >
> > +task:
> > +  depends_on: SanityCheck
> > +  # trigger_type: manual
> > +
> > +  env:
> > +    # Below are experimentally derived to be a decent choice.
> > +    CPUS: 2
>
> For cfbot it turns out to be easier to just use 4 cpus for everything. What
> time difference do you get from 2 vs 4 CPUs?

I shared the timings at the first email of the thread [1]. Copying the
timings from there:

╔══════════════════════╦════════╦═════════╗
║      CI Run Tim      ║        ║         ║
║   (Only Test Step)   ║ NetBSD ║ OpenBSD ║
║ (in minutes:seconds) ║        ║         ║
╠══════════════════════╬════════╬═════════╣
║     CPU: 2, TJ: 4    ║  13:18 ║  17:07  ║
╠══════════════════════╬════════╬═════════╣
║     CPU: 2, TJ: 6    ║  11:01 ║  16:23  ║
╠══════════════════════╬════════╬═════════╣
║     CPU: 2, TJ: 8    ║  10:14 ║  15:41  ║
╠══════════════════════╬════════╬═════════╣
║     CPU: 4, TJ: 4    ║  11:46 ║  16:03  ║
╠══════════════════════╬════════╬═════════╣
║     CPU: 4, TJ: 6    ║  09:56 ║  14:59  ║
╠══════════════════════╬════════╬═════════╣
║     CPU: 4, TJ: 8    ║  10:02 ║  15:09  ║
╚══════════════════════╩════════╩═════════╝

> > +    BUILD_JOBS: 8
> > +    TEST_JOBS: 8
>
> 8 build/test jobs for 2 cpus sounds unlikely to be close to optimal. A bit
> higher makes sense, but 4x?

I updated them with CPUS: 4 and JOBS: 8.

> > +    CIRRUS_WORKING_DIR: /home/postgres/postgres
>
> I'd add a comment explaining why we're setting this.

Done.

> > +    CCACHE_DIR: /tmp/ccache_dir
>
> And is it ok to put the ccache dir here, given the limited size of /tmp?

Yes, you are right; moved it to /home/postgres/cache.

> > +    PATH: /usr/sbin:$PATH
> > +
> > +  matrix:
> > +    - name: NetBSD - 10 - Meson
>
> Given the image name doesn't include the version it seems we shouldn't include
> it here either...

Done.

> > +      only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || 
> > $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*netbsd.*'
> > +      env:
> > +        IMAGE_FAMILY: pg-ci-netbsd-postgres
> > +        INCLUDE_DIRS: -Dextra_include_dirs=/usr/pkg/include 
> > -Dextra_lib_dirs=/usr/pkg/lib
> > +        # initdb fails with: 'invalid locale settings' error on NetBSD.
> > +        # Force 'LANG' and 'LC_*' variables to be 'C'.
> > +        LANG: "C"
> > +        LC_ALL: "C"
> > +      setup_additional_packages_script: |
> > +        #pkgin -y install ...
> > +      <<: *netbsd_task_template
> > +
> > +    - name: OpenBSD - 7 - Meson
> > +      only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || 
> > $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*openbsd.*'
> > +      env:
> > +        IMAGE_FAMILY: pg-ci-openbsd-postgres
> > +        INCLUDE_DIRS: -Dextra_include_dirs=/usr/local/include 
> > -Dextra_lib_dirs=/usr/local/lib
> > +        UUID: -Duuid=e2fs
>
> So for netbsd we're not using any uuid support?  Ah, I see, it's documented
> further down. Maybe reference that, or move the comment around?

Done.

> > +  # -Duuid=bsd is not set since 'bsd' uuid option
> > +  # is not working on NetBSD & OpenBSD. See
> > +  # 
> > https://www.postgresql.org/message-id/17358-89806e7420797...@postgresql.org
> > +  # And other uuid options are not available on NetBSD.
> > +  configure_script: |
> > +    su postgres <<-EOF
> > +      meson setup \
> > +        --buildtype=debugoptimized \
> > +        -Dcassert=true -Dinjection_points=true \
> > +        -Dssl=openssl ${UUID} \
> > +        -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
> > +        ${INCLUDE_DIRS} \
> > +        build
> > +    EOF
>
> https://cirrus-ci.com/task/4879081273032704?logs=configure#L320
>
> [14:48:50.729] Run-time dependency krb5-gssapi found: NO (tried pkgconfig and 
> cmake)
> [14:48:50.729] Library gssapi_krb5 found: NO
>
> https://cirrus-ci.com/task/6286456156585984?logs=configure#L109
>
> [14:49:28.049] Run-time dependency krb5-gssapi found: NO (tried pkgconfig and 
> cmake)
> [14:49:28.049] Library gssapi_krb5 found: NO
>
> Is gss really not available / installed on either?

NetBSD is fixed [2] but we require MIT Kerberos [3] which requires a
gssapi_ext.h file. OpenBSD does not have MIT Kerberos nor gssapi_ext.h
file [4].

> https://cirrus-ci.com/task/4879081273032704?logs=configure#L49-L51
> [14:48:50.729] Run-time dependency tcl found: NO (tried pkgconfig and cmake)
> [14:48:50.729] Library tcl found: NO
> [14:48:50.729] Has header "tcl.h" with dependency -ltcl: NO
>
> Is TCL not available on openbsd?

Version option is added, it is working now.

> > +  build_script: su postgres -c 'ninja -C build -j${BUILD_JOBS}'
> > +  upload_caches: ccache
> > +
> > +  test_world_script: |
> > +    su postgres <<-EOF
> > +      # Otherwise tests will fail on OpenBSD, due to the lack of enough 
> > processes.
> > +      ulimit -p 256
>
> Should we also increase the number of semaphores?
>
> https://postgr.es/m/db2773a2-aca0-43d0-99c1-060efcd9954e%40gmail.com

It is already increased while creating the bsd images [5] [6].

> Perhaps it'd be better to update the system config earlier in the openbsd
> specific portion of the test?

'ulimit -p' needs to be run as a postgres user, but postgres user is
created after the OpenBSD specific portion. I can put an if statement
to make it only work for OpenBSD. Does that sound good?

> >          build/tmp_install/usr/local/pgsql/bin/pg_ctl -D build/runningcheck 
> > stop || true
> >        EOF
> >      <<: *on_failure_meson
> > -    cores_script: src/tools/ci/cores_backtrace.sh freebsd /tmp/cores
> > +    cores_script: src/tools/ci/cores_backtrace.sh bsd /tmp/cores
>
> Hm, what's the deal with this change?

Removed, forgot to revert it before sending the patch.

> >    on_failure:
> >      <<: *on_failure_meson
> > +    cores_script: |
> > +      # Although OSes are forced to core dump inside ${CORE_DUMP_DIR}, 
> > they may
> > +      # not obey this. So, move core files to the ${CORE_DUMP_DIR} 
> > directory.
> > +      find build/ -maxdepth 1 -type f -name '*.core' -exec mv '{}' 
> > ${CORE_DUMP_DIR} \;
> > +      src/tools/ci/cores_backtrace.sh ${OS_NAME} ${CORE_DUMP_DIR}
>
> s/OSs are forced/we try to configure the OS/
>
> Is -maxdepth 1 really sufficient? The tests run in subdirectories, don't they?

You are right, maxdepth is removed now.

> > +  matrix:
> > +    - name: NetBSD - 10 - Meson
> > +      only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || 
> > $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*netbsd.*'
> ...
> > +    - name: OpenBSD - 7 - Meson
> > +      only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || 
> > $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*openbsd.*'
>
> Think these probably should be added to src/tools/ci/README

Done.

[1] 
postgr.es/m/CAN55FZ0GXrojT2yUTrST5McJk8UWmYxUX8b696XjL01B1pKsxg%40mail.gmail.com
[2] https://github.com/anarazel/pg-vm-images/pull/108
[3] f7431bca8b
[4] postgr.es/m/3598083.1680976022%40sss.pgh.pa.us
[5] 
https://github.com/anarazel/pg-vm-images/blob/af8757bd5ed3f4055809bffde28334a8547dfced/scripts/bsd/netbsd-prep-postgres.sh#L30C1-L32C56
[6] 
https://github.com/anarazel/pg-vm-images/blob/af8757bd5ed3f4055809bffde28334a8547dfced/scripts/bsd/openbsd-prep-postgres.sh#L50C1-L53C63

--
Regards,
Nazir Bilal Yavuz
Microsoft
From 4388cb77794c94c329bfe2ac977a59f71b72f6d0 Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <byavu...@gmail.com>
Date: Thu, 7 Nov 2024 15:48:31 +0300
Subject: [PATCH v3 1/3] Fix meson could not find bsd_auth.h

bsd_auth.h file needs to be compiled together with the 'sys/types.h' as
it has missing type definitions.

See synopsis at https://man.openbsd.org/authenticate.3
---
 meson.build | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index cfd654d2916..50731f47f7e 100644
--- a/meson.build
+++ b/meson.build
@@ -557,7 +557,8 @@ test_c_args = cppflags + cflags
 bsd_authopt = get_option('bsd_auth')
 bsd_auth = not_found_dep
 if cc.check_header('bsd_auth.h', required: bsd_authopt,
-    args: test_c_args, include_directories: postgres_inc)
+    args: test_c_args, prefix: '#include <sys/types.h>',
+    include_directories: postgres_inc)
   cdata.set('USE_BSD_AUTH', 1)
   bsd_auth = declare_dependency()
 endif
-- 
2.47.1

From eb1d8e55d341b109a503759945f89ca530c6aafa Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <byavu...@gmail.com>
Date: Mon, 11 Nov 2024 13:23:22 +0300
Subject: [PATCH v3 2/3] Add NetBSD and OpenBSD tasks to the Postgres CI

NetBSD and OpenBSD Postgres CI images are generated [1] but their tasks
are not added to the upstream Postgres yet. This patch adds them.

Note: These tasks will be triggered manually to save CI credits but a
related line is commented out for now to trigger CFBot.

Author: Nazir Bilal Yavuz <byavu...@gmail.com>

[1] https://github.com/anarazel/pg-vm-images
---
 .cirrus.tasks.yml   | 90 +++++++++++++++++++++++++++++++++++++++++++++
 .cirrus.yml         | 10 +++++
 src/tools/ci/README |  2 +-
 3 files changed, 101 insertions(+), 1 deletion(-)

diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
index 18e944ca89d..43cca1aeb58 100644
--- a/.cirrus.tasks.yml
+++ b/.cirrus.tasks.yml
@@ -213,6 +213,96 @@ task:
     cores_script: src/tools/ci/cores_backtrace.sh freebsd /tmp/cores
 
 
+task:
+  depends_on: SanityCheck
+  # trigger_type: manual
+
+  env:
+    # Below are experimentally derived to be a decent choice.
+    CPUS: 4
+    BUILD_JOBS: 8
+    TEST_JOBS: 8
+
+    # Default working directory is /tmp but its total size (1.2 GB) is not
+    # enough, so different working and cache directory are set.
+    CIRRUS_WORKING_DIR: /home/postgres/postgres
+    CCACHE_DIR: /home/postgres/cache
+
+    PATH: /usr/sbin:$PATH
+
+  matrix:
+    - name: NetBSD - Meson
+      only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*netbsd.*'
+      env:
+        IMAGE_FAMILY: pg-ci-netbsd-postgres
+        PKGCONFIG_PATH: '/usr/lib/pkgconfig:/usr/pkg/lib/pkgconfig'
+        # initdb fails with: 'invalid locale settings' error on NetBSD.
+        # Force 'LANG' and 'LC_*' variables to be 'C'.
+        LANG: "C"
+        LC_ALL: "C"
+        # -Duuid is not set for the NetBSD, see the comment at the configure
+        # script for more information.
+      setup_additional_packages_script: |
+        #pkgin -y install ...
+      <<: *netbsd_task_template
+
+    - name: OpenBSD - Meson
+      only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*openbsd.*'
+      env:
+        IMAGE_FAMILY: pg-ci-openbsd-postgres
+        PKGCONFIG_PATH: '/usr/lib/pkgconfig:/usr/local/lib/pkgconfig'
+        UUID: -Duuid=e2fs
+        TCL: -Dtcl_version=tcl86
+      setup_additional_packages_script: |
+        #pkg_add -I ...
+      <<: *openbsd_task_template
+
+  sysinfo_script: |
+    locale
+    id
+    uname -a
+    ulimit -a -H && ulimit -a -S
+    env
+
+  ccache_cache:
+    folder: $CCACHE_DIR
+
+  create_user_script: |
+    useradd postgres
+    chown -R postgres:users /home/postgres
+    mkdir -p ${CCACHE_DIR}
+    chown -R postgres:users ${CCACHE_DIR}
+
+  # -Duuid=bsd is not set since 'bsd' uuid option
+  # is not working on NetBSD & OpenBSD. See
+  # https://www.postgresql.org/message-id/17358-89806e7420797...@postgresql.org
+  # And other uuid options are not available on NetBSD.
+  configure_script: |
+    su postgres <<-EOF
+      meson setup \
+        --buildtype=debugoptimized \
+        --pkg-config-path ${PKGCONFIG_PATH} \
+        -Dcassert=true -Dinjection_points=true \
+        -Dssl=openssl ${UUID} ${TCL} \
+        -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \
+        build
+    EOF
+
+  build_script: su postgres -c 'ninja -C build -j${BUILD_JOBS}'
+  upload_caches: ccache
+
+  test_world_script: |
+    su postgres <<-EOF
+      ulimit -c unlimited
+      # Otherwise tests will fail on OpenBSD, due to the lack of enough processes.
+      ulimit -p 256
+      meson test $MTEST_ARGS --num-processes ${TEST_JOBS}
+    EOF
+
+  on_failure:
+    <<: *on_failure_meson
+
+
 # configure feature flags, shared between the task running the linux tests and
 # the CompilerWarnings task
 LINUX_CONFIGURE_FEATURES: &LINUX_CONFIGURE_FEATURES >-
diff --git a/.cirrus.yml b/.cirrus.yml
index a83129ae46d..33c6e481d74 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -52,6 +52,16 @@ default_freebsd_task_template: &freebsd_task_template
     PLATFORM: freebsd
   <<: *cirrus_community_vm_template
 
+default_netbsd_task_template: &netbsd_task_template
+  env:
+    PLATFORM: netbsd
+  <<: *cirrus_community_vm_template
+
+default_openbsd_task_template: &openbsd_task_template
+  env:
+    PLATFORM: openbsd
+  <<: *cirrus_community_vm_template
+
 
 default_windows_task_template: &windows_task_template
   env:
diff --git a/src/tools/ci/README b/src/tools/ci/README
index 30ddd200c96..dd703272d3f 100644
--- a/src/tools/ci/README
+++ b/src/tools/ci/README
@@ -61,7 +61,7 @@ Controlling CI via commit messages
 The behavior of CI can be controlled by special content in commit
 messages. Currently the following controls are available:
 
-- ci-os-only: {(freebsd|linux|macos|windows|mingw)}
+- ci-os-only: {(freebsd|netbsd|openbsd|linux|macos|windows|mingw)}
 
   Only runs CI on operating systems specified. This can be useful when
   addressing portability issues affecting only a subset of platforms.
-- 
2.47.1

From 5ba96dd27488a5e8d484db3d46edf10c8a529660 Mon Sep 17 00:00:00 2001
From: Nazir Bilal Yavuz <byavu...@gmail.com>
Date: Wed, 8 Jan 2025 10:56:23 +0300
Subject: [PATCH v3 3/3] Collect core files on NetBSD and OpenBSD

NetBSD and OpenBSD operating systems are added to the CI. Now, collect
core files on failure on these operating systems.
---
 .cirrus.tasks.yml               | 15 +++++++++++++++
 src/tools/ci/cores_backtrace.sh |  6 ++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml
index 43cca1aeb58..a4aeabd097b 100644
--- a/.cirrus.tasks.yml
+++ b/.cirrus.tasks.yml
@@ -229,11 +229,13 @@ task:
     CCACHE_DIR: /home/postgres/cache
 
     PATH: /usr/sbin:$PATH
+    CORE_DUMP_DIR: /var/crash
 
   matrix:
     - name: NetBSD - Meson
       only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*netbsd.*'
       env:
+        OS_NAME: netbsd
         IMAGE_FAMILY: pg-ci-netbsd-postgres
         PKGCONFIG_PATH: '/usr/lib/pkgconfig:/usr/pkg/lib/pkgconfig'
         # initdb fails with: 'invalid locale settings' error on NetBSD.
@@ -249,12 +251,15 @@ task:
     - name: OpenBSD - Meson
       only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*openbsd.*'
       env:
+        OS_NAME: openbsd
         IMAGE_FAMILY: pg-ci-openbsd-postgres
         PKGCONFIG_PATH: '/usr/lib/pkgconfig:/usr/local/lib/pkgconfig'
         UUID: -Duuid=e2fs
         TCL: -Dtcl_version=tcl86
       setup_additional_packages_script: |
         #pkg_add -I ...
+      # Always core dump to ${CORE_DUMP_DIR}
+      set_core_dump_script: sysctl -w kern.nosuidcoredump=2
       <<: *openbsd_task_template
 
   sysinfo_script: |
@@ -272,6 +277,10 @@ task:
     chown -R postgres:users /home/postgres
     mkdir -p ${CCACHE_DIR}
     chown -R postgres:users ${CCACHE_DIR}
+  setup_core_files_script: |
+    mkdir -p ${CORE_DUMP_DIR}
+    chmod -R 770 ${CORE_DUMP_DIR}
+    chown -R postgres:users ${CORE_DUMP_DIR}
 
   # -Duuid=bsd is not set since 'bsd' uuid option
   # is not working on NetBSD & OpenBSD. See
@@ -301,6 +310,12 @@ task:
 
   on_failure:
     <<: *on_failure_meson
+    cores_script: |
+      # Although we try to configure the OS to core dump inside
+      # ${CORE_DUMP_DIR}, they may not obey this. So, move core files to the
+      # ${CORE_DUMP_DIR} directory.
+      find build/ -type f -name '*.core' -exec mv '{}' ${CORE_DUMP_DIR} \;
+      src/tools/ci/cores_backtrace.sh ${OS_NAME} ${CORE_DUMP_DIR}
 
 
 # configure feature flags, shared between the task running the linux tests and
diff --git a/src/tools/ci/cores_backtrace.sh b/src/tools/ci/cores_backtrace.sh
index 28d3cecfc67..4b174a5cf56 100755
--- a/src/tools/ci/cores_backtrace.sh
+++ b/src/tools/ci/cores_backtrace.sh
@@ -9,7 +9,7 @@ os=$1
 directory=$2
 
 case $os in
-    freebsd|linux|macos)
+    freebsd|netbsd|openbsd|linux|macos)
     ;;
     *)
         echo "unsupported operating system ${os}"
@@ -26,7 +26,7 @@ for corefile in $(find "$directory" -type f) ; do
         echo -e '\n\n'
     fi
 
-    if [ "$os" = 'macos' ]; then
+    if [ "$os" = 'macos' ] || [ "$os" = 'openbsd' ]; then
         lldb -c $corefile --batch -o 'thread backtrace all' -o 'quit'
     else
         auxv=$(gdb --quiet --core ${corefile} --batch -ex 'info auxv' 2>/dev/null)
@@ -37,6 +37,8 @@ for corefile in $(find "$directory" -type f) ; do
 
         if [ "$os" = 'freebsd' ]; then
             binary=$(echo "$auxv" | grep AT_EXECPATH | perl -pe "s/^.*\"(.*)\"\$/\$1/g")
+        elif [ "$os" = 'netbsd' ]; then
+            binary=$(echo "$auxv" | grep AT_SUN_EXECNAME | perl -pe "s/^.*\"(.*)\"\$/\$1/g")
         elif [ "$os" = 'linux' ]; then
             binary=$(echo "$auxv" | grep AT_EXECFN | perl -pe "s/^.*\"(.*)\"\$/\$1/g")
         else
-- 
2.47.1

Reply via email to