Sha256: af1020683e67eb44fa92dbd49ca1ccb4642199a917b03c84018df7f4ca618306

Contents?: true

Size: 1.28 KB

Versions: 11

Compression:

Stored size: 1.28 KB

Contents

# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

require 'contrast/components/interface'

module Contrast
  module Utils
    # Simple utility used to make OS calls and determine state. For that state
    # which will not change at runtime, such as the operating system, the
    # Utility memozies to avoid multiple lookups.
    module OS
      include Contrast::Components::Interface
      access_component :scope

      class << self
        def running?
          result = false
          with_contrast_scope do
            process = `ps aux | grep contrast-servic[e]`
            processes = process.split("\n")
            result = !processes.empty? && processes.any? { |process_descriptor| !process_descriptor.include?('grep') }
          end
          result
        end

        # check if service was killed and is a zombie process
        # returns an array of zombie process PIDs as strings; empty array if there are none
        def zombie_pids
          with_contrast_scope do
            zombie_pid_list = `ps aux | grep contrast-servic[e] | grep Z | awk '{print $2}'` # retrieve pid of service processes
            zombie_pid_list.split("\n")
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
contrast-agent-4.4.1 lib/contrast/utils/os.rb
contrast-agent-4.4.0 lib/contrast/utils/os.rb
contrast-agent-4.3.2 lib/contrast/utils/os.rb
contrast-agent-4.3.1 lib/contrast/utils/os.rb
contrast-agent-4.3.0 lib/contrast/utils/os.rb
contrast-agent-4.2.0 lib/contrast/utils/os.rb
contrast-agent-4.1.0 lib/contrast/utils/os.rb
contrast-agent-4.0.0 lib/contrast/utils/os.rb
contrast-agent-3.16.0 lib/contrast/utils/os.rb
contrast-agent-3.15.0 lib/contrast/utils/os.rb
contrast-agent-3.14.0 lib/contrast/utils/os.rb