Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Makes linphonecsh to handle arguments passed to init
  • Loading branch information
fgrisez committed Feb 6, 2015
1 parent 5d19161 commit 083b340
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions console/shell.c
Expand Up @@ -22,7 +22,8 @@

#include <stdio.h>
#include <stdlib.h>

#include <string.h>
#include <assert.h>

#ifdef WIN32
#include <ws2tcpip.h>
Expand Down Expand Up @@ -125,11 +126,36 @@ static void print_usage(void){
exit(-1);
}

#ifdef WIN32
static char *argv_to_line(int argc, char *argv[]) {
int i;
int line_length;
char *line;

assert( argc>=0 );

if(argc == 0) return NULL;

line_length = strlen(argv[0]);
for(i=1; i<argc; i++) {
line_length += strlen(argv[i]) + 1;
}

line = ortp_malloc0((line_length +1) * sizeof(char));
strcat(line, argv[0]);
for(i=1; i<argc; i++) {
strcat(line, " ");
strcat(line, argv[i]);
}
return line;
}
#endif

#define MAX_ARGS 10

#ifndef WIN32
static void spawn_linphonec(int argc, char *argv[]){
char * args[10];
char * args[MAX_ARGS];
int i,j;
pid_t pid;
j=0;
Expand Down Expand Up @@ -178,13 +204,21 @@ static void spawn_linphonec(int argc, char *argv[]){
PROCESS_INFORMATION pinfo;
STARTUPINFO si;
BOOL ret;
const char *cmd = "linphoned.exe --pipe -c NUL";
char *args_in_line = argv_to_line(argc, argv);
char *cmd_with_args;

ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pinfo, sizeof(pinfo) );


ret=CreateProcess(NULL,"linphoned.exe --pipe -c NUL",
if(args_in_line) {
cmd_with_args = ortp_strdup_printf("%s %s", cmd, args_in_line);
} else {
cmd_with_args = ortp_strdup(cmd);
}

ret=CreateProcess(NULL, cmd_with_args,
NULL,
NULL,
FALSE,
Expand All @@ -193,8 +227,12 @@ static void spawn_linphonec(int argc, char *argv[]){
NULL,
&si,
&pinfo);

if(args_in_line) ortp_free(args_in_line);
ortp_free(cmd_with_args);

if (!ret){
fprintf(stderr,"Spawning of linphonec.exe failed.\n");
fprintf(stderr,"Spawning of linphoned.exe failed.\n");
}else{
WaitForInputIdle(pinfo.hProcess,1000);
}
Expand Down

0 comments on commit 083b340

Please sign in to comment.