# pkg: Fail to create /usr: Bad file descriptor



## HL1234 (Jun 4, 2016)

Hello,
since a long time I want to do some update but a problem I do not understand:
system:9.1-RELEASE-p17 FreeBSD 9.1-RELEASE-p17

please see the output of command it shows all:

```
# pkg install pcre
Updating FreeBSD repository catalogue...
FreeBSD repository is up-to-date.
All repositories are up-to-date.
Checking integrity... done (0 conflicting)
The following 1 package(s) will be affected (of 0 checked):

Installed packages to be UPGRADED:
  pcre: 8.34 -> 8.38_1

Proceed with this action? [y/N]: y
[1/1] Upgrading pcre from 8.34 to 8.38_1...
pkg: dup2(rootfd): Invalid argument             <-----
[1/1] Extracting pcre-8.38_1:  0%
pkg: Fail to create /usr: Bad file descriptor   <-----
[1/1] Extracting pcre-8.38_1: 100%
```

I have done
`fsck -t ufs -fy` in single mode two times, until there was no longer any error on the file system shown.
I also fetch a new port-tree with `portsnap` after deleting the associated directories.

But the installation still fails. It is independent if I take pcre or anything else.

Can anyone tel me what these errors tell me?
and what to check or what to do?

Thanks a lot.


----------



## wblock@ (Jun 4, 2016)

portsnap(8) updates the ports tree, but that is not used by `pkg`.

Something is preventing writing to /usr.  If it is not a corrupted filesystem, it could be related to permissions of some type of security measures.


----------



## HL1234 (Jun 4, 2016)

wblock@ said:


> Something is preventing writing to /usr.  If it is not a corrupted filesystem, it could be related to permissions of some type of security measures.



hmm - strange.
I try this:

```
#  cd ~
#  touch anything.x

#  cp anything.x /usr/ports
#  ll /usr/ports/anything.x
-rw-r--r-- 1 root wheel 0 Jun  4 16:03 /usr/ports/anything.x

#  cp anything.x /usr/local/bin
#  ll /usr/local/bin/anything.x
-rw-r--r-- 1 root wheel 0 Jun  4 16:06 /usr/local/bin/anything.x
```

in /etc/rc.conf is

```
kern_securelevel="-1"  #the default
```

It seems there is no problem with write access to /usr for me. What kind of of security measures with pkg(8) and /usr can it be?
What means

```
pkg: dup2(rootfd): Invalid argument
```


----------



## HL1234 (Jun 4, 2016)

I've get a more detailed output

```
[haraldlangner.de /usr/ports] => pkg -d install pcre
DBG(1)[60623]> pkg initialized
Updating FreeBSD repository catalogue...
DBG(1)[60623]> PkgRepo: verifying update for FreeBSD
DBG(1)[60623]> Pkgrepo, begin update of '/var/db/pkg/repo-FreeBSD.sqlite'
DBG(1)[60623]> Fetch: fetching from: http://pkgmir.pkg.freebsd.org/FreeBSD:9:i386/latest/meta.txz with opts "i"
DBG(1)[60623]> Fetch: fetching from: http://pkgmir.pkg.freebsd.org/FreeBSD:9:i386/latest/packagesite.txz with opts "i"
FreeBSD repository is up-to-date.
All repositories are up-to-date.
DBG(1)[60623]> want to get an advisory lock on a database
DBG(1)[60623]> Binary> loading /var/cache/pkg/pcre-8.38_1-52e7ce0881.txz
Checking integrity...DBG(1)[60623]> check integrity for 1 items added
done (0 conflicting)
The following 1 package(s) will be affected (of 0 checked):

Installed packages to be UPGRADED:
  pcre: 8.34 -> 8.38_1

Proceed with this action? [y/N]: y
DBG(1)[60623]> want to upgrade advisory to exclusive lock
[1/1] Upgrading pcre from 8.34 to 8.38_1...
pkg: dup2(rootfd): Invalid argument
[1/1] Extracting pcre-8.38_1:  0%
pkg: Fail to create /usr: Bad file descriptor
[1/1] Extracting pcre-8.38_1: 100%
DBG(1)[60623]> release an exclusive lock on a database
DBG(1)[60623]> release an advisory lock on a database
```


