<commit_before>module Vagrant
  module LXC
    module Action
      class ClearForwardedPorts
        def initialize(app, env)
          @app = app
          @logger = Log4r::Logger.new("vagrant::lxc::action::clear_forwarded_ports")
        end

        def call(env)
          @env = env

          if redir_pids.any?
            env[:ui].info I18n.t("vagrant.actions.vm.clear_forward_ports.deleting")
            redir_pids.each do |pid|
              next unless is_redir_pid?(pid)
              @logger.debug "Killing pid #{pid}"
              system "sudo pkill -TERM -P #{pid}"
            end

            @logger.info "Removing redir pids files"
            remove_redir_pids
          else
            @logger.info "No redir pids found"
          end

          @app.call env
        end

        protected

        def redir_pids
          @redir_pids = Dir[@env[:machine].data_dir.join('pids').to_s + "/redir_*.pid"].map do |file|
            File.read(file).strip.chomp
          end
        end

        def is_redir_pid?(pid)
          @logger.debug "Checking if #{pid} is a redir process with `ps -o cmd= #{pid}`"
          `ps -o cmd= #{pid}`.strip.chomp =~ /redir/
        end

        def remove_redir_pids
          Dir[@env[:machine].data_dir.join('pids').to_s + "/redir_*.pid"].each do |file|
            File.delete file
          end
        end<commit_msg>clean redir pid with sudo only if port is < than 1024<commit_after>module Vagrant
  module LXC
    module Action
      class ClearForwardedPorts
        def initialize(app, env)
          @app = app
          @logger = Log4r::Logger.new("vagrant::lxc::action::clear_forwarded_ports")
        end

        def call(env)
          @env = env

          if redir_pids.any?
            env[:ui].info I18n.t("vagrant.actions.vm.clear_forward_ports.deleting")
            redir_pids.each do |pid|
              next unless is_redir_pid?(pid[0])
              @logger.debug "Killing pid #{pid[0]}"
	      if pid[1]
		system  "sudo pkill -TERM -P #{pid[0]}"
	      else
		system "pkill -TERM -P #{pid[0]}"
	      end
            end

            @logger.info "Removing redir pids files"
            remove_redir_pids
          else
            @logger.info "No redir pids found"
          end

          @app.call env
        end

        protected

        def redir_pids
          @redir_pids = Dir[@env[:machine].data_dir.join('pids').to_s + "/redir_*.pid"].map do |file|
	     port_number = file.split(/[^\d]/).join
	     privileged_port = true if Integer(port_number) > 1024
	     a = [ File.read(file).strip.chomp , privileged_port ]
          end
        end

        def is_redir_pid?(pid)
          @logger.debug "Checking if #{pid} is a redir process with `ps -o cmd= #{pid}`"
          `ps -o cmd= #{pid}`.strip.chomp =~ /redir/
        end

        def remove_redir_pids
          Dir[@env[:machine].data_dir.join('pids').to_s + "/redir_*.pid"].each do |file|
            File.delete file
          end
        end
{'fraction_non_alphanumeric': 0.11511511511511512, 'fraction_numerical': 0.006339673006339673, 'mean_word_length': 1.7254545454545454, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5758063', 'n_tokens_mistral': 997, 'n_tokens_neox': 965, 'n_words': 225}