Browse Source

Added shell parameter "max_single_command_length"

Ivan Arkhipov 5 years ago
parent
commit
925972be8d
4 changed files with 25 additions and 3 deletions
  1. 0 0
      esh_constants.h
  2. 13 1
      esh_init.c
  3. 1 0
      esh_misc.c
  4. 11 2
      esh_types.h

+ 0 - 0
esh_constants.h


+ 13 - 1
esh_init.c

@@ -20,6 +20,7 @@ void EShInit(int argc, char** argv) {
 		   "Commands history file path: %s\n"
 		   "Max history lines: %d\n"
 		   "Max running jobs: %d\n"
+		   "Max single command length: %d\n"
 		   "===================================\n",
 		   esh_info_global->user_data->pw_name, 
 		   esh_info_global->build_ref,
@@ -28,7 +29,8 @@ void EShInit(int argc, char** argv) {
 		   esh_info_global->config_file_path,
 		   esh_info_global->history_file_path,
 		   esh_info_global->history_limit,
-		   esh_info_global->max_jobs_number);
+		   esh_info_global->max_jobs_number,
+		   esh_info_global->max_command_length);
 }
  
 void EShInitInfo(int argc, char** argv) {
@@ -59,6 +61,8 @@ void EShInitInfo(int argc, char** argv) {
 
 	esh_info_global->max_jobs_number = 64;
 
+	esh_info_global->max_command_length = 1024;
+
 	esh_info_global->jobs_number = 0;
 
 	esh_info_global->max_invite_message_len = 2048;
@@ -95,6 +99,10 @@ void EShParseCommandLineArgs(int argc, char** argv) {
 		if (strcmp(argv[i], "-max_active_jobs") == 0) {
 			sscanf(argv[i + 1], "%d", &esh_info_global->max_jobs_number);
 		}
+		
+		if (strcmp(argv[i], "-max_command_length") == 0) {
+			sscanf(argv[i + 1], "%d", &esh_info_global->max_command_length);
+		}
 	}
 }
 
@@ -124,6 +132,10 @@ void EShProcessConfigFile() {
 		if (strstr(line, "max_active_jobs=") == line) {
 			sscanf(line + strlen("max_active_jobs="), "%d", &esh_info_global->max_jobs_number);
 		}
+
+		if (strstr(line, "max_command_length=") == line) {
+			sscanf(line + strlen("max_command_length="), "%d", &esh_info_global->max_command_length);
+		}
     }
 
 	fclose(file);

+ 1 - 0
esh_misc.c

@@ -36,6 +36,7 @@ void EShShowHelpAndExit() {
 		   "-history_path FILENAME      uses file with name FILENAME as storage for entered commands history (default: ~/.esh_history)\n"
 		   "-history_limit INT          limits commands number to keep up to INT (default: 5000 lines)\n"
 		   "-max_active_jobs INT        limits shell active jobs number up to INT (default: 64)\n"
+		   "-max_command_length INT     limits maximum length of single command up to INT (default: 1024 chars)\n"
 		   "\n"
 		   "\n"
 		   "Copyleft. Written by Ivan Arkhipov aka Endevir (me@endevir.ru), MIPT, Dolgoprudny, Russia, 2019.\n",

+ 11 - 2
esh_types.h

@@ -20,10 +20,18 @@ typedef enum {
 	EXEC_CMD
 } ESH_COMMAND_TYPE;
 
+typedef enum {
+	NO_CONDITION, // ex. commands delimited by ';' 
+	PREVIOUS_EXIT_SUCCESS, // ex. commands delimited by '&&'
+	PREVIOUS_EXIT_FAILED // ex. commands delimited by '||'
+} ESH_JOB_CONDITION;
+
 typedef struct {
 	char* command;
 	ESH_COMMAND_TYPE command_type;
 	ESH_JOB_TYPE job_type;
+	ESH_JOB_CONDITION job_start_condition;
+
 	pid_t job_pid;
 
 	int stdout_pipe[2]; // 0 is for writing in child process and for reading in parent process.
@@ -35,11 +43,12 @@ typedef struct {
 	struct passwd* user_data;
 	char* current_working_dir;
 
-	char* config_file_path; // path to file, containing configurations (changeable via settings/cmd line args)
+	char* config_file_path; // path to file, containing configurations (changeable via cmd line args)
 	char* history_file_path; // path to file, where entered commands history is stored (changeable via settings/cmd line args)
 	int history_limit; // max lines of commands, which can be stored (changeable via settings/cmd line args)
 	int max_jobs_number; // max active jobs (foreground & background) limit (changeable via settings/cmd line args)
-
+	int max_command_length; // max length of single command (changeable via settings/cmd line args)
+	
 	int max_invite_message_len;
 	char* invite_message;