----------



## kpa (Jun 4, 2016)

Post the output of `pkg -vv`. FreeBSD 9.1 is unsupported because the support ended on December 31, 2014. That might have to do with the problem and upgrading to 9.3 is recommended.


----------



## HL1234 (Jun 4, 2016)

Hello kpa, this is the output you ask for
`pkg -vv`

```
# cd /usr/ports
#  pkg -vv
Version  : 1.8.3
PKG_DBDIR = "/var/db/pkg";
PKG_CACHEDIR = "/var/cache/pkg";
PORTSDIR = "/usr/ports";
INDEXDIR = "";
INDEXFILE = "INDEX-9";
HANDLE_RC_SCRIPTS = false;
DEFAULT_ALWAYS_YES = false;
ASSUME_ALWAYS_YES = false;
REPOS_DIR [
  "/etc/pkg/",
  "/usr/local/etc/pkg/repos/",
]
PLIST_KEYWORDS_DIR = "";
SYSLOG = true;
ABI = "FreeBSD:9:i386";
ALTABI = "freebsd:9:x86:32";
DEVELOPER_MODE = false;
VULNXML_SITE = "http://vuxml.freebsd.org/freebsd/vuln.xml.bz2";
FETCH_RETRY = 3;
PKG_PLUGINS_DIR = "/usr/local/lib/pkg/plugins";
PKG_ENABLE_PLUGINS = true;
PLUGINS [
]
DEBUG_SCRIPTS = false;
PLUGINS_CONF_DIR = "/usr/local/etc/pkg/";
PERMISSIVE = false;
REPO_AUTOUPDATE = true;
NAMESERVER = "";
HTTP_USER_AGENT = "pkg/1.8.3";
EVENT_PIPE = "";
FETCH_TIMEOUT = 30;
UNSET_TIMESTAMP = false;
SSH_RESTRICT_DIR = "";
PKG_ENV {
}
PKG_SSH_ARGS = "";
DEBUG_LEVEL = 0;
ALIAS {
  all-depends = "query %dn-%dv";
  annotations = "info -A";
  build-depends = "info -qd";
  download = "fetch";
  iinfo = "info -i -g -x";
  isearch = "search -i -g -x";
  leaf = "query -e \"%a == 0\" \"%n-%v\"";
  leaf = "query -e \"%a == 0\" \"%n-%v\"";
  list = "info -ql";
  origin = "info -qo";
  provided-depends = "info -qb";
  raw = "info -R";
  required-depends = "info -qr";
  shared-depends = "info -qB";
  show = "info -f -k";
  size = "info -sq";
}
CUDF_SOLVER = "";
SAT_SOLVER = "";
RUN_SCRIPTS = true;
CASE_SENSITIVE_MATCH = false;
LOCK_WAIT = 1;
LOCK_RETRIES = 5;
SQLITE_PROFILE = false;
WORKERS_COUNT = 0;
READ_LOCK = false;
PLIST_ACCEPT_DIRECTORIES = false;
IP_VERSION = 0;
AUTOMERGE = true;
VERSION_SOURCE = "";
CONSERVATIVE_UPGRADE = true;
PKG_CREATE_VERBOSE = false;
AUTOCLEAN = false;
DOT_FILE = "";
REPOSITORIES {
}
VALID_URL_SCHEME [
  "pkg+http",
  "pkg+https",
  "https",
  "http",
  "file",
  "ssh",
  "ftp",
  "ftps",
  "pkg+ssh",
  "pkg+ftp",
  "pkg+ftps",
]
ALLOW_BASE_SHLIBS = false;
WARN_SIZE_LIMIT = 1048576;


Repositories:
  FreeBSD: {
  url  : "pkg+http://pkg.FreeBSD.org/FreeBSD:9:i386/latest",
  enabled  : yes,
  priority  : 0,
  mirror_type  : "SRV",
  signature_type  : "FINGERPRINTS",
  fingerprints  : "/usr/share/keys/pkg"
  }
#
```

