# pkg segfaulting



## cbrace (Sep 1, 2019)

Hi all,

On one of my systems, pkg is broken:

```
$ sudo pkg install upgrade
Updating FreeBSD repository catalogue...
Fetching meta.txz: 100%    944 B   0.9kB/s    00:01
Fetching packagesite.txz: 100%    6 MiB 824.1kB/s    00:08
Processing entries: 100%
Child process pid=97251 terminated abnormally: Segmentation fault
```
If I rerun it at this point, it runs without apparent error, but doesn't seem to find anything:

```
$ sudo pkg upgrade  
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Checking for upgrades (0 candidates): 100%
Processing candidates (0 candidates): 100%
Checking integrity... done (0 conflicting)
Your packages are up to date.
```


```
$ pkg info | wc -l
     118
```


```
$ sudo pkg install nmap
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
pkg: No packages available to install matching 'nmap' have been found in the repositories
```
Something must be broken here, but what?

```
$ ls -l /var/db/pkg
total 37816
-rw-r--r--  1 root  wheel       246 Sep  1 08:00 FreeBSD.meta
-rw-r--r--  1 root  wheel  17539072 Sep  1 08:52 local.sqlite
-rw-------  1 root  wheel  52555776 Sep  1 01:36 pkg.core
drwxr-xr-x  2 root  wheel         2 Sep  1 08:00 provides
-rw-r--r--  1 root  wheel    184320 Sep  1 08:01 repo-FreeBSD.sqlite
-rw-r--r--  1 root  wheel    184320 Sep  1 01:37 repo-FreeBSD.sqlite-pkgtemp
-r--r--r--  1 root  wheel   5841515 Aug 30 03:39 vuln.xml
```
Anyone have any suggestions for me?

```
$ uname -r
11.3-RELEASE-p3
```


----------



## yuripv (Sep 1, 2019)

`pkg install upgrade` doesn't make much sense, though it shouldn't lead to a segfault. `pkg upgrade` showing 0 packages to upgrade is normal if there's nothing to upgrade.

Finally, `pkg install nmap` not finding nmap package is bad, try forcefully updating the pkg database using `pkg update -f`.


----------



## cbrace (Sep 1, 2019)

Sorry, cut and paste error: meant `pkg upgrade`*.*

I try running `pkg update -f` three times in succession; each time it segfaults.

The weird thing is that nmap is already installed; `pkg info nmap` works, but `pkg install nmap` returns nothing.

Could this file be corrupted? /var/db/pkg/local.sqlite

Here is potential brute-force solution I haven't tried yet which comprises removing all packages and reinstalling them:
pkg segfault abort, signal 6, runs out of memory, package not installed


----------



## yuripv (Sep 1, 2019)

Try making a copy of /var/db/pkg/ (just to be safe) first, and look into `pkg check` (with different options) and/or `pkg upgrade -f` commands.

Note that I didn't ever hit such problem, so the above may prove useless, sorry.

Yet, the best option might be looking into the core dump itself, and finding why exactly it does segfault (if you want to/have time), starting with https://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/debugging.html.


----------



## SirDice (Sep 2, 2019)

Try forcing a re-install of pkg(8): `pkg-static install -f pkg`


----------

