program exits prematurely - added echos to help trace - chttpd - Questions

This is a discussion on program exits prematurely - added echos to help trace - chttpd - Questions ; Hello. I am having some problems with chttpd not running on my computer. I have added some echo statements to locate the fault. I have located a section of code that I believe may be of help in solving the ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: program exits prematurely - added echos to help trace - chttpd

  1. program exits prematurely - added echos to help trace - chttpd

    Hello.

    I am having some problems with chttpd not running on my computer. I have added
    some echo statements to locate the fault.

    I have located a section of code that I believe may be of help in solving the
    problem:

    #else
    printf("daemon chk\n"); /* debug!! - this echos */
    if (daemon( 0, 0)==-1){
    printf("daemon perror\n"); /* debug!! - this does not echo */
    perror("daemon:");
    exit(1);
    }
    printf("eochk daemon\n"); /* debug!! - this does not echo */
    #endif
    user_id = UID;
    group_id = GID;
    printf("identifying\n"); /* debug!! - this does not echo */

    Unfortunately, I don't know how to use the debugging tools properly at the
    moment, because I am used to an MSDOS assembly language environment and
    Microsoft Codeview. I haven't yet fully adapted to the linux development
    environment.

    Anyhow, from what I can tell from the above, I would expect the second or
    third echo to work.

    Does this mean that the code is exiting prematurely on "if (daemon( 0,0)==-1)"
    ?

    Does anyone know how to fix this, or have any suggestions as to what may be
    wrong ?

    Thanks in advance to anyone who can help.

    Regards,

    Mark.

    --

    Mark Hobley
    393 Quinton Road West
    QUINTON
    Birmingham
    B32 1QE

    Reply to: markhobley at hotpop dot do_not_type_this_bit com

    http://markhobley.yi.org/

  2. Re: program exits prematurely - added echos to help trace - chttpd

    markhobley@hotpop.deletethisbit.com (Mark Hobley) writes:
    > I am having some problems with chttpd not running on my computer. I
    > have added some echo statements to locate the fault.


    Use strace.

    > I have located a section of code that I believe may be of help in
    > solving the problem:
    >
    > #else
    > printf("daemon chk\n"); /* debug!! - this echos */
    > if (daemon( 0, 0)==-1){
    > printf("daemon perror\n"); /* debug!! - this does not echo */
    > perror("daemon:");
    > exit(1);
    > }
    > printf("eochk daemon\n"); /* debug!! - this does not echo */
    > #endif
    > user_id = UID;
    > group_id = GID;
    > printf("identifying\n"); /* debug!! - this does not echo */


    daemon() redirects stdout and stderr, so you might not see the results
    of the printfs.

    --
    http://www.greenend.org.uk/rjk/

  3. Re: program exits prematurely - added echos to help trace - chttpd

    markhobley@hotpop.deletethisbit.com (Mark Hobley) writes:

    > I have located a section of code that I believe may be of help in solving the
    > problem:
    >
    > #else
    > printf("daemon chk\n"); /* debug!! - this echos */
    > if (daemon( 0, 0)==-1){
    > printf("daemon perror\n"); /* debug!! - this does not echo */
    > perror("daemon:");
    > exit(1);
    > }
    > printf("eochk daemon\n"); /* debug!! - this does not echo */
    > #endif
    > user_id = UID;
    > group_id = GID;
    > printf("identifying\n"); /* debug!! - this does not echo */
    >
    > Unfortunately, I don't know how to use the debugging tools properly at the
    > moment, because I am used to an MSDOS assembly language environment and
    > Microsoft Codeview. I haven't yet fully adapted to the linux development
    > environment.


    Run the program in a debugger:

    gdb ./myprogram
    break daemon # stop at the daemon() call
    step # execute one line of code
    bt # print the stack (backtrace)
    # repeat the last two, and you should get an idea about what's going
    on.

    (Hint: install a debugging version of glibc, and compile chttpd with
    -g3 -gdwarf-2)and then run gdb like this:
    "LD_LIBRARY_PATH=/usr/lib/debug gdb ..."

    Obviously, this is only scratching the surface of the capabilities of
    gdb.

    > Anyhow, from what I can tell from the above, I would expect the second or
    > third echo to work.


    Possibly. The printf() calls print to stdout, which is buffered. If
    the program quit unexpectedly the buffered data would not be flushed.
    Use fprintf(stderr ...); or else add fflush(stdout); after each
    printf() call.

    > Does this mean that the code is exiting prematurely on "if (daemon( 0,0)==-1)"


    Possibly. Try the above and see if it provides better information.
    My gut feeling would be it returns false and terminates after this
    section of code, but using stderr/flushing stdout will show this up.


    HTH,
    Roger

    --
    Roger Leigh

    Printing on GNU/Linux? http://gimp-print.sourceforge.net/
    GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.

+ Reply to Thread