Skip to content

Commit cf749c0

Browse files
committed
log: always use poiner receiver
1 parent e37bb1e commit cf749c0

File tree

97 files changed

+217
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+217
-200
lines changed

awsinteg/kinesis.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func NewKinesisHoseClient() (*KinesisHoseClient, error) {
17-
logger := lalog.Logger{ComponentName: "kinesis"}
17+
logger := &lalog.Logger{ComponentName: "kinesis"}
1818
regionName := inet.GetAWSRegion()
1919
if regionName == "" {
2020
return nil, fmt.Errorf("NewKinesisHoseClient: unable to determine AWS region, is it set in environment variable AWS_REGION?")
@@ -34,7 +34,7 @@ func NewKinesisHoseClient() (*KinesisHoseClient, error) {
3434
}
3535

3636
type KinesisHoseClient struct {
37-
logger lalog.Logger
37+
logger *lalog.Logger
3838
apiSession *session.Session
3939
client *firehose.Firehose
4040
}

awsinteg/s3.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
func NewS3Client() (*S3Client, error) {
19-
logger := lalog.Logger{ComponentName: "s3"}
19+
logger := &lalog.Logger{ComponentName: "s3"}
2020
regionName := inet.GetAWSRegion()
2121
if regionName == "" {
2222
return nil, fmt.Errorf("NewS3Client: unable to determine AWS region, is it set in environment variable AWS_REGION?")
@@ -36,7 +36,7 @@ func NewS3Client() (*S3Client, error) {
3636
}
3737

3838
type S3Client struct {
39-
logger lalog.Logger
39+
logger *lalog.Logger
4040
apiSession *session.Session
4141
uploader *s3manager.Uploader
4242
}

awsinteg/sns.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func NewSNSClient() (*SNSClient, error) {
17-
logger := lalog.Logger{ComponentName: "sns"}
17+
logger := &lalog.Logger{ComponentName: "sns"}
1818
regionName := inet.GetAWSRegion()
1919
if regionName == "" {
2020
return nil, fmt.Errorf("NewSNSClient: unable to determine AWS region, is it set in environment variable AWS_REGION?")
@@ -34,7 +34,7 @@ func NewSNSClient() (*SNSClient, error) {
3434
}
3535

3636
type SNSClient struct {
37-
logger lalog.Logger
37+
logger *lalog.Logger
3838
apiSession *session.Session
3939
client *sns.SNS
4040
}

awsinteg/sqs.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func NewSQSClient() (*SQSClient, error) {
17-
logger := lalog.Logger{ComponentName: "sqs"}
17+
logger := &lalog.Logger{ComponentName: "sqs"}
1818
regionName := inet.GetAWSRegion()
1919
if regionName == "" {
2020
return nil, fmt.Errorf("NewSQSClient: unable to determine AWS region, is it set in environment variable AWS_REGION?")
@@ -34,7 +34,7 @@ func NewSQSClient() (*SQSClient, error) {
3434
}
3535

3636
type SQSClient struct {
37-
logger lalog.Logger
37+
logger *lalog.Logger
3838
apiSession *session.Session
3939
client *sqs.SQS
4040
}

cli/log.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ InstallOptionalLoggerSQSCallback installs a global callback function for all lai
5151
log entry to AWS SQS.
5252
This behaviour is enabled optionally by specifying the queue URL in environment variable LAITOS_SEND_WARNING_LOG_TO_SQS_URL.
5353
*/
54-
func InstallOptionalLoggerSQSCallback(logger lalog.Logger, sqsURL string) {
54+
func InstallOptionalLoggerSQSCallback(logger *lalog.Logger, sqsURL string) {
5555
if misc.EnableAWSIntegration && sqsURL != "" {
5656
logger.Info(nil, nil, "installing callback for sending logger warning messages to SQS")
5757
loggerSQSClientInitOnce.Do(func() {
@@ -105,10 +105,10 @@ func ClearDedupBuffersInBackground() {
105105
numDropped := lalog.NumDropped.Load()
106106
<-tickerChan
107107
newDropped := lalog.NumDropped.Load()
108+
lalog.ClearDedupBuffers()
108109
if diff := newDropped - numDropped; diff > 0 {
109110
lalog.DefaultLogger.Warning(nil, nil, "dropped %d log messages", diff)
110111
}
111-
lalog.ClearDedupBuffers()
112112
}
113113
}()
114114
}

cli/proxy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type ProxyCLIOptions struct {
4545
DownstreamSegmentLength int
4646
}
4747

48-
func HandleTCPOverDNSClient(logger lalog.Logger, proxyOpts ProxyCLIOptions) {
48+
func HandleTCPOverDNSClient(logger *lalog.Logger, proxyOpts ProxyCLIOptions) {
4949
// Initialise the options with default values.
5050
if proxyOpts.MaxSegmentLength == 0 {
5151
proxyOpts.MaxSegmentLength = dnsd.MaxUpstreamSegmentLength(proxyOpts.LaitosDNSName)

cli/security.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func EncryptFile(filePath string) {
8989
// the unlock password immediately.
9090
// If a password is available and hence obtained, the function will return the password string.
9191
// If no password is available or an IO error occurs, the function will return an empty string.
92-
func GetUnlockingPassword(ctx context.Context, useTLS bool, logger lalog.Logger, challengeStr, serverAddr string) string {
92+
func GetUnlockingPassword(ctx context.Context, useTLS bool, logger *lalog.Logger, challengeStr, serverAddr string) string {
9393
hostName, _ := os.Hostname()
9494
dialTimeoutCtx, dialTimeoutCancel := context.WithTimeout(ctx, PasswdRPCTimeout)
9595
defer dialTimeoutCancel()
@@ -144,7 +144,7 @@ func GetUnlockingPassword(ctx context.Context, useTLS bool, logger lalog.Logger,
144144
// and config files, and retries until this password is available and subsequently obtained.
145145
// The function blocks caller until a password has been obtained or the input context is cancelled.
146146
// The default source of PRNG must be seeded prior to calling this function.
147-
func GetUnlockingPasswordWithRetry(ctx context.Context, useTLS bool, logger lalog.Logger, serverAddrs ...string) string {
147+
func GetUnlockingPasswordWithRetry(ctx context.Context, useTLS bool, logger *lalog.Logger, serverAddrs ...string) string {
148148
challengeStr := netboundfileenc.GetRandomChallenge()
149149
logger.Info("", nil, "trying to obtain config file decryption password from %d servers via gRPC, using magic challenge \"%s\"", len(serverAddrs), challengeStr)
150150
for {
@@ -166,7 +166,7 @@ func GetUnlockingPasswordWithRetry(ctx context.Context, useTLS bool, logger lalo
166166
}
167167

168168
// HandleSecurityDataUtil the main routine of data file maintenance utilities.
169-
func HandleSecurityDataUtil(dataUtil, dataUtilFile string, logger lalog.Logger) {
169+
func HandleSecurityDataUtil(dataUtil, dataUtilFile string, logger *lalog.Logger) {
170170
if dataUtilFile == "" {
171171
logger.Abort("", nil, "please provide data utility target file in parameter \"-datautilfile\"")
172172
return

cli/security_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ func TestGetUnlockingPassword(t *testing.T) {
1919
Port: 8972,
2020
PasswordRegister: netboundfileenc.NewPasswordRegister(10, 10, lalog.DefaultLogger),
2121
}
22+
if err := daemon.Initialise(); err != nil {
23+
t.Fatal(err)
24+
}
2225
go func() {
2326
if err := daemon.StartAndBlock(); err != nil {
2427
t.Error(err)
@@ -28,12 +31,12 @@ func TestGetUnlockingPassword(t *testing.T) {
2831
if !misc.ProbePort(30*time.Second, daemon.Address, daemon.Port) {
2932
t.Fatal("daemon did not start on time")
3033
}
31-
password := GetUnlockingPassword(context.Background(), false, *lalog.DefaultLogger, "test-challenge-str", net.JoinHostPort("127.0.0.1", strconv.Itoa(daemon.Port)))
34+
password := GetUnlockingPassword(context.Background(), false, lalog.DefaultLogger, "test-challenge-str", net.JoinHostPort("127.0.0.1", strconv.Itoa(daemon.Port)))
3235
if password != "" {
3336
t.Fatal("should not have got a password at this point")
3437
}
3538
daemon.PasswordRegister.FulfilIntent("test-challenge-str", "good-password")
36-
password = GetUnlockingPassword(context.Background(), false, *lalog.DefaultLogger, "test-challenge-str", net.JoinHostPort("127.0.0.1", strconv.Itoa(daemon.Port)))
39+
password = GetUnlockingPassword(context.Background(), false, lalog.DefaultLogger, "test-challenge-str", net.JoinHostPort("127.0.0.1", strconv.Itoa(daemon.Port)))
3740
if password != "good-password" {
3841
t.Fatalf("did not get the password: %s", password)
3942
}

cli/supervise.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ between each restart.
2525
If the input function crashes in a panic, there won't be an auto-restart.
2626
The function returns to the caller only after the input function returns nil.
2727
*/
28-
func AutoRestart(logger lalog.Logger, logActorName string, fun func() error) {
28+
func AutoRestart(logger *lalog.Logger, logActorName string, fun func() error) {
2929
delaySec := 0
3030
for {
3131
if misc.EmergencyLockDown {
@@ -66,7 +66,7 @@ func DumpGoroutinesOnInterrupt() {
6666
// This function helps securing several laitos program components that depend on
6767
// the default PRNG, therefore, it should be invoked at or near the start of the
6868
// main function.
69-
func ReseedPseudoRandAndInBackground(logger lalog.Logger) {
69+
func ReseedPseudoRandAndInBackground(logger *lalog.Logger) {
7070
// Avoid using misc.Periodic, for it uses the PRNG internally.
7171
reseedFun := func() {
7272
seedBytes := make([]byte, 8)
@@ -97,7 +97,7 @@ func ReseedPseudoRandAndInBackground(logger lalog.Logger) {
9797
// If the text file is encrypted, the function will retrieve its encryption
9898
// password from STDIN, password unlocking server, or a web server for password
9999
// input, and then return the text file decrypted.
100-
func GetConfig(logger lalog.Logger, pwdServer bool, pwdServerPort int, pwdServerURL string, passwordUnlockServers string) []byte {
100+
func GetConfig(logger *lalog.Logger, pwdServer bool, pwdServerPort int, pwdServerURL string, passwordUnlockServers string) []byte {
101101
configBytes := []byte(strings.TrimSpace(os.Getenv("LAITOS_CONFIG")))
102102
if len(configBytes) == 0 {
103103
// Proceed to read the config file

cli/supervise_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestAutoRestart(t *testing.T) {
2424
}
2525
done := make(chan struct{})
2626
go func() {
27-
AutoRestart(lalog.Logger{}, "sample", sampleFun)
27+
AutoRestart(&lalog.Logger{}, "sample", sampleFun)
2828
done <- struct{}{}
2929
}()
3030
start := time.Now()
@@ -61,7 +61,7 @@ func TestAutoRestartDuringLockDown(t *testing.T) {
6161
misc.EmergencyLockDown = false
6262
}()
6363
go func() {
64-
AutoRestart(lalog.Logger{}, "sample", sampleFun)
64+
AutoRestart(&lalog.Logger{}, "sample", sampleFun)
6565
done <- struct{}{}
6666
}()
6767
<-done

cli/sys.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const (
2727
CopyNonEssentialUtilitiesInBackground immediately copies utility programs that are not essential but helpful to certain
2828
toolbox features and daemons, and then continues in background at regular interval (1 hour).
2929
*/
30-
func CopyNonEssentialUtilitiesInBackground(logger lalog.Logger) {
30+
func CopyNonEssentialUtilitiesInBackground(logger *lalog.Logger) {
3131
periodicCopy := &misc.Periodic{
3232
LogActorName: "copy-non-essential-utils",
3333
Interval: 1 * time.Hour,
@@ -44,7 +44,7 @@ func CopyNonEssentialUtilitiesInBackground(logger lalog.Logger) {
4444
}
4545

4646
// DisableConflicts prevents system daemons from conflicting with laitos, this is usually done by disabling them.
47-
func DisableConflicts(logger lalog.Logger) {
47+
func DisableConflicts(logger *lalog.Logger) {
4848
if !platform.HostIsWindows() && os.Getuid() != 0 {
4949
// Sorry, I do not know how to detect administrator privilege on Windows.
5050
logger.Abort("", nil, "you must run laitos as root user if you wish to automatically disable system conflicts")
@@ -70,7 +70,7 @@ func DisableConflicts(logger lalog.Logger) {
7070
// the new comma-separated daemon list from the daemonList file.
7171
// If laitos is not running on App Engine then the function does nothing and
7272
// returns an empty string.
73-
func GAEDaemonList(logger lalog.Logger) string {
73+
func GAEDaemonList(logger *lalog.Logger) string {
7474
if os.Getenv("GAE_ENV") == "standard" {
7575
misc.EnablePrometheusIntegration = true
7676
// Change working directory to the data directory (if not done yet).
@@ -99,7 +99,7 @@ func GAEDaemonList(logger lalog.Logger) string {
9999
}
100100

101101
// StartProfilingServer starts an HTTP server on localhost to serve program profiling data
102-
func StartProfilingServer(logger lalog.Logger, pprofHTTPPort int) {
102+
func StartProfilingServer(logger *lalog.Logger, pprofHTTPPort int) {
103103
if pprofHTTPPort > 0 {
104104
go func() {
105105
// Expose the entire selection of profiling profiles identical to the ones installed by pprof standard library package

daemon/autounlock/autounlock.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ type Daemon struct {
4040
URLAndPassword map[string]string `json:"URLAndPassword"` // URLAndPassword is a mapping between URL and corresponding password.
4141
IntervalSec int `json:"IntervalSec"` // IntervalSec is the interval at which URLs are checked.
4242

43-
logger lalog.Logger
43+
logger *lalog.Logger
4444
cancelFunc func()
4545
}
4646

4747
func (daemon *Daemon) Initialise() error {
4848
if daemon.IntervalSec < 10*60 {
4949
daemon.IntervalSec = 10 * 60 // 10 minutes is reasonable for almost all cases
5050
}
51-
daemon.logger = lalog.Logger{ComponentName: "autounlock", ComponentID: []lalog.LoggerIDField{{Key: "Intv", Value: daemon.IntervalSec}}}
51+
daemon.logger = &lalog.Logger{ComponentName: "autounlock", ComponentID: []lalog.LoggerIDField{{Key: "Intv", Value: daemon.IntervalSec}}}
5252
// Make sure that all URLs and passwords are present, and URLs can be parsed.
5353
for aURL, passwd := range daemon.URLAndPassword {
5454
if aURL == "" || passwd == "" {

daemon/common/recurring_cmds.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type RecurringCommands struct {
3939
transientCommands []string
4040
results *datastruct.RingBuffer // results are the most recent command results and test messages to retrieve.
4141
mutex *sync.RWMutex // mutex prevents concurrent access to internal structures.
42-
logger lalog.Logger
42+
logger *lalog.Logger
4343
cancelFunc func()
4444
}
4545

@@ -57,7 +57,7 @@ func (cmds *RecurringCommands) Initialise() error {
5757
cmds.results = datastruct.NewRingBuffer(int64(cmds.MaxResults))
5858
cmds.transientCommands = make([]string, 0, 10)
5959
cmds.mutex = new(sync.RWMutex)
60-
cmds.logger = lalog.Logger{
60+
cmds.logger = &lalog.Logger{
6161
ComponentName: "RecurringCommands",
6262
ComponentID: []lalog.LoggerIDField{{Key: "Intv", Value: cmds.IntervalSec}},
6363
}

daemon/common/tcpsrv.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type TCPApp interface {
2828
// GetTCPStatsCollector returns the stats collector that counts and times client connections for the TCP application.
2929
GetTCPStatsCollector() *misc.Stats
3030
// HandleTCPConnection converses with the TCP client. The client connection is closed by server upon returning from the implementation.
31-
HandleTCPConnection(lalog.Logger, string, *net.TCPConn)
31+
HandleTCPConnection(*lalog.Logger, string, *net.TCPConn)
3232
}
3333

3434
// TCPServer implements common routines for a TCP server that interacts with unlimited number of clients while applying a rate limit.
@@ -49,7 +49,7 @@ type TCPServer struct {
4949
LimitPerSec int
5050

5151
mutex *sync.Mutex
52-
logger lalog.Logger
52+
logger *lalog.Logger
5353
rateLimit *misc.RateLimit
5454
listener net.Listener
5555
}
@@ -70,7 +70,7 @@ func NewTCPServer(listenAddr string, listenPort int, appName string, app TCPApp,
7070
// Initialise initialises the internal structures of the TCP server, preparing it for accepting clients.
7171
func (srv *TCPServer) Initialise() {
7272
srv.mutex = new(sync.Mutex)
73-
srv.logger = lalog.Logger{
73+
srv.logger = &lalog.Logger{
7474
ComponentName: srv.AppName,
7575
ComponentID: []lalog.LoggerIDField{{Key: "Addr", Value: srv.ListenAddr}, {Key: "TCPPort", Value: srv.ListenPort}},
7676
}

daemon/common/tcpsrv_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (app *TCPTestApp) GetTCPStatsCollector() *misc.Stats {
2121
return app.stats
2222
}
2323

24-
func (app *TCPTestApp) HandleTCPConnection(logger lalog.Logger, clientIP string, conn *net.TCPConn) {
24+
func (app *TCPTestApp) HandleTCPConnection(logger *lalog.Logger, clientIP string, conn *net.TCPConn) {
2525
if clientIP == "" {
2626
panic("client IP must not be empty")
2727
}

daemon/common/udpsrv.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type UDPApp interface {
2222
// GetUDPStatsCollector returns the stats collector that counts and times UDP conversations.
2323
GetUDPStatsCollector() *misc.Stats
2424
// HandleUDPClient converses with a UDP client based on a received packet.
25-
HandleUDPClient(lalog.Logger, string, *net.UDPAddr, []byte, *net.UDPConn)
25+
HandleUDPClient(*lalog.Logger, string, *net.UDPAddr, []byte, *net.UDPConn)
2626
}
2727

2828
// UDPServer implements common routines for a UDP server that interacts with unlimited number of clients while applying a rate limit.
@@ -43,7 +43,7 @@ type UDPServer struct {
4343
LimitPerSec int
4444

4545
mutex *sync.Mutex
46-
logger lalog.Logger
46+
logger *lalog.Logger
4747
rateLimit *misc.RateLimit
4848
udpServer *net.UDPConn
4949
}
@@ -64,7 +64,7 @@ func NewUDPServer(listenAddr string, listenPort int, appName string, app UDPApp,
6464
// Initialise initialises the internal structures of UDP server, preparing it for processing clients.
6565
func (srv *UDPServer) Initialise() {
6666
srv.mutex = new(sync.Mutex)
67-
srv.logger = lalog.Logger{
67+
srv.logger = &lalog.Logger{
6868
ComponentName: srv.AppName,
6969
ComponentID: []lalog.LoggerIDField{{Key: "Addr", Value: srv.ListenAddr}, {Key: "UDPPort", Value: srv.ListenPort}},
7070
}

daemon/common/udpsrv_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (app *UDPTestApp) GetUDPStatsCollector() *misc.Stats {
2020
return app.stats
2121
}
2222

23-
func (app *UDPTestApp) HandleUDPClient(logger lalog.Logger, clientIP string, client *net.UDPAddr, packet []byte, srv *net.UDPConn) {
23+
func (app *UDPTestApp) HandleUDPClient(logger *lalog.Logger, clientIP string, client *net.UDPAddr, packet []byte, srv *net.UDPConn) {
2424
if clientIP == "" {
2525
panic("client IP must not be empty")
2626
}

daemon/dnsd/blacklist.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ var Whitelist = []string{
7777
DownloadAllBlacklists attempts to download all hosts files and return combined list of domain names to block.
7878
The special cases of white listed names are removed from return value.
7979
*/
80-
func DownloadAllBlacklists(maxEntries int, logger lalog.Logger) []string {
80+
func DownloadAllBlacklists(maxEntries int, logger *lalog.Logger) []string {
8181
wg := new(sync.WaitGroup)
8282
wg.Add(len(HostsFileURLs))
8383

daemon/dnsd/blacklist_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func TestDownloadAllBlacklists(t *testing.T) {
12-
names := DownloadAllBlacklists(BlacklistMaxEntries, lalog.Logger{})
12+
names := DownloadAllBlacklists(BlacklistMaxEntries, &lalog.Logger{})
1313
if len(names) < 5000 {
1414
t.Fatal("number of names is too little")
1515
}

daemon/dnsd/dnsd.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ type Daemon struct {
145145

146146
context context.Context
147147
cancelFunc func()
148-
logger lalog.Logger
148+
logger *lalog.Logger
149149
allowQueryFromCidrNets []*net.IPNet
150150
}
151151

@@ -177,7 +177,7 @@ func (daemon *Daemon) Initialise() error {
177177
daemon.Forwarders = make([]string, len(DefaultForwarders))
178178
copy(daemon.Forwarders, DefaultForwarders)
179179
}
180-
daemon.logger = lalog.Logger{
180+
daemon.logger = &lalog.Logger{
181181
ComponentName: "dnsd",
182182
ComponentID: []lalog.LoggerIDField{{Key: "TCP", Value: daemon.TCPPort}, {Key: "UDP", Value: daemon.UDPPort}},
183183
}

0 commit comments

Comments
 (0)