forum.netbsd.se - NetBSD Sweden

You are not logged in.

#1 2004-05-25 04:30:17

elip
Guest

fast-cgi

hey...i'm trying to run the following script on NetBSD 2.0, built from May 21st sources.
nevermind the path's of the binaries, they are correct.
it works fine in linux, in NetBSD, i get the following error:

spawn-fcgi.c.79: bind failed: Invalid argument
I have no idea why.  thanks for the help.

#!/bin/bash

## ABSOLUTE path to the spawn-fcgi binary
SPAWNFCGI="/usr/local/bin/spawn-fcgi"

## ABSOLUTE path to the PHP binary
FCGIPROGRAM="/usr/local/bin/php"

## bind to tcp-port on localhost
FCGIPORT="1026"

## number of PHP childs to spawn
PHP_FCGI_CHILDREN=5

## number of request server by a single php-process until is will be restarted
PHP_FCGI_MAX_REQUESTS=1000

## IP adresses where PHP should access server connections from
FCGI_WEB_SERVER_ADDRS="127.0.0.1,192.168.0.1"

# allowed environment variables sperated by spaces
ALLOWED_ENV="ORACLE_HOME PATH USER"

## if this script is run as root switch to the following user
USERID=wwwrun
GROUPID=wwwrun


################## no config below this line

if test x$PHP_FCGI_CHILDREN = x; then
  PHP_FCGI_CHILDREN=5
fi

export PHP_FCGI_MAX_REQUESTS
export FCGI_WEB_SERVER_ADDRS

ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"

if test x$UID = x0; then
  EX="$SPAWNFCGI -p $FCGIPORT -f $FCGIPROGRAM -u $USERID -g $GROUPID -C $PHP_FCGI_CHILDREN"
else
  EX="$SPAWNFCGI -p $FCGIPORT -f $FCGIPROGRAM -C $PHP_FCGI_CHILDREN"
fi

# copy the allowed environment variables
E=

for i in $ALLOWED_ENV; do
  E="$E $i=${!i}"
done
 
# clean environment and set up a new one
env - $E $EX

 

#2 2004-05-25 09:05:04

mikael
Member
From: Stockholm, Sweden
Registered: 2004-05-11
Posts: 101

Re: fast-cgi

Have you used a correct typecast of socklen_t when calling
bind in the spawn-fcgi binary?
Be sure to use the system defined types.

The problem is not your script, but the creation of the socket in
the $SPAWNFCGI program.

Offline

 

#3 2004-05-25 12:42:52

elip
Guest

Re: fast-cgi

yes, i know that's where the problem lays...however, i am a complete newb to unix...

so with that said...what is a typecast? what is socklen_t...can i somehow not use unix sockets?

 

#4 2004-05-25 13:19:15

elip
Guest

Re: fast-cgi

after my second post i realized the irony of this whole thread...i'm trying to spawn php and fast-cgi, so that i can set-up a forum on one of my sites...which forum software did i choose, why, its none other than PunBB! hah!

 

#5 2004-05-25 14:02:10

mikael
Member
From: Stockholm, Sweden
Registered: 2004-05-11
Posts: 101

Re: fast-cgi

Aha, thought that spawn-fcgi stuff was your work. Well that
limits the cause of errors down. Forget about the actual creation
of the socket, that is probably correct if the program compiles.

Offline

 

#6 2004-05-25 14:22:01

mikael
Member
From: Stockholm, Sweden
Registered: 2004-05-11
Posts: 101

Re: fast-cgi

Okey, this is a better guess of what is going on.

Is it true that your application is trying to bind several sockets to
the same port? If that is the case, then this is a violation
to how bind functions in NetBSD since the release of NetBSD 1.4.

You can find information about this under SECURITY CONSIDERATIONS' in
the manpage of bind. http://man.netbsd.se/?find=bind+2+162

Offline

 

#7 2004-05-29 06:24:36

elip
Guest

Re: fast-cgi

well, i'm stumped...i really don't know why it can't bind the socket...i emailed the person who wrote the code...didn't hear back...so i'm stuck, if anyone wants to look at the code for spawn-fcgi.c that's failing on me,     here it is

Let me know if anyone can help out.  Thanks ahead of time.  Thanks Mikael for helping out.

 

#8 2004-06-05 18:00:30

elip
Guest

Re: fast-cgi

here's the kdump output:
not sure if it really helps?

400 ktrace   EMUL  "netbsd"
   400 ktrace   CALL  execve(0xbfbff88b,0xbfbff7c4,0xbfbff7dc)
   400 ktrace   NAMI  "/usr/local/sbin/spawn-fcgi"
   400 ktrace   NAMI  "/usr/libexec/ld.elf_so"
   400 spawn-fcgi EMUL  "netbsd"
   400 spawn-fcgi RET   execve JUSTRETURN
   400 spawn-fcgi CALL  mmap(0,0x8000,3,0x1002,0xffffffff,0,0,0)
   400 spawn-fcgi RET   mmap 1208315904/0x48057000
   400 spawn-fcgi CALL  open(0x48051fa8,0,0)
   400 spawn-fcgi NAMI  "/etc/ld.so.conf"
   400 spawn-fcgi RET   open 3
   400 spawn-fcgi CALL  __fstat13(3,0xbfbff6cc)
   400 spawn-fcgi RET   __fstat13 0
   400 spawn-fcgi CALL  mmap(0,0x37,1,1,3,0,0,0)
   400 spawn-fcgi RET   mmap 1208348672/0x4805f000
   400 spawn-fcgi CALL  close(3)
   400 spawn-fcgi RET   close 0
   400 spawn-fcgi CALL  munmap(0x4805f000,0x37)
   400 spawn-fcgi RET   munmap 0
   400 spawn-fcgi CALL  open(0x4805a0c0,0,0)
   400 spawn-fcgi NAMI  "/usr/lib/libc.so.12"
   400 spawn-fcgi RET   open 3
   400 spawn-fcgi CALL  __fstat13(3,0xbfbff3cc)
   400 spawn-fcgi RET   __fstat13 0
   400 spawn-fcgi CALL  mmap(0,0x1000,1,1,3,0,0,0)
   400 spawn-fcgi RET   mmap 1208348672/0x4805f000
   400 spawn-fcgi CALL  munmap(0x4805f000,0x1000)
   400 spawn-fcgi RET   munmap 0
   400 spawn-fcgi CALL  mmap(0,0xaf000,5,2,3,0,0,0)
   400 spawn-fcgi RET   mmap 1208348672/0x4805f000
   400 spawn-fcgi CALL  mmap(0x480fa000,0x6000,3,0x12,3,0,0x9b000,0)
   400 spawn-fcgi RET   mmap 1208983552/0x480fa000
   400 spawn-fcgi CALL  mmap(0x48100000,0xe000,3,0x1012,0xffffffff,0,0,0)
   400 spawn-fcgi RET   mmap 1209008128/0x48100000
   400 spawn-fcgi CALL  close(3)
   400 spawn-fcgi RET   close 0
   400 spawn-fcgi CALL  getuid
   400 spawn-fcgi RET   getuid 0
   400 spawn-fcgi CALL  socket(2,1,0)
   400 spawn-fcgi RET   socket 3
   400 spawn-fcgi CALL  connect(3,0xbfbff700,0x10)
   400 spawn-fcgi RET   connect -1 errno 61 Connection refused
   400 spawn-fcgi CALL  bind(3,0xbfbff700,0x10)
   400 spawn-fcgi RET   bind -1 errno 22 Invalid argument
   400 spawn-fcgi CALL  issetugid
   400 spawn-fcgi RET   issetugid 0
   400 spawn-fcgi CALL  issetugid
   400 spawn-fcgi RET   issetugid 0
   400 spawn-fcgi CALL  open(0x480f8553,0,0x1b6)
   400 spawn-fcgi NAMI  "/usr/share/nls/nls.alias"
   400 spawn-fcgi RET   open 4
   400 spawn-fcgi CALL  __fstat13(4,0xbfbfec80)
   400 spawn-fcgi RET   __fstat13 0
   400 spawn-fcgi CALL  __sysctl(0xbfbfebf8,2,0xbfbfebf0,0xbfbfebf4,0,0)
   400 spawn-fcgi RET   __sysctl 0
   400 spawn-fcgi CALL  readlink(0x480f934e,0xbfbfec70,0x3f)
   400 spawn-fcgi NAMI  "/etc/malloc.conf"
   400 spawn-fcgi RET   readlink -1 errno 2 No such file or directory
   400 spawn-fcgi CALL  mmap(0,0x1000,3,0x1002,0xffffffff,0,0,0)
   400 spawn-fcgi RET   mmap 1209065472/0x4810e000
   400 spawn-fcgi CALL  break(0x804abc8)
   400 spawn-fcgi RET   break 0
   400 spawn-fcgi CALL  break(0x804bbc8)
   400 spawn-fcgi RET   break 0
   400 spawn-fcgi CALL  break(0x804c000)
   400 spawn-fcgi RET   break 0
   400 spawn-fcgi CALL  break(0x804e000)
   400 spawn-fcgi RET   break 0
   400 spawn-fcgi CALL  read(4,0x804c000,0x2000)
   400 spawn-fcgi GIO   fd 4 read 1520 bytes
       "# $NetBSD: nls.alias,v 1.3 2003/04/14 05:21:51 salo Exp $
        #
        # This file defines aliase names of nls catalogs.
        # Syntax is similar to X11's locale.alias.
        # (The first word is an alias name and the second
        # one is nls catalog name.)

        ca_ES.ISO8859-1 ca
        ca_ES.ISO8859-15        ca
        cs_CZ.ISO8859-2 cs
        #da_DK.ISO8859-1        da
        #da_DK.ISO8859-15       da
        de_AT.ISO8859-1 de
        de_AT.ISO8859-15        de
        de_CH.ISO8859-1 de
        de_CH.ISO8859-15        de
        de_DE.ISO8859-1 de
        de_DE.ISO8859-15        de
        #en_AU.ISO8859-1        en
        #en_AU.ISO8859-15       en
        #en_CA.ISO8859-1        en
        #en_CA.ISO8859-15       en
        #en_GB.ISO8859-1        en
        #en_GB.ISO8859-15       en
        #en_US.ISO8859-1        en
        #en_US.ISO8859-15       en
        #en_US.UTF-8    en
        es_ES.ISO8859-1 es
        es_ES.ISO8859-15        es
        fi_FI.ISO8859-1 fi
        fi_FI.ISO8859-15        fi
        fr_BE.ISO8859-1 fr
        fr_BE.ISO8859-15        fr
        fr_CA.ISO8859-1 fr
        fr_CA.ISO8859-15        fr
        fr_CH.ISO8859-1 fr
        fr_CH.ISO8859-15        fr
        fr_FR.ISO8859-1 fr
        fr_FR.ISO8859-15        fr
        #hr_HR.ISO8859-2        hr
        #hu_HU.ISO8859-2        hu
        #is_IS.ISO8859-1        is
        #is_IS.ISO8859-15       is
        #it_CH.ISO8859-1        it
        #it_CH.ISO8859-15       it
        #it_IT.ISO8859-1        it
        #it_IT.ISO8859-15       it
        #ja_JP.ISO2022-JP       ja
        #ja_JP.ISO2022-JP2      ja
        #ja_JP.SJIS     ja
        #ja_JP.ct       ja
        #ja_JP.eucJP    ja
        #ko_KR.eucKR    ko
        #lt_LT.ISO8859-4        lt
        nl_BE.ISO8859-1 nl
        nl_BE.ISO8859-15        nl
        nl_NL.ISO8859-1 nl
        nl_NL.ISO8859-15        nl
        no_NO.ISO8859-1 no
        no_NO.ISO8859-15        no
        pl_PL.ISO8859-2 pl
        #pt_PT.ISO8859-1        pt
        #pt_PT.ISO8859-15       pt
        #ru_RU.CP866    ru
        #ru_RU.ISO8859-5        ru
        #ru_RU.KOI8-R   ru
        #sl_SI.ISO8859-2        sl
        sk_SK.ISO8859-2 sk
        sv_SE.ISO8859-1 sv
        sv_SE.ISO8859-15        sv
        #uk_UA.KOI8-U   uk
        #zh_CN.eucCN    zh
        #zh_TW.Big5     zh
        #zh_TW.eucTW    zh
       "
   400 spawn-fcgi RET   read 1520/0x5f0
   400 spawn-fcgi CALL  read(4,0x804c000,0x2000)
   400 spawn-fcgi RET   read 0
   400 spawn-fcgi CALL  close(4)
   400 spawn-fcgi RET   close 0
   400 spawn-fcgi CALL  open(0xbfbff210,0,0)
   400 spawn-fcgi NAMI  "/usr/share/nls/C/libc.cat"
   400 spawn-fcgi RET   open 4
   400 spawn-fcgi CALL  __fstat13(4,0xbfbfed50)
   400 spawn-fcgi RET   __fstat13 0
   400 spawn-fcgi CALL  mmap(0,0x103b,1,1,4,0,0,0)
   400 spawn-fcgi RET   mmap 1209069568/0x4810f000
   400 spawn-fcgi CALL  close(4)
   400 spawn-fcgi RET   close 0
   400 spawn-fcgi CALL  munmap(0x4810f000,0x103b)
   400 spawn-fcgi RET   munmap 0
   400 spawn-fcgi CALL  write(2,0xbfbfed70,0x2f)
   400 spawn-fcgi GIO   fd 2 wrote 47 bytes
       "spawn-fcgi.c.79: bind failed: Invalid argument
       "
   400 spawn-fcgi RET   write 47/0x2f
   400 spawn-fcgi CALL  exit(0xffffffff)

 

