This is the mail archive of the cygwin-developers mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Avoid collisions between parallel installations of Cygwin


On Oct 21 05:59, Eric Blake wrote:
> According to Corinna Vinschen on 10/21/2009 4:16 AM:
> > The data starts at 0x1f7cb4, so the offset is 50 bytes.  What POSIX
> > tool allows to stream a file from stdin to stdout while changing
> > specified binary data?  Perl, as usual, I assume, but is there some
> > simple already existing tool for that?
> 
> Well, a combination of simple tools.  A chain of dd commands in a pipeline
> will work from a shell script.  I just tested that:
> 
> echo 123456789012345678901234567890 > a
> { dd bs=1 count=10; printf 'binary data'; dd bs=1 skip=11; } < a > b
> 
> replaced offsets 10-21 of file 'a' with "binary data" in file 'b'.

Nice.  I created a simple shell script which can do the job.  It even
allows to replace the cygwin1.dll in /bin on the fly.  My script name of
choice is "enable-unique-object-names":

  $ enable-unique-object-names
  Usage: enable-unique-object-names [show|yes|no] [path-to-cygwin-DLL]
  $ enable-unique-object-names show
  Default to /bin/cygwin1.dll
  yes
  $ enable-unique-object-names no
  $ enable-unique-object-names show
  Default to /bin/cygwin1.dll
  no

Do you think this is sufficient for now?  In theory, if we use a specific
layout of the datastructure using unambiguous magic entry strings, there
wouldn't be a reason to use the .rsrc section at all.  The DLL could
simply read the values from a global datastructure in the .data section.
That would speed up the code in init_installation_root() a lot since it
won't need this FindResource/LoadResource/LockResource stuff.


Corinna


===== SNIP =====
#!/bin/bash
if [ -z "$1" ]
then
  echo "Usage: $0 [show|yes|no] [path-to-cygwin-DLL]"
  exit 0
fi
if [ -z "$2" ]
then
  file="/bin/cygwin1.dll" || file="$2"
  echo "Default to ${file}"
else
  file="$2"
fi
if [ ! -f "$file" ]
then
  echo "$0: ${file}: No such file"
  exit 1
fi
tmp="/tmp/"$(basename "${file}")".$$"

offset=$(strings -el -td "$file" | awk '/CYGPROPS/{ print $1; }')
offset=$(expr $offset + 50)
case $1 in
  s | show)
    val=$(od -j $offset -N 4 -tu4 "$file" | awk '{print $2;}')
    [ $val -eq 0 ] && echo yes || echo no
    exit 0
    ;;
  y | yes | n | no)
    { dd bs=$offset count=1 2>/dev/null
      case "$1" in
        y*) printf '\0\0\0\0' ;;
        *)  printf '\1\0\0\0' ;;
      esac
      dd bs=4 skip=1 2>/dev/null
    } < "$file" > "$tmp"
    ;;
  *)
    echo "Usage: $0 [show|yes|no] [path-to-cygwin-DLL]"
    exit 1
esac
# Only the yes/no cases will get to this point...
chmod 755 "$tmp"
origfile=$(basename "$file")".orig.$$"
winfile=$(cygpath -wa "$file")
wintmp=$(cygpath -wa "$tmp")
cmd /c "ren ${winfile} ${origfile} & copy ${wintmp} ${winfile} > NUL: & del ${wintmp}"
chmod 755 "$file"
rm "${file}.orig.$$"
===== SNAP =====



-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]