| Project Homepage | Sourceforge Page | CVS Repository | Freshmeat.net Page | Download project | Author's Homepage |
run-free is a command line launching program written in gtk. This version of run-free is written is C for gtk+1.2
Definition in file main.h.
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Global Switches | |
| Switches used throughout the program | |
| gboolean | run_in_term |
| gboolean | die |
| gboolean | no_kbhit |
| gboolean | keep_open |
Global Parameters | |
| common GLOBAL parameters | |
| char * | home_directory |
| char * | history_file |
| int | history_len |
| char * | terminal_path |
| char * | command |
| gboolean | bash_shell_mode |
Functions | |
| void | run_command (char *command) |
| Run a command. | |
|
|
Run a command.
Definition at line 383 of file main.c. References bash_shell_mode, combo_init(), combo_mode, command, die, environ, history_file, keep_open, no_kbhit, run_in_term, terminal_path, and writeHistory(). Referenced by on_combo_entry1_key_press_event(), and on_runButton_clicked().
00384 {
00385
00386 char pre[64], post[64], *buffer;
00387
00388 //anything except NULL is allowed.
00389 if(!command)
00390 return;
00391
00392 //populate parts of the command
00393 if(run_in_term)
00394 {
00395 //we want to run this in a terminal so act accordingly
00396 if(bash_shell_mode == TRUE)
00397 {
00398 //endable user alias settings (i.e. ls --color)
00399 strcpy(pre," -e bash -i -c \'");
00400 }
00401 else
00402 {
00403 strcpy(pre," -e sh -c \'");
00404 }
00405
00406 if(!no_kbhit)
00407 {
00408 //alsways show "HIT ANY KEY"
00409 if(keep_open)
00410 if(bash_shell_mode == TRUE)
00411 strcpy(post, "; bash -i \'&");
00412 else
00413 strcpy(post, "; sh \'&");
00414 else
00415 strcpy(post, "; run-free -k \'&");
00416 }
00417 else
00418 if(keep_open)
00419 if(bash_shell_mode == TRUE)
00420 strcpy(post, "; bash -i \'&");
00421 else
00422 strcpy(post, "; sh \'&");
00423 else
00424 strcpy(post, "; \'&");
00425
00426
00427 //allocate a buffer
00428 buffer = g_malloc(strlen(terminal_path)
00429 +strlen(pre)
00430 +strlen(command)
00431 +strlen(post)
00432 +1);
00433
00434 //populate the buffer with the command
00435 sprintf(buffer, "%s%s%s%s", terminal_path, pre, command, post);
00436 }
00437 else
00438 {
00439 //no terminal, we must want to just execute something in the
00440 //background
00441 strcpy(pre, "");
00442 strcpy(post, " &");
00443
00444 //allocate a buffer
00445 buffer = g_malloc( +strlen(pre)
00446 +strlen(command)
00447 +strlen(post)
00448 +1);
00449
00450 //populate the buffer with the command
00451 sprintf(buffer, "%s%s%s", pre, command, post);
00452 }
00453
00454
00455
00456 //fork the program to execute the command
00457 int pid = fork();
00458
00459 //if we are the child...
00460 if(pid == 0)
00461 {
00462 //update the history file
00463 writeHistory(command, history_file);
00464
00465 //populate the command to execute
00466 char * argv[4];
00467 argv[0] = "sh";
00468 argv[1] = "-c";
00469 argv[2] = (char *)buffer;
00470 argv[3] = 0;
00471
00472 /**\warning
00473 NOTE: this function is a potential security problem because we are not
00474 replacing the environment. if this is ever going to be a SUID
00475 application then I need to handle this. I'll work on this in the
00476 future -parasyte
00477 */
00478 //execute the program
00479 execve("/bin/sh", argv, environ);
00480
00481 //free memory
00482 g_free(buffer);
00483
00484 //exit properly
00485 exit(0);
00486 }
00487 else
00488 {
00489 g_free(buffer);
00490
00491 if(die)
00492 {
00493 //kill the main program
00494 gtk_main_quit();
00495 }
00496 else
00497 {
00498 //update the history list
00499 combo_init(combo_mode);
00500 }
00501 }
00502 }
|
Here is the call graph for this function:

|
|
execute bash in interactive mode Definition at line 57 of file main.h. Referenced by main(), and run_command(). |
|
|
the command line entered in the entry box Definition at line 54 of file main.h. Referenced by main(), on_mainWindow_destroy(), run_command(), and writeHistory(). |
|
|
do not die unles killed Definition at line 39 of file main.h. Referenced by main(), on_combo_entry1_key_press_event(), and run_command(). |
|
|
the history file Definition at line 49 of file main.h. Referenced by combo_init(), main(), on_combo_entry1_key_press_event(), on_mainWindow_destroy(), on_runButton_clicked(), and run_command(). |
|
|
the history length Definition at line 50 of file main.h. Referenced by main(), and readHistory(). |
|
|
the home directory Definition at line 48 of file main.h. Referenced by main(), and on_mainWindow_destroy(). |
|
|
keep the terminal open Definition at line 41 of file main.h. Referenced by main(), on_combo_entry1_key_press_event(), and run_command(). |
|
|
do not allow kbhit Definition at line 40 of file main.h. Referenced by main(), and run_command(). |
|
|
toggle run_in_term checkbox Definition at line 38 of file main.h. Referenced by main(), on_checkbutton_toggled(), and run_command(). |
|
|
this is the path to a terminal program Definition at line 51 of file main.h. Referenced by main(), on_mainWindow_destroy(), and run_command(). |
1.3.5