[Sumover-dev] [svn commit] r4213 - rat/trunk
sumover-dev at cs.ucl.ac.uk
sumover-dev at cs.ucl.ac.uk
Tue Jul 8 23:25:18 BST 2008
Author: turam
Date: Tue Jul 8 23:25:15 2008
New Revision: 4213
Modified:
rat/trunk/cmd_parser.c
rat/trunk/main_control.c
rat/trunk/main_engine.c
rat/trunk/main_ui.c
rat/trunk/process.c
rat/trunk/process.h
rat/trunk/tcltk.c
Log:
Accept -X arguments on command line, and pass to underlying apps and into tcl interpreter
Modified: rat/trunk/cmd_parser.c
==============================================================================
--- rat/trunk/cmd_parser.c (original)
+++ rat/trunk/cmd_parser.c Tue Jul 8 23:25:15 2008
@@ -326,6 +326,7 @@
{ "-t", NULL, 1 }, /* handled in parse early args */
{ "-noui", NULL, 0 }, /* handled in parse early args */
{ "-T", NULL, 0 }, /* transcoder: special handling */
+ { "-X", NULL, 1 }, /* tcl resource handling */
};
static uint32_t late_args_cnt = sizeof(late_args)/sizeof(late_args[0]);
Modified: rat/trunk/main_control.c
==============================================================================
--- rat/trunk/main_control.c (original)
+++ rat/trunk/main_control.c Tue Jul 8 23:25:15 2008
@@ -74,7 +74,6 @@
{
char *addr, *p;
int i, port, okay = TRUE;
-
addr = xstrdup(candidate);
addr = strtok(addr, "/");
@@ -251,7 +250,7 @@
argc -= 1; /* Skip process name */
argv += 1;
- naddr = address_count(argc, argv);
+ naddr = 1; /* address_count(argc, argv); */
if (naddr < 1) {
usage(NULL);
return FALSE;
@@ -475,6 +474,8 @@
int seed = (gethostid() << 8) | (getpid() & 0xff), final_iters;
struct timeval timeout;
int i, num_sessions = 0;
+ char **xargv = xmalloc(argc);
+ int xargc=0;
#ifdef WIN32
win32_create_null_window(); /* Needed to listen to messages */
@@ -507,10 +508,19 @@
fatal_error("RAT v" RAT_VERSION, "Could not initialize Mbus: Is multicast enabled?");
return FALSE;
}
+
+ /* pull out -X arguments */
+ for(i=0; i<argc; i++) {
+ if( strcmp(argv[i],"-X") == 0 ) {
+ xargv[xargc] = argv[i]; xargc++; i++;
+ xargv[xargc] = argv[i]; xargc++;
+ }
+ }
+
if (ui_enabled) {
token_u[0] = generate_token();
- fork_process(UI_NAME, c_addr, &pid_ui, 1, token_u);
+ fork_process(UI_NAME, c_addr, &pid_ui, 1, token_u, xargc, xargv);
if ((u_addr = mbus_rendezvous_waiting(m, "()", token_u[0], m, 20000000)) == NULL) {
fatal_error("RAT v" RAT_VERSION, "MBUS Failed to rendezvous with UI - Likely firewall/VPN issue");
return FALSE;
@@ -519,7 +529,7 @@
token_e[0] = generate_token();
token_e[1] = generate_token();
- fork_process(ENGINE_NAME, c_addr, &pid_engine, num_sessions, token_e);
+ fork_process(ENGINE_NAME, c_addr, &pid_engine, num_sessions, token_e, xargc, xargv);
should_exit = FALSE;
for (i = 0; i < num_sessions; i++) {
debug_msg("Waiting for %s from media engine...\n", token_e[i]);
@@ -529,7 +539,7 @@
}
debug_msg("...got it (%s)\n",e_addr[i]);
}
-
+
if (parse_addresses(m, e_addr, argc, argv) == TRUE) {
char *peer;
@@ -587,6 +597,7 @@
if (ui_enabled) xfree(token_u[0]);
xfree(token_e[0]);
xfree(token_e[1]);
+ xfree(xargv);
debug_msg("Controller exit\n");
return 0;
}
Modified: rat/trunk/main_engine.c
==============================================================================
--- rat/trunk/main_engine.c (original)
+++ rat/trunk/main_engine.c Tue Jul 8 23:25:15 2008
@@ -74,10 +74,6 @@
{
int i, tc;
- if ((argc != 5) && (argc != 8)) {
- printf("Usage: rat-%s-media [-T] -ctrl <addr> -token <token> [-token <token>]\n", RAT_VERSION);
- exit(1);
- }
tc = 0;
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-ctrl") == 0) {
@@ -91,8 +87,12 @@
/* Enable transcoder... */
debug_msg("Enabled transcoder support\n");
num_sessions = 2;
+ } else if (strcmp(argv[i], "-X") == 0) {
+ /* accept -X arguments, but only because they get passed to tcl */
+ i++;
} else {
- printf("Unknown argument \"%s\"\n", argv[i]);
+ printf("Unknown argument to %s: \"%s\"\n", argv[0], argv[i]);
+ printf("Usage: rat-%s-media [-T] -ctrl <addr> -token <token> [-token <token>] [-X arg=value]\n", RAT_VERSION);
abort();
}
}
Modified: rat/trunk/main_ui.c
==============================================================================
--- rat/trunk/main_ui.c (original)
+++ rat/trunk/main_ui.c Tue Jul 8 23:25:15 2008
@@ -38,22 +38,22 @@
int got_quit = FALSE;
static int mbus_shutdown_error = FALSE;
+
static void parse_args(int argc, char *argv[])
{
int i;
-
- if (argc != 5) {
- printf("UI usage: %s -ctrl <addr> -token <token>\n", argv[0]);
- exit(1);
- }
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-ctrl") == 0) {
c_addr = xstrdup(argv[++i]);
} else if (strcmp(argv[i], "-token") == 0) {
token = xstrdup(argv[++i]);
token_e = mbus_encode_str(token);
+ } else if (strcmp(argv[i], "-X") == 0) {
+ /* accept -X arguments, but only because they get passed to tcl */
+ i++;
} else {
- printf("Unknown argument \"%s\"\n", argv[i]);
+ printf("Unknown argument to %s: \"%s\"\n", argv[0], argv[i]);
+ printf("UI usage: %s -ctrl <addr> -token <token> [-X arg=value]\n", argv[0]);
abort();
}
}
Modified: rat/trunk/process.c
==============================================================================
--- rat/trunk/process.c (original)
+++ rat/trunk/process.c Tue Jul 8 23:25:15 2008
@@ -17,9 +17,11 @@
#include "mbus.h"
#include "process.h"
-void fork_process(char *proc_name, char *ctrl_addr, pid_t *pid, int num_tokens, char *token[2])
+
+void fork_process(char *proc_name, char *ctrl_addr, pid_t *pid, int num_tokens, char *token[2], int argc, char **argv)
{
#ifdef WIN32
+ int i;
char args[1024];
LPSTARTUPINFO startup_info;
LPPROCESS_INFORMATION proc_info;
@@ -51,6 +53,9 @@
} else {
_snprintf(args, sizeof(args), "%s -T -ctrl \"%s\" -token %s -token %s", proc_name, ctrl_addr, token[0], token[1]);
}
+ for(i=0;i<argc;i++) {
+ _snprintf(args, sizeof(args), "%s %s", args, argv[i]);
+ }
if (!CreateProcess(NULL, args, NULL, NULL, TRUE, 0, NULL, NULL, startup_info, proc_info)) {
perror("Couldn't create process");
@@ -60,7 +65,7 @@
debug_msg("Forked %s\n", proc_name);
#else /* ...we're on unix */
char *path, *path_env;
-
+ int i;
#ifdef DEBUG_FORK
if (num_tokens == 1) {
debug_msg("%s -ctrl '%s' -token %s\n", proc_name, ctrl_addr, token[0]);
@@ -88,24 +93,34 @@
} else {
debug_msg("Running as root? PATH unmodified\n");
}
-
/* Fork off the sub-process... */
+ char **args = xmalloc(argc);
+ int numargs=0;
*pid = fork();
if (*pid == -1) {
perror("Cannot fork");
abort();
} else if (*pid == 0) {
- if (num_tokens == 1) {
- execlp(proc_name, proc_name, "-ctrl", ctrl_addr, "-token", token[0], NULL);
- } else {
- execlp(proc_name, proc_name, "-T", "-ctrl", ctrl_addr, "-token", token[0], "-token", token[1], NULL);
- }
- perror("Cannot execute subprocess");
- /* Note: this MUST NOT be exit() or abort(), since they affect the standard */
- /* IO channels in the parent process (fork duplicates file descriptors, but */
- /* they still point to the same underlying file). */
- _exit(1);
+ args[numargs++] = proc_name;
+ args[numargs++] = "-ctrl";
+ args[numargs++] = ctrl_addr;
+ for(i=0;i<num_tokens;i++) {
+ args[numargs++] = "-token";
+ args[numargs++] = token[i];
+ }
+ for(i=0;i<argc;i++) {
+ args[numargs++] = argv[i];
+ }
+ args[numargs++] = NULL;
+ execvp( proc_name, args );
+
+ perror("Cannot execute subprocess");
+ /* Note: this MUST NOT be exit() or abort(), since they affect the standard */
+ /* IO channels in the parent process (fork duplicates file descriptors, but */
+ /* they still point to the same underlying file). */
+ _exit(1);
}
+ xfree(args);
#endif
#endif
}
Modified: rat/trunk/process.h
==============================================================================
--- rat/trunk/process.h (original)
+++ rat/trunk/process.h Tue Jul 8 23:25:15 2008
@@ -7,6 +7,6 @@
* All rights reserved.
*/
-void fork_process(char *proc_name, char *ctrl_addr, pid_t *pid, int num_tokens, char *token[2]);
+void fork_process(char *proc_name, char *ctrl_addr, pid_t *pid, int num_tokens, char *token[2], int argc, char **argv);
void kill_process(pid_t proc);
Modified: rat/trunk/tcltk.c
==============================================================================
--- rat/trunk/tcltk.c (original)
+++ rat/trunk/tcltk.c Tue Jul 8 23:25:15 2008
@@ -272,11 +272,23 @@
#include "xbm/balloon.xbm"
#include "xbm/reception.xbm"
+static char*
+parse_assignment(char* cp)
+{
+ cp = strchr(cp, '=');
+ if (cp != 0) {
+ *cp = 0;
+ return (cp + 1);
+ } else
+ return ("true");
+}
+
int
tcl_init1(int argc, char **argv)
{
char *cmd_line_args, buffer[10];
Tcl_Obj *audiotool_obj;
+ int i;
Tcl_FindExecutable(argv[0]);
interp = Tcl_CreateInterp();
@@ -289,6 +301,12 @@
Tcl_SetVar(interp, "argc", buffer, TCL_GLOBAL_ONLY);
Tcl_SetVar(interp, "argv0", argv[0], TCL_GLOBAL_ONLY);
Tcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);
+ for(i=1; i<argc; i++ ) {
+ if( strcmp(argv[i],"-X") == 0) {
+ const char* value = parse_assignment(argv[++i]);
+ Tcl_SetVar(interp, argv[i], value, TCL_GLOBAL_ONLY);
+ }
+ }
/*
* There is no easy way of preventing the Init functions from
More information about the Sumover-dev
mailing list