cvs commit: ALFS/nALFS/src/handlers conditionals.c execute.c

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Sat Feb 7 19:15:09 PST 2004


kpfleming    04/02/07 20:15:09

  Modified:    nALFS/src backend.c backend.h
               nALFS/src/handlers conditionals.c execute.c
  Log:
  replace do_execute_command with execute_direct_command, which allows execution of a specify command path (does not assume a shell will be used)
  modify <execute> handler to use execute_direct_command to execute its temporary script when <content> is used
  add execute_shell_command, new function to be used by version 3.2 handlers that will support <shell> element in <stageinfo>
  mark existing execute_command function as deprecated, all future handlers should use execute_shell_command instead
  
  Revision  Changes    Path
  1.8       +34 -3     ALFS/nALFS/src/backend.c
  
  Index: backend.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/backend.c,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- backend.c	6 Feb 2004 05:54:36 -0000	1.7
  +++ backend.c	8 Feb 2004 03:15:09 -0000	1.8
  @@ -200,7 +200,7 @@
   	}
   }
   
  -static INLINE int do_execute_command(const char *cmdstring)
  +int execute_direct_command(const char *command, char *const argv[])
   {
   	int status, pfd[2];
   	pid_t got_pid, command_pid = 0;
  @@ -242,7 +242,7 @@
   				strerror(errno));
   		}
   
  -		execlp("sh", "sh", "-c", cmdstring, NULL);
  +		execvp(command, argv);
   
   		Nprint_err("Executing command using \"sh\" failed: %s",
   			strerror(errno));
  @@ -288,11 +288,38 @@
   	return status;
   }
   
  +int execute_shell_command(element_s *element, const char *format, ...)
  +{
  +	va_list ap;
  +	int status = 0;
  +	char command[MAX_COMMAND_LEN];
  +	char *args[4];
  +
  +
  +	va_start(ap, format);
  +	status = vsnprintf(command, sizeof command, format, ap);
  +	va_end(ap);
  +
  +	if (status > -1 && status < (int) sizeof command) {
  +		args[0] = "sh";
  +		args[1] = "-c";
  +		args[2] = command;
  +		args[3] = NULL;
  +		status = execute_direct_command("sh", args);
  +	} else {
  +		Nprint_err("System command is too long.");
  +		return -1;
  +	}
  +
  +	return status;
  +}
  +
   int execute_command(const char *format, ...)
   {
   	va_list ap;
   	int status = 0;
   	char command[MAX_COMMAND_LEN];
  +	char *args[4];
   
   
   	va_start(ap, format);
  @@ -300,7 +327,11 @@
   	va_end(ap);
   
   	if (status > -1 && status < (int) sizeof command) {
  -		status = do_execute_command(command);
  +		args[0] = "sh";
  +		args[1] = "-c";
  +		args[2] = command;
  +		args[3] = NULL;
  +		status = execute_direct_command("sh", args);
   	} else {
   		Nprint_err("System command is too long.");
   		return -1;
  
  
  
  1.4       +4 -0      ALFS/nALFS/src/backend.h
  
  Index: backend.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/backend.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- backend.h	6 Feb 2004 05:54:36 -0000	1.3
  +++ backend.h	8 Feb 2004 03:15:09 -0000	1.4
  @@ -42,7 +42,11 @@
   
   void fatal_backend_error(const char *format, ...);
   
  +/* execute_command() is deprecated, please use execute_shell_command() */
   int execute_command(const char *format, ...);
  +
  +int execute_direct_command(const char *command, char *const argv[]);
  +int execute_shell_command(element_s *element, const char *format, ...);
   
   int do_execute_test_element(element_s *element, int *result);
   int execute_children(element_s *element);
  
  
  
  1.3       +4 -0      ALFS/nALFS/src/handlers/conditionals.c
  
  Index: conditionals.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/conditionals.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- conditionals.c	7 Feb 2004 04:24:22 -0000	1.2
  +++ conditionals.c	8 Feb 2004 03:15:09 -0000	1.3
  @@ -226,11 +226,15 @@
   
   static int package_version_test_3_2(element_s *element, int *result)
   {
  +	(void) element;
  +	(void) result;
   	return 0;
   }
   
   static int package_built_test_3_2(element_s *element, int *result)
   {
  +	(void) element;
  +	(void) result;
   	return 0;
   }
   #endif
  
  
  
  1.18      +4 -1      ALFS/nALFS/src/handlers/execute.c
  
  Index: execute.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/execute.c,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- execute.c	8 Feb 2004 02:21:36 -0000	1.17
  +++ execute.c	8 Feb 2004 03:15:09 -0000	1.18
  @@ -207,6 +207,7 @@
   		FILE *temp_script;
   		char *tok;
   		char *temp_file_name;
  +		char *args[2];
   
   		temp_file_name = xstrdup(*opt_alfs_directory);
   		append_str(&temp_file_name, "/");
  @@ -224,7 +225,9 @@
   					Nprint_h_err("    %s (%s)", temp_file_name, strerror(errno));
   				} else {
   					Nprint_h("Executing script in %s:", base);
  -					status = execute_command(temp_file_name);
  +					args[0] = "nALFS_temp_script";
  +					args[1] = NULL;
  +					status = execute_direct_command(temp_file_name, args);
   				}
   				unlink(temp_file_name);
   			} else {
  
  
  



More information about the alfs-log mailing list