Project Homepage Sourceforge Page CVS Repository Freshmeat.net Page Download project Author's Homepage

main.h File Reference


Detailed Description

run-free main include file

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:

Included by dependency graph

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.


Function Documentation

void run_command char *  command  ) 
 

Run a command.

Author:
Karl N. Redman
Parameters:
command The command we want to run
Purpose: Execute the command in a way that is consistant with the design of run-free.

Note:
This is a custom system() type call in order to handle environment settings properly (in the future) if this program is to be a setuid application (which is in the works)

Warning:
NOTE: this function is a potential security problem because we are not replacing the environment. if this is ever going to be a SUID application then I need to handle this. I'll work on this in the future -parasyte

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:


Variable Documentation

gboolean bash_shell_mode
 

execute bash in interactive mode

Definition at line 57 of file main.h.

Referenced by main(), and run_command().

char* 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().

gboolean die
 

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().

char* history_file
 

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().

int history_len
 

the history length

Definition at line 50 of file main.h.

Referenced by main(), and readHistory().

char* home_directory
 

the home directory

Definition at line 48 of file main.h.

Referenced by main(), and on_mainWindow_destroy().

gboolean keep_open
 

keep the terminal open

Definition at line 41 of file main.h.

Referenced by main(), on_combo_entry1_key_press_event(), and run_command().

gboolean no_kbhit
 

do not allow kbhit

Definition at line 40 of file main.h.

Referenced by main(), and run_command().

gboolean run_in_term
 

toggle run_in_term checkbox

Definition at line 38 of file main.h.

Referenced by main(), on_checkbutton_toggled(), and run_command().

char* terminal_path
 

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().


Generated on Thu Mar 18 07:26:19 2004 for run-free by doxygen 1.3.5