Repository: fatedier/frp (language: go)

Issue:
Exit code should be non-zero when due to errors
### Bug Description

Log:
```
Oct 30 07:11:29 darkbox systemd[1]: Started Frp Client Service.
Oct 30 07:11:29 darkbox frpc[142]: 2023/10/30 07:11:29 [I] [root.go:220] start frpc service for config file [/etc/frp/frpc.ini]
Oct 30 07:11:36 darkbox frpc[142]: 2023/10/30 07:11:36 [W] [service.go:133] login to server failed: dial tcp: lookup scaleway.riaqn.org on 127.0.0.53:53: server misbehaving
Oct 30 07:11:36 darkbox frpc[142]: 2023/10/30 07:11:36 [I] [root.go:236] frpc service for config file [/etc/frp/frpc.ini] stopped
Oct 30 07:11:36 darkbox systemd[1]: frpc.service: Deactivated successfully.```
```

Output of `systemctl status frpc.service`:
```
   Main PID: 142 (code=exited, status=0/SUCCESS)
```

Exit code of the process should not be zero when due to errors. In particular, the restart mechanism of `systemd` relies on the exit code of frpc to decide if to restart. Sure, I can set `Restart=always` to restart even if exit code is zero, but this needs to be fixed.

### frpc Version

0.51.3

### frps Version

0.51.3

### System Architecture

linux/amd64

### Configurations

Doesn't matter.

### Logs

_No response_

### Steps to reproduce

1. 
2. 
3. 
...


### Affected area

- [ ] Docs
- [ ] Installation
- [ ] Performance and Scalability
- [ ] Security
- [ ] User Experience
- [ ] Test and Release
- [ ] Developer Infrastructure
- [ ] Client Plugin
- [ ] Server Plugin
- [ ] Extensions
- [ ] Others


Discussion / hints:

Fix patch:
diff --git a/Release.md b/Release.md
index 1660f1e19e2..16e8324b8dd 100644
--- a/Release.md
+++ b/Release.md
@@ -1,3 +1,3 @@
 ### Fixes
 
-* `admin_user` is not effective in the INI configuration.
+* frpc: Return code 1 when the first login attempt fails and exits.
diff --git a/client/service.go b/client/service.go
index 184a87a3305..4b394d8a163 100644
--- a/client/service.go
+++ b/client/service.go
@@ -83,8 +83,8 @@ func NewService(
 	pxyCfgs []v1.ProxyConfigurer,
 	visitorCfgs []v1.VisitorConfigurer,
 	cfgFile string,
-) (svr *Service, err error) {
-	svr = &Service{
+) *Service {
+	return &Service{
 		authSetter:  auth.NewAuthSetter(cfg.Auth),
 		cfg:         cfg,
 		cfgFile:     cfgFile,
@@ -93,7 +93,6 @@ func NewService(
 		ctx:         context.Background(),
 		exit:        0,
 	}
-	return
 }
 
 func (svr *Service) GetController() *Control {
diff --git a/cmd/frpc/sub/root.go b/cmd/frpc/sub/root.go
index 915e6b35174..125c88c05c4 100644
--- a/cmd/frpc/sub/root.go
+++ b/cmd/frpc/sub/root.go
@@ -139,10 +139,7 @@ func startService(
 		log.Info("start frpc service for config file [%s]", cfgFile)
 		defer log.Info("frpc service for config file [%s] stopped", cfgFile)
 	}
-	svr, err := client.NewService(cfg, pxyCfgs, visitorCfgs, cfgFile)
-	if err != nil {
-		return err
-	}
+	svr := client.NewService(cfg, pxyCfgs, visitorCfgs, cfgFile)
 
 	shouldGracefulClose := cfg.Transport.Protocol == "kcp" || cfg.Transport.Protocol == "quic"
 	// Capture the exit signal if we use kcp or quic.
@@ -150,6 +147,5 @@ func startService(
 		go handleTermSignal(svr)
 	}
 
-	_ = svr.Run(context.Background())
-	return nil
+	return svr.Run(context.Background())
 }


Test patch: