Thread: C guru help needed URGENT

  1. #46
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Do you see in the new trace that the poll timeout is being affected?

    Code:
    poll([{fd=4, events=POLLIN}, {fd=0, events=POLLIN}], 2, 5) = 0 (Timeout)
    rt_sigprocmask(SIG_BLOCK, [ALRM], NULL, 8) = 0
    gettimeofday({1348050630, xxxxx}, NULL) = 0
    rt_sigprocmask(SIG_UNBLOCK, [ALRM], NULL, 8) = 0
    poll([{fd=4, events=POLLIN}, {fd=0, events=POLLIN}], 2, 5) = 0 (Timeout)
    rt_sigprocmask(SIG_BLOCK, [ALRM], NULL, 8) = 0
    gettimeofday({1348050630, yyyyy}, NULL) = 0
    rt_sigprocmask(SIG_UNBLOCK, [ALRM], NULL, 8) = 0
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  2. #47
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    i increased it to 500
    and still no luck

    Code:
    rt_sigprocmask(SIG_BLOCK, [ALRM], NULL, 8) = 0
    gettimeofday({1348140798, 56749}, NULL) = 0
    rt_sigprocmask(SIG_UNBLOCK, [ALRM], NULL, 8) = 0
    poll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=0, events=POLLIN}], 3, 0) = 1 ([{fd=6, revents=POLLIN}])
    recv(6, "\0006\0003\5\5\1\0\2\3\353\0\3\20\2\3\352\0\2\0\201\0\0\1\10\0E\300\0,\361\r"..., 4104, 0) = 70
    recv(6, "\0006\0003\25\25\1\0\2\3\353\0\3\20\2\3\352\0\2\0\201\0\0\1\10\0E\300\0,\361\r"..., 4104, 0) = 70
    recv(6, 0xa996500, 4104, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    sendto(6, "\0003\0006\5\5\1\0\2\3\353\0\3\20\2\3\352\0\2\0\201\0\0\1\10\0E\300\0,\361\r"..., 70, 0, {sa_family=AF_INET, sin_port=htons(49051), sin_addr=inet_addr("192.168.51.1")}, 16) = 70
    rt_sigprocmask(SIG_BLOCK, [ALRM], NULL, 8) = 0
    gettimeofday({1348140798, 58866}, NULL) = 0
    rt_sigprocmask(SIG_UNBLOCK, [ALRM], NULL, 8) = 0
    poll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=0, events=POLLIN}], 3, 0) = 1 ([{fd=6, revents=POLLIN}])
    recv(6, "\0006\0003\25\25\1\0\2\3\353\0\3\20\2\3\352\0\2\0\201\0\0\1\10\0E\300\0,\361\r"..., 4104, 0) = 70
    recv(6, 0xa996500, 4104, 0)             = -1 EAGAIN (Resource temporarily unavailable)
    --- SIGSEGV (Segmentation fault) @ 0 (0) ---
    +++ killed by SIGSEGV (core dumped) +++

  3. #48
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    when i give it return 0 for gettimeofday ( empty function just returns 0)
    then it gets stuck at
    Code:
    t_sigprocmask(SIG_UNBLOCK, [ALRM], NULL, 8) = 0
    poll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=0, events=POLLIN}], 3, 4) = 0 (Timeout)
    rt_sigprocmask(SIG_BLOCK, [ALRM], NULL, 8) = 0
    rt_sigprocmask(SIG_UNBLOCK, [ALRM], NULL, 8) = 0
    poll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=0, events=POLLIN}], 3, 4) = 0 (Timeout)
    rt_sigprocmask(SIG_BLOCK, [ALRM], NULL, 8) = 0
    rt_sigprocmask(SIG_UNBLOCK, [ALRM], NULL, 8) = 0
    poll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=0, events=POLLIN}], 3, 4^C

  4. #49
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    so salem can you help me with the code for what i have in mind ?

    gettimeofday()
    if called first time , return correct time , store in variable
    after being called 2nd to 20 or 30 or 40the time ( configurable )
    start a "personal clock" , where 1 milisecond equals 100 miliseconds; and start returning this time ..effectivelt slowind down time
    you think it can work

  5. #50
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    1. Read post #36 again.
    If you have a statically linked executable, then PRELOAD will NOT work.
    Yes, you may have the syntax sorted out, and the loader recognises it as a valid option, and it may even be loaded into the address space of the running program.
    But a statically linked program will NOT call it.

    Here's my test program.
    The thing to note is that typing in a word beginning with c will cause it to crash.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/time.h>
    #include <poll.h>
    
    void doit ( void ) {
        while ( 1 ) {
            struct pollfd   p = { 0, POLLIN, 0 };
            int result = poll(&p,1,0);
            if ( result > 0 ) {
                char buff[100];
                int n = read(0,buff,sizeof(buff));
                int ch = buff[0];
                write(1,buff,n);
                if ( ch == 'q' ) break;
                if ( ch == 'c' ) {
                    int *dummy = 0;
                    *dummy = 0;
                }
            } else {
                struct timeval  now;
                int r = gettimeofday(&now,NULL);
            }
        }
    }
               
    int main ( ) {
        doit();
        return 0;
    }
    First, a bit of information for core files.
    The core file can be inspected using a debugger.
    How effective that is depends on the extent of the symbol table in the executable.

    Here are three examples, with less information each time.
    Code:
    # Good - gdb will point at a line of code
    $ gcc -g -static foo.c
    $ ./a.out 
    hello
    hello
    crash
    crash
    Segmentation fault (core dumped)
    $ gdb a.out core
    GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
    Copyright (C) 2011 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-linux-gnu".
    For bug reporting instructions, please see:
    <http://bugs.launchpad.net/gdb-linaro/>...
    Reading symbols from /home/sc/Documents/a.out...done.
    [New LWP 4757]
    Core was generated by `./a.out'.
    Program terminated with signal 11, Segmentation fault.
    #0  0x0000000000401102 in doit () at foo.c:86
    86	                *dummy = 0;
    (gdb) bt
    #0  0x0000000000401102 in doit () at foo.c:86
    #1  0x0000000000401149 in main () at foo.c:96
    (gdb) q
    $ 
    
    
    # Bad - gdb will just print global function names
    $ gcc -static foo.c
    $ ./a.out 
    hello
    hello
    crash
    crash
    Segmentation fault (core dumped)
    $ gdb a.out core
    GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
    Copyright (C) 2011 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-linux-gnu".
    For bug reporting instructions, please see:
    <http://bugs.launchpad.net/gdb-linaro/>...
    Reading symbols from /home/sc/Documents/a.out...(no debugging symbols found)...done.
    [New LWP 4766]
    Core was generated by `./a.out'.
    Program terminated with signal 11, Segmentation fault.
    #0  0x0000000000401102 in doit ()
    (gdb) bt
    #0  0x0000000000401102 in doit ()
    #1  0x0000000000401149 in main ()
    (gdb) q
    $ 
    
    
    # Ugly - gdb will just print hex addresses
    $ strip a.out
    $ ./a.out 
    hello
    hello
    crash
    crash
    Segmentation fault (core dumped)
    $ gdb a.out core
    GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
    Copyright (C) 2011 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-linux-gnu".
    For bug reporting instructions, please see:
    <http://bugs.launchpad.net/gdb-linaro/>...
    Reading symbols from /home/sc/Documents/a.out...(no debugging symbols found)...done.
    [New LWP 4771]
    Core was generated by `./a.out'.
    Program terminated with signal 11, Segmentation fault.
    #0  0x0000000000401102 in ?? ()
    (gdb) bt
    #0  0x0000000000401102 in ?? ()
    #1  0x0000000000401149 in ?? ()
    #2  0x000000000040130a in ?? ()
    #3  0x0000000000400f61 in ?? ()
    #4  0x00007fffc78fa318 in ?? ()
    #5  0x0000000000000000 in ?? ()
    (gdb) q
    If you've got a core file, can you try with gdb to see what other information you can obtain.

    The "resource unavailable" just means that there was no data for recv() at that moment in time.
    After each one, there is another call to poll() to wait for a while until more data arrives.
    Do you also get these when you run just a single instance of your code?


    > --- SIGSEGV (Segmentation fault) @ 0 (0) ---
    > +++ killed by SIGSEGV (core dumped) +++
    This is just the code trying to dereference a NULL pointer.
    I get the same when I trace my test program.
    Code:
    poll([{fd=0, events=POLLIN}], 1, 0)     = 0 (Timeout)
    poll([{fd=0, events=POLLIN}], 1, 0)     = 0 (Timeout)
    poll([{fd=0, events=POLLIN}], 1, 0)     = 0 (Timeout)
    
    poll([{fd=0, events=POLLIN}], 1, 0)     = 1 ([{fd=0, revents=POLLIN}])
    read(0, "crash\n", 100)                 = 6
    write(1, "crash\n", 6crash
    )                  = 6
    --- SIGSEGV (Segmentation fault) @ 0 (0) ---
    +++ killed by SIGSEGV +++
    Segmentation fault
    I don't think you can infer anything from the trace about this crash.
    Without source code, this is going to be tough to solve.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #51
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    Thanx but my doubt is
    1. when i added printf to empty gettime
    i DO get the *s printed on my screen
    2. is it possible that it , like you say , loads the new gettime
    and original gettime ,
    but then how can i see *s ( no pun intended )
    when i put them in printf ?

    i the case of empty printf , it loads half way , but since it cannot start a timer , it sits there is my take on it

  7. #52
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    btw there is no corefile

  8. #53
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    btw the file its trying to open i think is a socket that it uses to communicate with the other copy of the program
    basically you run 4 copies and they send stuff to each other by opening a socket in tmp directory

  9. #54
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    Ok another interesting thing , hope i dont jinx it , 2 copies are running fine of the same program with same timer.so loaded and 2 keep crashing

  10. #55
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    Update: I can sun 2 copies just fine
    but another 2 dont work

  11. #56
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    can someone tell me my mistake in this ?

    Code:
    #include <poll.h>
    #include <stdio.h>
    #include <unistd.h>
    
    
    int __wrap_poll(struct pollfd *fds, nfds_t nfds, int timeout) {
         usleep(100);
        printf("Sleeping\n");
        return __real_poll(fds,nfds,timeout);
    }

    or compile options ?
    gcc -Wl,--wrap,poll -fPIC -c poll.c
    gcc -Wl,--wrap=poll -fPIC -c poll.c

  12. #57
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    or compile options ?
    When you compile it what compile errors do you receive? Post the complete compile error message.


    A couple of the mistakes are that variables, functions starting with two underscores are reserved for standard usage.

    Jim

  13. #58
    Registered User
    Join Date
    Sep 2012
    Posts
    50
    Quote Originally Posted by jimblumberg View Post
    When you compile it what compile errors do you receive? Post the complete compile error message.


    A couple of the mistakes are that variables, functions starting with two underscores are reserved for standard usage.

    Jim
    hey
    I dont get any errors
    and when i preload it with ld_preload , it does load
    i check it with LD_PRELOAD=/home/poll.so ldd ./program
    but the program is not using my version of the poll

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Urgent help needed
    By bathulasubbu in forum C Programming
    Replies: 3
    Last Post: 03-25-2011, 09:33 AM
  2. Urgent, help needed.
    By sinnclaus in forum C Programming
    Replies: 4
    Last Post: 03-29-2010, 06:08 AM
  3. Urgent! Help Needed
    By DarkManiac in forum C++ Programming
    Replies: 4
    Last Post: 04-14-2004, 07:16 PM
  4. Urgent: Help needed.
    By Cn00b in forum C Programming
    Replies: 12
    Last Post: 04-02-2003, 10:18 PM
  5. Urgent help needed!!!
    By gibs21 in forum C Programming
    Replies: 2
    Last Post: 09-26-2002, 01:45 PM