Thread: Interrupted System Call

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    1

    Interrupted System Call

    Hey Everyone, I was hoping you could give me a little help here. I am trying to use a helper method I made in a program of mine, and I do not seem to be having any luck. Whenever I do something wrong, I get a "Interrupted System Call" error.

    I can't seem to find a clear definition of what this means, but it looks like there is a problem with the way my helper method is called.

    Here is how I call it in main()
    Code:
    			
    getURL(test, toHere);     // a little helper method to extract the URL from the string "test"
    And here is what the helper method looks like.

    Code:
    //This method will extract a URL from source and put it in dest
    void *getURL(char *source, char *dest) {
            // No idea why I have the * in "*getURL()" it just stopped giving me problems w/ it.
    	printf("Starting void method thing: %s\n", source);
    
    	char *origin1;    
    	origin1 = strstr(source, "GET");     // Find the GET http request
    	origin1 += strlen("GET ");     // increment origin1 to the beginning of the URL
    
    	int i = 0;
    	for ( i = 0; i < strlen(origin1); i++) {    // starting from origin.. search the whole string
    		if ( *(origin1+i) == '/' || *(origin1+i) == ' ' )
    			break;     // if you find a '/' or a space, you've reached the end of the URL
    	}
    	
    	strncpy(dest, origin1, i);     // This line is causing the error!
    
    	dest[i] = '\0';     // Incase the last char isn't NULL
    	puts(dest);      // Print for satisfaction :(
    }
    The line "strncpy(dest,origin1,i);" is the line causing me trouble. I am at a loss here because I am not getting any compilation errors about incorrect parameter types or anything. the int i has the value 15 after the for loop, so that should be fine as well.

    I have also used memcpy(&dest, origin1, i); This seemed to work, but I was unable to output dest to sys.out after that

    If anyone could help me with this, it would be most appreciated! Even an explanation on "Interrupted system call" would be a great help.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    And what exactly is toHere?

    If it isn't something like
    char toHere[1000];
    or
    char *toHere = malloc( 1000 );

    then you're writing data all over memory you don't own.
    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.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    do you have an actual buffer where your dest points - or it is some kind of uninitialized pointer?

    memcopy should receive dest not &dest

    you should check the return value of strstr before use
    you should calculatestrlen befoer loop

    prototype of the function should be

    void getURL(const char* source, char* dest);
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  3. Inline asm
    By brietje698 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2007, 02:54 PM
  4. nanosleep() -system call does some confusing things
    By jtk in forum Linux Programming
    Replies: 5
    Last Post: 08-30-2007, 04:15 AM
  5. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM