<commit_before>#!/bin/bash

# This script exports a common::run function which builds
# and runs mounttables and other daemons needed to run and
# test the Veyron Browser.
# The ports on which to run these services should be passed
# as arguments to the function.
# This script shuts down these services on exit.
# TODO(aghassemi) This script is becoming too complicated and
# big for shell scripting, switch to a JavaScript or Go implementation

source "${VEYRON_ROOT}/scripts/lib/shell.sh"

trap 'terminate force' INT TERM
trap 'terminate' EXIT

# PIDS is a file that keeps track of PIDS of spawned services (one PID per line).
PIDS=$(shell::tmp_file)

# TERMINATING is a file that keeps track of whether we are in the the middle of terminating the script.
TERMINATING=$(shell::tmp_file)
echo "false" > "${TERMINATING}"

# We use temporary files to keep track if PIDs since subshells are isolated and
# can not access variables in parent's scope and we like to run services in subshells
# so we can easily track if they have exited or not.

# terminate is automatically called when receiving a signal or can be manually
# called from other functions to exit the script
# The string 'force' can be provided as the first argument to indicate whether
# we should kill the process and exit with an non-zero error code instead of
# the default behavior which is to wait for termination and exit with exit code 0
terminate() {
  # Indicate that we are terminating, reset the trap so it won't get called again and
  # throw out further output.
  echo "true" > "${TERMINATING}"
  trap - EXIT INT TERM
  exec &> /dev/null

  # Kill all the spawned processes.
  while read ID; do
    kill -KILL "${ID}" || true
  done < "${PIDS}"<commit_msg>browser: using "go list" to locate shell.sh<commit_after>#!/bin/bash

# This script exports a common::run function which builds
# and runs mounttables and other daemons needed to run and
# test the Veyron Browser.
# The ports on which to run these services should be passed
# as arguments to the function.
# This script shuts down these services on exit.
# TODO(aghassemi) This script is becoming too complicated and
# big for shell scripting, switch to a JavaScript or Go implementation

source "$(go list -f {{.Dir}} veyron.io/veyron/shell/lib)/shell.sh"

trap 'terminate force' INT TERM
trap 'terminate' EXIT

# PIDS is a file that keeps track of PIDS of spawned services (one PID per line).
PIDS=$(shell::tmp_file)

# TERMINATING is a file that keeps track of whether we are in the the middle of terminating the script.
TERMINATING=$(shell::tmp_file)
echo "false" > "${TERMINATING}"

# We use temporary files to keep track if PIDs since subshells are isolated and
# can not access variables in parent's scope and we like to run services in subshells
# so we can easily track if they have exited or not.

# terminate is automatically called when receiving a signal or can be manually
# called from other functions to exit the script
# The string 'force' can be provided as the first argument to indicate whether
# we should kill the process and exit with an non-zero error code instead of
# the default behavior which is to wait for termination and exit with exit code 0
terminate() {
  # Indicate that we are terminating, reset the trap so it won't get called again and
  # throw out further output.
  echo "true" > "${TERMINATING}"
  trap - EXIT INT TERM
  exec &> /dev/null

  # Kill all the spawned processes.
  while read ID; do
    kill -KILL "${ID}" || true
  done < "${PIDS}"
{'fraction_non_alphanumeric': 0.06763285024154589, 'fraction_numerical': 0.0005683432793407218, 'mean_word_length': 4.116279069767442, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '487206', 'n_tokens_mistral': 995, 'n_tokens_neox': 956, 'n_words': 533}