Repository: ethereum/go-ethereum (language: go)

Issue:
Few tests don't pass on OpenBSD/adJ
#### System information

Geth version `geth version`: 1.14.13-unstable-341647f1-20241219
CL client & version: ?
OS & Version: OpenBSD/adJ 7.6


#### Expected behaviour

```
gmake test
```

All tests passing

#### Actual behaviour

Most of the tests pass except:

```
--- FAIL: TestAccountNewBadRepeat (0.12s)                                                                                                                       
    test_cmd.go:261: (stderr:9) INFO [12-26|17:14:24.403] Maximum peer count                       ETH=50 total=50                                              
    test_cmd.go:261: (stderr:9) INFO [12-26|17:14:24.407] Smartcard socket not found, disabling    err="stat /var/run/pcscd/pcscd.comm: no such file or director
y"                                                                                                                                                              
    test_cmd.go:261: (stderr:9) Fatal: Passwords do not match                                                                                                   
    test_cmd.go:115: not enough output, got until ◊:                                                                                                            
        ---------------- (stdout text)                                                                                                                          
        Your new account is locked with a password. Please give a password. Do not forget this password.                                                        
        !! Unsupported terminal, password will be echoed.                                                                                                       
        Password:                                                                                                                                               
        Repeat password:                                                        
         

        ---------------- (expected text)                                                                                                                        
        Your new account is locked with a password. Please give a password. Do not forget this password.                                                        
        !! Unsupported terminal, password will be echoed.                                                                                                       
        Password:                                                                                                                                               
        Repeat password:                                                                                                                                        
        ◊Fatal: Passwords do not match                                                                                                                          
                                                                                                                                                                
--- FAIL: TestWalletImportBadPassword (0.20s)                                                                                                                   
    test_cmd.go:261: (stderr:18) INFO [12-26|17:14:24.968] Maximum peer count                       ETH=50 total=50                                             
    test_cmd.go:261: (stderr:18) INFO [12-26|17:14:24.972] Smartcard socket not found, disabling    err="stat /var/run/pcscd/pcscd.comm: no such file or directo
ry"                                                                                                                                                             
    test_cmd.go:261: (stderr:18) Fatal: could not decrypt key with given password                                                                               
    test_cmd.go:115: not enough output, got until ◊:                                                                                                            
        ---------------- (stdout text)                                                                                                                          
        !! Unsupported terminal, password will be echoed.                                                                                                       
        Password:                                                                                                                                               
                                                                                                                                                                
        ---------------- (expected text)                                                                                                                        
        !! Unsupported terminal, password will be echoed.                                                                                                       
        Password:                                                                                                                                               
        ◊Fatal: could not decrypt key with given password
         

--- FAIL: TestAccountImport (0.00s)                                                                                                                             
    --- FAIL: TestAccountImport/invalid_character (0.09s)                                                                                                       
        test_cmd.go:261: (stderr:25) Fatal: Failed to load the private key: invalid character '1' at end of key file                                            
        test_cmd.go:115: not enough output, got until ◊:                                                                                                        
            ---------------- (stdout text)                                                                                                                      
                                                                                                                                                                
            ---------------- (expected text)                                                                                                                    
            ◊Fatal: Failed to load the private key: invalid character '1' at end of key file                                                                    
                                                                                                                                                                
--- FAIL: TestCustomBackend (2.78s)
...
        Fatal: Failed to register the Ethereum service: db.engine choice was pebble but found pre-existing leveldb database in specified data directory         
FAIL                                                                                                                                                            
FAIL    github.com/ethereum/go-ethereum/cmd/geth        4.880s
...
panic: cannot allocate 67108864 bytes via mmap: cannot allocate memory [recovered]                                                                              
        panic: cannot allocate 67108864 bytes via mmap: cannot allocate memory 
FAIL    github.com/ethereum/go-ethereum/core/state      7.340s
...
fatal error: runtime: out of memory
...
FAIL    github.com/ethereum/go-ethereum/eth/protocols/snap      18.211s
```


#### Steps to reproduce the behaviour

```
gmake test
```

#### Backtrace




Discussion / hints:
Thanks for the report. We don't have a lot of openbsd users, we'd need someone with openbsd to help investigate this. Alternatively, do you know of some easy:ish way to emulate/simulate an openbsd container? 
IT's likely related to this method (`cmd/utils/cmd.go`);
```golang
// Fatalf formats a message to standard error and exits the program.
// The message is also printed to standard output if standard error
// is redirected to a different file.
func Fatalf(format string, args ...interface{}) {
	w := io.MultiWriter(os.Stdout, os.Stderr)
	if runtime.GOOS == "windows" {
		// The SameFile check below doesn't work on Windows.
		// stdout is unlikely to get redirected though, so just print there.
		w = os.Stdout
	} else {
		outf, _ := os.Stdout.Stat()
		errf, _ := os.Stderr.Stat()
		if outf != nil && errf != nil && os.SameFile(outf, errf) {
			w = os.Stderr
		}
	}
	fmt.Fprintf(w, "Fatal: "+format+"\n", args...)
	os.Exit(1)
}
```
Most likely `The SameFile check below doesn't work on Windows.` -- this is probably also true for openbsd. 

Also, this is odd: 
```
panic: cannot allocate 67108864 bytes via mmap: cannot allocate memory [recovered]                                                                              
```
Afaict, we don't use `mmap` directly, I guess it must be some library that uses mmap. 
So there are several issues there, that I will dig into over time:

 * [ ] the input passwords don't match
 * [ ] some incorrect value is read from the key file
 * [ ] there is the `mmap` issue, which is linked to fastcache and might be caused by some permissions. 



Fix patch:
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index de5918a7221d..4e03df0c4a8c 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -60,8 +60,8 @@ const (
 // is redirected to a different file.
 func Fatalf(format string, args ...interface{}) {
 	w := io.MultiWriter(os.Stdout, os.Stderr)
-	if runtime.GOOS == "windows" {
-		// The SameFile check below doesn't work on Windows.
+	if runtime.GOOS == "windows" || runtime.GOOS == "openbsd" {
+		// The SameFile check below doesn't work on Windows neither OpenBSD.
 		// stdout is unlikely to get redirected though, so just print there.
 		w = os.Stdout
 	} else {


Test patch: