Professional Web Applications Themes

name pipe problem, quick question - Linux / Unix Administration

I'm trying to re-write a start up script for a game server (hl ds) and setup named-pipes (cmd-1, for input, and res-1, for output, in /home187/b/), but when I use the syntax in an example, it never actually runns ./hlds as far as I can see from ps -x after running the script (./tfcrun &), I just see a couple extra 'tfcrun's listed, where ther should be just one, and an instance of ./hlds. The pipes do seem to be created though: $ ls -l b | grep prw prw-r--r-- 1 187 187 0 Jun 11 00:58 cmd-1 prw-r--r-- 1 ...

  1. #1

    Default name pipe problem, quick question

    I'm trying to re-write a start up script for a game server (hl ds) and
    setup named-pipes (cmd-1, for input, and res-1, for output, in
    /home187/b/), but when I use the syntax in an example, it never actually
    runns ./hlds as far as I can see from ps -x after running the script
    (./tfcrun &), I just see a couple extra 'tfcrun's listed, where ther
    should be just one, and an instance of ./hlds.

    The pipes do seem to be created though:

    $ ls -l b | grep prw
    prw-r--r-- 1 187 187 0 Jun 11 00:58 cmd-1
    prw-r--r-- 1 187 187 0 Jun 11 00:58 res-1

    What am I doing wrong? (script is below)

    system info:

    $ uname -a
    FreeBSD alderaan.matchservers.com 4.6-RELEASE FreeBSD 4.6-RELEASE #0:
    Mon Dec 8 18:42:42 EST 2003
    [email]rootyoda.quakeserver.org[/email]:/usr/src/sys/compile/GENERIC i386

    $ echo thanks for any help
    thanks for any help

    $ cat tfcrun

    #!/bin/sh

    cd ~/hlds_l
    b='/home/187/b'

    rm $b/cmd-1
    mkfifo $b/cmd-1
    rm $b/res-1
    mkfifo $b/res-1

    while true
    do

    d=`date`
    echo "Starting TFC Server now ($d)." >> tfc.log


    echo "" > $b/cmd-1&
    echo "" > $b/res-1&
    #./hlds -game tfc -port 27015 +ip 206.216.122.21 +maxplayers 18 +map
    2fort
    ../hlds -game tfc -port 27015 +ip 206.216.122.21 +maxplayers 18 +map
    2fort < $b/cmd-1 > $b/res-1

    d=`date`
    echo "Server stopped for some reason...restarting ($d)" >> tfc.log

    sleep 20 # Wait 20 seconds after a crash, then restart.

    done

    $ exit
    logout


    187 Guest

  2. #2

    Default Re: name pipe problem, quick question

    in comp.unix.admin i read:
    >rm $b/cmd-1
    >mkfifo $b/cmd-1
    >rm $b/res-1
    >mkfifo $b/res-1
    [...]
    >echo "" > $b/cmd-1&
    your script stops here, waiting for something to open $b/cmd-1 for reading.

    --
    a signature
    those who know me have no need of my name Guest

  3. #3

    Default Re: name pipe problem, quick question

    those who know me have no need of my name wrote:
    > in comp.unix.admin i read:
    >
    > > rm $b/cmd-1
    > > mkfifo $b/cmd-1
    > > rm $b/res-1
    > > mkfifo $b/res-1
    > [...]
    > > echo "" > $b/cmd-1&
    >
    > your script stops here, waiting for something to open $b/cmd-1 for
    > reading.
    I even tried starting the script with nohup ./tfcrun &

    How can I fix the problem? Any suggestions?


    187 Guest

  4. #4

    Default Re: name pipe problem, quick question

    In article <2itvdsFqt04iU1uni-berlin.de>,
    187 <bigal187.invalidadexec.com> wrote:
    >> > rm $b/cmd-1
    >> > mkfifo $b/cmd-1
    >> > rm $b/res-1
    >> > mkfifo $b/res-1
    >> [...]
    >> > echo "" > $b/cmd-1&
    >> your script stops here, waiting for something to open $b/cmd-1 for
    >> reading.
    >How can I fix the problem? Any suggestions?
    Don't write to the named pipes until the program is listening on them.

    -- Richard
    Richard Tobin Guest

  5. #5

    Default Re: name pipe problem, quick question

    "Richard Tobin" <richardcogsci.ed.ac.uk> wrote in message
    news:cacln2$7j6$1pc-news.cogsci.ed.ac.uk...
    > In article <2itvdsFqt04iU1uni-berlin.de>,
    > 187 <bigal187.invalidadexec.com> wrote:
    >
    > > > > rm $b/cmd-1
    > > > > mkfifo $b/cmd-1
    > > > > rm $b/res-1
    > > > > mkfifo $b/res-1
    > > > [...]
    > > > > echo "" > $b/cmd-1&
    >
    > > > your script stops here, waiting for something to open $b/cmd-1 for
    > > > reading.
    >
    > > How can I fix the problem? Any suggestions?
    >
    > Don't write to the named pipes until the program is listening on them.
    I'm not entirely sure what I'm doing (I've never worked with named pipes
    before), could you please elaborate a little? What do you mean exactly?

    I did try running with nohup, but hlds still doesn't run unless I remove
    the name pipes from its execing line.

    One think I'm not sure about is what the two echo lines are supposed to
    do (shown below and the last line of code you quoted.) I only put them
    in because they were in the example. As I said I'm not used to working
    with named pipes so any help would be appreciated.

    It still doesn't work even if I comment these lines:

    echo "" > $b/cmd-1&
    echo "" > $b/res-1&

    Please, if you know how ot make this work (that is, have named pipes to
    read and send to hlds), please help. I did search around google and
    google groups but nothing help and could not find any good examplesor
    help either.

    Thank you


    187 Guest

  6. #6

    Default Re: name pipe problem, quick question

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    187 wrote:
    > "Richard Tobin" <richardcogsci.ed.ac.uk> wrote in message
    > news:cacln2$7j6$1pc-news.cogsci.ed.ac.uk...
    >
    >>In article <2itvdsFqt04iU1uni-berlin.de>,
    >>187 <bigal187.invalidadexec.com> wrote:
    >>
    >>
    >>>>>rm $b/cmd-1
    >>>>>mkfifo $b/cmd-1
    >>>>>rm $b/res-1
    >>>>>mkfifo $b/res-1
    >>>>
    >>>> [...]
    >>>>
    >>>>>echo "" > $b/cmd-1&
    >>
    >>>>your script stops here, waiting for something to open $b/cmd-1 for
    >>>>reading.
    >>
    >>>How can I fix the problem? Any suggestions?
    >>
    >>Don't write to the named pipes until the program is listening on them.
    >
    >
    > I'm not entirely sure what I'm doing (I've never worked with named pipes
    > before), could you please elaborate a little? What do you mean exactly?
    Unless the programs handle named pipes with special settings
    (O_NONBLOCK, IIRC), you get blocking behaviour by default.

    A named pipe can have multiple writers, but only one reader. Any process
    that opens the pipe for writing blocks until the pipe has also been
    opened for reading. Any process that opens the pipe for reading blocks
    on the first read until the pipe has been opened for writing.

    The only way around this is to open the pipe in non-blocking mode, and
    you can't do this in a script.


    - --

    Lew Pitcher, IT Consultant, Enterprise Application Architecture
    Enterprise Technology Solutions, TD Bank Financial Group

    (Opinions expressed here are my own, not my employer's)
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (MingW32)

    iD8DBQFAygLCagVFX4UWr64RAkNfAKDqf4IpcMR34/+SXCo2JIHO6uuT7ACfa4S7
    GYvOhWNRxjhXZBxiCqzYMEM=
    =InmX
    -----END PGP SIGNATURE-----
    Lew Pitcher Guest

  7. #7

    Default Re: name pipe problem, quick question

    In article <m18yeua2b8.gnususa.net>,
    those who know me have no need of my name <not-a-real-addressusa.net>
    wrote:
    > in comp.unix.admin i read:
    >
    > >rm $b/cmd-1
    > >mkfifo $b/cmd-1
    > >rm $b/res-1
    > >mkfifo $b/res-1
    > [...]
    > >echo "" > $b/cmd-1&
    >
    > your script stops here, waiting for something to open $b/cmd-1 for reading.
    It shouldn't, since he's running that command in the background. The
    background process will block until another process opens the pipe for
    reading, but the script should continue.

    --
    Barry Margolin, [email]barmaralum.mit.edu[/email]
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    Barry Margolin Guest

  8. #8

    Default Re: name pipe problem, quick question

    In article <2it480Fr6g3jU1uni-berlin.de>,
    187 <bigal187.invalidadexec.com> wrote:
    >echo "" > $b/cmd-1&
    >echo "" > $b/res-1&
    In my earler message I didn't notice that you were running these in the
    background, so ignore that.
    >I just see a couple extra 'tfcrun's listed, where ther
    >should be just one, and an instance of ./hlds.
    Those are probably the echo commands, since echo is a shell built-in.
    >it never actually
    >runns ./hlds as far as I can see from ps -x after running the script
    >(./tfcrun &)
    Presumably you've checked the log file to be sure that it's not just
    exiting immediately.

    Try running it with "sh -x tfcrun" so that you see what commands are
    executed.

    -- Richard
    Richard Tobin Guest

  9. #9

    Default Re: name pipe problem, quick question

    Richard Tobin wrote:
    > In article <2it480Fr6g3jU1uni-berlin.de>,
    > 187 <bigal187.invalidadexec.com> wrote:
    >
    >> echo "" > $b/cmd-1&
    >> echo "" > $b/res-1&
    >
    > In my earler message I didn't notice that you were running these in
    > the background, so ignore that.
    >
    >> I just see a couple extra 'tfcrun's listed, where ther
    >> should be just one, and an instance of ./hlds.
    >
    > Those are probably the echo commands, since echo is a shell built-in.
    >
    >> it never actually
    >> runns ./hlds as far as I can see from ps -x after running the script
    >> (./tfcrun &)
    >
    > Presumably you've checked the log file to be sure that it's not just
    > exiting immediately.
    >
    > Try running it with "sh -x tfcrun" so that you see what commands are
    > executed.
    Well using ps I know hlds isnt running, unless I remove the

    < $b/cmd-1 > $b/res-1

    part. Is it possible ther is someting wrong with the way this is setup?
    Does the script need to be run with nohup?

    i tried

    nohup ./tfcrun &

    but hlds still doesnt seem to run.


    187 Guest

  10. #10

    Default Re: name pipe problem, quick question

    In article <2iupk3FrvlrvU1uni-berlin.de>,
    187 <bigal187.invalidadexec.com> wrote:
    >Well using ps I know hlds isnt running, unless I remove the
    >
    > < $b/cmd-1 > $b/res-1
    Ah, ok. What's reading from res-1? Nothing as far as I can see.
    The shell won't be able to open it until something's reading.

    (And if res-1 is for output, why did you echo something to it?)

    The rule with named pipes is that you must set the readers going
    before anything can be written; the writers will block until something
    reads.
    >Does the script need to be run with nohup?
    Nohup has nothing to do with this.

    -- Richard
    Richard Tobin Guest

  11. #11

    Default Re: name pipe problem, quick question

    187 wrote:
    >
    > I'm trying to re-write a start up script for a game server (hl ds) and
    > setup named-pipes
    Why are you using named pipes for a game server?
    > What am I doing wrong? (script is below)
    At a glance, using named pipes is what you are doing wrong. Game
    servers are usually designed to operate over the network using
    sockets. I'm not surprised that this one does not handle haivng
    its stdin and stdout put into a pipe that doesn't have anything
    on the other side.
    > echo "" > $b/cmd-1&
    > echo "" > $b/res-1&
    Putting these in backgroupnd is not enough to keep the shell from
    waiting. It's a bit like tape movement. The tape movement command
    will comlete asynchronously, but if the next coomand deals with a
    tape it has to do a sync/wait for the movement to complete. The
    pipe device itself hangs waiting for something to read from it.
    > ./hlds -game tfc -port 27015 +ip 206.216.122.21 +maxplayers 18 +map
    > 2fort < $b/cmd-1 > $b/res-1
    Remember that I/O redirection happens before the image is
    launched. One of the echo's above to cmd-1 puts data into that
    pipe, and the input redirection here takes that empty line
    back out. The other echo above to res-1 puts data into that
    pipe, and the output redirection above to res-1 puts more
    data into it. Since there's an EOL in the buffer, the pipe hangs
    waiting for some process to start reading from it.

    Going over the order of I/O redirection resolves many issues
    like this.

    If there's a program that logs the game server's output, it needs
    to be launched from a different shell. That should unhang the
    pipe and allow this thread to launch the game server image.

    Why are you using named pipes to log data? The game server
    isn't set up to handle it.

    Why did you prime the pump of both pipes with an empty line?
    The game server better expect a blank line as its first input
    line to make that pipe available for other processes.

    Lesson learned #1 - If you set up a named pipe make very certain
    you launch a reader on it in background before you launch any
    writers to it.

    Lesson learned #2 - Be very hesitant to use named pipes on any
    server that normally uses pipes.
    Doug Freyburger Guest

  12. #12

    Default Re: name pipe problem, quick question

    Doug Freyburger wrote:
    > 187 wrote:
    > >
    > > I'm trying to re-write a start up script for a game server (hl ds)
    > > and setup named-pipes
    >
    > Why are you using named pipes for a game server?
    >
    > > What am I doing wrong? (script is below)
    >
    > At a glance, using named pipes is what you are doing wrong. Game
    > servers are usually designed to operate over the network using
    > sockets. I'm not surprised that this one does not handle haivng
    > its stdin and stdout put into a pipe that doesn't have anything
    > on the other side.
    Ok, sorry for the confusion. This game server (half-life) doesnt do the
    game stuff from thep ipes, it uses udp sockets for that. THe purpose of
    the pieps is the be able to use the console you'd otherwise have access
    to if you ran hlds in the foreground. In other words theres a console
    scroll of whats going on and chats, etc, and one can send commands. If
    ran in foreground, normal STDOUT/STDIN action. Thats what the pipes were
    suppost to capture and send to.
    > > echo "" > $b/cmd-1&
    > > echo "" > $b/res-1&
    >
    > Putting these in backgroupnd is not enough to keep the shell from
    > waiting. It's a bit like tape movement. The tape movement command
    > will comlete asynchronously, but if the next coomand deals with a
    > tape it has to do a sync/wait for the movement to complete. The
    > pipe device itself hangs waiting for something to read from it.
    >
    > > ./hlds -game tfc -port 27015 +ip 206.216.122.21 +maxplayers 18 +map
    > > 2fort < $b/cmd-1 > $b/res-1
    >
    > Remember that I/O redirection happens before the image is
    > launched. One of the echo's above to cmd-1 puts data into that
    > pipe, and the input redirection here takes that empty line
    > back out. The other echo above to res-1 puts data into that
    > pipe, and the output redirection above to res-1 puts more
    > data into it. Since there's an EOL in the buffer, the pipe hangs
    > waiting for some process to start reading from it.
    >
    > Going over the order of I/O redirection resolves many issues
    > like this.
    >
    > If there's a program that logs the game server's output, it needs
    > to be launched from a different shell. That should unhang the
    > pipe and allow this thread to launch the game server image.
    >
    > Why are you using named pipes to log data? The game server
    > isn't set up to handle it.
    >
    > Why did you prime the pump of both pipes with an empty line?
    > The game server better expect a blank line as its first input
    > line to make that pipe available for other processes.
    >
    > Lesson learned #1 - If you set up a named pipe make very certain
    > you launch a reader on it in background before you launch any
    > writers to it.
    >
    > Lesson learned #2 - Be very hesitant to use named pipes on any
    > server that normally uses pipes.
    Thank you.


    187 Guest

Similar Threads

  1. Having a problem with a short pipe read
    By Brian in forum PERL Modules
    Replies: 0
    Last Post: February 23rd, 03:58 PM
  2. Pipe animation question
    By Moe in forum Macromedia Flash
    Replies: 1
    Last Post: December 9th, 04:16 PM
  3. named pipe problem on Win32
    By Daniel Berger in forum Ruby
    Replies: 1
    Last Post: November 22nd, 01:48 AM
  4. pipe open question
    By Dave Saville in forum PERL Miscellaneous
    Replies: 3
    Last Post: September 17th, 02:52 PM
  5. Replies: 2
    Last Post: July 2nd, 02:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139