From 9e1b80a1be55291ef5903df829f6743e73f4f480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Thu, 2 May 2024 14:10:32 +0200 Subject: [PATCH 01/11] feat: use runners to startup the services --- pkg/runner/factory.go | 134 +++++++++++++++ pkg/runner/types.go | 6 + services/antivirus/pkg/command/server.go | 53 +++--- services/antivirus/pkg/service/service.go | 57 +++++-- services/audit/pkg/command/server.go | 60 +++---- services/audit/pkg/service/service.go | 17 +- services/clientlog/pkg/command/server.go | 49 +++--- services/clientlog/pkg/service/service.go | 27 ++- services/collaboration/pkg/command/server.go | 63 +++---- services/eventhistory/pkg/command/server.go | 50 +++--- services/graph/pkg/command/server.go | 49 +++--- services/idm/pkg/command/server.go | 65 ++++--- services/idp/pkg/command/server.go | 50 +++--- services/invitations/pkg/command/server.go | 51 +++--- services/nats/pkg/command/server.go | 69 +++----- services/nats/pkg/server/nats/nats.go | 15 +- services/notifications/pkg/command/server.go | 37 ++-- services/notifications/pkg/service/service.go | 42 ++++- services/ocdav/pkg/command/server.go | 159 +++++++++--------- services/ocs/pkg/command/server.go | 53 +++--- services/policies/pkg/command/server.go | 57 ++++--- .../policies/pkg/service/event/service.go | 63 +++++-- services/postprocessing/pkg/command/server.go | 62 +++---- .../postprocessing/pkg/service/service.go | 62 ++++++- services/proxy/pkg/command/server.go | 50 +++--- services/search/pkg/command/server.go | 46 +++-- services/settings/pkg/command/server.go | 61 +++---- services/sse/pkg/command/server.go | 47 +++--- services/thumbnails/pkg/command/server.go | 67 +++----- services/userlog/pkg/command/server.go | 47 +++--- services/web/pkg/command/server.go | 57 +++---- services/webdav/pkg/command/server.go | 51 +++--- services/webfinger/pkg/command/server.go | 51 +++--- 33 files changed, 997 insertions(+), 830 deletions(-) create mode 100644 pkg/runner/factory.go diff --git a/pkg/runner/factory.go b/pkg/runner/factory.go new file mode 100644 index 0000000000..e7925941e4 --- /dev/null +++ b/pkg/runner/factory.go @@ -0,0 +1,134 @@ +package runner + +import ( + "context" + "errors" + "net" + "net/http" + "time" + + ogrpc "github.com/opencloud-eu/opencloud/pkg/service/grpc" + ohttp "github.com/opencloud-eu/opencloud/pkg/service/http" + "google.golang.org/grpc" +) + +// NewGoMicroGrpcServerRunner creates a new runner based on the provided go-micro's +// GRPC service. The service is expected to be created via +// "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc".NewService(...) function +// +// The runner will behave as described: +// * The task is to start a server and listen for connections. If the server +// can't start, the task will finish with that error. +// * The stopper will call the server's stop method and send the result to +// the task. +// * The stopper will run asynchronously because the stop method could take a +// while and we don't want to block +func NewGoMicroGrpcServerRunner(name string, server ogrpc.Service, opts ...Option) *Runner { + httpCh := make(chan error, 1) + r := New(name, func() error { + // start the server and return if it fails + if err := server.Server().Start(); err != nil { + return err + } + return <-httpCh // wait for the result + }, func() { + // stop implies deregistering and waiting for request to finish, + // so don't block + go func() { + httpCh <- server.Server().Stop() // stop and send result through channel + close(httpCh) + }() + }, opts...) + return r +} + +// NewGoMicroHttpServerRunner creates a new runner based on the provided go-micro's +// HTTP service. The service is expected to be created via +// "github.com/owncloud/ocis/v2/ocis-pkg/service/http".NewService(...) function +// +// The runner will behave as described: +// * The task is to start a server and listen for connections. If the server +// can't start, the task will finish with that error. +// * The stopper will call the server's stop method and send the result to +// the task. +// * The stopper will run asynchronously because the stop method could take a +// while and we don't want to block +func NewGoMicroHttpServerRunner(name string, server ohttp.Service, opts ...Option) *Runner { + httpCh := make(chan error, 1) + r := New(name, func() error { + // start the server and return if it fails + if err := server.Server().Start(); err != nil { + return err + } + return <-httpCh // wait for the result + }, func() { + // stop implies deregistering and waiting for request to finish, + // so don't block + go func() { + httpCh <- server.Server().Stop() // stop and send result through channel + close(httpCh) + }() + }, opts...) + return r +} + +// NewGolangHttpServerRunner creates a new runner based on the provided HTTP server. +// The HTTP server is expected to be created via +// "github.com/owncloud/ocis/v2/ocis-pkg/service/debug".NewService(...) function +// and it's expected to be a regular golang HTTP server +// +// The runner will behave as described: +// * The task starts a server and listen for connections. If the server +// can't start, the task will finish with that error. If the server is shutdown +// the task will wait for the shutdown to return that result (task won't finish +// immediately, but wait until shutdown returns) +// * The stopper will call the server's shutdown method and send the result to +// the task. The stopper will wait up to 5 secs for the shutdown. +// * The stopper will run asynchronously because the shutdown could take a +// while and we don't want to block +func NewGolangHttpServerRunner(name string, server *http.Server, opts ...Option) *Runner { + debugCh := make(chan error, 1) + r := New(name, func() error { + // start listening and return if the error is NOT ErrServerClosed. + // ListenAndServe will always return a non-nil error. + // We need to wait and get the result of the Shutdown call. + // App shouldn't exit until Shutdown has returned. + if err := server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { + return err + } + // wait for the shutdown and return the result + return <-debugCh + }, func() { + // Since Shutdown might take some time, don't block + go func() { + // give 5 secs for the shutdown to finish + shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + + debugCh <- server.Shutdown(shutdownCtx) + close(debugCh) + }() + }, opts...) + + return r +} + +// NewGolangGrpcServerRunner creates a new runner based on the provided GRPC +// server. The GRPC server is expected to be a regular golang GRPC server, +// created via "google.golang.org/grpc".NewServer(...) +// A listener also needs to be provided for the server to listen there. +// +// The runner will just start the GRPC server in the listener, and the server +// will be gracefully stopped when interrupted +func NewGolangGrpcServerRunner(name string, server *grpc.Server, listener net.Listener, opts ...Option) *Runner { + r := New(name, func() error { + return server.Serve(listener) + }, func() { + // Since GracefulStop might take some time, don't block + go func() { + server.GracefulStop() + }() + }, opts...) + + return r +} diff --git a/pkg/runner/types.go b/pkg/runner/types.go index c4914e3263..4f226c18c2 100644 --- a/pkg/runner/types.go +++ b/pkg/runner/types.go @@ -1,10 +1,16 @@ package runner import ( + "os" "strings" + "syscall" "time" ) +var ( + StopSignals = []os.Signal{syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT} +) + // Runable represent a task that can be executed by the Runner. // It expected to be a long running task with an indefinite execution time, // so it's suitable for servers or services. diff --git a/services/antivirus/pkg/command/server.go b/services/antivirus/pkg/command/server.go index 4b05bd8fbe..05f3186c0d 100644 --- a/services/antivirus/pkg/command/server.go +++ b/services/antivirus/pkg/command/server.go @@ -3,12 +3,13 @@ package command import ( "context" "fmt" + "os/signal" - "github.com/oklog/run" "github.com/urfave/cli/v2" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/log" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/services/antivirus/pkg/config" "github.com/opencloud-eu/opencloud/services/antivirus/pkg/config/parser" @@ -26,31 +27,38 @@ func Server(cfg *config.Config) *cli.Command { return configlog.ReturnFatal(parser.ParseConfig(cfg)) }, Action: func(c *cli.Context) error { - var ( - gr = run.Group{} - ctx, cancel = context.WithCancel(c.Context) - logger = log.NewLogger( - log.Name(cfg.Service.Name), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } + + logger := log.NewLogger( + log.Name(cfg.Service.Name), + log.Level(cfg.Log.Level), + log.Pretty(cfg.Log.Pretty), + log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) - defer cancel() + traceProvider, err := tracing.GetServiceTraceProvider(cfg.Tracing, cfg.Service.Name) if err != nil { return err } + + gr := runner.NewGroup() { svc, err := service.NewAntivirus(cfg, logger, traceProvider) if err != nil { return cli.Exit(err.Error(), 1) } - gr.Add(svc.Run, func(_ error) { - cancel() - }) + gr.Add(runner.New("antivirus_svc", func() error { + return svc.Run() + }, func() { + svc.Close() + })) } { @@ -64,13 +72,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("antivirus_debug", debugServer)) } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/antivirus/pkg/service/service.go b/services/antivirus/pkg/service/service.go index 6dea06db6a..99c78d8794 100644 --- a/services/antivirus/pkg/service/service.go +++ b/services/antivirus/pkg/service/service.go @@ -11,6 +11,7 @@ import ( "os" "slices" "sync" + "sync/atomic" "time" "github.com/opencloud-eu/reva/v2/pkg/bytesize" @@ -54,7 +55,15 @@ func NewAntivirus(cfg *config.Config, logger log.Logger, tracerProvider trace.Tr return Antivirus{}, err } - av := Antivirus{config: cfg, log: logger, tracerProvider: tracerProvider, scanner: scanner, client: rhttp.GetHTTPClient(rhttp.Insecure(true))} + av := Antivirus{ + config: cfg, + log: logger, + tracerProvider: tracerProvider, + scanner: scanner, + client: rhttp.GetHTTPClient(rhttp.Insecure(true)), + stopCh: make(chan struct{}, 1), + stopped: new(atomic.Bool), + } switch mode := cfg.MaxScanSizeMode; mode { case config.MaxScanSizeModeSkip, config.MaxScanSizeModePartial: @@ -91,7 +100,9 @@ type Antivirus struct { maxScanSize uint64 tracerProvider trace.TracerProvider - client *http.Client + client *http.Client + stopCh chan struct{} + stopped *atomic.Bool } // Run runs the service @@ -131,26 +142,48 @@ func (av Antivirus) Run() error { wg.Add(1) go func() { defer wg.Done() - for e := range ch { - err := av.processEvent(e, natsStream) - if err != nil { - switch { - case errors.Is(err, ErrFatal): - av.log.Fatal().Err(err).Msg("fatal error - exiting") - case errors.Is(err, ErrEvent): - av.log.Error().Err(err).Msg("continuing") - default: - av.log.Fatal().Err(err).Msg("unknown error - exiting") + + EventLoop: + for { + select { + case e, ok := <-ch: + if !ok { + break EventLoop } + + err := av.processEvent(e, natsStream) + if err != nil { + switch { + case errors.Is(err, ErrFatal): + av.log.Fatal().Err(err).Msg("fatal error - exiting") + case errors.Is(err, ErrEvent): + av.log.Error().Err(err).Msg("continuing") + default: + av.log.Fatal().Err(err).Msg("unknown error - exiting") + } + } + + if av.stopped.Load() { + break EventLoop + } + case <-av.stopCh: + break EventLoop } } }() } + wg.Wait() return nil } +func (av Antivirus) Close() { + if av.stopped.CompareAndSwap(false, true) { + close(av.stopCh) + } +} + func (av Antivirus) processEvent(e events.Event, s events.Publisher) error { ctx, span := av.tracerProvider.Tracer("antivirus").Start(e.GetTraceContext(context.Background()), "processEvent") defer span.End() diff --git a/services/audit/pkg/command/server.go b/services/audit/pkg/command/server.go index 38727520b2..78f05df855 100644 --- a/services/audit/pkg/command/server.go +++ b/services/audit/pkg/command/server.go @@ -3,14 +3,15 @@ package command import ( "context" "fmt" + "os/signal" - "github.com/oklog/run" "github.com/opencloud-eu/reva/v2/pkg/events" "github.com/opencloud-eu/reva/v2/pkg/events/stream" "github.com/urfave/cli/v2" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/generators" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/services/audit/pkg/config" "github.com/opencloud-eu/opencloud/services/audit/pkg/config/parser" "github.com/opencloud-eu/opencloud/services/audit/pkg/logging" @@ -29,13 +30,15 @@ func Server(cfg *config.Config) *cli.Command { return configlog.ReturnFatal(parser.ParseConfig(cfg)) }, Action: func(c *cli.Context) error { - var ( - gr = run.Group{} - logger = logging.Configure(cfg.Service.Name, cfg.Log) + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - ctx, cancel = context.WithCancel(c.Context) - ) - defer cancel() + logger := logging.Configure(cfg.Service.Name, cfg.Log) + gr := runner.NewGroup() connName := generators.GenerateConnectionName(cfg.Service.Name, generators.NTypeBus) client, err := stream.NatsFromConfig(connName, false, stream.NatsConfig(cfg.Events)) @@ -47,24 +50,17 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(func() error { - svc.AuditLoggerFromConfig(ctx, cfg.Auditlog, evts, logger) - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "stream"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "stream"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } + // we need an additional context for the audit server in order to + // cancel it anytime + svcCtx, svcCancel := context.WithCancel(ctx) + defer svcCancel() - cancel() - }) + gr.Add(runner.New("audit_svc", func() error { + svc.AuditLoggerFromConfig(svcCtx, cfg.Auditlog, evts, logger) + return nil + }, func() { + svcCancel() + })) { debugServer, err := debug.Server( @@ -77,12 +73,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("audit_debug", debugServer)) } - return gr.Run() + + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/audit/pkg/service/service.go b/services/audit/pkg/service/service.go index 9afb079b19..1de8d27e74 100644 --- a/services/audit/pkg/service/service.go +++ b/services/audit/pkg/service/service.go @@ -42,7 +42,11 @@ func StartAuditLogger(ctx context.Context, ch <-chan events.Event, log log.Logge select { case <-ctx.Done(): return - case i := <-ch: + case i, ok := <-ch: + if !ok { + return + } + var auditEvent interface{} switch ev := i.Event.(type) { case events.ShareCreated: @@ -113,6 +117,10 @@ func StartAuditLogger(ctx context.Context, ch <-chan events.Event, log log.Logge auditEvent = types.ScienceMeshInviteTokenGenerated(ev) default: log.Error().Interface("event", ev).Msg(fmt.Sprintf("can't handle event of type '%T'", ev)) + if ctx.Err() != nil { + // if context is done, do not process more events + return + } continue } @@ -120,12 +128,19 @@ func StartAuditLogger(ctx context.Context, ch <-chan events.Event, log log.Logge b, err := marshaller(auditEvent) if err != nil { log.Error().Err(err).Msg("error marshaling the event") + if ctx.Err() != nil { + return + } continue } for _, l := range logto { l(b) } + + if ctx.Err() != nil { + return + } } } diff --git a/services/clientlog/pkg/command/server.go b/services/clientlog/pkg/command/server.go index 9392f3a396..f9e1e8a7cf 100644 --- a/services/clientlog/pkg/command/server.go +++ b/services/clientlog/pkg/command/server.go @@ -3,8 +3,8 @@ package command import ( "context" "fmt" + "os/signal" - "github.com/oklog/run" "github.com/opencloud-eu/reva/v2/pkg/events" "github.com/opencloud-eu/reva/v2/pkg/events/stream" "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" @@ -13,6 +13,7 @@ import ( "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/generators" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/clientlog/pkg/config" @@ -61,14 +62,16 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) - defer cancel() - connName := generators.GenerateConnectionName(cfg.Service.Name, generators.NTypeBus) s, err := stream.NatsFromConfig(connName, false, stream.NatsConfig(cfg.Events)) if err != nil { @@ -90,6 +93,7 @@ func Server(cfg *config.Config) *cli.Command { return fmt.Errorf("could not get reva client selector: %s", err) } + gr := runner.NewGroup() { svc, err := service.NewClientlogService( service.Logger(logger), @@ -105,23 +109,11 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(func() error { + gr.Add(runner.New("clientlog_svc", func() error { return svc.Run() - }, func(err error) { - if err != nil { - logger.Info(). - Str("transport", "stream"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "stream"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + }, func() { + svc.Close() + })) } { @@ -135,13 +127,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("clientlog_debug", debugServer)) } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/clientlog/pkg/service/service.go b/services/clientlog/pkg/service/service.go index 72b6c7a6b8..487fbdc808 100644 --- a/services/clientlog/pkg/service/service.go +++ b/services/clientlog/pkg/service/service.go @@ -7,6 +7,7 @@ import ( "fmt" "path/filepath" "reflect" + "sync/atomic" gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" group "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1" @@ -33,6 +34,8 @@ type ClientlogService struct { tracer trace.Tracer publisher events.Publisher ch <-chan events.Event + stopCh chan struct{} + stopped atomic.Bool } // NewClientlogService returns a clientlog service @@ -60,6 +63,7 @@ func NewClientlogService(opts ...Option) (*ClientlogService, error) { tracer: o.TraceProvider.Tracer("github.com/opencloud-eu/opencloud/services/clientlog/pkg/service"), publisher: o.Stream, ch: ch, + stopCh: make(chan struct{}, 1), } for _, e := range o.RegisteredEvents { @@ -72,13 +76,32 @@ func NewClientlogService(opts ...Option) (*ClientlogService, error) { // Run runs the service func (cl *ClientlogService) Run() error { - for event := range cl.ch { - cl.processEvent(event) +EventLoop: + for { + select { + case event, ok := <-cl.ch: + if !ok { + break EventLoop + } + cl.processEvent(event) + + if cl.stopped.Load() { + break EventLoop + } + case <-cl.stopCh: + break EventLoop + } } return nil } +func (cl *ClientlogService) Close() { + if cl.stopped.CompareAndSwap(false, true) { + close(cl.stopCh) + } +} + func (cl *ClientlogService) processEvent(event events.Event) { gwc, err := cl.gatewaySelector.Next() if err != nil { diff --git a/services/collaboration/pkg/command/server.go b/services/collaboration/pkg/command/server.go index a048470b6b..2bb369956c 100644 --- a/services/collaboration/pkg/command/server.go +++ b/services/collaboration/pkg/command/server.go @@ -4,14 +4,15 @@ import ( "context" "fmt" "net" + "os/signal" "time" - "github.com/oklog/run" "github.com/urfave/cli/v2" microstore "go-micro.dev/v4/store" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/services/collaboration/pkg/config" "github.com/opencloud-eu/opencloud/services/collaboration/pkg/config/parser" @@ -41,9 +42,12 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } // prepare components if err := helpers.RegisterOpenCloudService(ctx, cfg, logger); err != nil { @@ -89,6 +93,8 @@ func Server(cfg *config.Config) *cli.Command { store.Authentication(cfg.Store.AuthUsername, cfg.Store.AuthPassword), ) + gr := runner.NewGroup() + // start GRPC server grpcServer, teardown, err := grpc.Server( grpc.AppURLs(appUrls), @@ -103,28 +109,11 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(func() error { - l, err := net.Listen("tcp", cfg.GRPC.Addr) - if err != nil { - return err - } - return grpcServer.Serve(l) - }, - func(err error) { - if err != nil { - logger.Info(). - Str("transport", "grpc"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "grpc"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + l, err := net.Listen("tcp", cfg.GRPC.Addr) + if err != nil { + return err + } + gr.Add(runner.NewGolangGrpcServerRunner("collaboration_grpc", grpcServer, l)) // start debug server debugServer, err := debug.Server( @@ -136,11 +125,7 @@ func Server(cfg *config.Config) *cli.Command { logger.Error().Err(err).Str("transport", "debug").Msg("Failed to initialize server") return err } - - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("collaboration_debug", debugServer)) // start HTTP server httpServer, err := http.Server( @@ -152,14 +137,20 @@ func Server(cfg *config.Config) *cli.Command { http.Store(st), ) if err != nil { - logger.Error().Err(err).Str("transport", "http").Msg("Failed to initialize server") + logger.Info().Err(err).Str("transport", "http").Msg("Failed to initialize server") return err } - gr.Add(httpServer.Run, func(_ error) { - cancel() - }) + gr.Add(runner.NewGoMicroHttpServerRunner("collaboration_http", httpServer)) - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/eventhistory/pkg/command/server.go b/services/eventhistory/pkg/command/server.go index 7d4049191c..eaa85e2480 100644 --- a/services/eventhistory/pkg/command/server.go +++ b/services/eventhistory/pkg/command/server.go @@ -3,8 +3,8 @@ package command import ( "context" "fmt" + "os/signal" - "github.com/oklog/run" "github.com/opencloud-eu/reva/v2/pkg/events/stream" "github.com/opencloud-eu/reva/v2/pkg/store" "github.com/urfave/cli/v2" @@ -12,6 +12,7 @@ import ( "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/generators" + "github.com/opencloud-eu/opencloud/pkg/runner" ogrpc "github.com/opencloud-eu/opencloud/pkg/service/grpc" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" @@ -46,16 +47,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - var ( - gr = run.Group{} - ctx, cancel = context.WithCancel(c.Context) - m = metrics.New() - ) - - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } + m := metrics.New() m.BuildInfo.WithLabelValues(version.GetString()).Set(1) + gr := runner.NewGroup() + connName := generators.GenerateConnectionName(cfg.Service.Name, generators.NTypeBus) consumer, err := stream.NatsFromConfig(connName, false, stream.NatsConfig(cfg.Events)) if err != nil { @@ -84,21 +87,7 @@ func Server(cfg *config.Config) *cli.Command { grpc.TraceProvider(traceProvider), ) - gr.Add(service.Run, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "grpc"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "grpc"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + gr.Add(runner.NewGoMicroGrpcServerRunner("eventhistory_grpc", service)) { debugServer, err := debug.Server( @@ -111,13 +100,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("eventhistory_debug", debugServer)) } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/graph/pkg/command/server.go b/services/graph/pkg/command/server.go index 9cf76e4add..4eb5c5c1d3 100644 --- a/services/graph/pkg/command/server.go +++ b/services/graph/pkg/command/server.go @@ -3,9 +3,10 @@ package command import ( "context" "fmt" + "os/signal" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/graph/pkg/config" @@ -33,14 +34,17 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } + mtrcs := metrics.New() - - defer cancel() - mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) + gr := runner.NewGroup() { server, err := http.Server( http.Logger(logger), @@ -54,23 +58,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(func() error { - return server.Run() - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + gr.Add(runner.NewGoMicroHttpServerRunner("graph_http", server)) } { @@ -84,13 +72,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("graph_debug", server)) } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/idm/pkg/command/server.go b/services/idm/pkg/command/server.go index 1789ce98f3..85546df7b2 100644 --- a/services/idm/pkg/command/server.go +++ b/services/idm/pkg/command/server.go @@ -7,18 +7,19 @@ import ( "fmt" "html/template" "os" + "os/signal" "strings" "github.com/go-ldap/ldif" "github.com/libregraph/idm/pkg/ldappassword" "github.com/libregraph/idm/pkg/ldbbolt" "github.com/libregraph/idm/server" - "github.com/oklog/run" "github.com/urfave/cli/v2" "github.com/opencloud-eu/opencloud/pkg/config/configlog" pkgcrypto "github.com/opencloud-eu/opencloud/pkg/crypto" "github.com/opencloud-eu/opencloud/pkg/log" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/services/idm" "github.com/opencloud-eu/opencloud/services/idm/pkg/config" "github.com/opencloud-eu/opencloud/services/idm/pkg/config/parser" @@ -36,14 +37,16 @@ func Server(cfg *config.Config) *cli.Command { return configlog.ReturnFatal(parser.ParseConfig(cfg)) }, Action: func(c *cli.Context) error { - var ( - gr = run.Group{} - logger = logging.Configure(cfg.Service.Name, cfg.Log) - ctx, cancel = context.WithCancel(c.Context) - ) + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - defer cancel() + logger := logging.Configure(cfg.Service.Name, cfg.Log) + gr := runner.NewGroup() { servercfg := server.Config{ Logger: log.LogrusWrap(logger.Logger), @@ -75,30 +78,16 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(func() error { - err := make(chan error, 1) - select { - case <-ctx.Done(): - return nil + // we need an additional context for the idm server in order to + // cancel it anytime + svcCtx, svcCancel := context.WithCancel(ctx) + defer svcCancel() - case err <- svc.Serve(ctx): - return <-err - } - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + gr.Add(runner.New("idm_svc", func() error { + return svc.Serve(svcCtx) + }, func() { + svcCancel() + })) } { @@ -112,14 +101,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("idm_debug", debugServer)) } - return gr.Run() - //return start(ctx, logger, cfg) + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/idp/pkg/command/server.go b/services/idp/pkg/command/server.go index 350d93fdfa..db12bcc0c6 100644 --- a/services/idp/pkg/command/server.go +++ b/services/idp/pkg/command/server.go @@ -12,10 +12,11 @@ import ( "io" "io/fs" "os" + "os/signal" "path/filepath" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/idp/pkg/config" @@ -57,16 +58,18 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - var ( - gr = run.Group{} - ctx, cancel = context.WithCancel(c.Context) - metrics = metrics.New() - ) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } + metrics := metrics.New() metrics.BuildInfo.WithLabelValues(version.GetString()).Set(1) + gr := runner.NewGroup() { server, err := http.Server( http.Logger(logger), @@ -84,23 +87,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(func() error { - return server.Run() - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + gr.Add(runner.NewGoMicroHttpServerRunner("idp_http", server)) } { @@ -114,13 +101,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("idp_debug", debugServer)) } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/invitations/pkg/command/server.go b/services/invitations/pkg/command/server.go index e4d8046fa3..647637bd42 100644 --- a/services/invitations/pkg/command/server.go +++ b/services/invitations/pkg/command/server.go @@ -3,9 +3,10 @@ package command import ( "context" "fmt" + "os/signal" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/invitations/pkg/config" @@ -34,16 +35,17 @@ func Server(cfg *config.Config) *cli.Command { return err } - var ( - gr = run.Group{} - ctx, cancel = context.WithCancel(c.Context) - metrics = metrics.New(metrics.Logger(logger)) - ) - - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } + metrics := metrics.New(metrics.Logger(logger)) metrics.BuildInfo.WithLabelValues(version.GetString()).Set(1) + gr := runner.NewGroup() { svc, err := service.New( @@ -74,23 +76,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(func() error { - return server.Run() - }, func(err error) { - if err != nil { - logger.Info(). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + gr.Add(runner.NewGoMicroHttpServerRunner("invitations_http", server)) } { @@ -104,13 +90,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("invitations_debug", debugServer)) } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/nats/pkg/command/server.go b/services/nats/pkg/command/server.go index 14ac3e2ceb..56c0618d96 100644 --- a/services/nats/pkg/command/server.go +++ b/services/nats/pkg/command/server.go @@ -4,14 +4,13 @@ import ( "context" "crypto/tls" "fmt" - "time" - - "github.com/oklog/run" + "os/signal" "github.com/urfave/cli/v2" "github.com/opencloud-eu/opencloud/pkg/config/configlog" pkgcrypto "github.com/opencloud-eu/opencloud/pkg/crypto" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/services/nats/pkg/config" "github.com/opencloud-eu/opencloud/services/nats/pkg/config/parser" "github.com/opencloud-eu/opencloud/services/nats/pkg/logging" @@ -31,11 +30,14 @@ func Server(cfg *config.Config) *cli.Command { Action: func(c *cli.Context) error { logger := logging.Configure(cfg.Service.Name, cfg.Log) - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } + gr := runner.NewGroup() { debugServer, err := debug.Server( debug.Logger(logger), @@ -47,10 +49,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("nats_debug", debugServer)) } var tlsConf *tls.Config @@ -77,8 +76,7 @@ func Server(cfg *config.Config) *cli.Command { } } natsServer, err := nats.NewNATSServer( - ctx, - logger, + logging.NewLogWrapper(logger), nats.Host(cfg.Nats.Host), nats.Port(cfg.Nats.Port), nats.ClusterID(cfg.Nats.ClusterID), @@ -90,40 +88,21 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(func() error { - err := make(chan error, 1) - select { - case <-ctx.Done(): - return nil - case err <- natsServer.ListenAndServe(): - return <-err - } - - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "nats"). - Str("server", cfg.Service.Name). - Msg("letting other services deregister") - - time.Sleep(3 * time.Second) - - logger.Info(). - Str("transport", "nats"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "nats"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - + gr.Add(runner.New("nats_svc", func() error { + return natsServer.ListenAndServe() + }, func() { natsServer.Shutdown() - cancel() - }) + })) - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/nats/pkg/server/nats/nats.go b/services/nats/pkg/server/nats/nats.go index a6550e1bc9..e13d7f8be6 100644 --- a/services/nats/pkg/server/nats/nats.go +++ b/services/nats/pkg/server/nats/nats.go @@ -1,24 +1,19 @@ package nats import ( - "context" "time" nserver "github.com/nats-io/nats-server/v2/server" - "github.com/opencloud-eu/opencloud/pkg/log" - "github.com/opencloud-eu/opencloud/services/nats/pkg/logging" - "github.com/rs/zerolog" ) var NATSListenAndServeLoopTimer = 1 * time.Second type NATSServer struct { - ctx context.Context server *nserver.Server } // NatsOption configures the new NATSServer instance -func NewNATSServer(ctx context.Context, logger log.Logger, opts ...NatsOption) (*NATSServer, error) { +func NewNATSServer(logger nserver.Logger, opts ...NatsOption) (*NATSServer, error) { natsOpts := &nserver.Options{} for _, o := range opts { @@ -35,19 +30,17 @@ func NewNATSServer(ctx context.Context, logger log.Logger, opts ...NatsOption) ( return nil, err } - nLogger := logging.NewLogWrapper(logger) - server.SetLoggerV2(nLogger, logger.GetLevel() <= zerolog.DebugLevel, logger.GetLevel() <= zerolog.TraceLevel, false) + server.SetLoggerV2(logger, true, true, false) return &NATSServer{ - ctx: ctx, server: server, }, nil } // ListenAndServe runs the NATSServer in a blocking way until the server is shutdown or an error occurs func (n *NATSServer) ListenAndServe() (err error) { - go n.server.Start() - <-n.ctx.Done() + n.server.Start() // it won't block + n.server.WaitForShutdown() // block until the server is fully shutdown return nil } diff --git a/services/notifications/pkg/command/server.go b/services/notifications/pkg/command/server.go index ae14d9486b..f49bfd4cc0 100644 --- a/services/notifications/pkg/command/server.go +++ b/services/notifications/pkg/command/server.go @@ -3,13 +3,13 @@ package command import ( "context" "fmt" + "os/signal" "reflect" ehsvc "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/services/eventhistory/v0" "github.com/opencloud-eu/reva/v2/pkg/store" microstore "go-micro.dev/v4/store" - "github.com/oklog/run" "github.com/urfave/cli/v2" "github.com/opencloud-eu/reva/v2/pkg/events" @@ -19,6 +19,7 @@ import ( "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/generators" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/service/grpc" "github.com/opencloud-eu/opencloud/pkg/tracing" settingssvc "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/services/settings/v0" @@ -57,11 +58,14 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr := run.Group{} - - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } + gr := runner.NewGroup() { debugServer, err := debug.Server( debug.Logger(logger), @@ -73,10 +77,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("notifications_debug", debugServer)) } // evs defines a list of events to subscribe to @@ -139,11 +140,21 @@ func Server(cfg *config.Config) *cli.Command { cfg.Notifications.EmailTemplatePath, cfg.Notifications.DefaultLanguage, cfg.WebUIURL, cfg.Notifications.TranslationPath, cfg.Notifications.SMTP.Sender, notificationStore, historyClient, registeredEvents) - gr.Add(svc.Run, func(error) { - cancel() - }) + gr.Add(runner.New("notifications_svc", func() error { + return svc.Run() + }, func() { + svc.Close() + })) - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/notifications/pkg/service/service.go b/services/notifications/pkg/service/service.go index e3b717731b..0f27191bd3 100644 --- a/services/notifications/pkg/service/service.go +++ b/services/notifications/pkg/service/service.go @@ -5,11 +5,10 @@ import ( "errors" "fmt" "net/url" - "os" - "os/signal" "path" "strings" - "syscall" + "sync" + "sync/atomic" ehsvc "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/services/eventhistory/v0" "go-micro.dev/v4/store" @@ -44,6 +43,7 @@ func init() { // Service should be named `Runner` type Service interface { Run() error + Close() } // NewEventsNotifier provides a new eventsNotifier @@ -62,7 +62,6 @@ func NewEventsNotifier( logger: logger, channel: channel, events: events, - signals: make(chan os.Signal, 1), gatewaySelector: gatewaySelector, valueService: valueService, serviceAccountID: serviceAccountID, @@ -76,6 +75,8 @@ func NewEventsNotifier( splitter: newIntervalSplitter(logger, valueService), userEventStore: newUserEventStore(logger, store, historyClient), registeredEvents: registeredEvents, + stopCh: make(chan struct{}, 1), + stopped: new(atomic.Bool), } } @@ -83,7 +84,6 @@ type eventsNotifier struct { logger log.Logger channel channels.Channel events <-chan events.Event - signals chan os.Signal gatewaySelector pool.Selectable[gateway.GatewayAPIClient] valueService settingssvc.ValueService emailTemplatePath string @@ -97,16 +97,27 @@ type eventsNotifier struct { splitter *intervalSplitter userEventStore *userEventStore registeredEvents map[string]events.Unmarshaller + stopCh chan struct{} + stopped *atomic.Bool } func (s eventsNotifier) Run() error { - signal.Notify(s.signals, syscall.SIGINT, syscall.SIGTERM) + var wg sync.WaitGroup + s.logger.Debug(). Msg("eventsNotifier started") +EventLoop: for { select { - case evt := <-s.events: + case evt, ok := <-s.events: + if !ok { + break EventLoop + } + // TODO: needs to be replaced with a worker pool + wg.Add(1) go func() { + defer wg.Done() + switch e := evt.Event.(type) { case events.SpaceShared: s.handleSpaceShared(e, evt.ID) @@ -124,12 +135,25 @@ func (s eventsNotifier) Run() error { s.sendGroupedEmailsJob(e, evt.ID) } }() - case <-s.signals: + + if s.stopped.Load() { + break EventLoop + } + case <-s.stopCh: s.logger.Debug(). Msg("eventsNotifier stopped") - return nil + break EventLoop } } + // wait until all the goroutines processing events have finished + wg.Wait() + return nil +} + +func (s eventsNotifier) Close() { + if s.stopped.CompareAndSwap(false, true) { + close(s.stopCh) + } } func (s eventsNotifier) render(ctx context.Context, template email.MessageTemplate, diff --git a/services/ocdav/pkg/command/server.go b/services/ocdav/pkg/command/server.go index 6201ddfa97..9b37eaeb29 100644 --- a/services/ocdav/pkg/command/server.go +++ b/services/ocdav/pkg/command/server.go @@ -3,11 +3,13 @@ package command import ( "context" "fmt" + "os/signal" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/broker" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" + ohttp "github.com/opencloud-eu/opencloud/pkg/service/http" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/ocdav/pkg/config" @@ -34,85 +36,77 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - gr.Add(func() error { - // init reva shared config explicitly as the go-micro based ocdav does not use - // the reva runtime. But we need e.g. the shared client settings to be initialized - sc := map[string]interface{}{ - "jwt_secret": cfg.TokenManager.JWTSecret, - "gatewaysvc": cfg.Reva.Address, - "skip_user_groups_in_token": cfg.SkipUserGroupsInToken, - "grpc_client_options": cfg.Reva.GetGRPCClientConfig(), - } - if err := sharedconf.Decode(sc); err != nil { - logger.Error().Err(err).Msg("error decoding shared config for ocdav") - } - opts := []ocdav.Option{ - ocdav.Name(cfg.HTTP.Namespace + "." + cfg.Service.Name), - ocdav.Version(version.GetString()), - ocdav.Context(ctx), - ocdav.Logger(logger.Logger), - ocdav.Address(cfg.HTTP.Addr), - ocdav.AllowCredentials(cfg.HTTP.CORS.AllowCredentials), - ocdav.AllowedMethods(cfg.HTTP.CORS.AllowedMethods), - ocdav.AllowedHeaders(cfg.HTTP.CORS.AllowedHeaders), - ocdav.AllowedOrigins(cfg.HTTP.CORS.AllowedOrigins), - ocdav.FilesNamespace(cfg.FilesNamespace), - ocdav.WebdavNamespace(cfg.WebdavNamespace), - ocdav.OCMNamespace(cfg.OCMNamespace), - ocdav.AllowDepthInfinity(cfg.AllowPropfindDepthInfinity), - ocdav.SharesNamespace(cfg.SharesNamespace), - ocdav.Timeout(cfg.Timeout), - ocdav.Insecure(cfg.Insecure), - ocdav.PublicURL(cfg.PublicURL), - ocdav.Prefix(cfg.HTTP.Prefix), - ocdav.GatewaySvc(cfg.Reva.Address), - ocdav.JWTSecret(cfg.TokenManager.JWTSecret), - ocdav.ProductName(cfg.Status.ProductName), - ocdav.ProductVersion(cfg.Status.ProductVersion), - ocdav.Product(cfg.Status.Product), - ocdav.Version(cfg.Status.Version), - ocdav.VersionString(cfg.Status.VersionString), - ocdav.Edition(cfg.Status.Edition), - ocdav.MachineAuthAPIKey(cfg.MachineAuthAPIKey), - ocdav.Broker(broker.NoOp{}), - // ocdav.FavoriteManager() // FIXME needs a proper persistence implementation https://github.com/owncloud/ocis/issues/1228 - // ocdav.LockSystem(), // will default to the CS3 lock system - // ocdav.TLSConfig() // tls config for the http server - ocdav.MetricsEnabled(true), - ocdav.MetricsNamespace("opencloud"), - ocdav.Tracing("Adding these strings is a workaround for ->", "https://github.com/cs3org/reva/issues/4131"), - ocdav.WithTraceProvider(traceProvider), - ocdav.RegisterTTL(registry.GetRegisterTTL()), - ocdav.RegisterInterval(registry.GetRegisterInterval()), - ocdav.URLSigningSharedSecret(cfg.URLSigningSharedSecret), - } + gr := runner.NewGroup() - s, err := ocdav.Service(opts...) - if err != nil { - return err - } + // init reva shared config explicitly as the go-micro based ocdav does not use + // the reva runtime. But we need e.g. the shared client settings to be initialized + sc := map[string]interface{}{ + "jwt_secret": cfg.TokenManager.JWTSecret, + "gatewaysvc": cfg.Reva.Address, + "skip_user_groups_in_token": cfg.SkipUserGroupsInToken, + "grpc_client_options": cfg.Reva.GetGRPCClientConfig(), + } + if err := sharedconf.Decode(sc); err != nil { + logger.Error().Err(err).Msg("error decoding shared config for ocdav") + } + opts := []ocdav.Option{ + ocdav.Name(cfg.HTTP.Namespace + "." + cfg.Service.Name), + ocdav.Version(version.GetString()), + ocdav.Context(ctx), + ocdav.Logger(logger.Logger), + ocdav.Address(cfg.HTTP.Addr), + ocdav.AllowCredentials(cfg.HTTP.CORS.AllowCredentials), + ocdav.AllowedMethods(cfg.HTTP.CORS.AllowedMethods), + ocdav.AllowedHeaders(cfg.HTTP.CORS.AllowedHeaders), + ocdav.AllowedOrigins(cfg.HTTP.CORS.AllowedOrigins), + ocdav.FilesNamespace(cfg.FilesNamespace), + ocdav.WebdavNamespace(cfg.WebdavNamespace), + ocdav.OCMNamespace(cfg.OCMNamespace), + ocdav.AllowDepthInfinity(cfg.AllowPropfindDepthInfinity), + ocdav.SharesNamespace(cfg.SharesNamespace), + ocdav.Timeout(cfg.Timeout), + ocdav.Insecure(cfg.Insecure), + ocdav.PublicURL(cfg.PublicURL), + ocdav.Prefix(cfg.HTTP.Prefix), + ocdav.GatewaySvc(cfg.Reva.Address), + ocdav.JWTSecret(cfg.TokenManager.JWTSecret), + ocdav.ProductName(cfg.Status.ProductName), + ocdav.ProductVersion(cfg.Status.ProductVersion), + ocdav.Product(cfg.Status.Product), + ocdav.Version(cfg.Status.Version), + ocdav.VersionString(cfg.Status.VersionString), + ocdav.Edition(cfg.Status.Edition), + ocdav.MachineAuthAPIKey(cfg.MachineAuthAPIKey), + ocdav.Broker(broker.NoOp{}), + // ocdav.FavoriteManager() // FIXME needs a proper persistence implementation https://github.com/owncloud/ocis/issues/1228 + // ocdav.LockSystem(), // will default to the CS3 lock system + // ocdav.TLSConfig() // tls config for the http server + ocdav.MetricsEnabled(true), + ocdav.MetricsNamespace("ocis"), + ocdav.Tracing("Adding these strings is a workaround for ->", "https://github.com/cs3org/reva/issues/4131"), + ocdav.WithTraceProvider(traceProvider), + ocdav.RegisterTTL(registry.GetRegisterTTL()), + ocdav.RegisterInterval(registry.GetRegisterInterval()), + ocdav.URLSigningSharedSecret(cfg.URLSigningSharedSecret), + } - return s.Run() - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } + s, err := ocdav.Service(opts...) + if err != nil { + return err + } - cancel() - }) + // creating a runner for a go-micro service is a bit complex, so we'll + // wrap the go-micro service with an ocis service the same way as + // ocis-pkg/service/http is doing in order to reuse the factory. + gr.Add(runner.NewGoMicroHttpServerRunner("ocdav_http", ohttp.Service{Service: s})) debugServer, err := debug.Server( debug.Logger(logger), @@ -125,12 +119,17 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("ocdav_debug", debugServer)) - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/ocs/pkg/command/server.go b/services/ocs/pkg/command/server.go index dbf8c3c5d3..a8df3fde12 100644 --- a/services/ocs/pkg/command/server.go +++ b/services/ocs/pkg/command/server.go @@ -3,9 +3,10 @@ package command import ( "context" "fmt" + "os/signal" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" + "github.com/opencloud-eu/opencloud/pkg/runner" ogrpc "github.com/opencloud-eu/opencloud/pkg/service/grpc" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" @@ -39,16 +40,17 @@ func Server(cfg *config.Config) *cli.Command { return err } - var ( - gr = run.Group{} - ctx, cancel = context.WithCancel(c.Context) - metrics = metrics.New() - ) - - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } + metrics := metrics.New() metrics.BuildInfo.WithLabelValues(version.GetString()).Set(1) + gr := runner.NewGroup() { server, err := http.Server( http.Logger(logger), @@ -67,27 +69,11 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(func() error { - return server.Run() - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + gr.Add(runner.NewGoMicroHttpServerRunner("ocs_http", server)) } { - server, err := debug.Server( + debugServer, err := debug.Server( debug.Logger(logger), debug.Context(ctx), debug.Config(cfg), @@ -98,13 +84,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("ocs_debug", debugServer)) } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/policies/pkg/command/server.go b/services/policies/pkg/command/server.go index ab671a84b3..eaf49364be 100644 --- a/services/policies/pkg/command/server.go +++ b/services/policies/pkg/command/server.go @@ -3,14 +3,15 @@ package command import ( "context" "fmt" + "os/signal" - "github.com/oklog/run" "github.com/opencloud-eu/reva/v2/pkg/events/stream" "github.com/urfave/cli/v2" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/generators" "github.com/opencloud-eu/opencloud/pkg/log" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/service/grpc" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" @@ -33,18 +34,20 @@ func Server(cfg *config.Config) *cli.Command { return configlog.ReturnFatal(parser.ParseConfig(cfg)) }, Action: func(c *cli.Context) error { - var ( - gr = run.Group{} - ctx, cancel = context.WithCancel(c.Context) - logger = log.NewLogger( - log.Name(cfg.Service.Name), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ).SubloggerWithRequestID(ctx) - ) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } + + logger := log.NewLogger( + log.Name(cfg.Service.Name), + log.Level(cfg.Log.Level), + log.Pretty(cfg.Log.Pretty), + log.Color(cfg.Log.Color), + log.File(cfg.Log.File), + ).SubloggerWithRequestID(ctx) traceProvider, err := tracing.GetServiceTraceProvider(cfg.Tracing, cfg.Service.Name) if err != nil { @@ -56,6 +59,7 @@ func Server(cfg *config.Config) *cli.Command { return err } + gr := runner.NewGroup() { grpcClient, err := grpc.NewClient( append( @@ -98,9 +102,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(svc.Run, func(_ error) { - cancel() - }) + gr.Add(runner.NewGoMicroGrpcServerRunner("policies_grpc", svc)) } { @@ -116,9 +118,11 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(eventSvc.Run, func(_ error) { - cancel() - }) + gr.Add(runner.New("policies_svc", func() error { + return eventSvc.Run() + }, func() { + eventSvc.Close() + })) } { @@ -132,13 +136,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("policies_debug", debugServer)) } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/policies/pkg/service/event/service.go b/services/policies/pkg/service/event/service.go index 32ca2e0677..1561fcfdaf 100644 --- a/services/policies/pkg/service/event/service.go +++ b/services/policies/pkg/service/event/service.go @@ -2,6 +2,7 @@ package eventSVC import ( "context" + "sync/atomic" "github.com/opencloud-eu/opencloud/pkg/log" "github.com/opencloud-eu/opencloud/services/policies/pkg/engine" @@ -11,23 +12,27 @@ import ( // Service defines the service handlers. type Service struct { - ctx context.Context - query string - log log.Logger - stream events.Stream - engine engine.Engine - tp trace.TracerProvider + ctx context.Context + query string + log log.Logger + stream events.Stream + engine engine.Engine + tp trace.TracerProvider + stopCh chan struct{} + stopped *atomic.Bool } // New returns a service implementation for Service. func New(ctx context.Context, stream events.Stream, logger log.Logger, tp trace.TracerProvider, engine engine.Engine, query string) (Service, error) { svc := Service{ - ctx: ctx, - log: logger, - query: query, - tp: tp, - engine: engine, - stream: stream, + ctx: ctx, + log: logger, + query: query, + tp: tp, + engine: engine, + stream: stream, + stopCh: make(chan struct{}, 1), + stopped: new(atomic.Bool), } return svc, nil @@ -40,16 +45,42 @@ func (s Service) Run() error { return err } - for e := range ch { - err := s.processEvent(e) - if err != nil { - return err +EventLoop: + for { + select { + case <-s.stopCh: + break EventLoop + case e, ok := <-ch: + if !ok { + break EventLoop + } + + err := s.processEvent(e) + if err != nil { + return err + } + + if s.stopped.Load() { + break EventLoop + } } } return nil } +// Close will make the policies service to stop processing, so the `Run` +// method can finish. +// TODO: Underlying services can't be stopped. This means that some goroutines +// will get stuck trying to push events through a channel nobody is reading +// from, so resources won't be freed and there will be memory leaks. For now, +// if the service is stopped, you should close the app soon after. +func (s Service) Close() { + if s.stopped.CompareAndSwap(false, true) { + close(s.stopCh) + } +} + func (s Service) processEvent(e events.Event) error { ctx := e.GetTraceContext(s.ctx) ctx, span := s.tp.Tracer("policies").Start(ctx, "processEvent") diff --git a/services/postprocessing/pkg/command/server.go b/services/postprocessing/pkg/command/server.go index 1cbeafacb0..9a8a72d6ef 100644 --- a/services/postprocessing/pkg/command/server.go +++ b/services/postprocessing/pkg/command/server.go @@ -4,12 +4,13 @@ import ( "context" "fmt" "os" + "os/signal" - "github.com/oklog/run" "github.com/opencloud-eu/reva/v2/pkg/store" "github.com/urfave/cli/v2" microstore "go-micro.dev/v4/store" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/services/postprocessing/pkg/config" "github.com/opencloud-eu/opencloud/services/postprocessing/pkg/config/parser" @@ -33,18 +34,21 @@ func Server(cfg *config.Config) *cli.Command { return err }, Action: func(c *cli.Context) error { - var ( - gr = run.Group{} - logger = logging.Configure(cfg.Service.Name, cfg.Log) - ctx, cancel = context.WithCancel(c.Context) - ) - defer cancel() + logger := logging.Configure(cfg.Service.Name, cfg.Log) + + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } traceProvider, err := tracing.GetServiceTraceProvider(cfg.Tracing, cfg.Service.Name) if err != nil { return err } + gr := runner.NewGroup() { st := store.Create( store.Store(cfg.Store.Store), @@ -59,30 +63,12 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr.Add(func() error { - err := make(chan error, 1) - select { - case <-ctx.Done(): - return nil - case err <- svc.Run(): - return <-err - } - }, func(err error) { - if err != nil { - logger.Info(). - Str("transport", "stream"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "stream"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + gr.Add(runner.New("postprocessing_svc", func() error { + return svc.Run() + }, func() { + svc.Close() + })) } { @@ -96,12 +82,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("postprocessing_debug", debugServer)) } - return gr.Run() + + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/postprocessing/pkg/service/service.go b/services/postprocessing/pkg/service/service.go index 9fb8639d1e..9fb6b18d0d 100644 --- a/services/postprocessing/pkg/service/service.go +++ b/services/postprocessing/pkg/service/service.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "sync" + "sync/atomic" "time" "github.com/opencloud-eu/opencloud/pkg/generators" @@ -34,6 +35,8 @@ type PostprocessingService struct { c config.Postprocessing tp trace.TracerProvider metrics *metrics.Metrics + stopCh chan struct{} + stopped atomic.Bool } var ( @@ -97,6 +100,7 @@ func NewPostprocessingService(ctx context.Context, logger log.Logger, sto store. c: cfg.Postprocessing, tp: tp, metrics: m, + stopCh: make(chan struct{}, 1), }, nil } @@ -108,26 +112,66 @@ func (pps *PostprocessingService) Run() error { wg.Add(1) go func() { defer wg.Done() - for e := range pps.events { - if err := pps.processEvent(e); err != nil { - switch { - case errors.Is(err, ErrFatal): - pps.log.Fatal().Err(err).Msg("fatal error - exiting") - case errors.Is(err, ErrEvent): - pps.log.Error().Err(err).Msg("continuing") - default: - pps.log.Fatal().Err(err).Msg("unknown error - exiting") + + EventLoop: + for { + select { + case <-pps.stopCh: + // stop requested + // TODO: we might need a way to unsubscribe from the event channel, otherwise + // we'll be leaking a goroutine in reva that will be stuck waiting for + // someone to read from the event channel. + // Note: redis implementation seems to have a timeout, so the goroutine + // will exit if there is nobody processing the events and the timeout + // is reached. The behavior is unclear with natsjs + break EventLoop + case e, ok := <-pps.events: + if !ok { + // event channel is closed, so nothing more to do + break EventLoop + } + + err := pps.processEvent(e) + if err != nil { + switch { + case errors.Is(err, ErrFatal): + pps.log.Fatal().Err(err).Msg("fatal error - exiting") + case errors.Is(err, ErrEvent): + pps.log.Error().Err(err).Msg("continuing") + default: + pps.log.Fatal().Err(err).Msg("unknown error - exiting") + } + } + + if pps.stopped.Load() { + // if stopped, don't process any more events + break EventLoop } } } }() } + wg.Wait() return nil } +// Close will make the postprocessing service to stop processing, so the `Run` +// method can finish. +// TODO: Underlying services can't be stopped. This means that some goroutines +// will get stuck trying to push events through a channel nobody is reading +// from, so resources won't be freed and there will be memory leaks. For now, +// if the service is stopped, you should close the app soon after. +func (pps *PostprocessingService) Close() { + if pps.stopped.CompareAndSwap(false, true) { + close(pps.stopCh) + } +} + func (pps *PostprocessingService) processEvent(e raw.Event) error { + pps.log.Debug().Str("Type", e.Type).Str("ID", e.ID).Msg("processing event received") + var ( next interface{} pp *postprocessing.Postprocessing diff --git a/services/proxy/pkg/command/server.go b/services/proxy/pkg/command/server.go index 14b96513e6..31fa3a6699 100644 --- a/services/proxy/pkg/command/server.go +++ b/services/proxy/pkg/command/server.go @@ -5,18 +5,19 @@ import ( "crypto/tls" "fmt" "net/http" + "os/signal" "time" gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" chimiddleware "github.com/go-chi/chi/v5/middleware" "github.com/justinas/alice" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/generators" "github.com/opencloud-eu/opencloud/pkg/log" pkgmiddleware "github.com/opencloud-eu/opencloud/pkg/middleware" "github.com/opencloud-eu/opencloud/pkg/oidc" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/service/grpc" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" @@ -107,13 +108,14 @@ func Server(cfg *config.Config) *cli.Command { oidc.WithJWKSOptions(cfg.OIDC.JWKS), ) + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } + m := metrics.New() - - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - - defer cancel() - m.BuildInfo.WithLabelValues(version.GetString()).Set(1) rp, err := proxy.NewMultiHostReverseProxy( @@ -183,6 +185,7 @@ func Server(cfg *config.Config) *cli.Command { return fmt.Errorf("failed to initialize reverse proxy: %w", err) } + gr := runner.NewGroup() { middlewares := loadMiddlewares(logger, cfg, userInfoCache, signingKeyStore, traceProvider, *m, userProvider, publisher, gatewaySelector, serviceSelector) @@ -203,23 +206,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(func() error { - return server.Run() - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + gr.Add(runner.NewGoMicroHttpServerRunner("proxy_http", server)) } { @@ -233,13 +220,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("proxy_debug", debugServer)) } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/search/pkg/command/server.go b/services/search/pkg/command/server.go index bbb2c191a8..261b65b635 100644 --- a/services/search/pkg/command/server.go +++ b/services/search/pkg/command/server.go @@ -3,9 +3,10 @@ package command import ( "context" "fmt" + "os/signal" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" + "github.com/opencloud-eu/opencloud/pkg/runner" ogrpc "github.com/opencloud-eu/opencloud/pkg/service/grpc" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" @@ -40,13 +41,19 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) + gr := runner.NewGroup() + grpcServer, teardown, err := grpc.Server( grpc.Config(cfg), grpc.Logger(logger), @@ -62,21 +69,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(grpcServer.Run, func(_ error) { - if err == nil { - logger.Info(). - Str("transport", "grpc"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "grpc"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + gr.Add(runner.NewGoMicroGrpcServerRunner("search_grpc", grpcServer)) debugServer, err := debug.Server( debug.Logger(logger), @@ -88,12 +81,17 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("search_debug", debugServer)) - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/settings/pkg/command/server.go b/services/settings/pkg/command/server.go index ce66284fd9..4ae0942c64 100644 --- a/services/settings/pkg/command/server.go +++ b/services/settings/pkg/command/server.go @@ -3,9 +3,10 @@ package command import ( "context" "fmt" + "os/signal" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" + "github.com/opencloud-eu/opencloud/pkg/runner" ogrpc "github.com/opencloud-eu/opencloud/pkg/service/grpc" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" @@ -42,15 +43,20 @@ func Server(cfg *config.Config) *cli.Command { return err } - servers := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) handle := svc.NewDefaultLanguageService(cfg, svc.NewService(cfg, logger)) + servers := runner.NewGroup() + // prepare an HTTP server and add it to the group run. httpServer, err := http.Server( http.Name(cfg.Service.Name), @@ -67,21 +73,7 @@ func Server(cfg *config.Config) *cli.Command { Msg("Error initializing http service") return fmt.Errorf("could not initialize http service: %w", err) } - servers.Add(httpServer.Run, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + servers.Add(runner.NewGoMicroHttpServerRunner("settings_http", httpServer)) // prepare a gRPC server and add it to the group run. grpcServer := grpc.Server( @@ -93,21 +85,7 @@ func Server(cfg *config.Config) *cli.Command { grpc.ServiceHandler(handle), grpc.TraceProvider(traceProvider), ) - servers.Add(grpcServer.Run, func(_ error) { - if err == nil { - logger.Info(). - Str("transport", "grpc"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "grpc"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + servers.Add(runner.NewGoMicroGrpcServerRunner("settings_grpc", grpcServer)) // prepare a debug server and add it to the group run. debugServer, err := debug.Server( @@ -120,12 +98,17 @@ func Server(cfg *config.Config) *cli.Command { return err } - servers.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + servers.Add(runner.NewGolangHttpServerRunner("settings_debug", debugServer)) - return servers.Run() + grResults := servers.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/sse/pkg/command/server.go b/services/sse/pkg/command/server.go index 27fbd576c4..4579567d3a 100644 --- a/services/sse/pkg/command/server.go +++ b/services/sse/pkg/command/server.go @@ -3,8 +3,8 @@ package command import ( "context" "fmt" + "os/signal" - "github.com/oklog/run" "github.com/opencloud-eu/reva/v2/pkg/events" "github.com/opencloud-eu/reva/v2/pkg/events/stream" "github.com/urfave/cli/v2" @@ -12,6 +12,7 @@ import ( "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/generators" "github.com/opencloud-eu/opencloud/pkg/log" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/services/sse/pkg/config" "github.com/opencloud-eu/opencloud/services/sse/pkg/config/parser" @@ -34,24 +35,27 @@ func Server(cfg *config.Config) *cli.Command { return configlog.ReturnFatal(parser.ParseConfig(cfg)) }, Action: func(c *cli.Context) error { - var ( - gr = run.Group{} - ctx, cancel = context.WithCancel(c.Context) - logger = log.NewLogger( - log.Name(cfg.Service.Name), - log.Level(cfg.Log.Level), - log.Pretty(cfg.Log.Pretty), - log.Color(cfg.Log.Color), - log.File(cfg.Log.File), - ) + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } + + logger := log.NewLogger( + log.Name(cfg.Service.Name), + log.Level(cfg.Log.Level), + log.Pretty(cfg.Log.Pretty), + log.Color(cfg.Log.Color), + log.File(cfg.Log.File), ) - defer cancel() tracerProvider, err := tracing.GetServiceTraceProvider(cfg.Tracing, cfg.Service.Name) if err != nil { return err } + gr := runner.NewGroup() { connName := generators.GenerateConnectionName(cfg.Service.Name, generators.NTypeBus) natsStream, err := stream.NatsFromConfig(connName, true, stream.NatsConfig(cfg.Events)) @@ -71,9 +75,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(server.Run, func(_ error) { - cancel() - }) + gr.Add(runner.NewGoMicroHttpServerRunner("sse_http", server)) } { @@ -87,13 +89,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("sse_debug", debugServer)) } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/thumbnails/pkg/command/server.go b/services/thumbnails/pkg/command/server.go index d434e60b0a..cf1410bd81 100644 --- a/services/thumbnails/pkg/command/server.go +++ b/services/thumbnails/pkg/command/server.go @@ -3,9 +3,10 @@ package command import ( "context" "fmt" + "os/signal" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" + "github.com/opencloud-eu/opencloud/pkg/runner" ogrpc "github.com/opencloud-eu/opencloud/pkg/service/grpc" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" @@ -40,16 +41,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - var ( - gr = run.Group{} - ctx, cancel = context.WithCancel(c.Context) - m = metrics.New() - ) - - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } + m := metrics.New() m.BuildInfo.WithLabelValues(version.GetString()).Set(1) + gr := runner.NewGroup() + service := grpc.NewService( grpc.Logger(logger), grpc.Context(ctx), @@ -61,22 +64,7 @@ func Server(cfg *config.Config) *cli.Command { grpc.TraceProvider(traceProvider), grpc.MaxConcurrentRequests(cfg.GRPC.MaxConcurrentRequests), ) - - gr.Add(service.Run, func(_ error) { - if err == nil { - logger.Info(). - Str("transport", "grpc"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "grpc"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + gr.Add(runner.NewGoMicroGrpcServerRunner("thumbnails_grpc", service)) server, err := debug.Server( debug.Logger(logger), @@ -87,11 +75,7 @@ func Server(cfg *config.Config) *cli.Command { logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server") return err } - - gr.Add(server.ListenAndServe, func(_ error) { - _ = server.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("thumbnails_debug", server)) httpServer, err := http.Server( http.Logger(logger), @@ -109,24 +93,17 @@ func Server(cfg *config.Config) *cli.Command { return err } + gr.Add(runner.NewGoMicroHttpServerRunner("thumbnails_http", httpServer)) - gr.Add(httpServer.Run, func(_ error) { - if err == nil { - logger.Info(). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError } - - cancel() - }) - - return gr.Run() + } + return nil }, } } diff --git a/services/userlog/pkg/command/server.go b/services/userlog/pkg/command/server.go index b75e9f7ef7..d99c6b3125 100644 --- a/services/userlog/pkg/command/server.go +++ b/services/userlog/pkg/command/server.go @@ -3,8 +3,8 @@ package command import ( "context" "fmt" + "os/signal" - "github.com/oklog/run" "github.com/opencloud-eu/reva/v2/pkg/events" "github.com/opencloud-eu/reva/v2/pkg/events/stream" "github.com/opencloud-eu/reva/v2/pkg/rgrpc/todo/pool" @@ -15,6 +15,7 @@ import ( "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/generators" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" ogrpc "github.com/opencloud-eu/opencloud/pkg/service/grpc" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" @@ -69,14 +70,16 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) - defer cancel() - connName := generators.GenerateConnectionName(cfg.Service.Name, generators.NTypeBus) stream, err := stream.NatsFromConfig(connName, false, stream.NatsConfig(cfg.Events)) if err != nil { @@ -111,6 +114,7 @@ func Server(cfg *config.Config) *cli.Command { vClient := settingssvc.NewValueService("eu.opencloud.api.settings", grpcClient) rClient := settingssvc.NewRoleService("eu.opencloud.api.settings", grpcClient) + gr := runner.NewGroup() { server, err := http.Server( http.Logger(logger), @@ -132,23 +136,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(func() error { - return server.Run() - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + gr.Add(runner.NewGoMicroHttpServerRunner("userlog_http", server)) } { @@ -162,13 +150,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("userlog_debug", debugServer)) } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/web/pkg/command/server.go b/services/web/pkg/command/server.go index 25eeec2083..9bffe86bdc 100644 --- a/services/web/pkg/command/server.go +++ b/services/web/pkg/command/server.go @@ -5,9 +5,10 @@ import ( "encoding/json" "fmt" "os" + "os/signal" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/services/web/pkg/config" "github.com/opencloud-eu/opencloud/services/web/pkg/config/parser" @@ -47,14 +48,16 @@ func Server(cfg *config.Config) *cli.Command { } } - var ( - gr = run.Group{} - ctx, cancel = context.WithCancel(c.Context) - m = metrics.New() - ) + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - defer cancel() + m := metrics.New() + gr := runner.NewGroup() { server, err := http.Server( http.Logger(logger), @@ -73,30 +76,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(func() error { - err := server.Run() - if err != nil { - logger.Error(). - Err(err). - Str("transport", "http"). - Msg("Failed to start server") - } - return err - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + gr.Add(runner.NewGoMicroHttpServerRunner("web_http", server)) } { @@ -110,13 +90,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("web_debug", debugServer)) } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/webdav/pkg/command/server.go b/services/webdav/pkg/command/server.go index 51cf58ecde..48f0e0795a 100644 --- a/services/webdav/pkg/command/server.go +++ b/services/webdav/pkg/command/server.go @@ -3,9 +3,10 @@ package command import ( "context" "fmt" + "os/signal" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" + "github.com/opencloud-eu/opencloud/pkg/runner" ogrpc "github.com/opencloud-eu/opencloud/pkg/service/grpc" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" @@ -41,16 +42,17 @@ func Server(cfg *config.Config) *cli.Command { return err } - var ( - gr = run.Group{} - ctx, cancel = context.WithCancel(c.Context) - metrics = metrics.New() - ) - - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } + metrics := metrics.New() metrics.BuildInfo.WithLabelValues(version.GetString()).Set(1) + gr := runner.NewGroup() { server, err := http.Server( http.Logger(logger), @@ -69,23 +71,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(func() error { - return server.Run() - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + gr.Add(runner.NewGoMicroHttpServerRunner("webdav_http", server)) } { @@ -100,13 +86,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(err error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("webdav_debug", debugServer)) } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/webfinger/pkg/command/server.go b/services/webfinger/pkg/command/server.go index 432bc61213..1c58a4ee3c 100644 --- a/services/webfinger/pkg/command/server.go +++ b/services/webfinger/pkg/command/server.go @@ -3,9 +3,10 @@ package command import ( "context" "fmt" + "os/signal" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/webfinger/pkg/config" @@ -35,16 +36,17 @@ func Server(cfg *config.Config) *cli.Command { return err } - var ( - gr = run.Group{} - ctx, cancel = context.WithCancel(c.Context) - m = metrics.New(metrics.Logger(logger)) - ) - - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } + m := metrics.New(metrics.Logger(logger)) m.BuildInfo.WithLabelValues(version.GetString()).Set(1) + gr := runner.NewGroup() { relationProviders, err := getRelationProviders(cfg) if err != nil { @@ -82,23 +84,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(func() error { - return server.Run() - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + gr.Add(runner.NewGoMicroHttpServerRunner("webfinger_http", server)) } { @@ -113,13 +99,18 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(debugServer.ListenAndServe, func(err error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + gr.Add(runner.NewGolangHttpServerRunner("webfinger_debug", debugServer)) } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } From 7727c3ff1b89cb98c858d50cbc84e6041ba8b797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Pablo=20Villaf=C3=A1=C3=B1ez?= Date: Fri, 9 May 2025 11:49:17 +0200 Subject: [PATCH 02/11] fix: linter issue --- services/antivirus/pkg/service/service.go | 2 +- services/postprocessing/pkg/service/service.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/antivirus/pkg/service/service.go b/services/antivirus/pkg/service/service.go index 99c78d8794..796cf54c60 100644 --- a/services/antivirus/pkg/service/service.go +++ b/services/antivirus/pkg/service/service.go @@ -138,7 +138,7 @@ func (av Antivirus) Run() error { } wg := sync.WaitGroup{} - for i := 0; i < av.config.Workers; i++ { + for range av.config.Workers { wg.Add(1) go func() { defer wg.Done() diff --git a/services/postprocessing/pkg/service/service.go b/services/postprocessing/pkg/service/service.go index 9fb6b18d0d..fa59d21501 100644 --- a/services/postprocessing/pkg/service/service.go +++ b/services/postprocessing/pkg/service/service.go @@ -108,7 +108,7 @@ func NewPostprocessingService(ctx context.Context, logger log.Logger, sto store. func (pps *PostprocessingService) Run() error { wg := sync.WaitGroup{} - for i := 0; i < pps.c.Workers; i++ { + for range pps.c.Workers { wg.Add(1) go func() { defer wg.Done() From 65d05bbd5c8b35fa9547893e79511b6b12eac56e Mon Sep 17 00:00:00 2001 From: Roman Perekhod Date: Mon, 12 May 2025 23:15:07 +0200 Subject: [PATCH 03/11] feat: fix the graceful shutdown using the new ocis and reva runners MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- changelog/unreleased/fix-graceful-shutdown.md | 6 + opencloud/pkg/runtime/service/service.go | 76 ++++++-- pkg/runner/factory.go | 24 ++- pkg/runner/option.go | 6 +- services/app-provider/pkg/command/server.go | 75 ++++---- services/app-registry/pkg/command/server.go | 77 ++++---- services/auth-app/pkg/command/server.go | 104 +++++----- services/auth-basic/pkg/command/server.go | 79 ++++---- services/auth-bearer/pkg/command/server.go | 77 ++++---- services/auth-machine/pkg/command/server.go | 77 ++++---- services/auth-service/pkg/command/server.go | 84 ++++----- services/frontend/pkg/command/server.go | 96 +++++----- services/gateway/pkg/command/server.go | 78 ++++---- services/groups/pkg/command/server.go | 78 ++++---- services/ocm/pkg/command/server.go | 79 ++++---- services/settings/pkg/command/server.go | 10 +- services/sharing/pkg/command/server.go | 78 ++++---- .../storage-publiclink/pkg/command/server.go | 76 ++++---- services/storage-shares/pkg/command/server.go | 76 ++++---- services/storage-system/pkg/command/server.go | 76 ++++---- services/storage-users/pkg/command/server.go | 95 ++++------ services/users/pkg/command/server.go | 79 ++++---- .../reva/v2/cmd/revad/internal/grace/grace.go | 78 ++++---- .../reva/v2/cmd/revad/runtime/drivenserver.go | 178 ++++++++++++++++++ .../reva/v2/cmd/revad/runtime/runtime.go | 3 +- .../opencloud-eu/reva/v2/pkg/rgrpc/rgrpc.go | 4 +- .../opencloud-eu/reva/v2/pkg/rhttp/rhttp.go | 4 +- 27 files changed, 935 insertions(+), 838 deletions(-) create mode 100644 changelog/unreleased/fix-graceful-shutdown.md create mode 100644 vendor/github.com/opencloud-eu/reva/v2/cmd/revad/runtime/drivenserver.go diff --git a/changelog/unreleased/fix-graceful-shutdown.md b/changelog/unreleased/fix-graceful-shutdown.md new file mode 100644 index 0000000000..3e596433c3 --- /dev/null +++ b/changelog/unreleased/fix-graceful-shutdown.md @@ -0,0 +1,6 @@ +Bugfix: Fix the graceful shutdown + +Fix the graceful shutdown using the new ocis and reva runners. + +https://github.com/owncloud/ocis/pull/11295 +https://github.com/owncloud/ocis/issues/11170 \ No newline at end of file diff --git a/opencloud/pkg/runtime/service/service.go b/opencloud/pkg/runtime/service/service.go index bbf92aa082..ab161e8233 100644 --- a/opencloud/pkg/runtime/service/service.go +++ b/opencloud/pkg/runtime/service/service.go @@ -2,13 +2,15 @@ package service import ( "context" + "errors" "fmt" "net" "net/http" "net/rpc" - "os" + "os/signal" "sort" "strings" + "sync" "time" "github.com/cenkalti/backoff" @@ -16,6 +18,7 @@ import ( "github.com/olekukonko/tablewriter" occfg "github.com/opencloud-eu/opencloud/pkg/config" "github.com/opencloud-eu/opencloud/pkg/log" + "github.com/opencloud-eu/opencloud/pkg/runner" ogrpc "github.com/opencloud-eu/opencloud/pkg/service/grpc" "github.com/opencloud-eu/opencloud/pkg/shared" activitylog "github.com/opencloud-eu/opencloud/services/activitylog/pkg/command" @@ -358,8 +361,9 @@ func Start(ctx context.Context, o ...Option) error { return err } - // get a cancel function to stop the service - ctx, cancel := context.WithCancel(ctx) + // cancel the context when a signal is received. + notifyCtx, cancel := signal.NotifyContext(ctx, runner.StopSignals...) + defer cancel() // tolerance controls backoff cycles from the supervisor. tolerance := 5 @@ -397,6 +401,7 @@ func Start(ctx context.Context, o ...Option) error { if err != nil { s.Log.Fatal().Err(err).Msg("could not start listener") } + srv := new(http.Server) defer func() { if r := recover(); r != nil { @@ -404,7 +409,6 @@ func Start(ctx context.Context, o ...Option) error { if _, err = net.Dial("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)); err != nil { reason.WriteString("runtime address already in use") } - fmt.Println(reason.String()) } }() @@ -417,10 +421,7 @@ func Start(ctx context.Context, o ...Option) error { // go supervisor.Serve() // because that will briefly create a race condition as it starts up, if you try to .Add() services immediately afterward. // https://pkg.go.dev/github.com/thejerf/suture/v4@v4.0.0#Supervisor - go s.Supervisor.ServeBackground(s.context) - - // trap will block on context done channel for interruptions. - go trap(s, ctx) + go s.Supervisor.ServeBackground(s.context) // TODO Why does Supervisor uses s.context? for i, service := range s.Services { scheduleServiceTokens(s, service) @@ -434,7 +435,15 @@ func Start(ctx context.Context, o ...Option) error { // schedule services that are optional scheduleServiceTokens(s, s.Additional) - return http.Serve(l, nil) + go func() { + if err = srv.Serve(l); err != nil && !errors.Is(err, http.ErrServerClosed) { + s.Log.Fatal().Err(err).Msg("could not start rpc server") + } + }() + + // trapShutdownCtx will block on the context-done channel for interruptions. + trapShutdownCtx(s, srv, notifyCtx) + return nil } // scheduleServiceTokens adds service tokens to the service supervisor. @@ -501,20 +510,51 @@ func (s *Service) List(_ struct{}, reply *string) error { return nil } -// trap blocks on halt channel. When the runtime is interrupted it -// signals the controller to stop any supervised process. -func trap(s *Service, ctx context.Context) { +func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) { <-ctx.Done() + wg := sync.WaitGroup{} + wg.Add(1) + go func() { + defer wg.Done() + // TODO: To discuss the default timeout + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) + defer cancel() + if err := srv.Shutdown(ctx); err != nil { + s.Log.Error().Err(err).Msg("could not shutdown tcp listener") + return + } + s.Log.Info().Msg("tcp listener shutdown") + }() + for sName := range s.serviceToken { for i := range s.serviceToken[sName] { - if err := s.Supervisor.Remove(s.serviceToken[sName][i]); err != nil { - s.Log.Error().Err(err).Str("service", "runtime service").Msgf("terminating with signal: %v", s) - } + wg.Add(1) + go func() { + s.Log.Warn().Msgf("=== RemoveAndWait for %s", sName) + defer wg.Done() + // TODO: To discuss the default timeout + if err := s.Supervisor.RemoveAndWait(s.serviceToken[sName][i], 20*time.Second); err != nil && !errors.Is(err, suture.ErrSupervisorNotRunning) { + s.Log.Error().Err(err).Str("service", sName).Msgf("terminating with signal: %+v", s) + } + s.Log.Warn().Msgf("=== Done RemoveAndWait for %s", sName) + }() } } - s.Log.Debug().Str("service", "runtime service").Msgf("terminating with signal: %v", s) - time.Sleep(3 * time.Second) // give the services time to deregister - os.Exit(0) // FIXME this cause an early exit that prevents services from shitting down properly + + done := make(chan struct{}) + go func() { + wg.Wait() + close(done) + }() + + select { + // TODO: To discuss the default timeout + case <-time.After(30 * time.Second): + s.Log.Fatal().Msg("ocis graceful shutdown timeout reached, terminating") + case <-done: + s.Log.Info().Msg("all ocis services gracefully stopped") + return + } } // pingNats will attempt to connect to nats, blocking until a connection is established diff --git a/pkg/runner/factory.go b/pkg/runner/factory.go index e7925941e4..37767ddde4 100644 --- a/pkg/runner/factory.go +++ b/pkg/runner/factory.go @@ -9,6 +9,7 @@ import ( ogrpc "github.com/opencloud-eu/opencloud/pkg/service/grpc" ohttp "github.com/opencloud-eu/opencloud/pkg/service/http" + "github.com/opencloud-eu/reva/v2/cmd/revad/runtime" "google.golang.org/grpc" ) @@ -102,7 +103,8 @@ func NewGolangHttpServerRunner(name string, server *http.Server, opts ...Option) // Since Shutdown might take some time, don't block go func() { // give 5 secs for the shutdown to finish - shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + // TODO: To discuss the default timeout + shutdownCtx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel() debugCh <- server.Shutdown(shutdownCtx) @@ -132,3 +134,23 @@ func NewGolangGrpcServerRunner(name string, server *grpc.Server, listener net.Li return r } + +func NewRevaServiceRunner(name string, server runtime.RevaDrivenServer, opts ...Option) *Runner { + httpCh := make(chan error, 1) + r := New(name, func() error { + // start the server and return if it fails + if err := server.Start(); err != nil { + return err + } + return <-httpCh // wait for the result + }, func() { + // stop implies deregistering and waiting for the request to finish, + // so don't block + go func() { + httpCh <- server.Stop() // stop and send a result through a channel + close(httpCh) + }() + }, opts...) + + return r +} diff --git a/pkg/runner/option.go b/pkg/runner/option.go index af1dca0455..649deb14ed 100644 --- a/pkg/runner/option.go +++ b/pkg/runner/option.go @@ -7,10 +7,12 @@ import ( var ( // DefaultInterruptDuration is the default value for the `WithInterruptDuration` // for the "regular" runners. This global value can be adjusted if needed. - DefaultInterruptDuration = 10 * time.Second + // TODO: To discuss the default timeout + DefaultInterruptDuration = 20 * time.Second // DefaultGroupInterruptDuration is the default value for the `WithInterruptDuration` // for the group runners. This global value can be adjusted if needed. - DefaultGroupInterruptDuration = 15 * time.Second + // TODO: To discuss the default timeout + DefaultGroupInterruptDuration = 25 * time.Second ) // Option defines a single option function. diff --git a/services/app-provider/pkg/command/server.go b/services/app-provider/pkg/command/server.go index 16570e3e8b..0790f3b42d 100644 --- a/services/app-provider/pkg/command/server.go +++ b/services/app-provider/pkg/command/server.go @@ -4,15 +4,16 @@ import ( "context" "fmt" "os" + "os/signal" "path" "github.com/gofrs/uuid" - "github.com/oklog/run" "github.com/opencloud-eu/reva/v2/cmd/revad/runtime" "github.com/urfave/cli/v2" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/app-provider/pkg/config" @@ -37,66 +38,58 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - // make sure the run group executes all interrupt handlers when the context is canceled - gr.Add(func() error { - <-ctx.Done() - return nil - }, func(_ error) { - }) + gr := runner.NewGroup() - gr.Add(func() error { + { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.AppProviderConfigFromStruct(cfg) reg := registry.GetRegistry() - runtime.RunWithOptions(rCfg, pidFile, + revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) - - debugServer, err := debug.Server( - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - if err != nil { - logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") - return err + gr.Add(runner.NewRevaServiceRunner("app-provider_revad", revaSrv)) } - gr.Add(debugServer.ListenAndServe, func(_ error) { - cancel() - }) + { + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(runner.NewGolangHttpServerRunner("app-provider_debug", debugServer)) + } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/app-registry/pkg/command/server.go b/services/app-registry/pkg/command/server.go index 184ee32281..aa6e2c91f7 100644 --- a/services/app-registry/pkg/command/server.go +++ b/services/app-registry/pkg/command/server.go @@ -4,12 +4,13 @@ import ( "context" "fmt" "os" + "os/signal" "path" "github.com/gofrs/uuid" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/app-registry/pkg/config" @@ -36,67 +37,59 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - // make sure the run group executes all interrupt handlers when the context is canceled - gr.Add(func() error { - <-ctx.Done() - return nil - }, func(_ error) { - }) + gr := runner.NewGroup() + + { - gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.AppRegistryConfigFromStruct(cfg, logger) reg := registry.GetRegistry() - runtime.RunWithOptions(rCfg, pidFile, + revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) - - debugServer, err := debug.Server( - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - if err != nil { - logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") - return err + gr.Add(runner.NewRevaServiceRunner("app-registry_revad", revaSrv)) } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + { + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(runner.NewGolangHttpServerRunner("app-registry_debug", debugServer)) + } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/auth-app/pkg/command/server.go b/services/auth-app/pkg/command/server.go index 91fbebdb9b..51390cd964 100644 --- a/services/auth-app/pkg/command/server.go +++ b/services/auth-app/pkg/command/server.go @@ -4,12 +4,13 @@ import ( "context" "fmt" "os" + "os/signal" "path" "github.com/gofrs/uuid" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" ogrpc "github.com/opencloud-eu/opencloud/pkg/service/grpc" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" @@ -44,60 +45,43 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - // make sure the run group executes all interrupt handlers when the context is canceled - gr.Add(func() error { - <-ctx.Done() - return nil - }, func(_ error) { - }) + gr := runner.NewGroup() + { - gr.Add(func() error { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.AuthAppConfigFromStruct(cfg) reg := registry.GetRegistry() - runtime.RunWithOptions(rCfg, pidFile, + revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) + gr.Add(runner.NewRevaServiceRunner("auth-app_revad", revaSrv)) - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) - - debugServer, err := debug.Server( - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - if err != nil { - logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") - return err } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + { + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(runner.NewGolangHttpServerRunner("auth-app_debug", debugServer)) + } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { @@ -128,24 +112,32 @@ func Server(cfg *config.Config) *cli.Command { return err } - rClient := settingssvc.NewRoleService("eu.opencloud.api.settings", grpcClient) - server, err := http.Server( - http.Logger(logger), - http.Context(ctx), - http.Config(cfg), - http.GatewaySelector(gatewaySelector), - http.RoleClient(rClient), - http.TracerProvider(traceProvider), - ) - if err != nil { - logger.Fatal().Err(err).Msg("failed to initialize http server") + { + rClient := settingssvc.NewRoleService("eu.opencloud.api.settings", grpcClient) + server, err := http.Server( + http.Logger(logger), + http.Context(ctx), + http.Config(cfg), + http.GatewaySelector(gatewaySelector), + http.RoleClient(rClient), + http.TracerProvider(traceProvider), + ) + if err != nil { + logger.Fatal().Err(err).Msg("failed to initialize http server") + } + + gr.Add(runner.NewGoMicroHttpServerRunner("auth-app_http", server)) } - gr.Add(server.Run, func(err error) { - logger.Error().Err(err).Str("server", "http").Msg("shutting down server") - }) + grResults := gr.Run(ctx) - return gr.Run() + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/auth-basic/pkg/command/server.go b/services/auth-basic/pkg/command/server.go index 3ae1dffdf8..aa86c85395 100644 --- a/services/auth-basic/pkg/command/server.go +++ b/services/auth-basic/pkg/command/server.go @@ -4,13 +4,14 @@ import ( "context" "fmt" "os" + "os/signal" "path" "github.com/gofrs/uuid" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/ldap" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/auth-basic/pkg/config" @@ -37,10 +38,15 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } + + gr := runner.NewGroup() // the reva runtime calls `os.Exit` in the case of a failure and there is no way for the OpenCloud // runtime to catch it and restart a reva service. Therefore, we need to ensure the service has @@ -54,62 +60,47 @@ func Server(cfg *config.Config) *cli.Command { } } - // make sure the run group executes all interrupt handlers when the context is canceled - gr.Add(func() error { - <-ctx.Done() - return nil - }, func(_ error) { - }) - - gr.Add(func() error { + { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.AuthBasicConfigFromStruct(cfg) reg := registry.GetRegistry() - runtime.RunWithOptions(rCfg, pidFile, + revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) - - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) - - debugServer, err := debug.Server( - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - if err != nil { - logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") - return err + gr.Add(runner.NewRevaServiceRunner("auth-basic_revad", revaSrv)) } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + { + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(runner.NewGolangHttpServerRunner("auth-basic_debug", debugServer)) + } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/auth-bearer/pkg/command/server.go b/services/auth-bearer/pkg/command/server.go index 84c34183ab..96d4028c6e 100644 --- a/services/auth-bearer/pkg/command/server.go +++ b/services/auth-bearer/pkg/command/server.go @@ -4,12 +4,13 @@ import ( "context" "fmt" "os" + "os/signal" "path" "github.com/gofrs/uuid" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/auth-bearer/pkg/config" @@ -36,67 +37,57 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - // make sure the run group executes all interrupt handlers when the context is canceled - gr.Add(func() error { - <-ctx.Done() - return nil - }, func(_ error) { - }) + gr := runner.NewGroup() - gr.Add(func() error { + { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.AuthBearerConfigFromStruct(cfg) reg := registry.GetRegistry() - runtime.RunWithOptions(rCfg, pidFile, + revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) - - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) - - debugServer, err := debug.Server( - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - if err != nil { - logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") - return err + gr.Add(runner.NewRevaServiceRunner("auth-bearer_revad", revaSrv)) } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + { + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(runner.NewGolangHttpServerRunner("auth-bearer_debug", debugServer)) + } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/auth-machine/pkg/command/server.go b/services/auth-machine/pkg/command/server.go index b182c24b44..0b3ce11d0a 100644 --- a/services/auth-machine/pkg/command/server.go +++ b/services/auth-machine/pkg/command/server.go @@ -4,12 +4,13 @@ import ( "context" "fmt" "os" + "os/signal" "path" "github.com/gofrs/uuid" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/auth-machine/pkg/config" @@ -36,67 +37,57 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - // make sure the run group executes all interrupt handlers when the context is canceled - gr.Add(func() error { - <-ctx.Done() - return nil - }, func(_ error) { - }) + gr := runner.NewGroup() - gr.Add(func() error { + { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.AuthMachineConfigFromStruct(cfg) reg := registry.GetRegistry() - runtime.RunWithOptions(rCfg, pidFile, + revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) - - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) - - debugServer, err := debug.Server( - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - if err != nil { - logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") - return err + gr.Add(runner.NewRevaServiceRunner("auth-machine_revad", revaSrv)) } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + { + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(runner.NewGolangHttpServerRunner("auth-machine_debug", debugServer)) + } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/auth-service/pkg/command/server.go b/services/auth-service/pkg/command/server.go index 8f70dcdee6..90f24d83e7 100644 --- a/services/auth-service/pkg/command/server.go +++ b/services/auth-service/pkg/command/server.go @@ -4,12 +4,13 @@ import ( "context" "fmt" "os" + "os/signal" "path" "github.com/gofrs/uuid" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/auth-service/pkg/config" @@ -36,68 +37,57 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") - reg := registry.GetRegistry() + gr := runner.NewGroup() - rcfg := revaconfig.AuthMachineConfigFromStruct(cfg) + { + pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + reg := registry.GetRegistry() + rcfg := revaconfig.AuthMachineConfigFromStruct(cfg) - // make sure the run group executes all interrupt handlers when the context is canceled - gr.Add(func() error { - <-ctx.Done() - return nil - }, func(_ error) { - }) - - gr.Add(func() error { - runtime.RunWithOptions(rcfg, pidFile, + revaSrv := runtime.RunDrivenServerWithOptions(rcfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) - - debugServer, err := debug.Server( - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - - if err != nil { - logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") - return err + gr.Add(runner.NewRevaServiceRunner("auth-service_revad", revaSrv)) } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + { + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(runner.NewGolangHttpServerRunner("auth-service_debug", debugServer)) + } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/frontend/pkg/command/server.go b/services/frontend/pkg/command/server.go index bc78570519..ea0da1b7a7 100644 --- a/services/frontend/pkg/command/server.go +++ b/services/frontend/pkg/command/server.go @@ -4,15 +4,16 @@ import ( "context" "fmt" "os" + "os/signal" "path" "github.com/gofrs/uuid" - "github.com/oklog/run" "github.com/opencloud-eu/reva/v2/cmd/revad/runtime" "github.com/urfave/cli/v2" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/frontend/pkg/config" @@ -37,64 +38,45 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() - - rCfg, err := revaconfig.FrontendConfigFromStruct(cfg, logger) - if err != nil { - return err + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() } - // make sure the run group executes all interrupt handlers when the context is canceled - gr.Add(func() error { - <-ctx.Done() - return nil - }, func(_ error) { - }) + gr := runner.NewGroup() - gr.Add(func() error { + { + rCfg, err := revaconfig.FrontendConfigFromStruct(cfg, logger) + if err != nil { + return err + } pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") reg := registry.GetRegistry() - runtime.RunWithOptions(rCfg, pidFile, + revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) - - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) - - debugServer, err := debug.Server( - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - if err != nil { - logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") - return err + gr.Add(runner.NewRevaServiceRunner("frontend_revad", revaSrv)) } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + { + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(runner.NewGolangHttpServerRunner("frontend_debug", debugServer)) + } httpSvc := registry.BuildHTTPService(cfg.HTTP.Namespace+"."+cfg.Service.Name, cfg.HTTP.Addr, version.GetString()) if err := registry.RegisterService(ctx, logger, httpSvc, cfg.Debug.Addr); err != nil { @@ -102,13 +84,23 @@ func Server(cfg *config.Config) *cli.Command { } // add event handler - gr.Add(func() error { - return ListenForEvents(ctx, cfg, logger) - }, func(_ error) { - cancel() - }) + gr.Add(runner.New("frontend_event", + func() error { + return ListenForEvents(ctx, cfg, logger) + }, func() { + logger.Info().Msg("stopping event handler") + }, + )) - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/gateway/pkg/command/server.go b/services/gateway/pkg/command/server.go index 20b5ed752a..e131a12749 100644 --- a/services/gateway/pkg/command/server.go +++ b/services/gateway/pkg/command/server.go @@ -4,12 +4,13 @@ import ( "context" "fmt" "os" + "os/signal" "path" "github.com/gofrs/uuid" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/gateway/pkg/config" @@ -36,69 +37,58 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - // make sure the run group executes all interrupt handlers when the context is canceled - gr.Add(func() error { - <-ctx.Done() - return nil - }, func(_ error) { - }) + gr := runner.NewGroup() - gr.Add(func() error { + { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.GatewayConfigFromStruct(cfg, logger) reg := registry.GetRegistry() - runtime.RunWithOptions(rCfg, pidFile, + revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) - logger.Info(). - Str("server", cfg.Service.Name). - Msg("reva runtime exited") - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - cancel() - }) - - debugServer, err := debug.Server( - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - if err != nil { - logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") - return err + gr.Add(runner.NewRevaServiceRunner("gateway_revad", revaSrv)) } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + { + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(runner.NewGolangHttpServerRunner("gateway_debug", debugServer)) + } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/groups/pkg/command/server.go b/services/groups/pkg/command/server.go index 6371e1b146..2282e786e8 100644 --- a/services/groups/pkg/command/server.go +++ b/services/groups/pkg/command/server.go @@ -4,13 +4,14 @@ import ( "context" "fmt" "os" + "os/signal" "path" "github.com/gofrs/uuid" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/ldap" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/groups/pkg/config" @@ -37,10 +38,6 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - - defer cancel() // the reva runtime calls os.Exit in the case of a failure and there is no way for the OpenCloud // runtime to catch it and restart a reva service. Therefore we need to ensure the service has @@ -54,62 +51,57 @@ func Server(cfg *config.Config) *cli.Command { } } - // make sure the run group executes all interrupt handlers when the context is canceled - gr.Add(func() error { - <-ctx.Done() - return nil - }, func(_ error) { - }) + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - gr.Add(func() error { + gr := runner.NewGroup() + + { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.GroupsConfigFromStruct(cfg) reg := registry.GetRegistry() - runtime.RunWithOptions(rCfg, pidFile, + revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) - - debugServer, err := debug.Server( - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - if err != nil { - logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") - return err + gr.Add(runner.NewRevaServiceRunner("groups_revad", revaSrv)) } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + { + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(runner.NewGolangHttpServerRunner("groups_debug", debugServer)) + } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/ocm/pkg/command/server.go b/services/ocm/pkg/command/server.go index 900be491ba..f0f955eea4 100644 --- a/services/ocm/pkg/command/server.go +++ b/services/ocm/pkg/command/server.go @@ -4,12 +4,13 @@ import ( "context" "fmt" "os" + "os/signal" "path" "github.com/gofrs/uuid" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/ocm/pkg/config" @@ -36,61 +37,43 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - rCfg := revaconfig.OCMConfigFromStruct(cfg, logger) + gr := runner.NewGroup() - // make sure the run group executes all interrupt handlers when the context is canceled - gr.Add(func() error { - <-ctx.Done() - return nil - }, func(_ error) { - }) - - gr.Add(func() error { + { + rCfg := revaconfig.OCMConfigFromStruct(cfg, logger) pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") reg := registry.GetRegistry() - runtime.RunWithOptions(rCfg, pidFile, + revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "http"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) - - debugServer, err := debug.Server( - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - if err != nil { - logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") - return err + gr.Add(runner.NewRevaServiceRunner("ocm_revad", revaSrv)) } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + { + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(runner.NewGolangHttpServerRunner("ocm_debug", debugServer)) + } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { @@ -102,7 +85,15 @@ func Server(cfg *config.Config) *cli.Command { logger.Fatal().Err(err).Msg("failed to register the http service") } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/settings/pkg/command/server.go b/services/settings/pkg/command/server.go index 4ae0942c64..67bd695378 100644 --- a/services/settings/pkg/command/server.go +++ b/services/settings/pkg/command/server.go @@ -55,7 +55,7 @@ func Server(cfg *config.Config) *cli.Command { handle := svc.NewDefaultLanguageService(cfg, svc.NewService(cfg, logger)) - servers := runner.NewGroup() + gr := runner.NewGroup() // prepare an HTTP server and add it to the group run. httpServer, err := http.Server( @@ -73,7 +73,7 @@ func Server(cfg *config.Config) *cli.Command { Msg("Error initializing http service") return fmt.Errorf("could not initialize http service: %w", err) } - servers.Add(runner.NewGoMicroHttpServerRunner("settings_http", httpServer)) + gr.Add(runner.NewGoMicroHttpServerRunner("settings_http", httpServer)) // prepare a gRPC server and add it to the group run. grpcServer := grpc.Server( @@ -85,7 +85,7 @@ func Server(cfg *config.Config) *cli.Command { grpc.ServiceHandler(handle), grpc.TraceProvider(traceProvider), ) - servers.Add(runner.NewGoMicroGrpcServerRunner("settings_grpc", grpcServer)) + gr.Add(runner.NewGoMicroGrpcServerRunner("settings_grpc", grpcServer)) // prepare a debug server and add it to the group run. debugServer, err := debug.Server( @@ -98,9 +98,9 @@ func Server(cfg *config.Config) *cli.Command { return err } - servers.Add(runner.NewGolangHttpServerRunner("settings_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner("settings_debug", debugServer)) - grResults := servers.Run(ctx) + grResults := gr.Run(ctx) // return the first non-nil error found in the results for _, grResult := range grResults { diff --git a/services/sharing/pkg/command/server.go b/services/sharing/pkg/command/server.go index 0193406a56..6b29f4ace5 100644 --- a/services/sharing/pkg/command/server.go +++ b/services/sharing/pkg/command/server.go @@ -4,13 +4,14 @@ import ( "context" "fmt" "os" + "os/signal" "path" "path/filepath" "github.com/gofrs/uuid" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/sharing/pkg/config" @@ -37,10 +38,6 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - - defer cancel() // precreate folders if cfg.UserSharingDriver == "json" && cfg.UserSharingDrivers.JSON.File != "" { @@ -54,14 +51,16 @@ func Server(cfg *config.Config) *cli.Command { } } - // make sure the run group executes all interrupt handlers when the context is canceled - gr.Add(func() error { - <-ctx.Done() - return nil - }, func(_ error) { - }) + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - gr.Add(func() error { + gr := runner.NewGroup() + + { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg, err := revaconfig.SharingConfigFromStruct(cfg, logger) if err != nil { @@ -69,50 +68,43 @@ func Server(cfg *config.Config) *cli.Command { } reg := registry.GetRegistry() - runtime.RunWithOptions(rCfg, pidFile, + revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) - - debugServer, err := debug.Server( - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - - if err != nil { - logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") - return err + gr.Add(runner.NewRevaServiceRunner("sharing_revad", revaSrv)) } - gr.Add(debugServer.ListenAndServe, func(_ error) { - cancel() - }) + { + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(runner.NewGolangHttpServerRunner("sharing_debug", debugServer)) + } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/storage-publiclink/pkg/command/server.go b/services/storage-publiclink/pkg/command/server.go index 95ca4a4f21..50b937dbf0 100644 --- a/services/storage-publiclink/pkg/command/server.go +++ b/services/storage-publiclink/pkg/command/server.go @@ -4,12 +4,13 @@ import ( "context" "fmt" "os" + "os/signal" "path" "github.com/gofrs/uuid" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/storage-publiclink/pkg/config" @@ -36,67 +37,58 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - // make sure the run group executes all interrupt handlers when the context is canceled - gr.Add(func() error { - <-ctx.Done() - return nil - }, func(_ error) { - }) + gr := runner.NewGroup() - gr.Add(func() error { + { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.StoragePublicLinkConfigFromStruct(cfg) reg := registry.GetRegistry() - runtime.RunWithOptions(rCfg, pidFile, + revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) - - debugServer, err := debug.Server( - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - if err != nil { - logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") - return err + gr.Add(runner.NewRevaServiceRunner("storage-publiclink_revad", revaSrv)) } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + { + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(runner.NewGolangHttpServerRunner("storage-publiclink_debug", debugServer)) + } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/storage-shares/pkg/command/server.go b/services/storage-shares/pkg/command/server.go index a0ccf04829..1abce31c41 100644 --- a/services/storage-shares/pkg/command/server.go +++ b/services/storage-shares/pkg/command/server.go @@ -4,12 +4,13 @@ import ( "context" "fmt" "os" + "os/signal" "path" "github.com/gofrs/uuid" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/storage-shares/pkg/config" @@ -36,67 +37,58 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - // make sure the run group executes all interrupt handlers when the context is canceled - gr.Add(func() error { - <-ctx.Done() - return nil - }, func(_ error) { - }) + gr := runner.NewGroup() - gr.Add(func() error { + { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.StorageSharesConfigFromStruct(cfg) reg := registry.GetRegistry() - runtime.RunWithOptions(rCfg, pidFile, + revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) - - debugServer, err := debug.Server( - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - if err != nil { - logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") - return err + gr.Add(runner.NewRevaServiceRunner("storage-shares_revad", revaSrv)) } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + { + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(runner.NewGolangHttpServerRunner("storage-shares_debug", debugServer)) + } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { logger.Fatal().Err(err).Msg("failed to register the grpc service") } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/storage-system/pkg/command/server.go b/services/storage-system/pkg/command/server.go index 7b98cdabb0..f8882b841c 100644 --- a/services/storage-system/pkg/command/server.go +++ b/services/storage-system/pkg/command/server.go @@ -4,15 +4,16 @@ import ( "context" "fmt" "os" + "os/signal" "path" "github.com/gofrs/uuid" - "github.com/oklog/run" "github.com/opencloud-eu/reva/v2/cmd/revad/runtime" "github.com/urfave/cli/v2" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/storage-system/pkg/config" @@ -37,60 +38,43 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - // make sure the run group executes all interrupt handlers when the context is canceled - gr.Add(func() error { - <-ctx.Done() - return nil - }, func(_ error) { - }) + gr := runner.NewGroup() - gr.Add(func() error { + { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.StorageSystemFromStruct(cfg) reg := registry.GetRegistry() - runtime.RunWithOptions(rCfg, pidFile, + revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) - - debugServer, err := debug.Server( - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - if err != nil { - logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") - return err + gr.Add(runner.NewRevaServiceRunner("storage-system_revad", revaSrv)) } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + { + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(runner.NewGolangHttpServerRunner("storage-system_debug", debugServer)) + } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { @@ -102,7 +86,15 @@ func Server(cfg *config.Config) *cli.Command { logger.Fatal().Err(err).Msg("failed to register the http service") } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/storage-users/pkg/command/server.go b/services/storage-users/pkg/command/server.go index 9e1d881c17..338e0f6d76 100644 --- a/services/storage-users/pkg/command/server.go +++ b/services/storage-users/pkg/command/server.go @@ -4,12 +4,13 @@ import ( "context" "fmt" "os" + "os/signal" "path" "github.com/gofrs/uuid" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/storage-users/pkg/config" @@ -38,60 +39,42 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - defer cancel() + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - // make sure the run group executes all interrupt handlers when the context is canceled - gr.Add(func() error { - <-ctx.Done() - return nil - }, func(_ error) { - }) + gr := runner.NewGroup() - gr.Add(func() error { + { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.StorageUsersConfigFromStruct(cfg) reg := registry.GetRegistry() - runtime.RunWithOptions(rCfg, pidFile, + revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) - - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) - - debugServer, err := debug.Server( - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - if err != nil { - logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") - return err + gr.Add(runner.NewRevaServiceRunner("storage-users_revad", revaSrv)) } - gr.Add(debugServer.ListenAndServe, func(err error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + { + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(runner.NewGolangHttpServerRunner("storage-users_debug", debugServer)) + } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) if err := registry.RegisterService(ctx, logger, grpcSvc, cfg.Debug.Addr); err != nil { @@ -113,25 +96,19 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { logger.Fatal().Err(err).Msg("can't create event handler") } - - gr.Add(eventSVC.Run, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "stream"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "stream"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) + // The event service Run() function handles the stop signal itself + go eventSVC.Run() } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/services/users/pkg/command/server.go b/services/users/pkg/command/server.go index fc26b68501..e215b5e385 100644 --- a/services/users/pkg/command/server.go +++ b/services/users/pkg/command/server.go @@ -4,13 +4,14 @@ import ( "context" "fmt" "os" + "os/signal" "path" "github.com/gofrs/uuid" - "github.com/oklog/run" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/ldap" "github.com/opencloud-eu/opencloud/pkg/registry" + "github.com/opencloud-eu/opencloud/pkg/runner" "github.com/opencloud-eu/opencloud/pkg/tracing" "github.com/opencloud-eu/opencloud/pkg/version" "github.com/opencloud-eu/opencloud/services/users/pkg/config" @@ -37,10 +38,6 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr := run.Group{} - ctx, cancel := context.WithCancel(c.Context) - - defer cancel() // the reva runtime calls os.Exit in the case of a failure and there is no way for the OpenCloud // runtime to catch it and restart a reva service. Therefore we need to ensure the service has @@ -54,55 +51,41 @@ func Server(cfg *config.Config) *cli.Command { } } - // make sure the run group executes all interrupt handlers when the context is canceled - gr.Add(func() error { - <-ctx.Done() - return nil - }, func(_ error) { - }) + var cancel context.CancelFunc + ctx := cfg.Context + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } - gr.Add(func() error { + gr := runner.NewGroup() + + { pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg := revaconfig.UsersConfigFromStruct(cfg) reg := registry.GetRegistry() - runtime.RunWithOptions(rCfg, pidFile, + revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, runtime.WithLogger(&logger.Logger), runtime.WithRegistry(reg), runtime.WithTraceProvider(traceProvider), ) - - return nil - }, func(err error) { - if err == nil { - logger.Info(). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } else { - logger.Error().Err(err). - Str("transport", "reva"). - Str("server", cfg.Service.Name). - Msg("Shutting down server") - } - - cancel() - }) - - debugServer, err := debug.Server( - debug.Logger(logger), - debug.Context(ctx), - debug.Config(cfg), - ) - if err != nil { - logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") - return err + gr.Add(runner.NewRevaServiceRunner("users_revad", revaSrv)) } - gr.Add(debugServer.ListenAndServe, func(_ error) { - _ = debugServer.Shutdown(ctx) - cancel() - }) + { + debugServer, err := debug.Server( + debug.Logger(logger), + debug.Context(ctx), + debug.Config(cfg), + ) + if err != nil { + logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") + return err + } + + gr.Add(runner.NewGolangHttpServerRunner("users_debug", debugServer)) + } // FIXME we should defer registering the service until we are sure that reva is running grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) @@ -110,7 +93,15 @@ func Server(cfg *config.Config) *cli.Command { logger.Fatal().Err(err).Msg("failed to register the grpc service") } - return gr.Run() + grResults := gr.Run(ctx) + + // return the first non-nil error found in the results + for _, grResult := range grResults { + if grResult.RunnerError != nil { + return grResult.RunnerError + } + } + return nil }, } } diff --git a/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/internal/grace/grace.go b/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/internal/grace/grace.go index afdc6da6b7..0366d05558 100644 --- a/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/internal/grace/grace.go +++ b/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/internal/grace/grace.go @@ -26,6 +26,7 @@ import ( "path/filepath" "strconv" "strings" + "sync" "syscall" "time" @@ -88,13 +89,18 @@ func NewWatcher(opts ...Option) *Watcher { // Exit exits the current process cleaning up // existing pid files. func (w *Watcher) Exit(errc int) { + w.Clean() + os.Exit(errc) +} + +// Clean removes the pid file. +func (w *Watcher) Clean() { err := w.clean() if err != nil { w.log.Warn().Err(err).Msg("error removing pid file") } else { w.log.Info().Msgf("pid file %q got removed", w.pidFile) } - os.Exit(errc) } func (w *Watcher) clean() error { @@ -266,7 +272,7 @@ type Server interface { // TrapSignals captures the OS signal. func (w *Watcher) TrapSignals() { signalCh := make(chan os.Signal, 1024) - signal.Notify(signalCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT) + signal.Notify(signalCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM) for { s := <-signalCh w.log.Info().Msgf("%v signal received", s) @@ -284,14 +290,9 @@ func (w *Watcher) TrapSignals() { w.log.Info().Msgf("child forked with new pid %d", p.Pid) w.childPIDs = append(w.childPIDs, p.Pid) } - - case syscall.SIGQUIT: - gracefulShutdown(w) - case syscall.SIGINT, syscall.SIGTERM: - if w.gracefulShutdownTimeout == 0 { - hardShutdown(w) - } + case syscall.SIGQUIT, syscall.SIGINT, syscall.SIGTERM: gracefulShutdown(w) + return } } } @@ -300,38 +301,43 @@ func (w *Watcher) TrapSignals() { // exit() is problematic (i.e. racey) especiaily when orchestrating multiple // reva services from some external runtime (like in the "opencloud server" case func gracefulShutdown(w *Watcher) { + defer w.Clean() w.log.Info().Int("Timeout", w.gracefulShutdownTimeout).Msg("preparing for a graceful shutdown with deadline") + wg := sync.WaitGroup{} + + for _, s := range w.ss { + wg.Add(1) + go func() { + defer wg.Done() + w.log.Info().Msgf("fd to %s:%s gracefully closed", s.Network(), s.Address()) + err := s.GracefulStop() + if err != nil { + w.log.Error().Err(err).Msg("error stopping server") + } + }() + } + + done := make(chan struct{}) go func() { - count := w.gracefulShutdownTimeout - ticker := time.NewTicker(time.Second) - for ; true; <-ticker.C { - w.log.Info().Msgf("shutting down in %d seconds", count-1) - count-- - if count <= 0 { - w.log.Info().Msg("deadline reached before draining active conns, hard stopping ...") - for _, s := range w.ss { - err := s.Stop() - if err != nil { - w.log.Error().Err(err).Msg("error stopping server") - } - w.log.Info().Msgf("fd to %s:%s abruptly closed", s.Network(), s.Address()) - } - w.Exit(1) + wg.Wait() + close(done) + }() + + select { + case <-time.After(time.Duration(w.gracefulShutdownTimeout) * time.Second): + w.log.Info().Msg("graceful shutdown timeout reached. running hard shutdown") + for _, s := range w.ss { + w.log.Info().Msgf("fd to %s:%s abruptly closed", s.Network(), s.Address()) + err := s.Stop() + if err != nil { + w.log.Error().Err(err).Msg("error stopping server") } } - }() - for _, s := range w.ss { - w.log.Info().Msgf("fd to %s:%s gracefully closed ", s.Network(), s.Address()) - err := s.GracefulStop() - if err != nil { - w.log.Error().Err(err).Msg("error stopping server") - w.log.Info().Msg("exit with error code 1") - - w.Exit(1) - } + return + case <-done: + w.log.Info().Msg("all servers gracefully stopped") + return } - w.log.Info().Msg("exit with error code 0") - w.Exit(0) } // TODO: Ideally this would call exit() but properly return an error. The diff --git a/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/runtime/drivenserver.go b/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/runtime/drivenserver.go new file mode 100644 index 0000000000..b9eb819ece --- /dev/null +++ b/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/runtime/drivenserver.go @@ -0,0 +1,178 @@ +package runtime + +import ( + "errors" + "fmt" + "net" + "net/http" + "os" + "time" + + "github.com/opencloud-eu/reva/v2/pkg/registry" + "github.com/rs/zerolog" +) + +const ( + HTTP = iota + GRPC +) + +// RevaDrivenServer is an interface that defines the methods for starting and stopping reva HTTP/GRPC services. +type RevaDrivenServer interface { + Start() error + Stop() error +} + +// revaServer is an interface that defines the methods for starting and stopping a reva server. +type revaServer interface { + Start(ln net.Listener) error + Stop() error + GracefulStop() error + Network() string + Address() string +} + +// sever represents a generic reva server that implements the RevaDrivenServer interface. +type server struct { + srv revaServer + log *zerolog.Logger + gracefulShutdownTimeout time.Duration + protocol string +} + +// NewDrivenHTTPServerWithOptions runs a revad server w/o watcher with the given config file and options. +// Use it in cases where you want to run a revad server without the need for a watcher and the os signal handling as a part of another runtime. +// Returns nil if no http server is configured in the config file. +// The GracefulShutdownTimeout set to default 20 seconds and can be overridden in the core config. +// Logging a fatal error and exit with code 1 if the http server cannot be created. +func NewDrivenHTTPServerWithOptions(mainConf map[string]interface{}, opts ...Option) RevaDrivenServer { + if !isEnabledHTTP(mainConf) { + return nil + } + options := newOptions(opts...) + if srv := newServer(HTTP, mainConf, options); srv != nil { + return srv + } + options.Logger.Fatal().Msg("nothing to do, no http enabled_services declared in config") + return nil +} + +// NewDrivenGRPCServerWithOptions runs a revad server w/o watcher with the given config file and options. +// Use it in cases where you want to run a revad server without the need for a watcher and the os signal handling as a part of another runtime. +// Returns nil if no grpc server is configured in the config file. +// The GracefulShutdownTimeout set to default 20 seconds and can be overridden in the core config. +// Logging a fatal error and exit with code 1 if the grpc server cannot be created. +func NewDrivenGRPCServerWithOptions(mainConf map[string]interface{}, opts ...Option) RevaDrivenServer { + if !isEnabledGRPC(mainConf) { + return nil + } + options := newOptions(opts...) + if srv := newServer(GRPC, mainConf, options); srv != nil { + return srv + } + options.Logger.Fatal().Msg("nothing to do, no grpc enabled_services declared in config") + return nil +} + +// Start starts the reva server, listening on the configured address and network. +func (s *server) Start() error { + if s.srv == nil { + err := fmt.Errorf("reva %s server not initialized", s.protocol) + s.log.Fatal().Err(err).Send() + return err + } + ln, err := net.Listen(s.srv.Network(), s.srv.Address()) + if err != nil { + s.log.Fatal().Err(err).Send() + return err + } + if err = s.srv.Start(ln); err != nil { + if !errors.Is(err, http.ErrServerClosed) { + s.log.Error().Err(err).Msgf("reva %s server error", s.protocol) + } + return err + } + return nil +} + +// Stop gracefully stops the reva server, waiting for the graceful shutdown timeout. +func (s *server) Stop() error { + if s.srv == nil { + return nil + } + done := make(chan struct{}) + go func() { + s.log.Info().Msgf("gracefully stopping %s:%s reva %s server", s.srv.Network(), s.srv.Address(), s.protocol) + if err := s.srv.GracefulStop(); err != nil { + s.log.Error().Err(err).Msgf("error gracefully stopping reva %s server", s.protocol) + s.srv.Stop() + } + close(done) + }() + + select { + case <-time.After(s.gracefulShutdownTimeout): + s.log.Info().Msg("graceful shutdown timeout reached. running hard shutdown") + err := s.srv.Stop() + if err != nil { + s.log.Error().Err(err).Msgf("error stopping reva %s server", s.protocol) + } + return nil + case <-done: + s.log.Info().Msgf("reva %s server gracefully stopped", s.protocol) + return nil + } +} + +// newServer runs a revad server w/o watcher with the given config file and options. +func newServer(protocol int, mainConf map[string]interface{}, options Options) RevaDrivenServer { + parseSharedConfOrDie(mainConf["shared"]) + coreConf := parseCoreConfOrDie(mainConf["core"]) + log := options.Logger + + if err := registry.Init(options.Registry); err != nil { + log.Fatal().Err(err).Msg("failed to initialize registry client") + return nil + } + + host, _ := os.Hostname() + log.Info().Msgf("host info: %s", host) + + // Only initialize tracing if we didn't get a tracer provider. + if options.TraceProvider == nil { + log.Debug().Msg("no pre-existing tracer given, initializing tracing") + options.TraceProvider = initTracing(coreConf) + } + initCPUCount(coreConf, log) + + gracefulShutdownTimeout := 20 * time.Second + if coreConf.GracefulShutdownTimeout > 0 { + gracefulShutdownTimeout = time.Duration(coreConf.GracefulShutdownTimeout) * time.Second + } + + srv := &server{ + log: options.Logger, + gracefulShutdownTimeout: gracefulShutdownTimeout, + } + switch protocol { + case HTTP: + s, err := getHTTPServer(mainConf["http"], options.Logger, options.TraceProvider) + if err != nil { + options.Logger.Fatal().Err(err).Msg("error creating http server") + return nil + } + srv.srv = s + srv.protocol = "http" + return srv + case GRPC: + s, err := getGRPCServer(mainConf["grpc"], options.Logger, options.TraceProvider) + if err != nil { + options.Logger.Fatal().Err(err).Msg("error creating grpc server") + return nil + } + srv.srv = s + srv.protocol = "grpc" + return srv + } + return nil +} diff --git a/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/runtime/runtime.go b/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/runtime/runtime.go index 4e7dc3d73f..2ae269195a 100644 --- a/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/runtime/runtime.go +++ b/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/runtime/runtime.go @@ -53,7 +53,8 @@ func RunWithOptions(mainConf map[string]interface{}, pidFile string, opts ...Opt coreConf := parseCoreConfOrDie(mainConf["core"]) if err := registry.Init(options.Registry); err != nil { - panic(err) + options.Logger.Fatal().Err(err).Msg("failed to initialize registry client") + return } run(mainConf, coreConf, options.Logger, options.TraceProvider, pidFile) diff --git a/vendor/github.com/opencloud-eu/reva/v2/pkg/rgrpc/rgrpc.go b/vendor/github.com/opencloud-eu/reva/v2/pkg/rgrpc/rgrpc.go index 8adb98afe4..43e4821d35 100644 --- a/vendor/github.com/opencloud-eu/reva/v2/pkg/rgrpc/rgrpc.go +++ b/vendor/github.com/opencloud-eu/reva/v2/pkg/rgrpc/rgrpc.go @@ -279,15 +279,15 @@ func (s *Server) cleanupServices() { // Stop stops the server. func (s *Server) Stop() error { - s.cleanupServices() s.s.Stop() + s.cleanupServices() return nil } // GracefulStop gracefully stops the server. func (s *Server) GracefulStop() error { - s.cleanupServices() s.s.GracefulStop() + s.cleanupServices() return nil } diff --git a/vendor/github.com/opencloud-eu/reva/v2/pkg/rhttp/rhttp.go b/vendor/github.com/opencloud-eu/reva/v2/pkg/rhttp/rhttp.go index 3d6919b509..6636280b60 100644 --- a/vendor/github.com/opencloud-eu/reva/v2/pkg/rhttp/rhttp.go +++ b/vendor/github.com/opencloud-eu/reva/v2/pkg/rhttp/rhttp.go @@ -132,10 +132,10 @@ func (s *Server) Start(ln net.Listener) error { // Stop stops the server. func (s *Server) Stop() error { - s.closeServices() // TODO(labkode): set ctx deadline to zero ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() + defer s.closeServices() return s.httpServer.Shutdown(ctx) } @@ -164,7 +164,7 @@ func (s *Server) Address() string { // GracefulStop gracefully stops the server. func (s *Server) GracefulStop() error { - s.closeServices() + defer s.closeServices() return s.httpServer.Shutdown(context.Background()) } From 9a3fc08dd461c199ba791a5e44ecdc8ddb1a46cc Mon Sep 17 00:00:00 2001 From: Roman Perekhod Date: Tue, 20 May 2025 23:41:26 +0200 Subject: [PATCH 04/11] to separate controll ower the http and grpc driven services --- opencloud/pkg/runtime/service/service.go | 32 ++++++++----------- pkg/runner/factory.go | 14 +++++--- pkg/runner/option.go | 2 -- services/antivirus/pkg/command/server.go | 6 ++-- services/app-provider/pkg/command/server.go | 30 +++++++++-------- services/app-registry/pkg/command/server.go | 31 +++++++++--------- services/audit/pkg/command/server.go | 6 ++-- services/auth-app/pkg/command/server.go | 31 +++++++++--------- services/auth-basic/pkg/command/server.go | 29 +++++++++-------- services/auth-bearer/pkg/command/server.go | 29 +++++++++-------- services/auth-machine/pkg/command/server.go | 29 +++++++++-------- services/auth-service/pkg/command/server.go | 31 ++++++++++-------- services/clientlog/pkg/command/server.go | 6 ++-- services/collaboration/pkg/command/server.go | 6 ++-- services/eventhistory/pkg/command/server.go | 6 ++-- services/frontend/pkg/command/server.go | 28 +++++++++------- services/gateway/pkg/command/server.go | 30 +++++++++-------- services/graph/pkg/command/server.go | 6 ++-- services/groups/pkg/command/server.go | 30 +++++++++-------- services/idm/pkg/command/server.go | 6 ++-- services/idp/pkg/command/server.go | 6 ++-- services/invitations/pkg/command/server.go | 6 ++-- services/nats/pkg/command/server.go | 6 ++-- services/notifications/pkg/command/server.go | 6 ++-- services/ocdav/pkg/command/server.go | 6 ++-- services/ocm/pkg/command/server.go | 30 +++++++++-------- services/ocs/pkg/command/server.go | 6 ++-- services/policies/pkg/command/server.go | 6 ++-- services/postprocessing/pkg/command/server.go | 6 ++-- services/proxy/pkg/command/server.go | 11 +++---- services/search/pkg/command/server.go | 6 ++-- services/settings/pkg/command/server.go | 6 ++-- services/sharing/pkg/command/server.go | 28 +++++++++------- services/sse/pkg/command/server.go | 6 ++-- .../storage-publiclink/pkg/command/server.go | 30 +++++++++-------- services/storage-shares/pkg/command/server.go | 30 +++++++++-------- services/storage-system/pkg/command/server.go | 30 +++++++++-------- services/storage-users/pkg/command/server.go | 29 +++++++++-------- services/thumbnails/pkg/command/server.go | 6 ++-- services/userlog/pkg/command/server.go | 6 ++-- services/users/pkg/command/server.go | 29 +++++++++-------- services/web/pkg/command/server.go | 6 ++-- services/webdav/pkg/command/server.go | 6 ++-- services/webfinger/pkg/command/server.go | 6 ++-- 44 files changed, 370 insertions(+), 331 deletions(-) diff --git a/opencloud/pkg/runtime/service/service.go b/opencloud/pkg/runtime/service/service.go index ab161e8233..50d4fd9058 100644 --- a/opencloud/pkg/runtime/service/service.go +++ b/opencloud/pkg/runtime/service/service.go @@ -85,8 +85,6 @@ type Service struct { Log log.Logger serviceToken map[string][]suture.ServiceToken - context context.Context - cancel context.CancelFunc cfg *occfg.Config } @@ -108,16 +106,12 @@ func NewService(ctx context.Context, options ...Option) (*Service, error) { log.Level(opts.Config.Log.Level), ) - globalCtx, cancelGlobal := context.WithCancel(ctx) - s := &Service{ Services: make([]serviceFuncMap, len(_waitFuncs)), Additional: make(serviceFuncMap), Log: l, serviceToken: make(map[string][]suture.ServiceToken), - context: globalCtx, - cancel: cancelGlobal, cfg: opts.Config, } @@ -362,8 +356,11 @@ func Start(ctx context.Context, o ...Option) error { } // cancel the context when a signal is received. - notifyCtx, cancel := signal.NotifyContext(ctx, runner.StopSignals...) - defer cancel() + var cancel context.CancelFunc + if ctx == nil { + ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + defer cancel() + } // tolerance controls backoff cycles from the supervisor. tolerance := 5 @@ -416,12 +413,12 @@ func Start(ctx context.Context, o ...Option) error { // prepare the set of services to run s.generateRunSet(s.cfg) - // there are reasons not to do this, but we have race conditions ourselves. Until we resolve them, mind the following disclaimer: + // There are reasons not to do this, but we have race conditions ourselves. Until we resolve them, mind the following disclaimer: // Calling ServeBackground will CORRECTLY start the supervisor running in a new goroutine. It is risky to directly run // go supervisor.Serve() // because that will briefly create a race condition as it starts up, if you try to .Add() services immediately afterward. // https://pkg.go.dev/github.com/thejerf/suture/v4@v4.0.0#Supervisor - go s.Supervisor.ServeBackground(s.context) // TODO Why does Supervisor uses s.context? + go s.Supervisor.ServeBackground(ctx) for i, service := range s.Services { scheduleServiceTokens(s, service) @@ -442,7 +439,7 @@ func Start(ctx context.Context, o ...Option) error { }() // trapShutdownCtx will block on the context-done channel for interruptions. - trapShutdownCtx(s, srv, notifyCtx) + trapShutdownCtx(s, srv, ctx) return nil } @@ -516,8 +513,7 @@ func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) { wg.Add(1) go func() { defer wg.Done() - // TODO: To discuss the default timeout - ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), runner.DefaultInterruptDuration) defer cancel() if err := srv.Shutdown(ctx); err != nil { s.Log.Error().Err(err).Msg("could not shutdown tcp listener") @@ -530,13 +526,12 @@ func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) { for i := range s.serviceToken[sName] { wg.Add(1) go func() { - s.Log.Warn().Msgf("=== RemoveAndWait for %s", sName) + s.Log.Warn().Msgf("call supervisor RemoveAndWait for %s", sName) defer wg.Done() - // TODO: To discuss the default timeout - if err := s.Supervisor.RemoveAndWait(s.serviceToken[sName][i], 20*time.Second); err != nil && !errors.Is(err, suture.ErrSupervisorNotRunning) { + if err := s.Supervisor.RemoveAndWait(s.serviceToken[sName][i], runner.DefaultInterruptDuration); err != nil && !errors.Is(err, suture.ErrSupervisorNotRunning) { s.Log.Error().Err(err).Str("service", sName).Msgf("terminating with signal: %+v", s) } - s.Log.Warn().Msgf("=== Done RemoveAndWait for %s", sName) + s.Log.Warn().Msgf("done supervisor RemoveAndWait for %s", sName) }() } } @@ -548,8 +543,7 @@ func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) { }() select { - // TODO: To discuss the default timeout - case <-time.After(30 * time.Second): + case <-time.After(runner.DefaultGroupInterruptDuration): s.Log.Fatal().Msg("ocis graceful shutdown timeout reached, terminating") case <-done: s.Log.Info().Msg("all ocis services gracefully stopped") diff --git a/pkg/runner/factory.go b/pkg/runner/factory.go index 37767ddde4..3931c39c1d 100644 --- a/pkg/runner/factory.go +++ b/pkg/runner/factory.go @@ -5,7 +5,6 @@ import ( "errors" "net" "net/http" - "time" ogrpc "github.com/opencloud-eu/opencloud/pkg/service/grpc" ohttp "github.com/opencloud-eu/opencloud/pkg/service/http" @@ -102,9 +101,8 @@ func NewGolangHttpServerRunner(name string, server *http.Server, opts ...Option) }, func() { // Since Shutdown might take some time, don't block go func() { - // give 5 secs for the shutdown to finish - // TODO: To discuss the default timeout - shutdownCtx, cancel := context.WithTimeout(context.Background(), 20*time.Second) + // TODO: Provide the adjustable TimeoutDuration + shutdownCtx, cancel := context.WithTimeout(context.Background(), DefaultInterruptDuration) defer cancel() debugCh <- server.Shutdown(shutdownCtx) @@ -135,6 +133,14 @@ func NewGolangGrpcServerRunner(name string, server *grpc.Server, listener net.Li return r } +// NewRevaServiceRunner creates a new runner based on the provided reva RevaDrivenServer +// The runner will behave as described: +// * The task is to start a server and listen for connections. If the server +// can't start, the task will finish with that error. +// * The stopper will call the server's stop method and send the result to +// the task. +// * The stopper will run asynchronously because the stop method could take a +// while and we don't want to block func NewRevaServiceRunner(name string, server runtime.RevaDrivenServer, opts ...Option) *Runner { httpCh := make(chan error, 1) r := New(name, func() error { diff --git a/pkg/runner/option.go b/pkg/runner/option.go index 649deb14ed..ae7dd8aeff 100644 --- a/pkg/runner/option.go +++ b/pkg/runner/option.go @@ -7,11 +7,9 @@ import ( var ( // DefaultInterruptDuration is the default value for the `WithInterruptDuration` // for the "regular" runners. This global value can be adjusted if needed. - // TODO: To discuss the default timeout DefaultInterruptDuration = 20 * time.Second // DefaultGroupInterruptDuration is the default value for the `WithInterruptDuration` // for the group runners. This global value can be adjusted if needed. - // TODO: To discuss the default timeout DefaultGroupInterruptDuration = 25 * time.Second ) diff --git a/services/antivirus/pkg/command/server.go b/services/antivirus/pkg/command/server.go index 05f3186c0d..9d22a5de6c 100644 --- a/services/antivirus/pkg/command/server.go +++ b/services/antivirus/pkg/command/server.go @@ -28,11 +28,11 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context logger := log.NewLogger( log.Name(cfg.Service.Name), diff --git a/services/app-provider/pkg/command/server.go b/services/app-provider/pkg/command/server.go index 0790f3b42d..66d1a8fea9 100644 --- a/services/app-provider/pkg/command/server.go +++ b/services/app-provider/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/opencloud-eu/reva/v2/cmd/revad/runtime" "github.com/urfave/cli/v2" @@ -40,26 +37,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.AppProviderConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("app-provider_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/app-registry/pkg/command/server.go b/services/app-registry/pkg/command/server.go index aa6e2c91f7..5642063e9b 100644 --- a/services/app-registry/pkg/command/server.go +++ b/services/app-registry/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/pkg/runner" @@ -39,27 +36,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.AppRegistryConfigFromStruct(cfg, logger) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("app-registry_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/audit/pkg/command/server.go b/services/audit/pkg/command/server.go index 78f05df855..4dbced80ac 100644 --- a/services/audit/pkg/command/server.go +++ b/services/audit/pkg/command/server.go @@ -31,11 +31,11 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context logger := logging.Configure(cfg.Service.Name, cfg.Log) gr := runner.NewGroup() diff --git a/services/auth-app/pkg/command/server.go b/services/auth-app/pkg/command/server.go index 51390cd964..8ca8b6befd 100644 --- a/services/auth-app/pkg/command/server.go +++ b/services/auth-app/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/pkg/runner" @@ -47,26 +44,30 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.AuthAppConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - gr.Add(runner.NewRevaServiceRunner("auth-app_revad", revaSrv)) - + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/auth-basic/pkg/command/server.go b/services/auth-basic/pkg/command/server.go index aa86c85395..eba9374de7 100644 --- a/services/auth-basic/pkg/command/server.go +++ b/services/auth-basic/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/ldap" "github.com/opencloud-eu/opencloud/pkg/registry" @@ -40,11 +37,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() @@ -61,16 +58,22 @@ func Server(cfg *config.Config) *cli.Command { } { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.AuthBasicConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - gr.Add(runner.NewRevaServiceRunner("auth-basic_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/auth-bearer/pkg/command/server.go b/services/auth-bearer/pkg/command/server.go index 96d4028c6e..f0ed477831 100644 --- a/services/auth-bearer/pkg/command/server.go +++ b/services/auth-bearer/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/pkg/runner" @@ -39,25 +36,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.AuthBearerConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - gr.Add(runner.NewRevaServiceRunner("auth-bearer_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/auth-machine/pkg/command/server.go b/services/auth-machine/pkg/command/server.go index 0b3ce11d0a..6dd71e8877 100644 --- a/services/auth-machine/pkg/command/server.go +++ b/services/auth-machine/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/pkg/runner" @@ -39,25 +36,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.AuthMachineConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - gr.Add(runner.NewRevaServiceRunner("auth-machine_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/auth-service/pkg/command/server.go b/services/auth-service/pkg/command/server.go index 90f24d83e7..d097a4c6fa 100644 --- a/services/auth-service/pkg/command/server.go +++ b/services/auth-service/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/pkg/runner" @@ -39,25 +36,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") - reg := registry.GetRegistry() - rcfg := revaconfig.AuthMachineConfigFromStruct(cfg) - - revaSrv := runtime.RunDrivenServerWithOptions(rcfg, pidFile, + // run the appropriate reva servers based on the config + rCfg := revaconfig.AuthMachineConfigFromStruct(cfg) + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - gr.Add(runner.NewRevaServiceRunner("auth-service_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/clientlog/pkg/command/server.go b/services/clientlog/pkg/command/server.go index f9e1e8a7cf..fbf1ab461a 100644 --- a/services/clientlog/pkg/command/server.go +++ b/services/clientlog/pkg/command/server.go @@ -63,11 +63,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/collaboration/pkg/command/server.go b/services/collaboration/pkg/command/server.go index 2bb369956c..79efd6ae27 100644 --- a/services/collaboration/pkg/command/server.go +++ b/services/collaboration/pkg/command/server.go @@ -43,11 +43,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context // prepare components if err := helpers.RegisterOpenCloudService(ctx, cfg, logger); err != nil { diff --git a/services/eventhistory/pkg/command/server.go b/services/eventhistory/pkg/command/server.go index eaa85e2480..c6cf336fc9 100644 --- a/services/eventhistory/pkg/command/server.go +++ b/services/eventhistory/pkg/command/server.go @@ -48,11 +48,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context m := metrics.New() m.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/frontend/pkg/command/server.go b/services/frontend/pkg/command/server.go index ea0da1b7a7..0d04efb549 100644 --- a/services/frontend/pkg/command/server.go +++ b/services/frontend/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/opencloud-eu/reva/v2/cmd/revad/runtime" "github.com/urfave/cli/v2" @@ -40,11 +37,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() @@ -53,15 +50,22 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") - reg := registry.GetRegistry() - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + // run the appropriate reva servers based on the config + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - gr.Add(runner.NewRevaServiceRunner("frontend_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/gateway/pkg/command/server.go b/services/gateway/pkg/command/server.go index e131a12749..f07cba2dc8 100644 --- a/services/gateway/pkg/command/server.go +++ b/services/gateway/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/pkg/runner" @@ -39,26 +36,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.GatewayConfigFromStruct(cfg, logger) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("gateway_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/graph/pkg/command/server.go b/services/graph/pkg/command/server.go index 4eb5c5c1d3..77247a8a2c 100644 --- a/services/graph/pkg/command/server.go +++ b/services/graph/pkg/command/server.go @@ -35,11 +35,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/groups/pkg/command/server.go b/services/groups/pkg/command/server.go index 2282e786e8..b5ef09d2c5 100644 --- a/services/groups/pkg/command/server.go +++ b/services/groups/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/ldap" "github.com/opencloud-eu/opencloud/pkg/registry" @@ -52,26 +49,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.GroupsConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("groups_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/idm/pkg/command/server.go b/services/idm/pkg/command/server.go index 85546df7b2..e87affc734 100644 --- a/services/idm/pkg/command/server.go +++ b/services/idm/pkg/command/server.go @@ -38,11 +38,11 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context logger := logging.Configure(cfg.Service.Name, cfg.Log) diff --git a/services/idp/pkg/command/server.go b/services/idp/pkg/command/server.go index db12bcc0c6..fc47ee8936 100644 --- a/services/idp/pkg/command/server.go +++ b/services/idp/pkg/command/server.go @@ -60,11 +60,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context metrics := metrics.New() metrics.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/invitations/pkg/command/server.go b/services/invitations/pkg/command/server.go index 647637bd42..be1d589344 100644 --- a/services/invitations/pkg/command/server.go +++ b/services/invitations/pkg/command/server.go @@ -36,11 +36,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context metrics := metrics.New(metrics.Logger(logger)) metrics.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/nats/pkg/command/server.go b/services/nats/pkg/command/server.go index 56c0618d96..8ab7709755 100644 --- a/services/nats/pkg/command/server.go +++ b/services/nats/pkg/command/server.go @@ -31,11 +31,11 @@ func Server(cfg *config.Config) *cli.Command { logger := logging.Configure(cfg.Service.Name, cfg.Log) var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { diff --git a/services/notifications/pkg/command/server.go b/services/notifications/pkg/command/server.go index f49bfd4cc0..2a7e70edff 100644 --- a/services/notifications/pkg/command/server.go +++ b/services/notifications/pkg/command/server.go @@ -59,11 +59,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { diff --git a/services/ocdav/pkg/command/server.go b/services/ocdav/pkg/command/server.go index 9b37eaeb29..db3f76af6e 100644 --- a/services/ocdav/pkg/command/server.go +++ b/services/ocdav/pkg/command/server.go @@ -38,11 +38,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() diff --git a/services/ocm/pkg/command/server.go b/services/ocm/pkg/command/server.go index f0f955eea4..05f42e12b2 100644 --- a/services/ocm/pkg/command/server.go +++ b/services/ocm/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/pkg/runner" @@ -39,26 +36,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { + // run the appropriate reva servers based on the config rCfg := revaconfig.OCMConfigFromStruct(cfg, logger) - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("ocm_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/ocs/pkg/command/server.go b/services/ocs/pkg/command/server.go index a8df3fde12..01abae2ace 100644 --- a/services/ocs/pkg/command/server.go +++ b/services/ocs/pkg/command/server.go @@ -41,11 +41,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context metrics := metrics.New() metrics.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/policies/pkg/command/server.go b/services/policies/pkg/command/server.go index eaf49364be..0871ffa556 100644 --- a/services/policies/pkg/command/server.go +++ b/services/policies/pkg/command/server.go @@ -35,11 +35,11 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context logger := log.NewLogger( log.Name(cfg.Service.Name), diff --git a/services/postprocessing/pkg/command/server.go b/services/postprocessing/pkg/command/server.go index 9a8a72d6ef..af881d8fe2 100644 --- a/services/postprocessing/pkg/command/server.go +++ b/services/postprocessing/pkg/command/server.go @@ -37,11 +37,11 @@ func Server(cfg *config.Config) *cli.Command { logger := logging.Configure(cfg.Service.Name, cfg.Log) var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context traceProvider, err := tracing.GetServiceTraceProvider(cfg.Tracing, cfg.Service.Name) if err != nil { diff --git a/services/proxy/pkg/command/server.go b/services/proxy/pkg/command/server.go index 31fa3a6699..e6f9e72319 100644 --- a/services/proxy/pkg/command/server.go +++ b/services/proxy/pkg/command/server.go @@ -109,9 +109,8 @@ func Server(cfg *config.Config) *cli.Command { ) var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } @@ -192,7 +191,7 @@ func Server(cfg *config.Config) *cli.Command { server, err := proxyHTTP.Server( proxyHTTP.Handler(lh.Handler()), proxyHTTP.Logger(logger), - proxyHTTP.Context(ctx), + proxyHTTP.Context(cfg.Context), proxyHTTP.Config(cfg), proxyHTTP.Metrics(metrics.New()), proxyHTTP.Middlewares(middlewares), @@ -212,7 +211,7 @@ func Server(cfg *config.Config) *cli.Command { { debugServer, err := debug.Server( debug.Logger(logger), - debug.Context(ctx), + debug.Context(cfg.Context), debug.Config(cfg), ) if err != nil { @@ -223,7 +222,7 @@ func Server(cfg *config.Config) *cli.Command { gr.Add(runner.NewGolangHttpServerRunner("proxy_debug", debugServer)) } - grResults := gr.Run(ctx) + grResults := gr.Run(cfg.Context) // return the first non-nil error found in the results for _, grResult := range grResults { diff --git a/services/search/pkg/command/server.go b/services/search/pkg/command/server.go index 261b65b635..cef5f3c2fe 100644 --- a/services/search/pkg/command/server.go +++ b/services/search/pkg/command/server.go @@ -43,11 +43,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/settings/pkg/command/server.go b/services/settings/pkg/command/server.go index 67bd695378..14634f2b1e 100644 --- a/services/settings/pkg/command/server.go +++ b/services/settings/pkg/command/server.go @@ -44,11 +44,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/sharing/pkg/command/server.go b/services/sharing/pkg/command/server.go index 6b29f4ace5..edc28a01be 100644 --- a/services/sharing/pkg/command/server.go +++ b/services/sharing/pkg/command/server.go @@ -5,10 +5,8 @@ import ( "fmt" "os" "os/signal" - "path" "path/filepath" - "github.com/gofrs/uuid" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/pkg/runner" @@ -52,29 +50,35 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") rCfg, err := revaconfig.SharingConfigFromStruct(cfg, logger) if err != nil { return err } - reg := registry.GetRegistry() - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + // run the appropriate reva servers based on the config + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("sharing_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/sse/pkg/command/server.go b/services/sse/pkg/command/server.go index 4579567d3a..1b40de0af8 100644 --- a/services/sse/pkg/command/server.go +++ b/services/sse/pkg/command/server.go @@ -36,11 +36,11 @@ func Server(cfg *config.Config) *cli.Command { }, Action: func(c *cli.Context) error { var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context logger := log.NewLogger( log.Name(cfg.Service.Name), diff --git a/services/storage-publiclink/pkg/command/server.go b/services/storage-publiclink/pkg/command/server.go index 50b937dbf0..97ff68a690 100644 --- a/services/storage-publiclink/pkg/command/server.go +++ b/services/storage-publiclink/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/pkg/runner" @@ -39,26 +36,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.StoragePublicLinkConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("storage-publiclink_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/storage-shares/pkg/command/server.go b/services/storage-shares/pkg/command/server.go index 1abce31c41..7347252e57 100644 --- a/services/storage-shares/pkg/command/server.go +++ b/services/storage-shares/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/pkg/runner" @@ -39,26 +36,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.StorageSharesConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("storage-shares_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/storage-system/pkg/command/server.go b/services/storage-system/pkg/command/server.go index f8882b841c..c96a376aa3 100644 --- a/services/storage-system/pkg/command/server.go +++ b/services/storage-system/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/opencloud-eu/reva/v2/cmd/revad/runtime" "github.com/urfave/cli/v2" @@ -40,26 +37,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.StorageSystemFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - - gr.Add(runner.NewRevaServiceRunner("storage-system_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/storage-users/pkg/command/server.go b/services/storage-users/pkg/command/server.go index 338e0f6d76..c029c04b70 100644 --- a/services/storage-users/pkg/command/server.go +++ b/services/storage-users/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/registry" "github.com/opencloud-eu/opencloud/pkg/runner" @@ -41,25 +38,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.StorageUsersConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - gr.Add(runner.NewRevaServiceRunner("storage-users_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/thumbnails/pkg/command/server.go b/services/thumbnails/pkg/command/server.go index cf1410bd81..d9112d666c 100644 --- a/services/thumbnails/pkg/command/server.go +++ b/services/thumbnails/pkg/command/server.go @@ -42,11 +42,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context m := metrics.New() m.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/userlog/pkg/command/server.go b/services/userlog/pkg/command/server.go index d99c6b3125..ff37ac2283 100644 --- a/services/userlog/pkg/command/server.go +++ b/services/userlog/pkg/command/server.go @@ -71,11 +71,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context mtrcs := metrics.New() mtrcs.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/users/pkg/command/server.go b/services/users/pkg/command/server.go index e215b5e385..7c35c1f5b3 100644 --- a/services/users/pkg/command/server.go +++ b/services/users/pkg/command/server.go @@ -3,11 +3,8 @@ package command import ( "context" "fmt" - "os" "os/signal" - "path" - "github.com/gofrs/uuid" "github.com/opencloud-eu/opencloud/pkg/config/configlog" "github.com/opencloud-eu/opencloud/pkg/ldap" "github.com/opencloud-eu/opencloud/pkg/registry" @@ -52,25 +49,31 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context gr := runner.NewGroup() { - pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") + // run the appropriate reva servers based on the config rCfg := revaconfig.UsersConfigFromStruct(cfg) - reg := registry.GetRegistry() - - revaSrv := runtime.RunDrivenServerWithOptions(rCfg, pidFile, + if rServer := runtime.NewDrivenHTTPServerWithOptions(rCfg, runtime.WithLogger(&logger.Logger), - runtime.WithRegistry(reg), + runtime.WithRegistry(registry.GetRegistry()), runtime.WithTraceProvider(traceProvider), - ) - gr.Add(runner.NewRevaServiceRunner("users_revad", revaSrv)) + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rhttp", rServer)) + } + if rServer := runtime.NewDrivenGRPCServerWithOptions(rCfg, + runtime.WithLogger(&logger.Logger), + runtime.WithRegistry(registry.GetRegistry()), + runtime.WithTraceProvider(traceProvider), + ); rServer != nil { + gr.Add(runner.NewRevaServiceRunner(cfg.Service.Name+".rgrpc", rServer)) + } } { diff --git a/services/web/pkg/command/server.go b/services/web/pkg/command/server.go index 9bffe86bdc..9c7f266199 100644 --- a/services/web/pkg/command/server.go +++ b/services/web/pkg/command/server.go @@ -49,11 +49,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context m := metrics.New() diff --git a/services/webdav/pkg/command/server.go b/services/webdav/pkg/command/server.go index 48f0e0795a..fd304398fd 100644 --- a/services/webdav/pkg/command/server.go +++ b/services/webdav/pkg/command/server.go @@ -43,11 +43,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context metrics := metrics.New() metrics.BuildInfo.WithLabelValues(version.GetString()).Set(1) diff --git a/services/webfinger/pkg/command/server.go b/services/webfinger/pkg/command/server.go index 1c58a4ee3c..e5d17e6fc6 100644 --- a/services/webfinger/pkg/command/server.go +++ b/services/webfinger/pkg/command/server.go @@ -37,11 +37,11 @@ func Server(cfg *config.Config) *cli.Command { } var cancel context.CancelFunc - ctx := cfg.Context - if ctx == nil { - ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) + if cfg.Context == nil { + cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...) defer cancel() } + ctx := cfg.Context m := metrics.New(metrics.Logger(logger)) m.BuildInfo.WithLabelValues(version.GetString()).Set(1) From c597dfb917c1bfe3e5a2c60a8f12e8eae1d95ec4 Mon Sep 17 00:00:00 2001 From: Roman Perekhod Date: Tue, 27 May 2025 13:02:34 +0200 Subject: [PATCH 05/11] set default timeouts and clean up --- opencloud/pkg/runtime/service/service.go | 11 ++++++++--- pkg/runner/factory.go | 2 +- pkg/runner/grouprunner.go | 2 +- pkg/runner/runner.go | 2 +- services/antivirus/pkg/command/server.go | 6 +++--- services/app-provider/pkg/command/server.go | 2 +- services/app-registry/pkg/command/server.go | 2 +- services/audit/pkg/command/server.go | 4 ++-- services/auth-basic/pkg/command/server.go | 2 +- services/auth-bearer/pkg/command/server.go | 2 +- services/auth-machine/pkg/command/server.go | 2 +- services/auth-service/pkg/command/server.go | 2 +- services/clientlog/pkg/command/server.go | 4 ++-- services/collaboration/pkg/command/server.go | 4 ++-- services/eventhistory/pkg/command/server.go | 4 ++-- services/frontend/pkg/command/server.go | 4 ++-- services/gateway/pkg/command/server.go | 2 +- services/graph/pkg/command/server.go | 4 ++-- services/groups/pkg/command/server.go | 2 +- services/idm/pkg/command/server.go | 4 ++-- services/idp/pkg/command/server.go | 4 ++-- services/invitations/pkg/command/server.go | 4 ++-- services/nats/pkg/command/server.go | 4 ++-- services/notifications/pkg/command/server.go | 4 ++-- services/ocdav/pkg/command/server.go | 4 ++-- services/ocm/pkg/command/server.go | 2 +- services/ocs/pkg/command/server.go | 4 ++-- services/policies/pkg/command/server.go | 6 +++--- services/postprocessing/pkg/command/server.go | 2 +- services/proxy/pkg/command/server.go | 4 ++-- services/search/pkg/command/server.go | 4 ++-- services/settings/pkg/command/server.go | 6 +++--- services/sharing/pkg/command/server.go | 2 +- services/sse/pkg/command/server.go | 4 ++-- services/thumbnails/pkg/command/server.go | 6 +++--- services/userlog/pkg/command/server.go | 4 ++-- services/users/pkg/command/server.go | 2 +- services/web/pkg/command/server.go | 4 ++-- services/webdav/pkg/command/server.go | 4 ++-- services/webfinger/pkg/command/server.go | 4 ++-- 40 files changed, 75 insertions(+), 70 deletions(-) diff --git a/opencloud/pkg/runtime/service/service.go b/opencloud/pkg/runtime/service/service.go index 50d4fd9058..80b05c266d 100644 --- a/opencloud/pkg/runtime/service/service.go +++ b/opencloud/pkg/runtime/service/service.go @@ -73,6 +73,11 @@ var ( // wait funcs run after the service group has been started. _waitFuncs = []func(*occfg.Config) error{pingNats, pingGateway, nil, wait(time.Second), nil} + + // Use the runner.DefaultInterruptDuration as defaults for the individual service shutdown timeouts. + _defaultShutdownTimeoutDuration = runner.DefaultInterruptDuration + // Use the runner.DefaultGroupInterruptDuration as defaults for the server interruption timeout. + _defaultInterruptTimeoutDuration = runner.DefaultGroupInterruptDuration ) type serviceFuncMap map[string]func(*occfg.Config) suture.Service @@ -513,7 +518,7 @@ func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) { wg.Add(1) go func() { defer wg.Done() - ctx, cancel := context.WithTimeout(context.Background(), runner.DefaultInterruptDuration) + ctx, cancel := context.WithTimeout(context.Background(), _defaultShutdownTimeoutDuration) defer cancel() if err := srv.Shutdown(ctx); err != nil { s.Log.Error().Err(err).Msg("could not shutdown tcp listener") @@ -528,7 +533,7 @@ func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) { go func() { s.Log.Warn().Msgf("call supervisor RemoveAndWait for %s", sName) defer wg.Done() - if err := s.Supervisor.RemoveAndWait(s.serviceToken[sName][i], runner.DefaultInterruptDuration); err != nil && !errors.Is(err, suture.ErrSupervisorNotRunning) { + if err := s.Supervisor.RemoveAndWait(s.serviceToken[sName][i], _defaultShutdownTimeoutDuration); err != nil && !errors.Is(err, suture.ErrSupervisorNotRunning) { s.Log.Error().Err(err).Str("service", sName).Msgf("terminating with signal: %+v", s) } s.Log.Warn().Msgf("done supervisor RemoveAndWait for %s", sName) @@ -543,7 +548,7 @@ func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) { }() select { - case <-time.After(runner.DefaultGroupInterruptDuration): + case <-time.After(_defaultInterruptTimeoutDuration): s.Log.Fatal().Msg("ocis graceful shutdown timeout reached, terminating") case <-done: s.Log.Info().Msg("all ocis services gracefully stopped") diff --git a/pkg/runner/factory.go b/pkg/runner/factory.go index 3931c39c1d..9ad599a876 100644 --- a/pkg/runner/factory.go +++ b/pkg/runner/factory.go @@ -101,7 +101,7 @@ func NewGolangHttpServerRunner(name string, server *http.Server, opts ...Option) }, func() { // Since Shutdown might take some time, don't block go func() { - // TODO: Provide the adjustable TimeoutDuration + // Use the DefaultInterruptDuration or InterruptDuration as the shutdown timeout. shutdownCtx, cancel := context.WithTimeout(context.Background(), DefaultInterruptDuration) defer cancel() diff --git a/pkg/runner/grouprunner.go b/pkg/runner/grouprunner.go index e44f72d4c7..4c4574b931 100644 --- a/pkg/runner/grouprunner.go +++ b/pkg/runner/grouprunner.go @@ -21,7 +21,7 @@ import ( // // The interrupt duration for the group can be set through the // `WithInterruptDuration` option. If the option isn't supplied, the default -// value (15 secs) will be used. +// value `DefaultGroupInterruptDuration` will be used. // // It's recommended that the timeouts are handled by each runner individually, // meaning that each runner's timeout should be less than the group runner's diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 6733a745f1..7e169d8e39 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -32,7 +32,7 @@ type Runner struct { // // The interrupt duration, which can be set through the `WithInterruptDuration` // option, will be used to ensure the runner doesn't block forever. If the -// option isn't supplied, the default value (10 secs) will be used. +// option isn't supplied, the default value `DefaultInterruptDuration` will be used. // The interrupt duration will be used to start a timeout when the // runner gets interrupted (either the context of the `Run` method is done // or this runner's `Interrupt` method is called). If the timeout is reached, diff --git a/services/antivirus/pkg/command/server.go b/services/antivirus/pkg/command/server.go index 9d22a5de6c..e6f48ee4d6 100644 --- a/services/antivirus/pkg/command/server.go +++ b/services/antivirus/pkg/command/server.go @@ -47,14 +47,14 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr := runner.NewGroup() + gr := runner.NewGroup(runner.Option()) { svc, err := service.NewAntivirus(cfg, logger, traceProvider) if err != nil { return cli.Exit(err.Error(), 1) } - gr.Add(runner.New("antivirus_svc", func() error { + gr.Add(runner.New(cfg.Service.Name+".svc", func() error { return svc.Run() }, func() { svc.Close() @@ -72,7 +72,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("antivirus_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grResults := gr.Run(ctx) diff --git a/services/app-provider/pkg/command/server.go b/services/app-provider/pkg/command/server.go index 66d1a8fea9..88e8ef0732 100644 --- a/services/app-provider/pkg/command/server.go +++ b/services/app-provider/pkg/command/server.go @@ -75,7 +75,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("app-provider_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) diff --git a/services/app-registry/pkg/command/server.go b/services/app-registry/pkg/command/server.go index 5642063e9b..bd9540acfb 100644 --- a/services/app-registry/pkg/command/server.go +++ b/services/app-registry/pkg/command/server.go @@ -74,7 +74,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("app-registry_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) diff --git a/services/audit/pkg/command/server.go b/services/audit/pkg/command/server.go index 4dbced80ac..1a8bce1a53 100644 --- a/services/audit/pkg/command/server.go +++ b/services/audit/pkg/command/server.go @@ -55,7 +55,7 @@ func Server(cfg *config.Config) *cli.Command { svcCtx, svcCancel := context.WithCancel(ctx) defer svcCancel() - gr.Add(runner.New("audit_svc", func() error { + gr.Add(runner.New(cfg.Service.Name+".svc", func() error { svc.AuditLoggerFromConfig(svcCtx, cfg.Auditlog, evts, logger) return nil }, func() { @@ -73,7 +73,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("audit_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grResults := gr.Run(ctx) diff --git a/services/auth-basic/pkg/command/server.go b/services/auth-basic/pkg/command/server.go index eba9374de7..0d6576dd79 100644 --- a/services/auth-basic/pkg/command/server.go +++ b/services/auth-basic/pkg/command/server.go @@ -87,7 +87,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("auth-basic_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) diff --git a/services/auth-bearer/pkg/command/server.go b/services/auth-bearer/pkg/command/server.go index f0ed477831..d78b93bbbc 100644 --- a/services/auth-bearer/pkg/command/server.go +++ b/services/auth-bearer/pkg/command/server.go @@ -74,7 +74,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("auth-bearer_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) diff --git a/services/auth-machine/pkg/command/server.go b/services/auth-machine/pkg/command/server.go index 6dd71e8877..d3d78682a7 100644 --- a/services/auth-machine/pkg/command/server.go +++ b/services/auth-machine/pkg/command/server.go @@ -74,7 +74,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("auth-machine_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) diff --git a/services/auth-service/pkg/command/server.go b/services/auth-service/pkg/command/server.go index d097a4c6fa..03b4181f65 100644 --- a/services/auth-service/pkg/command/server.go +++ b/services/auth-service/pkg/command/server.go @@ -74,7 +74,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("auth-service_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) diff --git a/services/clientlog/pkg/command/server.go b/services/clientlog/pkg/command/server.go index fbf1ab461a..a82fadd6ae 100644 --- a/services/clientlog/pkg/command/server.go +++ b/services/clientlog/pkg/command/server.go @@ -109,7 +109,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.New("clientlog_svc", func() error { + gr.Add(runner.New(cfg.Service.Name+".svc", func() error { return svc.Run() }, func() { svc.Close() @@ -127,7 +127,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("clientlog_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grResults := gr.Run(ctx) diff --git a/services/collaboration/pkg/command/server.go b/services/collaboration/pkg/command/server.go index 79efd6ae27..f5ebcce29b 100644 --- a/services/collaboration/pkg/command/server.go +++ b/services/collaboration/pkg/command/server.go @@ -113,7 +113,7 @@ func Server(cfg *config.Config) *cli.Command { if err != nil { return err } - gr.Add(runner.NewGolangGrpcServerRunner("collaboration_grpc", grpcServer, l)) + gr.Add(runner.NewGolangGrpcServerRunner(cfg.Service.Name+".grpc", grpcServer, l)) // start debug server debugServer, err := debug.Server( @@ -125,7 +125,7 @@ func Server(cfg *config.Config) *cli.Command { logger.Error().Err(err).Str("transport", "debug").Msg("Failed to initialize server") return err } - gr.Add(runner.NewGolangHttpServerRunner("collaboration_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) // start HTTP server httpServer, err := http.Server( diff --git a/services/eventhistory/pkg/command/server.go b/services/eventhistory/pkg/command/server.go index c6cf336fc9..245b77bb07 100644 --- a/services/eventhistory/pkg/command/server.go +++ b/services/eventhistory/pkg/command/server.go @@ -87,7 +87,7 @@ func Server(cfg *config.Config) *cli.Command { grpc.TraceProvider(traceProvider), ) - gr.Add(runner.NewGoMicroGrpcServerRunner("eventhistory_grpc", service)) + gr.Add(runner.NewGoMicroGrpcServerRunner(cfg.Service.Name+".grpc", service)) { debugServer, err := debug.Server( @@ -100,7 +100,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("eventhistory_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grResults := gr.Run(ctx) diff --git a/services/frontend/pkg/command/server.go b/services/frontend/pkg/command/server.go index 0d04efb549..909475f369 100644 --- a/services/frontend/pkg/command/server.go +++ b/services/frontend/pkg/command/server.go @@ -79,7 +79,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("frontend_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } httpSvc := registry.BuildHTTPService(cfg.HTTP.Namespace+"."+cfg.Service.Name, cfg.HTTP.Addr, version.GetString()) @@ -88,7 +88,7 @@ func Server(cfg *config.Config) *cli.Command { } // add event handler - gr.Add(runner.New("frontend_event", + gr.Add(runner.New(cfg.Service.Name+".event", func() error { return ListenForEvents(ctx, cfg, logger) }, func() { diff --git a/services/gateway/pkg/command/server.go b/services/gateway/pkg/command/server.go index f07cba2dc8..b0dca37d1a 100644 --- a/services/gateway/pkg/command/server.go +++ b/services/gateway/pkg/command/server.go @@ -74,7 +74,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("gateway_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) diff --git a/services/graph/pkg/command/server.go b/services/graph/pkg/command/server.go index 77247a8a2c..7a10c42cfb 100644 --- a/services/graph/pkg/command/server.go +++ b/services/graph/pkg/command/server.go @@ -58,7 +58,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGoMicroHttpServerRunner("graph_http", server)) + gr.Add(runner.NewGoMicroHttpServerRunner(cfg.Service.Name+".http", server)) } { @@ -72,7 +72,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("graph_debug", server)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", server)) } grResults := gr.Run(ctx) diff --git a/services/groups/pkg/command/server.go b/services/groups/pkg/command/server.go index b5ef09d2c5..270400fc17 100644 --- a/services/groups/pkg/command/server.go +++ b/services/groups/pkg/command/server.go @@ -87,7 +87,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("groups_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) diff --git a/services/idm/pkg/command/server.go b/services/idm/pkg/command/server.go index e87affc734..3d860381a6 100644 --- a/services/idm/pkg/command/server.go +++ b/services/idm/pkg/command/server.go @@ -83,7 +83,7 @@ func Server(cfg *config.Config) *cli.Command { svcCtx, svcCancel := context.WithCancel(ctx) defer svcCancel() - gr.Add(runner.New("idm_svc", func() error { + gr.Add(runner.New(cfg.Service.Name+".svc", func() error { return svc.Serve(svcCtx) }, func() { svcCancel() @@ -101,7 +101,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("idm_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grResults := gr.Run(ctx) diff --git a/services/idp/pkg/command/server.go b/services/idp/pkg/command/server.go index fc47ee8936..5240e488da 100644 --- a/services/idp/pkg/command/server.go +++ b/services/idp/pkg/command/server.go @@ -87,7 +87,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGoMicroHttpServerRunner("idp_http", server)) + gr.Add(runner.NewGoMicroHttpServerRunner(cfg.Service.Name+".http", server)) } { @@ -101,7 +101,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("idp_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grResults := gr.Run(ctx) diff --git a/services/invitations/pkg/command/server.go b/services/invitations/pkg/command/server.go index be1d589344..066080ebb8 100644 --- a/services/invitations/pkg/command/server.go +++ b/services/invitations/pkg/command/server.go @@ -76,7 +76,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGoMicroHttpServerRunner("invitations_http", server)) + gr.Add(runner.NewGoMicroHttpServerRunner(cfg.Service.Name+".http", server)) } { @@ -90,7 +90,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("invitations_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grResults := gr.Run(ctx) diff --git a/services/nats/pkg/command/server.go b/services/nats/pkg/command/server.go index 8ab7709755..b47a93e5b7 100644 --- a/services/nats/pkg/command/server.go +++ b/services/nats/pkg/command/server.go @@ -49,7 +49,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("nats_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } var tlsConf *tls.Config @@ -88,7 +88,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.New("nats_svc", func() error { + gr.Add(runner.New(cfg.Service.Name+".svc", func() error { return natsServer.ListenAndServe() }, func() { natsServer.Shutdown() diff --git a/services/notifications/pkg/command/server.go b/services/notifications/pkg/command/server.go index 2a7e70edff..6297a8fac0 100644 --- a/services/notifications/pkg/command/server.go +++ b/services/notifications/pkg/command/server.go @@ -77,7 +77,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("notifications_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } // evs defines a list of events to subscribe to @@ -140,7 +140,7 @@ func Server(cfg *config.Config) *cli.Command { cfg.Notifications.EmailTemplatePath, cfg.Notifications.DefaultLanguage, cfg.WebUIURL, cfg.Notifications.TranslationPath, cfg.Notifications.SMTP.Sender, notificationStore, historyClient, registeredEvents) - gr.Add(runner.New("notifications_svc", func() error { + gr.Add(runner.New(cfg.Service.Name+".svc", func() error { return svc.Run() }, func() { svc.Close() diff --git a/services/ocdav/pkg/command/server.go b/services/ocdav/pkg/command/server.go index db3f76af6e..368b21f433 100644 --- a/services/ocdav/pkg/command/server.go +++ b/services/ocdav/pkg/command/server.go @@ -106,7 +106,7 @@ func Server(cfg *config.Config) *cli.Command { // creating a runner for a go-micro service is a bit complex, so we'll // wrap the go-micro service with an ocis service the same way as // ocis-pkg/service/http is doing in order to reuse the factory. - gr.Add(runner.NewGoMicroHttpServerRunner("ocdav_http", ohttp.Service{Service: s})) + gr.Add(runner.NewGoMicroHttpServerRunner(cfg.Service.Name+".http", ohttp.Service{Service: s})) debugServer, err := debug.Server( debug.Logger(logger), @@ -119,7 +119,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("ocdav_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) grResults := gr.Run(ctx) diff --git a/services/ocm/pkg/command/server.go b/services/ocm/pkg/command/server.go index 05f42e12b2..6b2cd8406d 100644 --- a/services/ocm/pkg/command/server.go +++ b/services/ocm/pkg/command/server.go @@ -74,7 +74,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("ocm_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) diff --git a/services/ocs/pkg/command/server.go b/services/ocs/pkg/command/server.go index 01abae2ace..c0df575082 100644 --- a/services/ocs/pkg/command/server.go +++ b/services/ocs/pkg/command/server.go @@ -69,7 +69,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGoMicroHttpServerRunner("ocs_http", server)) + gr.Add(runner.NewGoMicroHttpServerRunner(cfg.Service.Name+".http", server)) } { @@ -84,7 +84,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("ocs_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grResults := gr.Run(ctx) diff --git a/services/policies/pkg/command/server.go b/services/policies/pkg/command/server.go index 0871ffa556..de1e8fec1c 100644 --- a/services/policies/pkg/command/server.go +++ b/services/policies/pkg/command/server.go @@ -102,7 +102,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGoMicroGrpcServerRunner("policies_grpc", svc)) + gr.Add(runner.NewGoMicroGrpcServerRunner(cfg.Service.Name+".grpc", svc)) } { @@ -118,7 +118,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.New("policies_svc", func() error { + gr.Add(runner.New(cfg.Service.Name+".svc", func() error { return eventSvc.Run() }, func() { eventSvc.Close() @@ -136,7 +136,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("policies_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grResults := gr.Run(ctx) diff --git a/services/postprocessing/pkg/command/server.go b/services/postprocessing/pkg/command/server.go index af881d8fe2..b48e022fb9 100644 --- a/services/postprocessing/pkg/command/server.go +++ b/services/postprocessing/pkg/command/server.go @@ -64,7 +64,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.New("postprocessing_svc", func() error { + gr.Add(runner.New(cfg.Service.Name+".svc", func() error { return svc.Run() }, func() { svc.Close() diff --git a/services/proxy/pkg/command/server.go b/services/proxy/pkg/command/server.go index e6f9e72319..c129fe0278 100644 --- a/services/proxy/pkg/command/server.go +++ b/services/proxy/pkg/command/server.go @@ -205,7 +205,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGoMicroHttpServerRunner("proxy_http", server)) + gr.Add(runner.NewGoMicroHttpServerRunner(cfg.Service.Name+".http", server)) } { @@ -219,7 +219,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("proxy_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grResults := gr.Run(cfg.Context) diff --git a/services/search/pkg/command/server.go b/services/search/pkg/command/server.go index cef5f3c2fe..490e2d6729 100644 --- a/services/search/pkg/command/server.go +++ b/services/search/pkg/command/server.go @@ -69,7 +69,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGoMicroGrpcServerRunner("search_grpc", grpcServer)) + gr.Add(runner.NewGoMicroGrpcServerRunner(cfg.Service.Name+".grpc", grpcServer)) debugServer, err := debug.Server( debug.Logger(logger), @@ -81,7 +81,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("search_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) grResults := gr.Run(ctx) diff --git a/services/settings/pkg/command/server.go b/services/settings/pkg/command/server.go index 14634f2b1e..b44dec3894 100644 --- a/services/settings/pkg/command/server.go +++ b/services/settings/pkg/command/server.go @@ -73,7 +73,7 @@ func Server(cfg *config.Config) *cli.Command { Msg("Error initializing http service") return fmt.Errorf("could not initialize http service: %w", err) } - gr.Add(runner.NewGoMicroHttpServerRunner("settings_http", httpServer)) + gr.Add(runner.NewGoMicroHttpServerRunner(cfg.Service.Name+".http", httpServer)) // prepare a gRPC server and add it to the group run. grpcServer := grpc.Server( @@ -85,7 +85,7 @@ func Server(cfg *config.Config) *cli.Command { grpc.ServiceHandler(handle), grpc.TraceProvider(traceProvider), ) - gr.Add(runner.NewGoMicroGrpcServerRunner("settings_grpc", grpcServer)) + gr.Add(runner.NewGoMicroGrpcServerRunner(cfg.Service.Name+".grpc", grpcServer)) // prepare a debug server and add it to the group run. debugServer, err := debug.Server( @@ -98,7 +98,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("settings_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) grResults := gr.Run(ctx) diff --git a/services/sharing/pkg/command/server.go b/services/sharing/pkg/command/server.go index edc28a01be..9f7394d606 100644 --- a/services/sharing/pkg/command/server.go +++ b/services/sharing/pkg/command/server.go @@ -92,7 +92,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("sharing_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, cfg.GRPC.Protocol, cfg.GRPC.Addr, version.GetString()) diff --git a/services/sse/pkg/command/server.go b/services/sse/pkg/command/server.go index 1b40de0af8..e916204b46 100644 --- a/services/sse/pkg/command/server.go +++ b/services/sse/pkg/command/server.go @@ -75,7 +75,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGoMicroHttpServerRunner("sse_http", server)) + gr.Add(runner.NewGoMicroHttpServerRunner(cfg.Service.Name+".http", server)) } { @@ -89,7 +89,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("sse_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grResults := gr.Run(ctx) diff --git a/services/thumbnails/pkg/command/server.go b/services/thumbnails/pkg/command/server.go index d9112d666c..491428a243 100644 --- a/services/thumbnails/pkg/command/server.go +++ b/services/thumbnails/pkg/command/server.go @@ -64,7 +64,7 @@ func Server(cfg *config.Config) *cli.Command { grpc.TraceProvider(traceProvider), grpc.MaxConcurrentRequests(cfg.GRPC.MaxConcurrentRequests), ) - gr.Add(runner.NewGoMicroGrpcServerRunner("thumbnails_grpc", service)) + gr.Add(runner.NewGoMicroGrpcServerRunner(cfg.Service.Name+".grpc", service)) server, err := debug.Server( debug.Logger(logger), @@ -75,7 +75,7 @@ func Server(cfg *config.Config) *cli.Command { logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server") return err } - gr.Add(runner.NewGolangHttpServerRunner("thumbnails_debug", server)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", server)) httpServer, err := http.Server( http.Logger(logger), @@ -93,7 +93,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGoMicroHttpServerRunner("thumbnails_http", httpServer)) + gr.Add(runner.NewGoMicroHttpServerRunner(cfg.Service.Name+".http", httpServer)) grResults := gr.Run(ctx) diff --git a/services/userlog/pkg/command/server.go b/services/userlog/pkg/command/server.go index ff37ac2283..056540ee3e 100644 --- a/services/userlog/pkg/command/server.go +++ b/services/userlog/pkg/command/server.go @@ -136,7 +136,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGoMicroHttpServerRunner("userlog_http", server)) + gr.Add(runner.NewGoMicroHttpServerRunner(cfg.Service.Name+".http", server)) } { @@ -150,7 +150,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("userlog_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grResults := gr.Run(ctx) diff --git a/services/users/pkg/command/server.go b/services/users/pkg/command/server.go index 7c35c1f5b3..939b27c9db 100644 --- a/services/users/pkg/command/server.go +++ b/services/users/pkg/command/server.go @@ -87,7 +87,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("users_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } // FIXME we should defer registering the service until we are sure that reva is running diff --git a/services/web/pkg/command/server.go b/services/web/pkg/command/server.go index 9c7f266199..6b0c4a6244 100644 --- a/services/web/pkg/command/server.go +++ b/services/web/pkg/command/server.go @@ -76,7 +76,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGoMicroHttpServerRunner("web_http", server)) + gr.Add(runner.NewGoMicroHttpServerRunner(cfg.Service.Name+".http", server)) } { @@ -90,7 +90,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("web_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grResults := gr.Run(ctx) diff --git a/services/webdav/pkg/command/server.go b/services/webdav/pkg/command/server.go index fd304398fd..2ed4233b54 100644 --- a/services/webdav/pkg/command/server.go +++ b/services/webdav/pkg/command/server.go @@ -71,7 +71,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGoMicroHttpServerRunner("webdav_http", server)) + gr.Add(runner.NewGoMicroHttpServerRunner(cfg.Service.Name+".http", server)) } { @@ -86,7 +86,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("webdav_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grResults := gr.Run(ctx) diff --git a/services/webfinger/pkg/command/server.go b/services/webfinger/pkg/command/server.go index e5d17e6fc6..5a9504e79e 100644 --- a/services/webfinger/pkg/command/server.go +++ b/services/webfinger/pkg/command/server.go @@ -84,7 +84,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGoMicroHttpServerRunner("webfinger_http", server)) + gr.Add(runner.NewGoMicroHttpServerRunner(cfg.Service.Name+".http", server)) } { @@ -99,7 +99,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(runner.NewGolangHttpServerRunner("webfinger_debug", debugServer)) + gr.Add(runner.NewGolangHttpServerRunner(cfg.Service.Name+".debug", debugServer)) } grResults := gr.Run(ctx) From fbbcf3d83315120b0ceadcf4fa88935895e77c10 Mon Sep 17 00:00:00 2001 From: Roman Perekhod Date: Tue, 27 May 2025 18:36:30 +0200 Subject: [PATCH 06/11] remove recover --- opencloud/pkg/runtime/service/service.go | 66 ++++++++++-------------- services/antivirus/pkg/command/server.go | 2 +- 2 files changed, 27 insertions(+), 41 deletions(-) diff --git a/opencloud/pkg/runtime/service/service.go b/opencloud/pkg/runtime/service/service.go index 80b05c266d..7683c0262f 100644 --- a/opencloud/pkg/runtime/service/service.go +++ b/opencloud/pkg/runtime/service/service.go @@ -392,28 +392,8 @@ func Start(ctx context.Context, o ...Option) error { } } - if err = rpc.Register(s); err != nil { - if s != nil { - s.Log.Fatal().Err(err).Msg("could not register rpc service") - } - } - rpc.HandleHTTP() - - l, err := net.Listen("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)) - if err != nil { - s.Log.Fatal().Err(err).Msg("could not start listener") - } - srv := new(http.Server) - - defer func() { - if r := recover(); r != nil { - reason := strings.Builder{} - if _, err = net.Dial("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)); err != nil { - reason.WriteString("runtime address already in use") - } - fmt.Println(reason.String()) - } - }() + // register and run the runtime rpc server + s.runRPCServer() // prepare the set of services to run s.generateRunSet(s.cfg) @@ -437,14 +417,8 @@ func Start(ctx context.Context, o ...Option) error { // schedule services that are optional scheduleServiceTokens(s, s.Additional) - go func() { - if err = srv.Serve(l); err != nil && !errors.Is(err, http.ErrServerClosed) { - s.Log.Fatal().Err(err).Msg("could not start rpc server") - } - }() - // trapShutdownCtx will block on the context-done channel for interruptions. - trapShutdownCtx(s, srv, ctx) + trapShutdownCtx(s, ctx) return nil } @@ -512,20 +486,32 @@ func (s *Service) List(_ struct{}, reply *string) error { return nil } -func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) { - <-ctx.Done() - wg := sync.WaitGroup{} - wg.Add(1) - go func() { - defer wg.Done() - ctx, cancel := context.WithTimeout(context.Background(), _defaultShutdownTimeoutDuration) - defer cancel() - if err := srv.Shutdown(ctx); err != nil { - s.Log.Error().Err(err).Msg("could not shutdown tcp listener") +// register and run the runtime rpc server +func (s *Service) runRPCServer() { + if err := rpc.Register(s); err != nil { + if s != nil { + s.Log.Fatal().Err(err).Msg("could not register rpc service") return } - s.Log.Info().Msg("tcp listener shutdown") + } + rpc.HandleHTTP() + // run rpc server + srv := new(http.Server) + go func() { + l, err := net.Listen("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)) + if err != nil { + s.Log.Fatal().Err(err).Msg("could not start listener") + return + } + if err = srv.Serve(l); err != nil && !errors.Is(err, http.ErrServerClosed) { + s.Log.Fatal().Err(err).Msg("could not start rpc server") + } }() +} + +func trapShutdownCtx(s *Service, ctx context.Context) { + <-ctx.Done() + wg := sync.WaitGroup{} for sName := range s.serviceToken { for i := range s.serviceToken[sName] { diff --git a/services/antivirus/pkg/command/server.go b/services/antivirus/pkg/command/server.go index e6f48ee4d6..17eb51cf55 100644 --- a/services/antivirus/pkg/command/server.go +++ b/services/antivirus/pkg/command/server.go @@ -47,7 +47,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr := runner.NewGroup(runner.Option()) + gr := runner.NewGroup() { svc, err := service.NewAntivirus(cfg, logger, traceProvider) if err != nil { From d76afadd4d47b7ec62ad07436363d7933e341205 Mon Sep 17 00:00:00 2001 From: Roman Perekhod Date: Wed, 28 May 2025 11:28:25 +0200 Subject: [PATCH 07/11] clean up --- opencloud/pkg/runtime/service/service.go | 58 +++++++++++--------- services/storage-users/pkg/command/server.go | 7 ++- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/opencloud/pkg/runtime/service/service.go b/opencloud/pkg/runtime/service/service.go index 7683c0262f..1310f11b77 100644 --- a/opencloud/pkg/runtime/service/service.go +++ b/opencloud/pkg/runtime/service/service.go @@ -392,8 +392,18 @@ func Start(ctx context.Context, o ...Option) error { } } - // register and run the runtime rpc server - s.runRPCServer() + if err = rpc.Register(s); err != nil { + if s != nil { + s.Log.Fatal().Err(err).Msg("could not register rpc service") + } + } + rpc.HandleHTTP() + + l, err := net.Listen("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)) + if err != nil { + s.Log.Fatal().Err(err).Msg("could not start listener") + } + srv := new(http.Server) // prepare the set of services to run s.generateRunSet(s.cfg) @@ -417,8 +427,14 @@ func Start(ctx context.Context, o ...Option) error { // schedule services that are optional scheduleServiceTokens(s, s.Additional) + go func() { + if err = srv.Serve(l); err != nil && !errors.Is(err, http.ErrServerClosed) { + s.Log.Fatal().Err(err).Msg("could not start rpc server") + } + }() + // trapShutdownCtx will block on the context-done channel for interruptions. - trapShutdownCtx(s, ctx) + trapShutdownCtx(s, srv, ctx) return nil } @@ -486,32 +502,20 @@ func (s *Service) List(_ struct{}, reply *string) error { return nil } -// register and run the runtime rpc server -func (s *Service) runRPCServer() { - if err := rpc.Register(s); err != nil { - if s != nil { - s.Log.Fatal().Err(err).Msg("could not register rpc service") - return - } - } - rpc.HandleHTTP() - // run rpc server - srv := new(http.Server) - go func() { - l, err := net.Listen("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)) - if err != nil { - s.Log.Fatal().Err(err).Msg("could not start listener") - return - } - if err = srv.Serve(l); err != nil && !errors.Is(err, http.ErrServerClosed) { - s.Log.Fatal().Err(err).Msg("could not start rpc server") - } - }() -} - -func trapShutdownCtx(s *Service, ctx context.Context) { +func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) { <-ctx.Done() wg := sync.WaitGroup{} + wg.Add(1) + go func() { + defer wg.Done() + ctx, cancel := context.WithTimeout(context.Background(), _defaultShutdownTimeoutDuration) + defer cancel() + if err := srv.Shutdown(ctx); err != nil { + s.Log.Error().Err(err).Msg("could not shutdown tcp listener") + return + } + s.Log.Info().Msg("tcp listener shutdown") + }() for sName := range s.serviceToken { for i := range s.serviceToken[sName] { diff --git a/services/storage-users/pkg/command/server.go b/services/storage-users/pkg/command/server.go index c029c04b70..a374757ac9 100644 --- a/services/storage-users/pkg/command/server.go +++ b/services/storage-users/pkg/command/server.go @@ -100,7 +100,12 @@ func Server(cfg *config.Config) *cli.Command { logger.Fatal().Err(err).Msg("can't create event handler") } // The event service Run() function handles the stop signal itself - go eventSVC.Run() + go func() { + err := eventSVC.Run() + if err != nil { + logger.Fatal().Err(err).Msg("can't run event server") + } + }() } grResults := gr.Run(ctx) From 9f096d41076dffe44533d16873d2e55c0e00a3d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Mon, 8 Sep 2025 17:25:07 +0200 Subject: [PATCH 08/11] update comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- pkg/runner/factory.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/runner/factory.go b/pkg/runner/factory.go index 9ad599a876..95d9c74559 100644 --- a/pkg/runner/factory.go +++ b/pkg/runner/factory.go @@ -14,7 +14,7 @@ import ( // NewGoMicroGrpcServerRunner creates a new runner based on the provided go-micro's // GRPC service. The service is expected to be created via -// "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc".NewService(...) function +// "github.com/opencloud-eu/opencloud/pkg/service/grpc".NewService(...) function // // The runner will behave as described: // * The task is to start a server and listen for connections. If the server @@ -44,7 +44,7 @@ func NewGoMicroGrpcServerRunner(name string, server ogrpc.Service, opts ...Optio // NewGoMicroHttpServerRunner creates a new runner based on the provided go-micro's // HTTP service. The service is expected to be created via -// "github.com/owncloud/ocis/v2/ocis-pkg/service/http".NewService(...) function +// "github.com/opencloud-eu/opencloud/pkg/service/http".NewService(...) function // // The runner will behave as described: // * The task is to start a server and listen for connections. If the server @@ -74,7 +74,7 @@ func NewGoMicroHttpServerRunner(name string, server ohttp.Service, opts ...Optio // NewGolangHttpServerRunner creates a new runner based on the provided HTTP server. // The HTTP server is expected to be created via -// "github.com/owncloud/ocis/v2/ocis-pkg/service/debug".NewService(...) function +// "github.com/opencloud-eu/opencloud/pkg/service/debug".NewService(...) function // and it's expected to be a regular golang HTTP server // // The runner will behave as described: From f8440edc9a9b2905ff52b9ac62bb56dfc4746ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Thu, 11 Sep 2025 10:01:12 +0200 Subject: [PATCH 09/11] bump reva MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- go.mod | 11 +- go.sum | 20 +- .../antithesishq/antithesis-sdk-go/LICENSE | 21 + .../antithesis-sdk-go/assert/assert.go | 151 +++ .../antithesis-sdk-go/assert/assert_noop.go | 16 + .../antithesis-sdk-go/assert/assert_types.go | 30 + .../assert/boolean_guidance.go | 66 ++ .../antithesis-sdk-go/assert/location.go | 58 ++ .../assert/numeric_guidance.go | 323 ++++++ .../antithesis-sdk-go/assert/rich_assert.go | 330 ++++++ .../assert/rich_assert_nop.go | 34 + .../antithesis-sdk-go/assert/tracker.go | 111 ++ .../antithesis-sdk-go/internal/emit.go | 242 +++++ .../antithesis-sdk-go/internal/sdk_const.go | 12 + .../nats-io/nats-server/v2/server/accounts.go | 31 +- .../nats-server/v2/server/auth_callout.go | 4 +- .../v2/server/certidp/ocsp_responder.go | 18 +- .../nats-io/nats-server/v2/server/client.go | 43 +- .../nats-io/nats-server/v2/server/const.go | 12 +- .../nats-io/nats-server/v2/server/consumer.go | 57 +- .../nats-io/nats-server/v2/server/errors.json | 20 + .../nats-io/nats-server/v2/server/events.go | 29 +- .../nats-server/v2/server/jetstream.go | 110 +- .../nats-server/v2/server/jetstream_api.go | 133 ++- .../v2/server/jetstream_cluster.go | 600 +++++++++-- .../v2/server/jetstream_errors_generated.go | 40 + .../v2/server/jetstream_versioning.go | 39 +- .../nats-io/nats-server/v2/server/jwt.go | 6 +- .../nats-io/nats-server/v2/server/leafnode.go | 47 +- .../nats-io/nats-server/v2/server/monitor.go | 9 + .../nats-io/nats-server/v2/server/raft.go | 165 +-- .../nats-io/nats-server/v2/server/route.go | 35 +- .../nats-io/nats-server/v2/server/stream.go | 97 +- .../reva/v2/cmd/revad/internal/grace/grace.go | 22 +- .../reva/v2/cmd/revad/runtime/drivenserver.go | 92 +- vendor/github.com/shamaton/msgpack/v2/LICENSE | 2 +- .../github.com/shamaton/msgpack/v2/README.md | 9 +- .../shamaton/msgpack/v2/ext/decode.go | 21 + .../shamaton/msgpack/v2/ext/decoder_stream.go | 11 + .../shamaton/msgpack/v2/ext/encode.go | 41 + .../shamaton/msgpack/v2/ext/encode_stream.go | 27 +- .../msgpack/v2/internal/common/common.go | 39 +- .../msgpack/v2/internal/decoding/struct.go | 4 +- .../msgpack/v2/internal/encoding/byte.go | 6 +- .../msgpack/v2/internal/encoding/complex.go | 4 +- .../msgpack/v2/internal/encoding/encoding.go | 141 ++- .../msgpack/v2/internal/encoding/float.go | 8 +- .../msgpack/v2/internal/encoding/int.go | 10 +- .../msgpack/v2/internal/encoding/map.go | 171 ++-- .../msgpack/v2/internal/encoding/slice.go | 61 +- .../msgpack/v2/internal/encoding/string.go | 8 +- .../msgpack/v2/internal/encoding/struct.go | 127 ++- .../msgpack/v2/internal/encoding/uint.go | 10 +- .../v2/internal/stream/decoding/struct.go | 4 +- .../v2/internal/stream/encoding/struct.go | 65 +- .../shamaton/msgpack/v2/time/encode.go | 6 +- .../golang.org/x/sys/plan9/pwd_go15_plan9.go | 21 - vendor/golang.org/x/sys/plan9/pwd_plan9.go | 14 +- .../golang.org/x/sys/unix/affinity_linux.go | 4 +- .../golang.org/x/sys/unix/syscall_solaris.go | 2 +- .../x/sys/unix/zsyscall_solaris_amd64.go | 8 +- vendor/golang.org/x/sys/unix/ztypes_linux.go | 41 + .../sys/windows/registry/zsyscall_windows.go | 16 +- .../golang.org/x/sys/windows/types_windows.go | 6 + .../x/sys/windows/zsyscall_windows.go | 966 +++++++++--------- vendor/modules.txt | 20 +- 66 files changed, 3771 insertions(+), 1136 deletions(-) create mode 100644 vendor/github.com/antithesishq/antithesis-sdk-go/LICENSE create mode 100644 vendor/github.com/antithesishq/antithesis-sdk-go/assert/assert.go create mode 100644 vendor/github.com/antithesishq/antithesis-sdk-go/assert/assert_noop.go create mode 100644 vendor/github.com/antithesishq/antithesis-sdk-go/assert/assert_types.go create mode 100644 vendor/github.com/antithesishq/antithesis-sdk-go/assert/boolean_guidance.go create mode 100644 vendor/github.com/antithesishq/antithesis-sdk-go/assert/location.go create mode 100644 vendor/github.com/antithesishq/antithesis-sdk-go/assert/numeric_guidance.go create mode 100644 vendor/github.com/antithesishq/antithesis-sdk-go/assert/rich_assert.go create mode 100644 vendor/github.com/antithesishq/antithesis-sdk-go/assert/rich_assert_nop.go create mode 100644 vendor/github.com/antithesishq/antithesis-sdk-go/assert/tracker.go create mode 100644 vendor/github.com/antithesishq/antithesis-sdk-go/internal/emit.go create mode 100644 vendor/github.com/antithesishq/antithesis-sdk-go/internal/sdk_const.go delete mode 100644 vendor/golang.org/x/sys/plan9/pwd_go15_plan9.go diff --git a/go.mod b/go.mod index b827d564a3..0c5b5f9c04 100644 --- a/go.mod +++ b/go.mod @@ -56,7 +56,7 @@ require ( github.com/mitchellh/mapstructure v1.5.0 github.com/mna/pigeon v1.3.0 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 - github.com/nats-io/nats-server/v2 v2.11.8 + github.com/nats-io/nats-server/v2 v2.11.9 github.com/nats-io/nats.go v1.45.0 github.com/oklog/run v1.2.0 github.com/olekukonko/tablewriter v1.0.9 @@ -65,7 +65,7 @@ require ( github.com/onsi/gomega v1.38.2 github.com/open-policy-agent/opa v1.6.0 github.com/opencloud-eu/libre-graph-api-go v1.0.8-0.20250724122329-41ba6b191e76 - github.com/opencloud-eu/reva/v2 v2.37.1-0.20250909074412-f272eeaa2674 + github.com/opencloud-eu/reva/v2 v2.37.1-0.20250911072739-9e673e021dca github.com/opensearch-project/opensearch-go/v4 v4.5.0 github.com/orcaman/concurrent-map v1.0.0 github.com/pkg/errors v0.9.1 @@ -134,6 +134,7 @@ require ( github.com/ajg/form v1.5.1 // indirect github.com/alexedwards/argon2id v1.0.0 // indirect github.com/amoghe/go-crypt v0.0.0-20220222110647-20eada5f5964 // indirect + github.com/antithesishq/antithesis-sdk-go v0.4.3-default-no-op // indirect github.com/armon/go-radix v1.0.0 // indirect github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect github.com/beorn7/perks v1.0.1 // indirect @@ -323,7 +324,7 @@ require ( github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect github.com/sethvargo/go-diceware v0.5.0 // indirect github.com/sethvargo/go-password v0.3.1 // indirect - github.com/shamaton/msgpack/v2 v2.2.3 // indirect + github.com/shamaton/msgpack/v2 v2.3.1 // indirect github.com/shirou/gopsutil/v4 v4.25.5 // indirect github.com/shurcooL/httpfs v0.0.0-20230704072500-f1e31cf0ba5c // indirect github.com/shurcooL/vfsgen v0.0.0-20230704071429-0000e147ea92 // indirect @@ -363,8 +364,8 @@ require ( go.yaml.in/yaml/v2 v2.4.2 // indirect go.yaml.in/yaml/v3 v3.0.4 // indirect golang.org/x/mod v0.27.0 // indirect - golang.org/x/sys v0.35.0 // indirect - golang.org/x/time v0.12.0 // indirect + golang.org/x/sys v0.36.0 // indirect + golang.org/x/time v0.13.0 // indirect golang.org/x/tools v0.36.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/genproto v0.0.0-20250303144028-a0af3efb3deb // indirect diff --git a/go.sum b/go.sum index 46322a3160..60bbdfd145 100644 --- a/go.sum +++ b/go.sum @@ -869,8 +869,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRW github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY4wsPvgQH/jsuJi4XO2ssZbdsIizr4CVC8= github.com/nats-io/jwt/v2 v2.7.4 h1:jXFuDDxs/GQjGDZGhNgH4tXzSUK6WQi2rsj4xmsNOtI= github.com/nats-io/jwt/v2 v2.7.4/go.mod h1:me11pOkwObtcBNR8AiMrUbtVOUGkqYjMQZ6jnSdVUIA= -github.com/nats-io/nats-server/v2 v2.11.8 h1:7T1wwwd/SKTDWW47KGguENE7Wa8CpHxLD1imet1iW7c= -github.com/nats-io/nats-server/v2 v2.11.8/go.mod h1:C2zlzMA8PpiMMxeXSz7FkU3V+J+H15kiqrkvgtn2kS8= +github.com/nats-io/nats-server/v2 v2.11.9 h1:k7nzHZjUf51W1b08xiQih63Rdxh0yr5O4K892Mx5gQA= +github.com/nats-io/nats-server/v2 v2.11.9/go.mod h1:1MQgsAQX1tVjpf3Yzrk3x2pzdsZiNL/TVP3Amhp3CR8= github.com/nats-io/nats.go v1.45.0 h1:/wGPbnYXDM0pLKFjZTX+2JOw9TQPoIgTFrUaH97giwA= github.com/nats-io/nats.go v1.45.0/go.mod h1:iRWIPokVIFbVijxuMQq4y9ttaBTMe0SFdlZfMDd+33g= github.com/nats-io/nkeys v0.4.11 h1:q44qGV008kYd9W1b1nEBkNzvnWxtRSQ7A8BoqRrcfa0= @@ -916,8 +916,8 @@ github.com/opencloud-eu/go-micro-plugins/v4/store/nats-js-kv v0.0.0-202505121527 github.com/opencloud-eu/go-micro-plugins/v4/store/nats-js-kv v0.0.0-20250512152754-23325793059a/go.mod h1:pjcozWijkNPbEtX5SIQaxEW/h8VAVZYTLx+70bmB3LY= github.com/opencloud-eu/libre-graph-api-go v1.0.8-0.20250724122329-41ba6b191e76 h1:vD/EdfDUrv4omSFjrinT8Mvf+8D7f9g4vgQ2oiDrVUI= github.com/opencloud-eu/libre-graph-api-go v1.0.8-0.20250724122329-41ba6b191e76/go.mod h1:pzatilMEHZFT3qV7C/X3MqOa3NlRQuYhlRhZTL+hN6Q= -github.com/opencloud-eu/reva/v2 v2.37.1-0.20250909074412-f272eeaa2674 h1:35OSsH9o4GAL9LX+BckhYlpp+EqJ0Bz69MXz+5gpaV4= -github.com/opencloud-eu/reva/v2 v2.37.1-0.20250909074412-f272eeaa2674/go.mod h1:eu0fTK68n+drdu7eT0u1QODDH3VHMugAdrS6G5VhMwA= +github.com/opencloud-eu/reva/v2 v2.37.1-0.20250911072739-9e673e021dca h1:0RrrnhJAlyVmzKfwoG8UvNCNkLa2gxDh2qriv09IfW0= +github.com/opencloud-eu/reva/v2 v2.37.1-0.20250911072739-9e673e021dca/go.mod h1:BFtLyq/7VXuWJhsZKxFocZTsYIVTRoqY4oNI3mXCRu0= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040= @@ -1065,8 +1065,8 @@ github.com/sethvargo/go-diceware v0.5.0 h1:exrQ7GpaBo00GqRVM1N8ChXSsi3oS7tjQiIeh github.com/sethvargo/go-diceware v0.5.0/go.mod h1:Lg1SyPS7yQO6BBgTN5r4f2MUDkqGfLWsOjHPY0kA8iw= github.com/sethvargo/go-password v0.3.1 h1:WqrLTjo7X6AcVYfC6R7GtSyuUQR9hGyAj/f1PYQZCJU= github.com/sethvargo/go-password v0.3.1/go.mod h1:rXofC1zT54N7R8K/h1WDUdkf9BOx5OptoxrMBcrXzvs= -github.com/shamaton/msgpack/v2 v2.2.3 h1:uDOHmxQySlvlUYfQwdjxyybAOzjlQsD1Vjy+4jmO9NM= -github.com/shamaton/msgpack/v2 v2.2.3/go.mod h1:6khjYnkx73f7VQU7wjcFS9DFjs+59naVWJv1TB7qdOI= +github.com/shamaton/msgpack/v2 v2.3.1 h1:R3QNLIGA/tbdczNMZ5PCRxrXvy+fnzsIaHG4kKMgWYo= +github.com/shamaton/msgpack/v2 v2.3.1/go.mod h1:6khjYnkx73f7VQU7wjcFS9DFjs+59naVWJv1TB7qdOI= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/gopsutil/v4 v4.25.5 h1:rtd9piuSMGeU8g1RMXjZs9y9luK5BwtnG7dZaQUJAsc= @@ -1519,8 +1519,8 @@ golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI= -golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k= +golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -1556,8 +1556,8 @@ golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE= -golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= +golang.org/x/time v0.13.0 h1:eUlYslOIt32DgYD6utsuUeHs4d7AsEYLuIAdg7FlYgI= +golang.org/x/time v0.13.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/vendor/github.com/antithesishq/antithesis-sdk-go/LICENSE b/vendor/github.com/antithesishq/antithesis-sdk-go/LICENSE new file mode 100644 index 0000000000..90f1712ed1 --- /dev/null +++ b/vendor/github.com/antithesishq/antithesis-sdk-go/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Antithesis + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/antithesishq/antithesis-sdk-go/assert/assert.go b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/assert.go new file mode 100644 index 0000000000..033fadfb2a --- /dev/null +++ b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/assert.go @@ -0,0 +1,151 @@ +//go:build enable_antithesis_sdk + +// Package assert enables defining [test properties] about your program or [workload]. It is part of the [Antithesis Go SDK], which enables Go applications to integrate with the [Antithesis platform]. +// +// Code that uses this package should be instrumented with the [antithesis-go-generator] utility. This step is required for the Always, Sometime, and Reachable methods. It is not required for the Unreachable and AlwaysOrUnreachable methods, but it will improve the experience of using them. +// +// These functions are no-ops with minimal performance overhead when called outside of the Antithesis environment. However, if the environment variable ANTITHESIS_SDK_LOCAL_OUTPUT is set, these functions will log to the file pointed to by that variable using a structured JSON format defined [here]. This allows you to make use of the Antithesis assertions package in your regular testing, or even in production. In particular, very few assertions frameworks offer a convenient way to define [Sometimes assertions], but they can be quite useful even outside Antithesis. +// +// Each function in this package takes a parameter called message, which is a human readable identifier used to aggregate assertions. Antithesis generates one test property per unique message and this test property will be named "" in the [triage report]. +// +// This test property either passes or fails, which depends upon the evaluation of every assertion that shares its message. Different assertions in different parts of the code should have different message, but the same assertion should always have the same message even if it is moved to a different file. +// +// Each function also takes a parameter called details, which is a key-value map of optional additional information provided by the user to add context for assertion failures. The information that is logged will appear in the [triage report], under the details section of the corresponding property. Normally the values passed to details are evaluated at runtime. +// +// [Antithesis Go SDK]: https://antithesis.com/docs/using_antithesis/sdk/go/ +// [Antithesis platform]: https://antithesis.com +// [test properties]: https://antithesis.com/docs/using_antithesis/properties/ +// [workload]: https://antithesis.com/docs/getting_started/first_test/ +// [antithesis-go-generator]: https://antithesis.com/docs/using_antithesis/sdk/go/instrumentor/ +// [triage report]: https://antithesis.com/docs/reports/triage/ +// [here]: https://antithesis.com/docs/using_antithesis/sdk/fallback/ +// [Sometimes assertions]: https://antithesis.com/docs/best_practices/sometimes_assertions/ +// +// [details]: https://antithesis.com/docs/reports/triage/#details +package assert + +type assertInfo struct { + Location *locationInfo `json:"location"` + Details map[string]any `json:"details"` + AssertType string `json:"assert_type"` + DisplayType string `json:"display_type"` + Message string `json:"message"` + Id string `json:"id"` + Hit bool `json:"hit"` + MustHit bool `json:"must_hit"` + Condition bool `json:"condition"` +} + +type wrappedAssertInfo struct { + A *assertInfo `json:"antithesis_assert"` +} + +// -------------------------------------------------------------------------------- +// Assertions +// -------------------------------------------------------------------------------- +const ( + wasHit = true + mustBeHit = true + optionallyHit = false + expectingTrue = true +) + +const ( + universalTest = "always" + existentialTest = "sometimes" + reachabilityTest = "reachability" +) + +const ( + alwaysDisplay = "Always" + alwaysOrUnreachableDisplay = "AlwaysOrUnreachable" + sometimesDisplay = "Sometimes" + reachableDisplay = "Reachable" + unreachableDisplay = "Unreachable" +) + +// Always asserts that condition is true every time this function is called, and that it is called at least once. The corresponding test property will be viewable in the Antithesis SDK: Always group of your triage report. +func Always(condition bool, message string, details map[string]any) { + locationInfo := newLocationInfo(offsetAPICaller) + id := makeKey(message, locationInfo) + assertImpl(condition, message, details, locationInfo, wasHit, mustBeHit, universalTest, alwaysDisplay, id) +} + +// AlwaysOrUnreachable asserts that condition is true every time this function is called. The corresponding test property will pass if the assertion is never encountered (unlike Always assertion types). This test property will be viewable in the “Antithesis SDK: Always” group of your triage report. +func AlwaysOrUnreachable(condition bool, message string, details map[string]any) { + locationInfo := newLocationInfo(offsetAPICaller) + id := makeKey(message, locationInfo) + assertImpl(condition, message, details, locationInfo, wasHit, optionallyHit, universalTest, alwaysOrUnreachableDisplay, id) +} + +// Sometimes asserts that condition is true at least one time that this function was called. (If the assertion is never encountered, the test property will therefore fail.) This test property will be viewable in the “Antithesis SDK: Sometimes” group. +func Sometimes(condition bool, message string, details map[string]any) { + locationInfo := newLocationInfo(offsetAPICaller) + id := makeKey(message, locationInfo) + assertImpl(condition, message, details, locationInfo, wasHit, mustBeHit, existentialTest, sometimesDisplay, id) +} + +// Unreachable asserts that a line of code is never reached. The corresponding test property will fail if this function is ever called. (If it is never called the test property will therefore pass.) This test property will be viewable in the “Antithesis SDK: Reachablity assertions” group. +func Unreachable(message string, details map[string]any) { + locationInfo := newLocationInfo(offsetAPICaller) + id := makeKey(message, locationInfo) + assertImpl(false, message, details, locationInfo, wasHit, optionallyHit, reachabilityTest, unreachableDisplay, id) +} + +// Reachable asserts that a line of code is reached at least once. The corresponding test property will pass if this function is ever called. (If it is never called the test property will therefore fail.) This test property will be viewable in the “Antithesis SDK: Reachablity assertions” group. +func Reachable(message string, details map[string]any) { + locationInfo := newLocationInfo(offsetAPICaller) + id := makeKey(message, locationInfo) + assertImpl(true, message, details, locationInfo, wasHit, mustBeHit, reachabilityTest, reachableDisplay, id) +} + +// AssertRaw is a low-level method designed to be used by third-party frameworks. Regular users of the assert package should not call it. +func AssertRaw(cond bool, message string, details map[string]any, + classname, funcname, filename string, line int, + hit bool, mustHit bool, + assertType string, displayType string, + id string, +) { + assertImpl(cond, message, details, + &locationInfo{classname, funcname, filename, line, columnUnknown}, + hit, mustHit, + assertType, displayType, + id) +} + +func assertImpl(cond bool, message string, details map[string]any, + loc *locationInfo, + hit bool, mustHit bool, + assertType string, displayType string, + id string, +) { + trackerEntry := assertTracker.getTrackerEntry(id, loc.Filename, loc.Classname) + + // Always grab the Filename and Classname captured when the trackerEntry was established + // This provides the consistency needed between instrumentation-time and runtime + if loc.Filename != trackerEntry.Filename { + loc.Filename = trackerEntry.Filename + } + + if loc.Classname != trackerEntry.Classname { + loc.Classname = trackerEntry.Classname + } + + aI := &assertInfo{ + Hit: hit, + MustHit: mustHit, + AssertType: assertType, + DisplayType: displayType, + Message: message, + Condition: cond, + Id: id, + Location: loc, + Details: details, + } + + trackerEntry.emit(aI) +} + +func makeKey(message string, _ *locationInfo) string { + return message +} diff --git a/vendor/github.com/antithesishq/antithesis-sdk-go/assert/assert_noop.go b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/assert_noop.go new file mode 100644 index 0000000000..640f18ef10 --- /dev/null +++ b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/assert_noop.go @@ -0,0 +1,16 @@ +//go:build !enable_antithesis_sdk + +package assert + +func Always(condition bool, message string, details map[string]any) {} +func AlwaysOrUnreachable(condition bool, message string, details map[string]any) {} +func Sometimes(condition bool, message string, details map[string]any) {} +func Unreachable(message string, details map[string]any) {} +func Reachable(message string, details map[string]any) {} +func AssertRaw(cond bool, message string, details map[string]any, + classname, funcname, filename string, line int, + hit bool, mustHit bool, + assertType string, displayType string, + id string, +) { +} diff --git a/vendor/github.com/antithesishq/antithesis-sdk-go/assert/assert_types.go b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/assert_types.go new file mode 100644 index 0000000000..d5203816da --- /dev/null +++ b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/assert_types.go @@ -0,0 +1,30 @@ +package assert + +// Allowable numeric types of comparison parameters +type Number interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint8 | ~uint16 | ~uint32 | ~float32 | ~float64 | ~uint64 | ~uint | ~uintptr +} + +// Internally, numeric guidanceFn Operands only use these +type operandConstraint interface { + int32 | int64 | uint64 | float64 +} + +type numConstraint interface { + uint64 | float64 +} + +// Used for boolean assertions +type NamedBool struct { + First string `json:"first"` + Second bool `json:"second"` +} + +// Convenience function to construct a NamedBool used for boolean assertions +func NewNamedBool(first string, second bool) *NamedBool { + p := NamedBool{ + First: first, + Second: second, + } + return &p +} diff --git a/vendor/github.com/antithesishq/antithesis-sdk-go/assert/boolean_guidance.go b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/boolean_guidance.go new file mode 100644 index 0000000000..7a2af845e4 --- /dev/null +++ b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/boolean_guidance.go @@ -0,0 +1,66 @@ +//go:build enable_antithesis_sdk + +package assert + +import ( + "sync" + + "github.com/antithesishq/antithesis-sdk-go/internal" +) + +// TODO: Tracker is intended to prevent sending the same guidance +// more than once. In this case, we always send, so the tracker +// is not presently used. +type booleanGuidance struct { + n int +} + +type booleanGuidanceTracker map[string]*booleanGuidance + +var ( + boolean_guidance_tracker booleanGuidanceTracker = make(booleanGuidanceTracker) + boolean_guidance_tracker_mutex sync.Mutex + boolean_guidance_info_mutex sync.Mutex +) + +func (tracker booleanGuidanceTracker) getTrackerEntry(messageKey string) *booleanGuidance { + var trackerEntry *booleanGuidance + var ok bool + + if tracker == nil { + return nil + } + + boolean_guidance_tracker_mutex.Lock() + defer boolean_guidance_tracker_mutex.Unlock() + if trackerEntry, ok = boolean_guidance_tracker[messageKey]; !ok { + trackerEntry = newBooleanGuidance() + tracker[messageKey] = trackerEntry + } + + return trackerEntry +} + +// Create a boolean guidance tracker +func newBooleanGuidance() *booleanGuidance { + trackerInfo := booleanGuidance{} + return &trackerInfo +} + +func (tI *booleanGuidance) send_value(bgI *booleanGuidanceInfo) { + if tI == nil { + return + } + + boolean_guidance_info_mutex.Lock() + defer boolean_guidance_info_mutex.Unlock() + + // The tracker entry should be consulted to determine + // if this Guidance info has already been sent, or not. + + emitBooleanGuidance(bgI) +} + +func emitBooleanGuidance(bgI *booleanGuidanceInfo) error { + return internal.Json_data(map[string]any{"antithesis_guidance": bgI}) +} diff --git a/vendor/github.com/antithesishq/antithesis-sdk-go/assert/location.go b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/location.go new file mode 100644 index 0000000000..463340a86a --- /dev/null +++ b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/location.go @@ -0,0 +1,58 @@ +//go:build enable_antithesis_sdk + +package assert + +import ( + "path" + "runtime" + "strings" +) + +// stackFrameOffset indicates how many frames to go up in the +// call stack to find the filename/location/line info. As +// this work is always done in NewLocationInfo(), the offset is +// specified from the perspective of NewLocationInfo +type stackFrameOffset int + +// Order is important here since iota is being used +const ( + offsetNewLocationInfo stackFrameOffset = iota + offsetHere + offsetAPICaller + offsetAPICallersCaller +) + +// locationInfo represents the attributes known at instrumentation time +// for each Antithesis assertion discovered +type locationInfo struct { + Classname string `json:"class"` + Funcname string `json:"function"` + Filename string `json:"file"` + Line int `json:"begin_line"` + Column int `json:"begin_column"` +} + +// columnUnknown is used when the column associated with +// a locationInfo is not available +const columnUnknown = 0 + +// NewLocationInfo creates a locationInfo directly from +// the current execution context +func newLocationInfo(nframes stackFrameOffset) *locationInfo { + // Get location info and add to details + funcname := "*function*" + classname := "*class*" + pc, filename, line, ok := runtime.Caller(int(nframes)) + if !ok { + filename = "*file*" + line = 0 + } else { + if this_func := runtime.FuncForPC(pc); this_func != nil { + fullname := this_func.Name() + funcname = path.Ext(fullname) + classname, _ = strings.CutSuffix(fullname, funcname) + funcname = funcname[1:] + } + } + return &locationInfo{classname, funcname, filename, line, columnUnknown} +} diff --git a/vendor/github.com/antithesishq/antithesis-sdk-go/assert/numeric_guidance.go b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/numeric_guidance.go new file mode 100644 index 0000000000..1bba49e90c --- /dev/null +++ b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/numeric_guidance.go @@ -0,0 +1,323 @@ +//go:build enable_antithesis_sdk + +package assert + +import ( + "math" + "sync" + + "github.com/antithesishq/antithesis-sdk-go/internal" +) + +// -------------------------------------------------------------------------------- +// IntegerGap is used for: +// - int, int8, int16, int32, int64: +// - uint, uint8, uint16, uint32, uint64, uintptr: +// +// FloatGap is used for: +// - float32, float64 +// -------------------------------------------------------------------------------- +type numericGapType int + +const ( + integerGapType numericGapType = iota + floatGapType +) + +func gapTypeForOperand[T Number](num T) numericGapType { + gapType := integerGapType + + switch any(num).(type) { + case float32, float64: + gapType = floatGapType + } + return gapType +} + +// -------------------------------------------------------------------------------- +// numericGuidanceTracker - Tracking Info for Numeric Guidance +// +// For GuidanceFnMaximize: +// - gap is the largest value sent so far +// +// For GuidanceFnMinimize: +// - gap is the most negative value sent so far +// +// -------------------------------------------------------------------------------- +type numericGuidanceInfo struct { + gap any + descriminator numericGapType + maximize bool +} + +type numericGuidanceTracker map[string]*numericGuidanceInfo + +var ( + numeric_guidance_tracker numericGuidanceTracker = make(numericGuidanceTracker) + numeric_guidance_tracker_mutex sync.Mutex + numeric_guidance_info_mutex sync.Mutex +) + +func (tracker numericGuidanceTracker) getTrackerEntry(messageKey string, trackerType numericGapType, maximize bool) *numericGuidanceInfo { + var trackerEntry *numericGuidanceInfo + var ok bool + + if tracker == nil { + return nil + } + + numeric_guidance_tracker_mutex.Lock() + defer numeric_guidance_tracker_mutex.Unlock() + if trackerEntry, ok = numeric_guidance_tracker[messageKey]; !ok { + trackerEntry = newNumericGuidanceInfo(trackerType, maximize) + tracker[messageKey] = trackerEntry + } + + return trackerEntry +} + +// Create an numeric guidance entry +func newNumericGuidanceInfo(trackerType numericGapType, maximize bool) *numericGuidanceInfo { + + var gap any + if trackerType == integerGapType { + gap = newGapValue(uint64(math.MaxUint64), maximize) + } else { + gap = newGapValue(float64(math.MaxFloat64), maximize) + } + trackerInfo := numericGuidanceInfo{ + maximize: maximize, + descriminator: trackerType, + gap: gap, + } + return &trackerInfo +} + +func (tI *numericGuidanceInfo) should_maximize() bool { + return tI.maximize +} + +func (tI *numericGuidanceInfo) is_integer_gap() bool { + return tI.descriminator == integerGapType +} + +// -------------------------------------------------------------------------------- +// Represents integral and floating point extremes +// -------------------------------------------------------------------------------- +type gapValue[T numConstraint] struct { + gap_size T + gap_is_negative bool +} + +func newGapValue[T numConstraint](sz T, is_neg bool) any { + switch any(sz).(type) { + case uint64: + return gapValue[uint64]{gap_size: uint64(sz), gap_is_negative: is_neg} + + case float64: + return gapValue[float64]{gap_size: float64(sz), gap_is_negative: is_neg} + } + return nil +} + +func is_same_sign(left_val int64, right_val int64) bool { + same_sign := false + if left_val < 0 { + // left is negative + if right_val < 0 { + same_sign = true + } + } else { + // left is non-negative + if right_val >= 0 { + same_sign = true + } + } + return same_sign +} + +func abs_int64(val int64) uint64 { + if val >= 0 { + return uint64(val) + } + return uint64(0 - val) +} + +func is_greater_than[T numConstraint](left gapValue[T], right gapValue[T]) bool { + if !left.gap_is_negative && !right.gap_is_negative { + return left.gap_size > right.gap_size + } + if !left.gap_is_negative && right.gap_is_negative { + return true // any positive is greater than a negative + } + if left.gap_is_negative && right.gap_is_negative { + return right.gap_size > left.gap_size + } + if left.gap_is_negative && !right.gap_is_negative { + return false // any negative is less than a positive + } + return false +} + +func is_less_than[T numConstraint](left gapValue[T], right gapValue[T]) bool { + if !left.gap_is_negative && !right.gap_is_negative { + return left.gap_size < right.gap_size + } + if !left.gap_is_negative && right.gap_is_negative { + return false // any positive is greater than a negative + } + if left.gap_is_negative && right.gap_is_negative { + return right.gap_size < left.gap_size + } + if left.gap_is_negative && !right.gap_is_negative { + return true // any negative is less than a positive + } + return true +} + +func send_value_if_needed(tI *numericGuidanceInfo, gI *guidanceInfo) { + if tI == nil { + return + } + + numeric_guidance_info_mutex.Lock() + defer numeric_guidance_info_mutex.Unlock() + + // if this is a catalog entry (gI.hit is false) + // do not update the reference gap in the tracker (tI *numericGuidanceInfo) + if !gI.Hit { + emitGuidance(gI) + return + } + + should_send := false + maximize := tI.should_maximize() + + var gap gapValue[uint64] + var float_gap gapValue[float64] + + // Needs to have individual case statements to assist + // the compiler to infer the actual type of the var named 'operands' + switch operands := (gI.Data).(type) { + case numericOperands[int32]: + gap = makeGap(operands) + case numericOperands[int64]: + gap = makeGap(operands) + case numericOperands[uint64]: + gap = makeGap(operands) + case numericOperands[float64]: + float_gap = makeFloatGap(operands) + } + + var prev_gap gapValue[uint64] + var prev_float_gap gapValue[float64] + has_prev_gap := false + has_prev_float_gap := false + + prev_gap, has_prev_gap = tI.gap.(gapValue[uint64]) + if !has_prev_gap { + prev_float_gap, has_prev_float_gap = tI.gap.(gapValue[float64]) + } + + if has_prev_gap { + if maximize { + should_send = is_greater_than(gap, prev_gap) + } else { + should_send = is_less_than(gap, prev_gap) + } + } + + if has_prev_float_gap { + if maximize { + should_send = is_greater_than(float_gap, prev_float_gap) + } else { + should_send = is_less_than(float_gap, prev_float_gap) + } + } + + if should_send { + if tI.is_integer_gap() { + tI.gap = gap + } else { + tI.gap = float_gap + } + emitGuidance(gI) + } +} + +func emitGuidance(gI *guidanceInfo) error { + return internal.Json_data(map[string]any{"antithesis_guidance": gI}) +} + +// When left and right are the same sign (both negative, or both non-negative) +// Calculate: = (left - right). The gap_size is abs() and +// gap_is_negative is (right > left) +func makeGap[Op operandConstraint](operand numericOperands[Op]) gapValue[uint64] { + + var gap_size uint64 + var gap_is_negative bool + + switch this_op := any(operand).(type) { + case numericOperands[int32]: + result := int64(this_op.Left) - int64(this_op.Right) + gap_size = abs_int64(result) + gap_is_negative = result < 0 + + case numericOperands[int64]: + if is_same_sign(this_op.Left, this_op.Right) { + result := int64(this_op.Left) - int64(this_op.Right) + gap_size = abs_int64(result) + gap_is_negative = result < 0 + break + } + + // Otherwise left and right are opposite signs + // gap = abs(left) + abs(right) + // gap_is_negative = left < right + left_gap_size := abs_int64(this_op.Left) + right_gap_size := abs_int64(this_op.Right) + gap_size = left_gap_size + right_gap_size + gap_is_negative = this_op.Left < this_op.Right + + case numericOperands[uint64]: + left_val := this_op.Left + right_val := this_op.Right + gap_is_negative = false + if left_val < right_val { + gap_is_negative = true + gap_size = right_val - left_val + } else { + gap_size = left_val - right_val + } + + default: + zero_gap, _ := newGapValue(uint64(0), false).(gapValue[uint64]) + return zero_gap + } + + this_gap, _ := newGapValue(gap_size, gap_is_negative).(gapValue[uint64]) + return this_gap +} // MakeGap + +func makeFloatGap[Op operandConstraint](operand numericOperands[Op]) gapValue[float64] { + switch this_op := any(operand).(type) { + case numericOperands[float64]: + left_val := this_op.Left + right_val := this_op.Right + gap_is_negative := false + var gap_size float64 + if left_val < right_val { + gap_is_negative = true + gap_size = right_val - left_val + } else { + gap_size = left_val - right_val + } + + this_gap, _ := newGapValue(gap_size, gap_is_negative).(gapValue[float64]) + return this_gap + + default: + zero_gap, _ := newGapValue(float64(0.0), false).(gapValue[float64]) + return zero_gap + } +} // MakeFloatGap diff --git a/vendor/github.com/antithesishq/antithesis-sdk-go/assert/rich_assert.go b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/rich_assert.go new file mode 100644 index 0000000000..0edc73622a --- /dev/null +++ b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/rich_assert.go @@ -0,0 +1,330 @@ +//go:build enable_antithesis_sdk + +package assert + +// A type for writing raw assertions. +// guidanceFnType allows the assertion to provide guidance to +// the Antithesis platform when testing in Antithesis. +// Regular users of the assert package should not use it. +type guidanceFnType int + +const ( + guidanceFnMaximize guidanceFnType = iota // Maximize (left - right) values + guidanceFnMinimize // Minimize (left - right) values + guidanceFnWantAll // Encourages fuzzing explorations where boolean values are true + guidanceFnWantNone // Encourages fuzzing explorations where boolean values are false + guidanceFnExplore +) + +// guidanceFnExplore + +func get_guidance_type_string(gt guidanceFnType) string { + switch gt { + case guidanceFnMaximize, guidanceFnMinimize: + return "numeric" + case guidanceFnWantAll, guidanceFnWantNone: + return "boolean" + case guidanceFnExplore: + return "json" + } + return "" +} + +type numericOperands[T operandConstraint] struct { + Left T `json:"left"` + Right T `json:"right"` +} + +type guidanceInfo struct { + Data any `json:"guidance_data,omitempty"` + Location *locationInfo `json:"location"` + GuidanceType string `json:"guidance_type"` + Message string `json:"message"` + Id string `json:"id"` + Maximize bool `json:"maximize"` + Hit bool `json:"hit"` +} + +type booleanGuidanceInfo struct { + Data any `json:"guidance_data,omitempty"` + Location *locationInfo `json:"location"` + GuidanceType string `json:"guidance_type"` + Message string `json:"message"` + Id string `json:"id"` + Maximize bool `json:"maximize"` + Hit bool `json:"hit"` +} + +func uses_maximize(gt guidanceFnType) bool { + return gt == guidanceFnMaximize || gt == guidanceFnWantAll +} + +func newOperands[T Number](left, right T) any { + switch any(left).(type) { + case int8, int16, int32: + return numericOperands[int32]{int32(left), int32(right)} + case int, int64: + return numericOperands[int64]{int64(left), int64(right)} + case uint8, uint16, uint32, uint, uint64, uintptr: + return numericOperands[uint64]{uint64(left), uint64(right)} + case float32, float64: + return numericOperands[float64]{float64(left), float64(right)} + } + return nil +} + +func build_numeric_guidance[T Number](gt guidanceFnType, message string, left, right T, loc *locationInfo, id string, hit bool) *guidanceInfo { + + operands := newOperands(left, right) + if !hit { + operands = nil + } + + gI := guidanceInfo{ + GuidanceType: get_guidance_type_string(gt), + Message: message, + Id: id, + Location: loc, + Maximize: uses_maximize(gt), + Data: operands, + Hit: hit, + } + + return &gI +} + +type namedBoolDictionary map[string]bool + +func build_boolean_guidance(gt guidanceFnType, message string, named_bools []NamedBool, + loc *locationInfo, + id string, hit bool) *booleanGuidanceInfo { + + var guidance_data any + + // To ensure the sequence and naming for the named_bool values + if hit { + named_bool_dictionary := namedBoolDictionary{} + for _, named_bool := range named_bools { + named_bool_dictionary[named_bool.First] = named_bool.Second + } + guidance_data = named_bool_dictionary + } + + bgI := booleanGuidanceInfo{ + GuidanceType: get_guidance_type_string(gt), + Message: message, + Id: id, + Location: loc, + Maximize: uses_maximize(gt), + Data: guidance_data, + Hit: hit, + } + + return &bgI +} + +func behavior_to_guidance(behavior string) guidanceFnType { + guidance := guidanceFnExplore + switch behavior { + case "maximize": + guidance = guidanceFnMaximize + case "minimize": + guidance = guidanceFnMinimize + case "all": + guidance = guidanceFnWantAll + case "none": + guidance = guidanceFnWantNone + } + return guidance +} + +func numericGuidanceImpl[T Number](left, right T, message, id string, loc *locationInfo, guidanceFn guidanceFnType, hit bool) { + tI := numeric_guidance_tracker.getTrackerEntry(id, gapTypeForOperand(left), uses_maximize(guidanceFn)) + gI := build_numeric_guidance(guidanceFn, message, left, right, loc, id, hit) + send_value_if_needed(tI, gI) +} + +func booleanGuidanceImpl(named_bools []NamedBool, message, id string, loc *locationInfo, guidanceFn guidanceFnType, hit bool) { + tI := boolean_guidance_tracker.getTrackerEntry(id) + bgI := build_boolean_guidance(guidanceFn, message, named_bools, loc, id, hit) + tI.send_value(bgI) +} + +// NumericGuidanceRaw is a low-level method designed to be used by third-party frameworks. Regular users of the assert package should not call it. +func NumericGuidanceRaw[T Number]( + left, right T, + message, id string, + classname, funcname, filename string, + line int, + behavior string, + hit bool, +) { + loc := &locationInfo{classname, funcname, filename, line, columnUnknown} + guidanceFn := behavior_to_guidance(behavior) + numericGuidanceImpl(left, right, message, id, loc, guidanceFn, hit) +} + +// BooleanGuidanceRaw is a low-level method designed to be used by third-party frameworks. Regular users of the assert package should not call it. +func BooleanGuidanceRaw( + named_bools []NamedBool, + message, id string, + classname, funcname, filename string, + line int, + behavior string, + hit bool, +) { + loc := &locationInfo{classname, funcname, filename, line, columnUnknown} + guidanceFn := behavior_to_guidance(behavior) + booleanGuidanceImpl(named_bools, message, id, loc, guidanceFn, hit) +} + +func add_numeric_details[T Number](details map[string]any, left, right T) map[string]any { + // ---------------------------------------------------- + // Can not use maps.Clone() until go 1.21.0 or above + // enhancedDetails := maps.Clone(details) + // ---------------------------------------------------- + enhancedDetails := map[string]any{} + for k, v := range details { + enhancedDetails[k] = v + } + enhancedDetails["left"] = left + enhancedDetails["right"] = right + return enhancedDetails +} + +func add_boolean_details(details map[string]any, named_bools []NamedBool) map[string]any { + // ---------------------------------------------------- + // Can not use maps.Clone() until go 1.21.0 or above + // enhancedDetails := maps.Clone(details) + // ---------------------------------------------------- + enhancedDetails := map[string]any{} + for k, v := range details { + enhancedDetails[k] = v + } + for _, named_bool := range named_bools { + enhancedDetails[named_bool.First] = named_bool.Second + } + return enhancedDetails +} + +// Equivalent to asserting Always(left > right, message, details). Information about left and right will automatically be added to the details parameter, with keys left and right. If you use this function for assertions that compare numeric quantities, you may help Antithesis find more bugs. +func AlwaysGreaterThan[T Number](left, right T, message string, details map[string]any) { + loc := newLocationInfo(offsetAPICaller) + id := makeKey(message, loc) + condition := left > right + all_details := add_numeric_details(details, left, right) + assertImpl(condition, message, all_details, loc, wasHit, mustBeHit, universalTest, alwaysDisplay, id) + + numericGuidanceImpl(left, right, message, id, loc, guidanceFnMinimize, wasHit) +} + +// Equivalent to asserting Always(left >= right, message, details). Information about left and right will automatically be added to the details parameter, with keys left and right. If you use this function for assertions that compare numeric quantities, you may help Antithesis find more bugs. +func AlwaysGreaterThanOrEqualTo[T Number](left, right T, message string, details map[string]any) { + loc := newLocationInfo(offsetAPICaller) + id := makeKey(message, loc) + condition := left >= right + all_details := add_numeric_details(details, left, right) + assertImpl(condition, message, all_details, loc, wasHit, mustBeHit, universalTest, alwaysDisplay, id) + + numericGuidanceImpl(left, right, message, id, loc, guidanceFnMinimize, wasHit) +} + +// Equivalent to asserting Sometimes(T left > T right, message, details). Information about left and right will automatically be added to the details parameter, with keys left and right. If you use this function for assertions that compare numeric quantities, you may help Antithesis find more bugs. +func SometimesGreaterThan[T Number](left, right T, message string, details map[string]any) { + loc := newLocationInfo(offsetAPICaller) + id := makeKey(message, loc) + condition := left > right + all_details := add_numeric_details(details, left, right) + assertImpl(condition, message, all_details, loc, wasHit, mustBeHit, existentialTest, sometimesDisplay, id) + + numericGuidanceImpl(left, right, message, id, loc, guidanceFnMaximize, wasHit) +} + +// Equivalent to asserting Sometimes(T left >= T right, message, details). Information about left and right will automatically be added to the details parameter, with keys left and right. If you use this function for assertions that compare numeric quantities, you may help Antithesis find more bugs. +func SometimesGreaterThanOrEqualTo[T Number](left, right T, message string, details map[string]any) { + loc := newLocationInfo(offsetAPICaller) + id := makeKey(message, loc) + condition := left >= right + all_details := add_numeric_details(details, left, right) + assertImpl(condition, message, all_details, loc, wasHit, mustBeHit, existentialTest, sometimesDisplay, id) + + numericGuidanceImpl(left, right, message, id, loc, guidanceFnMaximize, wasHit) +} + +// Equivalent to asserting Always(left < right, message, details). Information about left and right will automatically be added to the details parameter, with keys left and right. If you use this function for assertions that compare numeric quantities, you may help Antithesis find more bugs. +func AlwaysLessThan[T Number](left, right T, message string, details map[string]any) { + loc := newLocationInfo(offsetAPICaller) + id := makeKey(message, loc) + condition := left < right + all_details := add_numeric_details(details, left, right) + assertImpl(condition, message, all_details, loc, wasHit, mustBeHit, universalTest, alwaysDisplay, id) + + numericGuidanceImpl(left, right, message, id, loc, guidanceFnMaximize, wasHit) +} + +// Equivalent to asserting Always(left <= right, message, details). Information about left and right will automatically be added to the details parameter, with keys left and right. If you use this function for assertions that compare numeric quantities, you may help Antithesis find more bugs. +func AlwaysLessThanOrEqualTo[T Number](left, right T, message string, details map[string]any) { + loc := newLocationInfo(offsetAPICaller) + id := makeKey(message, loc) + condition := left <= right + all_details := add_numeric_details(details, left, right) + assertImpl(condition, message, all_details, loc, wasHit, mustBeHit, universalTest, alwaysDisplay, id) + + numericGuidanceImpl(left, right, message, id, loc, guidanceFnMaximize, wasHit) +} + +// Equivalent to asserting Sometimes(T left < T right, message, details). Information about left and right will automatically be added to the details parameter, with keys left and right. If you use this function for assertions that compare numeric quantities, you may help Antithesis find more bugs. +func SometimesLessThan[T Number](left, right T, message string, details map[string]any) { + loc := newLocationInfo(offsetAPICaller) + id := makeKey(message, loc) + condition := left < right + all_details := add_numeric_details(details, left, right) + assertImpl(condition, message, all_details, loc, wasHit, mustBeHit, existentialTest, sometimesDisplay, id) + + numericGuidanceImpl(left, right, message, id, loc, guidanceFnMinimize, wasHit) +} + +// Equivalent to asserting Sometimes(T left <= T right, message, details). Information about left and right will automatically be added to the details parameter, with keys left and right. If you use this function for assertions that compare numeric quantities, you may help Antithesis find more bugs. +func SometimesLessThanOrEqualTo[T Number](left, right T, message string, details map[string]any) { + loc := newLocationInfo(offsetAPICaller) + id := makeKey(message, loc) + condition := left <= right + all_details := add_numeric_details(details, left, right) + assertImpl(condition, message, all_details, loc, wasHit, mustBeHit, existentialTest, sometimesDisplay, id) + + numericGuidanceImpl(left, right, message, id, loc, guidanceFnMinimize, wasHit) +} + +// Asserts that every time this is called, at least one bool in named_bools is true. Equivalent to Always(named_bools[0].second || named_bools[1].second || ..., message, details). If you use this for assertions about the behavior of booleans, you may help Antithesis find more bugs. Information about named_bools will automatically be added to the details parameter, and the keys will be the names of the bools. +func AlwaysSome(named_bools []NamedBool, message string, details map[string]any) { + loc := newLocationInfo(offsetAPICaller) + id := makeKey(message, loc) + disjunction := false + for _, named_bool := range named_bools { + if named_bool.Second { + disjunction = true + break + } + } + all_details := add_boolean_details(details, named_bools) + assertImpl(disjunction, message, all_details, loc, wasHit, mustBeHit, universalTest, alwaysDisplay, id) + + booleanGuidanceImpl(named_bools, message, id, loc, guidanceFnWantNone, wasHit) +} + +// Asserts that at least one time this is called, every bool in named_bools is true. Equivalent to Sometimes(named_bools[0].second && named_bools[1].second && ..., message, details). If you use this for assertions about the behavior of booleans, you may help Antithesis find more bugs. Information about named_bools will automatically be added to the details parameter, and the keys will be the names of the bools. +func SometimesAll(named_bools []NamedBool, message string, details map[string]any) { + loc := newLocationInfo(offsetAPICaller) + id := makeKey(message, loc) + conjunction := true + for _, named_bool := range named_bools { + if !named_bool.Second { + conjunction = false + break + } + } + all_details := add_boolean_details(details, named_bools) + assertImpl(conjunction, message, all_details, loc, wasHit, mustBeHit, existentialTest, sometimesDisplay, id) + + booleanGuidanceImpl(named_bools, message, id, loc, guidanceFnWantAll, wasHit) +} diff --git a/vendor/github.com/antithesishq/antithesis-sdk-go/assert/rich_assert_nop.go b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/rich_assert_nop.go new file mode 100644 index 0000000000..79ca12c92f --- /dev/null +++ b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/rich_assert_nop.go @@ -0,0 +1,34 @@ +//go:build !enable_antithesis_sdk + +package assert + +func AlwaysGreaterThan[T Number](left, right T, message string, details map[string]any) {} +func AlwaysGreaterThanOrEqualTo[T Number](left, right T, message string, details map[string]any) {} +func SometimesGreaterThan[T Number](left, right T, message string, details map[string]any) {} +func SometimesGreaterThanOrEqualTo[T Number](left, right T, message string, details map[string]any) {} +func AlwaysLessThan[T Number](left, right T, message string, details map[string]any) {} +func AlwaysLessThanOrEqualTo[T Number](left, right T, message string, details map[string]any) {} +func SometimesLessThan[T Number](left, right T, message string, details map[string]any) {} +func SometimesLessThanOrEqualTo[T Number](left, right T, message string, details map[string]any) {} + +func AlwaysSome(named_bool []NamedBool, message string, details map[string]any) {} +func SometimesAll(named_bool []NamedBool, message string, details map[string]any) {} + +func NumericGuidanceRaw[T Number](left, right T, + message, id string, + classname, funcname, filename string, + line int, + behavior string, + hit bool, +) { +} + +func BooleanGuidanceRaw( + named_bools []NamedBool, + message, id string, + classname, funcname, filename string, + line int, + behavior string, + hit bool, +) { +} diff --git a/vendor/github.com/antithesishq/antithesis-sdk-go/assert/tracker.go b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/tracker.go new file mode 100644 index 0000000000..c88497d363 --- /dev/null +++ b/vendor/github.com/antithesishq/antithesis-sdk-go/assert/tracker.go @@ -0,0 +1,111 @@ +//go:build enable_antithesis_sdk + +package assert + +import ( + "runtime" + "sync" + "sync/atomic" + + "github.com/antithesishq/antithesis-sdk-go/internal" +) + +type trackerInfo struct { + Filename string + Classname string + PassCount int + FailCount int +} + +type emitTracker map[string]*trackerInfo + +// assert_tracker (global) keeps track of the unique asserts evaluated +var ( + assertTracker emitTracker = make(emitTracker) + trackerMutex sync.Mutex + trackerInfoMutex sync.Mutex +) + +func (tracker emitTracker) getTrackerEntry(messageKey string, filename, classname string) *trackerInfo { + var trackerEntry *trackerInfo + var ok bool + + if tracker == nil { + return nil + } + + trackerMutex.Lock() + defer trackerMutex.Unlock() + if trackerEntry, ok = tracker[messageKey]; !ok { + trackerEntry = newTrackerInfo(filename, classname) + tracker[messageKey] = trackerEntry + } + return trackerEntry +} + +func newTrackerInfo(filename, classname string) *trackerInfo { + trackerInfo := trackerInfo{ + PassCount: 0, + FailCount: 0, + Filename: filename, + Classname: classname, + } + return &trackerInfo +} + +func (ti *trackerInfo) emit(ai *assertInfo) { + if ti == nil || ai == nil { + return + } + + // Registrations are just sent to voidstar + hit := ai.Hit + if !hit { + emitAssert(ai) + return + } + + var err error + cond := ai.Condition + + trackerInfoMutex.Lock() + defer trackerInfoMutex.Unlock() + if cond { + if ti.PassCount == 0 { + err = emitAssert(ai) + } + if err == nil { + ti.PassCount++ + } + return + } + if ti.FailCount == 0 { + err = emitAssert(ai) + } + if err == nil { + ti.FailCount++ + } +} + +func versionMessage() { + languageBlock := map[string]any{ + "name": "Go", + "version": runtime.Version(), + } + versionBlock := map[string]any{ + "language": languageBlock, + "sdk_version": internal.SDK_Version, + "protocol_version": internal.Protocol_Version, + } + internal.Json_data(map[string]any{"antithesis_sdk": versionBlock}) +} + +// package-level flag +var hasEmitted atomic.Bool // initialzed to false + +func emitAssert(ai *assertInfo) error { + if hasEmitted.CompareAndSwap(false, true) { + versionMessage() + } + return internal.Json_data(wrappedAssertInfo{ai}) +} diff --git a/vendor/github.com/antithesishq/antithesis-sdk-go/internal/emit.go b/vendor/github.com/antithesishq/antithesis-sdk-go/internal/emit.go new file mode 100644 index 0000000000..97967c2a9d --- /dev/null +++ b/vendor/github.com/antithesishq/antithesis-sdk-go/internal/emit.go @@ -0,0 +1,242 @@ +//go:build enable_antithesis_sdk + +package internal + +import ( + "encoding/json" + "fmt" + "log" + "math/rand" + "os" + "unsafe" +) + +// -------------------------------------------------------------------------------- +// To build and run an executable with this package +// +// CC=clang CGO_ENABLED=1 go run ./main.go +// -------------------------------------------------------------------------------- + +// \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ +// +// The commented lines below, and the `import "C"` line which must directly follow +// the commented lines are used by CGO. They are load-bearing, and should not be +// changed without first understanding how CGO uses them. +// +// \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ + +// #cgo LDFLAGS: -ldl +// +// #include +// #include +// #include +// #include +// +// typedef void (*go_fuzz_json_data_fn)(const char *data, size_t size); +// void +// go_fuzz_json_data(void *f, const char *data, size_t size) { +// ((go_fuzz_json_data_fn)f)(data, size); +// } +// +// typedef void (*go_fuzz_flush_fn)(void); +// void +// go_fuzz_flush(void *f) { +// ((go_fuzz_flush_fn)f)(); +// } +// +// typedef uint64_t (*go_fuzz_get_random_fn)(void); +// uint64_t +// go_fuzz_get_random(void *f) { +// return ((go_fuzz_get_random_fn)f)(); +// } +// +// typedef bool (*go_notify_coverage_fn)(size_t); +// int +// go_notify_coverage(void *f, size_t edges) { +// bool b = ((go_notify_coverage_fn)f)(edges); +// return b ? 1 : 0; +// } +// +// typedef uint64_t (*go_init_coverage_fn)(size_t num_edges, const char *symbols); +// uint64_t +// go_init_coverage(void *f, size_t num_edges, const char *symbols) { +// return ((go_init_coverage_fn)f)(num_edges, symbols); +// } +// +import "C" + +func Json_data(v any) error { + if data, err := json.Marshal(v); err != nil { + return err + } else { + handler.output(string(data)) + return nil + } +} + +func Get_random() uint64 { + return handler.random() +} + +func Notify(edge uint64) bool { + return handler.notify(edge) +} + +func InitCoverage(num_edges uint64, symbols string) uint64 { + return handler.init_coverage(num_edges, symbols) +} + +type libHandler interface { + output(message string) + random() uint64 + notify(edge uint64) bool + init_coverage(num_edges uint64, symbols string) uint64 +} + +const ( + errorLogLinePrefix = "[* antithesis-sdk-go *]" + defaultNativeLibraryPath = "/usr/lib/libvoidstar.so" +) + +var handler libHandler + +type voidstarHandler struct { + fuzzJsonData unsafe.Pointer + fuzzFlush unsafe.Pointer + fuzzGetRandom unsafe.Pointer + initCoverage unsafe.Pointer + notifyCoverage unsafe.Pointer +} + +func (h *voidstarHandler) output(message string) { + msg_len := len(message) + if msg_len == 0 { + return + } + cstrMessage := C.CString(message) + defer C.free(unsafe.Pointer(cstrMessage)) + C.go_fuzz_json_data(h.fuzzJsonData, cstrMessage, C.ulong(msg_len)) + C.go_fuzz_flush(h.fuzzFlush) +} + +func (h *voidstarHandler) random() uint64 { + return uint64(C.go_fuzz_get_random(h.fuzzGetRandom)) +} + +func (h *voidstarHandler) init_coverage(num_edge uint64, symbols string) uint64 { + cstrSymbols := C.CString(symbols) + defer C.free(unsafe.Pointer(cstrSymbols)) + return uint64(C.go_init_coverage(h.initCoverage, C.ulong(num_edge), cstrSymbols)) +} + +func (h *voidstarHandler) notify(edge uint64) bool { + ival := int(C.go_notify_coverage(h.notifyCoverage, C.ulong(edge))) + return ival == 1 +} + +type localHandler struct { + outputFile *os.File // can be nil +} + +func (h *localHandler) output(message string) { + msg_len := len(message) + if msg_len == 0 { + return + } + if h.outputFile != nil { + h.outputFile.WriteString(message + "\n") + } +} + +func (h *localHandler) random() uint64 { + return rand.Uint64() +} + +func (h *localHandler) notify(edge uint64) bool { + return false +} + +func (h *localHandler) init_coverage(num_edges uint64, symbols string) uint64 { + return 0 +} + +// If we have a file at `defaultNativeLibraryPath`, we load the shared library +// (and panic on any error encountered during load). +// Otherwise fallback to the local handler. +func init() { + if _, err := os.Stat(defaultNativeLibraryPath); err == nil { + if handler, err = openSharedLib(defaultNativeLibraryPath); err != nil { + panic(err) + } + return + } + handler = openLocalHandler() +} + +// Attempt to load libvoidstar and some symbols from `path` +func openSharedLib(path string) (*voidstarHandler, error) { + cstrPath := C.CString(path) + defer C.free(unsafe.Pointer(cstrPath)) + + dlError := func(message string) error { + return fmt.Errorf("%s: (%s)", message, C.GoString(C.dlerror())) + } + + sharedLib := C.dlopen(cstrPath, C.int(C.RTLD_NOW)) + if sharedLib == nil { + return nil, dlError("Can not load the Antithesis native library") + } + + loadFunc := func(name string) (symbol unsafe.Pointer, err error) { + cstrName := C.CString(name) + defer C.free(unsafe.Pointer(cstrName)) + if symbol = C.dlsym(sharedLib, cstrName); symbol == nil { + err = dlError(fmt.Sprintf("Can not access symbol %s", name)) + } + return + } + + fuzzJsonData, err := loadFunc("fuzz_json_data") + if err != nil { + return nil, err + } + fuzzFlush, err := loadFunc("fuzz_flush") + if err != nil { + return nil, err + } + fuzzGetRandom, err := loadFunc("fuzz_get_random") + if err != nil { + return nil, err + } + notifyCoverage, err := loadFunc("notify_coverage") + if err != nil { + return nil, err + } + initCoverage, err := loadFunc("init_coverage_module") + if err != nil { + return nil, err + } + return &voidstarHandler{fuzzJsonData, fuzzFlush, fuzzGetRandom, initCoverage, notifyCoverage}, nil +} + +// If `localOutputEnvVar` is set to a non-empty path, attempt to open that path and truncate the file +// to serve as the log file of the local handler. +// Otherwise, we don't have a log file, and logging is a no-op in the local handler. +func openLocalHandler() *localHandler { + path, is_set := os.LookupEnv(localOutputEnvVar) + if !is_set || len(path) == 0 { + return &localHandler{nil} + } + + // Open the file R/W (create if needed and possible) + file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644) + if err != nil { + log.Printf("%s Failed to open path %s: %v", errorLogLinePrefix, path, err) + file = nil + } else if err = file.Truncate(0); err != nil { + log.Printf("%s Failed to truncate file at %s: %v", errorLogLinePrefix, path, err) + file = nil + } + + return &localHandler{file} +} diff --git a/vendor/github.com/antithesishq/antithesis-sdk-go/internal/sdk_const.go b/vendor/github.com/antithesishq/antithesis-sdk-go/internal/sdk_const.go new file mode 100644 index 0000000000..939582573e --- /dev/null +++ b/vendor/github.com/antithesishq/antithesis-sdk-go/internal/sdk_const.go @@ -0,0 +1,12 @@ +package internal + +// -------------------------------------------------------------------------------- +// Versions +// -------------------------------------------------------------------------------- +const SDK_Version = "0.4.3" +const Protocol_Version = "1.1.0" + +// -------------------------------------------------------------------------------- +// Environment Vars +// -------------------------------------------------------------------------------- +const localOutputEnvVar = "ANTITHESIS_SDK_LOCAL_OUTPUT" diff --git a/vendor/github.com/nats-io/nats-server/v2/server/accounts.go b/vendor/github.com/nats-io/nats-server/v2/server/accounts.go index 5b84b3b8b6..55bd077474 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/accounts.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/accounts.go @@ -378,6 +378,21 @@ func (a *Account) getClients() []*client { return clients } +// Returns a slice of external (non-internal) clients stored in the account, or nil if none is present. +// Lock is held on entry. +func (a *Account) getExternalClientsLocked() []*client { + if len(a.clients) == 0 { + return nil + } + var clients []*client + for c := range a.clients { + if !isInternalClient(c.kind) { + clients = append(clients, c) + } + } + return clients +} + // Called to track a remote server and connections and leafnodes it // has for this account. func (a *Account) updateRemoteServer(m *AccountNumConns) []*client { @@ -398,8 +413,10 @@ func (a *Account) updateRemoteServer(m *AccountNumConns) []*client { // conservative and bit harsh here. Clients will reconnect if we over compensate. var clients []*client if mtce { - clients = a.getClientsLocked() - slices.SortFunc(clients, func(i, j *client) int { return -i.start.Compare(j.start) }) // reserve + clients = a.getExternalClientsLocked() + + // Sort in reverse chronological. + slices.SortFunc(clients, func(i, j *client) int { return -i.start.Compare(j.start) }) over := (len(a.clients) - int(a.sysclients) + int(a.nrclients)) - int(a.mconns) if over < len(clients) { clients = clients[:over] @@ -3769,9 +3786,9 @@ func (s *Server) updateAccountClaimsWithRefresh(a *Account, ac *jwt.AccountClaim ajs := a.js a.mu.Unlock() - // Sort if we are over the limit. + // Sort in chronological order so that most recent connections over the limit are pruned. if a.MaxTotalConnectionsReached() { - slices.SortFunc(clients, func(i, j *client) int { return -i.start.Compare(j.start) }) // sort in reverse order + slices.SortFunc(clients, func(i, j *client) int { return i.start.Compare(j.start) }) } // If JetStream is enabled for this server we will call into configJetStream for the account @@ -3783,6 +3800,11 @@ func (s *Server) updateAccountClaimsWithRefresh(a *Account, ac *jwt.AccountClaim // Absent reload of js server cfg, this is going to be broken until js is disabled a.incomplete = true a.mu.Unlock() + } else { + a.mu.Lock() + // Refresh reference, we've just enabled JetStream, so it would have been nil before. + ajs = a.js + a.mu.Unlock() } } else if a.jsLimits != nil { // We do not have JS enabled for this server, but the account has it enabled so setup @@ -3811,6 +3833,7 @@ func (s *Server) updateAccountClaimsWithRefresh(a *Account, ac *jwt.AccountClaim } } + // client list is in chronological order (older cids at the beginning of the list). count := 0 for _, c := range clients { a.mu.RLock() diff --git a/vendor/github.com/nats-io/nats-server/v2/server/auth_callout.go b/vendor/github.com/nats-io/nats-server/v2/server/auth_callout.go index cc9e8db811..038d53bb3f 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/auth_callout.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/auth_callout.go @@ -403,7 +403,7 @@ func (s *Server) processClientOrLeafCallout(c *client, opts *Options) (authorize return false, errStr } req := []byte(b) - var hdr map[string]string + var hdr []byte // Check if we have been asked to encrypt. if xkp != nil { @@ -413,7 +413,7 @@ func (s *Server) processClientOrLeafCallout(c *client, opts *Options) (authorize s.Warnf(errStr) return false, errStr } - hdr = map[string]string{AuthRequestXKeyHeader: xkey} + hdr = genHeader(hdr, AuthRequestXKeyHeader, xkey) } // Send out our request. diff --git a/vendor/github.com/nats-io/nats-server/v2/server/certidp/ocsp_responder.go b/vendor/github.com/nats-io/nats-server/v2/server/certidp/ocsp_responder.go index ad6c2651bc..ea2b614ed6 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/certidp/ocsp_responder.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/certidp/ocsp_responder.go @@ -19,6 +19,7 @@ import ( "fmt" "io" "net/http" + "net/url" "strings" "time" @@ -55,7 +56,7 @@ func FetchOCSPResponse(link *ChainLink, opts *OCSPPeerConfig, log *Log) ([]byte, return nil, err } - reqEnc := base64.StdEncoding.EncodeToString(reqDER) + reqEnc := encodeOCSPRequest(reqDER) responders := *link.OCSPWebEndpoints @@ -68,10 +69,10 @@ func FetchOCSPResponse(link *ChainLink, opts *OCSPPeerConfig, log *Log) ([]byte, Timeout: timeout, } for _, u := range responders { - url := u.String() - log.Debugf(DbgMakingCARequest, url) - url = strings.TrimSuffix(url, "/") - raw, err = getRequestBytes(fmt.Sprintf("%s/%s", url, reqEnc), hc) + responderURL := u.String() + log.Debugf(DbgMakingCARequest, responderURL) + responderURL = strings.TrimSuffix(responderURL, "/") + raw, err = getRequestBytes(fmt.Sprintf("%s/%s", responderURL, reqEnc), hc) if err == nil { break } @@ -82,3 +83,10 @@ func FetchOCSPResponse(link *ChainLink, opts *OCSPPeerConfig, log *Log) ([]byte, return raw, nil } + +// encodeOCSPRequest encodes the OCSP request in base64 and URL-encodes it. +// This is needed to fulfill the OCSP responder's requirements for the request format. (X.690) +func encodeOCSPRequest(reqDER []byte) string { + reqEnc := base64.StdEncoding.EncodeToString(reqDER) + return url.QueryEscape(reqEnc) +} diff --git a/vendor/github.com/nats-io/nats-server/v2/server/client.go b/vendor/github.com/nats-io/nats-server/v2/server/client.go index c12834bc0a..bad079d345 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/client.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/client.go @@ -152,6 +152,7 @@ const ( compressionNegotiated // Marks if this connection has negotiated compression level with remote. didTLSFirst // Marks if this connection requested and was accepted doing the TLS handshake first (prior to INFO). isSlowConsumer // Marks connection as a slow consumer. + firstPong // Marks if this is the first PONG received ) // set the flag (would be equivalent to set the boolean to true) @@ -2563,6 +2564,14 @@ func (c *client) processPong() { c.rtt = computeRTT(c.rttStart) srv := c.srv reorderGWs := c.kind == GATEWAY && c.gw.outbound + firstPong := c.flags.setIfNotSet(firstPong) + var ri *routeInfo + // When receiving the first PONG, for a route with pooling, we may be + // instructed to start a new route. + if firstPong && c.kind == ROUTER && c.route != nil { + ri = c.route.startNewRoute + c.route.startNewRoute = nil + } // If compression is currently active for a route/leaf connection, if the // compression configuration is s2_auto, check if we should change // the compression level. @@ -2581,6 +2590,11 @@ func (c *client) processPong() { if reorderGWs { srv.gateway.orderOutboundConnections() } + if ri != nil { + srv.startGoRoutine(func() { + srv.connectToRoute(ri.url, ri.rtype, true, ri.gossipMode, _EMPTY_) + }) + } } // Select the s2 compression level based on the client's current RTT and the configured @@ -3084,6 +3098,13 @@ func (c *client) addShadowSub(sub *subscription, ime *ime, enact bool) (*subscri // Update our route map here. But only if we are not a leaf node or a hub leafnode. if c.kind != LEAF || c.isHubLeafNode() { c.srv.updateRemoteSubscription(im.acc, &nsub, 1) + } else if c.kind == LEAF { + // Update all leafnodes that connect to this server. Note that we could have + // used the updateLeafNodes() function since when it does invoke updateSmap() + // this function already takes care of not sending to a spoke leafnode since + // the `nsub` here is already from a spoke leafnode, but to be explicit, we + // use this version that updates only leafnodes that connect to this server. + im.acc.updateLeafNodesEx(&nsub, 1, true) } return &nsub, nil @@ -3192,14 +3213,12 @@ func (c *client) unsubscribe(acc *Account, sub *subscription, force, remove bool // Check to see if we have shadow subscriptions. var updateRoute bool - var updateGWs bool + var isSpokeLeaf bool shadowSubs := sub.shadow sub.shadow = nil if len(shadowSubs) > 0 { - updateRoute = (c.kind == CLIENT || c.kind == SYSTEM || c.kind == LEAF) && c.srv != nil - if updateRoute { - updateGWs = c.srv.gateway.enabled - } + isSpokeLeaf = c.isSpokeLeafNode() + updateRoute = !isSpokeLeaf && (c.kind == CLIENT || c.kind == SYSTEM || c.kind == LEAF) && c.srv != nil } sub.close() c.mu.Unlock() @@ -3208,16 +3227,12 @@ func (c *client) unsubscribe(acc *Account, sub *subscription, force, remove bool for _, nsub := range shadowSubs { if err := nsub.im.acc.sl.Remove(nsub); err != nil { c.Debugf("Could not remove shadow import subscription for account %q", nsub.im.acc.Name) - } else { - if updateRoute { - c.srv.updateRouteSubscriptionMap(nsub.im.acc, nsub, -1) - } - if updateGWs { - c.srv.gatewayUpdateSubInterest(nsub.im.acc.Name, nsub, -1) - } } - // Now check on leafnode updates. - nsub.im.acc.updateLeafNodes(nsub, -1) + if updateRoute { + c.srv.updateRemoteSubscription(nsub.im.acc, nsub, -1) + } else if isSpokeLeaf { + nsub.im.acc.updateLeafNodesEx(nsub, -1, true) + } } // Now check to see if this was part of a respMap entry for service imports. diff --git a/vendor/github.com/nats-io/nats-server/v2/server/const.go b/vendor/github.com/nats-io/nats-server/v2/server/const.go index c7e09f3577..a5a61c26ff 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/const.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/const.go @@ -43,6 +43,14 @@ var ( semVerRe = regexp.MustCompile(`^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`) ) +// formatRevision formats a VCS revision string for display. +func formatRevision(revision string) string { + if len(revision) >= 7 { + return revision[:7] + } + return revision +} + func init() { // Use build info if present, it would be if building using 'go build .' // or when using a release. @@ -50,7 +58,7 @@ func init() { for _, setting := range info.Settings { switch setting.Key { case "vcs.revision": - gitCommit = setting.Value[:7] + gitCommit = formatRevision(setting.Value) } } } @@ -58,7 +66,7 @@ func init() { const ( // VERSION is the current version for the server. - VERSION = "2.11.8" + VERSION = "2.11.9" // PROTO is the currently supported protocol. // 0 was the original diff --git a/vendor/github.com/nats-io/nats-server/v2/server/consumer.go b/vendor/github.com/nats-io/nats-server/v2/server/consumer.go index 7e7977a5b9..e945bb517f 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/consumer.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/consumer.go @@ -20,6 +20,8 @@ import ( "errors" "fmt" "math/rand" + "os" + "path/filepath" "reflect" "regexp" "slices" @@ -70,6 +72,13 @@ type ConsumerInfo struct { PriorityGroups []PriorityGroupState `json:"priority_groups,omitempty"` } +// consumerInfoClusterResponse is a response used in a cluster to communicate the consumer info +// back to the meta leader as part of a consumer list request. +type consumerInfoClusterResponse struct { + ConsumerInfo + OfflineReason string `json:"offline_reason,omitempty"` // Reporting when a consumer is offline. +} + type PriorityGroupState struct { Group string `json:"group"` PinnedClientID string `json:"pinned_client_id,omitempty"` @@ -452,6 +461,7 @@ type consumer struct { dthresh time.Duration mch chan struct{} // Message channel qch chan struct{} // Quit channel + mqch chan struct{} // The monitor's quit channel. inch chan bool // Interest change channel sfreq int32 ackEventT string @@ -497,6 +507,10 @@ type consumer struct { /// pinnedTtl is the remaining time before the current PinId expires. pinnedTtl *time.Timer pinnedTS time.Time + + // If standalone/single-server, the offline reason needs to be stored directly in the consumer. + // Otherwise, if clustered it will be part of the consumer assignment. + offlineReason string } // A single subject filter. @@ -1021,10 +1035,11 @@ func (mset *stream) addConsumerWithAssignment(config *ConsumerConfig, oname stri outq: mset.outq, active: true, qch: make(chan struct{}), + mqch: make(chan struct{}), uch: make(chan struct{}, 1), mch: make(chan struct{}, 1), sfreq: int32(sampleFreq), - maxdc: uint64(config.MaxDeliver), + maxdc: uint64(max(config.MaxDeliver, 0)), // MaxDeliver is negative (-1) when infinite. maxp: config.MaxAckPending, retention: cfg.Retention, created: time.Now().UTC(), @@ -1285,6 +1300,26 @@ func (o *consumer) setConsumerAssignment(ca *consumerAssignment) { } } +func (o *consumer) monitorQuitC() <-chan struct{} { + if o == nil { + return nil + } + o.mu.RLock() + defer o.mu.RUnlock() + return o.mqch +} + +// signalMonitorQuit signals to exit the monitor loop. If there's no Raft node, +// this will be the only way to stop the monitor goroutine. +func (o *consumer) signalMonitorQuit() { + o.mu.Lock() + defer o.mu.Unlock() + if o.mqch != nil { + close(o.mqch) + o.mqch = nil + } +} + func (o *consumer) updateC() <-chan struct{} { o.mu.RLock() defer o.mu.RUnlock() @@ -2239,7 +2274,8 @@ func (o *consumer) updateConfig(cfg *ConsumerConfig) error { } // Set MaxDeliver if changed if cfg.MaxDeliver != o.cfg.MaxDeliver { - o.maxdc = uint64(cfg.MaxDeliver) + // MaxDeliver is negative (-1) when infinite. + o.maxdc = uint64(max(cfg.MaxDeliver, 0)) } // Set InactiveThreshold if changed. if val := cfg.InactiveThreshold; val != o.cfg.InactiveThreshold { @@ -4836,7 +4872,7 @@ func (o *consumer) setMaxPendingBytes(limit int) { // This does some quick sanity checks to see if we should re-calculate num pending. // Lock should be held. func (o *consumer) checkNumPending() uint64 { - if o.mset != nil { + if o.mset != nil && o.mset.store != nil { var state StreamState o.mset.store.FastState(&state) npc := o.numPending() @@ -5758,6 +5794,13 @@ func (o *consumer) stopWithFlags(dflag, sdflag, doSignal, advisory bool) error { } o.closed = true + // Signal to the monitor loop. + // Can't use only qch here, since that's used when stepping down as a leader. + if o.mqch != nil { + close(o.mqch) + o.mqch = nil + } + // Check if we are the leader and are being deleted (as a node). if dflag && o.isLeader() { // If we are clustered and node leader (probable from above), stepdown. @@ -5880,6 +5923,14 @@ func (o *consumer) stopWithFlags(dflag, sdflag, doSignal, advisory bool) error { } else { err = store.Stop() } + } else if dflag { + // If there's no store (for example, when it's offline), manually delete the directories. + o.mu.RLock() + stream, consumer := o.stream, o.name + o.mu.RUnlock() + accDir := filepath.Join(js.config.StoreDir, a.GetName()) + consumersDir := filepath.Join(accDir, streamsDir, stream, consumerDir) + os.RemoveAll(filepath.Join(consumersDir, consumer)) } return err diff --git a/vendor/github.com/nats-io/nats-server/v2/server/errors.json b/vendor/github.com/nats-io/nats-server/v2/server/errors.json index 3a80cc4d64..a9eaf3be68 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/errors.json +++ b/vendor/github.com/nats-io/nats-server/v2/server/errors.json @@ -1668,5 +1668,25 @@ "help": "", "url": "", "deprecates": "" + }, + { + "constant": "JSStreamOfflineReasonErrF", + "code": 500, + "error_code": 10194, + "description": "stream is offline: {err}", + "comment": "", + "help": "", + "url": "", + "deprecates": "" + }, + { + "constant": "JSConsumerOfflineReasonErrF", + "code": 500, + "error_code": 10195, + "description": "consumer is offline: {err}", + "comment": "", + "help": "", + "url": "", + "deprecates": "" } ] diff --git a/vendor/github.com/nats-io/nats-server/v2/server/events.go b/vendor/github.com/nats-io/nats-server/v2/server/events.go index 53400b9f5c..c22cbe3a57 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/events.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/events.go @@ -419,7 +419,7 @@ type pubMsg struct { sub string rply string si *ServerInfo - hdr map[string]string + hdr []byte msg any oct compressionType echo bool @@ -428,7 +428,7 @@ type pubMsg struct { var pubMsgPool sync.Pool -func newPubMsg(c *client, sub, rply string, si *ServerInfo, hdr map[string]string, +func newPubMsg(c *client, sub, rply string, si *ServerInfo, hdr []byte, msg any, oct compressionType, echo, last bool) *pubMsg { var m *pubMsg @@ -601,17 +601,28 @@ RESET: // Add in NL b = append(b, _CRLF_...) + // Optional raw header addition. + if pm.hdr != nil { + b = append(pm.hdr, b...) + nhdr := len(pm.hdr) + nsize := len(b) - LEN_CR_LF + // MQTT producers don't have CRLF, so add it back. + if c.isMqtt() { + nsize += LEN_CR_LF + } + // Update pubArgs + // If others will use this later we need to save and restore original. + c.pa.hdr = nhdr + c.pa.size = nsize + c.pa.hdb = []byte(strconv.Itoa(nhdr)) + c.pa.szb = []byte(strconv.Itoa(nsize)) + } + // Check if we should set content-encoding if contentHeader != _EMPTY_ { b = c.setHeader(contentEncodingHeader, contentHeader, b) } - // Optional header processing. - if pm.hdr != nil { - for k, v := range pm.hdr { - b = c.setHeader(k, v, b) - } - } // Tracing if trace { c.traceInOp(fmt.Sprintf("PUB %s %s %d", c.pa.subject, c.pa.reply, c.pa.size), nil) @@ -688,7 +699,7 @@ func (s *Server) sendInternalAccountMsg(a *Account, subject string, msg any) err } // Used to send an internal message with an optional reply to an arbitrary account. -func (s *Server) sendInternalAccountMsgWithReply(a *Account, subject, reply string, hdr map[string]string, msg any, echo bool) error { +func (s *Server) sendInternalAccountMsgWithReply(a *Account, subject, reply string, hdr []byte, msg any, echo bool) error { s.mu.RLock() if s.sys == nil || s.sys.sendq == nil { s.mu.RUnlock() diff --git a/vendor/github.com/nats-io/nats-server/v2/server/jetstream.go b/vendor/github.com/nats-io/nats-server/v2/server/jetstream.go index c119da6333..d676f64022 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/jetstream.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/jetstream.go @@ -14,6 +14,7 @@ package server import ( + "bytes" "crypto/hmac" "crypto/sha256" "encoding/binary" @@ -1333,8 +1334,54 @@ func (a *Account) EnableJetStream(limits map[string]JetStreamAccountLimits) erro } var cfg FileStreamInfo - if err := json.Unmarshal(buf, &cfg); err != nil { - s.Warnf(" Error unmarshalling stream metafile %q: %v", metafile, err) + decoder := json.NewDecoder(bytes.NewReader(buf)) + decoder.DisallowUnknownFields() + strictErr := decoder.Decode(&cfg) + if strictErr != nil { + cfg = FileStreamInfo{} + if err := json.Unmarshal(buf, &cfg); err != nil { + s.Warnf(" Error unmarshalling stream metafile %q: %v", metafile, err) + continue + } + } + if supported := supportsRequiredApiLevel(cfg.Metadata); !supported || strictErr != nil { + var offlineReason string + if !supported { + apiLevel := getRequiredApiLevel(cfg.Metadata) + offlineReason = fmt.Sprintf("unsupported - required API level: %s, current API level: %d", apiLevel, JSApiLevel) + s.Warnf(" Detected unsupported stream '%s > %s', delete the stream or upgrade the server to API level %s", a.Name, cfg.StreamConfig.Name, apiLevel) + } else { + offlineReason = fmt.Sprintf("decoding error: %v", strictErr) + s.Warnf(" Error unmarshalling stream metafile %q: %v", metafile, strictErr) + } + singleServerMode := !s.JetStreamIsClustered() && s.standAloneMode() + if singleServerMode { + // Fake a stream, so we can respond to API requests as single-server. + mset := &stream{ + acc: a, + jsa: jsa, + cfg: cfg.StreamConfig, + js: js, + srv: s, + stype: cfg.Storage, + consumers: make(map[string]*consumer), + active: false, + created: time.Now().UTC(), + offlineReason: offlineReason, + } + if !cfg.Created.IsZero() { + mset.created = cfg.Created + } + mset.closed.Store(true) + + jsa.mu.Lock() + jsa.streams[cfg.Name] = mset + jsa.mu.Unlock() + + // Now do the consumers. + odir := filepath.Join(sdir, fi.Name(), consumerDir) + consumers = append(consumers, &ce{mset, odir}) + } continue } @@ -1455,13 +1502,66 @@ func (a *Account) EnableJetStream(limits map[string]JetStreamAccountLimits) erro } var cfg FileConsumerInfo - if err := json.Unmarshal(buf, &cfg); err != nil { - s.Warnf(" Error unmarshalling consumer metafile %q: %v", metafile, err) + decoder := json.NewDecoder(bytes.NewReader(buf)) + decoder.DisallowUnknownFields() + strictErr := decoder.Decode(&cfg) + if strictErr != nil { + cfg = FileConsumerInfo{} + if err := json.Unmarshal(buf, &cfg); err != nil { + s.Warnf(" Error unmarshalling consumer metafile %q: %v", metafile, err) + continue + } + } + if supported := supportsRequiredApiLevel(cfg.Metadata); !supported || strictErr != nil { + var offlineReason string + if !supported { + apiLevel := getRequiredApiLevel(cfg.Metadata) + offlineReason = fmt.Sprintf("unsupported - required API level: %s, current API level: %d", apiLevel, JSApiLevel) + s.Warnf(" Detected unsupported consumer '%s > %s > %s', delete the consumer or upgrade the server to API level %s", a.Name, e.mset.name(), cfg.Name, apiLevel) + } else { + offlineReason = fmt.Sprintf("decoding error: %v", strictErr) + s.Warnf(" Error unmarshalling consumer metafile %q: %v", metafile, strictErr) + } + singleServerMode := !s.JetStreamIsClustered() && s.standAloneMode() + if singleServerMode { + if !e.mset.closed.Load() { + s.Warnf(" Stopping unsupported stream '%s > %s'", a.Name, e.mset.name()) + e.mset.mu.Lock() + e.mset.offlineReason = "stopped" + e.mset.mu.Unlock() + e.mset.stop(false, false) + } + + // Fake a consumer, so we can respond to API requests as single-server. + o := &consumer{ + mset: e.mset, + js: s.getJetStream(), + acc: a, + srv: s, + cfg: cfg.ConsumerConfig, + active: false, + stream: e.mset.name(), + name: cfg.Name, + dseq: 1, + sseq: 1, + created: time.Now().UTC(), + closed: true, + offlineReason: offlineReason, + } + if !cfg.Created.IsZero() { + o.created = cfg.Created + } + + e.mset.mu.Lock() + e.mset.setConsumer(o) + e.mset.mu.Unlock() + } continue } + isEphemeral := !isDurableConsumer(&cfg.ConsumerConfig) if isEphemeral { - // This is an ephermal consumer and this could fail on restart until + // This is an ephemeral consumer and this could fail on restart until // the consumer can reconnect. We will create it as a durable and switch it. cfg.ConsumerConfig.Durable = ofi.Name() } diff --git a/vendor/github.com/nats-io/nats-server/v2/server/jetstream_api.go b/vendor/github.com/nats-io/nats-server/v2/server/jetstream_api.go index 555678a8f0..66145181d3 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/jetstream_api.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/jetstream_api.go @@ -485,8 +485,9 @@ type JSApiStreamListRequest struct { type JSApiStreamListResponse struct { ApiResponse ApiPaged - Streams []*StreamInfo `json:"streams"` - Missing []string `json:"missing,omitempty"` + Streams []*StreamInfo `json:"streams"` + Missing []string `json:"missing,omitempty"` + Offline map[string]string `json:"offline,omitempty"` } const JSApiStreamListResponseType = "io.nats.jetstream.api.v1.stream_list_response" @@ -747,8 +748,9 @@ const JSApiConsumerNamesResponseType = "io.nats.jetstream.api.v1.consumer_names_ type JSApiConsumerListResponse struct { ApiResponse ApiPaged - Consumers []*ConsumerInfo `json:"consumers"` - Missing []string `json:"missing,omitempty"` + Consumers []*ConsumerInfo `json:"consumers"` + Missing []string `json:"missing,omitempty"` + Offline map[string]string `json:"offline,omitempty"` } const JSApiConsumerListResponseType = "io.nats.jetstream.api.v1.consumer_list_response" @@ -1042,9 +1044,11 @@ type delayedAPIResponse struct { subject string reply string request string + hdr []byte response string rg *raftGroup deadline time.Time + noJs bool next *delayedAPIResponse } @@ -1147,7 +1151,12 @@ func (s *Server) delayedAPIResponder() { next() case <-tm.C: if r != nil { - s.sendAPIErrResponse(r.ci, r.acc, r.subject, r.reply, r.request, r.response) + // If it's not a JS API error, send it as a raw response without additional API/audit tracking. + if r.noJs { + s.sendInternalAccountMsgWithReply(r.acc, r.subject, _EMPTY_, r.hdr, r.response, false) + } else { + s.sendAPIErrResponse(r.ci, r.acc, r.subject, r.reply, r.request, r.response) + } pop() } next() @@ -1157,7 +1166,13 @@ func (s *Server) delayedAPIResponder() { func (s *Server) sendDelayedAPIErrResponse(ci *ClientInfo, acc *Account, subject, reply, request, response string, rg *raftGroup, duration time.Duration) { s.delayedAPIResponses.push(&delayedAPIResponse{ - ci, acc, subject, reply, request, response, rg, time.Now().Add(duration), nil, + ci, acc, subject, reply, request, nil, response, rg, time.Now().Add(duration), false, nil, + }) +} + +func (s *Server) sendDelayedErrResponse(acc *Account, subject string, hdr []byte, response string, duration time.Duration) { + s.delayedAPIResponses.push(&delayedAPIResponse{ + nil, acc, subject, _EMPTY_, _EMPTY_, hdr, response, nil, time.Now().Add(duration), true, nil, }) } @@ -1727,6 +1742,11 @@ func (s *Server) jsStreamUpdateRequest(sub *subscription, c *client, _ *Account, s.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp)) return } + if mset.offlineReason != _EMPTY_ { + resp.Error = NewJSStreamOfflineReasonError(errors.New(mset.offlineReason)) + s.sendDelayedAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp), nil, errRespDelay) + return + } // Update asset version metadata. setStaticStreamMetadata(&cfg) @@ -1958,7 +1978,17 @@ func (s *Server) jsStreamListRequest(sub *subscription, c *client, _ *Account, s offset = scnt } + var missingNames []string for _, mset := range msets[offset:] { + if mset.offlineReason != _EMPTY_ { + if resp.Offline == nil { + resp.Offline = make(map[string]string, 1) + } + resp.Offline[mset.getCfgName()] = mset.offlineReason + missingNames = append(missingNames, mset.getCfgName()) + continue + } + config := mset.config() resp.Streams = append(resp.Streams, &StreamInfo{ Created: mset.createdTime(), @@ -1976,6 +2006,7 @@ func (s *Server) jsStreamListRequest(sub *subscription, c *client, _ *Account, s resp.Total = scnt resp.Limit = JSApiListLimit resp.Offset = offset + resp.Missing = missingNames s.sendAPIResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(resp)) } @@ -2015,6 +2046,13 @@ func (s *Server) jsStreamInfoRequest(sub *subscription, c *client, a *Account, s if sa != nil { clusterWideConsCount = len(sa.consumers) offline = s.allPeersOffline(sa.Group) + if sa.unsupported != nil && sa.Group != nil && cc.meta != nil && sa.Group.isMember(cc.meta.ID()) { + // If we're a member for this stream, and it's not supported, report it as offline. + resp.Error = NewJSStreamOfflineReasonError(errors.New(sa.unsupported.reason)) + s.sendDelayedAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp), nil, errRespDelay) + js.mu.RUnlock() + return + } } js.mu.RUnlock() @@ -2120,6 +2158,12 @@ func (s *Server) jsStreamInfoRequest(sub *subscription, c *client, a *Account, s } } + if mset.offlineReason != _EMPTY_ { + resp.Error = NewJSStreamOfflineReasonError(errors.New(mset.offlineReason)) + s.sendDelayedAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp), nil, errRespDelay) + return + } + config := mset.config() resp.StreamInfo = &StreamInfo{ Created: mset.createdTime(), @@ -3447,6 +3491,10 @@ func (s *Server) jsMsgGetRequest(sub *subscription, c *client, _ *Account, subje s.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp)) return } + if mset.offlineReason != _EMPTY_ { + // Just let the request time out. + return + } var svp StoreMsg var sm *StoreMsg @@ -3533,6 +3581,11 @@ func (s *Server) jsConsumerUnpinRequest(sub *subscription, c *client, _ *Account s.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp)) return } + if sa.unsupported != nil { + js.mu.RUnlock() + // Just let the request time out. + return + } ca, ok := sa.consumers[consumer] if !ok || ca == nil { @@ -3541,6 +3594,11 @@ func (s *Server) jsConsumerUnpinRequest(sub *subscription, c *client, _ *Account s.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp)) return } + if ca.unsupported != nil { + js.mu.RUnlock() + // Just let the request time out. + return + } js.mu.RUnlock() // Then check if we are the leader. @@ -3572,12 +3630,20 @@ func (s *Server) jsConsumerUnpinRequest(sub *subscription, c *client, _ *Account s.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp)) return } + if mset.offlineReason != _EMPTY_ { + // Just let the request time out. + return + } o := mset.lookupConsumer(consumer) if o == nil { resp.Error = NewJSConsumerNotFoundError() s.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp)) return } + if o.offlineReason != _EMPTY_ { + // Just let the request time out. + return + } var foundPriority bool for _, group := range o.config().PriorityGroups { @@ -4437,11 +4503,23 @@ func (s *Server) jsConsumerCreateRequest(sub *subscription, c *client, a *Accoun s.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp)) return } + if stream.offlineReason != _EMPTY_ { + resp.Error = NewJSStreamOfflineReasonError(errors.New(stream.offlineReason)) + s.sendDelayedAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp), nil, errRespDelay) + return + } if o := stream.lookupConsumer(consumerName); o != nil { + if o.offlineReason != _EMPTY_ { + resp.Error = NewJSConsumerOfflineReasonError(errors.New(o.offlineReason)) + s.sendDelayedAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp), nil, errRespDelay) + return + } // If the consumer already exists then don't allow updating the PauseUntil, just set // it back to whatever the current configured value is. + o.mu.RLock() req.Config.PauseUntil = o.cfg.PauseUntil + o.mu.RUnlock() } // Initialize/update asset version metadata. @@ -4462,9 +4540,11 @@ func (s *Server) jsConsumerCreateRequest(sub *subscription, c *client, a *Accoun resp.ConsumerInfo = setDynamicConsumerInfoMetadata(o.initialInfo()) s.sendAPIResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(resp)) + o.mu.RLock() if o.cfg.PauseUntil != nil && !o.cfg.PauseUntil.IsZero() && time.Now().Before(*o.cfg.PauseUntil) { o.sendPauseAdvisoryLocked(&o.cfg) } + o.mu.RUnlock() } // Request for the list of all consumer names. @@ -4668,7 +4748,16 @@ func (s *Server) jsConsumerListRequest(sub *subscription, c *client, _ *Account, offset = ocnt } + var missingNames []string for _, o := range obs[offset:] { + if o.offlineReason != _EMPTY_ { + if resp.Offline == nil { + resp.Offline = make(map[string]string, 1) + } + resp.Offline[o.name] = o.offlineReason + missingNames = append(missingNames, o.name) + continue + } if cinfo := o.info(); cinfo != nil { resp.Consumers = append(resp.Consumers, cinfo) } @@ -4679,6 +4768,7 @@ func (s *Server) jsConsumerListRequest(sub *subscription, c *client, _ *Account, resp.Total = ocnt resp.Limit = JSApiListLimit resp.Offset = offset + resp.Missing = missingNames s.sendAPIResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(resp)) } @@ -4730,6 +4820,13 @@ func (s *Server) jsConsumerInfoRequest(sub *subscription, c *client, _ *Account, offline = s.allPeersOffline(rg) isMember = rg.isMember(ourID) } + if ca.unsupported != nil && isMember { + // If we're a member for this consumer, and it's not supported, report it as offline. + resp.Error = NewJSConsumerOfflineReasonError(errors.New(ca.unsupported.reason)) + s.sendDelayedAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp), nil, errRespDelay) + js.mu.RUnlock() + return + } } // Capture consumer leader here. isConsumerLeader := cc.isConsumerLeader(acc.Name, streamName, consumerName) @@ -4856,6 +4953,12 @@ func (s *Server) jsConsumerInfoRequest(sub *subscription, c *client, _ *Account, return } + if obs.offlineReason != _EMPTY_ { + resp.Error = NewJSConsumerOfflineReasonError(errors.New(obs.offlineReason)) + s.sendDelayedAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp), nil, errRespDelay) + return + } + if resp.ConsumerInfo = setDynamicConsumerInfoMetadata(obs.info()); resp.ConsumerInfo == nil { // This consumer returned nil which means it's closed. Respond with not found. resp.Error = NewJSConsumerNotFoundError() @@ -4997,6 +5100,11 @@ func (s *Server) jsConsumerPauseRequest(sub *subscription, c *client, _ *Account s.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp)) return } + if sa.unsupported != nil { + js.mu.RUnlock() + // Just let the request time out. + return + } ca, ok := sa.consumers[consumer] if !ok || ca == nil { @@ -5005,6 +5113,11 @@ func (s *Server) jsConsumerPauseRequest(sub *subscription, c *client, _ *Account s.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp)) return } + if ca.unsupported != nil { + js.mu.RUnlock() + // Just let the request time out. + return + } nca := *ca ncfg := *ca.Config @@ -5038,6 +5151,10 @@ func (s *Server) jsConsumerPauseRequest(sub *subscription, c *client, _ *Account s.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp)) return } + if mset.offlineReason != _EMPTY_ { + // Just let the request time out. + return + } obs := mset.lookupConsumer(consumer) if obs == nil { @@ -5045,6 +5162,10 @@ func (s *Server) jsConsumerPauseRequest(sub *subscription, c *client, _ *Account s.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp)) return } + if obs.offlineReason != _EMPTY_ { + // Just let the request time out. + return + } ncfg := obs.cfg pauseUTC := req.PauseUntil.UTC() diff --git a/vendor/github.com/nats-io/nats-server/v2/server/jetstream_cluster.go b/vendor/github.com/nats-io/nats-server/v2/server/jetstream_cluster.go index 2e6fa51799..7d1c206396 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/jetstream_cluster.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/jetstream_cluster.go @@ -21,6 +21,7 @@ import ( "encoding/json" "errors" "fmt" + "io" "math" "math/rand" "os" @@ -75,6 +76,7 @@ type jetStreamCluster struct { type inflightInfo struct { rg *raftGroup sync string + cfg *StreamConfig } // Used to guide placement of streams and meta controllers in clustered JetStream. @@ -145,6 +147,66 @@ type streamAssignment struct { reassigning bool // i.e. due to placement issues, lack of resources, etc. resetting bool // i.e. there was an error, and we're stopping and starting the stream err error + unsupported *unsupportedStreamAssignment +} + +type unsupportedStreamAssignment struct { + json []byte // The raw JSON content of the assignment, if it's unsupported due to the required API level. + reason string + info StreamInfo + sysc *client + infoSub *subscription +} + +func newUnsupportedStreamAssignment(s *Server, sa *streamAssignment, json []byte) *unsupportedStreamAssignment { + reason := "stopped" + if sa.Config != nil && !supportsRequiredApiLevel(sa.Config.Metadata) { + if req := getRequiredApiLevel(sa.Config.Metadata); req != _EMPTY_ { + reason = fmt.Sprintf("unsupported - required API level: %s, current API level: %d", req, JSApiLevel) + } + } + return &unsupportedStreamAssignment{ + json: json, + reason: reason, + info: StreamInfo{ + Created: sa.Created, + Config: *setDynamicStreamMetadata(sa.Config), + Domain: s.getOpts().JetStreamDomain, + TimeStamp: time.Now().UTC(), + }, + } +} + +func (usa *unsupportedStreamAssignment) setupInfoSub(s *Server, sa *streamAssignment) { + if usa.infoSub != nil { + return + } + + // Bind to the system account. + ic := s.createInternalJetStreamClient() + ic.registerWithAccount(s.SystemAccount()) + usa.sysc = ic + + // Note below the way we subscribe here is so that we can send requests to ourselves. + isubj := fmt.Sprintf(clusterStreamInfoT, sa.Client.serviceAccount(), sa.Config.Name) + usa.infoSub, _ = s.systemSubscribe(isubj, _EMPTY_, false, ic, usa.handleClusterStreamInfoRequest) +} + +func (usa *unsupportedStreamAssignment) handleClusterStreamInfoRequest(_ *subscription, c *client, _ *Account, _, reply string, _ []byte) { + s, acc := c.srv, c.acc + info := streamInfoClusterResponse{OfflineReason: usa.reason, StreamInfo: usa.info} + s.sendDelayedErrResponse(acc, reply, nil, s.jsonResponse(&info), errRespDelay) +} + +func (usa *unsupportedStreamAssignment) closeInfoSub(s *Server) { + if usa.infoSub != nil { + s.sysUnsubscribe(usa.infoSub) + usa.infoSub = nil + } + if usa.sysc != nil { + usa.sysc.closeConnection(ClientClosed) + usa.sysc = nil + } } // consumerAssignment is what the meta controller uses to assign consumers to streams. @@ -159,11 +221,104 @@ type consumerAssignment struct { Reply string `json:"reply,omitempty"` State *ConsumerState `json:"state,omitempty"` // Internal - responded bool - recovering bool - pending bool - deleted bool - err error + responded bool + recovering bool + pending bool + deleted bool + err error + unsupported *unsupportedConsumerAssignment +} + +type unsupportedConsumerAssignment struct { + json []byte // The raw JSON content of the assignment, if it's unsupported due to the required API level. + reason string + info ConsumerInfo + sysc *client + infoSub *subscription +} + +func newUnsupportedConsumerAssignment(ca *consumerAssignment, json []byte) *unsupportedConsumerAssignment { + reason := "stopped" + if ca.Config != nil && !supportsRequiredApiLevel(ca.Config.Metadata) { + if req := getRequiredApiLevel(ca.Config.Metadata); req != _EMPTY_ { + reason = fmt.Sprintf("unsupported - required API level: %s, current API level: %d", getRequiredApiLevel(ca.Config.Metadata), JSApiLevel) + } + } + return &unsupportedConsumerAssignment{ + json: json, + reason: reason, + info: ConsumerInfo{ + Stream: ca.Stream, + Name: ca.Name, + Created: ca.Created, + Config: setDynamicConsumerMetadata(ca.Config), + TimeStamp: time.Now().UTC(), + }, + } +} + +func (uca *unsupportedConsumerAssignment) setupInfoSub(s *Server, ca *consumerAssignment) { + if uca.infoSub != nil { + return + } + + // Bind to the system account. + ic := s.createInternalJetStreamClient() + ic.registerWithAccount(s.SystemAccount()) + uca.sysc = ic + + // Note below the way we subscribe here is so that we can send requests to ourselves. + isubj := fmt.Sprintf(clusterConsumerInfoT, ca.Client.serviceAccount(), ca.Stream, ca.Name) + uca.infoSub, _ = s.systemSubscribe(isubj, _EMPTY_, false, ic, uca.handleClusterConsumerInfoRequest) +} + +func (uca *unsupportedConsumerAssignment) handleClusterConsumerInfoRequest(_ *subscription, c *client, _ *Account, _, reply string, _ []byte) { + s, acc := c.srv, c.acc + info := consumerInfoClusterResponse{OfflineReason: uca.reason, ConsumerInfo: uca.info} + s.sendDelayedErrResponse(acc, reply, nil, s.jsonResponse(&info), errRespDelay) +} + +func (uca *unsupportedConsumerAssignment) closeInfoSub(s *Server) { + if uca.infoSub != nil { + s.sysUnsubscribe(uca.infoSub) + uca.infoSub = nil + } + if uca.sysc != nil { + uca.sysc.closeConnection(ClientClosed) + uca.sysc = nil + } +} + +type writeableConsumerAssignment struct { + consumerAssignment + // Internal + unsupportedJson []byte // The raw JSON content of the assignment, if it's unsupported due to the required API level. +} + +func (wca *writeableConsumerAssignment) MarshalJSON() ([]byte, error) { + if wca.unsupportedJson != nil { + return wca.unsupportedJson, nil + } + return json.Marshal(wca.consumerAssignment) +} + +func (wca *writeableConsumerAssignment) UnmarshalJSON(data []byte) error { + var unsupported bool + var ca consumerAssignment + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + if err := decoder.Decode(&ca); err != nil { + unsupported = true + ca = consumerAssignment{} + if err = json.Unmarshal(data, &ca); err != nil { + return err + } + } + wca.consumerAssignment = ca + if unsupported || (wca.Config != nil && !supportsRequiredApiLevel(wca.Config.Metadata)) { + wca.unsupportedJson = data + } + return nil } // streamPurge is what the stream leader will replicate when purging a stream. @@ -448,6 +603,10 @@ func (cc *jetStreamCluster) isStreamCurrent(account, stream string) bool { // For R1 it will make sure the stream is present on this server. func (js *jetStream) isStreamHealthy(acc *Account, sa *streamAssignment) error { js.mu.RLock() + if sa != nil && sa.unsupported != nil { + js.mu.RUnlock() + return nil + } s, cc := js.srv, js.cluster if cc == nil { // Non-clustered mode @@ -501,10 +660,14 @@ func (js *jetStream) isStreamHealthy(acc *Account, sa *streamAssignment) error { // isConsumerHealthy will determine if the consumer is up to date. // For R1 it will make sure the consunmer is present on this server. func (js *jetStream) isConsumerHealthy(mset *stream, consumer string, ca *consumerAssignment) error { + js.mu.RLock() + if ca != nil && ca.unsupported != nil { + js.mu.RUnlock() + return nil + } if mset == nil { return errors.New("stream missing") } - js.mu.RLock() s, cc := js.srv, js.cluster if cc == nil { // Non-clustered mode @@ -1386,12 +1549,44 @@ func (js *jetStream) checkClusterSize() { // Represents our stable meta state that we can write out. type writeableStreamAssignment struct { + backingStreamAssignment + // Internal + unsupportedJson []byte // The raw JSON content of the assignment, if it's unsupported due to the required API level. +} + +type backingStreamAssignment struct { Client *ClientInfo `json:"client,omitempty"` Created time.Time `json:"created"` Config *StreamConfig `json:"stream"` Group *raftGroup `json:"group"` Sync string `json:"sync"` - Consumers []*consumerAssignment + Consumers []*writeableConsumerAssignment +} + +func (wsa *writeableStreamAssignment) MarshalJSON() ([]byte, error) { + if wsa.unsupportedJson != nil { + return wsa.unsupportedJson, nil + } + return json.Marshal(wsa.backingStreamAssignment) +} + +func (wsa *writeableStreamAssignment) UnmarshalJSON(data []byte) error { + var unsupported bool + var bsa backingStreamAssignment + decoder := json.NewDecoder(bytes.NewReader(data)) + decoder.DisallowUnknownFields() + if err := decoder.Decode(&bsa); err != nil { + unsupported = true + bsa = backingStreamAssignment{} + if err = json.Unmarshal(data, &bsa); err != nil { + return err + } + } + wsa.backingStreamAssignment = bsa + if unsupported || (wsa.Config != nil && !supportsRequiredApiLevel(wsa.Config.Metadata)) { + wsa.unsupportedJson = data + } + return nil } func (js *jetStream) clusterStreamConfig(accName, streamName string) (StreamConfig, bool) { @@ -1416,13 +1611,19 @@ func (js *jetStream) metaSnapshot() ([]byte, error) { streams := make([]writeableStreamAssignment, 0, nsa) for _, asa := range cc.streams { for _, sa := range asa { + if sa.unsupported != nil && sa.unsupported.json != nil { + streams = append(streams, writeableStreamAssignment{unsupportedJson: sa.unsupported.json}) + continue + } wsa := writeableStreamAssignment{ - Client: sa.Client.forAssignmentSnap(), - Created: sa.Created, - Config: sa.Config, - Group: sa.Group, - Sync: sa.Sync, - Consumers: make([]*consumerAssignment, 0, len(sa.consumers)), + backingStreamAssignment: backingStreamAssignment{ + Client: sa.Client.forAssignmentSnap(), + Created: sa.Created, + Config: sa.Config, + Group: sa.Group, + Sync: sa.Sync, + Consumers: make([]*writeableConsumerAssignment, 0, len(sa.consumers)), + }, } for _, ca := range sa.consumers { // Skip if the consumer is pending, we can't include it in our snapshot. @@ -1430,11 +1631,16 @@ func (js *jetStream) metaSnapshot() ([]byte, error) { if ca.pending { continue } + if ca.unsupported != nil && ca.unsupported.json != nil { + wsa.Consumers = append(wsa.Consumers, &writeableConsumerAssignment{unsupportedJson: ca.unsupported.json}) + nca++ + continue + } cca := *ca cca.Stream = wsa.Config.Name // Needed for safe roll-backs. cca.Client = cca.Client.forAssignmentSnap() cca.Subject, cca.Reply = _EMPTY_, _EMPTY_ - wsa.Consumers = append(wsa.Consumers, &cca) + wsa.Consumers = append(wsa.Consumers, &writeableConsumerAssignment{consumerAssignment: cca}) nca++ } streams = append(streams, wsa) @@ -1493,11 +1699,18 @@ func (js *jetStream) applyMetaSnapshot(buf []byte, ru *recoveryUpdates, isRecove streams[wsa.Client.serviceAccount()] = as } sa := &streamAssignment{Client: wsa.Client, Created: wsa.Created, Config: wsa.Config, Group: wsa.Group, Sync: wsa.Sync} + if wsa.unsupportedJson != nil { + sa.unsupported = newUnsupportedStreamAssignment(js.srv, sa, wsa.unsupportedJson) + } if len(wsa.Consumers) > 0 { sa.consumers = make(map[string]*consumerAssignment) - for _, ca := range wsa.Consumers { - if ca.Stream == _EMPTY_ { - ca.Stream = sa.Config.Name // Rehydrate from the stream name. + for _, wca := range wsa.Consumers { + if wca.Stream == _EMPTY_ { + wca.Stream = sa.Config.Name // Rehydrate from the stream name. + } + ca := &consumerAssignment{Client: wca.Client, Created: wca.Created, Name: wca.Name, Stream: wca.Stream, Config: wca.Config, Group: wca.Group, Subject: wca.Subject, Reply: wca.Reply, State: wca.State} + if wca.unsupportedJson != nil { + ca.unsupported = newUnsupportedConsumerAssignment(ca, wca.unsupportedJson) } sa.consumers[ca.Name] = ca } @@ -1698,6 +1911,9 @@ func (js *jetStream) processAddPeer(peer string) { for _, asa := range cc.streams { for _, sa := range asa { + if sa.unsupported != nil { + continue + } if sa.missingPeers() { // Make sure the right cluster etc. if si.cluster != sa.Client.Cluster { @@ -1709,6 +1925,9 @@ func (js *jetStream) processAddPeer(peer string) { // Send our proposal for this csa. Also use same group definition for all the consumers as well. cc.meta.Propose(encodeAddStreamAssignment(csa)) for _, ca := range sa.consumers { + if ca.unsupported != nil { + continue + } // Ephemerals are R=1, so only auto-remap durables, or R>1. if ca.Config.Durable != _EMPTY_ || len(ca.Group.Peers) > 1 { cca := ca.copyGroup() @@ -1766,6 +1985,9 @@ func (js *jetStream) processRemovePeer(peer string) { for _, asa := range cc.streams { for _, sa := range asa { + if sa.unsupported != nil { + continue + } if rg := sa.Group; rg.isMember(peer) { js.removePeerFromStreamLocked(sa, peer) } @@ -1799,6 +2021,9 @@ func (js *jetStream) removePeerFromStreamLocked(sa *streamAssignment, peer strin cc.meta.Propose(encodeAddStreamAssignment(csa)) rg := csa.Group for _, ca := range sa.consumers { + if ca.unsupported != nil { + continue + } // Ephemerals are R=1, so only auto-remap durables, or R>1. if ca.Config.Durable != _EMPTY_ { cca := ca.copyGroup() @@ -1865,7 +2090,7 @@ func (js *jetStream) applyMetaEntries(entries []*Entry, ru *recoveryUpdates) (bo buf := e.Data switch entryOp(buf[0]) { case assignStreamOp: - sa, err := decodeStreamAssignment(buf[1:]) + sa, err := decodeStreamAssignment(js.srv, buf[1:]) if err != nil { js.srv.Errorf("JetStream cluster failed to decode stream assignment: %q", buf[1:]) return didSnap, didRemoveStream, didRemoveConsumer, err @@ -1875,11 +2100,11 @@ func (js *jetStream) applyMetaEntries(entries []*Entry, ru *recoveryUpdates) (bo key := sa.recoveryKey() ru.addStreams[key] = sa delete(ru.removeStreams, key) - } else if js.processStreamAssignment(sa) { - didRemoveStream = true + } else { + js.processStreamAssignment(sa) } case removeStreamOp: - sa, err := decodeStreamAssignment(buf[1:]) + sa, err := decodeStreamAssignment(js.srv, buf[1:]) if err != nil { js.srv.Errorf("JetStream cluster failed to decode stream assignment: %q", buf[1:]) return didSnap, didRemoveStream, didRemoveConsumer, err @@ -1958,7 +2183,7 @@ func (js *jetStream) applyMetaEntries(entries []*Entry, ru *recoveryUpdates) (bo didRemoveConsumer = true } case updateStreamOp: - sa, err := decodeStreamAssignment(buf[1:]) + sa, err := decodeStreamAssignment(js.srv, buf[1:]) if err != nil { js.srv.Errorf("JetStream cluster failed to decode stream assignment: %q", buf[1:]) return didSnap, didRemoveStream, didRemoveConsumer, err @@ -2640,6 +2865,9 @@ func (js *jetStream) monitorStream(mset *stream, sa *streamAssignment, sendSnaps js.mu.RLock() var needToWait bool for name, c := range sa.consumers { + if c.unsupported != nil { + continue + } for _, peer := range c.Group.Peers { // If we have peers still in the old set block. if oldPeerSet[peer] { @@ -2877,6 +3105,7 @@ func (mset *stream) resetClusteredState(err error) bool { // Need to do the rest in a separate Go routine. go func() { + mset.signalMonitorQuit() mset.monitorWg.Wait() mset.resetAndWaitOnConsumers() // Stop our stream. @@ -2899,6 +3128,9 @@ func (mset *stream) resetClusteredState(err error) bool { if cc := js.cluster; cc != nil && cc.meta != nil { ourID := cc.meta.ID() for _, ca := range sa.consumers { + if ca.unsupported != nil { + continue + } if rg := ca.Group; rg != nil && rg.isMember(ourID) { rg.node = nil // Erase group raft/node state. consumers = append(consumers, ca) @@ -3433,7 +3665,7 @@ func (js *jetStream) streamAssignment(account, stream string) (sa *streamAssignm } // processStreamAssignment is called when followers have replicated an assignment. -func (js *jetStream) processStreamAssignment(sa *streamAssignment) bool { +func (js *jetStream) processStreamAssignment(sa *streamAssignment) { js.mu.Lock() s, cc := js.srv, js.cluster accName, stream := sa.Client.serviceAccount(), sa.Config.Name @@ -3452,26 +3684,57 @@ func (js *jetStream) processStreamAssignment(sa *streamAssignment) bool { if s == nil || noMeta { js.mu.Unlock() - return false + return } accStreams := cc.streams[accName] if accStreams == nil { accStreams = make(map[string]*streamAssignment) - } else if osa := accStreams[stream]; osa != nil && osa != sa { - // Copy over private existing state from former SA. - if sa.Group != nil { - sa.Group.node = osa.Group.node + } else if osa := accStreams[stream]; osa != nil { + if osa != sa { + // Copy over private existing state from former SA. + if sa.Group != nil { + sa.Group.node = osa.Group.node + } + sa.consumers = osa.consumers + sa.responded = osa.responded + sa.err = osa.err + } + // Unsubscribe if it was previously unsupported. + if osa.unsupported != nil { + osa.unsupported.closeInfoSub(js.srv) + // If we've seen unsupported once, it remains for the lifetime of this server process. + if sa.unsupported == nil { + sa.unsupported = osa.unsupported + } } - sa.consumers = osa.consumers - sa.responded = osa.responded - sa.err = osa.err } // Update our state. accStreams[stream] = sa cc.streams[accName] = accStreams hasResponded := sa.responded + + // If unsupported, we can't register any further. + if sa.unsupported != nil { + sa.unsupported.setupInfoSub(s, sa) + apiLevel := getRequiredApiLevel(sa.Config.Metadata) + s.Warnf("Detected unsupported stream '%s > %s', delete the stream or upgrade the server to API level %s", accName, stream, apiLevel) + js.mu.Unlock() + + // Need to stop the stream, we can't keep running with an old config. + acc, err := s.LookupAccount(accName) + if err != nil { + return + } + mset, err := acc.lookupStream(stream) + if err != nil || mset.closed.Load() { + return + } + s.Warnf("Stopping unsupported stream '%s > %s'", accName, stream) + mset.stop(false, false) + return + } js.mu.Unlock() acc, err := s.LookupAccount(accName) @@ -3492,11 +3755,9 @@ func (js *jetStream) processStreamAssignment(sa *streamAssignment) bool { } else { s.Debugf(ll) } - return false + return } - var didRemove bool - // Check if this is for us.. if isMember { js.processClusterCreateStream(acc, sa) @@ -3510,10 +3771,7 @@ func (js *jetStream) processStreamAssignment(sa *streamAssignment) bool { js.mu.Lock() cc.streamsCheck = true js.mu.Unlock() - return false } - - return didRemove } // processUpdateStreamAssignment is called when followers have replicated an updated assignment. @@ -3577,6 +3835,36 @@ func (js *jetStream) processUpdateStreamAssignment(sa *streamAssignment) { sa.Group.node = nil } } + + // Unsubscribe if it was previously unsupported. + if osa.unsupported != nil { + osa.unsupported.closeInfoSub(js.srv) + // If we've seen unsupported once, it remains for the lifetime of this server process. + if sa.unsupported == nil { + sa.unsupported = osa.unsupported + } + } + + // If unsupported, we can't register any further. + if sa.unsupported != nil { + sa.unsupported.setupInfoSub(s, sa) + apiLevel := getRequiredApiLevel(sa.Config.Metadata) + s.Warnf("Detected unsupported stream '%s > %s', delete the stream or upgrade the server to API level %s", accName, stream, apiLevel) + js.mu.Unlock() + + // Need to stop the stream, we can't keep running with an old config. + acc, err := s.LookupAccount(accName) + if err != nil { + return + } + mset, err := acc.lookupStream(stream) + if err != nil || mset.closed.Load() { + return + } + s.Warnf("Stopping unsupported stream '%s > %s'", accName, stream) + mset.stop(false, false) + return + } js.mu.Unlock() acc, err := s.LookupAccount(accName) @@ -3619,6 +3907,7 @@ func (s *Server) removeStream(mset *stream, nsa *streamAssignment) { if !isShuttingDown { // wait for monitor to be shutdown. + mset.signalMonitorQuit() mset.monitorWg.Wait() } mset.stop(true, false) @@ -3672,7 +3961,7 @@ func (js *jetStream) processClusterUpdateStream(acc *Account, osa, sa *streamAss } mset.monitorWg.Add(1) // Start monitoring.. - s.startGoRoutine( + started := s.startGoRoutine( func() { js.monitorStream(mset, sa, needsNode) }, pprofLabels{ "type": "stream", @@ -3680,6 +3969,9 @@ func (js *jetStream) processClusterUpdateStream(acc *Account, osa, sa *streamAss "stream": mset.name(), }, ) + if !started { + mset.monitorWg.Done() + } } else if numReplicas == 1 && alreadyRunning { // We downgraded to R1. Make sure we cleanup the raft node and the stream monitor. mset.removeNode() @@ -3930,7 +4222,7 @@ func (js *jetStream) processClusterCreateStream(acc *Account, sa *streamAssignme if mset != nil { mset.monitorWg.Add(1) } - s.startGoRoutine( + started := s.startGoRoutine( func() { js.monitorStream(mset, sa, false) }, pprofLabels{ "type": "stream", @@ -3938,6 +4230,9 @@ func (js *jetStream) processClusterCreateStream(acc *Account, sa *streamAssignme "stream": mset.name(), }, ) + if !started && mset != nil { + mset.monitorWg.Done() + } } } else { // Single replica stream, process manually here. @@ -4049,6 +4344,13 @@ func (js *jetStream) processStreamRemoval(sa *streamAssignment) { accStreams := cc.streams[sa.Client.serviceAccount()] needDelete := accStreams != nil && accStreams[stream] != nil if needDelete { + if osa := accStreams[stream]; osa != nil && osa.unsupported != nil { + osa.unsupported.closeInfoSub(js.srv) + // Remember we used to be unsupported, just so we can send a successful delete response. + if sa.unsupported == nil { + sa.unsupported = osa.unsupported + } + } delete(accStreams, stream) if len(accStreams) == 0 { delete(cc.streams, sa.Client.serviceAccount()) @@ -4069,7 +4371,7 @@ func (js *jetStream) processClusterDeleteStream(sa *streamAssignment, isMember, s := js.srv node := sa.Group.node hadLeader := node == nil || !node.Leaderless() - offline := s.allPeersOffline(sa.Group) + offline := s.allPeersOffline(sa.Group) || sa.unsupported != nil var isMetaLeader bool if cc := js.cluster; cc != nil { isMetaLeader = cc.isLeader() @@ -4090,6 +4392,7 @@ func (js *jetStream) processClusterDeleteStream(sa *streamAssignment, isMember, n.Delete() } // wait for monitor to be shut down + mset.signalMonitorQuit() mset.monitorWg.Wait() err = mset.stop(true, wasLeader) stopped = true @@ -4107,7 +4410,7 @@ func (js *jetStream) processClusterDeleteStream(sa *streamAssignment, isMember, } // This is a stop gap cleanup in case - // 1) the account does not exist (and mset couldn't be stopped) and/or + // 1) the account or mset does not exist and/or // 2) node was nil (and couldn't be deleted) if !stopped || node == nil { if sacc := s.SystemAccount(); sacc != nil { @@ -4202,6 +4505,15 @@ func (js *jetStream) processConsumerAssignment(ca *consumerAssignment) { } ca.responded = oca.responded ca.err = oca.err + + // Unsubscribe if it was previously unsupported. + if oca.unsupported != nil { + oca.unsupported.closeInfoSub(s) + // If we've seen unsupported once, it remains for the lifetime of this server process. + if ca.unsupported == nil { + ca.unsupported = oca.unsupported + } + } } // Capture the optional state. We will pass it along if we are a member to apply. @@ -4213,6 +4525,35 @@ func (js *jetStream) processConsumerAssignment(ca *consumerAssignment) { // Ok to replace an existing one, we check on process call below. sa.consumers[ca.Name] = ca ca.pending = false + + // If unsupported, we can't register any further. + if ca.unsupported != nil { + ca.unsupported.setupInfoSub(s, ca) + apiLevel := getRequiredApiLevel(ca.Config.Metadata) + s.Warnf("Detected unsupported consumer '%s > %s > %s', delete the consumer or upgrade the server to API level %s", accName, stream, ca.Name, apiLevel) + + // Mark stream as unsupported as well + if sa.unsupported == nil { + sa.unsupported = newUnsupportedStreamAssignment(s, sa, nil) + } + sa.unsupported.setupInfoSub(s, sa) + js.mu.Unlock() + + // Be conservative by protecting the whole stream, even if just one consumer is unsupported. + // This ensures it's safe, even with Interest-based retention where it would otherwise + // continue accepting but dropping messages. + acc, err := s.LookupAccount(accName) + if err != nil { + return + } + mset, err := acc.lookupStream(stream) + if err != nil || mset.closed.Load() { + return + } + s.Warnf("Stopping unsupported stream '%s > %s'", accName, stream) + mset.stop(false, false) + return + } js.mu.Unlock() acc, err := s.LookupAccount(accName) @@ -4308,6 +4649,7 @@ func (js *jetStream) processConsumerRemoval(ca *consumerAssignment) { js.mu.Unlock() return } + wasLeader := cc.isConsumerLeader(ca.Client.serviceAccount(), ca.Stream, ca.Name) // Delete from our state. @@ -4320,6 +4662,10 @@ func (js *jetStream) processConsumerRemoval(ca *consumerAssignment) { needDelete = true oca.deleted = true delete(sa.consumers, ca.Name) + // Remember we used to be unsupported, just so we can send a successful delete response. + if ca.unsupported == nil { + ca.unsupported = oca.unsupported + } } } } @@ -4562,7 +4908,7 @@ func (js *jetStream) processClusterCreateConsumer(ca *consumerAssignment, state // Clustered consumer. // Start our monitoring routine if needed. if !alreadyRunning && o.shouldStartMonitor() { - s.startGoRoutine( + started := s.startGoRoutine( func() { js.monitorConsumer(o, ca) }, pprofLabels{ "type": "consumer", @@ -4571,6 +4917,9 @@ func (js *jetStream) processClusterCreateConsumer(ca *consumerAssignment, state "consumer": ca.Name, }, ) + if !started { + o.clearMonitorRunning() + } } // For existing consumer, only send response if not recovering. if wasExisting && !js.isMetaRecovering() { @@ -4597,7 +4946,7 @@ func (js *jetStream) processClusterDeleteConsumer(ca *consumerAssignment, wasLea js.mu.RLock() s := js.srv node := ca.Group.node - offline := s.allPeersOffline(ca.Group) + offline := s.allPeersOffline(ca.Group) || ca.unsupported != nil var isMetaLeader bool if cc := js.cluster; cc != nil { isMetaLeader = cc.isLeader() @@ -4605,6 +4954,7 @@ func (js *jetStream) processClusterDeleteConsumer(ca *consumerAssignment, wasLea recovering := ca.recovering js.mu.RUnlock() + stopped := false var resp = JSApiConsumerDeleteResponse{ApiResponse: ApiResponse{Type: JSApiConsumerDeleteResponseType}} var err error var acc *Account @@ -4614,13 +4964,9 @@ func (js *jetStream) processClusterDeleteConsumer(ca *consumerAssignment, wasLea if mset, _ := acc.lookupStream(ca.Stream); mset != nil { if o := mset.lookupConsumer(ca.Name); o != nil { err = o.stopWithFlags(true, false, true, wasLeader) + stopped = true } } - } else if ca.Group != nil { - // We have a missing account, see if we can cleanup. - if sacc := s.SystemAccount(); sacc != nil { - os.RemoveAll(filepath.Join(js.config.StoreDir, sacc.GetName(), defaultStoreDirName, ca.Group.Name)) - } } // Always delete the node if present. @@ -4628,6 +4974,19 @@ func (js *jetStream) processClusterDeleteConsumer(ca *consumerAssignment, wasLea node.Delete() } + // This is a stop gap cleanup in case + // 1) the account, mset, or consumer does not exist and/or + // 2) node was nil (and couldn't be deleted) + if !stopped || node == nil { + if sacc := s.SystemAccount(); sacc != nil { + os.RemoveAll(filepath.Join(js.config.StoreDir, sacc.GetName(), defaultStoreDirName, ca.Group.Name)) + } + } + + accDir := filepath.Join(js.config.StoreDir, ca.Client.serviceAccount()) + consumersDir := filepath.Join(accDir, streamsDir, ca.Stream, consumerDir) + os.RemoveAll(filepath.Join(consumersDir, ca.Name)) + if !wasLeader || ca.Reply == _EMPTY_ { if !(offline && isMetaLeader) { return @@ -4774,7 +5133,7 @@ func (js *jetStream) monitorConsumer(o *consumer, ca *consumerAssignment) { // from underneath the one that is running since it will be the same raft node. defer n.Stop() - qch, lch, aq, uch, ourPeerId := n.QuitC(), n.LeadChangeC(), n.ApplyQ(), o.updateC(), meta.ID() + qch, mqch, lch, aq, uch, ourPeerId := n.QuitC(), o.monitorQuitC(), n.LeadChangeC(), n.ApplyQ(), o.updateC(), meta.ID() s.Debugf("Starting consumer monitor for '%s > %s > %s' [%s]", o.acc.Name, ca.Stream, ca.Name, n.Group()) defer s.Debugf("Exiting consumer monitor for '%s > %s > %s' [%s]", o.acc.Name, ca.Stream, ca.Name, n.Group()) @@ -4863,6 +5222,10 @@ func (js *jetStream) monitorConsumer(o *consumer, ca *consumerAssignment) { // Server shutting down, but we might receive this before qch, so try to snapshot. doSnapshot(false) return + case <-mqch: + // Clean signal from shutdown routine so do best effort attempt to snapshot. + doSnapshot(false) + return case <-qch: // Clean signal from shutdown routine so do best effort attempt to snapshot. doSnapshot(false) @@ -5300,9 +5663,11 @@ func (js *jetStream) processConsumerLeaderChange(o *consumer, isLeader bool) err // Only send a pause advisory on consumer create if we're // actually paused. The timer would have been kicked by now // by the call to o.setLeader() above. + o.mu.RLock() if isLeader && o.cfg.PauseUntil != nil && !o.cfg.PauseUntil.IsZero() && time.Now().Before(*o.cfg.PauseUntil) { o.sendPauseAdvisoryLocked(&o.cfg) } + o.mu.RUnlock() return nil } @@ -5594,6 +5959,10 @@ func (s *Server) sendDomainLeaderElectAdvisory() { node := cc.meta js.mu.RUnlock() + if node == nil { + return + } + adv := &JSDomainLeaderElectedAdvisory{ TypedEvent: TypedEvent{ Type: JSDomainLeaderElectedAdvisoryType, @@ -5662,6 +6031,9 @@ func (js *jetStream) processLeaderChange(isLeader bool) { cc := js.cluster for acc, asa := range cc.streams { for _, sa := range asa { + if sa.unsupported != nil { + continue + } if sa.Sync == _EMPTY_ { s.Warnf("Stream assignment corrupt for stream '%s > %s'", acc, sa.Config.Name) nsa := &streamAssignment{Group: sa.Group, Config: sa.Config, Subject: sa.Subject, Reply: sa.Reply, Client: sa.Client} @@ -5877,6 +6249,9 @@ func (cc *jetStreamCluster) selectPeerGroup(r int, cluster string, cfg *StreamCo peerHA := make(map[string]int, len(peers)) for _, asa := range cc.streams { for _, sa := range asa { + if sa.unsupported != nil { + continue + } isHA := len(sa.Group.Peers) > 1 for _, peer := range sa.Group.Peers { peerStreams[peer]++ @@ -6228,6 +6603,11 @@ func (s *Server) jsClusteredStreamRequest(ci *ClientInfo, acc *Account, subject, if rg == nil { // Check inflight before proposing in case we have an existing inflight proposal. if existing, ok := streams[cfg.Name]; ok { + if !reflect.DeepEqual(existing.cfg, cfg) { + resp.Error = NewJSStreamNameExistError() + s.sendAPIErrResponse(ci, acc, subject, reply, string(rmsg), s.jsonResponse(&resp)) + return + } // We have existing for same stream. Re-use same group and syncSubject. rg, syncSubject = existing.rg, existing.sync } @@ -6255,7 +6635,7 @@ func (s *Server) jsClusteredStreamRequest(ci *ClientInfo, acc *Account, subject, // on concurrent create requests while this stream assignment has // possibly not been processed yet. if streams, ok := cc.inflight[acc.Name]; ok && self == nil { - streams[cfg.Name] = &inflightInfo{rg, syncSubject} + streams[cfg.Name] = &inflightInfo{rg, syncSubject, cfg} } } } @@ -6461,7 +6841,7 @@ func (s *Server) jsClusteredStreamUpdateRequest(ci *ClientInfo, acc *Account, su // try to pick one. This could happen with older streams that were assigned by // previous servers. if rg.Cluster == _EMPTY_ { - // Prefer placement directrives if we have them. + // Prefer placement directives if we have them. if newCfg.Placement != nil && newCfg.Placement.Cluster != _EMPTY_ { rg.Cluster = newCfg.Placement.Cluster } else { @@ -6895,11 +7275,11 @@ func (s *Server) jsClusteredStreamListRequest(acc *Account, ci *ClientInfo, filt // Create an inbox for our responses and send out our requests. s.mu.Lock() inbox := s.newRespInbox() - rc := make(chan *StreamInfo, len(streams)) + rc := make(chan *streamInfoClusterResponse, len(streams)) // Store our handler. s.sys.replies[inbox] = func(sub *subscription, _ *client, _ *Account, subject, _ string, msg []byte) { - var si StreamInfo + var si streamInfoClusterResponse if err := json.Unmarshal(msg, &si); err != nil { s.Warnf("Error unmarshalling clustered stream info response:%v", err) return @@ -6967,10 +7347,14 @@ LOOP: si.State.Consumers = consCount } delete(sent, si.Config.Name) - resp.Streams = append(resp.Streams, si) - // Check to see if we are done. - if len(resp.Streams) == len(streams) { - break LOOP + if si.OfflineReason == _EMPTY_ { + resp.Streams = append(resp.Streams, &si.StreamInfo) + } else if _, ok := resp.Offline[si.Config.Name]; !ok { + if resp.Offline == nil { + resp.Offline = make(map[string]string, 1) + } + resp.Offline[si.Config.Name] = si.OfflineReason + missingNames = append(missingNames, si.Config.Name) } } } @@ -7042,11 +7426,11 @@ func (s *Server) jsClusteredConsumerListRequest(acc *Account, ci *ClientInfo, of // Create an inbox for our responses and send out requests. s.mu.Lock() inbox := s.newRespInbox() - rc := make(chan *ConsumerInfo, len(consumers)) + rc := make(chan *consumerInfoClusterResponse, len(consumers)) // Store our handler. s.sys.replies[inbox] = func(sub *subscription, _ *client, _ *Account, subject, _ string, msg []byte) { - var ci ConsumerInfo + var ci consumerInfoClusterResponse if err := json.Unmarshal(msg, &ci); err != nil { s.Warnf("Error unmarshaling clustered consumer info response:%v", err) return @@ -7110,10 +7494,14 @@ LOOP: break LOOP case ci := <-rc: delete(sent, ci.Name) - resp.Consumers = append(resp.Consumers, ci) - // Check to see if we are done. - if len(resp.Consumers) == len(consumers) { - break LOOP + if ci.OfflineReason == _EMPTY_ { + resp.Consumers = append(resp.Consumers, &ci.ConsumerInfo) + } else if _, ok := resp.Offline[ci.Name]; !ok { + if resp.Offline == nil { + resp.Offline = make(map[string]string, 1) + } + resp.Offline[ci.Name] = ci.OfflineReason + missingNames = append(missingNames, ci.Name) } } } @@ -7266,14 +7654,24 @@ func encodeDeleteStreamAssignment(sa *streamAssignment) []byte { return bb.Bytes() } -func decodeStreamAssignment(buf []byte) (*streamAssignment, error) { +func decodeStreamAssignment(s *Server, buf []byte) (*streamAssignment, error) { + var unsupported bool var sa streamAssignment - err := json.Unmarshal(buf, &sa) - if err != nil { - return nil, err + decoder := json.NewDecoder(bytes.NewReader(buf)) + decoder.DisallowUnknownFields() + if err := decoder.Decode(&sa); err != nil { + unsupported = true + sa = streamAssignment{} + if err = json.Unmarshal(buf, &sa); err != nil { + return nil, err + } } fixCfgMirrorWithDedupWindow(sa.Config) - return &sa, err + + if unsupported || (sa.Config != nil && !supportsRequiredApiLevel(sa.Config.Metadata)) { + sa.unsupported = newUnsupportedStreamAssignment(s, &sa, copyBytes(buf)) + } + return &sa, nil } func encodeDeleteRange(dr *DeleteRange) []byte { @@ -7405,6 +7803,9 @@ func (s *Server) jsClusteredConsumerRequest(ci *ClientInfo, acc *Account, subjec // Don't count DIRECTS. total := 0 for cn, ca := range sa.consumers { + if ca.unsupported != nil { + continue + } // If the consumer name is specified and we think it already exists, then // we're likely updating an existing consumer, so don't count it. Otherwise // we will incorrectly return NewJSMaximumConsumersLimitError for an update. @@ -7618,8 +8019,15 @@ func (s *Server) jsClusteredConsumerRequest(ci *ClientInfo, acc *Account, subjec if rBefore < rAfter { newPeerSet := nca.Group.Peers - // scale up by adding new members from the stream peer set that are not yet in the consumer peer set + // Scale up by adding new members from the stream peer set that are not yet in the consumer peer set. streamPeerSet := copyStrings(sa.Group.Peers) + + // Respond with error when there is a config mismatch between the intended config and expected peer size. + if len(streamPeerSet) < rAfter { + resp.Error = NewJSConsumerReplicasExceedsStreamError() + s.sendAPIErrResponse(ci, acc, subject, reply, string(rmsg), s.jsonResponse(&resp)) + return + } rand.Shuffle(rAfter, func(i, j int) { streamPeerSet[i], streamPeerSet[j] = streamPeerSet[j], streamPeerSet[i] }) for _, p := range streamPeerSet { found := false @@ -7693,9 +8101,22 @@ func encodeDeleteConsumerAssignment(ca *consumerAssignment) []byte { } func decodeConsumerAssignment(buf []byte) (*consumerAssignment, error) { + var unsupported bool var ca consumerAssignment - err := json.Unmarshal(buf, &ca) - return &ca, err + decoder := json.NewDecoder(bytes.NewReader(buf)) + decoder.DisallowUnknownFields() + if err := decoder.Decode(&ca); err != nil { + unsupported = true + ca = consumerAssignment{} + if err = json.Unmarshal(buf, &ca); err != nil { + return nil, err + } + } + + if unsupported || (ca.Config != nil && !supportsRequiredApiLevel(ca.Config.Metadata)) { + ca.unsupported = newUnsupportedConsumerAssignment(&ca, copyBytes(buf)) + } + return &ca, nil } func encodeAddConsumerAssignmentCompressed(ca *consumerAssignment) []byte { @@ -7710,10 +8131,33 @@ func encodeAddConsumerAssignmentCompressed(ca *consumerAssignment) []byte { } func decodeConsumerAssignmentCompressed(buf []byte) (*consumerAssignment, error) { + var unsupported bool var ca consumerAssignment bb := bytes.NewBuffer(buf) s2d := s2.NewReader(bb) - return &ca, json.NewDecoder(s2d).Decode(&ca) + decoder := json.NewDecoder(s2d) + decoder.DisallowUnknownFields() + if err := decoder.Decode(&ca); err != nil { + unsupported = true + ca = consumerAssignment{} + bb = bytes.NewBuffer(buf) + s2d = s2.NewReader(bb) + if err = json.NewDecoder(s2d).Decode(&ca); err != nil { + return nil, err + } + } + + if unsupported || (ca.Config != nil && !supportsRequiredApiLevel(ca.Config.Metadata)) { + bb = bytes.NewBuffer(buf) + s2d = s2.NewReader(bb) + dec, err := io.ReadAll(s2d) + if err != nil { + return nil, err + } + ca.unsupported = newUnsupportedConsumerAssignment(&ca, copyBytes(dec)) + } + + return &ca, nil } var errBadStreamMsg = errors.New("jetstream cluster bad replicated stream msg") @@ -8846,9 +9290,12 @@ func (js *jetStream) clusterInfo(rg *raftGroup) *ClusterInfo { n := rg.node ci := &ClusterInfo{ - Name: s.cachedClusterName(), - Leader: s.serverNameForNode(n.GroupLeader()), - RaftGroup: rg.Name, + Name: s.cachedClusterName(), + Leader: s.serverNameForNode(n.GroupLeader()), + LeaderSince: n.LeaderSince(), + SystemAcc: n.IsSystemAccount(), + TrafficAcc: n.GetTrafficAccountName(), + RaftGroup: rg.Name, } now := time.Now() @@ -8945,6 +9392,9 @@ func (js *jetStream) streamAlternates(ci *ClientInfo, stream string) []StreamAlt var alts []StreamAlternate for _, sa := range cc.streams[acc.Name] { + if sa.unsupported != nil { + continue + } // Add in ourselves and any mirrors. if sa.Config.Name == stream || (sa.Config.Mirror != nil && sa.Config.Mirror.Name == stream) { alts = append(alts, StreamAlternate{Name: sa.Config.Name, Domain: domain, Cluster: sa.Group.Cluster}) diff --git a/vendor/github.com/nats-io/nats-server/v2/server/jetstream_errors_generated.go b/vendor/github.com/nats-io/nats-server/v2/server/jetstream_errors_generated.go index 162ca4f027..5cebda1f3c 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/jetstream_errors_generated.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/jetstream_errors_generated.go @@ -176,6 +176,9 @@ const ( // JSConsumerOfflineErr consumer is offline JSConsumerOfflineErr ErrorIdentifier = 10119 + // JSConsumerOfflineReasonErrF consumer is offline: {err} + JSConsumerOfflineReasonErrF ErrorIdentifier = 10195 + // JSConsumerOnMappedErr consumer direct on a mapped consumer JSConsumerOnMappedErr ErrorIdentifier = 10092 @@ -440,6 +443,9 @@ const ( // JSStreamOfflineErr stream is offline JSStreamOfflineErr ErrorIdentifier = 10118 + // JSStreamOfflineReasonErrF stream is offline: {err} + JSStreamOfflineReasonErrF ErrorIdentifier = 10194 + // JSStreamPurgeFailedF Generic stream purge failure error string ({err}) JSStreamPurgeFailedF ErrorIdentifier = 10110 @@ -566,6 +572,7 @@ var ( JSConsumerNameTooLongErrF: {Code: 400, ErrCode: 10102, Description: "consumer name is too long, maximum allowed is {max}"}, JSConsumerNotFoundErr: {Code: 404, ErrCode: 10014, Description: "consumer not found"}, JSConsumerOfflineErr: {Code: 500, ErrCode: 10119, Description: "consumer is offline"}, + JSConsumerOfflineReasonErrF: {Code: 500, ErrCode: 10195, Description: "consumer is offline: {err}"}, JSConsumerOnMappedErr: {Code: 400, ErrCode: 10092, Description: "consumer direct on a mapped consumer"}, JSConsumerOverlappingSubjectFilters: {Code: 400, ErrCode: 10138, Description: "consumer subject filters cannot overlap"}, JSConsumerPriorityPolicyWithoutGroup: {Code: 400, ErrCode: 10159, Description: "Setting PriorityPolicy requires at least one PriorityGroup to be set"}, @@ -654,6 +661,7 @@ var ( JSStreamNotFoundErr: {Code: 404, ErrCode: 10059, Description: "stream not found"}, JSStreamNotMatchErr: {Code: 400, ErrCode: 10060, Description: "expected stream does not match"}, JSStreamOfflineErr: {Code: 500, ErrCode: 10118, Description: "stream is offline"}, + JSStreamOfflineReasonErrF: {Code: 500, ErrCode: 10194, Description: "stream is offline: {err}"}, JSStreamPurgeFailedF: {Code: 500, ErrCode: 10110, Description: "{err}"}, JSStreamReplicasNotSupportedErr: {Code: 500, ErrCode: 10074, Description: "replicas > 1 not supported in non-clustered mode"}, JSStreamReplicasNotUpdatableErr: {Code: 400, ErrCode: 10061, Description: "Replicas configuration can not be updated"}, @@ -1331,6 +1339,22 @@ func NewJSConsumerOfflineError(opts ...ErrorOption) *ApiError { return ApiErrors[JSConsumerOfflineErr] } +// NewJSConsumerOfflineReasonError creates a new JSConsumerOfflineReasonErrF error: "consumer is offline: {err}" +func NewJSConsumerOfflineReasonError(err error, opts ...ErrorOption) *ApiError { + eopts := parseOpts(opts) + if ae, ok := eopts.err.(*ApiError); ok { + return ae + } + + e := ApiErrors[JSConsumerOfflineReasonErrF] + args := e.toReplacerArgs([]interface{}{"{err}", err}) + return &ApiError{ + Code: e.Code, + ErrCode: e.ErrCode, + Description: strings.NewReplacer(args...).Replace(e.Description), + } +} + // NewJSConsumerOnMappedError creates a new JSConsumerOnMappedErr error: "consumer direct on a mapped consumer" func NewJSConsumerOnMappedError(opts ...ErrorOption) *ApiError { eopts := parseOpts(opts) @@ -2349,6 +2373,22 @@ func NewJSStreamOfflineError(opts ...ErrorOption) *ApiError { return ApiErrors[JSStreamOfflineErr] } +// NewJSStreamOfflineReasonError creates a new JSStreamOfflineReasonErrF error: "stream is offline: {err}" +func NewJSStreamOfflineReasonError(err error, opts ...ErrorOption) *ApiError { + eopts := parseOpts(opts) + if ae, ok := eopts.err.(*ApiError); ok { + return ae + } + + e := ApiErrors[JSStreamOfflineReasonErrF] + args := e.toReplacerArgs([]interface{}{"{err}", err}) + return &ApiError{ + Code: e.Code, + ErrCode: e.ErrCode, + Description: strings.NewReplacer(args...).Replace(e.Description), + } +} + // NewJSStreamPurgeFailedError creates a new JSStreamPurgeFailedF error: "{err}" func NewJSStreamPurgeFailedError(err error, opts ...ErrorOption) *ApiError { eopts := parseOpts(opts) diff --git a/vendor/github.com/nats-io/nats-server/v2/server/jetstream_versioning.go b/vendor/github.com/nats-io/nats-server/v2/server/jetstream_versioning.go index 1192968b88..41ecf04c7d 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/jetstream_versioning.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/jetstream_versioning.go @@ -24,6 +24,23 @@ const ( JSServerLevelMetadataKey = "_nats.level" ) +// getRequiredApiLevel returns the required API level for the JetStream asset. +func getRequiredApiLevel(metadata map[string]string) string { + if l, ok := metadata[JSRequiredLevelMetadataKey]; ok && l != _EMPTY_ { + return l + } + return _EMPTY_ +} + +// supportsRequiredApiLevel returns whether the required API level for the JetStream asset is supported. +func supportsRequiredApiLevel(metadata map[string]string) bool { + if l := getRequiredApiLevel(metadata); l != _EMPTY_ { + li, err := strconv.Atoi(l) + return err == nil && li <= JSApiLevel + } + return true +} + // setStaticStreamMetadata sets JetStream stream metadata, like the server version and API level. // Any dynamic metadata is removed, it must not be stored and only be added for responses. func setStaticStreamMetadata(cfg *StreamConfig) { @@ -50,10 +67,15 @@ func setStaticStreamMetadata(cfg *StreamConfig) { // setDynamicStreamMetadata adds dynamic fields into the (copied) metadata. func setDynamicStreamMetadata(cfg *StreamConfig) *StreamConfig { - newCfg := *cfg + var newCfg StreamConfig + if cfg != nil { + newCfg = *cfg + } newCfg.Metadata = make(map[string]string) - for key, value := range cfg.Metadata { - newCfg.Metadata[key] = value + if cfg != nil { + for key, value := range cfg.Metadata { + newCfg.Metadata[key] = value + } } newCfg.Metadata[JSServerVersionMetadataKey] = VERSION newCfg.Metadata[JSServerLevelMetadataKey] = strconv.Itoa(JSApiLevel) @@ -121,10 +143,15 @@ func setStaticConsumerMetadata(cfg *ConsumerConfig) { // setDynamicConsumerMetadata adds dynamic fields into the (copied) metadata. func setDynamicConsumerMetadata(cfg *ConsumerConfig) *ConsumerConfig { - newCfg := *cfg + var newCfg ConsumerConfig + if cfg != nil { + newCfg = *cfg + } newCfg.Metadata = make(map[string]string) - for key, value := range cfg.Metadata { - newCfg.Metadata[key] = value + if cfg != nil { + for key, value := range cfg.Metadata { + newCfg.Metadata[key] = value + } } newCfg.Metadata[JSServerVersionMetadataKey] = VERSION newCfg.Metadata[JSServerLevelMetadataKey] = strconv.Itoa(JSApiLevel) diff --git a/vendor/github.com/nats-io/nats-server/v2/server/jwt.go b/vendor/github.com/nats-io/nats-server/v2/server/jwt.go index 04d7dc60a3..82d65d90d5 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/jwt.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/jwt.go @@ -80,7 +80,11 @@ func validateTrustedOperators(o *Options) error { if err != nil { return fmt.Errorf("default sentinel JWT not valid") } - if !juc.BearerToken { + + if !juc.BearerToken && juc.IssuerAccount != "" && juc.HasEmptyPermissions() { + // we cannot resolve the account yet - but this looks like a scoped user + // it will be rejected at runtime if not valid + } else if !juc.BearerToken { return fmt.Errorf("default sentinel must be a bearer token") } } diff --git a/vendor/github.com/nats-io/nats-server/v2/server/leafnode.go b/vendor/github.com/nats-io/nats-server/v2/server/leafnode.go index f49544812f..8b64c08001 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/leafnode.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/leafnode.go @@ -1418,7 +1418,7 @@ func (c *client) processLeafnodeInfo(info *Info) { c.setPermissions(perms) } - var resumeConnect, checkSyncConsumers bool + var resumeConnect bool // If this is a remote connection and this is the first INFO protocol, // then we need to finish the connect process by sending CONNECT, etc.. @@ -1428,7 +1428,6 @@ func (c *client) processLeafnodeInfo(info *Info) { resumeConnect = true } else if !firstINFO && didSolicit { c.leaf.remoteAccName = info.RemoteAccount - checkSyncConsumers = info.JetStream } // Check if we have the remote account information and if so make sure it's stored. @@ -1448,11 +1447,10 @@ func (c *client) processLeafnodeInfo(info *Info) { s.leafNodeFinishConnectProcess(c) } - // If we have JS enabled and so does the other side, we will - // check to see if we need to kick any internal source or mirror consumers. - if checkSyncConsumers { - s.checkInternalSyncConsumers(c.acc, info.Domain) - } + // Check to see if we need to kick any internal source or mirror consumers. + // This will be a no-op if JetStream not enabled for this server or if the bound account + // does not have jetstream. + s.checkInternalSyncConsumers(c.acc) } func (s *Server) negotiateLeafCompression(c *client, didSolicit bool, infoCompression string, co *CompressionOpts) (bool, error) { @@ -1984,16 +1982,16 @@ func (c *client) processLeafNodeConnect(s *Server, arg []byte, lang string) erro // This will be a no-op as needed. s.sendLeafNodeConnect(c.acc) - // If we have JS enabled and so does the other side, we will - // check to see if we need to kick any internal source or mirror consumers. - if proto.JetStream { - s.checkInternalSyncConsumers(acc, proto.Domain) - } + // Check to see if we need to kick any internal source or mirror consumers. + // This will be a no-op if JetStream not enabled for this server or if the bound account + // does not have jetstream. + s.checkInternalSyncConsumers(acc) + return nil } // checkInternalSyncConsumers -func (s *Server) checkInternalSyncConsumers(acc *Account, remoteDomain string) { +func (s *Server) checkInternalSyncConsumers(acc *Account) { // Grab our js js := s.getJetStream() @@ -2012,6 +2010,7 @@ func (s *Server) checkInternalSyncConsumers(acc *Account, remoteDomain string) { if jsa == nil { return } + var streams []*stream jsa.mu.RLock() for _, mset := range jsa.streams { @@ -2029,7 +2028,7 @@ func (s *Server) checkInternalSyncConsumers(acc *Account, remoteDomain string) { // Now loop through all candidates and check if we are the leader and have NOT // created the sync up consumer. for _, mset := range streams { - mset.retryDisconnectedSyncConsumers(remoteDomain) + mset.retryDisconnectedSyncConsumers() } } @@ -2228,9 +2227,11 @@ func (s *Server) updateInterestForAccountOnGateway(accName string, sub *subscrip acc.updateLeafNodes(sub, delta) } -// updateLeafNodes will make sure to update the account smap for the subscription. +// updateLeafNodesEx will make sure to update the account smap for the subscription. // Will also forward to all leaf nodes as needed. -func (acc *Account) updateLeafNodes(sub *subscription, delta int32) { +// If `hubOnly` is true, then will update only leaf nodes that connect to this server +// (that is, for which this server acts as a hub to them). +func (acc *Account) updateLeafNodesEx(sub *subscription, delta int32, hubOnly bool) { if acc == nil || sub == nil { return } @@ -2278,8 +2279,14 @@ func (acc *Account) updateLeafNodes(sub *subscription, delta int32) { if ln == sub.client { continue } - // Check to make sure this sub does not have an origin cluster that matches the leafnode. ln.mu.Lock() + // If `hubOnly` is true, it means that we want to update only leafnodes + // that connect to this server (so isHubLeafNode() would return `true`). + if hubOnly && !ln.isHubLeafNode() { + ln.mu.Unlock() + continue + } + // Check to make sure this sub does not have an origin cluster that matches the leafnode. // If skipped, make sure that we still let go the "$LDS." subscription that allows // the detection of loops as long as different cluster. clusterDifferent := cluster != ln.remoteCluster() @@ -2290,6 +2297,12 @@ func (acc *Account) updateLeafNodes(sub *subscription, delta int32) { } } +// updateLeafNodes will make sure to update the account smap for the subscription. +// Will also forward to all leaf nodes as needed. +func (acc *Account) updateLeafNodes(sub *subscription, delta int32) { + acc.updateLeafNodesEx(sub, delta, false) +} + // This will make an update to our internal smap and determine if we should send out // an interest update to the remote side. // Lock should be held. diff --git a/vendor/github.com/nats-io/nats-server/v2/server/monitor.go b/vendor/github.com/nats-io/nats-server/v2/server/monitor.go index b160d9d89a..352d0b7cb9 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/monitor.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/monitor.go @@ -3788,6 +3788,9 @@ func (s *Server) healthz(opts *HealthzOptions) *HealthStatus { } for stream, sa := range asa { + if sa != nil && sa.unsupported != nil { + continue + } // Make sure we can look up if err := js.isStreamHealthy(acc, sa); err != nil { if !details { @@ -3905,11 +3908,14 @@ type RaftzGroup struct { Applied uint64 `json:"applied"` CatchingUp bool `json:"catching_up,omitempty"` Leader string `json:"leader,omitempty"` + LeaderSince *time.Time `json:"leader_since,omitempty"` EverHadLeader bool `json:"ever_had_leader"` Term uint64 `json:"term"` Vote string `json:"voted_for,omitempty"` PTerm uint64 `json:"pterm"` PIndex uint64 `json:"pindex"` + SystemAcc bool `json:"system_account"` + TrafficAcc string `json:"traffic_account"` IPQPropLen int `json:"ipq_proposal_len"` IPQEntryLen int `json:"ipq_entry_len"` IPQRespLen int `json:"ipq_resp_len"` @@ -4010,11 +4016,14 @@ func (s *Server) Raftz(opts *RaftzOptions) *RaftzStatus { Applied: n.applied, CatchingUp: n.catchup != nil, Leader: n.leader, + LeaderSince: n.leaderSince.Load(), EverHadLeader: n.pleader.Load(), Term: n.term, Vote: n.vote, PTerm: n.pterm, PIndex: n.pindex, + SystemAcc: n.IsSystemAccount(), + TrafficAcc: n.acc.GetName(), IPQPropLen: n.prop.len(), IPQEntryLen: n.entry.len(), IPQRespLen: n.resp.len(), diff --git a/vendor/github.com/nats-io/nats-server/v2/server/raft.go b/vendor/github.com/nats-io/nats-server/v2/server/raft.go index 32b7d9182c..902f12078d 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/raft.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/raft.go @@ -31,6 +31,7 @@ import ( "sync/atomic" "time" + "github.com/antithesishq/antithesis-sdk-go/assert" "github.com/nats-io/nats-server/v2/internal/fastrand" "github.com/minio/highwayhash" @@ -48,6 +49,7 @@ type RaftNode interface { Size() (entries, bytes uint64) Progress() (index, commit, applied uint64) Leader() bool + LeaderSince() *time.Time Quorum() bool Current() bool Healthy() bool @@ -81,6 +83,7 @@ type RaftNode interface { Delete() RecreateInternalSubs() error IsSystemAccount() bool + GetTrafficAccountName() string } type WAL interface { @@ -145,10 +148,11 @@ type raft struct { bytes uint64 // Total amount of bytes stored in the WAL. (Saves us from needing to call wal.FastState very often) werr error // Last write error - state atomic.Int32 // RaftState - leaderState atomic.Bool // Is in (complete) leader state. - hh hash.Hash64 // Highwayhash, used for snapshots - snapfile string // Snapshot filename + state atomic.Int32 // RaftState + leaderState atomic.Bool // Is in (complete) leader state. + leaderSince atomic.Pointer[time.Time] // How long since becoming leader. + hh hash.Hash64 // Highwayhash, used for snapshots + snapfile string // Snapshot filename csz int // Cluster size qn int // Number of nodes needed to establish quorum @@ -579,6 +583,13 @@ func (n *raft) IsSystemAccount() bool { return n.isSysAcc.Load() } +// GetTrafficAccountName returns the account name of the account used for replication traffic. +func (n *raft) GetTrafficAccountName() string { + n.RLock() + defer n.RUnlock() + return n.acc.GetName() +} + func (n *raft) RecreateInternalSubs() error { n.Lock() defer n.Unlock() @@ -1092,7 +1103,11 @@ func (n *raft) Applied(index uint64) (entries uint64, bytes uint64) { // Quick sanity-check to confirm we're still leader. // In which case we must signal, since switchToLeader would not have done so already. if n.State() == Leader { - n.leaderState.Store(true) + if !n.leaderState.Swap(true) { + // Only update timestamp if leader state actually changed. + nowts := time.Now().UTC() + n.leaderSince.Store(&nowts) + } n.updateLeadChange(true) } } @@ -1399,6 +1414,15 @@ func (n *raft) Leader() bool { return n.leaderState.Load() } +// LeaderSince returns how long we have been leader for, +// if applicable. +func (n *raft) LeaderSince() *time.Time { + if n == nil { + return nil + } + return n.leaderSince.Load() +} + // stepdown immediately steps down the Raft node to the // follower state. This will take the lock itself. func (n *raft) stepdown(newLeader string) { @@ -1813,6 +1837,7 @@ func (n *raft) shutdown() { // to notify the runAs goroutines to stop what they're doing. if n.state.Swap(int32(Closed)) != int32(Closed) { n.leaderState.Store(false) + n.leaderSince.Store(nil) close(n.quit) } } @@ -3300,6 +3325,14 @@ func (n *raft) truncateWAL(term, index uint64) { n.debug("Clearing WAL state (no commits)") } } + if index < n.commit { + assert.Unreachable("WAL truncate lost commits", map[string]any{ + "term": term, + "index": index, + "commit": n.commit, + "applied": n.applied, + }) + } defer func() { // Check to see if we invalidated any snapshots that might have held state @@ -3388,7 +3421,6 @@ func (n *raft) processAppendEntry(ae *appendEntry, sub *subscription) { // Are we receiving from another leader. if n.State() == Leader { - // If we are the same we should step down to break the tie. if lterm >= n.term { // If the append entry term is newer than the current term, erase our // vote. @@ -3396,6 +3428,16 @@ func (n *raft) processAppendEntry(ae *appendEntry, sub *subscription) { n.term = lterm n.vote = noVote n.writeTermVote() + } else { + assert.Unreachable( + "Two leaders using the same term", + map[string]any{ + "Node id": n.id, + "Node term": n.term, + "AppendEntry id": ae.leader, + "AppendEntry term": ae.term, + "AppendEntry lterm": ae.lterm, + }) } n.debug("Received append entry from another leader, stepping down to %q", ae.leader) n.stepdownLocked(ae.leader) @@ -3444,22 +3486,50 @@ func (n *raft) processAppendEntry(ae *appendEntry, sub *subscription) { } } - // If we are/were catching up ignore old catchup subs. - // This could happen when we stall or cancel a catchup. - if !isNew && sub != nil && (!catchingUp || sub != n.catchup.sub) { + // If we are/were catching up ignore old catchup subs, but only if catching up from an older server + // that doesn't send the leader term when catching up. We can reject old catchups from newer subs + // later, just by checking the append entry is on the correct term. + if !isNew && sub != nil && ae.lterm == 0 && (!catchingUp || sub != n.catchup.sub) { n.Unlock() n.debug("AppendEntry ignoring old entry from previous catchup") return } + // If this term is greater than ours. + if lterm > n.term { + n.term = lterm + n.vote = noVote + if isNew { + n.writeTermVote() + } + if n.State() != Follower { + n.debug("Term higher than ours and we are not a follower: %v, stepping down to %q", n.State(), ae.leader) + n.stepdownLocked(ae.leader) + } + } else if lterm < n.term && sub != nil && (isNew || ae.lterm != 0) { + // Anything that's below our expected highest term needs to be rejected. + // Unless we're replaying (sub=nil), in which case we'll always continue. + // For backward-compatibility we shouldn't reject if we're being caught up by an old server. + if !isNew { + n.debug("AppendEntry ignoring old entry from previous catchup") + n.Unlock() + return + } + n.debug("Rejected AppendEntry from a leader (%s) with term %d which is less than ours", ae.leader, lterm) + ar := newAppendEntryResponse(n.term, n.pindex, n.id, false) + n.Unlock() + n.sendRPC(ae.reply, _EMPTY_, ar.encode(arbuf)) + arPool.Put(ar) + return + } + // Check state if we are catching up. - var resetCatchingUp bool if catchingUp { if cs := n.catchup; cs != nil && n.pterm >= cs.cterm && n.pindex >= cs.cindex { // If we are here we are good, so if we have a catchup pending we can cancel. n.cancelCatchup() // Reset our notion of catching up. - resetCatchingUp = true + catchingUp = false } else if isNew { var ar *appendEntryResponse var inbox string @@ -3479,34 +3549,6 @@ func (n *raft) processAppendEntry(ae *appendEntry, sub *subscription) { } } - // If this term is greater than ours. - if lterm > n.term { - n.term = lterm - n.vote = noVote - if isNew { - n.writeTermVote() - } - if n.State() != Follower { - n.debug("Term higher than ours and we are not a follower: %v, stepping down to %q", n.State(), ae.leader) - n.stepdownLocked(ae.leader) - } - } else if lterm < n.term && sub != nil && !(catchingUp && ae.lterm == 0) { - // Anything that's below our expected highest term needs to be rejected. - // Unless we're replaying (sub=nil), in which case we'll always continue. - // For backward-compatibility we shouldn't reject if we're being caught up by an old server. - n.debug("Rejected AppendEntry from a leader (%s) with term %d which is less than ours", ae.leader, lterm) - ar := newAppendEntryResponse(n.term, n.pindex, n.id, false) - n.Unlock() - n.sendRPC(ae.reply, _EMPTY_, ar.encode(arbuf)) - arPool.Put(ar) - return - } - - // Reset after checking the term is correct, because we use catchingUp in a condition above. - if resetCatchingUp { - catchingUp = false - } - if isNew && n.leader != ae.leader && n.State() == Follower { n.debug("AppendEntry updating leader to %q", ae.leader) n.updateLeader(ae.leader) @@ -3647,21 +3689,7 @@ CONTINUE: n.Unlock() return } - // Save in memory for faster processing during applyCommit. - // Only save so many however to avoid memory bloat. - if l := len(n.pae); l <= paeDropThreshold { - n.pae[n.pindex], l = ae, l+1 - if l > paeWarnThreshold && l%paeWarnModulo == 0 { - n.warn("%d append entries pending", len(n.pae)) - } - } else { - // Invalidate cache entry at this index, we might have - // stored it previously with a different value. - delete(n.pae, n.pindex) - if l%paeWarnModulo == 0 { - n.debug("Not saving to append entries pending") - } - } + n.cachePendingEntry(ae) } else { // This is a replay on startup so just take the appendEntry version. n.pterm = ae.term @@ -3880,12 +3908,7 @@ func (n *raft) sendAppendEntry(entries []*Entry) { return } n.active = time.Now() - - // Save in memory for faster processing during applyCommit. - n.pae[n.pindex] = ae - if l := len(n.pae); l > paeWarnThreshold && l%paeWarnModulo == 0 { - n.warn("%d append entries pending", len(n.pae)) - } + n.cachePendingEntry(ae) } n.sendRPC(n.asubj, n.areply, ae.buf) if !shouldStore { @@ -3893,6 +3916,21 @@ func (n *raft) sendAppendEntry(entries []*Entry) { } } +// cachePendingEntry saves append entries in memory for faster processing during applyCommit. +// Only save so many however to avoid memory bloat. +func (n *raft) cachePendingEntry(ae *appendEntry) { + if l := len(n.pae); l < paeDropThreshold { + n.pae[n.pindex], l = ae, l+1 + if l >= paeWarnThreshold && l%paeWarnModulo == 0 { + n.warn("%d append entries pending", len(n.pae)) + } + } else { + // Invalidate cache entry at this index, we might have + // stored it previously with a different value. + delete(n.pae, n.pindex) + } +} + type extensionState uint16 const ( @@ -4392,6 +4430,7 @@ func (n *raft) switchToFollowerLocked(leader string) { n.aflr = 0 n.leaderState.Store(false) + n.leaderSince.Store(nil) n.lxfer = false // Reset acks, we can't assume acks from a previous term are still valid in another term. if len(n.acks) > 0 { @@ -4458,7 +4497,11 @@ func (n *raft) switchToLeader() { // We know we have applied all entries in our log and can signal immediately. // For sanity reset applied floor back down to 0, so we aren't able to signal twice. n.aflr = 0 - n.leaderState.Store(true) + if !n.leaderState.Swap(true) { + // Only update timestamp if leader state actually changed. + nowts := time.Now().UTC() + n.leaderSince.Store(&nowts) + } n.updateLeadChange(true) } } diff --git a/vendor/github.com/nats-io/nats-server/v2/server/route.go b/vendor/github.com/nats-io/nats-server/v2/server/route.go index 2d72e6fe58..ac4d9c66b8 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/route.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/route.go @@ -87,6 +87,17 @@ type route struct { // Transient value used to set the Info.GossipMode when initiating // an implicit route and sending to the remote. gossipMode byte + // This will be set in case of pooling so that a route can trigger + // the creation of the next after receiving the first PONG, ensuring + // that authentication did not fail. + startNewRoute *routeInfo +} + +// This contains the information required to create a new route. +type routeInfo struct { + url *url.URL + rtype RouteType + gossipMode byte } // Do not change the values/order since they are exchanged between servers. @@ -2379,20 +2390,18 @@ func (s *Server) addRoute(c *client, didSolicit, sendDelayedInfo bool, gossipMod // Send the subscriptions interest. s.sendSubsToRoute(c, idx, _EMPTY_) - // In pool mode, if we did not yet reach the cap, try to connect a new connection + // In pool mode, if we did not yet reach the cap, try to connect a new connection, + // but do so only after receiving the first PONG to our PING, which will ensure + // that we have proper authentication. if pool && didSolicit && sz != effectivePoolSize { - s.startGoRoutine(func() { - select { - case <-time.After(time.Duration(rand.Intn(100)) * time.Millisecond): - case <-s.quitCh: - // Doing this here and not as a defer because connectToRoute is also - // calling s.grWG.Done() on exit, so we do this only if we don't - // invoke connectToRoute(). - s.grWG.Done() - return - } - s.connectToRoute(url, rtype, true, gossipMode, _EMPTY_) - }) + c.mu.Lock() + c.route.startNewRoute = &routeInfo{ + url: url, + rtype: rtype, + gossipMode: gossipMode, + } + c.sendPing() + c.mu.Unlock() } } s.mu.Unlock() diff --git a/vendor/github.com/nats-io/nats-server/v2/server/stream.go b/vendor/github.com/nats-io/nats-server/v2/server/stream.go index 9029427fc5..03330205a2 100644 --- a/vendor/github.com/nats-io/nats-server/v2/server/stream.go +++ b/vendor/github.com/nats-io/nats-server/v2/server/stream.go @@ -205,6 +205,13 @@ type StreamInfo struct { TimeStamp time.Time `json:"ts"` } +// streamInfoClusterResponse is a response used in a cluster to communicate the stream info +// back to the meta leader as part of a stream list request. +type streamInfoClusterResponse struct { + StreamInfo + OfflineReason string `json:"offline_reason,omitempty"` // Reporting when a stream is offline. +} + type StreamAlternate struct { Name string `json:"name"` Domain string `json:"domain,omitempty"` @@ -214,10 +221,13 @@ type StreamAlternate struct { // ClusterInfo shows information about the underlying set of servers // that make up the stream or consumer. type ClusterInfo struct { - Name string `json:"name,omitempty"` - RaftGroup string `json:"raft_group,omitempty"` - Leader string `json:"leader,omitempty"` - Replicas []*PeerInfo `json:"replicas,omitempty"` + Name string `json:"name,omitempty"` + RaftGroup string `json:"raft_group,omitempty"` + Leader string `json:"leader,omitempty"` + LeaderSince *time.Time `json:"leader_since,omitempty"` + SystemAcc bool `json:"system_account,omitempty"` + TrafficAcc string `json:"traffic_account,omitempty"` + Replicas []*PeerInfo `json:"replicas,omitempty"` } // PeerInfo shows information about all the peers in the cluster that @@ -375,6 +385,10 @@ type stream struct { lastBySub *subscription monitorWg sync.WaitGroup // Wait group for the monitor routine. + + // If standalone/single-server, the offline reason needs to be stored directly in the stream. + // Otherwise, if clustered it will be part of the stream assignment. + offlineReason string } type sourceInfo struct { @@ -937,6 +951,17 @@ func (mset *stream) monitorQuitC() <-chan struct{} { return mset.mqch } +// signalMonitorQuit signals to exit the monitor loop. If there's no Raft node, +// this will be the only way to stop the monitor goroutine. +func (mset *stream) signalMonitorQuit() { + mset.mu.Lock() + defer mset.mu.Unlock() + if mset.mqch != nil { + close(mset.mqch) + mset.mqch = nil + } +} + func (mset *stream) updateC() <-chan struct{} { if mset == nil { return nil @@ -1778,6 +1803,10 @@ func (s *Server) checkStreamCfg(config *StreamConfig, acc *Account, pedantic boo } } + // Remove placement if it's an empty object. + if cfg.Placement != nil && reflect.DeepEqual(cfg.Placement, &Placement{}) { + cfg.Placement = nil + } // For now don't allow preferred server in placement. if cfg.Placement != nil && cfg.Placement.Preferred != _EMPTY_ { return StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf("preferred server not permitted in placement")) @@ -2420,7 +2449,7 @@ func (mset *stream) mirrorInfo() *StreamSourceInfo { // retryDisconnectedSyncConsumers() will check if we have any disconnected // sync consumers for either mirror or a source and will reset and retry to connect. -func (mset *stream) retryDisconnectedSyncConsumers(remoteDomain string) { +func (mset *stream) retryDisconnectedSyncConsumers() { mset.mu.Lock() defer mset.mu.Unlock() @@ -2429,23 +2458,24 @@ func (mset *stream) retryDisconnectedSyncConsumers(remoteDomain string) { return } + shouldRetry := func(si *sourceInfo) bool { + if si != nil && (si.sip || si.sub == nil || (si.sub.client != nil && si.sub.client.isClosed())) { + // Need to reset + si.fails, si.sip = 0, false + mset.cancelSourceInfo(si) + return true + } + return false + } + // Check mirrors first. if si := mset.mirror; si != nil { - if si.sub == nil && !si.sip { - if remoteDomain == _EMPTY_ || (mset.cfg.Mirror != nil && mset.cfg.Mirror.External.Domain() == remoteDomain) { - // Need to reset - si.fails = 0 - mset.cancelSourceInfo(si) - mset.scheduleSetupMirrorConsumerRetry() - } + if shouldRetry(si) { + mset.scheduleSetupMirrorConsumerRetry() } } else { for _, si := range mset.sources { - ss := mset.streamSource(si.iname) - if remoteDomain == _EMPTY_ || (ss != nil && ss.External.Domain() == remoteDomain) { - // Need to reset - si.fails = 0 - mset.cancelSourceInfo(si) + if shouldRetry(si) { mset.setupSourceConsumer(si.iname, si.sseq+1, time.Time{}) } } @@ -2970,7 +3000,8 @@ func (mset *stream) setupMirrorConsumer() error { if mset.mirror != nil { mset.mirror.sip = false // If we need to retry, schedule now - if retry { + // If sub is not nil means we re-established somewhere else so do not re-attempt here. + if retry && mset.mirror.sub == nil { mset.mirror.fails++ // Cancel here since we can not do anything with this consumer at this point. mset.cancelSourceInfo(mset.mirror) @@ -3331,7 +3362,8 @@ func (mset *stream) trySetupSourceConsumer(iname string, seq uint64, startTime t if si := mset.sources[iname]; si != nil { si.sip = false // If we need to retry, schedule now - if retry { + // If sub is not nil means we re-established somewhere else so do not re-attempt here. + if retry && si.sub == nil { si.fails++ // Cancel here since we can not do anything with this consumer at this point. mset.cancelSourceInfo(si) @@ -5275,6 +5307,8 @@ func (mset *stream) processJetStreamMsg(subject, reply string, hdr, msg []byte, if ttl > 0 && mset.cfg.SubjectDeleteMarkerTTL > 0 && mset.cfg.MaxMsgsPer != 1 { if minTtl := int64(mset.cfg.SubjectDeleteMarkerTTL.Seconds()); ttl < minTtl { ttl = minTtl + hdr = removeHeaderIfPresent(hdr, JSMessageTTL) + hdr = genHeader(hdr, JSMessageTTL, strconv.FormatInt(ttl, 10)) } } @@ -5740,6 +5774,7 @@ func (mset *stream) resetAndWaitOnConsumers() { node.Stop() } if o.isMonitorRunning() { + o.signalMonitorQuit() o.monitorWg.Wait() } } @@ -5756,7 +5791,7 @@ func (mset *stream) delete() error { // Internal function to stop or delete the stream. func (mset *stream) stop(deleteFlag, advisory bool) error { mset.mu.RLock() - js, jsa, name := mset.js, mset.jsa, mset.cfg.Name + js, jsa, name, offlineReason := mset.js, mset.jsa, mset.cfg.Name, mset.offlineReason mset.mu.RUnlock() if jsa == nil { @@ -5765,7 +5800,10 @@ func (mset *stream) stop(deleteFlag, advisory bool) error { // Remove from our account map first. jsa.mu.Lock() - delete(jsa.streams, name) + // Preserve in the account if it's marked offline, to have it remain queryable. + if deleteFlag || offlineReason == _EMPTY_ { + delete(jsa.streams, name) + } accName := jsa.account.Name jsa.mu.Unlock() @@ -5798,9 +5836,12 @@ func (mset *stream) stop(deleteFlag, advisory bool) error { for _, o := range mset.consumers { obs = append(obs, o) } - mset.clsMu.Lock() - mset.consumers, mset.cList, mset.csl = nil, nil, nil - mset.clsMu.Unlock() + // Preserve the consumers if it's marked offline, to have them remain queryable. + if deleteFlag || offlineReason == _EMPTY_ { + mset.clsMu.Lock() + mset.consumers, mset.cList, mset.csl = nil, nil, nil + mset.clsMu.Unlock() + } // Check if we are a mirror. if mset.mirror != nil && mset.mirror.sub != nil { @@ -5824,6 +5865,7 @@ func (mset *stream) stop(deleteFlag, advisory bool) error { // but should we log? o.stopWithFlags(deleteFlag, deleteFlag, false, advisory) if !isShuttingDown { + o.signalMonitorQuit() o.monitorWg.Wait() } } @@ -5901,14 +5943,17 @@ func (mset *stream) stop(deleteFlag, advisory bool) error { } if deleteFlag { + // cleanup directories after the stream + accDir := filepath.Join(js.config.StoreDir, accName) if store != nil { // Ignore errors. store.Delete() + } else { + streamDir := filepath.Join(accDir, streamsDir) + os.RemoveAll(filepath.Join(streamDir, name)) } // Release any resources. js.releaseStreamResources(&mset.cfg) - // cleanup directories after the stream - accDir := filepath.Join(js.config.StoreDir, accName) // Do cleanup in separate go routine similar to how fs will use purge here.. go func() { // no op if not empty diff --git a/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/internal/grace/grace.go b/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/internal/grace/grace.go index 0366d05558..41cc78a821 100644 --- a/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/internal/grace/grace.go +++ b/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/internal/grace/grace.go @@ -297,9 +297,6 @@ func (w *Watcher) TrapSignals() { } } -// TODO: Ideally this would call exit() but properly return an error. The -// exit() is problematic (i.e. racey) especiaily when orchestrating multiple -// reva services from some external runtime (like in the "opencloud server" case func gracefulShutdown(w *Watcher) { defer w.Clean() w.log.Info().Int("Timeout", w.gracefulShutdownTimeout).Msg("preparing for a graceful shutdown with deadline") @@ -309,7 +306,7 @@ func gracefulShutdown(w *Watcher) { wg.Add(1) go func() { defer wg.Done() - w.log.Info().Msgf("fd to %s:%s gracefully closed", s.Network(), s.Address()) + w.log.Info().Str("network.transport", s.Network()).Str("network.local.address", s.Address()).Msg("fd gracefully closed") err := s.GracefulStop() if err != nil { w.log.Error().Err(err).Msg("error stopping server") @@ -327,7 +324,7 @@ func gracefulShutdown(w *Watcher) { case <-time.After(time.Duration(w.gracefulShutdownTimeout) * time.Second): w.log.Info().Msg("graceful shutdown timeout reached. running hard shutdown") for _, s := range w.ss { - w.log.Info().Msgf("fd to %s:%s abruptly closed", s.Network(), s.Address()) + w.log.Info().Str("network.transport", s.Network()).Str("network.local.address", s.Address()).Msg("fd abruptly closed") err := s.Stop() if err != nil { w.log.Error().Err(err).Msg("error stopping server") @@ -340,21 +337,6 @@ func gracefulShutdown(w *Watcher) { } } -// TODO: Ideally this would call exit() but properly return an error. The -// exit() is problematic (i.e. racey) especiaily when orchestrating multiple -// reva services from some external runtime (like in the "opencloud server" case -func hardShutdown(w *Watcher) { - w.log.Info().Msg("preparing for hard shutdown, aborting all conns") - for _, s := range w.ss { - w.log.Info().Msgf("fd to %s:%s abruptly closed", s.Network(), s.Address()) - err := s.Stop() - if err != nil { - w.log.Error().Err(err).Msg("error stopping server") - } - } - w.Exit(0) -} - func getListenerFile(ln net.Listener) (*os.File, error) { switch t := ln.(type) { case *net.TCPListener: diff --git a/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/runtime/drivenserver.go b/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/runtime/drivenserver.go index b9eb819ece..0a9e4fad65 100644 --- a/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/runtime/drivenserver.go +++ b/vendor/github.com/opencloud-eu/reva/v2/cmd/revad/runtime/drivenserver.go @@ -45,16 +45,18 @@ type server struct { // Returns nil if no http server is configured in the config file. // The GracefulShutdownTimeout set to default 20 seconds and can be overridden in the core config. // Logging a fatal error and exit with code 1 if the http server cannot be created. -func NewDrivenHTTPServerWithOptions(mainConf map[string]interface{}, opts ...Option) RevaDrivenServer { +func NewDrivenHTTPServerWithOptions(mainConf map[string]interface{}, opts ...Option) *server { if !isEnabledHTTP(mainConf) { return nil } options := newOptions(opts...) - if srv := newServer(HTTP, mainConf, options); srv != nil { - return srv + var srv *server + var err error + if srv, err = newServer(HTTP, mainConf, options); err != nil { + options.Logger.Fatal().Err(err).Msg("failed to create http server") } - options.Logger.Fatal().Msg("nothing to do, no http enabled_services declared in config") - return nil + return srv + } // NewDrivenGRPCServerWithOptions runs a revad server w/o watcher with the given config file and options. @@ -62,36 +64,37 @@ func NewDrivenHTTPServerWithOptions(mainConf map[string]interface{}, opts ...Opt // Returns nil if no grpc server is configured in the config file. // The GracefulShutdownTimeout set to default 20 seconds and can be overridden in the core config. // Logging a fatal error and exit with code 1 if the grpc server cannot be created. -func NewDrivenGRPCServerWithOptions(mainConf map[string]interface{}, opts ...Option) RevaDrivenServer { +func NewDrivenGRPCServerWithOptions(mainConf map[string]interface{}, opts ...Option) *server { if !isEnabledGRPC(mainConf) { return nil } options := newOptions(opts...) - if srv := newServer(GRPC, mainConf, options); srv != nil { - return srv + var srv *server + var err error + if srv, err = newServer(GRPC, mainConf, options); err != nil { + options.Logger.Fatal().Err(err).Msg("failed to create grpc server") } - options.Logger.Fatal().Msg("nothing to do, no grpc enabled_services declared in config") - return nil + return srv } // Start starts the reva server, listening on the configured address and network. func (s *server) Start() error { if s.srv == nil { - err := fmt.Errorf("reva %s server not initialized", s.protocol) - s.log.Fatal().Err(err).Send() - return err + return fmt.Errorf("reva %s server not initialized", s.protocol) } ln, err := net.Listen(s.srv.Network(), s.srv.Address()) if err != nil { - s.log.Fatal().Err(err).Send() return err } if err = s.srv.Start(ln); err != nil { if !errors.Is(err, http.ErrServerClosed) { - s.log.Error().Err(err).Msgf("reva %s server error", s.protocol) + s.log.Error().Err(err).Msg("reva server error") } return err } + // update logger with transport and address + logger := s.log.With().Str("network.transport", s.srv.Network()).Str("network.local.address", s.srv.Address()).Logger() + s.log = &logger return nil } @@ -102,10 +105,13 @@ func (s *server) Stop() error { } done := make(chan struct{}) go func() { - s.log.Info().Msgf("gracefully stopping %s:%s reva %s server", s.srv.Network(), s.srv.Address(), s.protocol) + s.log.Info().Msg("gracefully stopping reva server") if err := s.srv.GracefulStop(); err != nil { - s.log.Error().Err(err).Msgf("error gracefully stopping reva %s server", s.protocol) - s.srv.Stop() + s.log.Error().Err(err).Msg("error gracefully stopping reva server") + err := s.srv.Stop() + if err != nil { + s.log.Error().Err(err).Msg("error stopping reva server") + } } close(done) }() @@ -115,64 +121,66 @@ func (s *server) Stop() error { s.log.Info().Msg("graceful shutdown timeout reached. running hard shutdown") err := s.srv.Stop() if err != nil { - s.log.Error().Err(err).Msgf("error stopping reva %s server", s.protocol) + s.log.Error().Err(err).Msg("error stopping reva server") } return nil case <-done: - s.log.Info().Msgf("reva %s server gracefully stopped", s.protocol) + s.log.Info().Msg("reva server gracefully stopped") return nil } } // newServer runs a revad server w/o watcher with the given config file and options. -func newServer(protocol int, mainConf map[string]interface{}, options Options) RevaDrivenServer { +func newServer(protocol int, mainConf map[string]interface{}, options Options) (*server, error) { parseSharedConfOrDie(mainConf["shared"]) coreConf := parseCoreConfOrDie(mainConf["core"]) - log := options.Logger if err := registry.Init(options.Registry); err != nil { - log.Fatal().Err(err).Msg("failed to initialize registry client") - return nil + return nil, err } + srv := &server{} + + // update logger with hostname host, _ := os.Hostname() - log.Info().Msgf("host info: %s", host) + logger := options.Logger.With().Str("host.name", host).Logger() + srv.log = &logger // Only initialize tracing if we didn't get a tracer provider. if options.TraceProvider == nil { - log.Debug().Msg("no pre-existing tracer given, initializing tracing") + srv.log.Debug().Msg("no pre-existing tracer given, initializing tracing") options.TraceProvider = initTracing(coreConf) } - initCPUCount(coreConf, log) + initCPUCount(coreConf, srv.log) - gracefulShutdownTimeout := 20 * time.Second + srv.gracefulShutdownTimeout = 20 * time.Second if coreConf.GracefulShutdownTimeout > 0 { - gracefulShutdownTimeout = time.Duration(coreConf.GracefulShutdownTimeout) * time.Second + srv.gracefulShutdownTimeout = time.Duration(coreConf.GracefulShutdownTimeout) * time.Second } - srv := &server{ - log: options.Logger, - gracefulShutdownTimeout: gracefulShutdownTimeout, - } switch protocol { case HTTP: - s, err := getHTTPServer(mainConf["http"], options.Logger, options.TraceProvider) + s, err := getHTTPServer(mainConf["http"], srv.log, options.TraceProvider) if err != nil { - options.Logger.Fatal().Err(err).Msg("error creating http server") - return nil + return nil, err } srv.srv = s srv.protocol = "http" - return srv + // update logger with protocol + logger := srv.log.With().Str("protocol", "http").Logger() + srv.log = &logger + return srv, nil case GRPC: - s, err := getGRPCServer(mainConf["grpc"], options.Logger, options.TraceProvider) + s, err := getGRPCServer(mainConf["grpc"], srv.log, options.TraceProvider) if err != nil { - options.Logger.Fatal().Err(err).Msg("error creating grpc server") - return nil + return nil, err } srv.srv = s srv.protocol = "grpc" - return srv + // update logger with protocol + logger := srv.log.With().Str("protocol", "grpc").Logger() + srv.log = &logger + return srv, nil } - return nil + return nil, fmt.Errorf("unknown protocol: %d", protocol) } diff --git a/vendor/github.com/shamaton/msgpack/v2/LICENSE b/vendor/github.com/shamaton/msgpack/v2/LICENSE index a5810edab9..5593a580bf 100644 --- a/vendor/github.com/shamaton/msgpack/v2/LICENSE +++ b/vendor/github.com/shamaton/msgpack/v2/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 Masayuki Shamoto +Copyright (c) 2025 Masayuki Shamoto Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/vendor/github.com/shamaton/msgpack/v2/README.md b/vendor/github.com/shamaton/msgpack/v2/README.md index a8aa22f27b..97f5b7d85d 100644 --- a/vendor/github.com/shamaton/msgpack/v2/README.md +++ b/vendor/github.com/shamaton/msgpack/v2/README.md @@ -6,15 +6,12 @@ [![codecov](https://codecov.io/gh/shamaton/msgpack/branch/master/graph/badge.svg?token=9PD2JUK5V3)](https://codecov.io/gh/shamaton/msgpack) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fshamaton%2Fmsgpack.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fshamaton%2Fmsgpack?ref=badge_shield) -## 📣 Notice -If your application serializes only primitive types, array, map and struct, code generation is also recommended. -You can get the fastest performance with [msgpackgen](https://github.com/shamaton/msgpackgen). - ## Features * Supported types : primitive / array / slice / struct / map / interface{} and time.Time * Renaming fields via `msgpack:"field_name"` * Omitting fields via `msgpack:"-"` -* Supports extend encoder / decoder +* Omitting empty fields via `msgpack:"field_name,omitempty"` +* Supports extend encoder / decoder [(example)](./msgpack_example_test.go) * Can also Encoding / Decoding struct as array ## Installation @@ -66,7 +63,7 @@ func handle(w http.ResponseWriter, r *http.Request) { ## Benchmark This result made from [shamaton/msgpack_bench](https://github.com/shamaton/msgpack_bench) -![msgpack_bench](https://user-images.githubusercontent.com/4637556/128299009-4823e79b-d70b-4d11-8f35-10a4758dfeca.png) +![msgpack_bench](https://github.com/user-attachments/assets/ed5bc4c5-a149-4083-98b8-ee6820c00eae) ## License diff --git a/vendor/github.com/shamaton/msgpack/v2/ext/decode.go b/vendor/github.com/shamaton/msgpack/v2/ext/decode.go index ddc7829a58..6cae0eb11d 100644 --- a/vendor/github.com/shamaton/msgpack/v2/ext/decode.go +++ b/vendor/github.com/shamaton/msgpack/v2/ext/decode.go @@ -6,35 +6,56 @@ import ( "github.com/shamaton/msgpack/v2/def" ) +// Decoder defines an interface for decoding values from bytes. +// It provides methods to get the decoder type, check if the data matches the type, +// and convert the data into a Go value. type Decoder interface { + // Code returns the unique code representing the decoder type. Code() int8 + + // IsType checks if the data at the given offset matches the expected type. + // Returns true if the type matches, false otherwise. IsType(offset int, d *[]byte) bool + + // AsValue decodes the data at the given offset into a Go value of the specified kind. + // Returns the decoded value, the new offset, and an error if decoding fails. AsValue(offset int, k reflect.Kind, d *[]byte) (interface{}, int, error) } +// DecoderCommon provides common utility methods for decoding data from bytes. type DecoderCommon struct { } +// ReadSize1 reads a single byte from the given index in the byte slice. +// Returns the byte and the new index after reading. func (cd *DecoderCommon) ReadSize1(index int, d *[]byte) (byte, int) { rb := def.Byte1 return (*d)[index], index + rb } +// ReadSize2 reads two bytes from the given index in the byte slice. +// Returns the bytes as a slice and the new index after reading. func (cd *DecoderCommon) ReadSize2(index int, d *[]byte) ([]byte, int) { rb := def.Byte2 return (*d)[index : index+rb], index + rb } +// ReadSize4 reads four bytes from the given index in the byte slice. +// Returns the bytes as a slice and the new index after reading. func (cd *DecoderCommon) ReadSize4(index int, d *[]byte) ([]byte, int) { rb := def.Byte4 return (*d)[index : index+rb], index + rb } +// ReadSize8 reads eight bytes from the given index in the byte slice. +// Returns the bytes as a slice and the new index after reading. func (cd *DecoderCommon) ReadSize8(index int, d *[]byte) ([]byte, int) { rb := def.Byte8 return (*d)[index : index+rb], index + rb } +// ReadSizeN reads a specified number of bytes (n) from the given index in the byte slice. +// Returns the bytes as a slice and the new index after reading. func (cd *DecoderCommon) ReadSizeN(index, n int, d *[]byte) ([]byte, int) { return (*d)[index : index+n], index + n } diff --git a/vendor/github.com/shamaton/msgpack/v2/ext/decoder_stream.go b/vendor/github.com/shamaton/msgpack/v2/ext/decoder_stream.go index b7a8a30138..719469ecd6 100644 --- a/vendor/github.com/shamaton/msgpack/v2/ext/decoder_stream.go +++ b/vendor/github.com/shamaton/msgpack/v2/ext/decoder_stream.go @@ -4,8 +4,19 @@ import ( "reflect" ) +// StreamDecoder defines an interface for decoding streams of data. +// It provides methods to retrieve the decoder's code, check type compatibility, +// and convert raw data into a Go value of a specified kind. type StreamDecoder interface { + // Code returns the unique identifier for the decoder. Code() int8 + + // IsType checks if the provided code, inner type, and data length match the expected type. + // Returns true if the type matches, otherwise false. IsType(code byte, innerType int8, dataLength int) bool + + // ToValue converts the raw data into a Go value of the specified kind. + // Takes the code, raw data, and the target kind as input. + // Returns the decoded value or an error if the conversion fails. ToValue(code byte, data []byte, k reflect.Kind) (any, error) } diff --git a/vendor/github.com/shamaton/msgpack/v2/ext/encode.go b/vendor/github.com/shamaton/msgpack/v2/ext/encode.go index 56f5cd099e..38afeefb6d 100644 --- a/vendor/github.com/shamaton/msgpack/v2/ext/encode.go +++ b/vendor/github.com/shamaton/msgpack/v2/ext/encode.go @@ -4,27 +4,48 @@ import ( "reflect" ) +// Encoder defines an interface for encoding values into bytes. +// It provides methods to get the encoding type, calculate the byte size of a value, +// and write the encoded value into a byte slice. type Encoder interface { + // Code returns the unique code representing the encoder type. Code() int8 + + // Type returns the reflect.Type of the value that the encoder handles. Type() reflect.Type + + // CalcByteSize calculates the number of bytes required to encode the given value. + // Returns the size and an error if the calculation fails. CalcByteSize(value reflect.Value) (int, error) + + // WriteToBytes encodes the given value into a byte slice starting at the specified offset. + // Returns the new offset after writing the bytes. WriteToBytes(value reflect.Value, offset int, bytes *[]byte) int } +// EncoderCommon provides utility methods for encoding various types of values into bytes. +// It includes methods to encode integers and unsigned integers of different sizes, +// as well as methods to write raw byte slices into a target byte slice. type EncoderCommon struct { } +// SetByte1Int64 encodes a single byte from the given int64 value into the byte slice at the specified offset. +// Returns the new offset after writing the byte. func (c *EncoderCommon) SetByte1Int64(value int64, offset int, d *[]byte) int { (*d)[offset] = byte(value) return offset + 1 } +// SetByte2Int64 encodes the lower two bytes of the given int64 value into the byte slice at the specified offset. +// Returns the new offset after writing the bytes. func (c *EncoderCommon) SetByte2Int64(value int64, offset int, d *[]byte) int { (*d)[offset+0] = byte(value >> 8) (*d)[offset+1] = byte(value) return offset + 2 } +// SetByte4Int64 encodes the lower four bytes of the given int64 value into the byte slice at the specified offset. +// Returns the new offset after writing the bytes. func (c *EncoderCommon) SetByte4Int64(value int64, offset int, d *[]byte) int { (*d)[offset+0] = byte(value >> 24) (*d)[offset+1] = byte(value >> 16) @@ -33,6 +54,8 @@ func (c *EncoderCommon) SetByte4Int64(value int64, offset int, d *[]byte) int { return offset + 4 } +// SetByte8Int64 encodes all eight bytes of the given int64 value into the byte slice at the specified offset. +// Returns the new offset after writing the bytes. func (c *EncoderCommon) SetByte8Int64(value int64, offset int, d *[]byte) int { (*d)[offset] = byte(value >> 56) (*d)[offset+1] = byte(value >> 48) @@ -45,17 +68,23 @@ func (c *EncoderCommon) SetByte8Int64(value int64, offset int, d *[]byte) int { return offset + 8 } +// SetByte1Uint64 encodes a single byte from the given uint64 value into the byte slice at the specified offset. +// Returns the new offset after writing the byte. func (c *EncoderCommon) SetByte1Uint64(value uint64, offset int, d *[]byte) int { (*d)[offset] = byte(value) return offset + 1 } +// SetByte2Uint64 encodes the lower two bytes of the given uint64 value into the byte slice at the specified offset. +// Returns the new offset after writing the bytes. func (c *EncoderCommon) SetByte2Uint64(value uint64, offset int, d *[]byte) int { (*d)[offset] = byte(value >> 8) (*d)[offset+1] = byte(value) return offset + 2 } +// SetByte4Uint64 encodes the lower four bytes of the given uint64 value into the byte slice at the specified offset. +// Returns the new offset after writing the bytes. func (c *EncoderCommon) SetByte4Uint64(value uint64, offset int, d *[]byte) int { (*d)[offset] = byte(value >> 24) (*d)[offset+1] = byte(value >> 16) @@ -64,6 +93,8 @@ func (c *EncoderCommon) SetByte4Uint64(value uint64, offset int, d *[]byte) int return offset + 4 } +// SetByte8Uint64 encodes all eight bytes of the given uint64 value into the byte slice at the specified offset. +// Returns the new offset after writing the bytes. func (c *EncoderCommon) SetByte8Uint64(value uint64, offset int, d *[]byte) int { (*d)[offset] = byte(value >> 56) (*d)[offset+1] = byte(value >> 48) @@ -76,17 +107,23 @@ func (c *EncoderCommon) SetByte8Uint64(value uint64, offset int, d *[]byte) int return offset + 8 } +// SetByte1Int encodes a single byte from the given int value into the byte slice at the specified offset. +// Returns the new offset after writing the byte. func (c *EncoderCommon) SetByte1Int(code, offset int, d *[]byte) int { (*d)[offset] = byte(code) return offset + 1 } +// SetByte2Int encodes the lower two bytes of the given int value into the byte slice at the specified offset. +// Returns the new offset after writing the bytes. func (c *EncoderCommon) SetByte2Int(value int, offset int, d *[]byte) int { (*d)[offset] = byte(value >> 8) (*d)[offset+1] = byte(value) return offset + 2 } +// SetByte4Int encodes the lower four bytes of the given int value into the byte slice at the specified offset. +// Returns the new offset after writing the bytes. func (c *EncoderCommon) SetByte4Int(value int, offset int, d *[]byte) int { (*d)[offset] = byte(value >> 24) (*d)[offset+1] = byte(value >> 16) @@ -95,6 +132,8 @@ func (c *EncoderCommon) SetByte4Int(value int, offset int, d *[]byte) int { return offset + 4 } +// SetByte4Uint32 encodes the lower four bytes of the given uint32 value into the byte slice at the specified offset. +// Returns the new offset after writing the bytes. func (c *EncoderCommon) SetByte4Uint32(value uint32, offset int, d *[]byte) int { (*d)[offset] = byte(value >> 24) (*d)[offset+1] = byte(value >> 16) @@ -103,6 +142,8 @@ func (c *EncoderCommon) SetByte4Uint32(value uint32, offset int, d *[]byte) int return offset + 4 } +// SetBytes writes the given byte slice `bs` into the target byte slice at the specified offset. +// Returns the new offset after writing the bytes. func (c *EncoderCommon) SetBytes(bs []byte, offset int, d *[]byte) int { for i := range bs { (*d)[offset+i] = bs[i] diff --git a/vendor/github.com/shamaton/msgpack/v2/ext/encode_stream.go b/vendor/github.com/shamaton/msgpack/v2/ext/encode_stream.go index a284e62c8b..0172792bfd 100644 --- a/vendor/github.com/shamaton/msgpack/v2/ext/encode_stream.go +++ b/vendor/github.com/shamaton/msgpack/v2/ext/encode_stream.go @@ -7,29 +7,37 @@ import ( "github.com/shamaton/msgpack/v2/internal/common" ) -// StreamEncoder is interface that extended encoder should implement +// StreamEncoder is an interface that extended encoders should implement. +// It defines methods for encoding data into a stream. type StreamEncoder interface { + // Code returns the unique code for the encoder. Code() int8 + // Type returns the reflect.Type of the value being encoded. Type() reflect.Type + // Write encodes the given value and writes it to the provided StreamWriter. Write(w StreamWriter, value reflect.Value) error } -// StreamWriter is provided some writing functions for extended format by user +// StreamWriter provides methods for writing data in extended formats. +// It wraps an io.Writer and a buffer for efficient writing. type StreamWriter struct { - w io.Writer - buf *common.Buffer + w io.Writer // The underlying writer to write data to. + buf *common.Buffer // A buffer used for temporary storage during writing. } +// CreateStreamWriter creates and returns a new StreamWriter instance. func CreateStreamWriter(w io.Writer, buf *common.Buffer) StreamWriter { return StreamWriter{w, buf} } +// WriteByte1Int64 writes a single byte representation of an int64 value. func (w *StreamWriter) WriteByte1Int64(value int64) error { return w.buf.Write(w.w, byte(value), ) } +// WriteByte2Int64 writes a two-byte representation of an int64 value. func (w *StreamWriter) WriteByte2Int64(value int64) error { return w.buf.Write(w.w, byte(value>>8), @@ -37,6 +45,7 @@ func (w *StreamWriter) WriteByte2Int64(value int64) error { ) } +// WriteByte4Int64 writes a four-byte representation of an int64 value. func (w *StreamWriter) WriteByte4Int64(value int64) error { return w.buf.Write(w.w, byte(value>>24), @@ -46,6 +55,7 @@ func (w *StreamWriter) WriteByte4Int64(value int64) error { ) } +// WriteByte8Int64 writes an eight-byte representation of an int64 value. func (w *StreamWriter) WriteByte8Int64(value int64) error { return w.buf.Write(w.w, byte(value>>56), @@ -59,12 +69,14 @@ func (w *StreamWriter) WriteByte8Int64(value int64) error { ) } +// WriteByte1Uint64 writes a single byte representation of a uint64 value. func (w *StreamWriter) WriteByte1Uint64(value uint64) error { return w.buf.Write(w.w, byte(value), ) } +// WriteByte2Uint64 writes a two-byte representation of a uint64 value. func (w *StreamWriter) WriteByte2Uint64(value uint64) error { return w.buf.Write(w.w, byte(value>>8), @@ -72,6 +84,7 @@ func (w *StreamWriter) WriteByte2Uint64(value uint64) error { ) } +// WriteByte4Uint64 writes a four-byte representation of a uint64 value. func (w *StreamWriter) WriteByte4Uint64(value uint64) error { return w.buf.Write(w.w, byte(value>>24), @@ -81,6 +94,7 @@ func (w *StreamWriter) WriteByte4Uint64(value uint64) error { ) } +// WriteByte8Uint64 writes an eight-byte representation of a uint64 value. func (w *StreamWriter) WriteByte8Uint64(value uint64) error { return w.buf.Write(w.w, byte(value>>56), @@ -94,12 +108,14 @@ func (w *StreamWriter) WriteByte8Uint64(value uint64) error { ) } +// WriteByte1Int writes a single byte representation of an int value. func (w *StreamWriter) WriteByte1Int(value int) error { return w.buf.Write(w.w, byte(value), ) } +// WriteByte2Int writes a two-byte representation of an int value. func (w *StreamWriter) WriteByte2Int(value int) error { return w.buf.Write(w.w, byte(value>>8), @@ -107,6 +123,7 @@ func (w *StreamWriter) WriteByte2Int(value int) error { ) } +// WriteByte4Int writes a four-byte representation of an int value. func (w *StreamWriter) WriteByte4Int(value int) error { return w.buf.Write(w.w, byte(value>>24), @@ -116,6 +133,7 @@ func (w *StreamWriter) WriteByte4Int(value int) error { ) } +// WriteByte4Uint32 writes a four-byte representation of a uint32 value. func (w *StreamWriter) WriteByte4Uint32(value uint32) error { return w.buf.Write(w.w, byte(value>>24), @@ -125,6 +143,7 @@ func (w *StreamWriter) WriteByte4Uint32(value uint32) error { ) } +// WriteBytes writes a slice of bytes to the underlying writer. func (w *StreamWriter) WriteBytes(bs []byte) error { return w.buf.Write(w.w, bs...) } diff --git a/vendor/github.com/shamaton/msgpack/v2/internal/common/common.go b/vendor/github.com/shamaton/msgpack/v2/internal/common/common.go index 7c2b919111..ffd37673bc 100644 --- a/vendor/github.com/shamaton/msgpack/v2/internal/common/common.go +++ b/vendor/github.com/shamaton/msgpack/v2/internal/common/common.go @@ -1,23 +1,42 @@ package common -import "reflect" +import ( + "reflect" + "strings" +) // Common is used encoding/decoding type Common struct { } // CheckField returns flag whether should encode/decode or not and field name -func (c *Common) CheckField(field reflect.StructField) (bool, string) { +func (c *Common) CheckField(field reflect.StructField) (public, omit bool, name string) { // A to Z - if c.isPublic(field.Name) { - if tag := field.Tag.Get("msgpack"); tag == "-" { - return false, "" - } else if len(tag) > 0 { - return true, tag - } - return true, field.Name + if !c.isPublic(field.Name) { + return false, false, "" } - return false, "" + tag := field.Tag.Get("msgpack") + if tag == "" { + return true, false, field.Name + } + + parts := strings.Split(tag, ",") + // check ignore + if parts[0] == "-" { + return false, false, "" + } + // check omitempty + for _, part := range parts[1:] { + if part == "omitempty" { + omit = true + } + } + // check name + name = field.Name + if parts[0] != "" { + name = parts[0] + } + return true, omit, name } func (c *Common) isPublic(name string) bool { diff --git a/vendor/github.com/shamaton/msgpack/v2/internal/decoding/struct.go b/vendor/github.com/shamaton/msgpack/v2/internal/decoding/struct.go index 6f39f335f8..5af60b106a 100644 --- a/vendor/github.com/shamaton/msgpack/v2/internal/decoding/struct.go +++ b/vendor/github.com/shamaton/msgpack/v2/internal/decoding/struct.go @@ -71,7 +71,7 @@ func (d *decoder) setStructFromArray(rv reflect.Value, offset int, k reflect.Kin if !findCache { scta = &structCacheTypeArray{} for i := 0; i < rv.NumField(); i++ { - if ok, _ := d.CheckField(rv.Type().Field(i)); ok { + if ok, _, _ := d.CheckField(rv.Type().Field(i)); ok { scta.m = append(scta.m, i) } } @@ -112,7 +112,7 @@ func (d *decoder) setStructFromMap(rv reflect.Value, offset int, k reflect.Kind) if !cacheFind { sctm = &structCacheTypeMap{} for i := 0; i < rv.NumField(); i++ { - if ok, name := d.CheckField(rv.Type().Field(i)); ok { + if ok, _, name := d.CheckField(rv.Type().Field(i)); ok { sctm.keys = append(sctm.keys, []byte(name)) sctm.indexes = append(sctm.indexes, i) } diff --git a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/byte.go b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/byte.go index c1bb107cfb..cbd5a7d37a 100644 --- a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/byte.go +++ b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/byte.go @@ -16,11 +16,11 @@ func (e *encoder) isByteSlice(rv reflect.Value) bool { func (e *encoder) calcByteSlice(l int) (int, error) { if l <= math.MaxUint8 { - return def.Byte1 + l, nil + return def.Byte1 + def.Byte1 + l, nil } else if l <= math.MaxUint16 { - return def.Byte2 + l, nil + return def.Byte1 + def.Byte2 + l, nil } else if uint(l) <= math.MaxUint32 { - return def.Byte4 + l, nil + return def.Byte1 + def.Byte4 + l, nil } // not supported error return 0, fmt.Errorf("%w slice length : %d", def.ErrUnsupportedType, l) diff --git a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/complex.go b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/complex.go index 4a5f045d81..be640c096f 100644 --- a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/complex.go +++ b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/complex.go @@ -7,11 +7,11 @@ import ( ) func (e *encoder) calcComplex64() int { - return def.Byte1 + def.Byte8 + return def.Byte1 + def.Byte1 + def.Byte8 } func (e *encoder) calcComplex128() int { - return def.Byte1 + def.Byte16 + return def.Byte1 + def.Byte1 + def.Byte16 } func (e *encoder) writeComplex64(v complex64, offset int) int { diff --git a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/encoding.go b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/encoding.go index 1d393104df..62081b5d84 100644 --- a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/encoding.go +++ b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/encoding.go @@ -63,65 +63,48 @@ func Encode(v interface{}, asArray bool) (b []byte, err error) { //} func (e *encoder) calcSize(rv reflect.Value) (int, error) { - ret := def.Byte1 - switch rv.Kind() { case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: v := rv.Uint() - ret += e.calcUint(v) + return e.calcUint(v), nil case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: v := rv.Int() - ret += e.calcInt(int64(v)) + return e.calcInt(int64(v)), nil case reflect.Float32: - ret += e.calcFloat32(0) + return e.calcFloat32(0), nil case reflect.Float64: - ret += e.calcFloat64(0) + return e.calcFloat64(0), nil case reflect.String: - ret += e.calcString(rv.String()) + return e.calcString(rv.String()), nil case reflect.Bool: - // do nothing + return def.Byte1, nil case reflect.Complex64: - ret += e.calcComplex64() + return e.calcComplex64(), nil case reflect.Complex128: - ret += e.calcComplex128() + return e.calcComplex128(), nil case reflect.Slice: if rv.IsNil() { - return ret, nil + return def.Byte1, nil } - l := rv.Len() // bin format if e.isByteSlice(rv) { - r, err := e.calcByteSlice(l) + size, err := e.calcByteSlice(rv.Len()) if err != nil { return 0, err } - ret += r - return ret, nil - } - - // format size - if l <= 0x0f { - // format code only - } else if l <= math.MaxUint16 { - ret += def.Byte2 - } else if uint(l) <= math.MaxUint32 { - ret += def.Byte4 - } else { - // not supported error - return 0, fmt.Errorf("%w array length : %d", def.ErrUnsupportedType, l) + return size, nil } if size, find := e.calcFixedSlice(rv); find { - ret += size - return ret, nil + return size, nil } // func @@ -129,42 +112,34 @@ func (e *encoder) calcSize(rv reflect.Value) (int, error) { var f structCalcFunc if elem.Kind() == reflect.Struct { f = e.getStructCalc(elem) - ret += def.Byte1 * l } else { f = e.calcSize } + l := rv.Len() + size, err := e.calcLength(l) + if err != nil { + return 0, err + } + // objects size for i := 0; i < l; i++ { - size, err := f(rv.Index(i)) + s, err := f(rv.Index(i)) if err != nil { return 0, err } - ret += size + size += s } + return size, nil case reflect.Array: - l := rv.Len() // bin format if e.isByteSlice(rv) { - r, err := e.calcByteSlice(l) + size, err := e.calcByteSlice(rv.Len()) if err != nil { return 0, err } - ret += r - return ret, nil - } - - // format size - if l <= 0x0f { - // format code only - } else if l <= math.MaxUint16 { - ret += def.Byte2 - } else if uint(l) <= math.MaxUint32 { - ret += def.Byte4 - } else { - // not supported error - return 0, fmt.Errorf("array length %d is %w", l, def.ErrUnsupportedLength) + return size, nil } // func @@ -172,41 +147,33 @@ func (e *encoder) calcSize(rv reflect.Value) (int, error) { var f structCalcFunc if elem.Kind() == reflect.Struct { f = e.getStructCalc(elem) - ret += def.Byte1 * l } else { f = e.calcSize } + l := rv.Len() + size, err := e.calcLength(l) + if err != nil { + return 0, err + } + // objects size for i := 0; i < l; i++ { - size, err := f(rv.Index(i)) + s, err := f(rv.Index(i)) if err != nil { return 0, err } - ret += size + size += s } + return size, nil case reflect.Map: if rv.IsNil() { - return ret, nil - } - - l := rv.Len() - // format - if l <= 0x0f { - // do nothing - } else if l <= math.MaxUint16 { - ret += def.Byte2 - } else if uint(l) <= math.MaxUint32 { - ret += def.Byte4 - } else { - // not supported error - return 0, fmt.Errorf("map length %d is %w", l, def.ErrUnsupportedLength) + return def.Byte1, nil } if size, find := e.calcFixedMap(rv); find { - ret += size - return ret, nil + return size, nil } if e.mk == nil { @@ -214,8 +181,13 @@ func (e *encoder) calcSize(rv reflect.Value) (int, error) { e.mv = map[uintptr][]reflect.Value{} } - // key-value keys := rv.MapKeys() + size, err := e.calcLength(len(keys)) + if err != nil { + return 0, err + } + + // key-value mv := make([]reflect.Value, len(keys)) i := 0 for _, k := range keys { @@ -228,44 +200,56 @@ func (e *encoder) calcSize(rv reflect.Value) (int, error) { if err != nil { return 0, err } - ret += keySize + valueSize + size += keySize + valueSize mv[i] = value i++ } e.mk[rv.Pointer()], e.mv[rv.Pointer()] = keys, mv + return size, nil case reflect.Struct: size, err := e.calcStruct(rv) if err != nil { return 0, err } - ret += size + return size, nil case reflect.Ptr: if rv.IsNil() { - return ret, nil + return def.Byte1, nil } size, err := e.calcSize(rv.Elem()) if err != nil { return 0, err } - ret = size + return size, nil case reflect.Interface: size, err := e.calcSize(rv.Elem()) if err != nil { return 0, err } - ret = size + return size, nil case reflect.Invalid: // do nothing (return nil) + return def.Byte1, nil default: return 0, fmt.Errorf("%v is %w type", rv.Kind(), def.ErrUnsupportedType) } +} - return ret, nil +func (e *encoder) calcLength(l int) (int, error) { + if l <= 0x0f { + return def.Byte1, nil + } else if l <= math.MaxUint16 { + return def.Byte1 + def.Byte2, nil + } else if uint(l) <= math.MaxUint32 { + return def.Byte1 + def.Byte4, nil + } + // not supported error + return 0, fmt.Errorf("array length %d is %w", l, def.ErrUnsupportedLength) } func (e *encoder) create(rv reflect.Value, offset int) int { @@ -301,17 +285,14 @@ func (e *encoder) create(rv reflect.Value, offset int) int { if rv.IsNil() { return e.writeNil(offset) } - l := rv.Len() + // bin format if e.isByteSlice(rv) { - offset = e.writeByteSliceLength(l, offset) + offset = e.writeByteSliceLength(rv.Len(), offset) offset = e.setBytes(rv.Bytes(), offset) return offset } - // format - offset = e.writeSliceLength(l, offset) - if offset, find := e.writeFixedSlice(rv, offset); find { return offset } @@ -326,6 +307,8 @@ func (e *encoder) create(rv reflect.Value, offset int) int { } // objects + l := rv.Len() + offset = e.writeSliceLength(l, offset) for i := 0; i < l; i++ { offset = f(rv.Index(i), offset) } diff --git a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/float.go b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/float.go index 5f67f1f71c..34eef06e84 100644 --- a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/float.go +++ b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/float.go @@ -6,12 +6,12 @@ import ( "github.com/shamaton/msgpack/v2/def" ) -func (e *encoder) calcFloat32(v float64) int { - return def.Byte4 +func (e *encoder) calcFloat32(_ float64) int { + return def.Byte1 + def.Byte4 } -func (e *encoder) calcFloat64(v float64) int { - return def.Byte8 +func (e *encoder) calcFloat64(_ float64) int { + return def.Byte1 + def.Byte8 } func (e *encoder) writeFloat32(v float64, offset int) int { diff --git a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/int.go b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/int.go index aac761d24b..d5c7fd91eb 100644 --- a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/int.go +++ b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/int.go @@ -15,15 +15,15 @@ func (e *encoder) calcInt(v int64) int { return e.calcUint(uint64(v)) } else if e.isNegativeFixInt64(v) { // format code only - return 0 - } else if v >= math.MinInt8 { return def.Byte1 + } else if v >= math.MinInt8 { + return def.Byte1 + def.Byte1 } else if v >= math.MinInt16 { - return def.Byte2 + return def.Byte1 + def.Byte2 } else if v >= math.MinInt32 { - return def.Byte4 + return def.Byte1 + def.Byte4 } - return def.Byte8 + return def.Byte1 + def.Byte8 } func (e *encoder) writeInt(v int64, offset int) int { diff --git a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/map.go b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/map.go index da359fa4be..78ac9776c5 100644 --- a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/map.go +++ b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/map.go @@ -8,252 +8,291 @@ import ( ) func (e *encoder) calcFixedMap(rv reflect.Value) (int, bool) { - size := 0 - + // calcLength formally returns (int, error), but for map lengths in Go + // the error case is unreachable. The error value is always nil and is + // intentionally ignored with `_`. switch m := rv.Interface().(type) { case map[string]int: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcString(k) - size += def.Byte1 + e.calcInt(int64(v)) + size += e.calcString(k) + size += e.calcInt(int64(v)) } return size, true case map[string]uint: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcString(k) - size += def.Byte1 + e.calcUint(uint64(v)) + size += e.calcString(k) + size += e.calcUint(uint64(v)) } return size, true case map[string]string: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcString(k) - size += def.Byte1 + e.calcString(v) + size += e.calcString(k) + size += e.calcString(v) } return size, true case map[string]float32: + size, _ := e.calcLength(len(m)) for k := range m { - size += def.Byte1 + e.calcString(k) - size += def.Byte1 + e.calcFloat32(0) + size += e.calcString(k) + size += e.calcFloat32(0) } return size, true case map[string]float64: + size, _ := e.calcLength(len(m)) for k := range m { - size += def.Byte1 + e.calcString(k) - size += def.Byte1 + e.calcFloat64(0) + size += e.calcString(k) + size += e.calcFloat64(0) } return size, true case map[string]bool: + size, _ := e.calcLength(len(m)) for k := range m { - size += def.Byte1 + e.calcString(k) + size += e.calcString(k) size += def.Byte1 /*+ e.calcBool()*/ } return size, true case map[string]int8: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcString(k) - size += def.Byte1 + e.calcInt(int64(v)) + size += e.calcString(k) + size += e.calcInt(int64(v)) } return size, true case map[string]int16: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcString(k) - size += def.Byte1 + e.calcInt(int64(v)) + size += e.calcString(k) + size += e.calcInt(int64(v)) } return size, true case map[string]int32: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcString(k) - size += def.Byte1 + e.calcInt(int64(v)) + size += e.calcString(k) + size += e.calcInt(int64(v)) } return size, true case map[string]int64: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcString(k) - size += def.Byte1 + e.calcInt(v) + size += e.calcString(k) + size += e.calcInt(v) } return size, true case map[string]uint8: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcString(k) - size += def.Byte1 + e.calcUint(uint64(v)) + size += e.calcString(k) + size += e.calcUint(uint64(v)) } return size, true case map[string]uint16: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcString(k) - size += def.Byte1 + e.calcUint(uint64(v)) + size += e.calcString(k) + size += e.calcUint(uint64(v)) } return size, true case map[string]uint32: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcString(k) - size += def.Byte1 + e.calcUint(uint64(v)) + size += e.calcString(k) + size += e.calcUint(uint64(v)) } return size, true case map[string]uint64: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcString(k) - size += def.Byte1 + e.calcUint(v) + size += e.calcString(k) + size += e.calcUint(v) } return size, true case map[int]string: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcInt(int64(k)) - size += def.Byte1 + e.calcString(v) + size += e.calcInt(int64(k)) + size += e.calcString(v) } return size, true case map[int]bool: + size, _ := e.calcLength(len(m)) for k := range m { - size += def.Byte1 + e.calcInt(int64(k)) + size += e.calcInt(int64(k)) size += def.Byte1 /* + e.calcBool()*/ } return size, true case map[uint]string: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcUint(uint64(k)) - size += def.Byte1 + e.calcString(v) + size += e.calcUint(uint64(k)) + size += e.calcString(v) } return size, true case map[uint]bool: + size, _ := e.calcLength(len(m)) for k := range m { - size += def.Byte1 + e.calcUint(uint64(k)) + size += e.calcUint(uint64(k)) size += def.Byte1 /* + e.calcBool()*/ } return size, true case map[float32]string: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcFloat32(float64(k)) - size += def.Byte1 + e.calcString(v) + size += e.calcFloat32(float64(k)) + size += e.calcString(v) } return size, true case map[float32]bool: + size, _ := e.calcLength(len(m)) for k := range m { - size += def.Byte1 + e.calcFloat32(float64(k)) + size += e.calcFloat32(float64(k)) size += def.Byte1 /* + e.calcBool()*/ } return size, true case map[float64]string: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcFloat64(k) - size += def.Byte1 + e.calcString(v) + size += e.calcFloat64(k) + size += e.calcString(v) } return size, true case map[float64]bool: + size, _ := e.calcLength(len(m)) for k := range m { - size += def.Byte1 + e.calcFloat64(k) + size += e.calcFloat64(k) size += def.Byte1 /* + e.calcBool()*/ } return size, true case map[int8]string: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcInt(int64(k)) - size += def.Byte1 + e.calcString(v) + size += e.calcInt(int64(k)) + size += e.calcString(v) } return size, true case map[int8]bool: + size, _ := e.calcLength(len(m)) for k := range m { - size += def.Byte1 + e.calcInt(int64(k)) + size += e.calcInt(int64(k)) size += def.Byte1 /* + e.calcBool()*/ } return size, true case map[int16]string: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcInt(int64(k)) - size += def.Byte1 + e.calcString(v) + size += e.calcInt(int64(k)) + size += e.calcString(v) } return size, true case map[int16]bool: + size, _ := e.calcLength(len(m)) for k := range m { - size += def.Byte1 + e.calcInt(int64(k)) + size += e.calcInt(int64(k)) size += def.Byte1 /* + e.calcBool()*/ } return size, true case map[int32]string: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcInt(int64(k)) - size += def.Byte1 + e.calcString(v) + size += e.calcInt(int64(k)) + size += e.calcString(v) } return size, true case map[int32]bool: + size, _ := e.calcLength(len(m)) for k := range m { - size += def.Byte1 + e.calcInt(int64(k)) + size += e.calcInt(int64(k)) size += def.Byte1 /* + e.calcBool()*/ } return size, true case map[int64]string: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcInt(k) - size += def.Byte1 + e.calcString(v) + size += e.calcInt(k) + size += e.calcString(v) } return size, true case map[int64]bool: + size, _ := e.calcLength(len(m)) for k := range m { - size += def.Byte1 + e.calcInt(k) + size += e.calcInt(k) size += def.Byte1 /* + e.calcBool()*/ } return size, true case map[uint8]string: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcUint(uint64(k)) - size += def.Byte1 + e.calcString(v) + size += e.calcUint(uint64(k)) + size += e.calcString(v) } return size, true case map[uint8]bool: + size, _ := e.calcLength(len(m)) for k := range m { - size += def.Byte1 + e.calcUint(uint64(k)) + size += e.calcUint(uint64(k)) size += def.Byte1 /* + e.calcBool()*/ } return size, true case map[uint16]string: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcUint(uint64(k)) - size += def.Byte1 + e.calcString(v) + size += e.calcUint(uint64(k)) + size += e.calcString(v) } return size, true case map[uint16]bool: + size, _ := e.calcLength(len(m)) for k := range m { - size += def.Byte1 + e.calcUint(uint64(k)) + size += e.calcUint(uint64(k)) size += def.Byte1 /* + e.calcBool()*/ } return size, true case map[uint32]string: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcUint(uint64(k)) - size += def.Byte1 + e.calcString(v) + size += e.calcUint(uint64(k)) + size += e.calcString(v) } return size, true case map[uint32]bool: + size, _ := e.calcLength(len(m)) for k := range m { - size += def.Byte1 + e.calcUint(uint64(k)) + size += e.calcUint(uint64(k)) size += def.Byte1 /* + e.calcBool()*/ } return size, true case map[uint64]string: + size, _ := e.calcLength(len(m)) for k, v := range m { - size += def.Byte1 + e.calcUint(k) - size += def.Byte1 + e.calcString(v) + size += e.calcUint(k) + size += e.calcString(v) } return size, true case map[uint64]bool: + size, _ := e.calcLength(len(m)) for k := range m { - size += def.Byte1 + e.calcUint(k) + size += e.calcUint(k) size += def.Byte1 /* + e.calcBool()*/ } return size, true } - return size, false + return 0, false } func (e *encoder) writeMapLength(l int, offset int) int { diff --git a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/slice.go b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/slice.go index a18b8c9039..bae88c47ce 100644 --- a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/slice.go +++ b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/slice.go @@ -8,93 +8,108 @@ import ( ) func (e *encoder) calcFixedSlice(rv reflect.Value) (int, bool) { - size := 0 - + // calcLength formally returns (int, error), but for map lengths in Go + // the error case is unreachable. The error value is always nil and is + // intentionally ignored with `_`. switch sli := rv.Interface().(type) { case []int: + size, _ := e.calcLength(len(sli)) for _, v := range sli { - size += def.Byte1 + e.calcInt(int64(v)) + size += e.calcInt(int64(v)) } return size, true case []uint: + size, _ := e.calcLength(len(sli)) for _, v := range sli { - size += def.Byte1 + e.calcUint(uint64(v)) + size += e.calcUint(uint64(v)) } return size, true case []string: + size, _ := e.calcLength(len(sli)) for _, v := range sli { - size += def.Byte1 + e.calcString(v) + size += e.calcString(v) } return size, true case []float32: + size, _ := e.calcLength(len(sli)) for _, v := range sli { - size += def.Byte1 + e.calcFloat32(float64(v)) + size += e.calcFloat32(float64(v)) } return size, true case []float64: + size, _ := e.calcLength(len(sli)) for _, v := range sli { - size += def.Byte1 + e.calcFloat64(v) + size += e.calcFloat64(v) } return size, true case []bool: + size, _ := e.calcLength(len(sli)) size += def.Byte1 * len(sli) return size, true case []int8: + size, _ := e.calcLength(len(sli)) for _, v := range sli { - size += def.Byte1 + e.calcInt(int64(v)) + size += e.calcInt(int64(v)) } return size, true case []int16: + size, _ := e.calcLength(len(sli)) for _, v := range sli { - size += def.Byte1 + e.calcInt(int64(v)) + size += e.calcInt(int64(v)) } return size, true case []int32: + size, _ := e.calcLength(len(sli)) for _, v := range sli { - size += def.Byte1 + e.calcInt(int64(v)) + size += e.calcInt(int64(v)) } return size, true case []int64: + size, _ := e.calcLength(len(sli)) for _, v := range sli { - size += def.Byte1 + e.calcInt(v) + size += e.calcInt(v) } return size, true case []uint8: + size, _ := e.calcLength(len(sli)) for _, v := range sli { - size += def.Byte1 + e.calcUint(uint64(v)) + size += e.calcUint(uint64(v)) } return size, true case []uint16: + size, _ := e.calcLength(len(sli)) for _, v := range sli { - size += def.Byte1 + e.calcUint(uint64(v)) + size += e.calcUint(uint64(v)) } return size, true case []uint32: + size, _ := e.calcLength(len(sli)) for _, v := range sli { - size += def.Byte1 + e.calcUint(uint64(v)) + size += e.calcUint(uint64(v)) } return size, true case []uint64: + size, _ := e.calcLength(len(sli)) for _, v := range sli { - size += def.Byte1 + e.calcUint(v) + size += e.calcUint(v) } return size, true } - return size, false + return 0, false } func (e *encoder) writeSliceLength(l int, offset int) int { @@ -115,84 +130,98 @@ func (e *encoder) writeFixedSlice(rv reflect.Value, offset int) (int, bool) { switch sli := rv.Interface().(type) { case []int: + offset = e.writeSliceLength(len(sli), offset) for _, v := range sli { offset = e.writeInt(int64(v), offset) } return offset, true case []uint: + offset = e.writeSliceLength(len(sli), offset) for _, v := range sli { offset = e.writeUint(uint64(v), offset) } return offset, true case []string: + offset = e.writeSliceLength(len(sli), offset) for _, v := range sli { offset = e.writeString(v, offset) } return offset, true case []float32: + offset = e.writeSliceLength(len(sli), offset) for _, v := range sli { offset = e.writeFloat32(float64(v), offset) } return offset, true case []float64: + offset = e.writeSliceLength(len(sli), offset) for _, v := range sli { offset = e.writeFloat64(float64(v), offset) } return offset, true case []bool: + offset = e.writeSliceLength(len(sli), offset) for _, v := range sli { offset = e.writeBool(v, offset) } return offset, true case []int8: + offset = e.writeSliceLength(len(sli), offset) for _, v := range sli { offset = e.writeInt(int64(v), offset) } return offset, true case []int16: + offset = e.writeSliceLength(len(sli), offset) for _, v := range sli { offset = e.writeInt(int64(v), offset) } return offset, true case []int32: + offset = e.writeSliceLength(len(sli), offset) for _, v := range sli { offset = e.writeInt(int64(v), offset) } return offset, true case []int64: + offset = e.writeSliceLength(len(sli), offset) for _, v := range sli { offset = e.writeInt(v, offset) } return offset, true case []uint8: + offset = e.writeSliceLength(len(sli), offset) for _, v := range sli { offset = e.writeUint(uint64(v), offset) } return offset, true case []uint16: + offset = e.writeSliceLength(len(sli), offset) for _, v := range sli { offset = e.writeUint(uint64(v), offset) } return offset, true case []uint32: + offset = e.writeSliceLength(len(sli), offset) for _, v := range sli { offset = e.writeUint(uint64(v), offset) } return offset, true case []uint64: + offset = e.writeSliceLength(len(sli), offset) for _, v := range sli { offset = e.writeUint(v, offset) } diff --git a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/string.go b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/string.go index df23d9d339..34cff10050 100644 --- a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/string.go +++ b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/string.go @@ -12,13 +12,13 @@ func (e *encoder) calcString(v string) int { strBytes := *(*[]byte)(unsafe.Pointer(&v)) l := len(strBytes) if l < 32 { - return l - } else if l <= math.MaxUint8 { return def.Byte1 + l + } else if l <= math.MaxUint8 { + return def.Byte1 + def.Byte1 + l } else if l <= math.MaxUint16 { - return def.Byte2 + l + return def.Byte1 + def.Byte2 + l } - return def.Byte4 + l + return def.Byte1 + def.Byte4 + l // NOTE : length over uint32 } diff --git a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/struct.go b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/struct.go index 1dddf04ea0..3b6ed30735 100644 --- a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/struct.go +++ b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/struct.go @@ -1,7 +1,6 @@ package encoding import ( - "fmt" "math" "reflect" "sync" @@ -13,6 +12,8 @@ import ( type structCache struct { indexes []int names []string + omits []bool + noOmit bool common.Common } @@ -60,10 +61,16 @@ func (e *encoder) calcStructArray(rv reflect.Value) (int, error) { cache, find := cachemap.Load(t) var c *structCache if !find { - c = &structCache{} - for i := 0; i < rv.NumField(); i++ { + num := rv.NumField() + c = &structCache{ + indexes: make([]int, 0, num), + names: make([]string, 0, num), + omits: make([]bool, 0, num), + } + omitCount := 0 + for i := 0; i < num; i++ { field := t.Field(i) - if ok, name := e.CheckField(field); ok { + if ok, omit, name := e.CheckField(field); ok { size, err := e.calcSize(rv.Field(i)) if err != nil { return 0, err @@ -71,8 +78,13 @@ func (e *encoder) calcStructArray(rv reflect.Value) (int, error) { ret += size c.indexes = append(c.indexes, i) c.names = append(c.names, name) + c.omits = append(c.omits, omit) + if omit { + omitCount++ + } } } + c.noOmit = omitCount == 0 cachemap.Store(t, c) } else { c = cache.(*structCache) @@ -86,17 +98,11 @@ func (e *encoder) calcStructArray(rv reflect.Value) (int, error) { } // format size - l := len(c.indexes) - if l <= 0x0f { - // format code only - } else if l <= math.MaxUint16 { - ret += def.Byte2 - } else if uint(l) <= math.MaxUint32 { - ret += def.Byte4 - } else { - // not supported error - return 0, fmt.Errorf("array length %d is %w", l, def.ErrUnsupportedLength) + size, err := e.calcLength(len(c.indexes)) + if err != nil { + return 0, err } + ret += size return ret, nil } @@ -105,48 +111,72 @@ func (e *encoder) calcStructMap(rv reflect.Value) (int, error) { t := rv.Type() cache, find := cachemap.Load(t) var c *structCache + var l int if !find { - c = &structCache{} - for i := 0; i < rv.NumField(); i++ { - if ok, name := e.CheckField(rv.Type().Field(i)); ok { - keySize := def.Byte1 + e.calcString(name) - valueSize, err := e.calcSize(rv.Field(i)) + num := rv.NumField() + c = &structCache{ + indexes: make([]int, 0, num), + names: make([]string, 0, num), + omits: make([]bool, 0, num), + } + omitCount := 0 + for i := 0; i < num; i++ { + if ok, omit, name := e.CheckField(rv.Type().Field(i)); ok { + size, err := e.calcSizeWithOmitEmpty(rv.Field(i), name, omit) if err != nil { return 0, err } - ret += keySize + valueSize + ret += size c.indexes = append(c.indexes, i) c.names = append(c.names, name) + c.omits = append(c.omits, omit) + if omit { + omitCount++ + } + if size > 0 { + l++ + } } } + c.noOmit = omitCount == 0 cachemap.Store(t, c) } else { c = cache.(*structCache) for i := 0; i < len(c.indexes); i++ { - keySize := def.Byte1 + e.calcString(c.names[i]) - valueSize, err := e.calcSize(rv.Field(c.indexes[i])) + size, err := e.calcSizeWithOmitEmpty(rv.Field(c.indexes[i]), c.names[i], c.omits[i]) if err != nil { return 0, err } - ret += keySize + valueSize + ret += size + if size > 0 { + l++ + } } } // format size - l := len(c.indexes) - if l <= 0x0f { - // format code only - } else if l <= math.MaxUint16 { - ret += def.Byte2 - } else if uint(l) <= math.MaxUint32 { - ret += def.Byte4 - } else { - // not supported error - return 0, fmt.Errorf("map length %d is %w", l, def.ErrUnsupportedLength) + size, err := e.calcLength(len(c.indexes)) + if err != nil { + return 0, err } + ret += size return ret, nil } +func (e *encoder) calcSizeWithOmitEmpty(rv reflect.Value, name string, omit bool) (int, error) { + keySize := 0 + valueSize := 0 + if !omit || !rv.IsZero() { + keySize = e.calcString(name) + vSize, err := e.calcSize(rv) + if err != nil { + return 0, err + } + valueSize = vSize + } + return keySize + valueSize, nil +} + func (e *encoder) getStructWriter(typ reflect.Type) structWriteFunc { for i := range extCoders { @@ -212,19 +242,34 @@ func (e *encoder) writeStructMap(rv reflect.Value, offset int) int { // format size num := len(c.indexes) - if num <= 0x0f { - offset = e.setByte1Int(def.FixMap+num, offset) - } else if num <= math.MaxUint16 { + l := 0 + if c.noOmit { + l = num + } else { + for i := 0; i < num; i++ { + irv := rv.Field(c.indexes[i]) + if !c.omits[i] || !irv.IsZero() { + l++ + } + } + } + + if l <= 0x0f { + offset = e.setByte1Int(def.FixMap+l, offset) + } else if l <= math.MaxUint16 { offset = e.setByte1Int(def.Map16, offset) - offset = e.setByte2Int(num, offset) - } else if uint(num) <= math.MaxUint32 { + offset = e.setByte2Int(l, offset) + } else if uint(l) <= math.MaxUint32 { offset = e.setByte1Int(def.Map32, offset) - offset = e.setByte4Int(num, offset) + offset = e.setByte4Int(l, offset) } for i := 0; i < num; i++ { - offset = e.writeString(c.names[i], offset) - offset = e.create(rv.Field(c.indexes[i]), offset) + irv := rv.Field(c.indexes[i]) + if !c.omits[i] || !irv.IsZero() { + offset = e.writeString(c.names[i], offset) + offset = e.create(irv, offset) + } } return offset } diff --git a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/uint.go b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/uint.go index d0780e6efe..4c093b7271 100644 --- a/vendor/github.com/shamaton/msgpack/v2/internal/encoding/uint.go +++ b/vendor/github.com/shamaton/msgpack/v2/internal/encoding/uint.go @@ -9,15 +9,15 @@ import ( func (e *encoder) calcUint(v uint64) int { if v <= math.MaxInt8 { // format code only - return 0 - } else if v <= math.MaxUint8 { return def.Byte1 + } else if v <= math.MaxUint8 { + return def.Byte1 + def.Byte1 } else if v <= math.MaxUint16 { - return def.Byte2 + return def.Byte1 + def.Byte2 } else if v <= math.MaxUint32 { - return def.Byte4 + return def.Byte1 + def.Byte4 } - return def.Byte8 + return def.Byte1 + def.Byte8 } func (e *encoder) writeUint(v uint64, offset int) int { diff --git a/vendor/github.com/shamaton/msgpack/v2/internal/stream/decoding/struct.go b/vendor/github.com/shamaton/msgpack/v2/internal/stream/decoding/struct.go index e835be02f4..d0cbda0cbd 100644 --- a/vendor/github.com/shamaton/msgpack/v2/internal/stream/decoding/struct.go +++ b/vendor/github.com/shamaton/msgpack/v2/internal/stream/decoding/struct.go @@ -64,7 +64,7 @@ func (d *decoder) setStructFromArray(code byte, rv reflect.Value, k reflect.Kind if !findCache { scta = &structCacheTypeArray{} for i := 0; i < rv.NumField(); i++ { - if ok, _ := d.CheckField(rv.Type().Field(i)); ok { + if ok, _, _ := d.CheckField(rv.Type().Field(i)); ok { scta.m = append(scta.m, i) } } @@ -101,7 +101,7 @@ func (d *decoder) setStructFromMap(code byte, rv reflect.Value, k reflect.Kind) if !cacheFind { sctm = &structCacheTypeMap{} for i := 0; i < rv.NumField(); i++ { - if ok, name := d.CheckField(rv.Type().Field(i)); ok { + if ok, _, name := d.CheckField(rv.Type().Field(i)); ok { sctm.keys = append(sctm.keys, []byte(name)) sctm.indexes = append(sctm.indexes, i) } diff --git a/vendor/github.com/shamaton/msgpack/v2/internal/stream/encoding/struct.go b/vendor/github.com/shamaton/msgpack/v2/internal/stream/encoding/struct.go index e641bfa996..06eeac5854 100644 --- a/vendor/github.com/shamaton/msgpack/v2/internal/stream/encoding/struct.go +++ b/vendor/github.com/shamaton/msgpack/v2/internal/stream/encoding/struct.go @@ -13,6 +13,8 @@ import ( type structCache struct { indexes []int names []string + omits []bool + noOmit bool common.Common } @@ -88,34 +90,49 @@ func (e *encoder) writeStructArray(rv reflect.Value) error { func (e *encoder) writeStructMap(rv reflect.Value) error { c := e.getStructCache(rv) - // format size num := len(c.indexes) - if num <= 0x0f { - if err := e.setByte1Int(def.FixMap + num); err != nil { + l := 0 + if c.noOmit { + l = num + } else { + for i := 0; i < num; i++ { + irv := rv.Field(c.indexes[i]) + if !c.omits[i] || !irv.IsZero() { + l++ + } + } + } + + // format size + if l <= 0x0f { + if err := e.setByte1Int(def.FixMap + l); err != nil { return err } - } else if num <= math.MaxUint16 { + } else if l <= math.MaxUint16 { if err := e.setByte1Int(def.Map16); err != nil { return err } - if err := e.setByte2Int(num); err != nil { + if err := e.setByte2Int(l); err != nil { return err } - } else if uint(num) <= math.MaxUint32 { + } else if uint(l) <= math.MaxUint32 { if err := e.setByte1Int(def.Map32); err != nil { return err } - if err := e.setByte4Int(num); err != nil { + if err := e.setByte4Int(l); err != nil { return err } } for i := 0; i < num; i++ { - if err := e.writeString(c.names[i]); err != nil { - return err - } - if err := e.create(rv.Field(c.indexes[i])); err != nil { - return err + irv := rv.Field(c.indexes[i]) + if !c.omits[i] || !irv.IsZero() { + if err := e.writeString(c.names[i]); err != nil { + return err + } + if err := e.create(irv); err != nil { + return err + } } } return nil @@ -128,16 +145,24 @@ func (e *encoder) getStructCache(rv reflect.Value) *structCache { return cache.(*structCache) } - var c *structCache - if !find { - c = &structCache{} - for i := 0; i < rv.NumField(); i++ { - if ok, name := e.CheckField(rv.Type().Field(i)); ok { - c.indexes = append(c.indexes, i) - c.names = append(c.names, name) + num := rv.NumField() + c := &structCache{ + indexes: make([]int, 0, num), + names: make([]string, 0, num), + omits: make([]bool, 0, num), + } + omitCount := 0 + for i := 0; i < num; i++ { + if ok, omit, name := e.CheckField(rv.Type().Field(i)); ok { + c.indexes = append(c.indexes, i) + c.names = append(c.names, name) + c.omits = append(c.omits, omit) + if omit { + omitCount++ } } - cachemap.Store(t, c) } + c.noOmit = omitCount == 0 + cachemap.Store(t, c) return c } diff --git a/vendor/github.com/shamaton/msgpack/v2/time/encode.go b/vendor/github.com/shamaton/msgpack/v2/time/encode.go index ada5b9b4e0..b8ec582fb5 100644 --- a/vendor/github.com/shamaton/msgpack/v2/time/encode.go +++ b/vendor/github.com/shamaton/msgpack/v2/time/encode.go @@ -30,12 +30,12 @@ func (s *timeEncoder) CalcByteSize(value reflect.Value) (int, error) { if secs>>34 == 0 { data := uint64(t.Nanosecond())<<34 | secs if data&0xffffffff00000000 == 0 { - return def.Byte1 + def.Byte4, nil + return def.Byte1 + def.Byte1 + def.Byte4, nil } - return def.Byte1 + def.Byte8, nil + return def.Byte1 + def.Byte1 + def.Byte8, nil } - return def.Byte1 + def.Byte1 + def.Byte4 + def.Byte8, nil + return def.Byte1 + def.Byte1 + def.Byte1 + def.Byte4 + def.Byte8, nil } func (s *timeEncoder) WriteToBytes(value reflect.Value, offset int, bytes *[]byte) int { diff --git a/vendor/golang.org/x/sys/plan9/pwd_go15_plan9.go b/vendor/golang.org/x/sys/plan9/pwd_go15_plan9.go deleted file mode 100644 index 73687de748..0000000000 --- a/vendor/golang.org/x/sys/plan9/pwd_go15_plan9.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build go1.5 - -package plan9 - -import "syscall" - -func fixwd() { - syscall.Fixwd() -} - -func Getwd() (wd string, err error) { - return syscall.Getwd() -} - -func Chdir(path string) error { - return syscall.Chdir(path) -} diff --git a/vendor/golang.org/x/sys/plan9/pwd_plan9.go b/vendor/golang.org/x/sys/plan9/pwd_plan9.go index fb94582184..7a76489db1 100644 --- a/vendor/golang.org/x/sys/plan9/pwd_plan9.go +++ b/vendor/golang.org/x/sys/plan9/pwd_plan9.go @@ -2,22 +2,18 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build !go1.5 - package plan9 +import "syscall" + func fixwd() { + syscall.Fixwd() } func Getwd() (wd string, err error) { - fd, err := open(".", O_RDONLY) - if err != nil { - return "", err - } - defer Close(fd) - return Fd2path(fd) + return syscall.Getwd() } func Chdir(path string) error { - return chdir(path) + return syscall.Chdir(path) } diff --git a/vendor/golang.org/x/sys/unix/affinity_linux.go b/vendor/golang.org/x/sys/unix/affinity_linux.go index 6e5c81acd0..3c7a6d6e2f 100644 --- a/vendor/golang.org/x/sys/unix/affinity_linux.go +++ b/vendor/golang.org/x/sys/unix/affinity_linux.go @@ -38,9 +38,7 @@ func SchedSetaffinity(pid int, set *CPUSet) error { // Zero clears the set s, so that it contains no CPUs. func (s *CPUSet) Zero() { - for i := range s { - s[i] = 0 - } + clear(s[:]) } func cpuBitsIndex(cpu int) int { diff --git a/vendor/golang.org/x/sys/unix/syscall_solaris.go b/vendor/golang.org/x/sys/unix/syscall_solaris.go index abc3955477..18a3d9bdab 100644 --- a/vendor/golang.org/x/sys/unix/syscall_solaris.go +++ b/vendor/golang.org/x/sys/unix/syscall_solaris.go @@ -629,7 +629,7 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e //sys Kill(pid int, signum syscall.Signal) (err error) //sys Lchown(path string, uid int, gid int) (err error) //sys Link(path string, link string) (err error) -//sys Listen(s int, backlog int) (err error) = libsocket.__xnet_llisten +//sys Listen(s int, backlog int) (err error) = libsocket.__xnet_listen //sys Lstat(path string, stat *Stat_t) (err error) //sys Madvise(b []byte, advice int) (err error) //sys Mkdir(path string, mode uint32) (err error) diff --git a/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go b/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go index c6545413c4..b4609c20c2 100644 --- a/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go +++ b/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go @@ -72,7 +72,7 @@ import ( //go:cgo_import_dynamic libc_kill kill "libc.so" //go:cgo_import_dynamic libc_lchown lchown "libc.so" //go:cgo_import_dynamic libc_link link "libc.so" -//go:cgo_import_dynamic libc___xnet_llisten __xnet_llisten "libsocket.so" +//go:cgo_import_dynamic libc___xnet_listen __xnet_listen "libsocket.so" //go:cgo_import_dynamic libc_lstat lstat "libc.so" //go:cgo_import_dynamic libc_madvise madvise "libc.so" //go:cgo_import_dynamic libc_mkdir mkdir "libc.so" @@ -221,7 +221,7 @@ import ( //go:linkname procKill libc_kill //go:linkname procLchown libc_lchown //go:linkname procLink libc_link -//go:linkname proc__xnet_llisten libc___xnet_llisten +//go:linkname proc__xnet_listen libc___xnet_listen //go:linkname procLstat libc_lstat //go:linkname procMadvise libc_madvise //go:linkname procMkdir libc_mkdir @@ -371,7 +371,7 @@ var ( procKill, procLchown, procLink, - proc__xnet_llisten, + proc__xnet_listen, procLstat, procMadvise, procMkdir, @@ -1178,7 +1178,7 @@ func Link(path string, link string) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func Listen(s int, backlog int) (err error) { - _, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&proc__xnet_llisten)), 2, uintptr(s), uintptr(backlog), 0, 0, 0, 0) + _, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&proc__xnet_listen)), 2, uintptr(s), uintptr(backlog), 0, 0, 0, 0) if e1 != 0 { err = errnoErr(e1) } diff --git a/vendor/golang.org/x/sys/unix/ztypes_linux.go b/vendor/golang.org/x/sys/unix/ztypes_linux.go index cd236443f6..944e75a11c 100644 --- a/vendor/golang.org/x/sys/unix/ztypes_linux.go +++ b/vendor/golang.org/x/sys/unix/ztypes_linux.go @@ -632,6 +632,8 @@ const ( IFA_FLAGS = 0x8 IFA_RT_PRIORITY = 0x9 IFA_TARGET_NETNSID = 0xa + IFAL_LABEL = 0x2 + IFAL_ADDRESS = 0x1 RT_SCOPE_UNIVERSE = 0x0 RT_SCOPE_SITE = 0xc8 RT_SCOPE_LINK = 0xfd @@ -689,6 +691,7 @@ const ( SizeofRtAttr = 0x4 SizeofIfInfomsg = 0x10 SizeofIfAddrmsg = 0x8 + SizeofIfAddrlblmsg = 0xc SizeofIfaCacheinfo = 0x10 SizeofRtMsg = 0xc SizeofRtNexthop = 0x8 @@ -740,6 +743,15 @@ type IfAddrmsg struct { Index uint32 } +type IfAddrlblmsg struct { + Family uint8 + _ uint8 + Prefixlen uint8 + Flags uint8 + Index uint32 + Seq uint32 +} + type IfaCacheinfo struct { Prefered uint32 Valid uint32 @@ -3052,6 +3064,23 @@ const ( ) const ( + TCA_UNSPEC = 0x0 + TCA_KIND = 0x1 + TCA_OPTIONS = 0x2 + TCA_STATS = 0x3 + TCA_XSTATS = 0x4 + TCA_RATE = 0x5 + TCA_FCNT = 0x6 + TCA_STATS2 = 0x7 + TCA_STAB = 0x8 + TCA_PAD = 0x9 + TCA_DUMP_INVISIBLE = 0xa + TCA_CHAIN = 0xb + TCA_HW_OFFLOAD = 0xc + TCA_INGRESS_BLOCK = 0xd + TCA_EGRESS_BLOCK = 0xe + TCA_DUMP_FLAGS = 0xf + TCA_EXT_WARN_MSG = 0x10 RTNLGRP_NONE = 0x0 RTNLGRP_LINK = 0x1 RTNLGRP_NOTIFY = 0x2 @@ -3086,6 +3115,18 @@ const ( RTNLGRP_IPV6_MROUTE_R = 0x1f RTNLGRP_NEXTHOP = 0x20 RTNLGRP_BRVLAN = 0x21 + RTNLGRP_MCTP_IFADDR = 0x22 + RTNLGRP_TUNNEL = 0x23 + RTNLGRP_STATS = 0x24 + RTNLGRP_IPV4_MCADDR = 0x25 + RTNLGRP_IPV6_MCADDR = 0x26 + RTNLGRP_IPV6_ACADDR = 0x27 + TCA_ROOT_UNSPEC = 0x0 + TCA_ROOT_TAB = 0x1 + TCA_ROOT_FLAGS = 0x2 + TCA_ROOT_COUNT = 0x3 + TCA_ROOT_TIME_DELTA = 0x4 + TCA_ROOT_EXT_WARN_MSG = 0x5 ) type CapUserHeader struct { diff --git a/vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go b/vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go index fc1835d8a2..bc1ce4360b 100644 --- a/vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go +++ b/vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go @@ -52,7 +52,7 @@ var ( ) func regConnectRegistry(machinename *uint16, key syscall.Handle, result *syscall.Handle) (regerrno error) { - r0, _, _ := syscall.Syscall(procRegConnectRegistryW.Addr(), 3, uintptr(unsafe.Pointer(machinename)), uintptr(key), uintptr(unsafe.Pointer(result))) + r0, _, _ := syscall.SyscallN(procRegConnectRegistryW.Addr(), uintptr(unsafe.Pointer(machinename)), uintptr(key), uintptr(unsafe.Pointer(result))) if r0 != 0 { regerrno = syscall.Errno(r0) } @@ -60,7 +60,7 @@ func regConnectRegistry(machinename *uint16, key syscall.Handle, result *syscall } func regCreateKeyEx(key syscall.Handle, subkey *uint16, reserved uint32, class *uint16, options uint32, desired uint32, sa *syscall.SecurityAttributes, result *syscall.Handle, disposition *uint32) (regerrno error) { - r0, _, _ := syscall.Syscall9(procRegCreateKeyExW.Addr(), 9, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(reserved), uintptr(unsafe.Pointer(class)), uintptr(options), uintptr(desired), uintptr(unsafe.Pointer(sa)), uintptr(unsafe.Pointer(result)), uintptr(unsafe.Pointer(disposition))) + r0, _, _ := syscall.SyscallN(procRegCreateKeyExW.Addr(), uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(reserved), uintptr(unsafe.Pointer(class)), uintptr(options), uintptr(desired), uintptr(unsafe.Pointer(sa)), uintptr(unsafe.Pointer(result)), uintptr(unsafe.Pointer(disposition))) if r0 != 0 { regerrno = syscall.Errno(r0) } @@ -68,7 +68,7 @@ func regCreateKeyEx(key syscall.Handle, subkey *uint16, reserved uint32, class * } func regDeleteKey(key syscall.Handle, subkey *uint16) (regerrno error) { - r0, _, _ := syscall.Syscall(procRegDeleteKeyW.Addr(), 2, uintptr(key), uintptr(unsafe.Pointer(subkey)), 0) + r0, _, _ := syscall.SyscallN(procRegDeleteKeyW.Addr(), uintptr(key), uintptr(unsafe.Pointer(subkey))) if r0 != 0 { regerrno = syscall.Errno(r0) } @@ -76,7 +76,7 @@ func regDeleteKey(key syscall.Handle, subkey *uint16) (regerrno error) { } func regDeleteValue(key syscall.Handle, name *uint16) (regerrno error) { - r0, _, _ := syscall.Syscall(procRegDeleteValueW.Addr(), 2, uintptr(key), uintptr(unsafe.Pointer(name)), 0) + r0, _, _ := syscall.SyscallN(procRegDeleteValueW.Addr(), uintptr(key), uintptr(unsafe.Pointer(name))) if r0 != 0 { regerrno = syscall.Errno(r0) } @@ -84,7 +84,7 @@ func regDeleteValue(key syscall.Handle, name *uint16) (regerrno error) { } func regEnumValue(key syscall.Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) { - r0, _, _ := syscall.Syscall9(procRegEnumValueW.Addr(), 8, uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(valtype)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(buflen)), 0) + r0, _, _ := syscall.SyscallN(procRegEnumValueW.Addr(), uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(valtype)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(buflen))) if r0 != 0 { regerrno = syscall.Errno(r0) } @@ -92,7 +92,7 @@ func regEnumValue(key syscall.Handle, index uint32, name *uint16, nameLen *uint3 } func regLoadMUIString(key syscall.Handle, name *uint16, buf *uint16, buflen uint32, buflenCopied *uint32, flags uint32, dir *uint16) (regerrno error) { - r0, _, _ := syscall.Syscall9(procRegLoadMUIStringW.Addr(), 7, uintptr(key), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buf)), uintptr(buflen), uintptr(unsafe.Pointer(buflenCopied)), uintptr(flags), uintptr(unsafe.Pointer(dir)), 0, 0) + r0, _, _ := syscall.SyscallN(procRegLoadMUIStringW.Addr(), uintptr(key), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buf)), uintptr(buflen), uintptr(unsafe.Pointer(buflenCopied)), uintptr(flags), uintptr(unsafe.Pointer(dir))) if r0 != 0 { regerrno = syscall.Errno(r0) } @@ -100,7 +100,7 @@ func regLoadMUIString(key syscall.Handle, name *uint16, buf *uint16, buflen uint } func regSetValueEx(key syscall.Handle, valueName *uint16, reserved uint32, vtype uint32, buf *byte, bufsize uint32) (regerrno error) { - r0, _, _ := syscall.Syscall6(procRegSetValueExW.Addr(), 6, uintptr(key), uintptr(unsafe.Pointer(valueName)), uintptr(reserved), uintptr(vtype), uintptr(unsafe.Pointer(buf)), uintptr(bufsize)) + r0, _, _ := syscall.SyscallN(procRegSetValueExW.Addr(), uintptr(key), uintptr(unsafe.Pointer(valueName)), uintptr(reserved), uintptr(vtype), uintptr(unsafe.Pointer(buf)), uintptr(bufsize)) if r0 != 0 { regerrno = syscall.Errno(r0) } @@ -108,7 +108,7 @@ func regSetValueEx(key syscall.Handle, valueName *uint16, reserved uint32, vtype } func expandEnvironmentStrings(src *uint16, dst *uint16, size uint32) (n uint32, err error) { - r0, _, e1 := syscall.Syscall(procExpandEnvironmentStringsW.Addr(), 3, uintptr(unsafe.Pointer(src)), uintptr(unsafe.Pointer(dst)), uintptr(size)) + r0, _, e1 := syscall.SyscallN(procExpandEnvironmentStringsW.Addr(), uintptr(unsafe.Pointer(src)), uintptr(unsafe.Pointer(dst)), uintptr(size)) n = uint32(r0) if n == 0 { err = errnoErr(e1) diff --git a/vendor/golang.org/x/sys/windows/types_windows.go b/vendor/golang.org/x/sys/windows/types_windows.go index 958bcf47a3..993a2297db 100644 --- a/vendor/golang.org/x/sys/windows/types_windows.go +++ b/vendor/golang.org/x/sys/windows/types_windows.go @@ -1976,6 +1976,12 @@ const ( SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1 ) +// FILE_ZERO_DATA_INFORMATION from winioctl.h +type FileZeroDataInformation struct { + FileOffset int64 + BeyondFinalZero int64 +} + const ( ComputerNameNetBIOS = 0 ComputerNameDnsHostname = 1 diff --git a/vendor/golang.org/x/sys/windows/zsyscall_windows.go b/vendor/golang.org/x/sys/windows/zsyscall_windows.go index a58bc48b8e..641a5f4b77 100644 --- a/vendor/golang.org/x/sys/windows/zsyscall_windows.go +++ b/vendor/golang.org/x/sys/windows/zsyscall_windows.go @@ -546,25 +546,25 @@ var ( ) func cm_Get_DevNode_Status(status *uint32, problemNumber *uint32, devInst DEVINST, flags uint32) (ret CONFIGRET) { - r0, _, _ := syscall.Syscall6(procCM_Get_DevNode_Status.Addr(), 4, uintptr(unsafe.Pointer(status)), uintptr(unsafe.Pointer(problemNumber)), uintptr(devInst), uintptr(flags), 0, 0) + r0, _, _ := syscall.SyscallN(procCM_Get_DevNode_Status.Addr(), uintptr(unsafe.Pointer(status)), uintptr(unsafe.Pointer(problemNumber)), uintptr(devInst), uintptr(flags)) ret = CONFIGRET(r0) return } func cm_Get_Device_Interface_List(interfaceClass *GUID, deviceID *uint16, buffer *uint16, bufferLen uint32, flags uint32) (ret CONFIGRET) { - r0, _, _ := syscall.Syscall6(procCM_Get_Device_Interface_ListW.Addr(), 5, uintptr(unsafe.Pointer(interfaceClass)), uintptr(unsafe.Pointer(deviceID)), uintptr(unsafe.Pointer(buffer)), uintptr(bufferLen), uintptr(flags), 0) + r0, _, _ := syscall.SyscallN(procCM_Get_Device_Interface_ListW.Addr(), uintptr(unsafe.Pointer(interfaceClass)), uintptr(unsafe.Pointer(deviceID)), uintptr(unsafe.Pointer(buffer)), uintptr(bufferLen), uintptr(flags)) ret = CONFIGRET(r0) return } func cm_Get_Device_Interface_List_Size(len *uint32, interfaceClass *GUID, deviceID *uint16, flags uint32) (ret CONFIGRET) { - r0, _, _ := syscall.Syscall6(procCM_Get_Device_Interface_List_SizeW.Addr(), 4, uintptr(unsafe.Pointer(len)), uintptr(unsafe.Pointer(interfaceClass)), uintptr(unsafe.Pointer(deviceID)), uintptr(flags), 0, 0) + r0, _, _ := syscall.SyscallN(procCM_Get_Device_Interface_List_SizeW.Addr(), uintptr(unsafe.Pointer(len)), uintptr(unsafe.Pointer(interfaceClass)), uintptr(unsafe.Pointer(deviceID)), uintptr(flags)) ret = CONFIGRET(r0) return } func cm_MapCrToWin32Err(configRet CONFIGRET, defaultWin32Error Errno) (ret Errno) { - r0, _, _ := syscall.Syscall(procCM_MapCrToWin32Err.Addr(), 2, uintptr(configRet), uintptr(defaultWin32Error), 0) + r0, _, _ := syscall.SyscallN(procCM_MapCrToWin32Err.Addr(), uintptr(configRet), uintptr(defaultWin32Error)) ret = Errno(r0) return } @@ -574,7 +574,7 @@ func AdjustTokenGroups(token Token, resetToDefault bool, newstate *Tokengroups, if resetToDefault { _p0 = 1 } - r1, _, e1 := syscall.Syscall6(procAdjustTokenGroups.Addr(), 6, uintptr(token), uintptr(_p0), uintptr(unsafe.Pointer(newstate)), uintptr(buflen), uintptr(unsafe.Pointer(prevstate)), uintptr(unsafe.Pointer(returnlen))) + r1, _, e1 := syscall.SyscallN(procAdjustTokenGroups.Addr(), uintptr(token), uintptr(_p0), uintptr(unsafe.Pointer(newstate)), uintptr(buflen), uintptr(unsafe.Pointer(prevstate)), uintptr(unsafe.Pointer(returnlen))) if r1 == 0 { err = errnoErr(e1) } @@ -586,7 +586,7 @@ func AdjustTokenPrivileges(token Token, disableAllPrivileges bool, newstate *Tok if disableAllPrivileges { _p0 = 1 } - r1, _, e1 := syscall.Syscall6(procAdjustTokenPrivileges.Addr(), 6, uintptr(token), uintptr(_p0), uintptr(unsafe.Pointer(newstate)), uintptr(buflen), uintptr(unsafe.Pointer(prevstate)), uintptr(unsafe.Pointer(returnlen))) + r1, _, e1 := syscall.SyscallN(procAdjustTokenPrivileges.Addr(), uintptr(token), uintptr(_p0), uintptr(unsafe.Pointer(newstate)), uintptr(buflen), uintptr(unsafe.Pointer(prevstate)), uintptr(unsafe.Pointer(returnlen))) if r1 == 0 { err = errnoErr(e1) } @@ -594,7 +594,7 @@ func AdjustTokenPrivileges(token Token, disableAllPrivileges bool, newstate *Tok } func AllocateAndInitializeSid(identAuth *SidIdentifierAuthority, subAuth byte, subAuth0 uint32, subAuth1 uint32, subAuth2 uint32, subAuth3 uint32, subAuth4 uint32, subAuth5 uint32, subAuth6 uint32, subAuth7 uint32, sid **SID) (err error) { - r1, _, e1 := syscall.Syscall12(procAllocateAndInitializeSid.Addr(), 11, uintptr(unsafe.Pointer(identAuth)), uintptr(subAuth), uintptr(subAuth0), uintptr(subAuth1), uintptr(subAuth2), uintptr(subAuth3), uintptr(subAuth4), uintptr(subAuth5), uintptr(subAuth6), uintptr(subAuth7), uintptr(unsafe.Pointer(sid)), 0) + r1, _, e1 := syscall.SyscallN(procAllocateAndInitializeSid.Addr(), uintptr(unsafe.Pointer(identAuth)), uintptr(subAuth), uintptr(subAuth0), uintptr(subAuth1), uintptr(subAuth2), uintptr(subAuth3), uintptr(subAuth4), uintptr(subAuth5), uintptr(subAuth6), uintptr(subAuth7), uintptr(unsafe.Pointer(sid))) if r1 == 0 { err = errnoErr(e1) } @@ -602,7 +602,7 @@ func AllocateAndInitializeSid(identAuth *SidIdentifierAuthority, subAuth byte, s } func buildSecurityDescriptor(owner *TRUSTEE, group *TRUSTEE, countAccessEntries uint32, accessEntries *EXPLICIT_ACCESS, countAuditEntries uint32, auditEntries *EXPLICIT_ACCESS, oldSecurityDescriptor *SECURITY_DESCRIPTOR, sizeNewSecurityDescriptor *uint32, newSecurityDescriptor **SECURITY_DESCRIPTOR) (ret error) { - r0, _, _ := syscall.Syscall9(procBuildSecurityDescriptorW.Addr(), 9, uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(group)), uintptr(countAccessEntries), uintptr(unsafe.Pointer(accessEntries)), uintptr(countAuditEntries), uintptr(unsafe.Pointer(auditEntries)), uintptr(unsafe.Pointer(oldSecurityDescriptor)), uintptr(unsafe.Pointer(sizeNewSecurityDescriptor)), uintptr(unsafe.Pointer(newSecurityDescriptor))) + r0, _, _ := syscall.SyscallN(procBuildSecurityDescriptorW.Addr(), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(group)), uintptr(countAccessEntries), uintptr(unsafe.Pointer(accessEntries)), uintptr(countAuditEntries), uintptr(unsafe.Pointer(auditEntries)), uintptr(unsafe.Pointer(oldSecurityDescriptor)), uintptr(unsafe.Pointer(sizeNewSecurityDescriptor)), uintptr(unsafe.Pointer(newSecurityDescriptor))) if r0 != 0 { ret = syscall.Errno(r0) } @@ -610,7 +610,7 @@ func buildSecurityDescriptor(owner *TRUSTEE, group *TRUSTEE, countAccessEntries } func ChangeServiceConfig2(service Handle, infoLevel uint32, info *byte) (err error) { - r1, _, e1 := syscall.Syscall(procChangeServiceConfig2W.Addr(), 3, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(info))) + r1, _, e1 := syscall.SyscallN(procChangeServiceConfig2W.Addr(), uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(info))) if r1 == 0 { err = errnoErr(e1) } @@ -618,7 +618,7 @@ func ChangeServiceConfig2(service Handle, infoLevel uint32, info *byte) (err err } func ChangeServiceConfig(service Handle, serviceType uint32, startType uint32, errorControl uint32, binaryPathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16, displayName *uint16) (err error) { - r1, _, e1 := syscall.Syscall12(procChangeServiceConfigW.Addr(), 11, uintptr(service), uintptr(serviceType), uintptr(startType), uintptr(errorControl), uintptr(unsafe.Pointer(binaryPathName)), uintptr(unsafe.Pointer(loadOrderGroup)), uintptr(unsafe.Pointer(tagId)), uintptr(unsafe.Pointer(dependencies)), uintptr(unsafe.Pointer(serviceStartName)), uintptr(unsafe.Pointer(password)), uintptr(unsafe.Pointer(displayName)), 0) + r1, _, e1 := syscall.SyscallN(procChangeServiceConfigW.Addr(), uintptr(service), uintptr(serviceType), uintptr(startType), uintptr(errorControl), uintptr(unsafe.Pointer(binaryPathName)), uintptr(unsafe.Pointer(loadOrderGroup)), uintptr(unsafe.Pointer(tagId)), uintptr(unsafe.Pointer(dependencies)), uintptr(unsafe.Pointer(serviceStartName)), uintptr(unsafe.Pointer(password)), uintptr(unsafe.Pointer(displayName))) if r1 == 0 { err = errnoErr(e1) } @@ -626,7 +626,7 @@ func ChangeServiceConfig(service Handle, serviceType uint32, startType uint32, e } func checkTokenMembership(tokenHandle Token, sidToCheck *SID, isMember *int32) (err error) { - r1, _, e1 := syscall.Syscall(procCheckTokenMembership.Addr(), 3, uintptr(tokenHandle), uintptr(unsafe.Pointer(sidToCheck)), uintptr(unsafe.Pointer(isMember))) + r1, _, e1 := syscall.SyscallN(procCheckTokenMembership.Addr(), uintptr(tokenHandle), uintptr(unsafe.Pointer(sidToCheck)), uintptr(unsafe.Pointer(isMember))) if r1 == 0 { err = errnoErr(e1) } @@ -634,7 +634,7 @@ func checkTokenMembership(tokenHandle Token, sidToCheck *SID, isMember *int32) ( } func CloseServiceHandle(handle Handle) (err error) { - r1, _, e1 := syscall.Syscall(procCloseServiceHandle.Addr(), 1, uintptr(handle), 0, 0) + r1, _, e1 := syscall.SyscallN(procCloseServiceHandle.Addr(), uintptr(handle)) if r1 == 0 { err = errnoErr(e1) } @@ -642,7 +642,7 @@ func CloseServiceHandle(handle Handle) (err error) { } func ControlService(service Handle, control uint32, status *SERVICE_STATUS) (err error) { - r1, _, e1 := syscall.Syscall(procControlService.Addr(), 3, uintptr(service), uintptr(control), uintptr(unsafe.Pointer(status))) + r1, _, e1 := syscall.SyscallN(procControlService.Addr(), uintptr(service), uintptr(control), uintptr(unsafe.Pointer(status))) if r1 == 0 { err = errnoErr(e1) } @@ -650,7 +650,7 @@ func ControlService(service Handle, control uint32, status *SERVICE_STATUS) (err } func convertSecurityDescriptorToStringSecurityDescriptor(sd *SECURITY_DESCRIPTOR, revision uint32, securityInformation SECURITY_INFORMATION, str **uint16, strLen *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procConvertSecurityDescriptorToStringSecurityDescriptorW.Addr(), 5, uintptr(unsafe.Pointer(sd)), uintptr(revision), uintptr(securityInformation), uintptr(unsafe.Pointer(str)), uintptr(unsafe.Pointer(strLen)), 0) + r1, _, e1 := syscall.SyscallN(procConvertSecurityDescriptorToStringSecurityDescriptorW.Addr(), uintptr(unsafe.Pointer(sd)), uintptr(revision), uintptr(securityInformation), uintptr(unsafe.Pointer(str)), uintptr(unsafe.Pointer(strLen))) if r1 == 0 { err = errnoErr(e1) } @@ -658,7 +658,7 @@ func convertSecurityDescriptorToStringSecurityDescriptor(sd *SECURITY_DESCRIPTOR } func ConvertSidToStringSid(sid *SID, stringSid **uint16) (err error) { - r1, _, e1 := syscall.Syscall(procConvertSidToStringSidW.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(stringSid)), 0) + r1, _, e1 := syscall.SyscallN(procConvertSidToStringSidW.Addr(), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(stringSid))) if r1 == 0 { err = errnoErr(e1) } @@ -675,7 +675,7 @@ func convertStringSecurityDescriptorToSecurityDescriptor(str string, revision ui } func _convertStringSecurityDescriptorToSecurityDescriptor(str *uint16, revision uint32, sd **SECURITY_DESCRIPTOR, size *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procConvertStringSecurityDescriptorToSecurityDescriptorW.Addr(), 4, uintptr(unsafe.Pointer(str)), uintptr(revision), uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(size)), 0, 0) + r1, _, e1 := syscall.SyscallN(procConvertStringSecurityDescriptorToSecurityDescriptorW.Addr(), uintptr(unsafe.Pointer(str)), uintptr(revision), uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(size))) if r1 == 0 { err = errnoErr(e1) } @@ -683,7 +683,7 @@ func _convertStringSecurityDescriptorToSecurityDescriptor(str *uint16, revision } func ConvertStringSidToSid(stringSid *uint16, sid **SID) (err error) { - r1, _, e1 := syscall.Syscall(procConvertStringSidToSidW.Addr(), 2, uintptr(unsafe.Pointer(stringSid)), uintptr(unsafe.Pointer(sid)), 0) + r1, _, e1 := syscall.SyscallN(procConvertStringSidToSidW.Addr(), uintptr(unsafe.Pointer(stringSid)), uintptr(unsafe.Pointer(sid))) if r1 == 0 { err = errnoErr(e1) } @@ -691,7 +691,7 @@ func ConvertStringSidToSid(stringSid *uint16, sid **SID) (err error) { } func CopySid(destSidLen uint32, destSid *SID, srcSid *SID) (err error) { - r1, _, e1 := syscall.Syscall(procCopySid.Addr(), 3, uintptr(destSidLen), uintptr(unsafe.Pointer(destSid)), uintptr(unsafe.Pointer(srcSid))) + r1, _, e1 := syscall.SyscallN(procCopySid.Addr(), uintptr(destSidLen), uintptr(unsafe.Pointer(destSid)), uintptr(unsafe.Pointer(srcSid))) if r1 == 0 { err = errnoErr(e1) } @@ -703,7 +703,7 @@ func CreateProcessAsUser(token Token, appName *uint16, commandLine *uint16, proc if inheritHandles { _p0 = 1 } - r1, _, e1 := syscall.Syscall12(procCreateProcessAsUserW.Addr(), 11, uintptr(token), uintptr(unsafe.Pointer(appName)), uintptr(unsafe.Pointer(commandLine)), uintptr(unsafe.Pointer(procSecurity)), uintptr(unsafe.Pointer(threadSecurity)), uintptr(_p0), uintptr(creationFlags), uintptr(unsafe.Pointer(env)), uintptr(unsafe.Pointer(currentDir)), uintptr(unsafe.Pointer(startupInfo)), uintptr(unsafe.Pointer(outProcInfo)), 0) + r1, _, e1 := syscall.SyscallN(procCreateProcessAsUserW.Addr(), uintptr(token), uintptr(unsafe.Pointer(appName)), uintptr(unsafe.Pointer(commandLine)), uintptr(unsafe.Pointer(procSecurity)), uintptr(unsafe.Pointer(threadSecurity)), uintptr(_p0), uintptr(creationFlags), uintptr(unsafe.Pointer(env)), uintptr(unsafe.Pointer(currentDir)), uintptr(unsafe.Pointer(startupInfo)), uintptr(unsafe.Pointer(outProcInfo))) if r1 == 0 { err = errnoErr(e1) } @@ -711,7 +711,7 @@ func CreateProcessAsUser(token Token, appName *uint16, commandLine *uint16, proc } func CreateService(mgr Handle, serviceName *uint16, displayName *uint16, access uint32, srvType uint32, startType uint32, errCtl uint32, pathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall15(procCreateServiceW.Addr(), 13, uintptr(mgr), uintptr(unsafe.Pointer(serviceName)), uintptr(unsafe.Pointer(displayName)), uintptr(access), uintptr(srvType), uintptr(startType), uintptr(errCtl), uintptr(unsafe.Pointer(pathName)), uintptr(unsafe.Pointer(loadOrderGroup)), uintptr(unsafe.Pointer(tagId)), uintptr(unsafe.Pointer(dependencies)), uintptr(unsafe.Pointer(serviceStartName)), uintptr(unsafe.Pointer(password)), 0, 0) + r0, _, e1 := syscall.SyscallN(procCreateServiceW.Addr(), uintptr(mgr), uintptr(unsafe.Pointer(serviceName)), uintptr(unsafe.Pointer(displayName)), uintptr(access), uintptr(srvType), uintptr(startType), uintptr(errCtl), uintptr(unsafe.Pointer(pathName)), uintptr(unsafe.Pointer(loadOrderGroup)), uintptr(unsafe.Pointer(tagId)), uintptr(unsafe.Pointer(dependencies)), uintptr(unsafe.Pointer(serviceStartName)), uintptr(unsafe.Pointer(password))) handle = Handle(r0) if handle == 0 { err = errnoErr(e1) @@ -720,7 +720,7 @@ func CreateService(mgr Handle, serviceName *uint16, displayName *uint16, access } func createWellKnownSid(sidType WELL_KNOWN_SID_TYPE, domainSid *SID, sid *SID, sizeSid *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procCreateWellKnownSid.Addr(), 4, uintptr(sidType), uintptr(unsafe.Pointer(domainSid)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(sizeSid)), 0, 0) + r1, _, e1 := syscall.SyscallN(procCreateWellKnownSid.Addr(), uintptr(sidType), uintptr(unsafe.Pointer(domainSid)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(sizeSid))) if r1 == 0 { err = errnoErr(e1) } @@ -728,7 +728,7 @@ func createWellKnownSid(sidType WELL_KNOWN_SID_TYPE, domainSid *SID, sid *SID, s } func CryptAcquireContext(provhandle *Handle, container *uint16, provider *uint16, provtype uint32, flags uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procCryptAcquireContextW.Addr(), 5, uintptr(unsafe.Pointer(provhandle)), uintptr(unsafe.Pointer(container)), uintptr(unsafe.Pointer(provider)), uintptr(provtype), uintptr(flags), 0) + r1, _, e1 := syscall.SyscallN(procCryptAcquireContextW.Addr(), uintptr(unsafe.Pointer(provhandle)), uintptr(unsafe.Pointer(container)), uintptr(unsafe.Pointer(provider)), uintptr(provtype), uintptr(flags)) if r1 == 0 { err = errnoErr(e1) } @@ -736,7 +736,7 @@ func CryptAcquireContext(provhandle *Handle, container *uint16, provider *uint16 } func CryptGenRandom(provhandle Handle, buflen uint32, buf *byte) (err error) { - r1, _, e1 := syscall.Syscall(procCryptGenRandom.Addr(), 3, uintptr(provhandle), uintptr(buflen), uintptr(unsafe.Pointer(buf))) + r1, _, e1 := syscall.SyscallN(procCryptGenRandom.Addr(), uintptr(provhandle), uintptr(buflen), uintptr(unsafe.Pointer(buf))) if r1 == 0 { err = errnoErr(e1) } @@ -744,7 +744,7 @@ func CryptGenRandom(provhandle Handle, buflen uint32, buf *byte) (err error) { } func CryptReleaseContext(provhandle Handle, flags uint32) (err error) { - r1, _, e1 := syscall.Syscall(procCryptReleaseContext.Addr(), 2, uintptr(provhandle), uintptr(flags), 0) + r1, _, e1 := syscall.SyscallN(procCryptReleaseContext.Addr(), uintptr(provhandle), uintptr(flags)) if r1 == 0 { err = errnoErr(e1) } @@ -752,7 +752,7 @@ func CryptReleaseContext(provhandle Handle, flags uint32) (err error) { } func DeleteService(service Handle) (err error) { - r1, _, e1 := syscall.Syscall(procDeleteService.Addr(), 1, uintptr(service), 0, 0) + r1, _, e1 := syscall.SyscallN(procDeleteService.Addr(), uintptr(service)) if r1 == 0 { err = errnoErr(e1) } @@ -760,7 +760,7 @@ func DeleteService(service Handle) (err error) { } func DeregisterEventSource(handle Handle) (err error) { - r1, _, e1 := syscall.Syscall(procDeregisterEventSource.Addr(), 1, uintptr(handle), 0, 0) + r1, _, e1 := syscall.SyscallN(procDeregisterEventSource.Addr(), uintptr(handle)) if r1 == 0 { err = errnoErr(e1) } @@ -768,7 +768,7 @@ func DeregisterEventSource(handle Handle) (err error) { } func DuplicateTokenEx(existingToken Token, desiredAccess uint32, tokenAttributes *SecurityAttributes, impersonationLevel uint32, tokenType uint32, newToken *Token) (err error) { - r1, _, e1 := syscall.Syscall6(procDuplicateTokenEx.Addr(), 6, uintptr(existingToken), uintptr(desiredAccess), uintptr(unsafe.Pointer(tokenAttributes)), uintptr(impersonationLevel), uintptr(tokenType), uintptr(unsafe.Pointer(newToken))) + r1, _, e1 := syscall.SyscallN(procDuplicateTokenEx.Addr(), uintptr(existingToken), uintptr(desiredAccess), uintptr(unsafe.Pointer(tokenAttributes)), uintptr(impersonationLevel), uintptr(tokenType), uintptr(unsafe.Pointer(newToken))) if r1 == 0 { err = errnoErr(e1) } @@ -776,7 +776,7 @@ func DuplicateTokenEx(existingToken Token, desiredAccess uint32, tokenAttributes } func EnumDependentServices(service Handle, activityState uint32, services *ENUM_SERVICE_STATUS, buffSize uint32, bytesNeeded *uint32, servicesReturned *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procEnumDependentServicesW.Addr(), 6, uintptr(service), uintptr(activityState), uintptr(unsafe.Pointer(services)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded)), uintptr(unsafe.Pointer(servicesReturned))) + r1, _, e1 := syscall.SyscallN(procEnumDependentServicesW.Addr(), uintptr(service), uintptr(activityState), uintptr(unsafe.Pointer(services)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded)), uintptr(unsafe.Pointer(servicesReturned))) if r1 == 0 { err = errnoErr(e1) } @@ -784,7 +784,7 @@ func EnumDependentServices(service Handle, activityState uint32, services *ENUM_ } func EnumServicesStatusEx(mgr Handle, infoLevel uint32, serviceType uint32, serviceState uint32, services *byte, bufSize uint32, bytesNeeded *uint32, servicesReturned *uint32, resumeHandle *uint32, groupName *uint16) (err error) { - r1, _, e1 := syscall.Syscall12(procEnumServicesStatusExW.Addr(), 10, uintptr(mgr), uintptr(infoLevel), uintptr(serviceType), uintptr(serviceState), uintptr(unsafe.Pointer(services)), uintptr(bufSize), uintptr(unsafe.Pointer(bytesNeeded)), uintptr(unsafe.Pointer(servicesReturned)), uintptr(unsafe.Pointer(resumeHandle)), uintptr(unsafe.Pointer(groupName)), 0, 0) + r1, _, e1 := syscall.SyscallN(procEnumServicesStatusExW.Addr(), uintptr(mgr), uintptr(infoLevel), uintptr(serviceType), uintptr(serviceState), uintptr(unsafe.Pointer(services)), uintptr(bufSize), uintptr(unsafe.Pointer(bytesNeeded)), uintptr(unsafe.Pointer(servicesReturned)), uintptr(unsafe.Pointer(resumeHandle)), uintptr(unsafe.Pointer(groupName))) if r1 == 0 { err = errnoErr(e1) } @@ -792,13 +792,13 @@ func EnumServicesStatusEx(mgr Handle, infoLevel uint32, serviceType uint32, serv } func EqualSid(sid1 *SID, sid2 *SID) (isEqual bool) { - r0, _, _ := syscall.Syscall(procEqualSid.Addr(), 2, uintptr(unsafe.Pointer(sid1)), uintptr(unsafe.Pointer(sid2)), 0) + r0, _, _ := syscall.SyscallN(procEqualSid.Addr(), uintptr(unsafe.Pointer(sid1)), uintptr(unsafe.Pointer(sid2))) isEqual = r0 != 0 return } func FreeSid(sid *SID) (err error) { - r1, _, e1 := syscall.Syscall(procFreeSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0) + r1, _, e1 := syscall.SyscallN(procFreeSid.Addr(), uintptr(unsafe.Pointer(sid))) if r1 != 0 { err = errnoErr(e1) } @@ -806,7 +806,7 @@ func FreeSid(sid *SID) (err error) { } func GetAce(acl *ACL, aceIndex uint32, pAce **ACCESS_ALLOWED_ACE) (err error) { - r1, _, e1 := syscall.Syscall(procGetAce.Addr(), 3, uintptr(unsafe.Pointer(acl)), uintptr(aceIndex), uintptr(unsafe.Pointer(pAce))) + r1, _, e1 := syscall.SyscallN(procGetAce.Addr(), uintptr(unsafe.Pointer(acl)), uintptr(aceIndex), uintptr(unsafe.Pointer(pAce))) if r1 == 0 { err = errnoErr(e1) } @@ -814,7 +814,7 @@ func GetAce(acl *ACL, aceIndex uint32, pAce **ACCESS_ALLOWED_ACE) (err error) { } func GetLengthSid(sid *SID) (len uint32) { - r0, _, _ := syscall.Syscall(procGetLengthSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0) + r0, _, _ := syscall.SyscallN(procGetLengthSid.Addr(), uintptr(unsafe.Pointer(sid))) len = uint32(r0) return } @@ -829,7 +829,7 @@ func getNamedSecurityInfo(objectName string, objectType SE_OBJECT_TYPE, security } func _getNamedSecurityInfo(objectName *uint16, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION, owner **SID, group **SID, dacl **ACL, sacl **ACL, sd **SECURITY_DESCRIPTOR) (ret error) { - r0, _, _ := syscall.Syscall9(procGetNamedSecurityInfoW.Addr(), 8, uintptr(unsafe.Pointer(objectName)), uintptr(objectType), uintptr(securityInformation), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(sacl)), uintptr(unsafe.Pointer(sd)), 0) + r0, _, _ := syscall.SyscallN(procGetNamedSecurityInfoW.Addr(), uintptr(unsafe.Pointer(objectName)), uintptr(objectType), uintptr(securityInformation), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(sacl)), uintptr(unsafe.Pointer(sd))) if r0 != 0 { ret = syscall.Errno(r0) } @@ -837,7 +837,7 @@ func _getNamedSecurityInfo(objectName *uint16, objectType SE_OBJECT_TYPE, securi } func getSecurityDescriptorControl(sd *SECURITY_DESCRIPTOR, control *SECURITY_DESCRIPTOR_CONTROL, revision *uint32) (err error) { - r1, _, e1 := syscall.Syscall(procGetSecurityDescriptorControl.Addr(), 3, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(control)), uintptr(unsafe.Pointer(revision))) + r1, _, e1 := syscall.SyscallN(procGetSecurityDescriptorControl.Addr(), uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(control)), uintptr(unsafe.Pointer(revision))) if r1 == 0 { err = errnoErr(e1) } @@ -853,7 +853,7 @@ func getSecurityDescriptorDacl(sd *SECURITY_DESCRIPTOR, daclPresent *bool, dacl if *daclDefaulted { _p1 = 1 } - r1, _, e1 := syscall.Syscall6(procGetSecurityDescriptorDacl.Addr(), 4, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(&_p0)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(&_p1)), 0, 0) + r1, _, e1 := syscall.SyscallN(procGetSecurityDescriptorDacl.Addr(), uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(&_p0)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(&_p1))) *daclPresent = _p0 != 0 *daclDefaulted = _p1 != 0 if r1 == 0 { @@ -867,7 +867,7 @@ func getSecurityDescriptorGroup(sd *SECURITY_DESCRIPTOR, group **SID, groupDefau if *groupDefaulted { _p0 = 1 } - r1, _, e1 := syscall.Syscall(procGetSecurityDescriptorGroup.Addr(), 3, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(&_p0))) + r1, _, e1 := syscall.SyscallN(procGetSecurityDescriptorGroup.Addr(), uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(&_p0))) *groupDefaulted = _p0 != 0 if r1 == 0 { err = errnoErr(e1) @@ -876,7 +876,7 @@ func getSecurityDescriptorGroup(sd *SECURITY_DESCRIPTOR, group **SID, groupDefau } func getSecurityDescriptorLength(sd *SECURITY_DESCRIPTOR) (len uint32) { - r0, _, _ := syscall.Syscall(procGetSecurityDescriptorLength.Addr(), 1, uintptr(unsafe.Pointer(sd)), 0, 0) + r0, _, _ := syscall.SyscallN(procGetSecurityDescriptorLength.Addr(), uintptr(unsafe.Pointer(sd))) len = uint32(r0) return } @@ -886,7 +886,7 @@ func getSecurityDescriptorOwner(sd *SECURITY_DESCRIPTOR, owner **SID, ownerDefau if *ownerDefaulted { _p0 = 1 } - r1, _, e1 := syscall.Syscall(procGetSecurityDescriptorOwner.Addr(), 3, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(&_p0))) + r1, _, e1 := syscall.SyscallN(procGetSecurityDescriptorOwner.Addr(), uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(&_p0))) *ownerDefaulted = _p0 != 0 if r1 == 0 { err = errnoErr(e1) @@ -895,7 +895,7 @@ func getSecurityDescriptorOwner(sd *SECURITY_DESCRIPTOR, owner **SID, ownerDefau } func getSecurityDescriptorRMControl(sd *SECURITY_DESCRIPTOR, rmControl *uint8) (ret error) { - r0, _, _ := syscall.Syscall(procGetSecurityDescriptorRMControl.Addr(), 2, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(rmControl)), 0) + r0, _, _ := syscall.SyscallN(procGetSecurityDescriptorRMControl.Addr(), uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(rmControl))) if r0 != 0 { ret = syscall.Errno(r0) } @@ -911,7 +911,7 @@ func getSecurityDescriptorSacl(sd *SECURITY_DESCRIPTOR, saclPresent *bool, sacl if *saclDefaulted { _p1 = 1 } - r1, _, e1 := syscall.Syscall6(procGetSecurityDescriptorSacl.Addr(), 4, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(&_p0)), uintptr(unsafe.Pointer(sacl)), uintptr(unsafe.Pointer(&_p1)), 0, 0) + r1, _, e1 := syscall.SyscallN(procGetSecurityDescriptorSacl.Addr(), uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(&_p0)), uintptr(unsafe.Pointer(sacl)), uintptr(unsafe.Pointer(&_p1))) *saclPresent = _p0 != 0 *saclDefaulted = _p1 != 0 if r1 == 0 { @@ -921,7 +921,7 @@ func getSecurityDescriptorSacl(sd *SECURITY_DESCRIPTOR, saclPresent *bool, sacl } func getSecurityInfo(handle Handle, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION, owner **SID, group **SID, dacl **ACL, sacl **ACL, sd **SECURITY_DESCRIPTOR) (ret error) { - r0, _, _ := syscall.Syscall9(procGetSecurityInfo.Addr(), 8, uintptr(handle), uintptr(objectType), uintptr(securityInformation), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(sacl)), uintptr(unsafe.Pointer(sd)), 0) + r0, _, _ := syscall.SyscallN(procGetSecurityInfo.Addr(), uintptr(handle), uintptr(objectType), uintptr(securityInformation), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(sacl)), uintptr(unsafe.Pointer(sd))) if r0 != 0 { ret = syscall.Errno(r0) } @@ -929,25 +929,25 @@ func getSecurityInfo(handle Handle, objectType SE_OBJECT_TYPE, securityInformati } func getSidIdentifierAuthority(sid *SID) (authority *SidIdentifierAuthority) { - r0, _, _ := syscall.Syscall(procGetSidIdentifierAuthority.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0) + r0, _, _ := syscall.SyscallN(procGetSidIdentifierAuthority.Addr(), uintptr(unsafe.Pointer(sid))) authority = (*SidIdentifierAuthority)(unsafe.Pointer(r0)) return } func getSidSubAuthority(sid *SID, index uint32) (subAuthority *uint32) { - r0, _, _ := syscall.Syscall(procGetSidSubAuthority.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(index), 0) + r0, _, _ := syscall.SyscallN(procGetSidSubAuthority.Addr(), uintptr(unsafe.Pointer(sid)), uintptr(index)) subAuthority = (*uint32)(unsafe.Pointer(r0)) return } func getSidSubAuthorityCount(sid *SID) (count *uint8) { - r0, _, _ := syscall.Syscall(procGetSidSubAuthorityCount.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0) + r0, _, _ := syscall.SyscallN(procGetSidSubAuthorityCount.Addr(), uintptr(unsafe.Pointer(sid))) count = (*uint8)(unsafe.Pointer(r0)) return } func GetTokenInformation(token Token, infoClass uint32, info *byte, infoLen uint32, returnedLen *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procGetTokenInformation.Addr(), 5, uintptr(token), uintptr(infoClass), uintptr(unsafe.Pointer(info)), uintptr(infoLen), uintptr(unsafe.Pointer(returnedLen)), 0) + r1, _, e1 := syscall.SyscallN(procGetTokenInformation.Addr(), uintptr(token), uintptr(infoClass), uintptr(unsafe.Pointer(info)), uintptr(infoLen), uintptr(unsafe.Pointer(returnedLen))) if r1 == 0 { err = errnoErr(e1) } @@ -955,7 +955,7 @@ func GetTokenInformation(token Token, infoClass uint32, info *byte, infoLen uint } func ImpersonateSelf(impersonationlevel uint32) (err error) { - r1, _, e1 := syscall.Syscall(procImpersonateSelf.Addr(), 1, uintptr(impersonationlevel), 0, 0) + r1, _, e1 := syscall.SyscallN(procImpersonateSelf.Addr(), uintptr(impersonationlevel)) if r1 == 0 { err = errnoErr(e1) } @@ -963,7 +963,7 @@ func ImpersonateSelf(impersonationlevel uint32) (err error) { } func initializeSecurityDescriptor(absoluteSD *SECURITY_DESCRIPTOR, revision uint32) (err error) { - r1, _, e1 := syscall.Syscall(procInitializeSecurityDescriptor.Addr(), 2, uintptr(unsafe.Pointer(absoluteSD)), uintptr(revision), 0) + r1, _, e1 := syscall.SyscallN(procInitializeSecurityDescriptor.Addr(), uintptr(unsafe.Pointer(absoluteSD)), uintptr(revision)) if r1 == 0 { err = errnoErr(e1) } @@ -979,7 +979,7 @@ func InitiateSystemShutdownEx(machineName *uint16, message *uint16, timeout uint if rebootAfterShutdown { _p1 = 1 } - r1, _, e1 := syscall.Syscall6(procInitiateSystemShutdownExW.Addr(), 6, uintptr(unsafe.Pointer(machineName)), uintptr(unsafe.Pointer(message)), uintptr(timeout), uintptr(_p0), uintptr(_p1), uintptr(reason)) + r1, _, e1 := syscall.SyscallN(procInitiateSystemShutdownExW.Addr(), uintptr(unsafe.Pointer(machineName)), uintptr(unsafe.Pointer(message)), uintptr(timeout), uintptr(_p0), uintptr(_p1), uintptr(reason)) if r1 == 0 { err = errnoErr(e1) } @@ -987,7 +987,7 @@ func InitiateSystemShutdownEx(machineName *uint16, message *uint16, timeout uint } func isTokenRestricted(tokenHandle Token) (ret bool, err error) { - r0, _, e1 := syscall.Syscall(procIsTokenRestricted.Addr(), 1, uintptr(tokenHandle), 0, 0) + r0, _, e1 := syscall.SyscallN(procIsTokenRestricted.Addr(), uintptr(tokenHandle)) ret = r0 != 0 if !ret { err = errnoErr(e1) @@ -996,25 +996,25 @@ func isTokenRestricted(tokenHandle Token) (ret bool, err error) { } func isValidSecurityDescriptor(sd *SECURITY_DESCRIPTOR) (isValid bool) { - r0, _, _ := syscall.Syscall(procIsValidSecurityDescriptor.Addr(), 1, uintptr(unsafe.Pointer(sd)), 0, 0) + r0, _, _ := syscall.SyscallN(procIsValidSecurityDescriptor.Addr(), uintptr(unsafe.Pointer(sd))) isValid = r0 != 0 return } func isValidSid(sid *SID) (isValid bool) { - r0, _, _ := syscall.Syscall(procIsValidSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0) + r0, _, _ := syscall.SyscallN(procIsValidSid.Addr(), uintptr(unsafe.Pointer(sid))) isValid = r0 != 0 return } func isWellKnownSid(sid *SID, sidType WELL_KNOWN_SID_TYPE) (isWellKnown bool) { - r0, _, _ := syscall.Syscall(procIsWellKnownSid.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(sidType), 0) + r0, _, _ := syscall.SyscallN(procIsWellKnownSid.Addr(), uintptr(unsafe.Pointer(sid)), uintptr(sidType)) isWellKnown = r0 != 0 return } func LookupAccountName(systemName *uint16, accountName *uint16, sid *SID, sidLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) { - r1, _, e1 := syscall.Syscall9(procLookupAccountNameW.Addr(), 7, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(accountName)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(sidLen)), uintptr(unsafe.Pointer(refdDomainName)), uintptr(unsafe.Pointer(refdDomainNameLen)), uintptr(unsafe.Pointer(use)), 0, 0) + r1, _, e1 := syscall.SyscallN(procLookupAccountNameW.Addr(), uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(accountName)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(sidLen)), uintptr(unsafe.Pointer(refdDomainName)), uintptr(unsafe.Pointer(refdDomainNameLen)), uintptr(unsafe.Pointer(use))) if r1 == 0 { err = errnoErr(e1) } @@ -1022,7 +1022,7 @@ func LookupAccountName(systemName *uint16, accountName *uint16, sid *SID, sidLen } func LookupAccountSid(systemName *uint16, sid *SID, name *uint16, nameLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) { - r1, _, e1 := syscall.Syscall9(procLookupAccountSidW.Addr(), 7, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(refdDomainName)), uintptr(unsafe.Pointer(refdDomainNameLen)), uintptr(unsafe.Pointer(use)), 0, 0) + r1, _, e1 := syscall.SyscallN(procLookupAccountSidW.Addr(), uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(refdDomainName)), uintptr(unsafe.Pointer(refdDomainNameLen)), uintptr(unsafe.Pointer(use))) if r1 == 0 { err = errnoErr(e1) } @@ -1030,7 +1030,7 @@ func LookupAccountSid(systemName *uint16, sid *SID, name *uint16, nameLen *uint3 } func LookupPrivilegeValue(systemname *uint16, name *uint16, luid *LUID) (err error) { - r1, _, e1 := syscall.Syscall(procLookupPrivilegeValueW.Addr(), 3, uintptr(unsafe.Pointer(systemname)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(luid))) + r1, _, e1 := syscall.SyscallN(procLookupPrivilegeValueW.Addr(), uintptr(unsafe.Pointer(systemname)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(luid))) if r1 == 0 { err = errnoErr(e1) } @@ -1038,7 +1038,7 @@ func LookupPrivilegeValue(systemname *uint16, name *uint16, luid *LUID) (err err } func makeAbsoluteSD(selfRelativeSD *SECURITY_DESCRIPTOR, absoluteSD *SECURITY_DESCRIPTOR, absoluteSDSize *uint32, dacl *ACL, daclSize *uint32, sacl *ACL, saclSize *uint32, owner *SID, ownerSize *uint32, group *SID, groupSize *uint32) (err error) { - r1, _, e1 := syscall.Syscall12(procMakeAbsoluteSD.Addr(), 11, uintptr(unsafe.Pointer(selfRelativeSD)), uintptr(unsafe.Pointer(absoluteSD)), uintptr(unsafe.Pointer(absoluteSDSize)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(daclSize)), uintptr(unsafe.Pointer(sacl)), uintptr(unsafe.Pointer(saclSize)), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(ownerSize)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(groupSize)), 0) + r1, _, e1 := syscall.SyscallN(procMakeAbsoluteSD.Addr(), uintptr(unsafe.Pointer(selfRelativeSD)), uintptr(unsafe.Pointer(absoluteSD)), uintptr(unsafe.Pointer(absoluteSDSize)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(daclSize)), uintptr(unsafe.Pointer(sacl)), uintptr(unsafe.Pointer(saclSize)), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(ownerSize)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(groupSize))) if r1 == 0 { err = errnoErr(e1) } @@ -1046,7 +1046,7 @@ func makeAbsoluteSD(selfRelativeSD *SECURITY_DESCRIPTOR, absoluteSD *SECURITY_DE } func makeSelfRelativeSD(absoluteSD *SECURITY_DESCRIPTOR, selfRelativeSD *SECURITY_DESCRIPTOR, selfRelativeSDSize *uint32) (err error) { - r1, _, e1 := syscall.Syscall(procMakeSelfRelativeSD.Addr(), 3, uintptr(unsafe.Pointer(absoluteSD)), uintptr(unsafe.Pointer(selfRelativeSD)), uintptr(unsafe.Pointer(selfRelativeSDSize))) + r1, _, e1 := syscall.SyscallN(procMakeSelfRelativeSD.Addr(), uintptr(unsafe.Pointer(absoluteSD)), uintptr(unsafe.Pointer(selfRelativeSD)), uintptr(unsafe.Pointer(selfRelativeSDSize))) if r1 == 0 { err = errnoErr(e1) } @@ -1054,7 +1054,7 @@ func makeSelfRelativeSD(absoluteSD *SECURITY_DESCRIPTOR, selfRelativeSD *SECURIT } func NotifyServiceStatusChange(service Handle, notifyMask uint32, notifier *SERVICE_NOTIFY) (ret error) { - r0, _, _ := syscall.Syscall(procNotifyServiceStatusChangeW.Addr(), 3, uintptr(service), uintptr(notifyMask), uintptr(unsafe.Pointer(notifier))) + r0, _, _ := syscall.SyscallN(procNotifyServiceStatusChangeW.Addr(), uintptr(service), uintptr(notifyMask), uintptr(unsafe.Pointer(notifier))) if r0 != 0 { ret = syscall.Errno(r0) } @@ -1062,7 +1062,7 @@ func NotifyServiceStatusChange(service Handle, notifyMask uint32, notifier *SERV } func OpenProcessToken(process Handle, access uint32, token *Token) (err error) { - r1, _, e1 := syscall.Syscall(procOpenProcessToken.Addr(), 3, uintptr(process), uintptr(access), uintptr(unsafe.Pointer(token))) + r1, _, e1 := syscall.SyscallN(procOpenProcessToken.Addr(), uintptr(process), uintptr(access), uintptr(unsafe.Pointer(token))) if r1 == 0 { err = errnoErr(e1) } @@ -1070,7 +1070,7 @@ func OpenProcessToken(process Handle, access uint32, token *Token) (err error) { } func OpenSCManager(machineName *uint16, databaseName *uint16, access uint32) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall(procOpenSCManagerW.Addr(), 3, uintptr(unsafe.Pointer(machineName)), uintptr(unsafe.Pointer(databaseName)), uintptr(access)) + r0, _, e1 := syscall.SyscallN(procOpenSCManagerW.Addr(), uintptr(unsafe.Pointer(machineName)), uintptr(unsafe.Pointer(databaseName)), uintptr(access)) handle = Handle(r0) if handle == 0 { err = errnoErr(e1) @@ -1079,7 +1079,7 @@ func OpenSCManager(machineName *uint16, databaseName *uint16, access uint32) (ha } func OpenService(mgr Handle, serviceName *uint16, access uint32) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall(procOpenServiceW.Addr(), 3, uintptr(mgr), uintptr(unsafe.Pointer(serviceName)), uintptr(access)) + r0, _, e1 := syscall.SyscallN(procOpenServiceW.Addr(), uintptr(mgr), uintptr(unsafe.Pointer(serviceName)), uintptr(access)) handle = Handle(r0) if handle == 0 { err = errnoErr(e1) @@ -1092,7 +1092,7 @@ func OpenThreadToken(thread Handle, access uint32, openAsSelf bool, token *Token if openAsSelf { _p0 = 1 } - r1, _, e1 := syscall.Syscall6(procOpenThreadToken.Addr(), 4, uintptr(thread), uintptr(access), uintptr(_p0), uintptr(unsafe.Pointer(token)), 0, 0) + r1, _, e1 := syscall.SyscallN(procOpenThreadToken.Addr(), uintptr(thread), uintptr(access), uintptr(_p0), uintptr(unsafe.Pointer(token))) if r1 == 0 { err = errnoErr(e1) } @@ -1100,7 +1100,7 @@ func OpenThreadToken(thread Handle, access uint32, openAsSelf bool, token *Token } func QueryServiceConfig2(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procQueryServiceConfig2W.Addr(), 5, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(buff)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded)), 0) + r1, _, e1 := syscall.SyscallN(procQueryServiceConfig2W.Addr(), uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(buff)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded))) if r1 == 0 { err = errnoErr(e1) } @@ -1108,7 +1108,7 @@ func QueryServiceConfig2(service Handle, infoLevel uint32, buff *byte, buffSize } func QueryServiceConfig(service Handle, serviceConfig *QUERY_SERVICE_CONFIG, bufSize uint32, bytesNeeded *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procQueryServiceConfigW.Addr(), 4, uintptr(service), uintptr(unsafe.Pointer(serviceConfig)), uintptr(bufSize), uintptr(unsafe.Pointer(bytesNeeded)), 0, 0) + r1, _, e1 := syscall.SyscallN(procQueryServiceConfigW.Addr(), uintptr(service), uintptr(unsafe.Pointer(serviceConfig)), uintptr(bufSize), uintptr(unsafe.Pointer(bytesNeeded))) if r1 == 0 { err = errnoErr(e1) } @@ -1120,7 +1120,7 @@ func QueryServiceDynamicInformation(service Handle, infoLevel uint32, dynamicInf if err != nil { return } - r1, _, e1 := syscall.Syscall(procQueryServiceDynamicInformation.Addr(), 3, uintptr(service), uintptr(infoLevel), uintptr(dynamicInfo)) + r1, _, e1 := syscall.SyscallN(procQueryServiceDynamicInformation.Addr(), uintptr(service), uintptr(infoLevel), uintptr(dynamicInfo)) if r1 == 0 { err = errnoErr(e1) } @@ -1128,7 +1128,7 @@ func QueryServiceDynamicInformation(service Handle, infoLevel uint32, dynamicInf } func QueryServiceLockStatus(mgr Handle, lockStatus *QUERY_SERVICE_LOCK_STATUS, bufSize uint32, bytesNeeded *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procQueryServiceLockStatusW.Addr(), 4, uintptr(mgr), uintptr(unsafe.Pointer(lockStatus)), uintptr(bufSize), uintptr(unsafe.Pointer(bytesNeeded)), 0, 0) + r1, _, e1 := syscall.SyscallN(procQueryServiceLockStatusW.Addr(), uintptr(mgr), uintptr(unsafe.Pointer(lockStatus)), uintptr(bufSize), uintptr(unsafe.Pointer(bytesNeeded))) if r1 == 0 { err = errnoErr(e1) } @@ -1136,7 +1136,7 @@ func QueryServiceLockStatus(mgr Handle, lockStatus *QUERY_SERVICE_LOCK_STATUS, b } func QueryServiceStatus(service Handle, status *SERVICE_STATUS) (err error) { - r1, _, e1 := syscall.Syscall(procQueryServiceStatus.Addr(), 2, uintptr(service), uintptr(unsafe.Pointer(status)), 0) + r1, _, e1 := syscall.SyscallN(procQueryServiceStatus.Addr(), uintptr(service), uintptr(unsafe.Pointer(status))) if r1 == 0 { err = errnoErr(e1) } @@ -1144,7 +1144,7 @@ func QueryServiceStatus(service Handle, status *SERVICE_STATUS) (err error) { } func QueryServiceStatusEx(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procQueryServiceStatusEx.Addr(), 5, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(buff)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded)), 0) + r1, _, e1 := syscall.SyscallN(procQueryServiceStatusEx.Addr(), uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(buff)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded))) if r1 == 0 { err = errnoErr(e1) } @@ -1152,7 +1152,7 @@ func QueryServiceStatusEx(service Handle, infoLevel uint32, buff *byte, buffSize } func RegCloseKey(key Handle) (regerrno error) { - r0, _, _ := syscall.Syscall(procRegCloseKey.Addr(), 1, uintptr(key), 0, 0) + r0, _, _ := syscall.SyscallN(procRegCloseKey.Addr(), uintptr(key)) if r0 != 0 { regerrno = syscall.Errno(r0) } @@ -1160,7 +1160,7 @@ func RegCloseKey(key Handle) (regerrno error) { } func RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno error) { - r0, _, _ := syscall.Syscall9(procRegEnumKeyExW.Addr(), 8, uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(lastWriteTime)), 0) + r0, _, _ := syscall.SyscallN(procRegEnumKeyExW.Addr(), uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(lastWriteTime))) if r0 != 0 { regerrno = syscall.Errno(r0) } @@ -1176,7 +1176,7 @@ func RegNotifyChangeKeyValue(key Handle, watchSubtree bool, notifyFilter uint32, if asynchronous { _p1 = 1 } - r0, _, _ := syscall.Syscall6(procRegNotifyChangeKeyValue.Addr(), 5, uintptr(key), uintptr(_p0), uintptr(notifyFilter), uintptr(event), uintptr(_p1), 0) + r0, _, _ := syscall.SyscallN(procRegNotifyChangeKeyValue.Addr(), uintptr(key), uintptr(_p0), uintptr(notifyFilter), uintptr(event), uintptr(_p1)) if r0 != 0 { regerrno = syscall.Errno(r0) } @@ -1184,7 +1184,7 @@ func RegNotifyChangeKeyValue(key Handle, watchSubtree bool, notifyFilter uint32, } func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno error) { - r0, _, _ := syscall.Syscall6(procRegOpenKeyExW.Addr(), 5, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(options), uintptr(desiredAccess), uintptr(unsafe.Pointer(result)), 0) + r0, _, _ := syscall.SyscallN(procRegOpenKeyExW.Addr(), uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(options), uintptr(desiredAccess), uintptr(unsafe.Pointer(result))) if r0 != 0 { regerrno = syscall.Errno(r0) } @@ -1192,7 +1192,7 @@ func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint } func RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint32, subkeysLen *uint32, maxSubkeyLen *uint32, maxClassLen *uint32, valuesLen *uint32, maxValueNameLen *uint32, maxValueLen *uint32, saLen *uint32, lastWriteTime *Filetime) (regerrno error) { - r0, _, _ := syscall.Syscall12(procRegQueryInfoKeyW.Addr(), 12, uintptr(key), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(subkeysLen)), uintptr(unsafe.Pointer(maxSubkeyLen)), uintptr(unsafe.Pointer(maxClassLen)), uintptr(unsafe.Pointer(valuesLen)), uintptr(unsafe.Pointer(maxValueNameLen)), uintptr(unsafe.Pointer(maxValueLen)), uintptr(unsafe.Pointer(saLen)), uintptr(unsafe.Pointer(lastWriteTime))) + r0, _, _ := syscall.SyscallN(procRegQueryInfoKeyW.Addr(), uintptr(key), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(subkeysLen)), uintptr(unsafe.Pointer(maxSubkeyLen)), uintptr(unsafe.Pointer(maxClassLen)), uintptr(unsafe.Pointer(valuesLen)), uintptr(unsafe.Pointer(maxValueNameLen)), uintptr(unsafe.Pointer(maxValueLen)), uintptr(unsafe.Pointer(saLen)), uintptr(unsafe.Pointer(lastWriteTime))) if r0 != 0 { regerrno = syscall.Errno(r0) } @@ -1200,7 +1200,7 @@ func RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint } func RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) { - r0, _, _ := syscall.Syscall6(procRegQueryValueExW.Addr(), 6, uintptr(key), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(valtype)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(buflen))) + r0, _, _ := syscall.SyscallN(procRegQueryValueExW.Addr(), uintptr(key), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(valtype)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(buflen))) if r0 != 0 { regerrno = syscall.Errno(r0) } @@ -1208,7 +1208,7 @@ func RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32 } func RegisterEventSource(uncServerName *uint16, sourceName *uint16) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall(procRegisterEventSourceW.Addr(), 2, uintptr(unsafe.Pointer(uncServerName)), uintptr(unsafe.Pointer(sourceName)), 0) + r0, _, e1 := syscall.SyscallN(procRegisterEventSourceW.Addr(), uintptr(unsafe.Pointer(uncServerName)), uintptr(unsafe.Pointer(sourceName))) handle = Handle(r0) if handle == 0 { err = errnoErr(e1) @@ -1217,7 +1217,7 @@ func RegisterEventSource(uncServerName *uint16, sourceName *uint16) (handle Hand } func RegisterServiceCtrlHandlerEx(serviceName *uint16, handlerProc uintptr, context uintptr) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall(procRegisterServiceCtrlHandlerExW.Addr(), 3, uintptr(unsafe.Pointer(serviceName)), uintptr(handlerProc), uintptr(context)) + r0, _, e1 := syscall.SyscallN(procRegisterServiceCtrlHandlerExW.Addr(), uintptr(unsafe.Pointer(serviceName)), uintptr(handlerProc), uintptr(context)) handle = Handle(r0) if handle == 0 { err = errnoErr(e1) @@ -1226,7 +1226,7 @@ func RegisterServiceCtrlHandlerEx(serviceName *uint16, handlerProc uintptr, cont } func ReportEvent(log Handle, etype uint16, category uint16, eventId uint32, usrSId uintptr, numStrings uint16, dataSize uint32, strings **uint16, rawData *byte) (err error) { - r1, _, e1 := syscall.Syscall9(procReportEventW.Addr(), 9, uintptr(log), uintptr(etype), uintptr(category), uintptr(eventId), uintptr(usrSId), uintptr(numStrings), uintptr(dataSize), uintptr(unsafe.Pointer(strings)), uintptr(unsafe.Pointer(rawData))) + r1, _, e1 := syscall.SyscallN(procReportEventW.Addr(), uintptr(log), uintptr(etype), uintptr(category), uintptr(eventId), uintptr(usrSId), uintptr(numStrings), uintptr(dataSize), uintptr(unsafe.Pointer(strings)), uintptr(unsafe.Pointer(rawData))) if r1 == 0 { err = errnoErr(e1) } @@ -1234,7 +1234,7 @@ func ReportEvent(log Handle, etype uint16, category uint16, eventId uint32, usrS } func RevertToSelf() (err error) { - r1, _, e1 := syscall.Syscall(procRevertToSelf.Addr(), 0, 0, 0, 0) + r1, _, e1 := syscall.SyscallN(procRevertToSelf.Addr()) if r1 == 0 { err = errnoErr(e1) } @@ -1242,7 +1242,7 @@ func RevertToSelf() (err error) { } func setEntriesInAcl(countExplicitEntries uint32, explicitEntries *EXPLICIT_ACCESS, oldACL *ACL, newACL **ACL) (ret error) { - r0, _, _ := syscall.Syscall6(procSetEntriesInAclW.Addr(), 4, uintptr(countExplicitEntries), uintptr(unsafe.Pointer(explicitEntries)), uintptr(unsafe.Pointer(oldACL)), uintptr(unsafe.Pointer(newACL)), 0, 0) + r0, _, _ := syscall.SyscallN(procSetEntriesInAclW.Addr(), uintptr(countExplicitEntries), uintptr(unsafe.Pointer(explicitEntries)), uintptr(unsafe.Pointer(oldACL)), uintptr(unsafe.Pointer(newACL))) if r0 != 0 { ret = syscall.Errno(r0) } @@ -1250,7 +1250,7 @@ func setEntriesInAcl(countExplicitEntries uint32, explicitEntries *EXPLICIT_ACCE } func SetKernelObjectSecurity(handle Handle, securityInformation SECURITY_INFORMATION, securityDescriptor *SECURITY_DESCRIPTOR) (err error) { - r1, _, e1 := syscall.Syscall(procSetKernelObjectSecurity.Addr(), 3, uintptr(handle), uintptr(securityInformation), uintptr(unsafe.Pointer(securityDescriptor))) + r1, _, e1 := syscall.SyscallN(procSetKernelObjectSecurity.Addr(), uintptr(handle), uintptr(securityInformation), uintptr(unsafe.Pointer(securityDescriptor))) if r1 == 0 { err = errnoErr(e1) } @@ -1267,7 +1267,7 @@ func SetNamedSecurityInfo(objectName string, objectType SE_OBJECT_TYPE, security } func _SetNamedSecurityInfo(objectName *uint16, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION, owner *SID, group *SID, dacl *ACL, sacl *ACL) (ret error) { - r0, _, _ := syscall.Syscall9(procSetNamedSecurityInfoW.Addr(), 7, uintptr(unsafe.Pointer(objectName)), uintptr(objectType), uintptr(securityInformation), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(sacl)), 0, 0) + r0, _, _ := syscall.SyscallN(procSetNamedSecurityInfoW.Addr(), uintptr(unsafe.Pointer(objectName)), uintptr(objectType), uintptr(securityInformation), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(sacl))) if r0 != 0 { ret = syscall.Errno(r0) } @@ -1275,7 +1275,7 @@ func _SetNamedSecurityInfo(objectName *uint16, objectType SE_OBJECT_TYPE, securi } func setSecurityDescriptorControl(sd *SECURITY_DESCRIPTOR, controlBitsOfInterest SECURITY_DESCRIPTOR_CONTROL, controlBitsToSet SECURITY_DESCRIPTOR_CONTROL) (err error) { - r1, _, e1 := syscall.Syscall(procSetSecurityDescriptorControl.Addr(), 3, uintptr(unsafe.Pointer(sd)), uintptr(controlBitsOfInterest), uintptr(controlBitsToSet)) + r1, _, e1 := syscall.SyscallN(procSetSecurityDescriptorControl.Addr(), uintptr(unsafe.Pointer(sd)), uintptr(controlBitsOfInterest), uintptr(controlBitsToSet)) if r1 == 0 { err = errnoErr(e1) } @@ -1291,7 +1291,7 @@ func setSecurityDescriptorDacl(sd *SECURITY_DESCRIPTOR, daclPresent bool, dacl * if daclDefaulted { _p1 = 1 } - r1, _, e1 := syscall.Syscall6(procSetSecurityDescriptorDacl.Addr(), 4, uintptr(unsafe.Pointer(sd)), uintptr(_p0), uintptr(unsafe.Pointer(dacl)), uintptr(_p1), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetSecurityDescriptorDacl.Addr(), uintptr(unsafe.Pointer(sd)), uintptr(_p0), uintptr(unsafe.Pointer(dacl)), uintptr(_p1)) if r1 == 0 { err = errnoErr(e1) } @@ -1303,7 +1303,7 @@ func setSecurityDescriptorGroup(sd *SECURITY_DESCRIPTOR, group *SID, groupDefaul if groupDefaulted { _p0 = 1 } - r1, _, e1 := syscall.Syscall(procSetSecurityDescriptorGroup.Addr(), 3, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(group)), uintptr(_p0)) + r1, _, e1 := syscall.SyscallN(procSetSecurityDescriptorGroup.Addr(), uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(group)), uintptr(_p0)) if r1 == 0 { err = errnoErr(e1) } @@ -1315,7 +1315,7 @@ func setSecurityDescriptorOwner(sd *SECURITY_DESCRIPTOR, owner *SID, ownerDefaul if ownerDefaulted { _p0 = 1 } - r1, _, e1 := syscall.Syscall(procSetSecurityDescriptorOwner.Addr(), 3, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(owner)), uintptr(_p0)) + r1, _, e1 := syscall.SyscallN(procSetSecurityDescriptorOwner.Addr(), uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(owner)), uintptr(_p0)) if r1 == 0 { err = errnoErr(e1) } @@ -1323,7 +1323,7 @@ func setSecurityDescriptorOwner(sd *SECURITY_DESCRIPTOR, owner *SID, ownerDefaul } func setSecurityDescriptorRMControl(sd *SECURITY_DESCRIPTOR, rmControl *uint8) { - syscall.Syscall(procSetSecurityDescriptorRMControl.Addr(), 2, uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(rmControl)), 0) + syscall.SyscallN(procSetSecurityDescriptorRMControl.Addr(), uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(rmControl))) return } @@ -1336,7 +1336,7 @@ func setSecurityDescriptorSacl(sd *SECURITY_DESCRIPTOR, saclPresent bool, sacl * if saclDefaulted { _p1 = 1 } - r1, _, e1 := syscall.Syscall6(procSetSecurityDescriptorSacl.Addr(), 4, uintptr(unsafe.Pointer(sd)), uintptr(_p0), uintptr(unsafe.Pointer(sacl)), uintptr(_p1), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetSecurityDescriptorSacl.Addr(), uintptr(unsafe.Pointer(sd)), uintptr(_p0), uintptr(unsafe.Pointer(sacl)), uintptr(_p1)) if r1 == 0 { err = errnoErr(e1) } @@ -1344,7 +1344,7 @@ func setSecurityDescriptorSacl(sd *SECURITY_DESCRIPTOR, saclPresent bool, sacl * } func SetSecurityInfo(handle Handle, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION, owner *SID, group *SID, dacl *ACL, sacl *ACL) (ret error) { - r0, _, _ := syscall.Syscall9(procSetSecurityInfo.Addr(), 7, uintptr(handle), uintptr(objectType), uintptr(securityInformation), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(sacl)), 0, 0) + r0, _, _ := syscall.SyscallN(procSetSecurityInfo.Addr(), uintptr(handle), uintptr(objectType), uintptr(securityInformation), uintptr(unsafe.Pointer(owner)), uintptr(unsafe.Pointer(group)), uintptr(unsafe.Pointer(dacl)), uintptr(unsafe.Pointer(sacl))) if r0 != 0 { ret = syscall.Errno(r0) } @@ -1352,7 +1352,7 @@ func SetSecurityInfo(handle Handle, objectType SE_OBJECT_TYPE, securityInformati } func SetServiceStatus(service Handle, serviceStatus *SERVICE_STATUS) (err error) { - r1, _, e1 := syscall.Syscall(procSetServiceStatus.Addr(), 2, uintptr(service), uintptr(unsafe.Pointer(serviceStatus)), 0) + r1, _, e1 := syscall.SyscallN(procSetServiceStatus.Addr(), uintptr(service), uintptr(unsafe.Pointer(serviceStatus))) if r1 == 0 { err = errnoErr(e1) } @@ -1360,7 +1360,7 @@ func SetServiceStatus(service Handle, serviceStatus *SERVICE_STATUS) (err error) } func SetThreadToken(thread *Handle, token Token) (err error) { - r1, _, e1 := syscall.Syscall(procSetThreadToken.Addr(), 2, uintptr(unsafe.Pointer(thread)), uintptr(token), 0) + r1, _, e1 := syscall.SyscallN(procSetThreadToken.Addr(), uintptr(unsafe.Pointer(thread)), uintptr(token)) if r1 == 0 { err = errnoErr(e1) } @@ -1368,7 +1368,7 @@ func SetThreadToken(thread *Handle, token Token) (err error) { } func SetTokenInformation(token Token, infoClass uint32, info *byte, infoLen uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procSetTokenInformation.Addr(), 4, uintptr(token), uintptr(infoClass), uintptr(unsafe.Pointer(info)), uintptr(infoLen), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetTokenInformation.Addr(), uintptr(token), uintptr(infoClass), uintptr(unsafe.Pointer(info)), uintptr(infoLen)) if r1 == 0 { err = errnoErr(e1) } @@ -1376,7 +1376,7 @@ func SetTokenInformation(token Token, infoClass uint32, info *byte, infoLen uint } func StartServiceCtrlDispatcher(serviceTable *SERVICE_TABLE_ENTRY) (err error) { - r1, _, e1 := syscall.Syscall(procStartServiceCtrlDispatcherW.Addr(), 1, uintptr(unsafe.Pointer(serviceTable)), 0, 0) + r1, _, e1 := syscall.SyscallN(procStartServiceCtrlDispatcherW.Addr(), uintptr(unsafe.Pointer(serviceTable))) if r1 == 0 { err = errnoErr(e1) } @@ -1384,7 +1384,7 @@ func StartServiceCtrlDispatcher(serviceTable *SERVICE_TABLE_ENTRY) (err error) { } func StartService(service Handle, numArgs uint32, argVectors **uint16) (err error) { - r1, _, e1 := syscall.Syscall(procStartServiceW.Addr(), 3, uintptr(service), uintptr(numArgs), uintptr(unsafe.Pointer(argVectors))) + r1, _, e1 := syscall.SyscallN(procStartServiceW.Addr(), uintptr(service), uintptr(numArgs), uintptr(unsafe.Pointer(argVectors))) if r1 == 0 { err = errnoErr(e1) } @@ -1392,7 +1392,7 @@ func StartService(service Handle, numArgs uint32, argVectors **uint16) (err erro } func CertAddCertificateContextToStore(store Handle, certContext *CertContext, addDisposition uint32, storeContext **CertContext) (err error) { - r1, _, e1 := syscall.Syscall6(procCertAddCertificateContextToStore.Addr(), 4, uintptr(store), uintptr(unsafe.Pointer(certContext)), uintptr(addDisposition), uintptr(unsafe.Pointer(storeContext)), 0, 0) + r1, _, e1 := syscall.SyscallN(procCertAddCertificateContextToStore.Addr(), uintptr(store), uintptr(unsafe.Pointer(certContext)), uintptr(addDisposition), uintptr(unsafe.Pointer(storeContext))) if r1 == 0 { err = errnoErr(e1) } @@ -1400,7 +1400,7 @@ func CertAddCertificateContextToStore(store Handle, certContext *CertContext, ad } func CertCloseStore(store Handle, flags uint32) (err error) { - r1, _, e1 := syscall.Syscall(procCertCloseStore.Addr(), 2, uintptr(store), uintptr(flags), 0) + r1, _, e1 := syscall.SyscallN(procCertCloseStore.Addr(), uintptr(store), uintptr(flags)) if r1 == 0 { err = errnoErr(e1) } @@ -1408,7 +1408,7 @@ func CertCloseStore(store Handle, flags uint32) (err error) { } func CertCreateCertificateContext(certEncodingType uint32, certEncoded *byte, encodedLen uint32) (context *CertContext, err error) { - r0, _, e1 := syscall.Syscall(procCertCreateCertificateContext.Addr(), 3, uintptr(certEncodingType), uintptr(unsafe.Pointer(certEncoded)), uintptr(encodedLen)) + r0, _, e1 := syscall.SyscallN(procCertCreateCertificateContext.Addr(), uintptr(certEncodingType), uintptr(unsafe.Pointer(certEncoded)), uintptr(encodedLen)) context = (*CertContext)(unsafe.Pointer(r0)) if context == nil { err = errnoErr(e1) @@ -1417,7 +1417,7 @@ func CertCreateCertificateContext(certEncodingType uint32, certEncoded *byte, en } func CertDeleteCertificateFromStore(certContext *CertContext) (err error) { - r1, _, e1 := syscall.Syscall(procCertDeleteCertificateFromStore.Addr(), 1, uintptr(unsafe.Pointer(certContext)), 0, 0) + r1, _, e1 := syscall.SyscallN(procCertDeleteCertificateFromStore.Addr(), uintptr(unsafe.Pointer(certContext))) if r1 == 0 { err = errnoErr(e1) } @@ -1425,13 +1425,13 @@ func CertDeleteCertificateFromStore(certContext *CertContext) (err error) { } func CertDuplicateCertificateContext(certContext *CertContext) (dupContext *CertContext) { - r0, _, _ := syscall.Syscall(procCertDuplicateCertificateContext.Addr(), 1, uintptr(unsafe.Pointer(certContext)), 0, 0) + r0, _, _ := syscall.SyscallN(procCertDuplicateCertificateContext.Addr(), uintptr(unsafe.Pointer(certContext))) dupContext = (*CertContext)(unsafe.Pointer(r0)) return } func CertEnumCertificatesInStore(store Handle, prevContext *CertContext) (context *CertContext, err error) { - r0, _, e1 := syscall.Syscall(procCertEnumCertificatesInStore.Addr(), 2, uintptr(store), uintptr(unsafe.Pointer(prevContext)), 0) + r0, _, e1 := syscall.SyscallN(procCertEnumCertificatesInStore.Addr(), uintptr(store), uintptr(unsafe.Pointer(prevContext))) context = (*CertContext)(unsafe.Pointer(r0)) if context == nil { err = errnoErr(e1) @@ -1440,7 +1440,7 @@ func CertEnumCertificatesInStore(store Handle, prevContext *CertContext) (contex } func CertFindCertificateInStore(store Handle, certEncodingType uint32, findFlags uint32, findType uint32, findPara unsafe.Pointer, prevCertContext *CertContext) (cert *CertContext, err error) { - r0, _, e1 := syscall.Syscall6(procCertFindCertificateInStore.Addr(), 6, uintptr(store), uintptr(certEncodingType), uintptr(findFlags), uintptr(findType), uintptr(findPara), uintptr(unsafe.Pointer(prevCertContext))) + r0, _, e1 := syscall.SyscallN(procCertFindCertificateInStore.Addr(), uintptr(store), uintptr(certEncodingType), uintptr(findFlags), uintptr(findType), uintptr(findPara), uintptr(unsafe.Pointer(prevCertContext))) cert = (*CertContext)(unsafe.Pointer(r0)) if cert == nil { err = errnoErr(e1) @@ -1449,7 +1449,7 @@ func CertFindCertificateInStore(store Handle, certEncodingType uint32, findFlags } func CertFindChainInStore(store Handle, certEncodingType uint32, findFlags uint32, findType uint32, findPara unsafe.Pointer, prevChainContext *CertChainContext) (certchain *CertChainContext, err error) { - r0, _, e1 := syscall.Syscall6(procCertFindChainInStore.Addr(), 6, uintptr(store), uintptr(certEncodingType), uintptr(findFlags), uintptr(findType), uintptr(findPara), uintptr(unsafe.Pointer(prevChainContext))) + r0, _, e1 := syscall.SyscallN(procCertFindChainInStore.Addr(), uintptr(store), uintptr(certEncodingType), uintptr(findFlags), uintptr(findType), uintptr(findPara), uintptr(unsafe.Pointer(prevChainContext))) certchain = (*CertChainContext)(unsafe.Pointer(r0)) if certchain == nil { err = errnoErr(e1) @@ -1458,18 +1458,18 @@ func CertFindChainInStore(store Handle, certEncodingType uint32, findFlags uint3 } func CertFindExtension(objId *byte, countExtensions uint32, extensions *CertExtension) (ret *CertExtension) { - r0, _, _ := syscall.Syscall(procCertFindExtension.Addr(), 3, uintptr(unsafe.Pointer(objId)), uintptr(countExtensions), uintptr(unsafe.Pointer(extensions))) + r0, _, _ := syscall.SyscallN(procCertFindExtension.Addr(), uintptr(unsafe.Pointer(objId)), uintptr(countExtensions), uintptr(unsafe.Pointer(extensions))) ret = (*CertExtension)(unsafe.Pointer(r0)) return } func CertFreeCertificateChain(ctx *CertChainContext) { - syscall.Syscall(procCertFreeCertificateChain.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0) + syscall.SyscallN(procCertFreeCertificateChain.Addr(), uintptr(unsafe.Pointer(ctx))) return } func CertFreeCertificateContext(ctx *CertContext) (err error) { - r1, _, e1 := syscall.Syscall(procCertFreeCertificateContext.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0) + r1, _, e1 := syscall.SyscallN(procCertFreeCertificateContext.Addr(), uintptr(unsafe.Pointer(ctx))) if r1 == 0 { err = errnoErr(e1) } @@ -1477,7 +1477,7 @@ func CertFreeCertificateContext(ctx *CertContext) (err error) { } func CertGetCertificateChain(engine Handle, leaf *CertContext, time *Filetime, additionalStore Handle, para *CertChainPara, flags uint32, reserved uintptr, chainCtx **CertChainContext) (err error) { - r1, _, e1 := syscall.Syscall9(procCertGetCertificateChain.Addr(), 8, uintptr(engine), uintptr(unsafe.Pointer(leaf)), uintptr(unsafe.Pointer(time)), uintptr(additionalStore), uintptr(unsafe.Pointer(para)), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(chainCtx)), 0) + r1, _, e1 := syscall.SyscallN(procCertGetCertificateChain.Addr(), uintptr(engine), uintptr(unsafe.Pointer(leaf)), uintptr(unsafe.Pointer(time)), uintptr(additionalStore), uintptr(unsafe.Pointer(para)), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(chainCtx))) if r1 == 0 { err = errnoErr(e1) } @@ -1485,13 +1485,13 @@ func CertGetCertificateChain(engine Handle, leaf *CertContext, time *Filetime, a } func CertGetNameString(certContext *CertContext, nameType uint32, flags uint32, typePara unsafe.Pointer, name *uint16, size uint32) (chars uint32) { - r0, _, _ := syscall.Syscall6(procCertGetNameStringW.Addr(), 6, uintptr(unsafe.Pointer(certContext)), uintptr(nameType), uintptr(flags), uintptr(typePara), uintptr(unsafe.Pointer(name)), uintptr(size)) + r0, _, _ := syscall.SyscallN(procCertGetNameStringW.Addr(), uintptr(unsafe.Pointer(certContext)), uintptr(nameType), uintptr(flags), uintptr(typePara), uintptr(unsafe.Pointer(name)), uintptr(size)) chars = uint32(r0) return } func CertOpenStore(storeProvider uintptr, msgAndCertEncodingType uint32, cryptProv uintptr, flags uint32, para uintptr) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall6(procCertOpenStore.Addr(), 5, uintptr(storeProvider), uintptr(msgAndCertEncodingType), uintptr(cryptProv), uintptr(flags), uintptr(para), 0) + r0, _, e1 := syscall.SyscallN(procCertOpenStore.Addr(), uintptr(storeProvider), uintptr(msgAndCertEncodingType), uintptr(cryptProv), uintptr(flags), uintptr(para)) handle = Handle(r0) if handle == 0 { err = errnoErr(e1) @@ -1500,7 +1500,7 @@ func CertOpenStore(storeProvider uintptr, msgAndCertEncodingType uint32, cryptPr } func CertOpenSystemStore(hprov Handle, name *uint16) (store Handle, err error) { - r0, _, e1 := syscall.Syscall(procCertOpenSystemStoreW.Addr(), 2, uintptr(hprov), uintptr(unsafe.Pointer(name)), 0) + r0, _, e1 := syscall.SyscallN(procCertOpenSystemStoreW.Addr(), uintptr(hprov), uintptr(unsafe.Pointer(name))) store = Handle(r0) if store == 0 { err = errnoErr(e1) @@ -1509,7 +1509,7 @@ func CertOpenSystemStore(hprov Handle, name *uint16) (store Handle, err error) { } func CertVerifyCertificateChainPolicy(policyOID uintptr, chain *CertChainContext, para *CertChainPolicyPara, status *CertChainPolicyStatus) (err error) { - r1, _, e1 := syscall.Syscall6(procCertVerifyCertificateChainPolicy.Addr(), 4, uintptr(policyOID), uintptr(unsafe.Pointer(chain)), uintptr(unsafe.Pointer(para)), uintptr(unsafe.Pointer(status)), 0, 0) + r1, _, e1 := syscall.SyscallN(procCertVerifyCertificateChainPolicy.Addr(), uintptr(policyOID), uintptr(unsafe.Pointer(chain)), uintptr(unsafe.Pointer(para)), uintptr(unsafe.Pointer(status))) if r1 == 0 { err = errnoErr(e1) } @@ -1521,7 +1521,7 @@ func CryptAcquireCertificatePrivateKey(cert *CertContext, flags uint32, paramete if *callerFreeProvOrNCryptKey { _p0 = 1 } - r1, _, e1 := syscall.Syscall6(procCryptAcquireCertificatePrivateKey.Addr(), 6, uintptr(unsafe.Pointer(cert)), uintptr(flags), uintptr(parameters), uintptr(unsafe.Pointer(cryptProvOrNCryptKey)), uintptr(unsafe.Pointer(keySpec)), uintptr(unsafe.Pointer(&_p0))) + r1, _, e1 := syscall.SyscallN(procCryptAcquireCertificatePrivateKey.Addr(), uintptr(unsafe.Pointer(cert)), uintptr(flags), uintptr(parameters), uintptr(unsafe.Pointer(cryptProvOrNCryptKey)), uintptr(unsafe.Pointer(keySpec)), uintptr(unsafe.Pointer(&_p0))) *callerFreeProvOrNCryptKey = _p0 != 0 if r1 == 0 { err = errnoErr(e1) @@ -1530,7 +1530,7 @@ func CryptAcquireCertificatePrivateKey(cert *CertContext, flags uint32, paramete } func CryptDecodeObject(encodingType uint32, structType *byte, encodedBytes *byte, lenEncodedBytes uint32, flags uint32, decoded unsafe.Pointer, decodedLen *uint32) (err error) { - r1, _, e1 := syscall.Syscall9(procCryptDecodeObject.Addr(), 7, uintptr(encodingType), uintptr(unsafe.Pointer(structType)), uintptr(unsafe.Pointer(encodedBytes)), uintptr(lenEncodedBytes), uintptr(flags), uintptr(decoded), uintptr(unsafe.Pointer(decodedLen)), 0, 0) + r1, _, e1 := syscall.SyscallN(procCryptDecodeObject.Addr(), uintptr(encodingType), uintptr(unsafe.Pointer(structType)), uintptr(unsafe.Pointer(encodedBytes)), uintptr(lenEncodedBytes), uintptr(flags), uintptr(decoded), uintptr(unsafe.Pointer(decodedLen))) if r1 == 0 { err = errnoErr(e1) } @@ -1538,7 +1538,7 @@ func CryptDecodeObject(encodingType uint32, structType *byte, encodedBytes *byte } func CryptProtectData(dataIn *DataBlob, name *uint16, optionalEntropy *DataBlob, reserved uintptr, promptStruct *CryptProtectPromptStruct, flags uint32, dataOut *DataBlob) (err error) { - r1, _, e1 := syscall.Syscall9(procCryptProtectData.Addr(), 7, uintptr(unsafe.Pointer(dataIn)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(optionalEntropy)), uintptr(reserved), uintptr(unsafe.Pointer(promptStruct)), uintptr(flags), uintptr(unsafe.Pointer(dataOut)), 0, 0) + r1, _, e1 := syscall.SyscallN(procCryptProtectData.Addr(), uintptr(unsafe.Pointer(dataIn)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(optionalEntropy)), uintptr(reserved), uintptr(unsafe.Pointer(promptStruct)), uintptr(flags), uintptr(unsafe.Pointer(dataOut))) if r1 == 0 { err = errnoErr(e1) } @@ -1546,7 +1546,7 @@ func CryptProtectData(dataIn *DataBlob, name *uint16, optionalEntropy *DataBlob, } func CryptQueryObject(objectType uint32, object unsafe.Pointer, expectedContentTypeFlags uint32, expectedFormatTypeFlags uint32, flags uint32, msgAndCertEncodingType *uint32, contentType *uint32, formatType *uint32, certStore *Handle, msg *Handle, context *unsafe.Pointer) (err error) { - r1, _, e1 := syscall.Syscall12(procCryptQueryObject.Addr(), 11, uintptr(objectType), uintptr(object), uintptr(expectedContentTypeFlags), uintptr(expectedFormatTypeFlags), uintptr(flags), uintptr(unsafe.Pointer(msgAndCertEncodingType)), uintptr(unsafe.Pointer(contentType)), uintptr(unsafe.Pointer(formatType)), uintptr(unsafe.Pointer(certStore)), uintptr(unsafe.Pointer(msg)), uintptr(unsafe.Pointer(context)), 0) + r1, _, e1 := syscall.SyscallN(procCryptQueryObject.Addr(), uintptr(objectType), uintptr(object), uintptr(expectedContentTypeFlags), uintptr(expectedFormatTypeFlags), uintptr(flags), uintptr(unsafe.Pointer(msgAndCertEncodingType)), uintptr(unsafe.Pointer(contentType)), uintptr(unsafe.Pointer(formatType)), uintptr(unsafe.Pointer(certStore)), uintptr(unsafe.Pointer(msg)), uintptr(unsafe.Pointer(context))) if r1 == 0 { err = errnoErr(e1) } @@ -1554,7 +1554,7 @@ func CryptQueryObject(objectType uint32, object unsafe.Pointer, expectedContentT } func CryptUnprotectData(dataIn *DataBlob, name **uint16, optionalEntropy *DataBlob, reserved uintptr, promptStruct *CryptProtectPromptStruct, flags uint32, dataOut *DataBlob) (err error) { - r1, _, e1 := syscall.Syscall9(procCryptUnprotectData.Addr(), 7, uintptr(unsafe.Pointer(dataIn)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(optionalEntropy)), uintptr(reserved), uintptr(unsafe.Pointer(promptStruct)), uintptr(flags), uintptr(unsafe.Pointer(dataOut)), 0, 0) + r1, _, e1 := syscall.SyscallN(procCryptUnprotectData.Addr(), uintptr(unsafe.Pointer(dataIn)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(optionalEntropy)), uintptr(reserved), uintptr(unsafe.Pointer(promptStruct)), uintptr(flags), uintptr(unsafe.Pointer(dataOut))) if r1 == 0 { err = errnoErr(e1) } @@ -1562,7 +1562,7 @@ func CryptUnprotectData(dataIn *DataBlob, name **uint16, optionalEntropy *DataBl } func PFXImportCertStore(pfx *CryptDataBlob, password *uint16, flags uint32) (store Handle, err error) { - r0, _, e1 := syscall.Syscall(procPFXImportCertStore.Addr(), 3, uintptr(unsafe.Pointer(pfx)), uintptr(unsafe.Pointer(password)), uintptr(flags)) + r0, _, e1 := syscall.SyscallN(procPFXImportCertStore.Addr(), uintptr(unsafe.Pointer(pfx)), uintptr(unsafe.Pointer(password)), uintptr(flags)) store = Handle(r0) if store == 0 { err = errnoErr(e1) @@ -1571,7 +1571,7 @@ func PFXImportCertStore(pfx *CryptDataBlob, password *uint16, flags uint32) (sto } func DnsNameCompare(name1 *uint16, name2 *uint16) (same bool) { - r0, _, _ := syscall.Syscall(procDnsNameCompare_W.Addr(), 2, uintptr(unsafe.Pointer(name1)), uintptr(unsafe.Pointer(name2)), 0) + r0, _, _ := syscall.SyscallN(procDnsNameCompare_W.Addr(), uintptr(unsafe.Pointer(name1)), uintptr(unsafe.Pointer(name2))) same = r0 != 0 return } @@ -1586,7 +1586,7 @@ func DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSR } func _DnsQuery(name *uint16, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) { - r0, _, _ := syscall.Syscall6(procDnsQuery_W.Addr(), 6, uintptr(unsafe.Pointer(name)), uintptr(qtype), uintptr(options), uintptr(unsafe.Pointer(extra)), uintptr(unsafe.Pointer(qrs)), uintptr(unsafe.Pointer(pr))) + r0, _, _ := syscall.SyscallN(procDnsQuery_W.Addr(), uintptr(unsafe.Pointer(name)), uintptr(qtype), uintptr(options), uintptr(unsafe.Pointer(extra)), uintptr(unsafe.Pointer(qrs)), uintptr(unsafe.Pointer(pr))) if r0 != 0 { status = syscall.Errno(r0) } @@ -1594,12 +1594,12 @@ func _DnsQuery(name *uint16, qtype uint16, options uint32, extra *byte, qrs **DN } func DnsRecordListFree(rl *DNSRecord, freetype uint32) { - syscall.Syscall(procDnsRecordListFree.Addr(), 2, uintptr(unsafe.Pointer(rl)), uintptr(freetype), 0) + syscall.SyscallN(procDnsRecordListFree.Addr(), uintptr(unsafe.Pointer(rl)), uintptr(freetype)) return } func DwmGetWindowAttribute(hwnd HWND, attribute uint32, value unsafe.Pointer, size uint32) (ret error) { - r0, _, _ := syscall.Syscall6(procDwmGetWindowAttribute.Addr(), 4, uintptr(hwnd), uintptr(attribute), uintptr(value), uintptr(size), 0, 0) + r0, _, _ := syscall.SyscallN(procDwmGetWindowAttribute.Addr(), uintptr(hwnd), uintptr(attribute), uintptr(value), uintptr(size)) if r0 != 0 { ret = syscall.Errno(r0) } @@ -1607,7 +1607,7 @@ func DwmGetWindowAttribute(hwnd HWND, attribute uint32, value unsafe.Pointer, si } func DwmSetWindowAttribute(hwnd HWND, attribute uint32, value unsafe.Pointer, size uint32) (ret error) { - r0, _, _ := syscall.Syscall6(procDwmSetWindowAttribute.Addr(), 4, uintptr(hwnd), uintptr(attribute), uintptr(value), uintptr(size), 0, 0) + r0, _, _ := syscall.SyscallN(procDwmSetWindowAttribute.Addr(), uintptr(hwnd), uintptr(attribute), uintptr(value), uintptr(size)) if r0 != 0 { ret = syscall.Errno(r0) } @@ -1615,7 +1615,7 @@ func DwmSetWindowAttribute(hwnd HWND, attribute uint32, value unsafe.Pointer, si } func CancelMibChangeNotify2(notificationHandle Handle) (errcode error) { - r0, _, _ := syscall.Syscall(procCancelMibChangeNotify2.Addr(), 1, uintptr(notificationHandle), 0, 0) + r0, _, _ := syscall.SyscallN(procCancelMibChangeNotify2.Addr(), uintptr(notificationHandle)) if r0 != 0 { errcode = syscall.Errno(r0) } @@ -1623,7 +1623,7 @@ func CancelMibChangeNotify2(notificationHandle Handle) (errcode error) { } func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) { - r0, _, _ := syscall.Syscall6(procGetAdaptersAddresses.Addr(), 5, uintptr(family), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(adapterAddresses)), uintptr(unsafe.Pointer(sizePointer)), 0) + r0, _, _ := syscall.SyscallN(procGetAdaptersAddresses.Addr(), uintptr(family), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(adapterAddresses)), uintptr(unsafe.Pointer(sizePointer))) if r0 != 0 { errcode = syscall.Errno(r0) } @@ -1631,7 +1631,7 @@ func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapter } func GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) { - r0, _, _ := syscall.Syscall(procGetAdaptersInfo.Addr(), 2, uintptr(unsafe.Pointer(ai)), uintptr(unsafe.Pointer(ol)), 0) + r0, _, _ := syscall.SyscallN(procGetAdaptersInfo.Addr(), uintptr(unsafe.Pointer(ai)), uintptr(unsafe.Pointer(ol))) if r0 != 0 { errcode = syscall.Errno(r0) } @@ -1639,7 +1639,7 @@ func GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) { } func getBestInterfaceEx(sockaddr unsafe.Pointer, pdwBestIfIndex *uint32) (errcode error) { - r0, _, _ := syscall.Syscall(procGetBestInterfaceEx.Addr(), 2, uintptr(sockaddr), uintptr(unsafe.Pointer(pdwBestIfIndex)), 0) + r0, _, _ := syscall.SyscallN(procGetBestInterfaceEx.Addr(), uintptr(sockaddr), uintptr(unsafe.Pointer(pdwBestIfIndex))) if r0 != 0 { errcode = syscall.Errno(r0) } @@ -1647,7 +1647,7 @@ func getBestInterfaceEx(sockaddr unsafe.Pointer, pdwBestIfIndex *uint32) (errcod } func GetIfEntry(pIfRow *MibIfRow) (errcode error) { - r0, _, _ := syscall.Syscall(procGetIfEntry.Addr(), 1, uintptr(unsafe.Pointer(pIfRow)), 0, 0) + r0, _, _ := syscall.SyscallN(procGetIfEntry.Addr(), uintptr(unsafe.Pointer(pIfRow))) if r0 != 0 { errcode = syscall.Errno(r0) } @@ -1655,7 +1655,7 @@ func GetIfEntry(pIfRow *MibIfRow) (errcode error) { } func GetIfEntry2Ex(level uint32, row *MibIfRow2) (errcode error) { - r0, _, _ := syscall.Syscall(procGetIfEntry2Ex.Addr(), 2, uintptr(level), uintptr(unsafe.Pointer(row)), 0) + r0, _, _ := syscall.SyscallN(procGetIfEntry2Ex.Addr(), uintptr(level), uintptr(unsafe.Pointer(row))) if r0 != 0 { errcode = syscall.Errno(r0) } @@ -1663,7 +1663,7 @@ func GetIfEntry2Ex(level uint32, row *MibIfRow2) (errcode error) { } func GetUnicastIpAddressEntry(row *MibUnicastIpAddressRow) (errcode error) { - r0, _, _ := syscall.Syscall(procGetUnicastIpAddressEntry.Addr(), 1, uintptr(unsafe.Pointer(row)), 0, 0) + r0, _, _ := syscall.SyscallN(procGetUnicastIpAddressEntry.Addr(), uintptr(unsafe.Pointer(row))) if r0 != 0 { errcode = syscall.Errno(r0) } @@ -1675,7 +1675,7 @@ func NotifyIpInterfaceChange(family uint16, callback uintptr, callerContext unsa if initialNotification { _p0 = 1 } - r0, _, _ := syscall.Syscall6(procNotifyIpInterfaceChange.Addr(), 5, uintptr(family), uintptr(callback), uintptr(callerContext), uintptr(_p0), uintptr(unsafe.Pointer(notificationHandle)), 0) + r0, _, _ := syscall.SyscallN(procNotifyIpInterfaceChange.Addr(), uintptr(family), uintptr(callback), uintptr(callerContext), uintptr(_p0), uintptr(unsafe.Pointer(notificationHandle))) if r0 != 0 { errcode = syscall.Errno(r0) } @@ -1687,7 +1687,7 @@ func NotifyUnicastIpAddressChange(family uint16, callback uintptr, callerContext if initialNotification { _p0 = 1 } - r0, _, _ := syscall.Syscall6(procNotifyUnicastIpAddressChange.Addr(), 5, uintptr(family), uintptr(callback), uintptr(callerContext), uintptr(_p0), uintptr(unsafe.Pointer(notificationHandle)), 0) + r0, _, _ := syscall.SyscallN(procNotifyUnicastIpAddressChange.Addr(), uintptr(family), uintptr(callback), uintptr(callerContext), uintptr(_p0), uintptr(unsafe.Pointer(notificationHandle))) if r0 != 0 { errcode = syscall.Errno(r0) } @@ -1695,7 +1695,7 @@ func NotifyUnicastIpAddressChange(family uint16, callback uintptr, callerContext } func AddDllDirectory(path *uint16) (cookie uintptr, err error) { - r0, _, e1 := syscall.Syscall(procAddDllDirectory.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0) + r0, _, e1 := syscall.SyscallN(procAddDllDirectory.Addr(), uintptr(unsafe.Pointer(path))) cookie = uintptr(r0) if cookie == 0 { err = errnoErr(e1) @@ -1704,7 +1704,7 @@ func AddDllDirectory(path *uint16) (cookie uintptr, err error) { } func AssignProcessToJobObject(job Handle, process Handle) (err error) { - r1, _, e1 := syscall.Syscall(procAssignProcessToJobObject.Addr(), 2, uintptr(job), uintptr(process), 0) + r1, _, e1 := syscall.SyscallN(procAssignProcessToJobObject.Addr(), uintptr(job), uintptr(process)) if r1 == 0 { err = errnoErr(e1) } @@ -1712,7 +1712,7 @@ func AssignProcessToJobObject(job Handle, process Handle) (err error) { } func CancelIo(s Handle) (err error) { - r1, _, e1 := syscall.Syscall(procCancelIo.Addr(), 1, uintptr(s), 0, 0) + r1, _, e1 := syscall.SyscallN(procCancelIo.Addr(), uintptr(s)) if r1 == 0 { err = errnoErr(e1) } @@ -1720,7 +1720,7 @@ func CancelIo(s Handle) (err error) { } func CancelIoEx(s Handle, o *Overlapped) (err error) { - r1, _, e1 := syscall.Syscall(procCancelIoEx.Addr(), 2, uintptr(s), uintptr(unsafe.Pointer(o)), 0) + r1, _, e1 := syscall.SyscallN(procCancelIoEx.Addr(), uintptr(s), uintptr(unsafe.Pointer(o))) if r1 == 0 { err = errnoErr(e1) } @@ -1728,7 +1728,7 @@ func CancelIoEx(s Handle, o *Overlapped) (err error) { } func ClearCommBreak(handle Handle) (err error) { - r1, _, e1 := syscall.Syscall(procClearCommBreak.Addr(), 1, uintptr(handle), 0, 0) + r1, _, e1 := syscall.SyscallN(procClearCommBreak.Addr(), uintptr(handle)) if r1 == 0 { err = errnoErr(e1) } @@ -1736,7 +1736,7 @@ func ClearCommBreak(handle Handle) (err error) { } func ClearCommError(handle Handle, lpErrors *uint32, lpStat *ComStat) (err error) { - r1, _, e1 := syscall.Syscall(procClearCommError.Addr(), 3, uintptr(handle), uintptr(unsafe.Pointer(lpErrors)), uintptr(unsafe.Pointer(lpStat))) + r1, _, e1 := syscall.SyscallN(procClearCommError.Addr(), uintptr(handle), uintptr(unsafe.Pointer(lpErrors)), uintptr(unsafe.Pointer(lpStat))) if r1 == 0 { err = errnoErr(e1) } @@ -1744,7 +1744,7 @@ func ClearCommError(handle Handle, lpErrors *uint32, lpStat *ComStat) (err error } func CloseHandle(handle Handle) (err error) { - r1, _, e1 := syscall.Syscall(procCloseHandle.Addr(), 1, uintptr(handle), 0, 0) + r1, _, e1 := syscall.SyscallN(procCloseHandle.Addr(), uintptr(handle)) if r1 == 0 { err = errnoErr(e1) } @@ -1752,12 +1752,12 @@ func CloseHandle(handle Handle) (err error) { } func ClosePseudoConsole(console Handle) { - syscall.Syscall(procClosePseudoConsole.Addr(), 1, uintptr(console), 0, 0) + syscall.SyscallN(procClosePseudoConsole.Addr(), uintptr(console)) return } func ConnectNamedPipe(pipe Handle, overlapped *Overlapped) (err error) { - r1, _, e1 := syscall.Syscall(procConnectNamedPipe.Addr(), 2, uintptr(pipe), uintptr(unsafe.Pointer(overlapped)), 0) + r1, _, e1 := syscall.SyscallN(procConnectNamedPipe.Addr(), uintptr(pipe), uintptr(unsafe.Pointer(overlapped))) if r1 == 0 { err = errnoErr(e1) } @@ -1765,7 +1765,7 @@ func ConnectNamedPipe(pipe Handle, overlapped *Overlapped) (err error) { } func CreateDirectory(path *uint16, sa *SecurityAttributes) (err error) { - r1, _, e1 := syscall.Syscall(procCreateDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(sa)), 0) + r1, _, e1 := syscall.SyscallN(procCreateDirectoryW.Addr(), uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(sa))) if r1 == 0 { err = errnoErr(e1) } @@ -1773,7 +1773,7 @@ func CreateDirectory(path *uint16, sa *SecurityAttributes) (err error) { } func CreateEventEx(eventAttrs *SecurityAttributes, name *uint16, flags uint32, desiredAccess uint32) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall6(procCreateEventExW.Addr(), 4, uintptr(unsafe.Pointer(eventAttrs)), uintptr(unsafe.Pointer(name)), uintptr(flags), uintptr(desiredAccess), 0, 0) + r0, _, e1 := syscall.SyscallN(procCreateEventExW.Addr(), uintptr(unsafe.Pointer(eventAttrs)), uintptr(unsafe.Pointer(name)), uintptr(flags), uintptr(desiredAccess)) handle = Handle(r0) if handle == 0 || e1 == ERROR_ALREADY_EXISTS { err = errnoErr(e1) @@ -1782,7 +1782,7 @@ func CreateEventEx(eventAttrs *SecurityAttributes, name *uint16, flags uint32, d } func CreateEvent(eventAttrs *SecurityAttributes, manualReset uint32, initialState uint32, name *uint16) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall6(procCreateEventW.Addr(), 4, uintptr(unsafe.Pointer(eventAttrs)), uintptr(manualReset), uintptr(initialState), uintptr(unsafe.Pointer(name)), 0, 0) + r0, _, e1 := syscall.SyscallN(procCreateEventW.Addr(), uintptr(unsafe.Pointer(eventAttrs)), uintptr(manualReset), uintptr(initialState), uintptr(unsafe.Pointer(name))) handle = Handle(r0) if handle == 0 || e1 == ERROR_ALREADY_EXISTS { err = errnoErr(e1) @@ -1791,7 +1791,7 @@ func CreateEvent(eventAttrs *SecurityAttributes, manualReset uint32, initialStat } func CreateFileMapping(fhandle Handle, sa *SecurityAttributes, prot uint32, maxSizeHigh uint32, maxSizeLow uint32, name *uint16) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall6(procCreateFileMappingW.Addr(), 6, uintptr(fhandle), uintptr(unsafe.Pointer(sa)), uintptr(prot), uintptr(maxSizeHigh), uintptr(maxSizeLow), uintptr(unsafe.Pointer(name))) + r0, _, e1 := syscall.SyscallN(procCreateFileMappingW.Addr(), uintptr(fhandle), uintptr(unsafe.Pointer(sa)), uintptr(prot), uintptr(maxSizeHigh), uintptr(maxSizeLow), uintptr(unsafe.Pointer(name))) handle = Handle(r0) if handle == 0 || e1 == ERROR_ALREADY_EXISTS { err = errnoErr(e1) @@ -1800,7 +1800,7 @@ func CreateFileMapping(fhandle Handle, sa *SecurityAttributes, prot uint32, maxS } func CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile Handle) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall9(procCreateFileW.Addr(), 7, uintptr(unsafe.Pointer(name)), uintptr(access), uintptr(mode), uintptr(unsafe.Pointer(sa)), uintptr(createmode), uintptr(attrs), uintptr(templatefile), 0, 0) + r0, _, e1 := syscall.SyscallN(procCreateFileW.Addr(), uintptr(unsafe.Pointer(name)), uintptr(access), uintptr(mode), uintptr(unsafe.Pointer(sa)), uintptr(createmode), uintptr(attrs), uintptr(templatefile)) handle = Handle(r0) if handle == InvalidHandle { err = errnoErr(e1) @@ -1809,7 +1809,7 @@ func CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes } func CreateHardLink(filename *uint16, existingfilename *uint16, reserved uintptr) (err error) { - r1, _, e1 := syscall.Syscall(procCreateHardLinkW.Addr(), 3, uintptr(unsafe.Pointer(filename)), uintptr(unsafe.Pointer(existingfilename)), uintptr(reserved)) + r1, _, e1 := syscall.SyscallN(procCreateHardLinkW.Addr(), uintptr(unsafe.Pointer(filename)), uintptr(unsafe.Pointer(existingfilename)), uintptr(reserved)) if r1&0xff == 0 { err = errnoErr(e1) } @@ -1817,7 +1817,7 @@ func CreateHardLink(filename *uint16, existingfilename *uint16, reserved uintptr } func CreateIoCompletionPort(filehandle Handle, cphandle Handle, key uintptr, threadcnt uint32) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall6(procCreateIoCompletionPort.Addr(), 4, uintptr(filehandle), uintptr(cphandle), uintptr(key), uintptr(threadcnt), 0, 0) + r0, _, e1 := syscall.SyscallN(procCreateIoCompletionPort.Addr(), uintptr(filehandle), uintptr(cphandle), uintptr(key), uintptr(threadcnt)) handle = Handle(r0) if handle == 0 { err = errnoErr(e1) @@ -1826,7 +1826,7 @@ func CreateIoCompletionPort(filehandle Handle, cphandle Handle, key uintptr, thr } func CreateJobObject(jobAttr *SecurityAttributes, name *uint16) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall(procCreateJobObjectW.Addr(), 2, uintptr(unsafe.Pointer(jobAttr)), uintptr(unsafe.Pointer(name)), 0) + r0, _, e1 := syscall.SyscallN(procCreateJobObjectW.Addr(), uintptr(unsafe.Pointer(jobAttr)), uintptr(unsafe.Pointer(name))) handle = Handle(r0) if handle == 0 { err = errnoErr(e1) @@ -1835,7 +1835,7 @@ func CreateJobObject(jobAttr *SecurityAttributes, name *uint16) (handle Handle, } func CreateMutexEx(mutexAttrs *SecurityAttributes, name *uint16, flags uint32, desiredAccess uint32) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall6(procCreateMutexExW.Addr(), 4, uintptr(unsafe.Pointer(mutexAttrs)), uintptr(unsafe.Pointer(name)), uintptr(flags), uintptr(desiredAccess), 0, 0) + r0, _, e1 := syscall.SyscallN(procCreateMutexExW.Addr(), uintptr(unsafe.Pointer(mutexAttrs)), uintptr(unsafe.Pointer(name)), uintptr(flags), uintptr(desiredAccess)) handle = Handle(r0) if handle == 0 || e1 == ERROR_ALREADY_EXISTS { err = errnoErr(e1) @@ -1848,7 +1848,7 @@ func CreateMutex(mutexAttrs *SecurityAttributes, initialOwner bool, name *uint16 if initialOwner { _p0 = 1 } - r0, _, e1 := syscall.Syscall(procCreateMutexW.Addr(), 3, uintptr(unsafe.Pointer(mutexAttrs)), uintptr(_p0), uintptr(unsafe.Pointer(name))) + r0, _, e1 := syscall.SyscallN(procCreateMutexW.Addr(), uintptr(unsafe.Pointer(mutexAttrs)), uintptr(_p0), uintptr(unsafe.Pointer(name))) handle = Handle(r0) if handle == 0 || e1 == ERROR_ALREADY_EXISTS { err = errnoErr(e1) @@ -1857,7 +1857,7 @@ func CreateMutex(mutexAttrs *SecurityAttributes, initialOwner bool, name *uint16 } func CreateNamedPipe(name *uint16, flags uint32, pipeMode uint32, maxInstances uint32, outSize uint32, inSize uint32, defaultTimeout uint32, sa *SecurityAttributes) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall9(procCreateNamedPipeW.Addr(), 8, uintptr(unsafe.Pointer(name)), uintptr(flags), uintptr(pipeMode), uintptr(maxInstances), uintptr(outSize), uintptr(inSize), uintptr(defaultTimeout), uintptr(unsafe.Pointer(sa)), 0) + r0, _, e1 := syscall.SyscallN(procCreateNamedPipeW.Addr(), uintptr(unsafe.Pointer(name)), uintptr(flags), uintptr(pipeMode), uintptr(maxInstances), uintptr(outSize), uintptr(inSize), uintptr(defaultTimeout), uintptr(unsafe.Pointer(sa))) handle = Handle(r0) if handle == InvalidHandle { err = errnoErr(e1) @@ -1866,7 +1866,7 @@ func CreateNamedPipe(name *uint16, flags uint32, pipeMode uint32, maxInstances u } func CreatePipe(readhandle *Handle, writehandle *Handle, sa *SecurityAttributes, size uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procCreatePipe.Addr(), 4, uintptr(unsafe.Pointer(readhandle)), uintptr(unsafe.Pointer(writehandle)), uintptr(unsafe.Pointer(sa)), uintptr(size), 0, 0) + r1, _, e1 := syscall.SyscallN(procCreatePipe.Addr(), uintptr(unsafe.Pointer(readhandle)), uintptr(unsafe.Pointer(writehandle)), uintptr(unsafe.Pointer(sa)), uintptr(size)) if r1 == 0 { err = errnoErr(e1) } @@ -1878,7 +1878,7 @@ func CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityA if inheritHandles { _p0 = 1 } - r1, _, e1 := syscall.Syscall12(procCreateProcessW.Addr(), 10, uintptr(unsafe.Pointer(appName)), uintptr(unsafe.Pointer(commandLine)), uintptr(unsafe.Pointer(procSecurity)), uintptr(unsafe.Pointer(threadSecurity)), uintptr(_p0), uintptr(creationFlags), uintptr(unsafe.Pointer(env)), uintptr(unsafe.Pointer(currentDir)), uintptr(unsafe.Pointer(startupInfo)), uintptr(unsafe.Pointer(outProcInfo)), 0, 0) + r1, _, e1 := syscall.SyscallN(procCreateProcessW.Addr(), uintptr(unsafe.Pointer(appName)), uintptr(unsafe.Pointer(commandLine)), uintptr(unsafe.Pointer(procSecurity)), uintptr(unsafe.Pointer(threadSecurity)), uintptr(_p0), uintptr(creationFlags), uintptr(unsafe.Pointer(env)), uintptr(unsafe.Pointer(currentDir)), uintptr(unsafe.Pointer(startupInfo)), uintptr(unsafe.Pointer(outProcInfo))) if r1 == 0 { err = errnoErr(e1) } @@ -1886,7 +1886,7 @@ func CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityA } func createPseudoConsole(size uint32, in Handle, out Handle, flags uint32, pconsole *Handle) (hr error) { - r0, _, _ := syscall.Syscall6(procCreatePseudoConsole.Addr(), 5, uintptr(size), uintptr(in), uintptr(out), uintptr(flags), uintptr(unsafe.Pointer(pconsole)), 0) + r0, _, _ := syscall.SyscallN(procCreatePseudoConsole.Addr(), uintptr(size), uintptr(in), uintptr(out), uintptr(flags), uintptr(unsafe.Pointer(pconsole))) if r0 != 0 { hr = syscall.Errno(r0) } @@ -1894,7 +1894,7 @@ func createPseudoConsole(size uint32, in Handle, out Handle, flags uint32, pcons } func CreateSymbolicLink(symlinkfilename *uint16, targetfilename *uint16, flags uint32) (err error) { - r1, _, e1 := syscall.Syscall(procCreateSymbolicLinkW.Addr(), 3, uintptr(unsafe.Pointer(symlinkfilename)), uintptr(unsafe.Pointer(targetfilename)), uintptr(flags)) + r1, _, e1 := syscall.SyscallN(procCreateSymbolicLinkW.Addr(), uintptr(unsafe.Pointer(symlinkfilename)), uintptr(unsafe.Pointer(targetfilename)), uintptr(flags)) if r1&0xff == 0 { err = errnoErr(e1) } @@ -1902,7 +1902,7 @@ func CreateSymbolicLink(symlinkfilename *uint16, targetfilename *uint16, flags u } func CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall(procCreateToolhelp32Snapshot.Addr(), 2, uintptr(flags), uintptr(processId), 0) + r0, _, e1 := syscall.SyscallN(procCreateToolhelp32Snapshot.Addr(), uintptr(flags), uintptr(processId)) handle = Handle(r0) if handle == InvalidHandle { err = errnoErr(e1) @@ -1911,7 +1911,7 @@ func CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle Handle, er } func DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) { - r1, _, e1 := syscall.Syscall(procDefineDosDeviceW.Addr(), 3, uintptr(flags), uintptr(unsafe.Pointer(deviceName)), uintptr(unsafe.Pointer(targetPath))) + r1, _, e1 := syscall.SyscallN(procDefineDosDeviceW.Addr(), uintptr(flags), uintptr(unsafe.Pointer(deviceName)), uintptr(unsafe.Pointer(targetPath))) if r1 == 0 { err = errnoErr(e1) } @@ -1919,7 +1919,7 @@ func DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err } func DeleteFile(path *uint16) (err error) { - r1, _, e1 := syscall.Syscall(procDeleteFileW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0) + r1, _, e1 := syscall.SyscallN(procDeleteFileW.Addr(), uintptr(unsafe.Pointer(path))) if r1 == 0 { err = errnoErr(e1) } @@ -1927,12 +1927,12 @@ func DeleteFile(path *uint16) (err error) { } func deleteProcThreadAttributeList(attrlist *ProcThreadAttributeList) { - syscall.Syscall(procDeleteProcThreadAttributeList.Addr(), 1, uintptr(unsafe.Pointer(attrlist)), 0, 0) + syscall.SyscallN(procDeleteProcThreadAttributeList.Addr(), uintptr(unsafe.Pointer(attrlist))) return } func DeleteVolumeMountPoint(volumeMountPoint *uint16) (err error) { - r1, _, e1 := syscall.Syscall(procDeleteVolumeMountPointW.Addr(), 1, uintptr(unsafe.Pointer(volumeMountPoint)), 0, 0) + r1, _, e1 := syscall.SyscallN(procDeleteVolumeMountPointW.Addr(), uintptr(unsafe.Pointer(volumeMountPoint))) if r1 == 0 { err = errnoErr(e1) } @@ -1940,7 +1940,7 @@ func DeleteVolumeMountPoint(volumeMountPoint *uint16) (err error) { } func DeviceIoControl(handle Handle, ioControlCode uint32, inBuffer *byte, inBufferSize uint32, outBuffer *byte, outBufferSize uint32, bytesReturned *uint32, overlapped *Overlapped) (err error) { - r1, _, e1 := syscall.Syscall9(procDeviceIoControl.Addr(), 8, uintptr(handle), uintptr(ioControlCode), uintptr(unsafe.Pointer(inBuffer)), uintptr(inBufferSize), uintptr(unsafe.Pointer(outBuffer)), uintptr(outBufferSize), uintptr(unsafe.Pointer(bytesReturned)), uintptr(unsafe.Pointer(overlapped)), 0) + r1, _, e1 := syscall.SyscallN(procDeviceIoControl.Addr(), uintptr(handle), uintptr(ioControlCode), uintptr(unsafe.Pointer(inBuffer)), uintptr(inBufferSize), uintptr(unsafe.Pointer(outBuffer)), uintptr(outBufferSize), uintptr(unsafe.Pointer(bytesReturned)), uintptr(unsafe.Pointer(overlapped))) if r1 == 0 { err = errnoErr(e1) } @@ -1948,7 +1948,7 @@ func DeviceIoControl(handle Handle, ioControlCode uint32, inBuffer *byte, inBuff } func DisconnectNamedPipe(pipe Handle) (err error) { - r1, _, e1 := syscall.Syscall(procDisconnectNamedPipe.Addr(), 1, uintptr(pipe), 0, 0) + r1, _, e1 := syscall.SyscallN(procDisconnectNamedPipe.Addr(), uintptr(pipe)) if r1 == 0 { err = errnoErr(e1) } @@ -1960,7 +1960,7 @@ func DuplicateHandle(hSourceProcessHandle Handle, hSourceHandle Handle, hTargetP if bInheritHandle { _p0 = 1 } - r1, _, e1 := syscall.Syscall9(procDuplicateHandle.Addr(), 7, uintptr(hSourceProcessHandle), uintptr(hSourceHandle), uintptr(hTargetProcessHandle), uintptr(unsafe.Pointer(lpTargetHandle)), uintptr(dwDesiredAccess), uintptr(_p0), uintptr(dwOptions), 0, 0) + r1, _, e1 := syscall.SyscallN(procDuplicateHandle.Addr(), uintptr(hSourceProcessHandle), uintptr(hSourceHandle), uintptr(hTargetProcessHandle), uintptr(unsafe.Pointer(lpTargetHandle)), uintptr(dwDesiredAccess), uintptr(_p0), uintptr(dwOptions)) if r1 == 0 { err = errnoErr(e1) } @@ -1968,7 +1968,7 @@ func DuplicateHandle(hSourceProcessHandle Handle, hSourceHandle Handle, hTargetP } func EscapeCommFunction(handle Handle, dwFunc uint32) (err error) { - r1, _, e1 := syscall.Syscall(procEscapeCommFunction.Addr(), 2, uintptr(handle), uintptr(dwFunc), 0) + r1, _, e1 := syscall.SyscallN(procEscapeCommFunction.Addr(), uintptr(handle), uintptr(dwFunc)) if r1 == 0 { err = errnoErr(e1) } @@ -1976,12 +1976,12 @@ func EscapeCommFunction(handle Handle, dwFunc uint32) (err error) { } func ExitProcess(exitcode uint32) { - syscall.Syscall(procExitProcess.Addr(), 1, uintptr(exitcode), 0, 0) + syscall.SyscallN(procExitProcess.Addr(), uintptr(exitcode)) return } func ExpandEnvironmentStrings(src *uint16, dst *uint16, size uint32) (n uint32, err error) { - r0, _, e1 := syscall.Syscall(procExpandEnvironmentStringsW.Addr(), 3, uintptr(unsafe.Pointer(src)), uintptr(unsafe.Pointer(dst)), uintptr(size)) + r0, _, e1 := syscall.SyscallN(procExpandEnvironmentStringsW.Addr(), uintptr(unsafe.Pointer(src)), uintptr(unsafe.Pointer(dst)), uintptr(size)) n = uint32(r0) if n == 0 { err = errnoErr(e1) @@ -1990,7 +1990,7 @@ func ExpandEnvironmentStrings(src *uint16, dst *uint16, size uint32) (n uint32, } func FindClose(handle Handle) (err error) { - r1, _, e1 := syscall.Syscall(procFindClose.Addr(), 1, uintptr(handle), 0, 0) + r1, _, e1 := syscall.SyscallN(procFindClose.Addr(), uintptr(handle)) if r1 == 0 { err = errnoErr(e1) } @@ -1998,7 +1998,7 @@ func FindClose(handle Handle) (err error) { } func FindCloseChangeNotification(handle Handle) (err error) { - r1, _, e1 := syscall.Syscall(procFindCloseChangeNotification.Addr(), 1, uintptr(handle), 0, 0) + r1, _, e1 := syscall.SyscallN(procFindCloseChangeNotification.Addr(), uintptr(handle)) if r1 == 0 { err = errnoErr(e1) } @@ -2019,7 +2019,7 @@ func _FindFirstChangeNotification(path *uint16, watchSubtree bool, notifyFilter if watchSubtree { _p1 = 1 } - r0, _, e1 := syscall.Syscall(procFindFirstChangeNotificationW.Addr(), 3, uintptr(unsafe.Pointer(path)), uintptr(_p1), uintptr(notifyFilter)) + r0, _, e1 := syscall.SyscallN(procFindFirstChangeNotificationW.Addr(), uintptr(unsafe.Pointer(path)), uintptr(_p1), uintptr(notifyFilter)) handle = Handle(r0) if handle == InvalidHandle { err = errnoErr(e1) @@ -2028,7 +2028,7 @@ func _FindFirstChangeNotification(path *uint16, watchSubtree bool, notifyFilter } func findFirstFile1(name *uint16, data *win32finddata1) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall(procFindFirstFileW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(data)), 0) + r0, _, e1 := syscall.SyscallN(procFindFirstFileW.Addr(), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(data))) handle = Handle(r0) if handle == InvalidHandle { err = errnoErr(e1) @@ -2037,7 +2037,7 @@ func findFirstFile1(name *uint16, data *win32finddata1) (handle Handle, err erro } func FindFirstVolumeMountPoint(rootPathName *uint16, volumeMountPoint *uint16, bufferLength uint32) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall(procFindFirstVolumeMountPointW.Addr(), 3, uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(bufferLength)) + r0, _, e1 := syscall.SyscallN(procFindFirstVolumeMountPointW.Addr(), uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(bufferLength)) handle = Handle(r0) if handle == InvalidHandle { err = errnoErr(e1) @@ -2046,7 +2046,7 @@ func FindFirstVolumeMountPoint(rootPathName *uint16, volumeMountPoint *uint16, b } func FindFirstVolume(volumeName *uint16, bufferLength uint32) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall(procFindFirstVolumeW.Addr(), 2, uintptr(unsafe.Pointer(volumeName)), uintptr(bufferLength), 0) + r0, _, e1 := syscall.SyscallN(procFindFirstVolumeW.Addr(), uintptr(unsafe.Pointer(volumeName)), uintptr(bufferLength)) handle = Handle(r0) if handle == InvalidHandle { err = errnoErr(e1) @@ -2055,7 +2055,7 @@ func FindFirstVolume(volumeName *uint16, bufferLength uint32) (handle Handle, er } func FindNextChangeNotification(handle Handle) (err error) { - r1, _, e1 := syscall.Syscall(procFindNextChangeNotification.Addr(), 1, uintptr(handle), 0, 0) + r1, _, e1 := syscall.SyscallN(procFindNextChangeNotification.Addr(), uintptr(handle)) if r1 == 0 { err = errnoErr(e1) } @@ -2063,7 +2063,7 @@ func FindNextChangeNotification(handle Handle) (err error) { } func findNextFile1(handle Handle, data *win32finddata1) (err error) { - r1, _, e1 := syscall.Syscall(procFindNextFileW.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0) + r1, _, e1 := syscall.SyscallN(procFindNextFileW.Addr(), uintptr(handle), uintptr(unsafe.Pointer(data))) if r1 == 0 { err = errnoErr(e1) } @@ -2071,7 +2071,7 @@ func findNextFile1(handle Handle, data *win32finddata1) (err error) { } func FindNextVolumeMountPoint(findVolumeMountPoint Handle, volumeMountPoint *uint16, bufferLength uint32) (err error) { - r1, _, e1 := syscall.Syscall(procFindNextVolumeMountPointW.Addr(), 3, uintptr(findVolumeMountPoint), uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(bufferLength)) + r1, _, e1 := syscall.SyscallN(procFindNextVolumeMountPointW.Addr(), uintptr(findVolumeMountPoint), uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(bufferLength)) if r1 == 0 { err = errnoErr(e1) } @@ -2079,7 +2079,7 @@ func FindNextVolumeMountPoint(findVolumeMountPoint Handle, volumeMountPoint *uin } func FindNextVolume(findVolume Handle, volumeName *uint16, bufferLength uint32) (err error) { - r1, _, e1 := syscall.Syscall(procFindNextVolumeW.Addr(), 3, uintptr(findVolume), uintptr(unsafe.Pointer(volumeName)), uintptr(bufferLength)) + r1, _, e1 := syscall.SyscallN(procFindNextVolumeW.Addr(), uintptr(findVolume), uintptr(unsafe.Pointer(volumeName)), uintptr(bufferLength)) if r1 == 0 { err = errnoErr(e1) } @@ -2087,7 +2087,7 @@ func FindNextVolume(findVolume Handle, volumeName *uint16, bufferLength uint32) } func findResource(module Handle, name uintptr, resType uintptr) (resInfo Handle, err error) { - r0, _, e1 := syscall.Syscall(procFindResourceW.Addr(), 3, uintptr(module), uintptr(name), uintptr(resType)) + r0, _, e1 := syscall.SyscallN(procFindResourceW.Addr(), uintptr(module), uintptr(name), uintptr(resType)) resInfo = Handle(r0) if resInfo == 0 { err = errnoErr(e1) @@ -2096,7 +2096,7 @@ func findResource(module Handle, name uintptr, resType uintptr) (resInfo Handle, } func FindVolumeClose(findVolume Handle) (err error) { - r1, _, e1 := syscall.Syscall(procFindVolumeClose.Addr(), 1, uintptr(findVolume), 0, 0) + r1, _, e1 := syscall.SyscallN(procFindVolumeClose.Addr(), uintptr(findVolume)) if r1 == 0 { err = errnoErr(e1) } @@ -2104,7 +2104,7 @@ func FindVolumeClose(findVolume Handle) (err error) { } func FindVolumeMountPointClose(findVolumeMountPoint Handle) (err error) { - r1, _, e1 := syscall.Syscall(procFindVolumeMountPointClose.Addr(), 1, uintptr(findVolumeMountPoint), 0, 0) + r1, _, e1 := syscall.SyscallN(procFindVolumeMountPointClose.Addr(), uintptr(findVolumeMountPoint)) if r1 == 0 { err = errnoErr(e1) } @@ -2112,7 +2112,7 @@ func FindVolumeMountPointClose(findVolumeMountPoint Handle) (err error) { } func FlushFileBuffers(handle Handle) (err error) { - r1, _, e1 := syscall.Syscall(procFlushFileBuffers.Addr(), 1, uintptr(handle), 0, 0) + r1, _, e1 := syscall.SyscallN(procFlushFileBuffers.Addr(), uintptr(handle)) if r1 == 0 { err = errnoErr(e1) } @@ -2120,7 +2120,7 @@ func FlushFileBuffers(handle Handle) (err error) { } func FlushViewOfFile(addr uintptr, length uintptr) (err error) { - r1, _, e1 := syscall.Syscall(procFlushViewOfFile.Addr(), 2, uintptr(addr), uintptr(length), 0) + r1, _, e1 := syscall.SyscallN(procFlushViewOfFile.Addr(), uintptr(addr), uintptr(length)) if r1 == 0 { err = errnoErr(e1) } @@ -2132,7 +2132,7 @@ func FormatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, bu if len(buf) > 0 { _p0 = &buf[0] } - r0, _, e1 := syscall.Syscall9(procFormatMessageW.Addr(), 7, uintptr(flags), uintptr(msgsrc), uintptr(msgid), uintptr(langid), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(args)), 0, 0) + r0, _, e1 := syscall.SyscallN(procFormatMessageW.Addr(), uintptr(flags), uintptr(msgsrc), uintptr(msgid), uintptr(langid), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(args))) n = uint32(r0) if n == 0 { err = errnoErr(e1) @@ -2141,7 +2141,7 @@ func FormatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, bu } func FreeEnvironmentStrings(envs *uint16) (err error) { - r1, _, e1 := syscall.Syscall(procFreeEnvironmentStringsW.Addr(), 1, uintptr(unsafe.Pointer(envs)), 0, 0) + r1, _, e1 := syscall.SyscallN(procFreeEnvironmentStringsW.Addr(), uintptr(unsafe.Pointer(envs))) if r1 == 0 { err = errnoErr(e1) } @@ -2149,7 +2149,7 @@ func FreeEnvironmentStrings(envs *uint16) (err error) { } func FreeLibrary(handle Handle) (err error) { - r1, _, e1 := syscall.Syscall(procFreeLibrary.Addr(), 1, uintptr(handle), 0, 0) + r1, _, e1 := syscall.SyscallN(procFreeLibrary.Addr(), uintptr(handle)) if r1 == 0 { err = errnoErr(e1) } @@ -2157,7 +2157,7 @@ func FreeLibrary(handle Handle) (err error) { } func GenerateConsoleCtrlEvent(ctrlEvent uint32, processGroupID uint32) (err error) { - r1, _, e1 := syscall.Syscall(procGenerateConsoleCtrlEvent.Addr(), 2, uintptr(ctrlEvent), uintptr(processGroupID), 0) + r1, _, e1 := syscall.SyscallN(procGenerateConsoleCtrlEvent.Addr(), uintptr(ctrlEvent), uintptr(processGroupID)) if r1 == 0 { err = errnoErr(e1) } @@ -2165,19 +2165,19 @@ func GenerateConsoleCtrlEvent(ctrlEvent uint32, processGroupID uint32) (err erro } func GetACP() (acp uint32) { - r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0) + r0, _, _ := syscall.SyscallN(procGetACP.Addr()) acp = uint32(r0) return } func GetActiveProcessorCount(groupNumber uint16) (ret uint32) { - r0, _, _ := syscall.Syscall(procGetActiveProcessorCount.Addr(), 1, uintptr(groupNumber), 0, 0) + r0, _, _ := syscall.SyscallN(procGetActiveProcessorCount.Addr(), uintptr(groupNumber)) ret = uint32(r0) return } func GetCommModemStatus(handle Handle, lpModemStat *uint32) (err error) { - r1, _, e1 := syscall.Syscall(procGetCommModemStatus.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(lpModemStat)), 0) + r1, _, e1 := syscall.SyscallN(procGetCommModemStatus.Addr(), uintptr(handle), uintptr(unsafe.Pointer(lpModemStat))) if r1 == 0 { err = errnoErr(e1) } @@ -2185,7 +2185,7 @@ func GetCommModemStatus(handle Handle, lpModemStat *uint32) (err error) { } func GetCommState(handle Handle, lpDCB *DCB) (err error) { - r1, _, e1 := syscall.Syscall(procGetCommState.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(lpDCB)), 0) + r1, _, e1 := syscall.SyscallN(procGetCommState.Addr(), uintptr(handle), uintptr(unsafe.Pointer(lpDCB))) if r1 == 0 { err = errnoErr(e1) } @@ -2193,7 +2193,7 @@ func GetCommState(handle Handle, lpDCB *DCB) (err error) { } func GetCommTimeouts(handle Handle, timeouts *CommTimeouts) (err error) { - r1, _, e1 := syscall.Syscall(procGetCommTimeouts.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(timeouts)), 0) + r1, _, e1 := syscall.SyscallN(procGetCommTimeouts.Addr(), uintptr(handle), uintptr(unsafe.Pointer(timeouts))) if r1 == 0 { err = errnoErr(e1) } @@ -2201,13 +2201,13 @@ func GetCommTimeouts(handle Handle, timeouts *CommTimeouts) (err error) { } func GetCommandLine() (cmd *uint16) { - r0, _, _ := syscall.Syscall(procGetCommandLineW.Addr(), 0, 0, 0, 0) + r0, _, _ := syscall.SyscallN(procGetCommandLineW.Addr()) cmd = (*uint16)(unsafe.Pointer(r0)) return } func GetComputerNameEx(nametype uint32, buf *uint16, n *uint32) (err error) { - r1, _, e1 := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nametype), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n))) + r1, _, e1 := syscall.SyscallN(procGetComputerNameExW.Addr(), uintptr(nametype), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n))) if r1 == 0 { err = errnoErr(e1) } @@ -2215,7 +2215,7 @@ func GetComputerNameEx(nametype uint32, buf *uint16, n *uint32) (err error) { } func GetComputerName(buf *uint16, n *uint32) (err error) { - r1, _, e1 := syscall.Syscall(procGetComputerNameW.Addr(), 2, uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)), 0) + r1, _, e1 := syscall.SyscallN(procGetComputerNameW.Addr(), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n))) if r1 == 0 { err = errnoErr(e1) } @@ -2223,7 +2223,7 @@ func GetComputerName(buf *uint16, n *uint32) (err error) { } func GetConsoleCP() (cp uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetConsoleCP.Addr(), 0, 0, 0, 0) + r0, _, e1 := syscall.SyscallN(procGetConsoleCP.Addr()) cp = uint32(r0) if cp == 0 { err = errnoErr(e1) @@ -2232,7 +2232,7 @@ func GetConsoleCP() (cp uint32, err error) { } func GetConsoleMode(console Handle, mode *uint32) (err error) { - r1, _, e1 := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(mode)), 0) + r1, _, e1 := syscall.SyscallN(procGetConsoleMode.Addr(), uintptr(console), uintptr(unsafe.Pointer(mode))) if r1 == 0 { err = errnoErr(e1) } @@ -2240,7 +2240,7 @@ func GetConsoleMode(console Handle, mode *uint32) (err error) { } func GetConsoleOutputCP() (cp uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetConsoleOutputCP.Addr(), 0, 0, 0, 0) + r0, _, e1 := syscall.SyscallN(procGetConsoleOutputCP.Addr()) cp = uint32(r0) if cp == 0 { err = errnoErr(e1) @@ -2249,7 +2249,7 @@ func GetConsoleOutputCP() (cp uint32, err error) { } func GetConsoleScreenBufferInfo(console Handle, info *ConsoleScreenBufferInfo) (err error) { - r1, _, e1 := syscall.Syscall(procGetConsoleScreenBufferInfo.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(info)), 0) + r1, _, e1 := syscall.SyscallN(procGetConsoleScreenBufferInfo.Addr(), uintptr(console), uintptr(unsafe.Pointer(info))) if r1 == 0 { err = errnoErr(e1) } @@ -2257,7 +2257,7 @@ func GetConsoleScreenBufferInfo(console Handle, info *ConsoleScreenBufferInfo) ( } func GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetCurrentDirectoryW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0) + r0, _, e1 := syscall.SyscallN(procGetCurrentDirectoryW.Addr(), uintptr(buflen), uintptr(unsafe.Pointer(buf))) n = uint32(r0) if n == 0 { err = errnoErr(e1) @@ -2266,19 +2266,19 @@ func GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, err error) { } func GetCurrentProcessId() (pid uint32) { - r0, _, _ := syscall.Syscall(procGetCurrentProcessId.Addr(), 0, 0, 0, 0) + r0, _, _ := syscall.SyscallN(procGetCurrentProcessId.Addr()) pid = uint32(r0) return } func GetCurrentThreadId() (id uint32) { - r0, _, _ := syscall.Syscall(procGetCurrentThreadId.Addr(), 0, 0, 0, 0) + r0, _, _ := syscall.SyscallN(procGetCurrentThreadId.Addr()) id = uint32(r0) return } func GetDiskFreeSpaceEx(directoryName *uint16, freeBytesAvailableToCaller *uint64, totalNumberOfBytes *uint64, totalNumberOfFreeBytes *uint64) (err error) { - r1, _, e1 := syscall.Syscall6(procGetDiskFreeSpaceExW.Addr(), 4, uintptr(unsafe.Pointer(directoryName)), uintptr(unsafe.Pointer(freeBytesAvailableToCaller)), uintptr(unsafe.Pointer(totalNumberOfBytes)), uintptr(unsafe.Pointer(totalNumberOfFreeBytes)), 0, 0) + r1, _, e1 := syscall.SyscallN(procGetDiskFreeSpaceExW.Addr(), uintptr(unsafe.Pointer(directoryName)), uintptr(unsafe.Pointer(freeBytesAvailableToCaller)), uintptr(unsafe.Pointer(totalNumberOfBytes)), uintptr(unsafe.Pointer(totalNumberOfFreeBytes))) if r1 == 0 { err = errnoErr(e1) } @@ -2286,13 +2286,13 @@ func GetDiskFreeSpaceEx(directoryName *uint16, freeBytesAvailableToCaller *uint6 } func GetDriveType(rootPathName *uint16) (driveType uint32) { - r0, _, _ := syscall.Syscall(procGetDriveTypeW.Addr(), 1, uintptr(unsafe.Pointer(rootPathName)), 0, 0) + r0, _, _ := syscall.SyscallN(procGetDriveTypeW.Addr(), uintptr(unsafe.Pointer(rootPathName))) driveType = uint32(r0) return } func GetEnvironmentStrings() (envs *uint16, err error) { - r0, _, e1 := syscall.Syscall(procGetEnvironmentStringsW.Addr(), 0, 0, 0, 0) + r0, _, e1 := syscall.SyscallN(procGetEnvironmentStringsW.Addr()) envs = (*uint16)(unsafe.Pointer(r0)) if envs == nil { err = errnoErr(e1) @@ -2301,7 +2301,7 @@ func GetEnvironmentStrings() (envs *uint16, err error) { } func GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetEnvironmentVariableW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buffer)), uintptr(size)) + r0, _, e1 := syscall.SyscallN(procGetEnvironmentVariableW.Addr(), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buffer)), uintptr(size)) n = uint32(r0) if n == 0 { err = errnoErr(e1) @@ -2310,7 +2310,7 @@ func GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32 } func GetExitCodeProcess(handle Handle, exitcode *uint32) (err error) { - r1, _, e1 := syscall.Syscall(procGetExitCodeProcess.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(exitcode)), 0) + r1, _, e1 := syscall.SyscallN(procGetExitCodeProcess.Addr(), uintptr(handle), uintptr(unsafe.Pointer(exitcode))) if r1 == 0 { err = errnoErr(e1) } @@ -2318,7 +2318,7 @@ func GetExitCodeProcess(handle Handle, exitcode *uint32) (err error) { } func GetFileAttributesEx(name *uint16, level uint32, info *byte) (err error) { - r1, _, e1 := syscall.Syscall(procGetFileAttributesExW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(level), uintptr(unsafe.Pointer(info))) + r1, _, e1 := syscall.SyscallN(procGetFileAttributesExW.Addr(), uintptr(unsafe.Pointer(name)), uintptr(level), uintptr(unsafe.Pointer(info))) if r1 == 0 { err = errnoErr(e1) } @@ -2326,7 +2326,7 @@ func GetFileAttributesEx(name *uint16, level uint32, info *byte) (err error) { } func GetFileAttributes(name *uint16) (attrs uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetFileAttributesW.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0) + r0, _, e1 := syscall.SyscallN(procGetFileAttributesW.Addr(), uintptr(unsafe.Pointer(name))) attrs = uint32(r0) if attrs == INVALID_FILE_ATTRIBUTES { err = errnoErr(e1) @@ -2335,7 +2335,7 @@ func GetFileAttributes(name *uint16) (attrs uint32, err error) { } func GetFileInformationByHandle(handle Handle, data *ByHandleFileInformation) (err error) { - r1, _, e1 := syscall.Syscall(procGetFileInformationByHandle.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0) + r1, _, e1 := syscall.SyscallN(procGetFileInformationByHandle.Addr(), uintptr(handle), uintptr(unsafe.Pointer(data))) if r1 == 0 { err = errnoErr(e1) } @@ -2343,7 +2343,7 @@ func GetFileInformationByHandle(handle Handle, data *ByHandleFileInformation) (e } func GetFileInformationByHandleEx(handle Handle, class uint32, outBuffer *byte, outBufferLen uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procGetFileInformationByHandleEx.Addr(), 4, uintptr(handle), uintptr(class), uintptr(unsafe.Pointer(outBuffer)), uintptr(outBufferLen), 0, 0) + r1, _, e1 := syscall.SyscallN(procGetFileInformationByHandleEx.Addr(), uintptr(handle), uintptr(class), uintptr(unsafe.Pointer(outBuffer)), uintptr(outBufferLen)) if r1 == 0 { err = errnoErr(e1) } @@ -2351,7 +2351,7 @@ func GetFileInformationByHandleEx(handle Handle, class uint32, outBuffer *byte, } func GetFileTime(handle Handle, ctime *Filetime, atime *Filetime, wtime *Filetime) (err error) { - r1, _, e1 := syscall.Syscall6(procGetFileTime.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(ctime)), uintptr(unsafe.Pointer(atime)), uintptr(unsafe.Pointer(wtime)), 0, 0) + r1, _, e1 := syscall.SyscallN(procGetFileTime.Addr(), uintptr(handle), uintptr(unsafe.Pointer(ctime)), uintptr(unsafe.Pointer(atime)), uintptr(unsafe.Pointer(wtime))) if r1 == 0 { err = errnoErr(e1) } @@ -2359,7 +2359,7 @@ func GetFileTime(handle Handle, ctime *Filetime, atime *Filetime, wtime *Filetim } func GetFileType(filehandle Handle) (n uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetFileType.Addr(), 1, uintptr(filehandle), 0, 0) + r0, _, e1 := syscall.SyscallN(procGetFileType.Addr(), uintptr(filehandle)) n = uint32(r0) if n == 0 { err = errnoErr(e1) @@ -2368,7 +2368,7 @@ func GetFileType(filehandle Handle) (n uint32, err error) { } func GetFinalPathNameByHandle(file Handle, filePath *uint16, filePathSize uint32, flags uint32) (n uint32, err error) { - r0, _, e1 := syscall.Syscall6(procGetFinalPathNameByHandleW.Addr(), 4, uintptr(file), uintptr(unsafe.Pointer(filePath)), uintptr(filePathSize), uintptr(flags), 0, 0) + r0, _, e1 := syscall.SyscallN(procGetFinalPathNameByHandleW.Addr(), uintptr(file), uintptr(unsafe.Pointer(filePath)), uintptr(filePathSize), uintptr(flags)) n = uint32(r0) if n == 0 { err = errnoErr(e1) @@ -2377,7 +2377,7 @@ func GetFinalPathNameByHandle(file Handle, filePath *uint16, filePathSize uint32 } func GetFullPathName(path *uint16, buflen uint32, buf *uint16, fname **uint16) (n uint32, err error) { - r0, _, e1 := syscall.Syscall6(procGetFullPathNameW.Addr(), 4, uintptr(unsafe.Pointer(path)), uintptr(buflen), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(fname)), 0, 0) + r0, _, e1 := syscall.SyscallN(procGetFullPathNameW.Addr(), uintptr(unsafe.Pointer(path)), uintptr(buflen), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(fname))) n = uint32(r0) if n == 0 { err = errnoErr(e1) @@ -2386,13 +2386,13 @@ func GetFullPathName(path *uint16, buflen uint32, buf *uint16, fname **uint16) ( } func GetLargePageMinimum() (size uintptr) { - r0, _, _ := syscall.Syscall(procGetLargePageMinimum.Addr(), 0, 0, 0, 0) + r0, _, _ := syscall.SyscallN(procGetLargePageMinimum.Addr()) size = uintptr(r0) return } func GetLastError() (lasterr error) { - r0, _, _ := syscall.Syscall(procGetLastError.Addr(), 0, 0, 0, 0) + r0, _, _ := syscall.SyscallN(procGetLastError.Addr()) if r0 != 0 { lasterr = syscall.Errno(r0) } @@ -2400,7 +2400,7 @@ func GetLastError() (lasterr error) { } func GetLogicalDriveStrings(bufferLength uint32, buffer *uint16) (n uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetLogicalDriveStringsW.Addr(), 2, uintptr(bufferLength), uintptr(unsafe.Pointer(buffer)), 0) + r0, _, e1 := syscall.SyscallN(procGetLogicalDriveStringsW.Addr(), uintptr(bufferLength), uintptr(unsafe.Pointer(buffer))) n = uint32(r0) if n == 0 { err = errnoErr(e1) @@ -2409,7 +2409,7 @@ func GetLogicalDriveStrings(bufferLength uint32, buffer *uint16) (n uint32, err } func GetLogicalDrives() (drivesBitMask uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetLogicalDrives.Addr(), 0, 0, 0, 0) + r0, _, e1 := syscall.SyscallN(procGetLogicalDrives.Addr()) drivesBitMask = uint32(r0) if drivesBitMask == 0 { err = errnoErr(e1) @@ -2418,7 +2418,7 @@ func GetLogicalDrives() (drivesBitMask uint32, err error) { } func GetLongPathName(path *uint16, buf *uint16, buflen uint32) (n uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetLongPathNameW.Addr(), 3, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(buf)), uintptr(buflen)) + r0, _, e1 := syscall.SyscallN(procGetLongPathNameW.Addr(), uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(buf)), uintptr(buflen)) n = uint32(r0) if n == 0 { err = errnoErr(e1) @@ -2427,13 +2427,13 @@ func GetLongPathName(path *uint16, buf *uint16, buflen uint32) (n uint32, err er } func GetMaximumProcessorCount(groupNumber uint16) (ret uint32) { - r0, _, _ := syscall.Syscall(procGetMaximumProcessorCount.Addr(), 1, uintptr(groupNumber), 0, 0) + r0, _, _ := syscall.SyscallN(procGetMaximumProcessorCount.Addr(), uintptr(groupNumber)) ret = uint32(r0) return } func GetModuleFileName(module Handle, filename *uint16, size uint32) (n uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetModuleFileNameW.Addr(), 3, uintptr(module), uintptr(unsafe.Pointer(filename)), uintptr(size)) + r0, _, e1 := syscall.SyscallN(procGetModuleFileNameW.Addr(), uintptr(module), uintptr(unsafe.Pointer(filename)), uintptr(size)) n = uint32(r0) if n == 0 { err = errnoErr(e1) @@ -2442,7 +2442,7 @@ func GetModuleFileName(module Handle, filename *uint16, size uint32) (n uint32, } func GetModuleHandleEx(flags uint32, moduleName *uint16, module *Handle) (err error) { - r1, _, e1 := syscall.Syscall(procGetModuleHandleExW.Addr(), 3, uintptr(flags), uintptr(unsafe.Pointer(moduleName)), uintptr(unsafe.Pointer(module))) + r1, _, e1 := syscall.SyscallN(procGetModuleHandleExW.Addr(), uintptr(flags), uintptr(unsafe.Pointer(moduleName)), uintptr(unsafe.Pointer(module))) if r1 == 0 { err = errnoErr(e1) } @@ -2450,7 +2450,7 @@ func GetModuleHandleEx(flags uint32, moduleName *uint16, module *Handle) (err er } func GetNamedPipeClientProcessId(pipe Handle, clientProcessID *uint32) (err error) { - r1, _, e1 := syscall.Syscall(procGetNamedPipeClientProcessId.Addr(), 2, uintptr(pipe), uintptr(unsafe.Pointer(clientProcessID)), 0) + r1, _, e1 := syscall.SyscallN(procGetNamedPipeClientProcessId.Addr(), uintptr(pipe), uintptr(unsafe.Pointer(clientProcessID))) if r1 == 0 { err = errnoErr(e1) } @@ -2458,7 +2458,7 @@ func GetNamedPipeClientProcessId(pipe Handle, clientProcessID *uint32) (err erro } func GetNamedPipeHandleState(pipe Handle, state *uint32, curInstances *uint32, maxCollectionCount *uint32, collectDataTimeout *uint32, userName *uint16, maxUserNameSize uint32) (err error) { - r1, _, e1 := syscall.Syscall9(procGetNamedPipeHandleStateW.Addr(), 7, uintptr(pipe), uintptr(unsafe.Pointer(state)), uintptr(unsafe.Pointer(curInstances)), uintptr(unsafe.Pointer(maxCollectionCount)), uintptr(unsafe.Pointer(collectDataTimeout)), uintptr(unsafe.Pointer(userName)), uintptr(maxUserNameSize), 0, 0) + r1, _, e1 := syscall.SyscallN(procGetNamedPipeHandleStateW.Addr(), uintptr(pipe), uintptr(unsafe.Pointer(state)), uintptr(unsafe.Pointer(curInstances)), uintptr(unsafe.Pointer(maxCollectionCount)), uintptr(unsafe.Pointer(collectDataTimeout)), uintptr(unsafe.Pointer(userName)), uintptr(maxUserNameSize)) if r1 == 0 { err = errnoErr(e1) } @@ -2466,7 +2466,7 @@ func GetNamedPipeHandleState(pipe Handle, state *uint32, curInstances *uint32, m } func GetNamedPipeInfo(pipe Handle, flags *uint32, outSize *uint32, inSize *uint32, maxInstances *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procGetNamedPipeInfo.Addr(), 5, uintptr(pipe), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(outSize)), uintptr(unsafe.Pointer(inSize)), uintptr(unsafe.Pointer(maxInstances)), 0) + r1, _, e1 := syscall.SyscallN(procGetNamedPipeInfo.Addr(), uintptr(pipe), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(outSize)), uintptr(unsafe.Pointer(inSize)), uintptr(unsafe.Pointer(maxInstances))) if r1 == 0 { err = errnoErr(e1) } @@ -2474,7 +2474,7 @@ func GetNamedPipeInfo(pipe Handle, flags *uint32, outSize *uint32, inSize *uint3 } func GetNamedPipeServerProcessId(pipe Handle, serverProcessID *uint32) (err error) { - r1, _, e1 := syscall.Syscall(procGetNamedPipeServerProcessId.Addr(), 2, uintptr(pipe), uintptr(unsafe.Pointer(serverProcessID)), 0) + r1, _, e1 := syscall.SyscallN(procGetNamedPipeServerProcessId.Addr(), uintptr(pipe), uintptr(unsafe.Pointer(serverProcessID))) if r1 == 0 { err = errnoErr(e1) } @@ -2486,7 +2486,7 @@ func GetOverlappedResult(handle Handle, overlapped *Overlapped, done *uint32, wa if wait { _p0 = 1 } - r1, _, e1 := syscall.Syscall6(procGetOverlappedResult.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(done)), uintptr(_p0), 0, 0) + r1, _, e1 := syscall.SyscallN(procGetOverlappedResult.Addr(), uintptr(handle), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(done)), uintptr(_p0)) if r1 == 0 { err = errnoErr(e1) } @@ -2494,7 +2494,7 @@ func GetOverlappedResult(handle Handle, overlapped *Overlapped, done *uint32, wa } func GetPriorityClass(process Handle) (ret uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetPriorityClass.Addr(), 1, uintptr(process), 0, 0) + r0, _, e1 := syscall.SyscallN(procGetPriorityClass.Addr(), uintptr(process)) ret = uint32(r0) if ret == 0 { err = errnoErr(e1) @@ -2512,7 +2512,7 @@ func GetProcAddress(module Handle, procname string) (proc uintptr, err error) { } func _GetProcAddress(module Handle, procname *byte) (proc uintptr, err error) { - r0, _, e1 := syscall.Syscall(procGetProcAddress.Addr(), 2, uintptr(module), uintptr(unsafe.Pointer(procname)), 0) + r0, _, e1 := syscall.SyscallN(procGetProcAddress.Addr(), uintptr(module), uintptr(unsafe.Pointer(procname))) proc = uintptr(r0) if proc == 0 { err = errnoErr(e1) @@ -2521,7 +2521,7 @@ func _GetProcAddress(module Handle, procname *byte) (proc uintptr, err error) { } func GetProcessId(process Handle) (id uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetProcessId.Addr(), 1, uintptr(process), 0, 0) + r0, _, e1 := syscall.SyscallN(procGetProcessId.Addr(), uintptr(process)) id = uint32(r0) if id == 0 { err = errnoErr(e1) @@ -2530,7 +2530,7 @@ func GetProcessId(process Handle) (id uint32, err error) { } func getProcessPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint16, bufSize *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procGetProcessPreferredUILanguages.Addr(), 4, uintptr(flags), uintptr(unsafe.Pointer(numLanguages)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(bufSize)), 0, 0) + r1, _, e1 := syscall.SyscallN(procGetProcessPreferredUILanguages.Addr(), uintptr(flags), uintptr(unsafe.Pointer(numLanguages)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(bufSize))) if r1 == 0 { err = errnoErr(e1) } @@ -2538,7 +2538,7 @@ func getProcessPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uin } func GetProcessShutdownParameters(level *uint32, flags *uint32) (err error) { - r1, _, e1 := syscall.Syscall(procGetProcessShutdownParameters.Addr(), 2, uintptr(unsafe.Pointer(level)), uintptr(unsafe.Pointer(flags)), 0) + r1, _, e1 := syscall.SyscallN(procGetProcessShutdownParameters.Addr(), uintptr(unsafe.Pointer(level)), uintptr(unsafe.Pointer(flags))) if r1 == 0 { err = errnoErr(e1) } @@ -2546,7 +2546,7 @@ func GetProcessShutdownParameters(level *uint32, flags *uint32) (err error) { } func GetProcessTimes(handle Handle, creationTime *Filetime, exitTime *Filetime, kernelTime *Filetime, userTime *Filetime) (err error) { - r1, _, e1 := syscall.Syscall6(procGetProcessTimes.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(creationTime)), uintptr(unsafe.Pointer(exitTime)), uintptr(unsafe.Pointer(kernelTime)), uintptr(unsafe.Pointer(userTime)), 0) + r1, _, e1 := syscall.SyscallN(procGetProcessTimes.Addr(), uintptr(handle), uintptr(unsafe.Pointer(creationTime)), uintptr(unsafe.Pointer(exitTime)), uintptr(unsafe.Pointer(kernelTime)), uintptr(unsafe.Pointer(userTime))) if r1 == 0 { err = errnoErr(e1) } @@ -2554,12 +2554,12 @@ func GetProcessTimes(handle Handle, creationTime *Filetime, exitTime *Filetime, } func GetProcessWorkingSetSizeEx(hProcess Handle, lpMinimumWorkingSetSize *uintptr, lpMaximumWorkingSetSize *uintptr, flags *uint32) { - syscall.Syscall6(procGetProcessWorkingSetSizeEx.Addr(), 4, uintptr(hProcess), uintptr(unsafe.Pointer(lpMinimumWorkingSetSize)), uintptr(unsafe.Pointer(lpMaximumWorkingSetSize)), uintptr(unsafe.Pointer(flags)), 0, 0) + syscall.SyscallN(procGetProcessWorkingSetSizeEx.Addr(), uintptr(hProcess), uintptr(unsafe.Pointer(lpMinimumWorkingSetSize)), uintptr(unsafe.Pointer(lpMaximumWorkingSetSize)), uintptr(unsafe.Pointer(flags))) return } func GetQueuedCompletionStatus(cphandle Handle, qty *uint32, key *uintptr, overlapped **Overlapped, timeout uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procGetQueuedCompletionStatus.Addr(), 5, uintptr(cphandle), uintptr(unsafe.Pointer(qty)), uintptr(unsafe.Pointer(key)), uintptr(unsafe.Pointer(overlapped)), uintptr(timeout), 0) + r1, _, e1 := syscall.SyscallN(procGetQueuedCompletionStatus.Addr(), uintptr(cphandle), uintptr(unsafe.Pointer(qty)), uintptr(unsafe.Pointer(key)), uintptr(unsafe.Pointer(overlapped)), uintptr(timeout)) if r1 == 0 { err = errnoErr(e1) } @@ -2567,7 +2567,7 @@ func GetQueuedCompletionStatus(cphandle Handle, qty *uint32, key *uintptr, overl } func GetShortPathName(longpath *uint16, shortpath *uint16, buflen uint32) (n uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetShortPathNameW.Addr(), 3, uintptr(unsafe.Pointer(longpath)), uintptr(unsafe.Pointer(shortpath)), uintptr(buflen)) + r0, _, e1 := syscall.SyscallN(procGetShortPathNameW.Addr(), uintptr(unsafe.Pointer(longpath)), uintptr(unsafe.Pointer(shortpath)), uintptr(buflen)) n = uint32(r0) if n == 0 { err = errnoErr(e1) @@ -2576,12 +2576,12 @@ func GetShortPathName(longpath *uint16, shortpath *uint16, buflen uint32) (n uin } func getStartupInfo(startupInfo *StartupInfo) { - syscall.Syscall(procGetStartupInfoW.Addr(), 1, uintptr(unsafe.Pointer(startupInfo)), 0, 0) + syscall.SyscallN(procGetStartupInfoW.Addr(), uintptr(unsafe.Pointer(startupInfo))) return } func GetStdHandle(stdhandle uint32) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall(procGetStdHandle.Addr(), 1, uintptr(stdhandle), 0, 0) + r0, _, e1 := syscall.SyscallN(procGetStdHandle.Addr(), uintptr(stdhandle)) handle = Handle(r0) if handle == InvalidHandle { err = errnoErr(e1) @@ -2590,7 +2590,7 @@ func GetStdHandle(stdhandle uint32) (handle Handle, err error) { } func getSystemDirectory(dir *uint16, dirLen uint32) (len uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetSystemDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(dir)), uintptr(dirLen), 0) + r0, _, e1 := syscall.SyscallN(procGetSystemDirectoryW.Addr(), uintptr(unsafe.Pointer(dir)), uintptr(dirLen)) len = uint32(r0) if len == 0 { err = errnoErr(e1) @@ -2599,7 +2599,7 @@ func getSystemDirectory(dir *uint16, dirLen uint32) (len uint32, err error) { } func getSystemPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint16, bufSize *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procGetSystemPreferredUILanguages.Addr(), 4, uintptr(flags), uintptr(unsafe.Pointer(numLanguages)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(bufSize)), 0, 0) + r1, _, e1 := syscall.SyscallN(procGetSystemPreferredUILanguages.Addr(), uintptr(flags), uintptr(unsafe.Pointer(numLanguages)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(bufSize))) if r1 == 0 { err = errnoErr(e1) } @@ -2607,17 +2607,17 @@ func getSystemPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint } func GetSystemTimeAsFileTime(time *Filetime) { - syscall.Syscall(procGetSystemTimeAsFileTime.Addr(), 1, uintptr(unsafe.Pointer(time)), 0, 0) + syscall.SyscallN(procGetSystemTimeAsFileTime.Addr(), uintptr(unsafe.Pointer(time))) return } func GetSystemTimePreciseAsFileTime(time *Filetime) { - syscall.Syscall(procGetSystemTimePreciseAsFileTime.Addr(), 1, uintptr(unsafe.Pointer(time)), 0, 0) + syscall.SyscallN(procGetSystemTimePreciseAsFileTime.Addr(), uintptr(unsafe.Pointer(time))) return } func getSystemWindowsDirectory(dir *uint16, dirLen uint32) (len uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetSystemWindowsDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(dir)), uintptr(dirLen), 0) + r0, _, e1 := syscall.SyscallN(procGetSystemWindowsDirectoryW.Addr(), uintptr(unsafe.Pointer(dir)), uintptr(dirLen)) len = uint32(r0) if len == 0 { err = errnoErr(e1) @@ -2626,7 +2626,7 @@ func getSystemWindowsDirectory(dir *uint16, dirLen uint32) (len uint32, err erro } func GetTempPath(buflen uint32, buf *uint16) (n uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetTempPathW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0) + r0, _, e1 := syscall.SyscallN(procGetTempPathW.Addr(), uintptr(buflen), uintptr(unsafe.Pointer(buf))) n = uint32(r0) if n == 0 { err = errnoErr(e1) @@ -2635,7 +2635,7 @@ func GetTempPath(buflen uint32, buf *uint16) (n uint32, err error) { } func getThreadPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint16, bufSize *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procGetThreadPreferredUILanguages.Addr(), 4, uintptr(flags), uintptr(unsafe.Pointer(numLanguages)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(bufSize)), 0, 0) + r1, _, e1 := syscall.SyscallN(procGetThreadPreferredUILanguages.Addr(), uintptr(flags), uintptr(unsafe.Pointer(numLanguages)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(bufSize))) if r1 == 0 { err = errnoErr(e1) } @@ -2643,13 +2643,13 @@ func getThreadPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint } func getTickCount64() (ms uint64) { - r0, _, _ := syscall.Syscall(procGetTickCount64.Addr(), 0, 0, 0, 0) + r0, _, _ := syscall.SyscallN(procGetTickCount64.Addr()) ms = uint64(r0) return } func GetTimeZoneInformation(tzi *Timezoneinformation) (rc uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetTimeZoneInformation.Addr(), 1, uintptr(unsafe.Pointer(tzi)), 0, 0) + r0, _, e1 := syscall.SyscallN(procGetTimeZoneInformation.Addr(), uintptr(unsafe.Pointer(tzi))) rc = uint32(r0) if rc == 0xffffffff { err = errnoErr(e1) @@ -2658,7 +2658,7 @@ func GetTimeZoneInformation(tzi *Timezoneinformation) (rc uint32, err error) { } func getUserPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint16, bufSize *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procGetUserPreferredUILanguages.Addr(), 4, uintptr(flags), uintptr(unsafe.Pointer(numLanguages)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(bufSize)), 0, 0) + r1, _, e1 := syscall.SyscallN(procGetUserPreferredUILanguages.Addr(), uintptr(flags), uintptr(unsafe.Pointer(numLanguages)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(bufSize))) if r1 == 0 { err = errnoErr(e1) } @@ -2666,7 +2666,7 @@ func getUserPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint16 } func GetVersion() (ver uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetVersion.Addr(), 0, 0, 0, 0) + r0, _, e1 := syscall.SyscallN(procGetVersion.Addr()) ver = uint32(r0) if ver == 0 { err = errnoErr(e1) @@ -2675,7 +2675,7 @@ func GetVersion() (ver uint32, err error) { } func GetVolumeInformationByHandle(file Handle, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) { - r1, _, e1 := syscall.Syscall9(procGetVolumeInformationByHandleW.Addr(), 8, uintptr(file), uintptr(unsafe.Pointer(volumeNameBuffer)), uintptr(volumeNameSize), uintptr(unsafe.Pointer(volumeNameSerialNumber)), uintptr(unsafe.Pointer(maximumComponentLength)), uintptr(unsafe.Pointer(fileSystemFlags)), uintptr(unsafe.Pointer(fileSystemNameBuffer)), uintptr(fileSystemNameSize), 0) + r1, _, e1 := syscall.SyscallN(procGetVolumeInformationByHandleW.Addr(), uintptr(file), uintptr(unsafe.Pointer(volumeNameBuffer)), uintptr(volumeNameSize), uintptr(unsafe.Pointer(volumeNameSerialNumber)), uintptr(unsafe.Pointer(maximumComponentLength)), uintptr(unsafe.Pointer(fileSystemFlags)), uintptr(unsafe.Pointer(fileSystemNameBuffer)), uintptr(fileSystemNameSize)) if r1 == 0 { err = errnoErr(e1) } @@ -2683,7 +2683,7 @@ func GetVolumeInformationByHandle(file Handle, volumeNameBuffer *uint16, volumeN } func GetVolumeInformation(rootPathName *uint16, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) { - r1, _, e1 := syscall.Syscall9(procGetVolumeInformationW.Addr(), 8, uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeNameBuffer)), uintptr(volumeNameSize), uintptr(unsafe.Pointer(volumeNameSerialNumber)), uintptr(unsafe.Pointer(maximumComponentLength)), uintptr(unsafe.Pointer(fileSystemFlags)), uintptr(unsafe.Pointer(fileSystemNameBuffer)), uintptr(fileSystemNameSize), 0) + r1, _, e1 := syscall.SyscallN(procGetVolumeInformationW.Addr(), uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeNameBuffer)), uintptr(volumeNameSize), uintptr(unsafe.Pointer(volumeNameSerialNumber)), uintptr(unsafe.Pointer(maximumComponentLength)), uintptr(unsafe.Pointer(fileSystemFlags)), uintptr(unsafe.Pointer(fileSystemNameBuffer)), uintptr(fileSystemNameSize)) if r1 == 0 { err = errnoErr(e1) } @@ -2691,7 +2691,7 @@ func GetVolumeInformation(rootPathName *uint16, volumeNameBuffer *uint16, volume } func GetVolumeNameForVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16, bufferlength uint32) (err error) { - r1, _, e1 := syscall.Syscall(procGetVolumeNameForVolumeMountPointW.Addr(), 3, uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(unsafe.Pointer(volumeName)), uintptr(bufferlength)) + r1, _, e1 := syscall.SyscallN(procGetVolumeNameForVolumeMountPointW.Addr(), uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(unsafe.Pointer(volumeName)), uintptr(bufferlength)) if r1 == 0 { err = errnoErr(e1) } @@ -2699,7 +2699,7 @@ func GetVolumeNameForVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint } func GetVolumePathName(fileName *uint16, volumePathName *uint16, bufferLength uint32) (err error) { - r1, _, e1 := syscall.Syscall(procGetVolumePathNameW.Addr(), 3, uintptr(unsafe.Pointer(fileName)), uintptr(unsafe.Pointer(volumePathName)), uintptr(bufferLength)) + r1, _, e1 := syscall.SyscallN(procGetVolumePathNameW.Addr(), uintptr(unsafe.Pointer(fileName)), uintptr(unsafe.Pointer(volumePathName)), uintptr(bufferLength)) if r1 == 0 { err = errnoErr(e1) } @@ -2707,7 +2707,7 @@ func GetVolumePathName(fileName *uint16, volumePathName *uint16, bufferLength ui } func GetVolumePathNamesForVolumeName(volumeName *uint16, volumePathNames *uint16, bufferLength uint32, returnLength *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procGetVolumePathNamesForVolumeNameW.Addr(), 4, uintptr(unsafe.Pointer(volumeName)), uintptr(unsafe.Pointer(volumePathNames)), uintptr(bufferLength), uintptr(unsafe.Pointer(returnLength)), 0, 0) + r1, _, e1 := syscall.SyscallN(procGetVolumePathNamesForVolumeNameW.Addr(), uintptr(unsafe.Pointer(volumeName)), uintptr(unsafe.Pointer(volumePathNames)), uintptr(bufferLength), uintptr(unsafe.Pointer(returnLength))) if r1 == 0 { err = errnoErr(e1) } @@ -2715,7 +2715,7 @@ func GetVolumePathNamesForVolumeName(volumeName *uint16, volumePathNames *uint16 } func getWindowsDirectory(dir *uint16, dirLen uint32) (len uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetWindowsDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(dir)), uintptr(dirLen), 0) + r0, _, e1 := syscall.SyscallN(procGetWindowsDirectoryW.Addr(), uintptr(unsafe.Pointer(dir)), uintptr(dirLen)) len = uint32(r0) if len == 0 { err = errnoErr(e1) @@ -2724,7 +2724,7 @@ func getWindowsDirectory(dir *uint16, dirLen uint32) (len uint32, err error) { } func initializeProcThreadAttributeList(attrlist *ProcThreadAttributeList, attrcount uint32, flags uint32, size *uintptr) (err error) { - r1, _, e1 := syscall.Syscall6(procInitializeProcThreadAttributeList.Addr(), 4, uintptr(unsafe.Pointer(attrlist)), uintptr(attrcount), uintptr(flags), uintptr(unsafe.Pointer(size)), 0, 0) + r1, _, e1 := syscall.SyscallN(procInitializeProcThreadAttributeList.Addr(), uintptr(unsafe.Pointer(attrlist)), uintptr(attrcount), uintptr(flags), uintptr(unsafe.Pointer(size))) if r1 == 0 { err = errnoErr(e1) } @@ -2736,7 +2736,7 @@ func IsWow64Process(handle Handle, isWow64 *bool) (err error) { if *isWow64 { _p0 = 1 } - r1, _, e1 := syscall.Syscall(procIsWow64Process.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(&_p0)), 0) + r1, _, e1 := syscall.SyscallN(procIsWow64Process.Addr(), uintptr(handle), uintptr(unsafe.Pointer(&_p0))) *isWow64 = _p0 != 0 if r1 == 0 { err = errnoErr(e1) @@ -2749,7 +2749,7 @@ func IsWow64Process2(handle Handle, processMachine *uint16, nativeMachine *uint1 if err != nil { return } - r1, _, e1 := syscall.Syscall(procIsWow64Process2.Addr(), 3, uintptr(handle), uintptr(unsafe.Pointer(processMachine)), uintptr(unsafe.Pointer(nativeMachine))) + r1, _, e1 := syscall.SyscallN(procIsWow64Process2.Addr(), uintptr(handle), uintptr(unsafe.Pointer(processMachine)), uintptr(unsafe.Pointer(nativeMachine))) if r1 == 0 { err = errnoErr(e1) } @@ -2766,7 +2766,7 @@ func LoadLibraryEx(libname string, zero Handle, flags uintptr) (handle Handle, e } func _LoadLibraryEx(libname *uint16, zero Handle, flags uintptr) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall(procLoadLibraryExW.Addr(), 3, uintptr(unsafe.Pointer(libname)), uintptr(zero), uintptr(flags)) + r0, _, e1 := syscall.SyscallN(procLoadLibraryExW.Addr(), uintptr(unsafe.Pointer(libname)), uintptr(zero), uintptr(flags)) handle = Handle(r0) if handle == 0 { err = errnoErr(e1) @@ -2784,7 +2784,7 @@ func LoadLibrary(libname string) (handle Handle, err error) { } func _LoadLibrary(libname *uint16) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall(procLoadLibraryW.Addr(), 1, uintptr(unsafe.Pointer(libname)), 0, 0) + r0, _, e1 := syscall.SyscallN(procLoadLibraryW.Addr(), uintptr(unsafe.Pointer(libname))) handle = Handle(r0) if handle == 0 { err = errnoErr(e1) @@ -2793,7 +2793,7 @@ func _LoadLibrary(libname *uint16) (handle Handle, err error) { } func LoadResource(module Handle, resInfo Handle) (resData Handle, err error) { - r0, _, e1 := syscall.Syscall(procLoadResource.Addr(), 2, uintptr(module), uintptr(resInfo), 0) + r0, _, e1 := syscall.SyscallN(procLoadResource.Addr(), uintptr(module), uintptr(resInfo)) resData = Handle(r0) if resData == 0 { err = errnoErr(e1) @@ -2802,7 +2802,7 @@ func LoadResource(module Handle, resInfo Handle) (resData Handle, err error) { } func LocalAlloc(flags uint32, length uint32) (ptr uintptr, err error) { - r0, _, e1 := syscall.Syscall(procLocalAlloc.Addr(), 2, uintptr(flags), uintptr(length), 0) + r0, _, e1 := syscall.SyscallN(procLocalAlloc.Addr(), uintptr(flags), uintptr(length)) ptr = uintptr(r0) if ptr == 0 { err = errnoErr(e1) @@ -2811,7 +2811,7 @@ func LocalAlloc(flags uint32, length uint32) (ptr uintptr, err error) { } func LocalFree(hmem Handle) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall(procLocalFree.Addr(), 1, uintptr(hmem), 0, 0) + r0, _, e1 := syscall.SyscallN(procLocalFree.Addr(), uintptr(hmem)) handle = Handle(r0) if handle != 0 { err = errnoErr(e1) @@ -2820,7 +2820,7 @@ func LocalFree(hmem Handle) (handle Handle, err error) { } func LockFileEx(file Handle, flags uint32, reserved uint32, bytesLow uint32, bytesHigh uint32, overlapped *Overlapped) (err error) { - r1, _, e1 := syscall.Syscall6(procLockFileEx.Addr(), 6, uintptr(file), uintptr(flags), uintptr(reserved), uintptr(bytesLow), uintptr(bytesHigh), uintptr(unsafe.Pointer(overlapped))) + r1, _, e1 := syscall.SyscallN(procLockFileEx.Addr(), uintptr(file), uintptr(flags), uintptr(reserved), uintptr(bytesLow), uintptr(bytesHigh), uintptr(unsafe.Pointer(overlapped))) if r1 == 0 { err = errnoErr(e1) } @@ -2828,7 +2828,7 @@ func LockFileEx(file Handle, flags uint32, reserved uint32, bytesLow uint32, byt } func LockResource(resData Handle) (addr uintptr, err error) { - r0, _, e1 := syscall.Syscall(procLockResource.Addr(), 1, uintptr(resData), 0, 0) + r0, _, e1 := syscall.SyscallN(procLockResource.Addr(), uintptr(resData)) addr = uintptr(r0) if addr == 0 { err = errnoErr(e1) @@ -2837,7 +2837,7 @@ func LockResource(resData Handle) (addr uintptr, err error) { } func MapViewOfFile(handle Handle, access uint32, offsetHigh uint32, offsetLow uint32, length uintptr) (addr uintptr, err error) { - r0, _, e1 := syscall.Syscall6(procMapViewOfFile.Addr(), 5, uintptr(handle), uintptr(access), uintptr(offsetHigh), uintptr(offsetLow), uintptr(length), 0) + r0, _, e1 := syscall.SyscallN(procMapViewOfFile.Addr(), uintptr(handle), uintptr(access), uintptr(offsetHigh), uintptr(offsetLow), uintptr(length)) addr = uintptr(r0) if addr == 0 { err = errnoErr(e1) @@ -2846,7 +2846,7 @@ func MapViewOfFile(handle Handle, access uint32, offsetHigh uint32, offsetLow ui } func Module32First(snapshot Handle, moduleEntry *ModuleEntry32) (err error) { - r1, _, e1 := syscall.Syscall(procModule32FirstW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(moduleEntry)), 0) + r1, _, e1 := syscall.SyscallN(procModule32FirstW.Addr(), uintptr(snapshot), uintptr(unsafe.Pointer(moduleEntry))) if r1 == 0 { err = errnoErr(e1) } @@ -2854,7 +2854,7 @@ func Module32First(snapshot Handle, moduleEntry *ModuleEntry32) (err error) { } func Module32Next(snapshot Handle, moduleEntry *ModuleEntry32) (err error) { - r1, _, e1 := syscall.Syscall(procModule32NextW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(moduleEntry)), 0) + r1, _, e1 := syscall.SyscallN(procModule32NextW.Addr(), uintptr(snapshot), uintptr(unsafe.Pointer(moduleEntry))) if r1 == 0 { err = errnoErr(e1) } @@ -2862,7 +2862,7 @@ func Module32Next(snapshot Handle, moduleEntry *ModuleEntry32) (err error) { } func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) { - r1, _, e1 := syscall.Syscall(procMoveFileExW.Addr(), 3, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags)) + r1, _, e1 := syscall.SyscallN(procMoveFileExW.Addr(), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags)) if r1 == 0 { err = errnoErr(e1) } @@ -2870,7 +2870,7 @@ func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) { } func MoveFile(from *uint16, to *uint16) (err error) { - r1, _, e1 := syscall.Syscall(procMoveFileW.Addr(), 2, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), 0) + r1, _, e1 := syscall.SyscallN(procMoveFileW.Addr(), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to))) if r1 == 0 { err = errnoErr(e1) } @@ -2878,7 +2878,7 @@ func MoveFile(from *uint16, to *uint16) (err error) { } func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) { - r0, _, e1 := syscall.Syscall6(procMultiByteToWideChar.Addr(), 6, uintptr(codePage), uintptr(dwFlags), uintptr(unsafe.Pointer(str)), uintptr(nstr), uintptr(unsafe.Pointer(wchar)), uintptr(nwchar)) + r0, _, e1 := syscall.SyscallN(procMultiByteToWideChar.Addr(), uintptr(codePage), uintptr(dwFlags), uintptr(unsafe.Pointer(str)), uintptr(nstr), uintptr(unsafe.Pointer(wchar)), uintptr(nwchar)) nwrite = int32(r0) if nwrite == 0 { err = errnoErr(e1) @@ -2891,7 +2891,7 @@ func OpenEvent(desiredAccess uint32, inheritHandle bool, name *uint16) (handle H if inheritHandle { _p0 = 1 } - r0, _, e1 := syscall.Syscall(procOpenEventW.Addr(), 3, uintptr(desiredAccess), uintptr(_p0), uintptr(unsafe.Pointer(name))) + r0, _, e1 := syscall.SyscallN(procOpenEventW.Addr(), uintptr(desiredAccess), uintptr(_p0), uintptr(unsafe.Pointer(name))) handle = Handle(r0) if handle == 0 { err = errnoErr(e1) @@ -2904,7 +2904,7 @@ func OpenMutex(desiredAccess uint32, inheritHandle bool, name *uint16) (handle H if inheritHandle { _p0 = 1 } - r0, _, e1 := syscall.Syscall(procOpenMutexW.Addr(), 3, uintptr(desiredAccess), uintptr(_p0), uintptr(unsafe.Pointer(name))) + r0, _, e1 := syscall.SyscallN(procOpenMutexW.Addr(), uintptr(desiredAccess), uintptr(_p0), uintptr(unsafe.Pointer(name))) handle = Handle(r0) if handle == 0 { err = errnoErr(e1) @@ -2917,7 +2917,7 @@ func OpenProcess(desiredAccess uint32, inheritHandle bool, processId uint32) (ha if inheritHandle { _p0 = 1 } - r0, _, e1 := syscall.Syscall(procOpenProcess.Addr(), 3, uintptr(desiredAccess), uintptr(_p0), uintptr(processId)) + r0, _, e1 := syscall.SyscallN(procOpenProcess.Addr(), uintptr(desiredAccess), uintptr(_p0), uintptr(processId)) handle = Handle(r0) if handle == 0 { err = errnoErr(e1) @@ -2930,7 +2930,7 @@ func OpenThread(desiredAccess uint32, inheritHandle bool, threadId uint32) (hand if inheritHandle { _p0 = 1 } - r0, _, e1 := syscall.Syscall(procOpenThread.Addr(), 3, uintptr(desiredAccess), uintptr(_p0), uintptr(threadId)) + r0, _, e1 := syscall.SyscallN(procOpenThread.Addr(), uintptr(desiredAccess), uintptr(_p0), uintptr(threadId)) handle = Handle(r0) if handle == 0 { err = errnoErr(e1) @@ -2939,7 +2939,7 @@ func OpenThread(desiredAccess uint32, inheritHandle bool, threadId uint32) (hand } func PostQueuedCompletionStatus(cphandle Handle, qty uint32, key uintptr, overlapped *Overlapped) (err error) { - r1, _, e1 := syscall.Syscall6(procPostQueuedCompletionStatus.Addr(), 4, uintptr(cphandle), uintptr(qty), uintptr(key), uintptr(unsafe.Pointer(overlapped)), 0, 0) + r1, _, e1 := syscall.SyscallN(procPostQueuedCompletionStatus.Addr(), uintptr(cphandle), uintptr(qty), uintptr(key), uintptr(unsafe.Pointer(overlapped))) if r1 == 0 { err = errnoErr(e1) } @@ -2947,7 +2947,7 @@ func PostQueuedCompletionStatus(cphandle Handle, qty uint32, key uintptr, overla } func Process32First(snapshot Handle, procEntry *ProcessEntry32) (err error) { - r1, _, e1 := syscall.Syscall(procProcess32FirstW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0) + r1, _, e1 := syscall.SyscallN(procProcess32FirstW.Addr(), uintptr(snapshot), uintptr(unsafe.Pointer(procEntry))) if r1 == 0 { err = errnoErr(e1) } @@ -2955,7 +2955,7 @@ func Process32First(snapshot Handle, procEntry *ProcessEntry32) (err error) { } func Process32Next(snapshot Handle, procEntry *ProcessEntry32) (err error) { - r1, _, e1 := syscall.Syscall(procProcess32NextW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0) + r1, _, e1 := syscall.SyscallN(procProcess32NextW.Addr(), uintptr(snapshot), uintptr(unsafe.Pointer(procEntry))) if r1 == 0 { err = errnoErr(e1) } @@ -2963,7 +2963,7 @@ func Process32Next(snapshot Handle, procEntry *ProcessEntry32) (err error) { } func ProcessIdToSessionId(pid uint32, sessionid *uint32) (err error) { - r1, _, e1 := syscall.Syscall(procProcessIdToSessionId.Addr(), 2, uintptr(pid), uintptr(unsafe.Pointer(sessionid)), 0) + r1, _, e1 := syscall.SyscallN(procProcessIdToSessionId.Addr(), uintptr(pid), uintptr(unsafe.Pointer(sessionid))) if r1 == 0 { err = errnoErr(e1) } @@ -2971,7 +2971,7 @@ func ProcessIdToSessionId(pid uint32, sessionid *uint32) (err error) { } func PulseEvent(event Handle) (err error) { - r1, _, e1 := syscall.Syscall(procPulseEvent.Addr(), 1, uintptr(event), 0, 0) + r1, _, e1 := syscall.SyscallN(procPulseEvent.Addr(), uintptr(event)) if r1 == 0 { err = errnoErr(e1) } @@ -2979,7 +2979,7 @@ func PulseEvent(event Handle) (err error) { } func PurgeComm(handle Handle, dwFlags uint32) (err error) { - r1, _, e1 := syscall.Syscall(procPurgeComm.Addr(), 2, uintptr(handle), uintptr(dwFlags), 0) + r1, _, e1 := syscall.SyscallN(procPurgeComm.Addr(), uintptr(handle), uintptr(dwFlags)) if r1 == 0 { err = errnoErr(e1) } @@ -2987,7 +2987,7 @@ func PurgeComm(handle Handle, dwFlags uint32) (err error) { } func QueryDosDevice(deviceName *uint16, targetPath *uint16, max uint32) (n uint32, err error) { - r0, _, e1 := syscall.Syscall(procQueryDosDeviceW.Addr(), 3, uintptr(unsafe.Pointer(deviceName)), uintptr(unsafe.Pointer(targetPath)), uintptr(max)) + r0, _, e1 := syscall.SyscallN(procQueryDosDeviceW.Addr(), uintptr(unsafe.Pointer(deviceName)), uintptr(unsafe.Pointer(targetPath)), uintptr(max)) n = uint32(r0) if n == 0 { err = errnoErr(e1) @@ -2996,7 +2996,7 @@ func QueryDosDevice(deviceName *uint16, targetPath *uint16, max uint32) (n uint3 } func QueryFullProcessImageName(proc Handle, flags uint32, exeName *uint16, size *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procQueryFullProcessImageNameW.Addr(), 4, uintptr(proc), uintptr(flags), uintptr(unsafe.Pointer(exeName)), uintptr(unsafe.Pointer(size)), 0, 0) + r1, _, e1 := syscall.SyscallN(procQueryFullProcessImageNameW.Addr(), uintptr(proc), uintptr(flags), uintptr(unsafe.Pointer(exeName)), uintptr(unsafe.Pointer(size))) if r1 == 0 { err = errnoErr(e1) } @@ -3004,7 +3004,7 @@ func QueryFullProcessImageName(proc Handle, flags uint32, exeName *uint16, size } func QueryInformationJobObject(job Handle, JobObjectInformationClass int32, JobObjectInformation uintptr, JobObjectInformationLength uint32, retlen *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procQueryInformationJobObject.Addr(), 5, uintptr(job), uintptr(JobObjectInformationClass), uintptr(JobObjectInformation), uintptr(JobObjectInformationLength), uintptr(unsafe.Pointer(retlen)), 0) + r1, _, e1 := syscall.SyscallN(procQueryInformationJobObject.Addr(), uintptr(job), uintptr(JobObjectInformationClass), uintptr(JobObjectInformation), uintptr(JobObjectInformationLength), uintptr(unsafe.Pointer(retlen))) if r1 == 0 { err = errnoErr(e1) } @@ -3012,7 +3012,7 @@ func QueryInformationJobObject(job Handle, JobObjectInformationClass int32, JobO } func ReadConsole(console Handle, buf *uint16, toread uint32, read *uint32, inputControl *byte) (err error) { - r1, _, e1 := syscall.Syscall6(procReadConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(toread), uintptr(unsafe.Pointer(read)), uintptr(unsafe.Pointer(inputControl)), 0) + r1, _, e1 := syscall.SyscallN(procReadConsoleW.Addr(), uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(toread), uintptr(unsafe.Pointer(read)), uintptr(unsafe.Pointer(inputControl))) if r1 == 0 { err = errnoErr(e1) } @@ -3024,7 +3024,7 @@ func ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree if watchSubTree { _p0 = 1 } - r1, _, e1 := syscall.Syscall9(procReadDirectoryChangesW.Addr(), 8, uintptr(handle), uintptr(unsafe.Pointer(buf)), uintptr(buflen), uintptr(_p0), uintptr(mask), uintptr(unsafe.Pointer(retlen)), uintptr(unsafe.Pointer(overlapped)), uintptr(completionRoutine), 0) + r1, _, e1 := syscall.SyscallN(procReadDirectoryChangesW.Addr(), uintptr(handle), uintptr(unsafe.Pointer(buf)), uintptr(buflen), uintptr(_p0), uintptr(mask), uintptr(unsafe.Pointer(retlen)), uintptr(unsafe.Pointer(overlapped)), uintptr(completionRoutine)) if r1 == 0 { err = errnoErr(e1) } @@ -3036,7 +3036,7 @@ func readFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) ( if len(buf) > 0 { _p0 = &buf[0] } - r1, _, e1 := syscall.Syscall6(procReadFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0) + r1, _, e1 := syscall.SyscallN(procReadFile.Addr(), uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped))) if r1 == 0 { err = errnoErr(e1) } @@ -3044,7 +3044,7 @@ func readFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) ( } func ReadProcessMemory(process Handle, baseAddress uintptr, buffer *byte, size uintptr, numberOfBytesRead *uintptr) (err error) { - r1, _, e1 := syscall.Syscall6(procReadProcessMemory.Addr(), 5, uintptr(process), uintptr(baseAddress), uintptr(unsafe.Pointer(buffer)), uintptr(size), uintptr(unsafe.Pointer(numberOfBytesRead)), 0) + r1, _, e1 := syscall.SyscallN(procReadProcessMemory.Addr(), uintptr(process), uintptr(baseAddress), uintptr(unsafe.Pointer(buffer)), uintptr(size), uintptr(unsafe.Pointer(numberOfBytesRead))) if r1 == 0 { err = errnoErr(e1) } @@ -3052,7 +3052,7 @@ func ReadProcessMemory(process Handle, baseAddress uintptr, buffer *byte, size u } func ReleaseMutex(mutex Handle) (err error) { - r1, _, e1 := syscall.Syscall(procReleaseMutex.Addr(), 1, uintptr(mutex), 0, 0) + r1, _, e1 := syscall.SyscallN(procReleaseMutex.Addr(), uintptr(mutex)) if r1 == 0 { err = errnoErr(e1) } @@ -3060,7 +3060,7 @@ func ReleaseMutex(mutex Handle) (err error) { } func RemoveDirectory(path *uint16) (err error) { - r1, _, e1 := syscall.Syscall(procRemoveDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0) + r1, _, e1 := syscall.SyscallN(procRemoveDirectoryW.Addr(), uintptr(unsafe.Pointer(path))) if r1 == 0 { err = errnoErr(e1) } @@ -3068,7 +3068,7 @@ func RemoveDirectory(path *uint16) (err error) { } func RemoveDllDirectory(cookie uintptr) (err error) { - r1, _, e1 := syscall.Syscall(procRemoveDllDirectory.Addr(), 1, uintptr(cookie), 0, 0) + r1, _, e1 := syscall.SyscallN(procRemoveDllDirectory.Addr(), uintptr(cookie)) if r1 == 0 { err = errnoErr(e1) } @@ -3076,7 +3076,7 @@ func RemoveDllDirectory(cookie uintptr) (err error) { } func ResetEvent(event Handle) (err error) { - r1, _, e1 := syscall.Syscall(procResetEvent.Addr(), 1, uintptr(event), 0, 0) + r1, _, e1 := syscall.SyscallN(procResetEvent.Addr(), uintptr(event)) if r1 == 0 { err = errnoErr(e1) } @@ -3084,7 +3084,7 @@ func ResetEvent(event Handle) (err error) { } func resizePseudoConsole(pconsole Handle, size uint32) (hr error) { - r0, _, _ := syscall.Syscall(procResizePseudoConsole.Addr(), 2, uintptr(pconsole), uintptr(size), 0) + r0, _, _ := syscall.SyscallN(procResizePseudoConsole.Addr(), uintptr(pconsole), uintptr(size)) if r0 != 0 { hr = syscall.Errno(r0) } @@ -3092,7 +3092,7 @@ func resizePseudoConsole(pconsole Handle, size uint32) (hr error) { } func ResumeThread(thread Handle) (ret uint32, err error) { - r0, _, e1 := syscall.Syscall(procResumeThread.Addr(), 1, uintptr(thread), 0, 0) + r0, _, e1 := syscall.SyscallN(procResumeThread.Addr(), uintptr(thread)) ret = uint32(r0) if ret == 0xffffffff { err = errnoErr(e1) @@ -3101,7 +3101,7 @@ func ResumeThread(thread Handle) (ret uint32, err error) { } func SetCommBreak(handle Handle) (err error) { - r1, _, e1 := syscall.Syscall(procSetCommBreak.Addr(), 1, uintptr(handle), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetCommBreak.Addr(), uintptr(handle)) if r1 == 0 { err = errnoErr(e1) } @@ -3109,7 +3109,7 @@ func SetCommBreak(handle Handle) (err error) { } func SetCommMask(handle Handle, dwEvtMask uint32) (err error) { - r1, _, e1 := syscall.Syscall(procSetCommMask.Addr(), 2, uintptr(handle), uintptr(dwEvtMask), 0) + r1, _, e1 := syscall.SyscallN(procSetCommMask.Addr(), uintptr(handle), uintptr(dwEvtMask)) if r1 == 0 { err = errnoErr(e1) } @@ -3117,7 +3117,7 @@ func SetCommMask(handle Handle, dwEvtMask uint32) (err error) { } func SetCommState(handle Handle, lpDCB *DCB) (err error) { - r1, _, e1 := syscall.Syscall(procSetCommState.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(lpDCB)), 0) + r1, _, e1 := syscall.SyscallN(procSetCommState.Addr(), uintptr(handle), uintptr(unsafe.Pointer(lpDCB))) if r1 == 0 { err = errnoErr(e1) } @@ -3125,7 +3125,7 @@ func SetCommState(handle Handle, lpDCB *DCB) (err error) { } func SetCommTimeouts(handle Handle, timeouts *CommTimeouts) (err error) { - r1, _, e1 := syscall.Syscall(procSetCommTimeouts.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(timeouts)), 0) + r1, _, e1 := syscall.SyscallN(procSetCommTimeouts.Addr(), uintptr(handle), uintptr(unsafe.Pointer(timeouts))) if r1 == 0 { err = errnoErr(e1) } @@ -3133,7 +3133,7 @@ func SetCommTimeouts(handle Handle, timeouts *CommTimeouts) (err error) { } func SetConsoleCP(cp uint32) (err error) { - r1, _, e1 := syscall.Syscall(procSetConsoleCP.Addr(), 1, uintptr(cp), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetConsoleCP.Addr(), uintptr(cp)) if r1 == 0 { err = errnoErr(e1) } @@ -3141,7 +3141,7 @@ func SetConsoleCP(cp uint32) (err error) { } func setConsoleCursorPosition(console Handle, position uint32) (err error) { - r1, _, e1 := syscall.Syscall(procSetConsoleCursorPosition.Addr(), 2, uintptr(console), uintptr(position), 0) + r1, _, e1 := syscall.SyscallN(procSetConsoleCursorPosition.Addr(), uintptr(console), uintptr(position)) if r1 == 0 { err = errnoErr(e1) } @@ -3149,7 +3149,7 @@ func setConsoleCursorPosition(console Handle, position uint32) (err error) { } func SetConsoleMode(console Handle, mode uint32) (err error) { - r1, _, e1 := syscall.Syscall(procSetConsoleMode.Addr(), 2, uintptr(console), uintptr(mode), 0) + r1, _, e1 := syscall.SyscallN(procSetConsoleMode.Addr(), uintptr(console), uintptr(mode)) if r1 == 0 { err = errnoErr(e1) } @@ -3157,7 +3157,7 @@ func SetConsoleMode(console Handle, mode uint32) (err error) { } func SetConsoleOutputCP(cp uint32) (err error) { - r1, _, e1 := syscall.Syscall(procSetConsoleOutputCP.Addr(), 1, uintptr(cp), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetConsoleOutputCP.Addr(), uintptr(cp)) if r1 == 0 { err = errnoErr(e1) } @@ -3165,7 +3165,7 @@ func SetConsoleOutputCP(cp uint32) (err error) { } func SetCurrentDirectory(path *uint16) (err error) { - r1, _, e1 := syscall.Syscall(procSetCurrentDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetCurrentDirectoryW.Addr(), uintptr(unsafe.Pointer(path))) if r1 == 0 { err = errnoErr(e1) } @@ -3173,7 +3173,7 @@ func SetCurrentDirectory(path *uint16) (err error) { } func SetDefaultDllDirectories(directoryFlags uint32) (err error) { - r1, _, e1 := syscall.Syscall(procSetDefaultDllDirectories.Addr(), 1, uintptr(directoryFlags), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetDefaultDllDirectories.Addr(), uintptr(directoryFlags)) if r1 == 0 { err = errnoErr(e1) } @@ -3190,7 +3190,7 @@ func SetDllDirectory(path string) (err error) { } func _SetDllDirectory(path *uint16) (err error) { - r1, _, e1 := syscall.Syscall(procSetDllDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetDllDirectoryW.Addr(), uintptr(unsafe.Pointer(path))) if r1 == 0 { err = errnoErr(e1) } @@ -3198,7 +3198,7 @@ func _SetDllDirectory(path *uint16) (err error) { } func SetEndOfFile(handle Handle) (err error) { - r1, _, e1 := syscall.Syscall(procSetEndOfFile.Addr(), 1, uintptr(handle), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetEndOfFile.Addr(), uintptr(handle)) if r1 == 0 { err = errnoErr(e1) } @@ -3206,7 +3206,7 @@ func SetEndOfFile(handle Handle) (err error) { } func SetEnvironmentVariable(name *uint16, value *uint16) (err error) { - r1, _, e1 := syscall.Syscall(procSetEnvironmentVariableW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(value)), 0) + r1, _, e1 := syscall.SyscallN(procSetEnvironmentVariableW.Addr(), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(value))) if r1 == 0 { err = errnoErr(e1) } @@ -3214,13 +3214,13 @@ func SetEnvironmentVariable(name *uint16, value *uint16) (err error) { } func SetErrorMode(mode uint32) (ret uint32) { - r0, _, _ := syscall.Syscall(procSetErrorMode.Addr(), 1, uintptr(mode), 0, 0) + r0, _, _ := syscall.SyscallN(procSetErrorMode.Addr(), uintptr(mode)) ret = uint32(r0) return } func SetEvent(event Handle) (err error) { - r1, _, e1 := syscall.Syscall(procSetEvent.Addr(), 1, uintptr(event), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetEvent.Addr(), uintptr(event)) if r1 == 0 { err = errnoErr(e1) } @@ -3228,7 +3228,7 @@ func SetEvent(event Handle) (err error) { } func SetFileAttributes(name *uint16, attrs uint32) (err error) { - r1, _, e1 := syscall.Syscall(procSetFileAttributesW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(attrs), 0) + r1, _, e1 := syscall.SyscallN(procSetFileAttributesW.Addr(), uintptr(unsafe.Pointer(name)), uintptr(attrs)) if r1 == 0 { err = errnoErr(e1) } @@ -3236,7 +3236,7 @@ func SetFileAttributes(name *uint16, attrs uint32) (err error) { } func SetFileCompletionNotificationModes(handle Handle, flags uint8) (err error) { - r1, _, e1 := syscall.Syscall(procSetFileCompletionNotificationModes.Addr(), 2, uintptr(handle), uintptr(flags), 0) + r1, _, e1 := syscall.SyscallN(procSetFileCompletionNotificationModes.Addr(), uintptr(handle), uintptr(flags)) if r1 == 0 { err = errnoErr(e1) } @@ -3244,7 +3244,7 @@ func SetFileCompletionNotificationModes(handle Handle, flags uint8) (err error) } func SetFileInformationByHandle(handle Handle, class uint32, inBuffer *byte, inBufferLen uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procSetFileInformationByHandle.Addr(), 4, uintptr(handle), uintptr(class), uintptr(unsafe.Pointer(inBuffer)), uintptr(inBufferLen), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetFileInformationByHandle.Addr(), uintptr(handle), uintptr(class), uintptr(unsafe.Pointer(inBuffer)), uintptr(inBufferLen)) if r1 == 0 { err = errnoErr(e1) } @@ -3252,7 +3252,7 @@ func SetFileInformationByHandle(handle Handle, class uint32, inBuffer *byte, inB } func SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, err error) { - r0, _, e1 := syscall.Syscall6(procSetFilePointer.Addr(), 4, uintptr(handle), uintptr(lowoffset), uintptr(unsafe.Pointer(highoffsetptr)), uintptr(whence), 0, 0) + r0, _, e1 := syscall.SyscallN(procSetFilePointer.Addr(), uintptr(handle), uintptr(lowoffset), uintptr(unsafe.Pointer(highoffsetptr)), uintptr(whence)) newlowoffset = uint32(r0) if newlowoffset == 0xffffffff { err = errnoErr(e1) @@ -3261,7 +3261,7 @@ func SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence } func SetFileTime(handle Handle, ctime *Filetime, atime *Filetime, wtime *Filetime) (err error) { - r1, _, e1 := syscall.Syscall6(procSetFileTime.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(ctime)), uintptr(unsafe.Pointer(atime)), uintptr(unsafe.Pointer(wtime)), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetFileTime.Addr(), uintptr(handle), uintptr(unsafe.Pointer(ctime)), uintptr(unsafe.Pointer(atime)), uintptr(unsafe.Pointer(wtime))) if r1 == 0 { err = errnoErr(e1) } @@ -3269,7 +3269,7 @@ func SetFileTime(handle Handle, ctime *Filetime, atime *Filetime, wtime *Filetim } func SetFileValidData(handle Handle, validDataLength int64) (err error) { - r1, _, e1 := syscall.Syscall(procSetFileValidData.Addr(), 2, uintptr(handle), uintptr(validDataLength), 0) + r1, _, e1 := syscall.SyscallN(procSetFileValidData.Addr(), uintptr(handle), uintptr(validDataLength)) if r1 == 0 { err = errnoErr(e1) } @@ -3277,7 +3277,7 @@ func SetFileValidData(handle Handle, validDataLength int64) (err error) { } func SetHandleInformation(handle Handle, mask uint32, flags uint32) (err error) { - r1, _, e1 := syscall.Syscall(procSetHandleInformation.Addr(), 3, uintptr(handle), uintptr(mask), uintptr(flags)) + r1, _, e1 := syscall.SyscallN(procSetHandleInformation.Addr(), uintptr(handle), uintptr(mask), uintptr(flags)) if r1 == 0 { err = errnoErr(e1) } @@ -3285,7 +3285,7 @@ func SetHandleInformation(handle Handle, mask uint32, flags uint32) (err error) } func SetInformationJobObject(job Handle, JobObjectInformationClass uint32, JobObjectInformation uintptr, JobObjectInformationLength uint32) (ret int, err error) { - r0, _, e1 := syscall.Syscall6(procSetInformationJobObject.Addr(), 4, uintptr(job), uintptr(JobObjectInformationClass), uintptr(JobObjectInformation), uintptr(JobObjectInformationLength), 0, 0) + r0, _, e1 := syscall.SyscallN(procSetInformationJobObject.Addr(), uintptr(job), uintptr(JobObjectInformationClass), uintptr(JobObjectInformation), uintptr(JobObjectInformationLength)) ret = int(r0) if ret == 0 { err = errnoErr(e1) @@ -3294,7 +3294,7 @@ func SetInformationJobObject(job Handle, JobObjectInformationClass uint32, JobOb } func SetNamedPipeHandleState(pipe Handle, state *uint32, maxCollectionCount *uint32, collectDataTimeout *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procSetNamedPipeHandleState.Addr(), 4, uintptr(pipe), uintptr(unsafe.Pointer(state)), uintptr(unsafe.Pointer(maxCollectionCount)), uintptr(unsafe.Pointer(collectDataTimeout)), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetNamedPipeHandleState.Addr(), uintptr(pipe), uintptr(unsafe.Pointer(state)), uintptr(unsafe.Pointer(maxCollectionCount)), uintptr(unsafe.Pointer(collectDataTimeout))) if r1 == 0 { err = errnoErr(e1) } @@ -3302,7 +3302,7 @@ func SetNamedPipeHandleState(pipe Handle, state *uint32, maxCollectionCount *uin } func SetPriorityClass(process Handle, priorityClass uint32) (err error) { - r1, _, e1 := syscall.Syscall(procSetPriorityClass.Addr(), 2, uintptr(process), uintptr(priorityClass), 0) + r1, _, e1 := syscall.SyscallN(procSetPriorityClass.Addr(), uintptr(process), uintptr(priorityClass)) if r1 == 0 { err = errnoErr(e1) } @@ -3314,7 +3314,7 @@ func SetProcessPriorityBoost(process Handle, disable bool) (err error) { if disable { _p0 = 1 } - r1, _, e1 := syscall.Syscall(procSetProcessPriorityBoost.Addr(), 2, uintptr(process), uintptr(_p0), 0) + r1, _, e1 := syscall.SyscallN(procSetProcessPriorityBoost.Addr(), uintptr(process), uintptr(_p0)) if r1 == 0 { err = errnoErr(e1) } @@ -3322,7 +3322,7 @@ func SetProcessPriorityBoost(process Handle, disable bool) (err error) { } func SetProcessShutdownParameters(level uint32, flags uint32) (err error) { - r1, _, e1 := syscall.Syscall(procSetProcessShutdownParameters.Addr(), 2, uintptr(level), uintptr(flags), 0) + r1, _, e1 := syscall.SyscallN(procSetProcessShutdownParameters.Addr(), uintptr(level), uintptr(flags)) if r1 == 0 { err = errnoErr(e1) } @@ -3330,7 +3330,7 @@ func SetProcessShutdownParameters(level uint32, flags uint32) (err error) { } func SetProcessWorkingSetSizeEx(hProcess Handle, dwMinimumWorkingSetSize uintptr, dwMaximumWorkingSetSize uintptr, flags uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procSetProcessWorkingSetSizeEx.Addr(), 4, uintptr(hProcess), uintptr(dwMinimumWorkingSetSize), uintptr(dwMaximumWorkingSetSize), uintptr(flags), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetProcessWorkingSetSizeEx.Addr(), uintptr(hProcess), uintptr(dwMinimumWorkingSetSize), uintptr(dwMaximumWorkingSetSize), uintptr(flags)) if r1 == 0 { err = errnoErr(e1) } @@ -3338,7 +3338,7 @@ func SetProcessWorkingSetSizeEx(hProcess Handle, dwMinimumWorkingSetSize uintptr } func SetStdHandle(stdhandle uint32, handle Handle) (err error) { - r1, _, e1 := syscall.Syscall(procSetStdHandle.Addr(), 2, uintptr(stdhandle), uintptr(handle), 0) + r1, _, e1 := syscall.SyscallN(procSetStdHandle.Addr(), uintptr(stdhandle), uintptr(handle)) if r1 == 0 { err = errnoErr(e1) } @@ -3346,7 +3346,7 @@ func SetStdHandle(stdhandle uint32, handle Handle) (err error) { } func SetVolumeLabel(rootPathName *uint16, volumeName *uint16) (err error) { - r1, _, e1 := syscall.Syscall(procSetVolumeLabelW.Addr(), 2, uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeName)), 0) + r1, _, e1 := syscall.SyscallN(procSetVolumeLabelW.Addr(), uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeName))) if r1 == 0 { err = errnoErr(e1) } @@ -3354,7 +3354,7 @@ func SetVolumeLabel(rootPathName *uint16, volumeName *uint16) (err error) { } func SetVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16) (err error) { - r1, _, e1 := syscall.Syscall(procSetVolumeMountPointW.Addr(), 2, uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(unsafe.Pointer(volumeName)), 0) + r1, _, e1 := syscall.SyscallN(procSetVolumeMountPointW.Addr(), uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(unsafe.Pointer(volumeName))) if r1 == 0 { err = errnoErr(e1) } @@ -3362,7 +3362,7 @@ func SetVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16) (err erro } func SetupComm(handle Handle, dwInQueue uint32, dwOutQueue uint32) (err error) { - r1, _, e1 := syscall.Syscall(procSetupComm.Addr(), 3, uintptr(handle), uintptr(dwInQueue), uintptr(dwOutQueue)) + r1, _, e1 := syscall.SyscallN(procSetupComm.Addr(), uintptr(handle), uintptr(dwInQueue), uintptr(dwOutQueue)) if r1 == 0 { err = errnoErr(e1) } @@ -3370,7 +3370,7 @@ func SetupComm(handle Handle, dwInQueue uint32, dwOutQueue uint32) (err error) { } func SizeofResource(module Handle, resInfo Handle) (size uint32, err error) { - r0, _, e1 := syscall.Syscall(procSizeofResource.Addr(), 2, uintptr(module), uintptr(resInfo), 0) + r0, _, e1 := syscall.SyscallN(procSizeofResource.Addr(), uintptr(module), uintptr(resInfo)) size = uint32(r0) if size == 0 { err = errnoErr(e1) @@ -3383,13 +3383,13 @@ func SleepEx(milliseconds uint32, alertable bool) (ret uint32) { if alertable { _p0 = 1 } - r0, _, _ := syscall.Syscall(procSleepEx.Addr(), 2, uintptr(milliseconds), uintptr(_p0), 0) + r0, _, _ := syscall.SyscallN(procSleepEx.Addr(), uintptr(milliseconds), uintptr(_p0)) ret = uint32(r0) return } func TerminateJobObject(job Handle, exitCode uint32) (err error) { - r1, _, e1 := syscall.Syscall(procTerminateJobObject.Addr(), 2, uintptr(job), uintptr(exitCode), 0) + r1, _, e1 := syscall.SyscallN(procTerminateJobObject.Addr(), uintptr(job), uintptr(exitCode)) if r1 == 0 { err = errnoErr(e1) } @@ -3397,7 +3397,7 @@ func TerminateJobObject(job Handle, exitCode uint32) (err error) { } func TerminateProcess(handle Handle, exitcode uint32) (err error) { - r1, _, e1 := syscall.Syscall(procTerminateProcess.Addr(), 2, uintptr(handle), uintptr(exitcode), 0) + r1, _, e1 := syscall.SyscallN(procTerminateProcess.Addr(), uintptr(handle), uintptr(exitcode)) if r1 == 0 { err = errnoErr(e1) } @@ -3405,7 +3405,7 @@ func TerminateProcess(handle Handle, exitcode uint32) (err error) { } func Thread32First(snapshot Handle, threadEntry *ThreadEntry32) (err error) { - r1, _, e1 := syscall.Syscall(procThread32First.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(threadEntry)), 0) + r1, _, e1 := syscall.SyscallN(procThread32First.Addr(), uintptr(snapshot), uintptr(unsafe.Pointer(threadEntry))) if r1 == 0 { err = errnoErr(e1) } @@ -3413,7 +3413,7 @@ func Thread32First(snapshot Handle, threadEntry *ThreadEntry32) (err error) { } func Thread32Next(snapshot Handle, threadEntry *ThreadEntry32) (err error) { - r1, _, e1 := syscall.Syscall(procThread32Next.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(threadEntry)), 0) + r1, _, e1 := syscall.SyscallN(procThread32Next.Addr(), uintptr(snapshot), uintptr(unsafe.Pointer(threadEntry))) if r1 == 0 { err = errnoErr(e1) } @@ -3421,7 +3421,7 @@ func Thread32Next(snapshot Handle, threadEntry *ThreadEntry32) (err error) { } func UnlockFileEx(file Handle, reserved uint32, bytesLow uint32, bytesHigh uint32, overlapped *Overlapped) (err error) { - r1, _, e1 := syscall.Syscall6(procUnlockFileEx.Addr(), 5, uintptr(file), uintptr(reserved), uintptr(bytesLow), uintptr(bytesHigh), uintptr(unsafe.Pointer(overlapped)), 0) + r1, _, e1 := syscall.SyscallN(procUnlockFileEx.Addr(), uintptr(file), uintptr(reserved), uintptr(bytesLow), uintptr(bytesHigh), uintptr(unsafe.Pointer(overlapped))) if r1 == 0 { err = errnoErr(e1) } @@ -3429,7 +3429,7 @@ func UnlockFileEx(file Handle, reserved uint32, bytesLow uint32, bytesHigh uint3 } func UnmapViewOfFile(addr uintptr) (err error) { - r1, _, e1 := syscall.Syscall(procUnmapViewOfFile.Addr(), 1, uintptr(addr), 0, 0) + r1, _, e1 := syscall.SyscallN(procUnmapViewOfFile.Addr(), uintptr(addr)) if r1 == 0 { err = errnoErr(e1) } @@ -3437,7 +3437,7 @@ func UnmapViewOfFile(addr uintptr) (err error) { } func updateProcThreadAttribute(attrlist *ProcThreadAttributeList, flags uint32, attr uintptr, value unsafe.Pointer, size uintptr, prevvalue unsafe.Pointer, returnedsize *uintptr) (err error) { - r1, _, e1 := syscall.Syscall9(procUpdateProcThreadAttribute.Addr(), 7, uintptr(unsafe.Pointer(attrlist)), uintptr(flags), uintptr(attr), uintptr(value), uintptr(size), uintptr(prevvalue), uintptr(unsafe.Pointer(returnedsize)), 0, 0) + r1, _, e1 := syscall.SyscallN(procUpdateProcThreadAttribute.Addr(), uintptr(unsafe.Pointer(attrlist)), uintptr(flags), uintptr(attr), uintptr(value), uintptr(size), uintptr(prevvalue), uintptr(unsafe.Pointer(returnedsize))) if r1 == 0 { err = errnoErr(e1) } @@ -3445,7 +3445,7 @@ func updateProcThreadAttribute(attrlist *ProcThreadAttributeList, flags uint32, } func VirtualAlloc(address uintptr, size uintptr, alloctype uint32, protect uint32) (value uintptr, err error) { - r0, _, e1 := syscall.Syscall6(procVirtualAlloc.Addr(), 4, uintptr(address), uintptr(size), uintptr(alloctype), uintptr(protect), 0, 0) + r0, _, e1 := syscall.SyscallN(procVirtualAlloc.Addr(), uintptr(address), uintptr(size), uintptr(alloctype), uintptr(protect)) value = uintptr(r0) if value == 0 { err = errnoErr(e1) @@ -3454,7 +3454,7 @@ func VirtualAlloc(address uintptr, size uintptr, alloctype uint32, protect uint3 } func VirtualFree(address uintptr, size uintptr, freetype uint32) (err error) { - r1, _, e1 := syscall.Syscall(procVirtualFree.Addr(), 3, uintptr(address), uintptr(size), uintptr(freetype)) + r1, _, e1 := syscall.SyscallN(procVirtualFree.Addr(), uintptr(address), uintptr(size), uintptr(freetype)) if r1 == 0 { err = errnoErr(e1) } @@ -3462,7 +3462,7 @@ func VirtualFree(address uintptr, size uintptr, freetype uint32) (err error) { } func VirtualLock(addr uintptr, length uintptr) (err error) { - r1, _, e1 := syscall.Syscall(procVirtualLock.Addr(), 2, uintptr(addr), uintptr(length), 0) + r1, _, e1 := syscall.SyscallN(procVirtualLock.Addr(), uintptr(addr), uintptr(length)) if r1 == 0 { err = errnoErr(e1) } @@ -3470,7 +3470,7 @@ func VirtualLock(addr uintptr, length uintptr) (err error) { } func VirtualProtect(address uintptr, size uintptr, newprotect uint32, oldprotect *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procVirtualProtect.Addr(), 4, uintptr(address), uintptr(size), uintptr(newprotect), uintptr(unsafe.Pointer(oldprotect)), 0, 0) + r1, _, e1 := syscall.SyscallN(procVirtualProtect.Addr(), uintptr(address), uintptr(size), uintptr(newprotect), uintptr(unsafe.Pointer(oldprotect))) if r1 == 0 { err = errnoErr(e1) } @@ -3478,7 +3478,7 @@ func VirtualProtect(address uintptr, size uintptr, newprotect uint32, oldprotect } func VirtualProtectEx(process Handle, address uintptr, size uintptr, newProtect uint32, oldProtect *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procVirtualProtectEx.Addr(), 5, uintptr(process), uintptr(address), uintptr(size), uintptr(newProtect), uintptr(unsafe.Pointer(oldProtect)), 0) + r1, _, e1 := syscall.SyscallN(procVirtualProtectEx.Addr(), uintptr(process), uintptr(address), uintptr(size), uintptr(newProtect), uintptr(unsafe.Pointer(oldProtect))) if r1 == 0 { err = errnoErr(e1) } @@ -3486,7 +3486,7 @@ func VirtualProtectEx(process Handle, address uintptr, size uintptr, newProtect } func VirtualQuery(address uintptr, buffer *MemoryBasicInformation, length uintptr) (err error) { - r1, _, e1 := syscall.Syscall(procVirtualQuery.Addr(), 3, uintptr(address), uintptr(unsafe.Pointer(buffer)), uintptr(length)) + r1, _, e1 := syscall.SyscallN(procVirtualQuery.Addr(), uintptr(address), uintptr(unsafe.Pointer(buffer)), uintptr(length)) if r1 == 0 { err = errnoErr(e1) } @@ -3494,7 +3494,7 @@ func VirtualQuery(address uintptr, buffer *MemoryBasicInformation, length uintpt } func VirtualQueryEx(process Handle, address uintptr, buffer *MemoryBasicInformation, length uintptr) (err error) { - r1, _, e1 := syscall.Syscall6(procVirtualQueryEx.Addr(), 4, uintptr(process), uintptr(address), uintptr(unsafe.Pointer(buffer)), uintptr(length), 0, 0) + r1, _, e1 := syscall.SyscallN(procVirtualQueryEx.Addr(), uintptr(process), uintptr(address), uintptr(unsafe.Pointer(buffer)), uintptr(length)) if r1 == 0 { err = errnoErr(e1) } @@ -3502,7 +3502,7 @@ func VirtualQueryEx(process Handle, address uintptr, buffer *MemoryBasicInformat } func VirtualUnlock(addr uintptr, length uintptr) (err error) { - r1, _, e1 := syscall.Syscall(procVirtualUnlock.Addr(), 2, uintptr(addr), uintptr(length), 0) + r1, _, e1 := syscall.SyscallN(procVirtualUnlock.Addr(), uintptr(addr), uintptr(length)) if r1 == 0 { err = errnoErr(e1) } @@ -3510,13 +3510,13 @@ func VirtualUnlock(addr uintptr, length uintptr) (err error) { } func WTSGetActiveConsoleSessionId() (sessionID uint32) { - r0, _, _ := syscall.Syscall(procWTSGetActiveConsoleSessionId.Addr(), 0, 0, 0, 0) + r0, _, _ := syscall.SyscallN(procWTSGetActiveConsoleSessionId.Addr()) sessionID = uint32(r0) return } func WaitCommEvent(handle Handle, lpEvtMask *uint32, lpOverlapped *Overlapped) (err error) { - r1, _, e1 := syscall.Syscall(procWaitCommEvent.Addr(), 3, uintptr(handle), uintptr(unsafe.Pointer(lpEvtMask)), uintptr(unsafe.Pointer(lpOverlapped))) + r1, _, e1 := syscall.SyscallN(procWaitCommEvent.Addr(), uintptr(handle), uintptr(unsafe.Pointer(lpEvtMask)), uintptr(unsafe.Pointer(lpOverlapped))) if r1 == 0 { err = errnoErr(e1) } @@ -3528,7 +3528,7 @@ func waitForMultipleObjects(count uint32, handles uintptr, waitAll bool, waitMil if waitAll { _p0 = 1 } - r0, _, e1 := syscall.Syscall6(procWaitForMultipleObjects.Addr(), 4, uintptr(count), uintptr(handles), uintptr(_p0), uintptr(waitMilliseconds), 0, 0) + r0, _, e1 := syscall.SyscallN(procWaitForMultipleObjects.Addr(), uintptr(count), uintptr(handles), uintptr(_p0), uintptr(waitMilliseconds)) event = uint32(r0) if event == 0xffffffff { err = errnoErr(e1) @@ -3537,7 +3537,7 @@ func waitForMultipleObjects(count uint32, handles uintptr, waitAll bool, waitMil } func WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32, err error) { - r0, _, e1 := syscall.Syscall(procWaitForSingleObject.Addr(), 2, uintptr(handle), uintptr(waitMilliseconds), 0) + r0, _, e1 := syscall.SyscallN(procWaitForSingleObject.Addr(), uintptr(handle), uintptr(waitMilliseconds)) event = uint32(r0) if event == 0xffffffff { err = errnoErr(e1) @@ -3546,7 +3546,7 @@ func WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32, } func WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, reserved *byte) (err error) { - r1, _, e1 := syscall.Syscall6(procWriteConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(towrite), uintptr(unsafe.Pointer(written)), uintptr(unsafe.Pointer(reserved)), 0) + r1, _, e1 := syscall.SyscallN(procWriteConsoleW.Addr(), uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(towrite), uintptr(unsafe.Pointer(written)), uintptr(unsafe.Pointer(reserved))) if r1 == 0 { err = errnoErr(e1) } @@ -3558,7 +3558,7 @@ func writeFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) if len(buf) > 0 { _p0 = &buf[0] } - r1, _, e1 := syscall.Syscall6(procWriteFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0) + r1, _, e1 := syscall.SyscallN(procWriteFile.Addr(), uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped))) if r1 == 0 { err = errnoErr(e1) } @@ -3566,7 +3566,7 @@ func writeFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) } func WriteProcessMemory(process Handle, baseAddress uintptr, buffer *byte, size uintptr, numberOfBytesWritten *uintptr) (err error) { - r1, _, e1 := syscall.Syscall6(procWriteProcessMemory.Addr(), 5, uintptr(process), uintptr(baseAddress), uintptr(unsafe.Pointer(buffer)), uintptr(size), uintptr(unsafe.Pointer(numberOfBytesWritten)), 0) + r1, _, e1 := syscall.SyscallN(procWriteProcessMemory.Addr(), uintptr(process), uintptr(baseAddress), uintptr(unsafe.Pointer(buffer)), uintptr(size), uintptr(unsafe.Pointer(numberOfBytesWritten))) if r1 == 0 { err = errnoErr(e1) } @@ -3574,7 +3574,7 @@ func WriteProcessMemory(process Handle, baseAddress uintptr, buffer *byte, size } func AcceptEx(ls Handle, as Handle, buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, recvd *uint32, overlapped *Overlapped) (err error) { - r1, _, e1 := syscall.Syscall9(procAcceptEx.Addr(), 8, uintptr(ls), uintptr(as), uintptr(unsafe.Pointer(buf)), uintptr(rxdatalen), uintptr(laddrlen), uintptr(raddrlen), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(overlapped)), 0) + r1, _, e1 := syscall.SyscallN(procAcceptEx.Addr(), uintptr(ls), uintptr(as), uintptr(unsafe.Pointer(buf)), uintptr(rxdatalen), uintptr(laddrlen), uintptr(raddrlen), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(overlapped))) if r1 == 0 { err = errnoErr(e1) } @@ -3582,12 +3582,12 @@ func AcceptEx(ls Handle, as Handle, buf *byte, rxdatalen uint32, laddrlen uint32 } func GetAcceptExSockaddrs(buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, lrsa **RawSockaddrAny, lrsalen *int32, rrsa **RawSockaddrAny, rrsalen *int32) { - syscall.Syscall9(procGetAcceptExSockaddrs.Addr(), 8, uintptr(unsafe.Pointer(buf)), uintptr(rxdatalen), uintptr(laddrlen), uintptr(raddrlen), uintptr(unsafe.Pointer(lrsa)), uintptr(unsafe.Pointer(lrsalen)), uintptr(unsafe.Pointer(rrsa)), uintptr(unsafe.Pointer(rrsalen)), 0) + syscall.SyscallN(procGetAcceptExSockaddrs.Addr(), uintptr(unsafe.Pointer(buf)), uintptr(rxdatalen), uintptr(laddrlen), uintptr(raddrlen), uintptr(unsafe.Pointer(lrsa)), uintptr(unsafe.Pointer(lrsalen)), uintptr(unsafe.Pointer(rrsa)), uintptr(unsafe.Pointer(rrsalen))) return } func TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint32, overlapped *Overlapped, transmitFileBuf *TransmitFileBuffers, flags uint32) (err error) { - r1, _, e1 := syscall.Syscall9(procTransmitFile.Addr(), 7, uintptr(s), uintptr(handle), uintptr(bytesToWrite), uintptr(bytsPerSend), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(transmitFileBuf)), uintptr(flags), 0, 0) + r1, _, e1 := syscall.SyscallN(procTransmitFile.Addr(), uintptr(s), uintptr(handle), uintptr(bytesToWrite), uintptr(bytsPerSend), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(transmitFileBuf)), uintptr(flags)) if r1 == 0 { err = errnoErr(e1) } @@ -3595,7 +3595,7 @@ func TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint } func NetApiBufferFree(buf *byte) (neterr error) { - r0, _, _ := syscall.Syscall(procNetApiBufferFree.Addr(), 1, uintptr(unsafe.Pointer(buf)), 0, 0) + r0, _, _ := syscall.SyscallN(procNetApiBufferFree.Addr(), uintptr(unsafe.Pointer(buf))) if r0 != 0 { neterr = syscall.Errno(r0) } @@ -3603,7 +3603,7 @@ func NetApiBufferFree(buf *byte) (neterr error) { } func NetGetJoinInformation(server *uint16, name **uint16, bufType *uint32) (neterr error) { - r0, _, _ := syscall.Syscall(procNetGetJoinInformation.Addr(), 3, uintptr(unsafe.Pointer(server)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(bufType))) + r0, _, _ := syscall.SyscallN(procNetGetJoinInformation.Addr(), uintptr(unsafe.Pointer(server)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(bufType))) if r0 != 0 { neterr = syscall.Errno(r0) } @@ -3611,7 +3611,7 @@ func NetGetJoinInformation(server *uint16, name **uint16, bufType *uint32) (nete } func NetUserEnum(serverName *uint16, level uint32, filter uint32, buf **byte, prefMaxLen uint32, entriesRead *uint32, totalEntries *uint32, resumeHandle *uint32) (neterr error) { - r0, _, _ := syscall.Syscall9(procNetUserEnum.Addr(), 8, uintptr(unsafe.Pointer(serverName)), uintptr(level), uintptr(filter), uintptr(unsafe.Pointer(buf)), uintptr(prefMaxLen), uintptr(unsafe.Pointer(entriesRead)), uintptr(unsafe.Pointer(totalEntries)), uintptr(unsafe.Pointer(resumeHandle)), 0) + r0, _, _ := syscall.SyscallN(procNetUserEnum.Addr(), uintptr(unsafe.Pointer(serverName)), uintptr(level), uintptr(filter), uintptr(unsafe.Pointer(buf)), uintptr(prefMaxLen), uintptr(unsafe.Pointer(entriesRead)), uintptr(unsafe.Pointer(totalEntries)), uintptr(unsafe.Pointer(resumeHandle))) if r0 != 0 { neterr = syscall.Errno(r0) } @@ -3619,7 +3619,7 @@ func NetUserEnum(serverName *uint16, level uint32, filter uint32, buf **byte, pr } func NetUserGetInfo(serverName *uint16, userName *uint16, level uint32, buf **byte) (neterr error) { - r0, _, _ := syscall.Syscall6(procNetUserGetInfo.Addr(), 4, uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(userName)), uintptr(level), uintptr(unsafe.Pointer(buf)), 0, 0) + r0, _, _ := syscall.SyscallN(procNetUserGetInfo.Addr(), uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(userName)), uintptr(level), uintptr(unsafe.Pointer(buf))) if r0 != 0 { neterr = syscall.Errno(r0) } @@ -3627,7 +3627,7 @@ func NetUserGetInfo(serverName *uint16, userName *uint16, level uint32, buf **by } func NtCreateFile(handle *Handle, access uint32, oa *OBJECT_ATTRIBUTES, iosb *IO_STATUS_BLOCK, allocationSize *int64, attributes uint32, share uint32, disposition uint32, options uint32, eabuffer uintptr, ealength uint32) (ntstatus error) { - r0, _, _ := syscall.Syscall12(procNtCreateFile.Addr(), 11, uintptr(unsafe.Pointer(handle)), uintptr(access), uintptr(unsafe.Pointer(oa)), uintptr(unsafe.Pointer(iosb)), uintptr(unsafe.Pointer(allocationSize)), uintptr(attributes), uintptr(share), uintptr(disposition), uintptr(options), uintptr(eabuffer), uintptr(ealength), 0) + r0, _, _ := syscall.SyscallN(procNtCreateFile.Addr(), uintptr(unsafe.Pointer(handle)), uintptr(access), uintptr(unsafe.Pointer(oa)), uintptr(unsafe.Pointer(iosb)), uintptr(unsafe.Pointer(allocationSize)), uintptr(attributes), uintptr(share), uintptr(disposition), uintptr(options), uintptr(eabuffer), uintptr(ealength)) if r0 != 0 { ntstatus = NTStatus(r0) } @@ -3635,7 +3635,7 @@ func NtCreateFile(handle *Handle, access uint32, oa *OBJECT_ATTRIBUTES, iosb *IO } func NtCreateNamedPipeFile(pipe *Handle, access uint32, oa *OBJECT_ATTRIBUTES, iosb *IO_STATUS_BLOCK, share uint32, disposition uint32, options uint32, typ uint32, readMode uint32, completionMode uint32, maxInstances uint32, inboundQuota uint32, outputQuota uint32, timeout *int64) (ntstatus error) { - r0, _, _ := syscall.Syscall15(procNtCreateNamedPipeFile.Addr(), 14, uintptr(unsafe.Pointer(pipe)), uintptr(access), uintptr(unsafe.Pointer(oa)), uintptr(unsafe.Pointer(iosb)), uintptr(share), uintptr(disposition), uintptr(options), uintptr(typ), uintptr(readMode), uintptr(completionMode), uintptr(maxInstances), uintptr(inboundQuota), uintptr(outputQuota), uintptr(unsafe.Pointer(timeout)), 0) + r0, _, _ := syscall.SyscallN(procNtCreateNamedPipeFile.Addr(), uintptr(unsafe.Pointer(pipe)), uintptr(access), uintptr(unsafe.Pointer(oa)), uintptr(unsafe.Pointer(iosb)), uintptr(share), uintptr(disposition), uintptr(options), uintptr(typ), uintptr(readMode), uintptr(completionMode), uintptr(maxInstances), uintptr(inboundQuota), uintptr(outputQuota), uintptr(unsafe.Pointer(timeout))) if r0 != 0 { ntstatus = NTStatus(r0) } @@ -3643,7 +3643,7 @@ func NtCreateNamedPipeFile(pipe *Handle, access uint32, oa *OBJECT_ATTRIBUTES, i } func NtQueryInformationProcess(proc Handle, procInfoClass int32, procInfo unsafe.Pointer, procInfoLen uint32, retLen *uint32) (ntstatus error) { - r0, _, _ := syscall.Syscall6(procNtQueryInformationProcess.Addr(), 5, uintptr(proc), uintptr(procInfoClass), uintptr(procInfo), uintptr(procInfoLen), uintptr(unsafe.Pointer(retLen)), 0) + r0, _, _ := syscall.SyscallN(procNtQueryInformationProcess.Addr(), uintptr(proc), uintptr(procInfoClass), uintptr(procInfo), uintptr(procInfoLen), uintptr(unsafe.Pointer(retLen))) if r0 != 0 { ntstatus = NTStatus(r0) } @@ -3651,7 +3651,7 @@ func NtQueryInformationProcess(proc Handle, procInfoClass int32, procInfo unsafe } func NtQuerySystemInformation(sysInfoClass int32, sysInfo unsafe.Pointer, sysInfoLen uint32, retLen *uint32) (ntstatus error) { - r0, _, _ := syscall.Syscall6(procNtQuerySystemInformation.Addr(), 4, uintptr(sysInfoClass), uintptr(sysInfo), uintptr(sysInfoLen), uintptr(unsafe.Pointer(retLen)), 0, 0) + r0, _, _ := syscall.SyscallN(procNtQuerySystemInformation.Addr(), uintptr(sysInfoClass), uintptr(sysInfo), uintptr(sysInfoLen), uintptr(unsafe.Pointer(retLen))) if r0 != 0 { ntstatus = NTStatus(r0) } @@ -3659,7 +3659,7 @@ func NtQuerySystemInformation(sysInfoClass int32, sysInfo unsafe.Pointer, sysInf } func NtSetInformationFile(handle Handle, iosb *IO_STATUS_BLOCK, inBuffer *byte, inBufferLen uint32, class uint32) (ntstatus error) { - r0, _, _ := syscall.Syscall6(procNtSetInformationFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(iosb)), uintptr(unsafe.Pointer(inBuffer)), uintptr(inBufferLen), uintptr(class), 0) + r0, _, _ := syscall.SyscallN(procNtSetInformationFile.Addr(), uintptr(handle), uintptr(unsafe.Pointer(iosb)), uintptr(unsafe.Pointer(inBuffer)), uintptr(inBufferLen), uintptr(class)) if r0 != 0 { ntstatus = NTStatus(r0) } @@ -3667,7 +3667,7 @@ func NtSetInformationFile(handle Handle, iosb *IO_STATUS_BLOCK, inBuffer *byte, } func NtSetInformationProcess(proc Handle, procInfoClass int32, procInfo unsafe.Pointer, procInfoLen uint32) (ntstatus error) { - r0, _, _ := syscall.Syscall6(procNtSetInformationProcess.Addr(), 4, uintptr(proc), uintptr(procInfoClass), uintptr(procInfo), uintptr(procInfoLen), 0, 0) + r0, _, _ := syscall.SyscallN(procNtSetInformationProcess.Addr(), uintptr(proc), uintptr(procInfoClass), uintptr(procInfo), uintptr(procInfoLen)) if r0 != 0 { ntstatus = NTStatus(r0) } @@ -3675,7 +3675,7 @@ func NtSetInformationProcess(proc Handle, procInfoClass int32, procInfo unsafe.P } func NtSetSystemInformation(sysInfoClass int32, sysInfo unsafe.Pointer, sysInfoLen uint32) (ntstatus error) { - r0, _, _ := syscall.Syscall(procNtSetSystemInformation.Addr(), 3, uintptr(sysInfoClass), uintptr(sysInfo), uintptr(sysInfoLen)) + r0, _, _ := syscall.SyscallN(procNtSetSystemInformation.Addr(), uintptr(sysInfoClass), uintptr(sysInfo), uintptr(sysInfoLen)) if r0 != 0 { ntstatus = NTStatus(r0) } @@ -3683,13 +3683,13 @@ func NtSetSystemInformation(sysInfoClass int32, sysInfo unsafe.Pointer, sysInfoL } func RtlAddFunctionTable(functionTable *RUNTIME_FUNCTION, entryCount uint32, baseAddress uintptr) (ret bool) { - r0, _, _ := syscall.Syscall(procRtlAddFunctionTable.Addr(), 3, uintptr(unsafe.Pointer(functionTable)), uintptr(entryCount), uintptr(baseAddress)) + r0, _, _ := syscall.SyscallN(procRtlAddFunctionTable.Addr(), uintptr(unsafe.Pointer(functionTable)), uintptr(entryCount), uintptr(baseAddress)) ret = r0 != 0 return } func RtlDefaultNpAcl(acl **ACL) (ntstatus error) { - r0, _, _ := syscall.Syscall(procRtlDefaultNpAcl.Addr(), 1, uintptr(unsafe.Pointer(acl)), 0, 0) + r0, _, _ := syscall.SyscallN(procRtlDefaultNpAcl.Addr(), uintptr(unsafe.Pointer(acl))) if r0 != 0 { ntstatus = NTStatus(r0) } @@ -3697,13 +3697,13 @@ func RtlDefaultNpAcl(acl **ACL) (ntstatus error) { } func RtlDeleteFunctionTable(functionTable *RUNTIME_FUNCTION) (ret bool) { - r0, _, _ := syscall.Syscall(procRtlDeleteFunctionTable.Addr(), 1, uintptr(unsafe.Pointer(functionTable)), 0, 0) + r0, _, _ := syscall.SyscallN(procRtlDeleteFunctionTable.Addr(), uintptr(unsafe.Pointer(functionTable))) ret = r0 != 0 return } func RtlDosPathNameToNtPathName(dosName *uint16, ntName *NTUnicodeString, ntFileNamePart *uint16, relativeName *RTL_RELATIVE_NAME) (ntstatus error) { - r0, _, _ := syscall.Syscall6(procRtlDosPathNameToNtPathName_U_WithStatus.Addr(), 4, uintptr(unsafe.Pointer(dosName)), uintptr(unsafe.Pointer(ntName)), uintptr(unsafe.Pointer(ntFileNamePart)), uintptr(unsafe.Pointer(relativeName)), 0, 0) + r0, _, _ := syscall.SyscallN(procRtlDosPathNameToNtPathName_U_WithStatus.Addr(), uintptr(unsafe.Pointer(dosName)), uintptr(unsafe.Pointer(ntName)), uintptr(unsafe.Pointer(ntFileNamePart)), uintptr(unsafe.Pointer(relativeName))) if r0 != 0 { ntstatus = NTStatus(r0) } @@ -3711,7 +3711,7 @@ func RtlDosPathNameToNtPathName(dosName *uint16, ntName *NTUnicodeString, ntFile } func RtlDosPathNameToRelativeNtPathName(dosName *uint16, ntName *NTUnicodeString, ntFileNamePart *uint16, relativeName *RTL_RELATIVE_NAME) (ntstatus error) { - r0, _, _ := syscall.Syscall6(procRtlDosPathNameToRelativeNtPathName_U_WithStatus.Addr(), 4, uintptr(unsafe.Pointer(dosName)), uintptr(unsafe.Pointer(ntName)), uintptr(unsafe.Pointer(ntFileNamePart)), uintptr(unsafe.Pointer(relativeName)), 0, 0) + r0, _, _ := syscall.SyscallN(procRtlDosPathNameToRelativeNtPathName_U_WithStatus.Addr(), uintptr(unsafe.Pointer(dosName)), uintptr(unsafe.Pointer(ntName)), uintptr(unsafe.Pointer(ntFileNamePart)), uintptr(unsafe.Pointer(relativeName))) if r0 != 0 { ntstatus = NTStatus(r0) } @@ -3719,18 +3719,18 @@ func RtlDosPathNameToRelativeNtPathName(dosName *uint16, ntName *NTUnicodeString } func RtlGetCurrentPeb() (peb *PEB) { - r0, _, _ := syscall.Syscall(procRtlGetCurrentPeb.Addr(), 0, 0, 0, 0) + r0, _, _ := syscall.SyscallN(procRtlGetCurrentPeb.Addr()) peb = (*PEB)(unsafe.Pointer(r0)) return } func rtlGetNtVersionNumbers(majorVersion *uint32, minorVersion *uint32, buildNumber *uint32) { - syscall.Syscall(procRtlGetNtVersionNumbers.Addr(), 3, uintptr(unsafe.Pointer(majorVersion)), uintptr(unsafe.Pointer(minorVersion)), uintptr(unsafe.Pointer(buildNumber))) + syscall.SyscallN(procRtlGetNtVersionNumbers.Addr(), uintptr(unsafe.Pointer(majorVersion)), uintptr(unsafe.Pointer(minorVersion)), uintptr(unsafe.Pointer(buildNumber))) return } func rtlGetVersion(info *OsVersionInfoEx) (ntstatus error) { - r0, _, _ := syscall.Syscall(procRtlGetVersion.Addr(), 1, uintptr(unsafe.Pointer(info)), 0, 0) + r0, _, _ := syscall.SyscallN(procRtlGetVersion.Addr(), uintptr(unsafe.Pointer(info))) if r0 != 0 { ntstatus = NTStatus(r0) } @@ -3738,23 +3738,23 @@ func rtlGetVersion(info *OsVersionInfoEx) (ntstatus error) { } func RtlInitString(destinationString *NTString, sourceString *byte) { - syscall.Syscall(procRtlInitString.Addr(), 2, uintptr(unsafe.Pointer(destinationString)), uintptr(unsafe.Pointer(sourceString)), 0) + syscall.SyscallN(procRtlInitString.Addr(), uintptr(unsafe.Pointer(destinationString)), uintptr(unsafe.Pointer(sourceString))) return } func RtlInitUnicodeString(destinationString *NTUnicodeString, sourceString *uint16) { - syscall.Syscall(procRtlInitUnicodeString.Addr(), 2, uintptr(unsafe.Pointer(destinationString)), uintptr(unsafe.Pointer(sourceString)), 0) + syscall.SyscallN(procRtlInitUnicodeString.Addr(), uintptr(unsafe.Pointer(destinationString)), uintptr(unsafe.Pointer(sourceString))) return } func rtlNtStatusToDosErrorNoTeb(ntstatus NTStatus) (ret syscall.Errno) { - r0, _, _ := syscall.Syscall(procRtlNtStatusToDosErrorNoTeb.Addr(), 1, uintptr(ntstatus), 0, 0) + r0, _, _ := syscall.SyscallN(procRtlNtStatusToDosErrorNoTeb.Addr(), uintptr(ntstatus)) ret = syscall.Errno(r0) return } func clsidFromString(lpsz *uint16, pclsid *GUID) (ret error) { - r0, _, _ := syscall.Syscall(procCLSIDFromString.Addr(), 2, uintptr(unsafe.Pointer(lpsz)), uintptr(unsafe.Pointer(pclsid)), 0) + r0, _, _ := syscall.SyscallN(procCLSIDFromString.Addr(), uintptr(unsafe.Pointer(lpsz)), uintptr(unsafe.Pointer(pclsid))) if r0 != 0 { ret = syscall.Errno(r0) } @@ -3762,7 +3762,7 @@ func clsidFromString(lpsz *uint16, pclsid *GUID) (ret error) { } func coCreateGuid(pguid *GUID) (ret error) { - r0, _, _ := syscall.Syscall(procCoCreateGuid.Addr(), 1, uintptr(unsafe.Pointer(pguid)), 0, 0) + r0, _, _ := syscall.SyscallN(procCoCreateGuid.Addr(), uintptr(unsafe.Pointer(pguid))) if r0 != 0 { ret = syscall.Errno(r0) } @@ -3770,7 +3770,7 @@ func coCreateGuid(pguid *GUID) (ret error) { } func CoGetObject(name *uint16, bindOpts *BIND_OPTS3, guid *GUID, functionTable **uintptr) (ret error) { - r0, _, _ := syscall.Syscall6(procCoGetObject.Addr(), 4, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(bindOpts)), uintptr(unsafe.Pointer(guid)), uintptr(unsafe.Pointer(functionTable)), 0, 0) + r0, _, _ := syscall.SyscallN(procCoGetObject.Addr(), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(bindOpts)), uintptr(unsafe.Pointer(guid)), uintptr(unsafe.Pointer(functionTable))) if r0 != 0 { ret = syscall.Errno(r0) } @@ -3778,7 +3778,7 @@ func CoGetObject(name *uint16, bindOpts *BIND_OPTS3, guid *GUID, functionTable * } func CoInitializeEx(reserved uintptr, coInit uint32) (ret error) { - r0, _, _ := syscall.Syscall(procCoInitializeEx.Addr(), 2, uintptr(reserved), uintptr(coInit), 0) + r0, _, _ := syscall.SyscallN(procCoInitializeEx.Addr(), uintptr(reserved), uintptr(coInit)) if r0 != 0 { ret = syscall.Errno(r0) } @@ -3786,23 +3786,23 @@ func CoInitializeEx(reserved uintptr, coInit uint32) (ret error) { } func CoTaskMemFree(address unsafe.Pointer) { - syscall.Syscall(procCoTaskMemFree.Addr(), 1, uintptr(address), 0, 0) + syscall.SyscallN(procCoTaskMemFree.Addr(), uintptr(address)) return } func CoUninitialize() { - syscall.Syscall(procCoUninitialize.Addr(), 0, 0, 0, 0) + syscall.SyscallN(procCoUninitialize.Addr()) return } func stringFromGUID2(rguid *GUID, lpsz *uint16, cchMax int32) (chars int32) { - r0, _, _ := syscall.Syscall(procStringFromGUID2.Addr(), 3, uintptr(unsafe.Pointer(rguid)), uintptr(unsafe.Pointer(lpsz)), uintptr(cchMax)) + r0, _, _ := syscall.SyscallN(procStringFromGUID2.Addr(), uintptr(unsafe.Pointer(rguid)), uintptr(unsafe.Pointer(lpsz)), uintptr(cchMax)) chars = int32(r0) return } func EnumProcessModules(process Handle, module *Handle, cb uint32, cbNeeded *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procEnumProcessModules.Addr(), 4, uintptr(process), uintptr(unsafe.Pointer(module)), uintptr(cb), uintptr(unsafe.Pointer(cbNeeded)), 0, 0) + r1, _, e1 := syscall.SyscallN(procEnumProcessModules.Addr(), uintptr(process), uintptr(unsafe.Pointer(module)), uintptr(cb), uintptr(unsafe.Pointer(cbNeeded))) if r1 == 0 { err = errnoErr(e1) } @@ -3810,7 +3810,7 @@ func EnumProcessModules(process Handle, module *Handle, cb uint32, cbNeeded *uin } func EnumProcessModulesEx(process Handle, module *Handle, cb uint32, cbNeeded *uint32, filterFlag uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procEnumProcessModulesEx.Addr(), 5, uintptr(process), uintptr(unsafe.Pointer(module)), uintptr(cb), uintptr(unsafe.Pointer(cbNeeded)), uintptr(filterFlag), 0) + r1, _, e1 := syscall.SyscallN(procEnumProcessModulesEx.Addr(), uintptr(process), uintptr(unsafe.Pointer(module)), uintptr(cb), uintptr(unsafe.Pointer(cbNeeded)), uintptr(filterFlag)) if r1 == 0 { err = errnoErr(e1) } @@ -3818,7 +3818,7 @@ func EnumProcessModulesEx(process Handle, module *Handle, cb uint32, cbNeeded *u } func enumProcesses(processIds *uint32, nSize uint32, bytesReturned *uint32) (err error) { - r1, _, e1 := syscall.Syscall(procEnumProcesses.Addr(), 3, uintptr(unsafe.Pointer(processIds)), uintptr(nSize), uintptr(unsafe.Pointer(bytesReturned))) + r1, _, e1 := syscall.SyscallN(procEnumProcesses.Addr(), uintptr(unsafe.Pointer(processIds)), uintptr(nSize), uintptr(unsafe.Pointer(bytesReturned))) if r1 == 0 { err = errnoErr(e1) } @@ -3826,7 +3826,7 @@ func enumProcesses(processIds *uint32, nSize uint32, bytesReturned *uint32) (err } func GetModuleBaseName(process Handle, module Handle, baseName *uint16, size uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procGetModuleBaseNameW.Addr(), 4, uintptr(process), uintptr(module), uintptr(unsafe.Pointer(baseName)), uintptr(size), 0, 0) + r1, _, e1 := syscall.SyscallN(procGetModuleBaseNameW.Addr(), uintptr(process), uintptr(module), uintptr(unsafe.Pointer(baseName)), uintptr(size)) if r1 == 0 { err = errnoErr(e1) } @@ -3834,7 +3834,7 @@ func GetModuleBaseName(process Handle, module Handle, baseName *uint16, size uin } func GetModuleFileNameEx(process Handle, module Handle, filename *uint16, size uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procGetModuleFileNameExW.Addr(), 4, uintptr(process), uintptr(module), uintptr(unsafe.Pointer(filename)), uintptr(size), 0, 0) + r1, _, e1 := syscall.SyscallN(procGetModuleFileNameExW.Addr(), uintptr(process), uintptr(module), uintptr(unsafe.Pointer(filename)), uintptr(size)) if r1 == 0 { err = errnoErr(e1) } @@ -3842,7 +3842,7 @@ func GetModuleFileNameEx(process Handle, module Handle, filename *uint16, size u } func GetModuleInformation(process Handle, module Handle, modinfo *ModuleInfo, cb uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procGetModuleInformation.Addr(), 4, uintptr(process), uintptr(module), uintptr(unsafe.Pointer(modinfo)), uintptr(cb), 0, 0) + r1, _, e1 := syscall.SyscallN(procGetModuleInformation.Addr(), uintptr(process), uintptr(module), uintptr(unsafe.Pointer(modinfo)), uintptr(cb)) if r1 == 0 { err = errnoErr(e1) } @@ -3850,7 +3850,7 @@ func GetModuleInformation(process Handle, module Handle, modinfo *ModuleInfo, cb } func QueryWorkingSetEx(process Handle, pv uintptr, cb uint32) (err error) { - r1, _, e1 := syscall.Syscall(procQueryWorkingSetEx.Addr(), 3, uintptr(process), uintptr(pv), uintptr(cb)) + r1, _, e1 := syscall.SyscallN(procQueryWorkingSetEx.Addr(), uintptr(process), uintptr(pv), uintptr(cb)) if r1 == 0 { err = errnoErr(e1) } @@ -3862,7 +3862,7 @@ func SubscribeServiceChangeNotifications(service Handle, eventType uint32, callb if ret != nil { return } - r0, _, _ := syscall.Syscall6(procSubscribeServiceChangeNotifications.Addr(), 5, uintptr(service), uintptr(eventType), uintptr(callback), uintptr(callbackCtx), uintptr(unsafe.Pointer(subscription)), 0) + r0, _, _ := syscall.SyscallN(procSubscribeServiceChangeNotifications.Addr(), uintptr(service), uintptr(eventType), uintptr(callback), uintptr(callbackCtx), uintptr(unsafe.Pointer(subscription))) if r0 != 0 { ret = syscall.Errno(r0) } @@ -3874,12 +3874,12 @@ func UnsubscribeServiceChangeNotifications(subscription uintptr) (err error) { if err != nil { return } - syscall.Syscall(procUnsubscribeServiceChangeNotifications.Addr(), 1, uintptr(subscription), 0, 0) + syscall.SyscallN(procUnsubscribeServiceChangeNotifications.Addr(), uintptr(subscription)) return } func GetUserNameEx(nameFormat uint32, nameBuffre *uint16, nSize *uint32) (err error) { - r1, _, e1 := syscall.Syscall(procGetUserNameExW.Addr(), 3, uintptr(nameFormat), uintptr(unsafe.Pointer(nameBuffre)), uintptr(unsafe.Pointer(nSize))) + r1, _, e1 := syscall.SyscallN(procGetUserNameExW.Addr(), uintptr(nameFormat), uintptr(unsafe.Pointer(nameBuffre)), uintptr(unsafe.Pointer(nSize))) if r1&0xff == 0 { err = errnoErr(e1) } @@ -3887,7 +3887,7 @@ func GetUserNameEx(nameFormat uint32, nameBuffre *uint16, nSize *uint32) (err er } func TranslateName(accName *uint16, accNameFormat uint32, desiredNameFormat uint32, translatedName *uint16, nSize *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procTranslateNameW.Addr(), 5, uintptr(unsafe.Pointer(accName)), uintptr(accNameFormat), uintptr(desiredNameFormat), uintptr(unsafe.Pointer(translatedName)), uintptr(unsafe.Pointer(nSize)), 0) + r1, _, e1 := syscall.SyscallN(procTranslateNameW.Addr(), uintptr(unsafe.Pointer(accName)), uintptr(accNameFormat), uintptr(desiredNameFormat), uintptr(unsafe.Pointer(translatedName)), uintptr(unsafe.Pointer(nSize))) if r1&0xff == 0 { err = errnoErr(e1) } @@ -3895,7 +3895,7 @@ func TranslateName(accName *uint16, accNameFormat uint32, desiredNameFormat uint } func SetupDiBuildDriverInfoList(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverType SPDIT) (err error) { - r1, _, e1 := syscall.Syscall(procSetupDiBuildDriverInfoList.Addr(), 3, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(driverType)) + r1, _, e1 := syscall.SyscallN(procSetupDiBuildDriverInfoList.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(driverType)) if r1 == 0 { err = errnoErr(e1) } @@ -3903,7 +3903,7 @@ func SetupDiBuildDriverInfoList(deviceInfoSet DevInfo, deviceInfoData *DevInfoDa } func SetupDiCallClassInstaller(installFunction DI_FUNCTION, deviceInfoSet DevInfo, deviceInfoData *DevInfoData) (err error) { - r1, _, e1 := syscall.Syscall(procSetupDiCallClassInstaller.Addr(), 3, uintptr(installFunction), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData))) + r1, _, e1 := syscall.SyscallN(procSetupDiCallClassInstaller.Addr(), uintptr(installFunction), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData))) if r1 == 0 { err = errnoErr(e1) } @@ -3911,7 +3911,7 @@ func SetupDiCallClassInstaller(installFunction DI_FUNCTION, deviceInfoSet DevInf } func SetupDiCancelDriverInfoSearch(deviceInfoSet DevInfo) (err error) { - r1, _, e1 := syscall.Syscall(procSetupDiCancelDriverInfoSearch.Addr(), 1, uintptr(deviceInfoSet), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetupDiCancelDriverInfoSearch.Addr(), uintptr(deviceInfoSet)) if r1 == 0 { err = errnoErr(e1) } @@ -3919,7 +3919,7 @@ func SetupDiCancelDriverInfoSearch(deviceInfoSet DevInfo) (err error) { } func setupDiClassGuidsFromNameEx(className *uint16, classGuidList *GUID, classGuidListSize uint32, requiredSize *uint32, machineName *uint16, reserved uintptr) (err error) { - r1, _, e1 := syscall.Syscall6(procSetupDiClassGuidsFromNameExW.Addr(), 6, uintptr(unsafe.Pointer(className)), uintptr(unsafe.Pointer(classGuidList)), uintptr(classGuidListSize), uintptr(unsafe.Pointer(requiredSize)), uintptr(unsafe.Pointer(machineName)), uintptr(reserved)) + r1, _, e1 := syscall.SyscallN(procSetupDiClassGuidsFromNameExW.Addr(), uintptr(unsafe.Pointer(className)), uintptr(unsafe.Pointer(classGuidList)), uintptr(classGuidListSize), uintptr(unsafe.Pointer(requiredSize)), uintptr(unsafe.Pointer(machineName)), uintptr(reserved)) if r1 == 0 { err = errnoErr(e1) } @@ -3927,7 +3927,7 @@ func setupDiClassGuidsFromNameEx(className *uint16, classGuidList *GUID, classGu } func setupDiClassNameFromGuidEx(classGUID *GUID, className *uint16, classNameSize uint32, requiredSize *uint32, machineName *uint16, reserved uintptr) (err error) { - r1, _, e1 := syscall.Syscall6(procSetupDiClassNameFromGuidExW.Addr(), 6, uintptr(unsafe.Pointer(classGUID)), uintptr(unsafe.Pointer(className)), uintptr(classNameSize), uintptr(unsafe.Pointer(requiredSize)), uintptr(unsafe.Pointer(machineName)), uintptr(reserved)) + r1, _, e1 := syscall.SyscallN(procSetupDiClassNameFromGuidExW.Addr(), uintptr(unsafe.Pointer(classGUID)), uintptr(unsafe.Pointer(className)), uintptr(classNameSize), uintptr(unsafe.Pointer(requiredSize)), uintptr(unsafe.Pointer(machineName)), uintptr(reserved)) if r1 == 0 { err = errnoErr(e1) } @@ -3935,7 +3935,7 @@ func setupDiClassNameFromGuidEx(classGUID *GUID, className *uint16, classNameSiz } func setupDiCreateDeviceInfoListEx(classGUID *GUID, hwndParent uintptr, machineName *uint16, reserved uintptr) (handle DevInfo, err error) { - r0, _, e1 := syscall.Syscall6(procSetupDiCreateDeviceInfoListExW.Addr(), 4, uintptr(unsafe.Pointer(classGUID)), uintptr(hwndParent), uintptr(unsafe.Pointer(machineName)), uintptr(reserved), 0, 0) + r0, _, e1 := syscall.SyscallN(procSetupDiCreateDeviceInfoListExW.Addr(), uintptr(unsafe.Pointer(classGUID)), uintptr(hwndParent), uintptr(unsafe.Pointer(machineName)), uintptr(reserved)) handle = DevInfo(r0) if handle == DevInfo(InvalidHandle) { err = errnoErr(e1) @@ -3944,7 +3944,7 @@ func setupDiCreateDeviceInfoListEx(classGUID *GUID, hwndParent uintptr, machineN } func setupDiCreateDeviceInfo(deviceInfoSet DevInfo, DeviceName *uint16, classGUID *GUID, DeviceDescription *uint16, hwndParent uintptr, CreationFlags DICD, deviceInfoData *DevInfoData) (err error) { - r1, _, e1 := syscall.Syscall9(procSetupDiCreateDeviceInfoW.Addr(), 7, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(DeviceName)), uintptr(unsafe.Pointer(classGUID)), uintptr(unsafe.Pointer(DeviceDescription)), uintptr(hwndParent), uintptr(CreationFlags), uintptr(unsafe.Pointer(deviceInfoData)), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetupDiCreateDeviceInfoW.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(DeviceName)), uintptr(unsafe.Pointer(classGUID)), uintptr(unsafe.Pointer(DeviceDescription)), uintptr(hwndParent), uintptr(CreationFlags), uintptr(unsafe.Pointer(deviceInfoData))) if r1 == 0 { err = errnoErr(e1) } @@ -3952,7 +3952,7 @@ func setupDiCreateDeviceInfo(deviceInfoSet DevInfo, DeviceName *uint16, classGUI } func SetupDiDestroyDeviceInfoList(deviceInfoSet DevInfo) (err error) { - r1, _, e1 := syscall.Syscall(procSetupDiDestroyDeviceInfoList.Addr(), 1, uintptr(deviceInfoSet), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetupDiDestroyDeviceInfoList.Addr(), uintptr(deviceInfoSet)) if r1 == 0 { err = errnoErr(e1) } @@ -3960,7 +3960,7 @@ func SetupDiDestroyDeviceInfoList(deviceInfoSet DevInfo) (err error) { } func SetupDiDestroyDriverInfoList(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverType SPDIT) (err error) { - r1, _, e1 := syscall.Syscall(procSetupDiDestroyDriverInfoList.Addr(), 3, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(driverType)) + r1, _, e1 := syscall.SyscallN(procSetupDiDestroyDriverInfoList.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(driverType)) if r1 == 0 { err = errnoErr(e1) } @@ -3968,7 +3968,7 @@ func SetupDiDestroyDriverInfoList(deviceInfoSet DevInfo, deviceInfoData *DevInfo } func setupDiEnumDeviceInfo(deviceInfoSet DevInfo, memberIndex uint32, deviceInfoData *DevInfoData) (err error) { - r1, _, e1 := syscall.Syscall(procSetupDiEnumDeviceInfo.Addr(), 3, uintptr(deviceInfoSet), uintptr(memberIndex), uintptr(unsafe.Pointer(deviceInfoData))) + r1, _, e1 := syscall.SyscallN(procSetupDiEnumDeviceInfo.Addr(), uintptr(deviceInfoSet), uintptr(memberIndex), uintptr(unsafe.Pointer(deviceInfoData))) if r1 == 0 { err = errnoErr(e1) } @@ -3976,7 +3976,7 @@ func setupDiEnumDeviceInfo(deviceInfoSet DevInfo, memberIndex uint32, deviceInfo } func setupDiEnumDriverInfo(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverType SPDIT, memberIndex uint32, driverInfoData *DrvInfoData) (err error) { - r1, _, e1 := syscall.Syscall6(procSetupDiEnumDriverInfoW.Addr(), 5, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(driverType), uintptr(memberIndex), uintptr(unsafe.Pointer(driverInfoData)), 0) + r1, _, e1 := syscall.SyscallN(procSetupDiEnumDriverInfoW.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(driverType), uintptr(memberIndex), uintptr(unsafe.Pointer(driverInfoData))) if r1 == 0 { err = errnoErr(e1) } @@ -3984,7 +3984,7 @@ func setupDiEnumDriverInfo(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, d } func setupDiGetClassDevsEx(classGUID *GUID, Enumerator *uint16, hwndParent uintptr, Flags DIGCF, deviceInfoSet DevInfo, machineName *uint16, reserved uintptr) (handle DevInfo, err error) { - r0, _, e1 := syscall.Syscall9(procSetupDiGetClassDevsExW.Addr(), 7, uintptr(unsafe.Pointer(classGUID)), uintptr(unsafe.Pointer(Enumerator)), uintptr(hwndParent), uintptr(Flags), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(machineName)), uintptr(reserved), 0, 0) + r0, _, e1 := syscall.SyscallN(procSetupDiGetClassDevsExW.Addr(), uintptr(unsafe.Pointer(classGUID)), uintptr(unsafe.Pointer(Enumerator)), uintptr(hwndParent), uintptr(Flags), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(machineName)), uintptr(reserved)) handle = DevInfo(r0) if handle == DevInfo(InvalidHandle) { err = errnoErr(e1) @@ -3993,7 +3993,7 @@ func setupDiGetClassDevsEx(classGUID *GUID, Enumerator *uint16, hwndParent uintp } func SetupDiGetClassInstallParams(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, classInstallParams *ClassInstallHeader, classInstallParamsSize uint32, requiredSize *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procSetupDiGetClassInstallParamsW.Addr(), 5, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(classInstallParams)), uintptr(classInstallParamsSize), uintptr(unsafe.Pointer(requiredSize)), 0) + r1, _, e1 := syscall.SyscallN(procSetupDiGetClassInstallParamsW.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(classInstallParams)), uintptr(classInstallParamsSize), uintptr(unsafe.Pointer(requiredSize))) if r1 == 0 { err = errnoErr(e1) } @@ -4001,7 +4001,7 @@ func SetupDiGetClassInstallParams(deviceInfoSet DevInfo, deviceInfoData *DevInfo } func setupDiGetDeviceInfoListDetail(deviceInfoSet DevInfo, deviceInfoSetDetailData *DevInfoListDetailData) (err error) { - r1, _, e1 := syscall.Syscall(procSetupDiGetDeviceInfoListDetailW.Addr(), 2, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoSetDetailData)), 0) + r1, _, e1 := syscall.SyscallN(procSetupDiGetDeviceInfoListDetailW.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoSetDetailData))) if r1 == 0 { err = errnoErr(e1) } @@ -4009,7 +4009,7 @@ func setupDiGetDeviceInfoListDetail(deviceInfoSet DevInfo, deviceInfoSetDetailDa } func setupDiGetDeviceInstallParams(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, deviceInstallParams *DevInstallParams) (err error) { - r1, _, e1 := syscall.Syscall(procSetupDiGetDeviceInstallParamsW.Addr(), 3, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(deviceInstallParams))) + r1, _, e1 := syscall.SyscallN(procSetupDiGetDeviceInstallParamsW.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(deviceInstallParams))) if r1 == 0 { err = errnoErr(e1) } @@ -4017,7 +4017,7 @@ func setupDiGetDeviceInstallParams(deviceInfoSet DevInfo, deviceInfoData *DevInf } func setupDiGetDeviceInstanceId(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, instanceId *uint16, instanceIdSize uint32, instanceIdRequiredSize *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procSetupDiGetDeviceInstanceIdW.Addr(), 5, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(instanceId)), uintptr(instanceIdSize), uintptr(unsafe.Pointer(instanceIdRequiredSize)), 0) + r1, _, e1 := syscall.SyscallN(procSetupDiGetDeviceInstanceIdW.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(instanceId)), uintptr(instanceIdSize), uintptr(unsafe.Pointer(instanceIdRequiredSize))) if r1 == 0 { err = errnoErr(e1) } @@ -4025,7 +4025,7 @@ func setupDiGetDeviceInstanceId(deviceInfoSet DevInfo, deviceInfoData *DevInfoDa } func setupDiGetDeviceProperty(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, propertyKey *DEVPROPKEY, propertyType *DEVPROPTYPE, propertyBuffer *byte, propertyBufferSize uint32, requiredSize *uint32, flags uint32) (err error) { - r1, _, e1 := syscall.Syscall9(procSetupDiGetDevicePropertyW.Addr(), 8, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(propertyKey)), uintptr(unsafe.Pointer(propertyType)), uintptr(unsafe.Pointer(propertyBuffer)), uintptr(propertyBufferSize), uintptr(unsafe.Pointer(requiredSize)), uintptr(flags), 0) + r1, _, e1 := syscall.SyscallN(procSetupDiGetDevicePropertyW.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(propertyKey)), uintptr(unsafe.Pointer(propertyType)), uintptr(unsafe.Pointer(propertyBuffer)), uintptr(propertyBufferSize), uintptr(unsafe.Pointer(requiredSize)), uintptr(flags)) if r1 == 0 { err = errnoErr(e1) } @@ -4033,7 +4033,7 @@ func setupDiGetDeviceProperty(deviceInfoSet DevInfo, deviceInfoData *DevInfoData } func setupDiGetDeviceRegistryProperty(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, property SPDRP, propertyRegDataType *uint32, propertyBuffer *byte, propertyBufferSize uint32, requiredSize *uint32) (err error) { - r1, _, e1 := syscall.Syscall9(procSetupDiGetDeviceRegistryPropertyW.Addr(), 7, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(property), uintptr(unsafe.Pointer(propertyRegDataType)), uintptr(unsafe.Pointer(propertyBuffer)), uintptr(propertyBufferSize), uintptr(unsafe.Pointer(requiredSize)), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetupDiGetDeviceRegistryPropertyW.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(property), uintptr(unsafe.Pointer(propertyRegDataType)), uintptr(unsafe.Pointer(propertyBuffer)), uintptr(propertyBufferSize), uintptr(unsafe.Pointer(requiredSize))) if r1 == 0 { err = errnoErr(e1) } @@ -4041,7 +4041,7 @@ func setupDiGetDeviceRegistryProperty(deviceInfoSet DevInfo, deviceInfoData *Dev } func setupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *DrvInfoData, driverInfoDetailData *DrvInfoDetailData, driverInfoDetailDataSize uint32, requiredSize *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procSetupDiGetDriverInfoDetailW.Addr(), 6, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(driverInfoData)), uintptr(unsafe.Pointer(driverInfoDetailData)), uintptr(driverInfoDetailDataSize), uintptr(unsafe.Pointer(requiredSize))) + r1, _, e1 := syscall.SyscallN(procSetupDiGetDriverInfoDetailW.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(driverInfoData)), uintptr(unsafe.Pointer(driverInfoDetailData)), uintptr(driverInfoDetailDataSize), uintptr(unsafe.Pointer(requiredSize))) if r1 == 0 { err = errnoErr(e1) } @@ -4049,7 +4049,7 @@ func setupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoDa } func setupDiGetSelectedDevice(deviceInfoSet DevInfo, deviceInfoData *DevInfoData) (err error) { - r1, _, e1 := syscall.Syscall(procSetupDiGetSelectedDevice.Addr(), 2, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), 0) + r1, _, e1 := syscall.SyscallN(procSetupDiGetSelectedDevice.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData))) if r1 == 0 { err = errnoErr(e1) } @@ -4057,7 +4057,7 @@ func setupDiGetSelectedDevice(deviceInfoSet DevInfo, deviceInfoData *DevInfoData } func setupDiGetSelectedDriver(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *DrvInfoData) (err error) { - r1, _, e1 := syscall.Syscall(procSetupDiGetSelectedDriverW.Addr(), 3, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(driverInfoData))) + r1, _, e1 := syscall.SyscallN(procSetupDiGetSelectedDriverW.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(driverInfoData))) if r1 == 0 { err = errnoErr(e1) } @@ -4065,7 +4065,7 @@ func setupDiGetSelectedDriver(deviceInfoSet DevInfo, deviceInfoData *DevInfoData } func SetupDiOpenDevRegKey(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, Scope DICS_FLAG, HwProfile uint32, KeyType DIREG, samDesired uint32) (key Handle, err error) { - r0, _, e1 := syscall.Syscall6(procSetupDiOpenDevRegKey.Addr(), 6, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(Scope), uintptr(HwProfile), uintptr(KeyType), uintptr(samDesired)) + r0, _, e1 := syscall.SyscallN(procSetupDiOpenDevRegKey.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(Scope), uintptr(HwProfile), uintptr(KeyType), uintptr(samDesired)) key = Handle(r0) if key == InvalidHandle { err = errnoErr(e1) @@ -4074,7 +4074,7 @@ func SetupDiOpenDevRegKey(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, Sc } func SetupDiSetClassInstallParams(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, classInstallParams *ClassInstallHeader, classInstallParamsSize uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procSetupDiSetClassInstallParamsW.Addr(), 4, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(classInstallParams)), uintptr(classInstallParamsSize), 0, 0) + r1, _, e1 := syscall.SyscallN(procSetupDiSetClassInstallParamsW.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(classInstallParams)), uintptr(classInstallParamsSize)) if r1 == 0 { err = errnoErr(e1) } @@ -4082,7 +4082,7 @@ func SetupDiSetClassInstallParams(deviceInfoSet DevInfo, deviceInfoData *DevInfo } func SetupDiSetDeviceInstallParams(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, deviceInstallParams *DevInstallParams) (err error) { - r1, _, e1 := syscall.Syscall(procSetupDiSetDeviceInstallParamsW.Addr(), 3, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(deviceInstallParams))) + r1, _, e1 := syscall.SyscallN(procSetupDiSetDeviceInstallParamsW.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(deviceInstallParams))) if r1 == 0 { err = errnoErr(e1) } @@ -4090,7 +4090,7 @@ func SetupDiSetDeviceInstallParams(deviceInfoSet DevInfo, deviceInfoData *DevInf } func setupDiSetDeviceRegistryProperty(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, property SPDRP, propertyBuffer *byte, propertyBufferSize uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procSetupDiSetDeviceRegistryPropertyW.Addr(), 5, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(property), uintptr(unsafe.Pointer(propertyBuffer)), uintptr(propertyBufferSize), 0) + r1, _, e1 := syscall.SyscallN(procSetupDiSetDeviceRegistryPropertyW.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(property), uintptr(unsafe.Pointer(propertyBuffer)), uintptr(propertyBufferSize)) if r1 == 0 { err = errnoErr(e1) } @@ -4098,7 +4098,7 @@ func setupDiSetDeviceRegistryProperty(deviceInfoSet DevInfo, deviceInfoData *Dev } func SetupDiSetSelectedDevice(deviceInfoSet DevInfo, deviceInfoData *DevInfoData) (err error) { - r1, _, e1 := syscall.Syscall(procSetupDiSetSelectedDevice.Addr(), 2, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), 0) + r1, _, e1 := syscall.SyscallN(procSetupDiSetSelectedDevice.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData))) if r1 == 0 { err = errnoErr(e1) } @@ -4106,7 +4106,7 @@ func SetupDiSetSelectedDevice(deviceInfoSet DevInfo, deviceInfoData *DevInfoData } func SetupDiSetSelectedDriver(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *DrvInfoData) (err error) { - r1, _, e1 := syscall.Syscall(procSetupDiSetSelectedDriverW.Addr(), 3, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(driverInfoData))) + r1, _, e1 := syscall.SyscallN(procSetupDiSetSelectedDriverW.Addr(), uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoData)), uintptr(unsafe.Pointer(driverInfoData))) if r1 == 0 { err = errnoErr(e1) } @@ -4114,7 +4114,7 @@ func SetupDiSetSelectedDriver(deviceInfoSet DevInfo, deviceInfoData *DevInfoData } func setupUninstallOEMInf(infFileName *uint16, flags SUOI, reserved uintptr) (err error) { - r1, _, e1 := syscall.Syscall(procSetupUninstallOEMInfW.Addr(), 3, uintptr(unsafe.Pointer(infFileName)), uintptr(flags), uintptr(reserved)) + r1, _, e1 := syscall.SyscallN(procSetupUninstallOEMInfW.Addr(), uintptr(unsafe.Pointer(infFileName)), uintptr(flags), uintptr(reserved)) if r1 == 0 { err = errnoErr(e1) } @@ -4122,7 +4122,7 @@ func setupUninstallOEMInf(infFileName *uint16, flags SUOI, reserved uintptr) (er } func commandLineToArgv(cmd *uint16, argc *int32) (argv **uint16, err error) { - r0, _, e1 := syscall.Syscall(procCommandLineToArgvW.Addr(), 2, uintptr(unsafe.Pointer(cmd)), uintptr(unsafe.Pointer(argc)), 0) + r0, _, e1 := syscall.SyscallN(procCommandLineToArgvW.Addr(), uintptr(unsafe.Pointer(cmd)), uintptr(unsafe.Pointer(argc))) argv = (**uint16)(unsafe.Pointer(r0)) if argv == nil { err = errnoErr(e1) @@ -4131,7 +4131,7 @@ func commandLineToArgv(cmd *uint16, argc *int32) (argv **uint16, err error) { } func shGetKnownFolderPath(id *KNOWNFOLDERID, flags uint32, token Token, path **uint16) (ret error) { - r0, _, _ := syscall.Syscall6(procSHGetKnownFolderPath.Addr(), 4, uintptr(unsafe.Pointer(id)), uintptr(flags), uintptr(token), uintptr(unsafe.Pointer(path)), 0, 0) + r0, _, _ := syscall.SyscallN(procSHGetKnownFolderPath.Addr(), uintptr(unsafe.Pointer(id)), uintptr(flags), uintptr(token), uintptr(unsafe.Pointer(path))) if r0 != 0 { ret = syscall.Errno(r0) } @@ -4139,7 +4139,7 @@ func shGetKnownFolderPath(id *KNOWNFOLDERID, flags uint32, token Token, path **u } func ShellExecute(hwnd Handle, verb *uint16, file *uint16, args *uint16, cwd *uint16, showCmd int32) (err error) { - r1, _, e1 := syscall.Syscall6(procShellExecuteW.Addr(), 6, uintptr(hwnd), uintptr(unsafe.Pointer(verb)), uintptr(unsafe.Pointer(file)), uintptr(unsafe.Pointer(args)), uintptr(unsafe.Pointer(cwd)), uintptr(showCmd)) + r1, _, e1 := syscall.SyscallN(procShellExecuteW.Addr(), uintptr(hwnd), uintptr(unsafe.Pointer(verb)), uintptr(unsafe.Pointer(file)), uintptr(unsafe.Pointer(args)), uintptr(unsafe.Pointer(cwd)), uintptr(showCmd)) if r1 <= 32 { err = errnoErr(e1) } @@ -4147,12 +4147,12 @@ func ShellExecute(hwnd Handle, verb *uint16, file *uint16, args *uint16, cwd *ui } func EnumChildWindows(hwnd HWND, enumFunc uintptr, param unsafe.Pointer) { - syscall.Syscall(procEnumChildWindows.Addr(), 3, uintptr(hwnd), uintptr(enumFunc), uintptr(param)) + syscall.SyscallN(procEnumChildWindows.Addr(), uintptr(hwnd), uintptr(enumFunc), uintptr(param)) return } func EnumWindows(enumFunc uintptr, param unsafe.Pointer) (err error) { - r1, _, e1 := syscall.Syscall(procEnumWindows.Addr(), 2, uintptr(enumFunc), uintptr(param), 0) + r1, _, e1 := syscall.SyscallN(procEnumWindows.Addr(), uintptr(enumFunc), uintptr(param)) if r1 == 0 { err = errnoErr(e1) } @@ -4160,7 +4160,7 @@ func EnumWindows(enumFunc uintptr, param unsafe.Pointer) (err error) { } func ExitWindowsEx(flags uint32, reason uint32) (err error) { - r1, _, e1 := syscall.Syscall(procExitWindowsEx.Addr(), 2, uintptr(flags), uintptr(reason), 0) + r1, _, e1 := syscall.SyscallN(procExitWindowsEx.Addr(), uintptr(flags), uintptr(reason)) if r1 == 0 { err = errnoErr(e1) } @@ -4168,7 +4168,7 @@ func ExitWindowsEx(flags uint32, reason uint32) (err error) { } func GetClassName(hwnd HWND, className *uint16, maxCount int32) (copied int32, err error) { - r0, _, e1 := syscall.Syscall(procGetClassNameW.Addr(), 3, uintptr(hwnd), uintptr(unsafe.Pointer(className)), uintptr(maxCount)) + r0, _, e1 := syscall.SyscallN(procGetClassNameW.Addr(), uintptr(hwnd), uintptr(unsafe.Pointer(className)), uintptr(maxCount)) copied = int32(r0) if copied == 0 { err = errnoErr(e1) @@ -4177,19 +4177,19 @@ func GetClassName(hwnd HWND, className *uint16, maxCount int32) (copied int32, e } func GetDesktopWindow() (hwnd HWND) { - r0, _, _ := syscall.Syscall(procGetDesktopWindow.Addr(), 0, 0, 0, 0) + r0, _, _ := syscall.SyscallN(procGetDesktopWindow.Addr()) hwnd = HWND(r0) return } func GetForegroundWindow() (hwnd HWND) { - r0, _, _ := syscall.Syscall(procGetForegroundWindow.Addr(), 0, 0, 0, 0) + r0, _, _ := syscall.SyscallN(procGetForegroundWindow.Addr()) hwnd = HWND(r0) return } func GetGUIThreadInfo(thread uint32, info *GUIThreadInfo) (err error) { - r1, _, e1 := syscall.Syscall(procGetGUIThreadInfo.Addr(), 2, uintptr(thread), uintptr(unsafe.Pointer(info)), 0) + r1, _, e1 := syscall.SyscallN(procGetGUIThreadInfo.Addr(), uintptr(thread), uintptr(unsafe.Pointer(info))) if r1 == 0 { err = errnoErr(e1) } @@ -4197,19 +4197,19 @@ func GetGUIThreadInfo(thread uint32, info *GUIThreadInfo) (err error) { } func GetKeyboardLayout(tid uint32) (hkl Handle) { - r0, _, _ := syscall.Syscall(procGetKeyboardLayout.Addr(), 1, uintptr(tid), 0, 0) + r0, _, _ := syscall.SyscallN(procGetKeyboardLayout.Addr(), uintptr(tid)) hkl = Handle(r0) return } func GetShellWindow() (shellWindow HWND) { - r0, _, _ := syscall.Syscall(procGetShellWindow.Addr(), 0, 0, 0, 0) + r0, _, _ := syscall.SyscallN(procGetShellWindow.Addr()) shellWindow = HWND(r0) return } func GetWindowThreadProcessId(hwnd HWND, pid *uint32) (tid uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetWindowThreadProcessId.Addr(), 2, uintptr(hwnd), uintptr(unsafe.Pointer(pid)), 0) + r0, _, e1 := syscall.SyscallN(procGetWindowThreadProcessId.Addr(), uintptr(hwnd), uintptr(unsafe.Pointer(pid))) tid = uint32(r0) if tid == 0 { err = errnoErr(e1) @@ -4218,25 +4218,25 @@ func GetWindowThreadProcessId(hwnd HWND, pid *uint32) (tid uint32, err error) { } func IsWindow(hwnd HWND) (isWindow bool) { - r0, _, _ := syscall.Syscall(procIsWindow.Addr(), 1, uintptr(hwnd), 0, 0) + r0, _, _ := syscall.SyscallN(procIsWindow.Addr(), uintptr(hwnd)) isWindow = r0 != 0 return } func IsWindowUnicode(hwnd HWND) (isUnicode bool) { - r0, _, _ := syscall.Syscall(procIsWindowUnicode.Addr(), 1, uintptr(hwnd), 0, 0) + r0, _, _ := syscall.SyscallN(procIsWindowUnicode.Addr(), uintptr(hwnd)) isUnicode = r0 != 0 return } func IsWindowVisible(hwnd HWND) (isVisible bool) { - r0, _, _ := syscall.Syscall(procIsWindowVisible.Addr(), 1, uintptr(hwnd), 0, 0) + r0, _, _ := syscall.SyscallN(procIsWindowVisible.Addr(), uintptr(hwnd)) isVisible = r0 != 0 return } func LoadKeyboardLayout(name *uint16, flags uint32) (hkl Handle, err error) { - r0, _, e1 := syscall.Syscall(procLoadKeyboardLayoutW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(flags), 0) + r0, _, e1 := syscall.SyscallN(procLoadKeyboardLayoutW.Addr(), uintptr(unsafe.Pointer(name)), uintptr(flags)) hkl = Handle(r0) if hkl == 0 { err = errnoErr(e1) @@ -4245,7 +4245,7 @@ func LoadKeyboardLayout(name *uint16, flags uint32) (hkl Handle, err error) { } func MessageBox(hwnd HWND, text *uint16, caption *uint16, boxtype uint32) (ret int32, err error) { - r0, _, e1 := syscall.Syscall6(procMessageBoxW.Addr(), 4, uintptr(hwnd), uintptr(unsafe.Pointer(text)), uintptr(unsafe.Pointer(caption)), uintptr(boxtype), 0, 0) + r0, _, e1 := syscall.SyscallN(procMessageBoxW.Addr(), uintptr(hwnd), uintptr(unsafe.Pointer(text)), uintptr(unsafe.Pointer(caption)), uintptr(boxtype)) ret = int32(r0) if ret == 0 { err = errnoErr(e1) @@ -4254,13 +4254,13 @@ func MessageBox(hwnd HWND, text *uint16, caption *uint16, boxtype uint32) (ret i } func ToUnicodeEx(vkey uint32, scancode uint32, keystate *byte, pwszBuff *uint16, cchBuff int32, flags uint32, hkl Handle) (ret int32) { - r0, _, _ := syscall.Syscall9(procToUnicodeEx.Addr(), 7, uintptr(vkey), uintptr(scancode), uintptr(unsafe.Pointer(keystate)), uintptr(unsafe.Pointer(pwszBuff)), uintptr(cchBuff), uintptr(flags), uintptr(hkl), 0, 0) + r0, _, _ := syscall.SyscallN(procToUnicodeEx.Addr(), uintptr(vkey), uintptr(scancode), uintptr(unsafe.Pointer(keystate)), uintptr(unsafe.Pointer(pwszBuff)), uintptr(cchBuff), uintptr(flags), uintptr(hkl)) ret = int32(r0) return } func UnloadKeyboardLayout(hkl Handle) (err error) { - r1, _, e1 := syscall.Syscall(procUnloadKeyboardLayout.Addr(), 1, uintptr(hkl), 0, 0) + r1, _, e1 := syscall.SyscallN(procUnloadKeyboardLayout.Addr(), uintptr(hkl)) if r1 == 0 { err = errnoErr(e1) } @@ -4272,7 +4272,7 @@ func CreateEnvironmentBlock(block **uint16, token Token, inheritExisting bool) ( if inheritExisting { _p0 = 1 } - r1, _, e1 := syscall.Syscall(procCreateEnvironmentBlock.Addr(), 3, uintptr(unsafe.Pointer(block)), uintptr(token), uintptr(_p0)) + r1, _, e1 := syscall.SyscallN(procCreateEnvironmentBlock.Addr(), uintptr(unsafe.Pointer(block)), uintptr(token), uintptr(_p0)) if r1 == 0 { err = errnoErr(e1) } @@ -4280,7 +4280,7 @@ func CreateEnvironmentBlock(block **uint16, token Token, inheritExisting bool) ( } func DestroyEnvironmentBlock(block *uint16) (err error) { - r1, _, e1 := syscall.Syscall(procDestroyEnvironmentBlock.Addr(), 1, uintptr(unsafe.Pointer(block)), 0, 0) + r1, _, e1 := syscall.SyscallN(procDestroyEnvironmentBlock.Addr(), uintptr(unsafe.Pointer(block))) if r1 == 0 { err = errnoErr(e1) } @@ -4288,7 +4288,7 @@ func DestroyEnvironmentBlock(block *uint16) (err error) { } func GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) { - r1, _, e1 := syscall.Syscall(procGetUserProfileDirectoryW.Addr(), 3, uintptr(t), uintptr(unsafe.Pointer(dir)), uintptr(unsafe.Pointer(dirLen))) + r1, _, e1 := syscall.SyscallN(procGetUserProfileDirectoryW.Addr(), uintptr(t), uintptr(unsafe.Pointer(dir)), uintptr(unsafe.Pointer(dirLen))) if r1 == 0 { err = errnoErr(e1) } @@ -4305,7 +4305,7 @@ func GetFileVersionInfoSize(filename string, zeroHandle *Handle) (bufSize uint32 } func _GetFileVersionInfoSize(filename *uint16, zeroHandle *Handle) (bufSize uint32, err error) { - r0, _, e1 := syscall.Syscall(procGetFileVersionInfoSizeW.Addr(), 2, uintptr(unsafe.Pointer(filename)), uintptr(unsafe.Pointer(zeroHandle)), 0) + r0, _, e1 := syscall.SyscallN(procGetFileVersionInfoSizeW.Addr(), uintptr(unsafe.Pointer(filename)), uintptr(unsafe.Pointer(zeroHandle))) bufSize = uint32(r0) if bufSize == 0 { err = errnoErr(e1) @@ -4323,7 +4323,7 @@ func GetFileVersionInfo(filename string, handle uint32, bufSize uint32, buffer u } func _GetFileVersionInfo(filename *uint16, handle uint32, bufSize uint32, buffer unsafe.Pointer) (err error) { - r1, _, e1 := syscall.Syscall6(procGetFileVersionInfoW.Addr(), 4, uintptr(unsafe.Pointer(filename)), uintptr(handle), uintptr(bufSize), uintptr(buffer), 0, 0) + r1, _, e1 := syscall.SyscallN(procGetFileVersionInfoW.Addr(), uintptr(unsafe.Pointer(filename)), uintptr(handle), uintptr(bufSize), uintptr(buffer)) if r1 == 0 { err = errnoErr(e1) } @@ -4340,7 +4340,7 @@ func VerQueryValue(block unsafe.Pointer, subBlock string, pointerToBufferPointer } func _VerQueryValue(block unsafe.Pointer, subBlock *uint16, pointerToBufferPointer unsafe.Pointer, bufSize *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procVerQueryValueW.Addr(), 4, uintptr(block), uintptr(unsafe.Pointer(subBlock)), uintptr(pointerToBufferPointer), uintptr(unsafe.Pointer(bufSize)), 0, 0) + r1, _, e1 := syscall.SyscallN(procVerQueryValueW.Addr(), uintptr(block), uintptr(unsafe.Pointer(subBlock)), uintptr(pointerToBufferPointer), uintptr(unsafe.Pointer(bufSize))) if r1 == 0 { err = errnoErr(e1) } @@ -4348,7 +4348,7 @@ func _VerQueryValue(block unsafe.Pointer, subBlock *uint16, pointerToBufferPoint } func TimeBeginPeriod(period uint32) (err error) { - r1, _, e1 := syscall.Syscall(proctimeBeginPeriod.Addr(), 1, uintptr(period), 0, 0) + r1, _, e1 := syscall.SyscallN(proctimeBeginPeriod.Addr(), uintptr(period)) if r1 != 0 { err = errnoErr(e1) } @@ -4356,7 +4356,7 @@ func TimeBeginPeriod(period uint32) (err error) { } func TimeEndPeriod(period uint32) (err error) { - r1, _, e1 := syscall.Syscall(proctimeEndPeriod.Addr(), 1, uintptr(period), 0, 0) + r1, _, e1 := syscall.SyscallN(proctimeEndPeriod.Addr(), uintptr(period)) if r1 != 0 { err = errnoErr(e1) } @@ -4364,7 +4364,7 @@ func TimeEndPeriod(period uint32) (err error) { } func WinVerifyTrustEx(hwnd HWND, actionId *GUID, data *WinTrustData) (ret error) { - r0, _, _ := syscall.Syscall(procWinVerifyTrustEx.Addr(), 3, uintptr(hwnd), uintptr(unsafe.Pointer(actionId)), uintptr(unsafe.Pointer(data))) + r0, _, _ := syscall.SyscallN(procWinVerifyTrustEx.Addr(), uintptr(hwnd), uintptr(unsafe.Pointer(actionId)), uintptr(unsafe.Pointer(data))) if r0 != 0 { ret = syscall.Errno(r0) } @@ -4372,12 +4372,12 @@ func WinVerifyTrustEx(hwnd HWND, actionId *GUID, data *WinTrustData) (ret error) } func FreeAddrInfoW(addrinfo *AddrinfoW) { - syscall.Syscall(procFreeAddrInfoW.Addr(), 1, uintptr(unsafe.Pointer(addrinfo)), 0, 0) + syscall.SyscallN(procFreeAddrInfoW.Addr(), uintptr(unsafe.Pointer(addrinfo))) return } func GetAddrInfoW(nodename *uint16, servicename *uint16, hints *AddrinfoW, result **AddrinfoW) (sockerr error) { - r0, _, _ := syscall.Syscall6(procGetAddrInfoW.Addr(), 4, uintptr(unsafe.Pointer(nodename)), uintptr(unsafe.Pointer(servicename)), uintptr(unsafe.Pointer(hints)), uintptr(unsafe.Pointer(result)), 0, 0) + r0, _, _ := syscall.SyscallN(procGetAddrInfoW.Addr(), uintptr(unsafe.Pointer(nodename)), uintptr(unsafe.Pointer(servicename)), uintptr(unsafe.Pointer(hints)), uintptr(unsafe.Pointer(result))) if r0 != 0 { sockerr = syscall.Errno(r0) } @@ -4385,7 +4385,7 @@ func GetAddrInfoW(nodename *uint16, servicename *uint16, hints *AddrinfoW, resul } func WSACleanup() (err error) { - r1, _, e1 := syscall.Syscall(procWSACleanup.Addr(), 0, 0, 0, 0) + r1, _, e1 := syscall.SyscallN(procWSACleanup.Addr()) if r1 == socket_error { err = errnoErr(e1) } @@ -4393,7 +4393,7 @@ func WSACleanup() (err error) { } func WSADuplicateSocket(s Handle, processID uint32, info *WSAProtocolInfo) (err error) { - r1, _, e1 := syscall.Syscall(procWSADuplicateSocketW.Addr(), 3, uintptr(s), uintptr(processID), uintptr(unsafe.Pointer(info))) + r1, _, e1 := syscall.SyscallN(procWSADuplicateSocketW.Addr(), uintptr(s), uintptr(processID), uintptr(unsafe.Pointer(info))) if r1 != 0 { err = errnoErr(e1) } @@ -4401,7 +4401,7 @@ func WSADuplicateSocket(s Handle, processID uint32, info *WSAProtocolInfo) (err } func WSAEnumProtocols(protocols *int32, protocolBuffer *WSAProtocolInfo, bufferLength *uint32) (n int32, err error) { - r0, _, e1 := syscall.Syscall(procWSAEnumProtocolsW.Addr(), 3, uintptr(unsafe.Pointer(protocols)), uintptr(unsafe.Pointer(protocolBuffer)), uintptr(unsafe.Pointer(bufferLength))) + r0, _, e1 := syscall.SyscallN(procWSAEnumProtocolsW.Addr(), uintptr(unsafe.Pointer(protocols)), uintptr(unsafe.Pointer(protocolBuffer)), uintptr(unsafe.Pointer(bufferLength))) n = int32(r0) if n == -1 { err = errnoErr(e1) @@ -4414,7 +4414,7 @@ func WSAGetOverlappedResult(h Handle, o *Overlapped, bytes *uint32, wait bool, f if wait { _p0 = 1 } - r1, _, e1 := syscall.Syscall6(procWSAGetOverlappedResult.Addr(), 5, uintptr(h), uintptr(unsafe.Pointer(o)), uintptr(unsafe.Pointer(bytes)), uintptr(_p0), uintptr(unsafe.Pointer(flags)), 0) + r1, _, e1 := syscall.SyscallN(procWSAGetOverlappedResult.Addr(), uintptr(h), uintptr(unsafe.Pointer(o)), uintptr(unsafe.Pointer(bytes)), uintptr(_p0), uintptr(unsafe.Pointer(flags))) if r1 == 0 { err = errnoErr(e1) } @@ -4422,7 +4422,7 @@ func WSAGetOverlappedResult(h Handle, o *Overlapped, bytes *uint32, wait bool, f } func WSAIoctl(s Handle, iocc uint32, inbuf *byte, cbif uint32, outbuf *byte, cbob uint32, cbbr *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) { - r1, _, e1 := syscall.Syscall9(procWSAIoctl.Addr(), 9, uintptr(s), uintptr(iocc), uintptr(unsafe.Pointer(inbuf)), uintptr(cbif), uintptr(unsafe.Pointer(outbuf)), uintptr(cbob), uintptr(unsafe.Pointer(cbbr)), uintptr(unsafe.Pointer(overlapped)), uintptr(completionRoutine)) + r1, _, e1 := syscall.SyscallN(procWSAIoctl.Addr(), uintptr(s), uintptr(iocc), uintptr(unsafe.Pointer(inbuf)), uintptr(cbif), uintptr(unsafe.Pointer(outbuf)), uintptr(cbob), uintptr(unsafe.Pointer(cbbr)), uintptr(unsafe.Pointer(overlapped)), uintptr(completionRoutine)) if r1 == socket_error { err = errnoErr(e1) } @@ -4430,7 +4430,7 @@ func WSAIoctl(s Handle, iocc uint32, inbuf *byte, cbif uint32, outbuf *byte, cbo } func WSALookupServiceBegin(querySet *WSAQUERYSET, flags uint32, handle *Handle) (err error) { - r1, _, e1 := syscall.Syscall(procWSALookupServiceBeginW.Addr(), 3, uintptr(unsafe.Pointer(querySet)), uintptr(flags), uintptr(unsafe.Pointer(handle))) + r1, _, e1 := syscall.SyscallN(procWSALookupServiceBeginW.Addr(), uintptr(unsafe.Pointer(querySet)), uintptr(flags), uintptr(unsafe.Pointer(handle))) if r1 == socket_error { err = errnoErr(e1) } @@ -4438,7 +4438,7 @@ func WSALookupServiceBegin(querySet *WSAQUERYSET, flags uint32, handle *Handle) } func WSALookupServiceEnd(handle Handle) (err error) { - r1, _, e1 := syscall.Syscall(procWSALookupServiceEnd.Addr(), 1, uintptr(handle), 0, 0) + r1, _, e1 := syscall.SyscallN(procWSALookupServiceEnd.Addr(), uintptr(handle)) if r1 == socket_error { err = errnoErr(e1) } @@ -4446,7 +4446,7 @@ func WSALookupServiceEnd(handle Handle) (err error) { } func WSALookupServiceNext(handle Handle, flags uint32, size *int32, querySet *WSAQUERYSET) (err error) { - r1, _, e1 := syscall.Syscall6(procWSALookupServiceNextW.Addr(), 4, uintptr(handle), uintptr(flags), uintptr(unsafe.Pointer(size)), uintptr(unsafe.Pointer(querySet)), 0, 0) + r1, _, e1 := syscall.SyscallN(procWSALookupServiceNextW.Addr(), uintptr(handle), uintptr(flags), uintptr(unsafe.Pointer(size)), uintptr(unsafe.Pointer(querySet))) if r1 == socket_error { err = errnoErr(e1) } @@ -4454,7 +4454,7 @@ func WSALookupServiceNext(handle Handle, flags uint32, size *int32, querySet *WS } func WSARecv(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, overlapped *Overlapped, croutine *byte) (err error) { - r1, _, e1 := syscall.Syscall9(procWSARecv.Addr(), 7, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)), 0, 0) + r1, _, e1 := syscall.SyscallN(procWSARecv.Addr(), uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine))) if r1 == socket_error { err = errnoErr(e1) } @@ -4462,7 +4462,7 @@ func WSARecv(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32 } func WSARecvFrom(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, from *RawSockaddrAny, fromlen *int32, overlapped *Overlapped, croutine *byte) (err error) { - r1, _, e1 := syscall.Syscall9(procWSARecvFrom.Addr(), 9, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine))) + r1, _, e1 := syscall.SyscallN(procWSARecvFrom.Addr(), uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine))) if r1 == socket_error { err = errnoErr(e1) } @@ -4470,7 +4470,7 @@ func WSARecvFrom(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *ui } func WSASend(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, overlapped *Overlapped, croutine *byte) (err error) { - r1, _, e1 := syscall.Syscall9(procWSASend.Addr(), 7, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(sent)), uintptr(flags), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)), 0, 0) + r1, _, e1 := syscall.SyscallN(procWSASend.Addr(), uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(sent)), uintptr(flags), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine))) if r1 == socket_error { err = errnoErr(e1) } @@ -4478,7 +4478,7 @@ func WSASend(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, } func WSASendTo(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, to *RawSockaddrAny, tolen int32, overlapped *Overlapped, croutine *byte) (err error) { - r1, _, e1 := syscall.Syscall9(procWSASendTo.Addr(), 9, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(sent)), uintptr(flags), uintptr(unsafe.Pointer(to)), uintptr(tolen), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine))) + r1, _, e1 := syscall.SyscallN(procWSASendTo.Addr(), uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(sent)), uintptr(flags), uintptr(unsafe.Pointer(to)), uintptr(tolen), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine))) if r1 == socket_error { err = errnoErr(e1) } @@ -4486,7 +4486,7 @@ func WSASendTo(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32 } func WSASocket(af int32, typ int32, protocol int32, protoInfo *WSAProtocolInfo, group uint32, flags uint32) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall6(procWSASocketW.Addr(), 6, uintptr(af), uintptr(typ), uintptr(protocol), uintptr(unsafe.Pointer(protoInfo)), uintptr(group), uintptr(flags)) + r0, _, e1 := syscall.SyscallN(procWSASocketW.Addr(), uintptr(af), uintptr(typ), uintptr(protocol), uintptr(unsafe.Pointer(protoInfo)), uintptr(group), uintptr(flags)) handle = Handle(r0) if handle == InvalidHandle { err = errnoErr(e1) @@ -4495,7 +4495,7 @@ func WSASocket(af int32, typ int32, protocol int32, protoInfo *WSAProtocolInfo, } func WSAStartup(verreq uint32, data *WSAData) (sockerr error) { - r0, _, _ := syscall.Syscall(procWSAStartup.Addr(), 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0) + r0, _, _ := syscall.SyscallN(procWSAStartup.Addr(), uintptr(verreq), uintptr(unsafe.Pointer(data))) if r0 != 0 { sockerr = syscall.Errno(r0) } @@ -4503,7 +4503,7 @@ func WSAStartup(verreq uint32, data *WSAData) (sockerr error) { } func bind(s Handle, name unsafe.Pointer, namelen int32) (err error) { - r1, _, e1 := syscall.Syscall(procbind.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen)) + r1, _, e1 := syscall.SyscallN(procbind.Addr(), uintptr(s), uintptr(name), uintptr(namelen)) if r1 == socket_error { err = errnoErr(e1) } @@ -4511,7 +4511,7 @@ func bind(s Handle, name unsafe.Pointer, namelen int32) (err error) { } func Closesocket(s Handle) (err error) { - r1, _, e1 := syscall.Syscall(procclosesocket.Addr(), 1, uintptr(s), 0, 0) + r1, _, e1 := syscall.SyscallN(procclosesocket.Addr(), uintptr(s)) if r1 == socket_error { err = errnoErr(e1) } @@ -4519,7 +4519,7 @@ func Closesocket(s Handle) (err error) { } func connect(s Handle, name unsafe.Pointer, namelen int32) (err error) { - r1, _, e1 := syscall.Syscall(procconnect.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen)) + r1, _, e1 := syscall.SyscallN(procconnect.Addr(), uintptr(s), uintptr(name), uintptr(namelen)) if r1 == socket_error { err = errnoErr(e1) } @@ -4536,7 +4536,7 @@ func GetHostByName(name string) (h *Hostent, err error) { } func _GetHostByName(name *byte) (h *Hostent, err error) { - r0, _, e1 := syscall.Syscall(procgethostbyname.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0) + r0, _, e1 := syscall.SyscallN(procgethostbyname.Addr(), uintptr(unsafe.Pointer(name))) h = (*Hostent)(unsafe.Pointer(r0)) if h == nil { err = errnoErr(e1) @@ -4545,7 +4545,7 @@ func _GetHostByName(name *byte) (h *Hostent, err error) { } func getpeername(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) { - r1, _, e1 := syscall.Syscall(procgetpeername.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + r1, _, e1 := syscall.SyscallN(procgetpeername.Addr(), uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) if r1 == socket_error { err = errnoErr(e1) } @@ -4562,7 +4562,7 @@ func GetProtoByName(name string) (p *Protoent, err error) { } func _GetProtoByName(name *byte) (p *Protoent, err error) { - r0, _, e1 := syscall.Syscall(procgetprotobyname.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0) + r0, _, e1 := syscall.SyscallN(procgetprotobyname.Addr(), uintptr(unsafe.Pointer(name))) p = (*Protoent)(unsafe.Pointer(r0)) if p == nil { err = errnoErr(e1) @@ -4585,7 +4585,7 @@ func GetServByName(name string, proto string) (s *Servent, err error) { } func _GetServByName(name *byte, proto *byte) (s *Servent, err error) { - r0, _, e1 := syscall.Syscall(procgetservbyname.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(proto)), 0) + r0, _, e1 := syscall.SyscallN(procgetservbyname.Addr(), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(proto))) s = (*Servent)(unsafe.Pointer(r0)) if s == nil { err = errnoErr(e1) @@ -4594,7 +4594,7 @@ func _GetServByName(name *byte, proto *byte) (s *Servent, err error) { } func getsockname(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) { - r1, _, e1 := syscall.Syscall(procgetsockname.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) + r1, _, e1 := syscall.SyscallN(procgetsockname.Addr(), uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) if r1 == socket_error { err = errnoErr(e1) } @@ -4602,7 +4602,7 @@ func getsockname(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) { } func Getsockopt(s Handle, level int32, optname int32, optval *byte, optlen *int32) (err error) { - r1, _, e1 := syscall.Syscall6(procgetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(unsafe.Pointer(optlen)), 0) + r1, _, e1 := syscall.SyscallN(procgetsockopt.Addr(), uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(unsafe.Pointer(optlen))) if r1 == socket_error { err = errnoErr(e1) } @@ -4610,7 +4610,7 @@ func Getsockopt(s Handle, level int32, optname int32, optval *byte, optlen *int3 } func listen(s Handle, backlog int32) (err error) { - r1, _, e1 := syscall.Syscall(proclisten.Addr(), 2, uintptr(s), uintptr(backlog), 0) + r1, _, e1 := syscall.SyscallN(proclisten.Addr(), uintptr(s), uintptr(backlog)) if r1 == socket_error { err = errnoErr(e1) } @@ -4618,7 +4618,7 @@ func listen(s Handle, backlog int32) (err error) { } func Ntohs(netshort uint16) (u uint16) { - r0, _, _ := syscall.Syscall(procntohs.Addr(), 1, uintptr(netshort), 0, 0) + r0, _, _ := syscall.SyscallN(procntohs.Addr(), uintptr(netshort)) u = uint16(r0) return } @@ -4628,7 +4628,7 @@ func recvfrom(s Handle, buf []byte, flags int32, from *RawSockaddrAny, fromlen * if len(buf) > 0 { _p0 = &buf[0] } - r0, _, e1 := syscall.Syscall6(procrecvfrom.Addr(), 6, uintptr(s), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))) + r0, _, e1 := syscall.SyscallN(procrecvfrom.Addr(), uintptr(s), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(flags), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen))) n = int32(r0) if n == -1 { err = errnoErr(e1) @@ -4641,7 +4641,7 @@ func sendto(s Handle, buf []byte, flags int32, to unsafe.Pointer, tolen int32) ( if len(buf) > 0 { _p0 = &buf[0] } - r1, _, e1 := syscall.Syscall6(procsendto.Addr(), 6, uintptr(s), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(flags), uintptr(to), uintptr(tolen)) + r1, _, e1 := syscall.SyscallN(procsendto.Addr(), uintptr(s), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(flags), uintptr(to), uintptr(tolen)) if r1 == socket_error { err = errnoErr(e1) } @@ -4649,7 +4649,7 @@ func sendto(s Handle, buf []byte, flags int32, to unsafe.Pointer, tolen int32) ( } func Setsockopt(s Handle, level int32, optname int32, optval *byte, optlen int32) (err error) { - r1, _, e1 := syscall.Syscall6(procsetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(optlen), 0) + r1, _, e1 := syscall.SyscallN(procsetsockopt.Addr(), uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(optlen)) if r1 == socket_error { err = errnoErr(e1) } @@ -4657,7 +4657,7 @@ func Setsockopt(s Handle, level int32, optname int32, optval *byte, optlen int32 } func shutdown(s Handle, how int32) (err error) { - r1, _, e1 := syscall.Syscall(procshutdown.Addr(), 2, uintptr(s), uintptr(how), 0) + r1, _, e1 := syscall.SyscallN(procshutdown.Addr(), uintptr(s), uintptr(how)) if r1 == socket_error { err = errnoErr(e1) } @@ -4665,7 +4665,7 @@ func shutdown(s Handle, how int32) (err error) { } func socket(af int32, typ int32, protocol int32) (handle Handle, err error) { - r0, _, e1 := syscall.Syscall(procsocket.Addr(), 3, uintptr(af), uintptr(typ), uintptr(protocol)) + r0, _, e1 := syscall.SyscallN(procsocket.Addr(), uintptr(af), uintptr(typ), uintptr(protocol)) handle = Handle(r0) if handle == InvalidHandle { err = errnoErr(e1) @@ -4674,7 +4674,7 @@ func socket(af int32, typ int32, protocol int32) (handle Handle, err error) { } func WTSEnumerateSessions(handle Handle, reserved uint32, version uint32, sessions **WTS_SESSION_INFO, count *uint32) (err error) { - r1, _, e1 := syscall.Syscall6(procWTSEnumerateSessionsW.Addr(), 5, uintptr(handle), uintptr(reserved), uintptr(version), uintptr(unsafe.Pointer(sessions)), uintptr(unsafe.Pointer(count)), 0) + r1, _, e1 := syscall.SyscallN(procWTSEnumerateSessionsW.Addr(), uintptr(handle), uintptr(reserved), uintptr(version), uintptr(unsafe.Pointer(sessions)), uintptr(unsafe.Pointer(count))) if r1 == 0 { err = errnoErr(e1) } @@ -4682,12 +4682,12 @@ func WTSEnumerateSessions(handle Handle, reserved uint32, version uint32, sessio } func WTSFreeMemory(ptr uintptr) { - syscall.Syscall(procWTSFreeMemory.Addr(), 1, uintptr(ptr), 0, 0) + syscall.SyscallN(procWTSFreeMemory.Addr(), uintptr(ptr)) return } func WTSQueryUserToken(session uint32, token *Token) (err error) { - r1, _, e1 := syscall.Syscall(procWTSQueryUserToken.Addr(), 2, uintptr(session), uintptr(unsafe.Pointer(token)), 0) + r1, _, e1 := syscall.SyscallN(procWTSQueryUserToken.Addr(), uintptr(session), uintptr(unsafe.Pointer(token))) if r1 == 0 { err = errnoErr(e1) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 086216d564..6cfef450d0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -92,6 +92,10 @@ github.com/alexedwards/argon2id # github.com/amoghe/go-crypt v0.0.0-20220222110647-20eada5f5964 ## explicit github.com/amoghe/go-crypt +# github.com/antithesishq/antithesis-sdk-go v0.4.3-default-no-op +## explicit; go 1.20 +github.com/antithesishq/antithesis-sdk-go/assert +github.com/antithesishq/antithesis-sdk-go/internal # github.com/armon/go-radix v1.0.0 ## explicit github.com/armon/go-radix @@ -1053,8 +1057,8 @@ github.com/munnerz/goautoneg # github.com/nats-io/jwt/v2 v2.7.4 ## explicit; go 1.23.0 github.com/nats-io/jwt/v2 -# github.com/nats-io/nats-server/v2 v2.11.8 -## explicit; go 1.23.0 +# github.com/nats-io/nats-server/v2 v2.11.9 +## explicit; go 1.24.0 github.com/nats-io/nats-server/v2/conf github.com/nats-io/nats-server/v2/internal/fastrand github.com/nats-io/nats-server/v2/internal/ldap @@ -1270,7 +1274,7 @@ github.com/open-policy-agent/opa/v1/version # github.com/opencloud-eu/libre-graph-api-go v1.0.8-0.20250724122329-41ba6b191e76 ## explicit; go 1.18 github.com/opencloud-eu/libre-graph-api-go -# github.com/opencloud-eu/reva/v2 v2.37.1-0.20250909074412-f272eeaa2674 +# github.com/opencloud-eu/reva/v2 v2.37.1-0.20250911072739-9e673e021dca ## explicit; go 1.24.1 github.com/opencloud-eu/reva/v2/cmd/revad/internal/grace github.com/opencloud-eu/reva/v2/cmd/revad/runtime @@ -1870,7 +1874,7 @@ github.com/sethvargo/go-diceware/diceware # github.com/sethvargo/go-password v0.3.1 ## explicit; go 1.21 github.com/sethvargo/go-password/password -# github.com/shamaton/msgpack/v2 v2.2.3 +# github.com/shamaton/msgpack/v2 v2.3.1 ## explicit; go 1.20 github.com/shamaton/msgpack/v2 github.com/shamaton/msgpack/v2/def @@ -2358,8 +2362,8 @@ golang.org/x/oauth2/internal golang.org/x/sync/errgroup golang.org/x/sync/semaphore golang.org/x/sync/singleflight -# golang.org/x/sys v0.35.0 -## explicit; go 1.23.0 +# golang.org/x/sys v0.36.0 +## explicit; go 1.24.0 golang.org/x/sys/cpu golang.org/x/sys/execabs golang.org/x/sys/plan9 @@ -2397,8 +2401,8 @@ golang.org/x/text/transform golang.org/x/text/unicode/bidi golang.org/x/text/unicode/norm golang.org/x/text/width -# golang.org/x/time v0.12.0 -## explicit; go 1.23.0 +# golang.org/x/time v0.13.0 +## explicit; go 1.24.0 golang.org/x/time/rate # golang.org/x/tools v0.36.0 ## explicit; go 1.23.0 From 1a6028e96a7153b08e608d1ba0bbb629c1dba142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Thu, 11 Sep 2025 10:40:55 +0200 Subject: [PATCH 10/11] drop unnecessary changelog file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- changelog/unreleased/fix-graceful-shutdown.md | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 changelog/unreleased/fix-graceful-shutdown.md diff --git a/changelog/unreleased/fix-graceful-shutdown.md b/changelog/unreleased/fix-graceful-shutdown.md deleted file mode 100644 index 3e596433c3..0000000000 --- a/changelog/unreleased/fix-graceful-shutdown.md +++ /dev/null @@ -1,6 +0,0 @@ -Bugfix: Fix the graceful shutdown - -Fix the graceful shutdown using the new ocis and reva runners. - -https://github.com/owncloud/ocis/pull/11295 -https://github.com/owncloud/ocis/issues/11170 \ No newline at end of file From 0814a60c7c982e677c12764d72da06f7818eafb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 12 Sep 2025 10:45:10 +0200 Subject: [PATCH 11/11] clarify log messages, fix exit code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- opencloud/pkg/runtime/service/service.go | 29 ++++++++++++++---------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/opencloud/pkg/runtime/service/service.go b/opencloud/pkg/runtime/service/service.go index 1310f11b77..d4281bf11f 100644 --- a/opencloud/pkg/runtime/service/service.go +++ b/opencloud/pkg/runtime/service/service.go @@ -434,8 +434,7 @@ func Start(ctx context.Context, o ...Option) error { }() // trapShutdownCtx will block on the context-done channel for interruptions. - trapShutdownCtx(s, srv, ctx) - return nil + return trapShutdownCtx(s, srv, ctx) } // scheduleServiceTokens adds service tokens to the service supervisor. @@ -502,31 +501,35 @@ func (s *Service) List(_ struct{}, reply *string) error { return nil } -func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) { +func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) error { <-ctx.Done() + s.Log.Info().Msg("starting graceful shutdown") + start := time.Now() wg := sync.WaitGroup{} wg.Add(1) go func() { defer wg.Done() ctx, cancel := context.WithTimeout(context.Background(), _defaultShutdownTimeoutDuration) defer cancel() + s.Log.Debug().Msg("starting runtime listener shutdown") if err := srv.Shutdown(ctx); err != nil { - s.Log.Error().Err(err).Msg("could not shutdown tcp listener") + s.Log.Error().Err(err).Msg("could not shutdown runtime listener") return } - s.Log.Info().Msg("tcp listener shutdown") + s.Log.Debug().Msg("runtime listener shutdown done") }() for sName := range s.serviceToken { for i := range s.serviceToken[sName] { wg.Add(1) go func() { - s.Log.Warn().Msgf("call supervisor RemoveAndWait for %s", sName) + s.Log.Debug().Str("service", sName).Msg("starting graceful shutdown for service") defer wg.Done() if err := s.Supervisor.RemoveAndWait(s.serviceToken[sName][i], _defaultShutdownTimeoutDuration); err != nil && !errors.Is(err, suture.ErrSupervisorNotRunning) { - s.Log.Error().Err(err).Str("service", sName).Msgf("terminating with signal: %+v", s) + s.Log.Error().Err(err).Str("service", sName).Msg("could not shutdown service") + return } - s.Log.Warn().Msgf("done supervisor RemoveAndWait for %s", sName) + s.Log.Debug().Str("service", sName).Msg("graceful shutdown for service done") }() } } @@ -539,10 +542,12 @@ func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) { select { case <-time.After(_defaultInterruptTimeoutDuration): - s.Log.Fatal().Msg("ocis graceful shutdown timeout reached, terminating") + s.Log.Error().Dur("timeoutDuration", _defaultInterruptTimeoutDuration).Msg("graceful shutdown timeout reached, terminating") + return errors.New("graceful shutdown timeout reached, terminating") case <-done: - s.Log.Info().Msg("all ocis services gracefully stopped") - return + duration := time.Since(start) + s.Log.Info().Dur("duration", duration).Msg("graceful shutdown done") + return nil } } @@ -574,7 +579,7 @@ func pingGateway(cfg *occfg.Config) error { n := b.NextBackOff() _, err := pool.GetGatewayServiceClient(cfg.Reva.Address) if err != nil && n > time.Second { - logger.New().Error().Err(err).Msgf("can't connect to gateway service, retrying in %s", n) + logger.New().Error().Err(err).Dur("backoff", n).Msg("can't connect to gateway service, retrying") } return err }