Skip to content

Commit

Permalink
Fix minor bugs (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
scudette authored Feb 10, 2020
1 parent d0d3c50 commit 0022e2c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
13 changes: 8 additions & 5 deletions bin/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ func doFrontend() {
ctx, cancel := install_sig_handler()
defer cancel()

startFrontend(ctx, wg, config_obj)
server, err := startFrontend(ctx, wg, config_obj)
kingpin.FatalIfError(err, "startFrontend")
defer server.Close()

// Wait here until everything is done.
wg.Wait()
Expand All @@ -61,7 +63,7 @@ func doFrontend() {
func startFrontend(
ctx context.Context,
wg *sync.WaitGroup,
config_obj *config_proto.Config) {
config_obj *config_proto.Config) (*server.Server, error) {
logger := logging.GetLogger(config_obj, &logging.FrontendComponent)
logger.WithFields(logrus.Fields{
"version": config_obj.Version.Version,
Expand Down Expand Up @@ -113,7 +115,6 @@ func startFrontend(
// Create a new server
server_obj, err = server.NewServer(config_obj)
kingpin.FatalIfError(err, "Unable to create server")
defer server_obj.Close()

notifier = server_obj.NotificationPool
}
Expand All @@ -123,7 +124,7 @@ func startFrontend(
ctx, wg, config_obj, notifier)
if err != nil {
logger.Error("Failed starting services: ", err)
return
return nil, err
}

// Start monitoring.
Expand All @@ -146,7 +147,7 @@ func startFrontend(
// The below configures the frontend or gui services.
if !config_obj.ServerServices.FrontendServer &&
!config_obj.ServerServices.GuiServer {
return
return server_obj, nil
}

// Are we in autocert mode? There are special requirements in
Expand All @@ -164,6 +165,8 @@ func startFrontend(
} else {
startSelfSignedFrontend(ctx, wg, config_obj, server_obj)
}

return server_obj, nil
}

// When the GUI and Frontend share the same port we start them with
Expand Down
7 changes: 6 additions & 1 deletion bin/server_service_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,12 @@ func NewVelociraptorServerService(name string) (
defer cancel()

elog.Info(1, fmt.Sprintf("%s service started", name))
startFrontend(ctx, wg, config_obj)
server, err := startFrontend(ctx, wg, config_obj)
if err != nil {
elog.Info(1, fmt.Sprintf("%s service error", err))
return
}
defer server.Close()

// Wait here until everything is done.
wg.Wait()
Expand Down
11 changes: 9 additions & 2 deletions services/server_artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ func (self *ServerArtifactsRunner) Start(
self.config_obj, &logging.FrontendComponent)

// Listen for notifications from the server.
notification, _ := self.notifier.Listen(source)
notification, err := self.notifier.Listen(source)
if err != nil {
logger.Error("ServerArtifactsRunner", err)
return
}
defer self.notifier.Notify(source)

self.process(ctx, wg)
Expand Down Expand Up @@ -219,7 +223,7 @@ func (self *ServerArtifactsRunner) runQuery(

// All the queries will use the same scope. This allows one
// query to define functions for the next query in order.
for row_idx, query := range arg.Query {
for _, query := range arg.Query {
vql, err := vfilter.Parse(query.VQL)
if err != nil {
return err
Expand Down Expand Up @@ -253,6 +257,8 @@ func (self *ServerArtifactsRunner) runQuery(
}
}

row_idx := 0

process_query:
for {
select {
Expand All @@ -276,6 +282,7 @@ func (self *ServerArtifactsRunner) runQuery(
break process_query
}
if write_chan != nil {
row_idx += 1
write_chan <- row
}
}
Expand Down

0 comments on commit 0022e2c

Please sign in to comment.