what does it says?


----------



## kpa (Jun 4, 2016)

I don't see anything out of order in there. Maybe ask this on the freebsd-pkg mailing list. My suspicion however is still that ports-mgmt/pkg no longer works properly on unsupported versions of FreeBSD such as the 9.1 you're using.


----------



## tobik@ (Jun 4, 2016)

kpa is right, pkg > 1.7.2 is not supported on FreeBSD 9.1. This came up recently here in Thread 56462.


----------



## HL1234 (Jun 6, 2016)

Thanks, a lot.
I do not understand exactly what it means 
	
	



```
Implement F_DUPFD_CLOEXEC command for fcntl(2)
```
 and 
	
	



```
new API = dup3()
```
 I just recognize that there are something deep in the system has changed and thus I got these error "pkg: dup2(rootfd): Invalid argument".

I will search for how to do a downgrade for pkg < 1.7.2. The question is, when this works, can I install updates for all the application software (apache, mysql, etc..) even some about the ports? Or would I run in the same problems? 

A upgrade of the OS to 10.3 takes a lot of work to do. I have got not good experence with mergemaster, so all system scripts I has changed I has to update by hand. And in most case I have to upgrade the software to. My experence to this is, that I have to reconfigured the config-scripts like php.ini, httpd.conf, my.cnf, and more, too. Al lot of time get wasting, just to get the same finctionallity I now have on this old home webserver system.

But again, thanks a lot for your info.


----------



## chrbr (Jun 7, 2016)

Dear HL1234,
it can easily be forgotten to have a packaged locked in the past. Please see pkg-lock(8) for details. May be it is worth to check this when everything else is ok.


----------



## SirDice (Jun 7, 2016)

HL1234 said:


> A upgrade of the OS to 10.3 takes a lot of work to do


I would suggest updating to 9.3-RELEASE first. FreeBSD 9.3 will be supported until the end of the year. Upgrading 9.1 to 9.3 should be relatively easy. And it will allow you to update everything else. You then have a couple of months to test for 10.3.


----------



## HL1234 (Jun 16, 2016)

chrbr said:


> Dear HL1234,
> it can easily be forgotten to have a packaged locked in the past. Please see pkg-lock(8) for details...


`pkg-lock` did not work. I thing this it is the old style of the command. I do:
`pkg lock -l`
Yesterday I could downgrade to pkg-1.7.1. Then I had to lock it, because every install want to update pkg first. And then I could do the updates I want to do. Sadly, it don't fix my mysql problem - but here is not the right place to discuss this.
Thanks for your commends


----------



## chrbr (Jun 16, 2016)

HL1234 said:


> pkg-lock did not work.


The link shows the manual page. I think all new commands have the syntax `pkg something` but the man page pkg-something(). Usually they give more details about the special command. pkg(8) gives just an overview and lists the detailed pages at the end of the text.


----------



## bapt@ (Aug 23, 2016)

The reason of the failure is you are using pkg provided by FreeBSD meaning built on FreeBSD 9.3 where
F_DUPFD_CLOEXEC do exists, meaning the binary is incompatible with 9.1 where it does not exists.
If you build your own packages you won't have the issue as beside the fact 9.1 and 9.2 are not supported releases, we have added a compatibility fallback (at build time):
https://github.com/freebsd/pkg/pull/1449
https://github.com/freebsd/pkg/commit/be00b8b916ebaac792dc5c41806dc2048922fd6a

The policy of FreeBSD regarding the package is to build them on the lowest supported version of a given branch, in this case: 9.3
Concerning the binary compatibility binaries from 9.1 will all run on 9.3 without issues, but the opposite is not true as in the situation you are getting into now.

My recommendation is to upgrade to a supported version of FreeBSD (note that FreeBSD 9.3 will be EOLed at the end of this year) or if it is not possible for you for various reason, to build your own set of packages on 9.1.

Note that, potentially more ports than pkg might be inpacted by such problem.


----------

