Feat: specify Openvpn flags with OPENVPN_FLAGS

This commit is contained in:
Quentin McGaw (desktop)
2021-07-19 15:10:53 +00:00
parent fd39bc8518
commit 394abbbe35
6 changed files with 25 additions and 5 deletions

View File

@@ -18,7 +18,7 @@ const (
binOpenvpn25 = "openvpn"
)
func (c *configurator) Start(ctx context.Context, version string) (
func (c *configurator) Start(ctx context.Context, version string, flags []string) (
stdoutLines, stderrLines chan string, waitError chan error, err error) {
var bin string
switch version {
@@ -32,7 +32,9 @@ func (c *configurator) Start(ctx context.Context, version string) (
c.logger.Info("starting OpenVPN " + version)
cmd := exec.CommandContext(ctx, bin, "--config", constants.OpenVPNConf)
args := []string{"--config", constants.OpenVPNConf}
args = append(args, flags...)
cmd := exec.CommandContext(ctx, bin, args...)
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
return c.commander.Start(cmd)

View File

@@ -169,7 +169,8 @@ func (l *looper) Run(ctx context.Context, done chan<- struct{}) {
openvpnCtx, openvpnCancel := context.WithCancel(context.Background())
stdoutLines, stderrLines, waitError, err := l.conf.Start(openvpnCtx, settings.Version)
stdoutLines, stderrLines, waitError, err := l.conf.Start(
openvpnCtx, settings.Version, settings.Flags)
if err != nil {
openvpnCancel()
l.signalOrSetStatus(constants.Crashed)

View File

@@ -17,7 +17,7 @@ type Configurator interface {
WriteAuthFile(user, password string, puid, pgid int) error
CheckTUN() error
CreateTUN() error
Start(ctx context.Context, version string) (
Start(ctx context.Context, version string, flags []string) (
stdoutLines, stderrLines chan string, waitError chan error, err error)
}