2018-02-07 19:02:18 +01:00
|
|
|
package ooni
|
|
|
|
|
|
|
|
import (
|
2021-04-05 15:28:13 +02:00
|
|
|
"context"
|
2021-03-02 12:08:24 +01:00
|
|
|
_ "embed" // because we embed a file
|
2018-02-07 19:02:18 +01:00
|
|
|
"io/ioutil"
|
2022-11-15 09:55:05 +01:00
|
|
|
"net/url"
|
2018-02-07 19:02:18 +01:00
|
|
|
"os"
|
Optionally treat EOF on stdin just like SIGTERM (#111)
* Optionally treat EOF on stdin just like SIGTERM
On Unix, Node.js allows us to gracefully kill a process. On Windows
this is more compex. You certainly cannot rely on the default `kill()`
function, which calls `TerminateProcess`.
There is a bunch of C/C++ extensions that in principle allow you to
attempt to gracefully shutdown a Windows process.
But, hey, here's a reality check. Node.js controls our stdin. Node.js
does IPC easy. Controlling uv_spawn flags and using the right not well maintained
C/C++ Node.js extension to kill a process is fragile.
So, treat EOF and any other error on stdin as equivalent to SIGTERM.
However, systemd.
The sane thing to do with systemd is `StandardInput=null`. With such
configuration, stdin immediately returns EOF.
Then, introduce the `OONI_STDIN_EOF_IMPLIES_SIGTERM` environment
variable. When it is `true`, this behaviour is enabled, e.g.:
```bash
export OONI_STDIN_EOF_IMPLIES_SIGTERM=true # behaviour enabled
ooniprobe run
```
I want the default to be disabled because:
1. in the future we may find a better way to solve this problem and I
don't want the _default behaviour_ to change in such case
2. we know we need this knob for ooniprobe-desktop, and we will not
fail to provide it, so it won't suprise/damage us
3. a person trying to write a systemd unit for ooniprobe would be very
surprised to find out they need to disable this behaviour, if it was
enabled by default by this PR
Hence, I believe this design is consistent with designing for the
future and for trying to minimize surprises.
Also, why an environment variable and not a command line flag? Because:
1. we don't want such hypothetical flag to be available where it does not
make sense, e.g., for all subcommands but `run`
2. we don't want the ooni/probe-desktop app to write conditional
code because it needs to check the command we're using and then decide
whether to add such hypothetical flag
Also, why not enabling this only on Windows? Because again we don't
want the ooni/probe-desktop app to write conditional code.
To summarize: we want ooni/probe-desktop app to see the same behaviour
everywhere and we want others to be the least surprised.
Related to https://github.com/ooni/probe/issues/1005
* Update ooni.go
2020-02-13 14:53:06 +01:00
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2018-02-07 19:02:18 +01:00
|
|
|
|
2018-02-12 16:45:13 +01:00
|
|
|
"github.com/apex/log"
|
2021-02-02 10:32:46 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/config"
|
|
|
|
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/utils"
|
refactor: flatten and separate (#353)
* refactor(atomicx): move outside the engine package
After merging probe-engine into probe-cli, my impression is that we have
too much unnecessary nesting of packages in this repository.
The idea of this commit and of a bunch of following commits will instead
be to reduce the nesting and simplify the structure.
While there, improve the documentation.
* fix: always use the atomicx package
For consistency, never use sync/atomic and always use ./internal/atomicx
so we can just grep and make sure we're not risking to crash if we make
a subtle mistake on a 32 bit platform.
While there, mention in the contributing guidelines that we want to
always prefer the ./internal/atomicx package over sync/atomic.
* fix(atomicx): remove unnecessary constructor
We don't need a constructor here. The default constructed `&Int64{}`
instance is already usable and the constructor does not add anything to
what we are doing, rather it just creates extra confusion.
* cleanup(atomicx): we are not using Float64
Because atomicx.Float64 is unused, we can safely zap it.
* cleanup(atomicx): simplify impl and improve tests
We can simplify the implementation by using defer and by letting
the Load() method call Add(0).
We can improve tests by making many goroutines updated the
atomic int64 value concurrently.
* refactor(fsx): can live in the ./internal pkg
Let us reduce the amount of nesting. While there, ensure that the
package only exports the bare minimum, and improve the documentation
of the tests, to ease reading the code.
* refactor: move runtimex to ./internal
* refactor: move shellx into the ./internal package
While there, remove unnecessary dependency between packages.
While there, specify in the contributing guidelines that
one should use x/sys/execabs instead of os/exec.
* refactor: move ooapi into the ./internal pkg
* refactor(humanize): move to ./internal and better docs
* refactor: move platform to ./internal
* refactor(randx): move to ./internal
* refactor(multierror): move into the ./internal pkg
* refactor(kvstore): all kvstores in ./internal
Rather than having part of the kvstore inside ./internal/engine/kvstore
and part in ./internal/engine/kvstore.go, let us put every piece of code
that is kvstore related into the ./internal/kvstore package.
* fix(kvstore): always return ErrNoSuchKey on Get() error
It should help to use the kvstore everywhere removing all the
copies that are lingering around the tree.
* sessionresolver: make KVStore mandatory
Simplifies implementation. While there, use the ./internal/kvstore
package rather than having our private implementation.
* fix(ooapi): use the ./internal/kvstore package
* fix(platform): better documentation
2021-06-04 10:34:18 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/atomicx"
|
2022-11-15 10:35:30 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/database"
|
refactor: flatten and separate (#353)
* refactor(atomicx): move outside the engine package
After merging probe-engine into probe-cli, my impression is that we have
too much unnecessary nesting of packages in this repository.
The idea of this commit and of a bunch of following commits will instead
be to reduce the nesting and simplify the structure.
While there, improve the documentation.
* fix: always use the atomicx package
For consistency, never use sync/atomic and always use ./internal/atomicx
so we can just grep and make sure we're not risking to crash if we make
a subtle mistake on a 32 bit platform.
While there, mention in the contributing guidelines that we want to
always prefer the ./internal/atomicx package over sync/atomic.
* fix(atomicx): remove unnecessary constructor
We don't need a constructor here. The default constructed `&Int64{}`
instance is already usable and the constructor does not add anything to
what we are doing, rather it just creates extra confusion.
* cleanup(atomicx): we are not using Float64
Because atomicx.Float64 is unused, we can safely zap it.
* cleanup(atomicx): simplify impl and improve tests
We can simplify the implementation by using defer and by letting
the Load() method call Add(0).
We can improve tests by making many goroutines updated the
atomic int64 value concurrently.
* refactor(fsx): can live in the ./internal pkg
Let us reduce the amount of nesting. While there, ensure that the
package only exports the bare minimum, and improve the documentation
of the tests, to ease reading the code.
* refactor: move runtimex to ./internal
* refactor: move shellx into the ./internal package
While there, remove unnecessary dependency between packages.
While there, specify in the contributing guidelines that
one should use x/sys/execabs instead of os/exec.
* refactor: move ooapi into the ./internal pkg
* refactor(humanize): move to ./internal and better docs
* refactor: move platform to ./internal
* refactor(randx): move to ./internal
* refactor(multierror): move into the ./internal pkg
* refactor(kvstore): all kvstores in ./internal
Rather than having part of the kvstore inside ./internal/engine/kvstore
and part in ./internal/engine/kvstore.go, let us put every piece of code
that is kvstore related into the ./internal/kvstore package.
* fix(kvstore): always return ErrNoSuchKey on Get() error
It should help to use the kvstore everywhere removing all the
copies that are lingering around the tree.
* sessionresolver: make KVStore mandatory
Simplifies implementation. While there, use the ./internal/kvstore
package rather than having our private implementation.
* fix(ooapi): use the ./internal/kvstore package
* fix(platform): better documentation
2021-06-04 10:34:18 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/kvstore"
|
2022-05-25 10:19:03 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/legacy/assetsdir"
|
2022-04-29 13:41:09 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
2018-02-07 19:02:18 +01:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2022-04-29 13:41:09 +02:00
|
|
|
// DefaultSoftwareName is the default software name.
|
|
|
|
const DefaultSoftwareName = "ooniprobe-cli"
|
|
|
|
|
2022-11-15 10:35:30 +01:00
|
|
|
// logger is the logger used by the engine.
|
|
|
|
var logger = log.WithFields(log.Fields{
|
|
|
|
"type": "engine",
|
|
|
|
})
|
|
|
|
|
2020-11-13 20:07:30 +01:00
|
|
|
// ProbeCLI is the OONI Probe CLI context.
|
|
|
|
type ProbeCLI interface {
|
|
|
|
Config() *config.Config
|
2022-11-16 15:51:41 +01:00
|
|
|
DB() *database.Database
|
2020-11-13 20:07:30 +01:00
|
|
|
IsBatch() bool
|
|
|
|
Home() string
|
|
|
|
TempDir() string
|
2022-04-29 13:41:09 +02:00
|
|
|
NewProbeEngine(ctx context.Context, runType model.RunType) (ProbeEngine, error)
|
2020-11-13 20:07:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ProbeEngine is an instance of the OONI Probe engine.
|
|
|
|
type ProbeEngine interface {
|
|
|
|
Close() error
|
|
|
|
MaybeLookupLocation() error
|
|
|
|
ProbeASNString() string
|
|
|
|
ProbeCC() string
|
|
|
|
ProbeIP() string
|
|
|
|
ProbeNetworkName() string
|
|
|
|
}
|
|
|
|
|
2020-11-13 19:01:06 +01:00
|
|
|
// Probe contains the ooniprobe CLI context.
|
|
|
|
type Probe struct {
|
2020-11-13 20:07:30 +01:00
|
|
|
config *config.Config
|
2022-11-16 15:51:41 +01:00
|
|
|
db *database.Database
|
2020-11-13 20:07:30 +01:00
|
|
|
isBatch bool
|
2018-03-23 12:41:06 +01:00
|
|
|
|
2021-04-05 11:27:41 +02:00
|
|
|
home string
|
|
|
|
tempDir string
|
|
|
|
tunnelDir string
|
2018-03-23 12:10:14 +01:00
|
|
|
|
|
|
|
dbPath string
|
|
|
|
configPath string
|
2019-12-27 11:32:08 +01:00
|
|
|
|
refactor: flatten and separate (#353)
* refactor(atomicx): move outside the engine package
After merging probe-engine into probe-cli, my impression is that we have
too much unnecessary nesting of packages in this repository.
The idea of this commit and of a bunch of following commits will instead
be to reduce the nesting and simplify the structure.
While there, improve the documentation.
* fix: always use the atomicx package
For consistency, never use sync/atomic and always use ./internal/atomicx
so we can just grep and make sure we're not risking to crash if we make
a subtle mistake on a 32 bit platform.
While there, mention in the contributing guidelines that we want to
always prefer the ./internal/atomicx package over sync/atomic.
* fix(atomicx): remove unnecessary constructor
We don't need a constructor here. The default constructed `&Int64{}`
instance is already usable and the constructor does not add anything to
what we are doing, rather it just creates extra confusion.
* cleanup(atomicx): we are not using Float64
Because atomicx.Float64 is unused, we can safely zap it.
* cleanup(atomicx): simplify impl and improve tests
We can simplify the implementation by using defer and by letting
the Load() method call Add(0).
We can improve tests by making many goroutines updated the
atomic int64 value concurrently.
* refactor(fsx): can live in the ./internal pkg
Let us reduce the amount of nesting. While there, ensure that the
package only exports the bare minimum, and improve the documentation
of the tests, to ease reading the code.
* refactor: move runtimex to ./internal
* refactor: move shellx into the ./internal package
While there, remove unnecessary dependency between packages.
While there, specify in the contributing guidelines that
one should use x/sys/execabs instead of os/exec.
* refactor: move ooapi into the ./internal pkg
* refactor(humanize): move to ./internal and better docs
* refactor: move platform to ./internal
* refactor(randx): move to ./internal
* refactor(multierror): move into the ./internal pkg
* refactor(kvstore): all kvstores in ./internal
Rather than having part of the kvstore inside ./internal/engine/kvstore
and part in ./internal/engine/kvstore.go, let us put every piece of code
that is kvstore related into the ./internal/kvstore package.
* fix(kvstore): always return ErrNoSuchKey on Get() error
It should help to use the kvstore everywhere removing all the
copies that are lingering around the tree.
* sessionresolver: make KVStore mandatory
Simplifies implementation. While there, use the ./internal/kvstore
package rather than having our private implementation.
* fix(ooapi): use the ./internal/kvstore package
* fix(platform): better documentation
2021-06-04 10:34:18 +02:00
|
|
|
isTerminated *atomicx.Int64
|
2018-02-12 16:45:13 +01:00
|
|
|
|
2020-06-04 11:19:38 +02:00
|
|
|
softwareName string
|
|
|
|
softwareVersion string
|
2022-11-15 09:55:05 +01:00
|
|
|
proxyURL *url.URL
|
2018-03-23 12:41:06 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 20:07:30 +01:00
|
|
|
// SetIsBatch sets the value of isBatch.
|
|
|
|
func (p *Probe) SetIsBatch(v bool) {
|
|
|
|
p.isBatch = v
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsBatch returns whether we're running in batch mode.
|
|
|
|
func (p *Probe) IsBatch() bool {
|
|
|
|
return p.isBatch
|
|
|
|
}
|
|
|
|
|
|
|
|
// Config returns the configuration
|
|
|
|
func (p *Probe) Config() *config.Config {
|
|
|
|
return p.config
|
|
|
|
}
|
|
|
|
|
|
|
|
// DB returns the database we're using
|
2022-11-16 15:51:41 +01:00
|
|
|
func (p *Probe) DB() *database.Database {
|
2020-11-13 20:07:30 +01:00
|
|
|
return p.db
|
|
|
|
}
|
|
|
|
|
|
|
|
// Home returns the home directory.
|
|
|
|
func (p *Probe) Home() string {
|
|
|
|
return p.home
|
|
|
|
}
|
|
|
|
|
|
|
|
// TempDir returns the temporary directory.
|
|
|
|
func (p *Probe) TempDir() string {
|
|
|
|
return p.tempDir
|
|
|
|
}
|
|
|
|
|
2019-12-27 11:32:08 +01:00
|
|
|
// IsTerminated checks to see if the isTerminatedAtomicInt is set to a non zero
|
|
|
|
// value and therefore we have received the signal to shutdown the running test
|
2020-11-13 19:01:06 +01:00
|
|
|
func (p *Probe) IsTerminated() bool {
|
refactor: flatten and separate (#353)
* refactor(atomicx): move outside the engine package
After merging probe-engine into probe-cli, my impression is that we have
too much unnecessary nesting of packages in this repository.
The idea of this commit and of a bunch of following commits will instead
be to reduce the nesting and simplify the structure.
While there, improve the documentation.
* fix: always use the atomicx package
For consistency, never use sync/atomic and always use ./internal/atomicx
so we can just grep and make sure we're not risking to crash if we make
a subtle mistake on a 32 bit platform.
While there, mention in the contributing guidelines that we want to
always prefer the ./internal/atomicx package over sync/atomic.
* fix(atomicx): remove unnecessary constructor
We don't need a constructor here. The default constructed `&Int64{}`
instance is already usable and the constructor does not add anything to
what we are doing, rather it just creates extra confusion.
* cleanup(atomicx): we are not using Float64
Because atomicx.Float64 is unused, we can safely zap it.
* cleanup(atomicx): simplify impl and improve tests
We can simplify the implementation by using defer and by letting
the Load() method call Add(0).
We can improve tests by making many goroutines updated the
atomic int64 value concurrently.
* refactor(fsx): can live in the ./internal pkg
Let us reduce the amount of nesting. While there, ensure that the
package only exports the bare minimum, and improve the documentation
of the tests, to ease reading the code.
* refactor: move runtimex to ./internal
* refactor: move shellx into the ./internal package
While there, remove unnecessary dependency between packages.
While there, specify in the contributing guidelines that
one should use x/sys/execabs instead of os/exec.
* refactor: move ooapi into the ./internal pkg
* refactor(humanize): move to ./internal and better docs
* refactor: move platform to ./internal
* refactor(randx): move to ./internal
* refactor(multierror): move into the ./internal pkg
* refactor(kvstore): all kvstores in ./internal
Rather than having part of the kvstore inside ./internal/engine/kvstore
and part in ./internal/engine/kvstore.go, let us put every piece of code
that is kvstore related into the ./internal/kvstore package.
* fix(kvstore): always return ErrNoSuchKey on Get() error
It should help to use the kvstore everywhere removing all the
copies that are lingering around the tree.
* sessionresolver: make KVStore mandatory
Simplifies implementation. While there, use the ./internal/kvstore
package rather than having our private implementation.
* fix(ooapi): use the ./internal/kvstore package
* fix(platform): better documentation
2021-06-04 10:34:18 +02:00
|
|
|
return p.isTerminated.Load() != 0
|
2019-12-27 11:32:08 +01:00
|
|
|
}
|
|
|
|
|
2019-12-29 14:07:57 +01:00
|
|
|
// Terminate interrupts the running context
|
2020-11-13 19:01:06 +01:00
|
|
|
func (p *Probe) Terminate() {
|
refactor: flatten and separate (#353)
* refactor(atomicx): move outside the engine package
After merging probe-engine into probe-cli, my impression is that we have
too much unnecessary nesting of packages in this repository.
The idea of this commit and of a bunch of following commits will instead
be to reduce the nesting and simplify the structure.
While there, improve the documentation.
* fix: always use the atomicx package
For consistency, never use sync/atomic and always use ./internal/atomicx
so we can just grep and make sure we're not risking to crash if we make
a subtle mistake on a 32 bit platform.
While there, mention in the contributing guidelines that we want to
always prefer the ./internal/atomicx package over sync/atomic.
* fix(atomicx): remove unnecessary constructor
We don't need a constructor here. The default constructed `&Int64{}`
instance is already usable and the constructor does not add anything to
what we are doing, rather it just creates extra confusion.
* cleanup(atomicx): we are not using Float64
Because atomicx.Float64 is unused, we can safely zap it.
* cleanup(atomicx): simplify impl and improve tests
We can simplify the implementation by using defer and by letting
the Load() method call Add(0).
We can improve tests by making many goroutines updated the
atomic int64 value concurrently.
* refactor(fsx): can live in the ./internal pkg
Let us reduce the amount of nesting. While there, ensure that the
package only exports the bare minimum, and improve the documentation
of the tests, to ease reading the code.
* refactor: move runtimex to ./internal
* refactor: move shellx into the ./internal package
While there, remove unnecessary dependency between packages.
While there, specify in the contributing guidelines that
one should use x/sys/execabs instead of os/exec.
* refactor: move ooapi into the ./internal pkg
* refactor(humanize): move to ./internal and better docs
* refactor: move platform to ./internal
* refactor(randx): move to ./internal
* refactor(multierror): move into the ./internal pkg
* refactor(kvstore): all kvstores in ./internal
Rather than having part of the kvstore inside ./internal/engine/kvstore
and part in ./internal/engine/kvstore.go, let us put every piece of code
that is kvstore related into the ./internal/kvstore package.
* fix(kvstore): always return ErrNoSuchKey on Get() error
It should help to use the kvstore everywhere removing all the
copies that are lingering around the tree.
* sessionresolver: make KVStore mandatory
Simplifies implementation. While there, use the ./internal/kvstore
package rather than having our private implementation.
* fix(ooapi): use the ./internal/kvstore package
* fix(platform): better documentation
2021-06-04 10:34:18 +02:00
|
|
|
p.isTerminated.Add(1)
|
2019-12-27 11:32:08 +01:00
|
|
|
}
|
|
|
|
|
Optionally treat EOF on stdin just like SIGTERM (#111)
* Optionally treat EOF on stdin just like SIGTERM
On Unix, Node.js allows us to gracefully kill a process. On Windows
this is more compex. You certainly cannot rely on the default `kill()`
function, which calls `TerminateProcess`.
There is a bunch of C/C++ extensions that in principle allow you to
attempt to gracefully shutdown a Windows process.
But, hey, here's a reality check. Node.js controls our stdin. Node.js
does IPC easy. Controlling uv_spawn flags and using the right not well maintained
C/C++ Node.js extension to kill a process is fragile.
So, treat EOF and any other error on stdin as equivalent to SIGTERM.
However, systemd.
The sane thing to do with systemd is `StandardInput=null`. With such
configuration, stdin immediately returns EOF.
Then, introduce the `OONI_STDIN_EOF_IMPLIES_SIGTERM` environment
variable. When it is `true`, this behaviour is enabled, e.g.:
```bash
export OONI_STDIN_EOF_IMPLIES_SIGTERM=true # behaviour enabled
ooniprobe run
```
I want the default to be disabled because:
1. in the future we may find a better way to solve this problem and I
don't want the _default behaviour_ to change in such case
2. we know we need this knob for ooniprobe-desktop, and we will not
fail to provide it, so it won't suprise/damage us
3. a person trying to write a systemd unit for ooniprobe would be very
surprised to find out they need to disable this behaviour, if it was
enabled by default by this PR
Hence, I believe this design is consistent with designing for the
future and for trying to minimize surprises.
Also, why an environment variable and not a command line flag? Because:
1. we don't want such hypothetical flag to be available where it does not
make sense, e.g., for all subcommands but `run`
2. we don't want the ooni/probe-desktop app to write conditional
code because it needs to check the command we're using and then decide
whether to add such hypothetical flag
Also, why not enabling this only on Windows? Because again we don't
want the ooni/probe-desktop app to write conditional code.
To summarize: we want ooni/probe-desktop app to see the same behaviour
everywhere and we want others to be the least surprised.
Related to https://github.com/ooni/probe/issues/1005
* Update ooni.go
2020-02-13 14:53:06 +01:00
|
|
|
// ListenForSignals will listen for SIGINT and SIGTERM. When it receives those
|
|
|
|
// signals it will set isTerminatedAtomicInt to non-zero, which will cleanly
|
|
|
|
// shutdown the test logic.
|
|
|
|
//
|
|
|
|
// TODO refactor this to use a cancellable context.Context instead of a bool
|
|
|
|
// flag, probably as part of: https://github.com/ooni/probe-cli/issues/45
|
2020-11-13 19:01:06 +01:00
|
|
|
func (p *Probe) ListenForSignals() {
|
Optionally treat EOF on stdin just like SIGTERM (#111)
* Optionally treat EOF on stdin just like SIGTERM
On Unix, Node.js allows us to gracefully kill a process. On Windows
this is more compex. You certainly cannot rely on the default `kill()`
function, which calls `TerminateProcess`.
There is a bunch of C/C++ extensions that in principle allow you to
attempt to gracefully shutdown a Windows process.
But, hey, here's a reality check. Node.js controls our stdin. Node.js
does IPC easy. Controlling uv_spawn flags and using the right not well maintained
C/C++ Node.js extension to kill a process is fragile.
So, treat EOF and any other error on stdin as equivalent to SIGTERM.
However, systemd.
The sane thing to do with systemd is `StandardInput=null`. With such
configuration, stdin immediately returns EOF.
Then, introduce the `OONI_STDIN_EOF_IMPLIES_SIGTERM` environment
variable. When it is `true`, this behaviour is enabled, e.g.:
```bash
export OONI_STDIN_EOF_IMPLIES_SIGTERM=true # behaviour enabled
ooniprobe run
```
I want the default to be disabled because:
1. in the future we may find a better way to solve this problem and I
don't want the _default behaviour_ to change in such case
2. we know we need this knob for ooniprobe-desktop, and we will not
fail to provide it, so it won't suprise/damage us
3. a person trying to write a systemd unit for ooniprobe would be very
surprised to find out they need to disable this behaviour, if it was
enabled by default by this PR
Hence, I believe this design is consistent with designing for the
future and for trying to minimize surprises.
Also, why an environment variable and not a command line flag? Because:
1. we don't want such hypothetical flag to be available where it does not
make sense, e.g., for all subcommands but `run`
2. we don't want the ooni/probe-desktop app to write conditional
code because it needs to check the command we're using and then decide
whether to add such hypothetical flag
Also, why not enabling this only on Windows? Because again we don't
want the ooni/probe-desktop app to write conditional code.
To summarize: we want ooni/probe-desktop app to see the same behaviour
everywhere and we want others to be the least surprised.
Related to https://github.com/ooni/probe/issues/1005
* Update ooni.go
2020-02-13 14:53:06 +01:00
|
|
|
s := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(s, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
go func() {
|
|
|
|
<-s
|
|
|
|
log.Info("caught a stop signal, shutting down cleanly")
|
2020-11-13 19:01:06 +01:00
|
|
|
p.Terminate()
|
Optionally treat EOF on stdin just like SIGTERM (#111)
* Optionally treat EOF on stdin just like SIGTERM
On Unix, Node.js allows us to gracefully kill a process. On Windows
this is more compex. You certainly cannot rely on the default `kill()`
function, which calls `TerminateProcess`.
There is a bunch of C/C++ extensions that in principle allow you to
attempt to gracefully shutdown a Windows process.
But, hey, here's a reality check. Node.js controls our stdin. Node.js
does IPC easy. Controlling uv_spawn flags and using the right not well maintained
C/C++ Node.js extension to kill a process is fragile.
So, treat EOF and any other error on stdin as equivalent to SIGTERM.
However, systemd.
The sane thing to do with systemd is `StandardInput=null`. With such
configuration, stdin immediately returns EOF.
Then, introduce the `OONI_STDIN_EOF_IMPLIES_SIGTERM` environment
variable. When it is `true`, this behaviour is enabled, e.g.:
```bash
export OONI_STDIN_EOF_IMPLIES_SIGTERM=true # behaviour enabled
ooniprobe run
```
I want the default to be disabled because:
1. in the future we may find a better way to solve this problem and I
don't want the _default behaviour_ to change in such case
2. we know we need this knob for ooniprobe-desktop, and we will not
fail to provide it, so it won't suprise/damage us
3. a person trying to write a systemd unit for ooniprobe would be very
surprised to find out they need to disable this behaviour, if it was
enabled by default by this PR
Hence, I believe this design is consistent with designing for the
future and for trying to minimize surprises.
Also, why an environment variable and not a command line flag? Because:
1. we don't want such hypothetical flag to be available where it does not
make sense, e.g., for all subcommands but `run`
2. we don't want the ooni/probe-desktop app to write conditional
code because it needs to check the command we're using and then decide
whether to add such hypothetical flag
Also, why not enabling this only on Windows? Because again we don't
want the ooni/probe-desktop app to write conditional code.
To summarize: we want ooni/probe-desktop app to see the same behaviour
everywhere and we want others to be the least surprised.
Related to https://github.com/ooni/probe/issues/1005
* Update ooni.go
2020-02-13 14:53:06 +01:00
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
// MaybeListenForStdinClosed will treat any error on stdin just
|
|
|
|
// like SIGTERM if and only if
|
|
|
|
//
|
2022-11-15 09:55:05 +01:00
|
|
|
// os.Getenv("OONI_STDIN_EOF_IMPLIES_SIGTERM") == "true"
|
Optionally treat EOF on stdin just like SIGTERM (#111)
* Optionally treat EOF on stdin just like SIGTERM
On Unix, Node.js allows us to gracefully kill a process. On Windows
this is more compex. You certainly cannot rely on the default `kill()`
function, which calls `TerminateProcess`.
There is a bunch of C/C++ extensions that in principle allow you to
attempt to gracefully shutdown a Windows process.
But, hey, here's a reality check. Node.js controls our stdin. Node.js
does IPC easy. Controlling uv_spawn flags and using the right not well maintained
C/C++ Node.js extension to kill a process is fragile.
So, treat EOF and any other error on stdin as equivalent to SIGTERM.
However, systemd.
The sane thing to do with systemd is `StandardInput=null`. With such
configuration, stdin immediately returns EOF.
Then, introduce the `OONI_STDIN_EOF_IMPLIES_SIGTERM` environment
variable. When it is `true`, this behaviour is enabled, e.g.:
```bash
export OONI_STDIN_EOF_IMPLIES_SIGTERM=true # behaviour enabled
ooniprobe run
```
I want the default to be disabled because:
1. in the future we may find a better way to solve this problem and I
don't want the _default behaviour_ to change in such case
2. we know we need this knob for ooniprobe-desktop, and we will not
fail to provide it, so it won't suprise/damage us
3. a person trying to write a systemd unit for ooniprobe would be very
surprised to find out they need to disable this behaviour, if it was
enabled by default by this PR
Hence, I believe this design is consistent with designing for the
future and for trying to minimize surprises.
Also, why an environment variable and not a command line flag? Because:
1. we don't want such hypothetical flag to be available where it does not
make sense, e.g., for all subcommands but `run`
2. we don't want the ooni/probe-desktop app to write conditional
code because it needs to check the command we're using and then decide
whether to add such hypothetical flag
Also, why not enabling this only on Windows? Because again we don't
want the ooni/probe-desktop app to write conditional code.
To summarize: we want ooni/probe-desktop app to see the same behaviour
everywhere and we want others to be the least surprised.
Related to https://github.com/ooni/probe/issues/1005
* Update ooni.go
2020-02-13 14:53:06 +01:00
|
|
|
//
|
|
|
|
// When this feature is enabled, a collateral effect is that we swallow
|
|
|
|
// whatever is passed to us on the standard input.
|
|
|
|
//
|
|
|
|
// See https://github.com/ooni/probe-cli/pull/111 for more info
|
|
|
|
// regarding the design of this functionality.
|
|
|
|
//
|
|
|
|
// TODO refactor this to use a cancellable context.Context instead of a bool
|
|
|
|
// flag, probably as part of: https://github.com/ooni/probe-cli/issues/45
|
2020-11-13 19:01:06 +01:00
|
|
|
func (p *Probe) MaybeListenForStdinClosed() {
|
Optionally treat EOF on stdin just like SIGTERM (#111)
* Optionally treat EOF on stdin just like SIGTERM
On Unix, Node.js allows us to gracefully kill a process. On Windows
this is more compex. You certainly cannot rely on the default `kill()`
function, which calls `TerminateProcess`.
There is a bunch of C/C++ extensions that in principle allow you to
attempt to gracefully shutdown a Windows process.
But, hey, here's a reality check. Node.js controls our stdin. Node.js
does IPC easy. Controlling uv_spawn flags and using the right not well maintained
C/C++ Node.js extension to kill a process is fragile.
So, treat EOF and any other error on stdin as equivalent to SIGTERM.
However, systemd.
The sane thing to do with systemd is `StandardInput=null`. With such
configuration, stdin immediately returns EOF.
Then, introduce the `OONI_STDIN_EOF_IMPLIES_SIGTERM` environment
variable. When it is `true`, this behaviour is enabled, e.g.:
```bash
export OONI_STDIN_EOF_IMPLIES_SIGTERM=true # behaviour enabled
ooniprobe run
```
I want the default to be disabled because:
1. in the future we may find a better way to solve this problem and I
don't want the _default behaviour_ to change in such case
2. we know we need this knob for ooniprobe-desktop, and we will not
fail to provide it, so it won't suprise/damage us
3. a person trying to write a systemd unit for ooniprobe would be very
surprised to find out they need to disable this behaviour, if it was
enabled by default by this PR
Hence, I believe this design is consistent with designing for the
future and for trying to minimize surprises.
Also, why an environment variable and not a command line flag? Because:
1. we don't want such hypothetical flag to be available where it does not
make sense, e.g., for all subcommands but `run`
2. we don't want the ooni/probe-desktop app to write conditional
code because it needs to check the command we're using and then decide
whether to add such hypothetical flag
Also, why not enabling this only on Windows? Because again we don't
want the ooni/probe-desktop app to write conditional code.
To summarize: we want ooni/probe-desktop app to see the same behaviour
everywhere and we want others to be the least surprised.
Related to https://github.com/ooni/probe/issues/1005
* Update ooni.go
2020-02-13 14:53:06 +01:00
|
|
|
if os.Getenv("OONI_STDIN_EOF_IMPLIES_SIGTERM") != "true" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
go func() {
|
2020-11-13 19:01:06 +01:00
|
|
|
defer p.Terminate()
|
Optionally treat EOF on stdin just like SIGTERM (#111)
* Optionally treat EOF on stdin just like SIGTERM
On Unix, Node.js allows us to gracefully kill a process. On Windows
this is more compex. You certainly cannot rely on the default `kill()`
function, which calls `TerminateProcess`.
There is a bunch of C/C++ extensions that in principle allow you to
attempt to gracefully shutdown a Windows process.
But, hey, here's a reality check. Node.js controls our stdin. Node.js
does IPC easy. Controlling uv_spawn flags and using the right not well maintained
C/C++ Node.js extension to kill a process is fragile.
So, treat EOF and any other error on stdin as equivalent to SIGTERM.
However, systemd.
The sane thing to do with systemd is `StandardInput=null`. With such
configuration, stdin immediately returns EOF.
Then, introduce the `OONI_STDIN_EOF_IMPLIES_SIGTERM` environment
variable. When it is `true`, this behaviour is enabled, e.g.:
```bash
export OONI_STDIN_EOF_IMPLIES_SIGTERM=true # behaviour enabled
ooniprobe run
```
I want the default to be disabled because:
1. in the future we may find a better way to solve this problem and I
don't want the _default behaviour_ to change in such case
2. we know we need this knob for ooniprobe-desktop, and we will not
fail to provide it, so it won't suprise/damage us
3. a person trying to write a systemd unit for ooniprobe would be very
surprised to find out they need to disable this behaviour, if it was
enabled by default by this PR
Hence, I believe this design is consistent with designing for the
future and for trying to minimize surprises.
Also, why an environment variable and not a command line flag? Because:
1. we don't want such hypothetical flag to be available where it does not
make sense, e.g., for all subcommands but `run`
2. we don't want the ooni/probe-desktop app to write conditional
code because it needs to check the command we're using and then decide
whether to add such hypothetical flag
Also, why not enabling this only on Windows? Because again we don't
want the ooni/probe-desktop app to write conditional code.
To summarize: we want ooni/probe-desktop app to see the same behaviour
everywhere and we want others to be the least surprised.
Related to https://github.com/ooni/probe/issues/1005
* Update ooni.go
2020-02-13 14:53:06 +01:00
|
|
|
defer log.Info("stdin closed, shutting down cleanly")
|
|
|
|
b := make([]byte, 1<<10)
|
|
|
|
for {
|
|
|
|
if _, err := os.Stdin.Read(b); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2018-02-12 16:45:13 +01:00
|
|
|
// Init the OONI manager
|
2022-11-15 09:55:05 +01:00
|
|
|
func (p *Probe) Init(softwareName, softwareVersion, proxy string) error {
|
2018-03-23 12:10:14 +01:00
|
|
|
var err error
|
|
|
|
|
2020-11-13 20:07:30 +01:00
|
|
|
if err = MaybeInitializeHome(p.home); err != nil {
|
2018-03-23 12:10:14 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-13 19:01:06 +01:00
|
|
|
if p.configPath != "" {
|
|
|
|
log.Debugf("Reading config file from %s", p.configPath)
|
2020-11-13 20:07:30 +01:00
|
|
|
p.config, err = config.ReadConfig(p.configPath)
|
2018-03-23 12:10:14 +01:00
|
|
|
} else {
|
|
|
|
log.Debug("Reading default config file")
|
2020-11-13 20:07:30 +01:00
|
|
|
p.config, err = InitDefaultConfig(p.home)
|
2018-03-23 12:10:14 +01:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-13 20:07:30 +01:00
|
|
|
if err = p.config.MaybeMigrate(); err != nil {
|
2019-11-14 17:58:31 +01:00
|
|
|
return errors.Wrap(err, "migrating config")
|
|
|
|
}
|
2018-03-23 12:10:14 +01:00
|
|
|
|
2020-11-13 20:07:30 +01:00
|
|
|
p.dbPath = utils.DBDir(p.home, "main")
|
2020-11-13 19:01:06 +01:00
|
|
|
log.Debugf("Connecting to database sqlite3://%s", p.dbPath)
|
2022-11-16 15:51:41 +01:00
|
|
|
db, err := database.Open(p.dbPath)
|
2018-03-23 12:10:14 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-13 20:07:30 +01:00
|
|
|
p.db = db
|
2018-03-23 12:10:14 +01:00
|
|
|
|
2021-04-01 16:57:31 +02:00
|
|
|
// We cleanup the assets files used by versions of ooniprobe
|
|
|
|
// older than v3.9.0, where we started embedding the assets
|
|
|
|
// into the binary and use that directly. This cleanup doesn't
|
|
|
|
// remove the whole directory but only known files inside it
|
|
|
|
// and then the directory itself, if empty. We explicitly discard
|
|
|
|
// the return value as it does not matter to us here.
|
|
|
|
_, _ = assetsdir.Cleanup(utils.AssetsDir(p.home))
|
|
|
|
|
2018-03-19 13:20:42 +01:00
|
|
|
tempDir, err := ioutil.TempDir("", "ooni")
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "creating TempDir")
|
|
|
|
}
|
2020-11-13 20:07:30 +01:00
|
|
|
p.tempDir = tempDir
|
2022-02-11 12:57:54 +01:00
|
|
|
p.tunnelDir = utils.TunnelDir(p.home)
|
2018-03-19 13:20:42 +01:00
|
|
|
|
2020-11-13 19:01:06 +01:00
|
|
|
p.softwareName = softwareName
|
|
|
|
p.softwareVersion = softwareVersion
|
2022-11-15 09:55:05 +01:00
|
|
|
if proxy != "" {
|
|
|
|
p.proxyURL, err = url.Parse(proxy)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "invalid proxy URL")
|
|
|
|
}
|
|
|
|
}
|
2020-06-04 11:19:38 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewSession creates a new ooni/probe-engine session using the
|
|
|
|
// current configuration inside the context. The caller must close
|
|
|
|
// the session when done using it, by calling sess.Close().
|
2022-04-29 13:41:09 +02:00
|
|
|
func (p *Probe) NewSession(ctx context.Context, runType model.RunType) (*engine.Session, error) {
|
refactor: flatten and separate (#353)
* refactor(atomicx): move outside the engine package
After merging probe-engine into probe-cli, my impression is that we have
too much unnecessary nesting of packages in this repository.
The idea of this commit and of a bunch of following commits will instead
be to reduce the nesting and simplify the structure.
While there, improve the documentation.
* fix: always use the atomicx package
For consistency, never use sync/atomic and always use ./internal/atomicx
so we can just grep and make sure we're not risking to crash if we make
a subtle mistake on a 32 bit platform.
While there, mention in the contributing guidelines that we want to
always prefer the ./internal/atomicx package over sync/atomic.
* fix(atomicx): remove unnecessary constructor
We don't need a constructor here. The default constructed `&Int64{}`
instance is already usable and the constructor does not add anything to
what we are doing, rather it just creates extra confusion.
* cleanup(atomicx): we are not using Float64
Because atomicx.Float64 is unused, we can safely zap it.
* cleanup(atomicx): simplify impl and improve tests
We can simplify the implementation by using defer and by letting
the Load() method call Add(0).
We can improve tests by making many goroutines updated the
atomic int64 value concurrently.
* refactor(fsx): can live in the ./internal pkg
Let us reduce the amount of nesting. While there, ensure that the
package only exports the bare minimum, and improve the documentation
of the tests, to ease reading the code.
* refactor: move runtimex to ./internal
* refactor: move shellx into the ./internal package
While there, remove unnecessary dependency between packages.
While there, specify in the contributing guidelines that
one should use x/sys/execabs instead of os/exec.
* refactor: move ooapi into the ./internal pkg
* refactor(humanize): move to ./internal and better docs
* refactor: move platform to ./internal
* refactor(randx): move to ./internal
* refactor(multierror): move into the ./internal pkg
* refactor(kvstore): all kvstores in ./internal
Rather than having part of the kvstore inside ./internal/engine/kvstore
and part in ./internal/engine/kvstore.go, let us put every piece of code
that is kvstore related into the ./internal/kvstore package.
* fix(kvstore): always return ErrNoSuchKey on Get() error
It should help to use the kvstore everywhere removing all the
copies that are lingering around the tree.
* sessionresolver: make KVStore mandatory
Simplifies implementation. While there, use the ./internal/kvstore
package rather than having our private implementation.
* fix(ooapi): use the ./internal/kvstore package
* fix(platform): better documentation
2021-06-04 10:34:18 +02:00
|
|
|
kvstore, err := kvstore.NewFS(
|
2020-11-13 20:07:30 +01:00
|
|
|
utils.EngineDir(p.home),
|
2019-12-28 17:48:07 +01:00
|
|
|
)
|
|
|
|
if err != nil {
|
2020-06-04 11:19:38 +02:00
|
|
|
return nil, errors.Wrap(err, "creating engine's kvstore")
|
2019-12-28 17:48:07 +01:00
|
|
|
}
|
2022-02-11 12:57:54 +01:00
|
|
|
if err := os.MkdirAll(p.tunnelDir, 0700); err != nil {
|
2021-04-05 11:27:41 +02:00
|
|
|
return nil, errors.Wrap(err, "creating tunnel dir")
|
|
|
|
}
|
2022-04-29 13:41:09 +02:00
|
|
|
// When the software name is the default software name and we're running
|
|
|
|
// in unattended mode, adjust the software name accordingly.
|
|
|
|
//
|
|
|
|
// See https://github.com/ooni/probe/issues/2081.
|
|
|
|
softwareName := p.softwareName
|
|
|
|
if runType == model.RunTypeTimed && softwareName == DefaultSoftwareName {
|
|
|
|
softwareName = DefaultSoftwareName + "-unattended"
|
|
|
|
}
|
2021-04-05 15:28:13 +02:00
|
|
|
return engine.NewSession(ctx, engine.SessionConfig{
|
2020-11-26 18:48:20 +01:00
|
|
|
KVStore: kvstore,
|
2022-11-15 10:35:30 +01:00
|
|
|
Logger: logger,
|
2022-04-29 13:41:09 +02:00
|
|
|
SoftwareName: softwareName,
|
2020-11-13 19:01:06 +01:00
|
|
|
SoftwareVersion: p.softwareVersion,
|
2020-11-13 20:07:30 +01:00
|
|
|
TempDir: p.tempDir,
|
2021-04-05 11:27:41 +02:00
|
|
|
TunnelDir: p.tunnelDir,
|
2022-11-15 09:55:05 +01:00
|
|
|
ProxyURL: p.proxyURL,
|
2019-10-28 14:05:05 +01:00
|
|
|
})
|
2018-02-12 16:45:13 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 20:07:30 +01:00
|
|
|
// NewProbeEngine creates a new ProbeEngine instance.
|
2022-04-29 13:41:09 +02:00
|
|
|
func (p *Probe) NewProbeEngine(ctx context.Context, runType model.RunType) (ProbeEngine, error) {
|
|
|
|
sess, err := p.NewSession(ctx, runType)
|
2020-11-13 20:07:30 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return sess, nil
|
|
|
|
}
|
|
|
|
|
2020-11-13 19:01:06 +01:00
|
|
|
// NewProbe creates a new probe instance.
|
|
|
|
func NewProbe(configPath string, homePath string) *Probe {
|
|
|
|
return &Probe{
|
refactor: flatten and separate (#353)
* refactor(atomicx): move outside the engine package
After merging probe-engine into probe-cli, my impression is that we have
too much unnecessary nesting of packages in this repository.
The idea of this commit and of a bunch of following commits will instead
be to reduce the nesting and simplify the structure.
While there, improve the documentation.
* fix: always use the atomicx package
For consistency, never use sync/atomic and always use ./internal/atomicx
so we can just grep and make sure we're not risking to crash if we make
a subtle mistake on a 32 bit platform.
While there, mention in the contributing guidelines that we want to
always prefer the ./internal/atomicx package over sync/atomic.
* fix(atomicx): remove unnecessary constructor
We don't need a constructor here. The default constructed `&Int64{}`
instance is already usable and the constructor does not add anything to
what we are doing, rather it just creates extra confusion.
* cleanup(atomicx): we are not using Float64
Because atomicx.Float64 is unused, we can safely zap it.
* cleanup(atomicx): simplify impl and improve tests
We can simplify the implementation by using defer and by letting
the Load() method call Add(0).
We can improve tests by making many goroutines updated the
atomic int64 value concurrently.
* refactor(fsx): can live in the ./internal pkg
Let us reduce the amount of nesting. While there, ensure that the
package only exports the bare minimum, and improve the documentation
of the tests, to ease reading the code.
* refactor: move runtimex to ./internal
* refactor: move shellx into the ./internal package
While there, remove unnecessary dependency between packages.
While there, specify in the contributing guidelines that
one should use x/sys/execabs instead of os/exec.
* refactor: move ooapi into the ./internal pkg
* refactor(humanize): move to ./internal and better docs
* refactor: move platform to ./internal
* refactor(randx): move to ./internal
* refactor(multierror): move into the ./internal pkg
* refactor(kvstore): all kvstores in ./internal
Rather than having part of the kvstore inside ./internal/engine/kvstore
and part in ./internal/engine/kvstore.go, let us put every piece of code
that is kvstore related into the ./internal/kvstore package.
* fix(kvstore): always return ErrNoSuchKey on Get() error
It should help to use the kvstore everywhere removing all the
copies that are lingering around the tree.
* sessionresolver: make KVStore mandatory
Simplifies implementation. While there, use the ./internal/kvstore
package rather than having our private implementation.
* fix(ooapi): use the ./internal/kvstore package
* fix(platform): better documentation
2021-06-04 10:34:18 +02:00
|
|
|
home: homePath,
|
|
|
|
config: &config.Config{},
|
|
|
|
configPath: configPath,
|
|
|
|
isTerminated: &atomicx.Int64{},
|
2018-02-12 16:45:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-23 15:38:25 +01:00
|
|
|
// MaybeInitializeHome does the setup for a new OONI Home
|
|
|
|
func MaybeInitializeHome(home string) error {
|
2018-03-27 15:09:34 +02:00
|
|
|
for _, d := range utils.RequiredDirs(home) {
|
|
|
|
if _, e := os.Stat(d); e != nil {
|
|
|
|
if err := os.MkdirAll(d, 0700); err != nil {
|
2018-03-23 12:10:14 +01:00
|
|
|
return err
|
2018-03-19 13:20:42 +01:00
|
|
|
}
|
2018-03-08 20:46:31 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-23 12:10:14 +01:00
|
|
|
return nil
|
2018-03-08 20:46:31 +01:00
|
|
|
}
|
|
|
|
|
2021-03-02 12:08:24 +01:00
|
|
|
//go:embed default-config.json
|
|
|
|
var defaultConfig []byte
|
|
|
|
|
2018-06-25 17:49:17 +02:00
|
|
|
// InitDefaultConfig reads the config from common locations or creates it if
|
|
|
|
// missing.
|
|
|
|
func InitDefaultConfig(home string) (*config.Config, error) {
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
c *config.Config
|
|
|
|
configPath = utils.ConfigPath(home)
|
|
|
|
)
|
|
|
|
|
|
|
|
c, err = config.ReadConfig(configPath)
|
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
log.Debugf("writing default config to %s", configPath)
|
2021-06-15 14:01:45 +02:00
|
|
|
if err = os.WriteFile(configPath, defaultConfig, 0644); err != nil {
|
2018-02-12 16:45:13 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
2021-01-08 14:14:14 +01:00
|
|
|
// If the user did the informed consent procedure in
|
|
|
|
// probe-legacy, migrate it over.
|
|
|
|
if utils.DidLegacyInformedConsent() {
|
|
|
|
c, err := config.ReadConfig(configPath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
c.Lock()
|
|
|
|
c.InformedConsent = true
|
|
|
|
c.Unlock()
|
|
|
|
if err := c.Write(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:49:17 +02:00
|
|
|
return InitDefaultConfig(home)
|
2018-02-12 16:45:13 +01:00
|
|
|
}
|
2018-06-25 17:49:17 +02:00
|
|
|
return nil, err
|
2018-02-12 16:45:13 +01:00
|
|
|
}
|
2018-03-08 11:25:40 +01:00
|
|
|
|
2018-06-25 17:49:17 +02:00
|
|
|
return c, nil
|
2018-02-07 19:02:18 +01:00
|
|
|
}
|