fredszky's Profile
Reputation: 0
Apprentice
- Group:
- New Members
- Active Posts:
- 7 (0.06 per day)
- Joined:
- 28-January 13
- Profile Views:
- 55
- Last Active:
Mar 13 2013 02:47 AM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: execvp() and my program gets stuck, send() and it works.
Posted 7 Mar 2013
Thank you for your reply.
Yes i know my coding skills are novice at best, i will look into each and every of your points.
Any idea why the program wont keep running after execvp()? With send() instead it keeps looping as it should.
execvp() used to work just fine and looping some days ago, i don't know why it suddenly doesn't. Maybe after i fiddled around with fork()..? -
In Topic: String/argument error in my test-server
Posted 28 Jan 2013
Skydiver, on 28 January 2013 - 07:56 AM, said:Once you fix your code formatting and compile errors, the core of your problem is that str2 is uninitialized in the case when there is a single command. (See lines 76-83, and 136-143 in post #6.)
this indeed was the problem, i was able to program around this in my servercode, now i have a working (but ugly) solution.
i did something like this:
if(str2[0] >= '+' && str2[0] <= 'DEL') spawn2 (str1, arg2); else spawn1 (str1, arg1);
...where spawn 1 takes 1 less argument than spawn 2, and runs exevpc(...).
so, if str2 happends to contain: "a@@££@££" because its uninitialized, the program will fail, but anyway...
i dont find the "edit post" button here, but i forgot to say thanks for putting me in the right direction! -
In Topic: String/argument error in my test-server
Posted 28 Jan 2013
perhaps a } was missing. this should work:
#include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> #define SOCK_PATH "echo_socket" int main(void) { int s, s2, t, len; struct sockaddr_un local, remote; char str[100]; char* arg_list[222]; char str1[100], str2[100]; if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { perror("socket"); exit(1); } local.sun_family = AF_UNIX; strcpy(local.sun_path, SOCK_PATH); unlink(local.sun_path); len = strlen(local.sun_path) + sizeof(local.sun_family); if (bind(s, (struct sockaddr *)&local, len) == -1) { perror("bind"); exit(1); } if (listen(s, 5) == -1) { perror("listen"); exit(1); } for(;;)/> { int active,done, sent, n; printf("Waiting for a connection...\n"); t = sizeof(remote); if ((s2 = accept(s, (struct sockaddr *)&remote, &t)) == -1) { perror("accept"); exit(1); } printf("Connected.\n"); active = 0; done = 0; sent = 0; do { n = recv(s2, str, 100, 0); if (n <= 0) { if (n < 0) perror("recv"); done = 1; } if(str[0]=='s' && str[1]=='t' && str[2]=='o' && str[3]=='p') done = 1; if(str[0]=='s' && str[1]=='t' && str[2]=='a' && str[3]=='r'&& str[4]=='t') active = 1; str[strcspn ( str, "\n" )] = '\0'; strcpy(str1,str); int i=0,k=0; while (str1[i] != ' ') i++; while (str1[i] != '\0'){ str2[k] = str1[i+1]; k++; i++; } i=0; while (str1[i] != ' ') i++; str1[i] = '\0'; int spawn (char* program, char** arg_list) { printf("\n%s!!!\n%s!!!",program,arg_list); pid_t child_pid; child_pid = fork (); if (child_pid != 0) return child_pid; else{ execvp (program, arg_list); } fprintf (stderr, "an error occurred in execvp\n"); abort (); } char* arg_list[222]; char kommando[222]; char * tmp; i=0; tmp = strtok (kommando," "); arg_list[0] = tmp; while (tmp != NULL) { tmp = strtok (NULL, " "); arg_list[i+1] = tmp; i++; } char* arg[] = { str1, str2, NULL }; spawn (str1, arg); if (!done && sent == 0 && active == 0) if (send(s2, str, n, 0) < 0) { perror("send"); sent = 1; } if (!done && sent == 0 && active == 1) if (send(s2, str, n, 0) < 0) { perror("send"); sent = 1; } sent = 0; } while (!done); close(s2); } return 0; } -
In Topic: String/argument error in my test-server
Posted 28 Jan 2013
Skydiver, on 28 January 2013 - 06:56 AM, said:Does your code even compile? I see a do loop starting on line 53, but corresponding while on line 58 to close off the loop.
oh, yes it compiles, the corresponding while is at 136, something went wrong when i pasted it into the forum, intendation perhaps.
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Private
Friends
fredszky hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
fredszky has no profile comments yet. Why not say hello?