#!/bin/bash

# Copyright (C) 2009 Google Inc.

cat <<EOF
#!/bin/bash

# Copyright (C) 2009 Google Inc.

# This file is automatically generated, do not edit!

# Log all stderr output from nxserver-login and children
# (should only be critical errors)

PROGNAME=\$(basename "\$0")
PRIORITY=""
export PYTHONPATH="\$PYTHONPATH:$2"

log() {
  logger -t "\$PROGNAME[\$\$]" -p "user.\${PRIORITY:-crit}" -- "\$@"
}

PRIORITY=debug log "Called with args: \$*"

# Duplicate stdout to fd 3
exec 3>&1
exec $1 "\$@" 2>&1 >&3 | {
  PRIORITY=debug log "Started $1 \$*"
  while read; do
    log "\$REPLY"
  done
  PRIORITY=debug log "EOF on stderr, exiting"
}
EOF