#9 2004-06-06 02:41:09

mikael
Member
From: Stockholm, Sweden
Registered: 2004-05-11
Posts: 101

Re: fast-cgi

I find some parts of the code strange.

'connect' is called before 'bind' with the socket variable 'fcgi_fd'.
I don't know, but maybe BSD and Linux differs in the way the socket
is treated after this incorrect way of using sockets.

With a SOCK_STREAM socket, you should not use 'connect'
before 'bind'. The behavior of such use is probably not equaly
described between Linux and BSD. Sockets should not be used that way.

The one who wrote the code made the 'connect' call to test if
a server was already running. Try to solve that problem without
that connect call. Maybe it can be removed?

If not, try to make two sockets, one that makes the test, and another
one that is put to use with the rest of the program.

Even if the connect call fails (it should fail, no server should be listening), something is marked as 'in use' and makes the bind call fail with the error "Invalid argument."

So what is correct? The BSD-way or the Linux-way of treating this usage?
Well, this is incorrect usage. So nothing is right or wrong in this case.
This is not portable code.

Good luck!

Offline

 

#10 2004-06-07 00:56:40

elip
Guest

Re: fast-cgi

mikael wrote:



If not, try to make two sockets, one that makes the test, and another
one that is put to use with the rest of the program.


Good luck!

THANKS A LOT MIKAEL!!!
I finally got it to work...you were right...

I took your advice and replaced the connect with a socket, just as a first attempt...

if (-1 == connect(fcgi_fd, (struct sockaddr *) &fcgi_addr, servlen)) {
        /* server is not up, spawn in  */
        pid_t child;

replaced with:
if (-1 == socket(fcgi_fd, (struct sockaddr *) &fcgi_addr, servlen)) {
        /* server is not up, spawn in  */
        pid_t child;


Ignored the compiler warnings...and everything launched successfully!!!

Once again, thank you VERY MUCH!!!
I love this site!  Hope more people come to the forums!!!

 

#11 2004-06-07 09:43:38

mikael
Member
From: Stockholm, Sweden
Registered: 2004-05-11
Posts: 101

Re: fast-cgi

:-)

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2008 PunBB