#include <sys/wait.h>
#include <sys/stat.h>
#include <unistd.h>
+#else
+char *\r
+tow32cmd(const char* cmd)\r
+{\r
+ static char w32cmd[PATH_MAX + 1] = {0};\r
+ char cmd_buf[PATH_MAX + 1] = {0};\r
+ size_t i,j, len;\r
+ \r
+ if(!cmd)\r
+ {\r
+ errno = EINVAL;\r
+ return NULL;\r
+ }\r
+ \r
+ /* TODO : if ~*/\r
+ if(cmd[0] != '.')\r
+ {\r
+ strcpy(w32cmd, cmd);\r
+ return w32cmd;\r
+ }\r
+ \r
+ i = j = 0;\r
+ len = strlen(cmd);\r
+ \r
+ while(i < len)\r
+ {\r
+ if(cmd[i] != ' ' && cmd[i] != '\t' && cmd[i] != '>')\r
+ cmd_buf[j++] = cmd[i];\r
+ else\r
+ break;\r
+ \r
+ i++;\r
+ }\r
+\r
+ _fullpath(w32cmd, cmd_buf, sizeof(w32cmd));\r
+ \r
+ if(!strstr(w32cmd, ".exe"))\r
+ strcat(w32cmd, ".exe ");\r
+ \r
+ strcat(w32cmd, cmd + i);\r
+ \r
+ \r
+ /*printf("w32cmd : %s", w32cmd);*/\r
+\r
+ return w32cmd;\r
+}
#endif
#include <com.h>
int
command_run(command_t command)
{
-
if(!silent_flag)
INFO2("[%s] %s",command->context->pos, command->context->command_line);
{
command_interrupt(command);
}
+
+
}
return 0;
}
#ifdef WIN32
+
+#ifndef BUFSIZE
+#define BUFSIZE 4096\r
+#endif
void
command_exec(command_t command, const char* command_line)
{
HANDLE child_stdout_handle[2] = {NULL}; /* child_stdout_handle[0] <-> stdin of the child process */
HANDLE child_stderr = NULL;
+
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL; /* use default security for the pipe handles */
return;
}
-
CloseHandle(child_stdin_handle[0]);
CloseHandle(child_stdout_handle[1]);
+
if(command->timer)
{
writer_write(command->writer);
}
+ /* if there is a reader wait for its starting */
+ if(command->reader)
+ xbt_os_sem_acquire(command->reader->started);
+
+ /* if there is a reader wait for its ending */
+ if(command->writer)
+ xbt_os_sem_acquire(command->writer->written);
+
+ /* if there is a reader wait for its starting */
+ if(command->timer)
+ xbt_os_sem_acquire(command->timer->started);
+
si.cb = sizeof(STARTUPINFO);
si.dwFlags |= STARTF_USESTDHANDLES;
/* launch the process */
if(!CreateProcess(
NULL,
- (char*)command_line,
+ tow32cmd(command_line),
NULL,
NULL,
TRUE,
&pi)
)
{
- ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string((int)GetLastError(), 0));
- command_handle_failure(command,csr_create_process_function_failure);
+ if(ERROR_FILE_NOT_FOUND == GetLastError())
+ {
+ ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string(ECMDNOTFOUND, 1));
+ unit_set_error(command->unit, ECMDNOTFOUND, 1);
+ command_handle_failure(command, csr_command_not_found);
+ }
+ else
+ {
+ ERROR3("[%s] `%s' : NOK (%s)", command->context->pos, command->context->command_line, error_to_string((int)GetLastError(), 0));
- unit_set_error(command->unit, (int)GetLastError(), 0);
+ unit_set_error(command->unit, (int)GetLastError(), 0);
+ command_handle_failure(command, csr_create_process_function_failure);
+ }
+
}
else
{
break;
case csr_unexpected_signal_caught:
- printf(" reason : unexpected signal caught\n");
+ printf(" reason : unexpected signal caught\n");
break;
case csr_expected_signal_not_receipt :
else
printf(" no expected exit code specified\n");
- /* if an expected exit code was specified display it */
+ /* no expected signal expected */
if(NULL == command->context->signal)
+ {
printf(" no expected signal specified\n");
+
+ if(command->signal)
+ printf(" but got signal : %s\n",command->signal);
+
+ }
+ /* if an expected exit code was specified display it */
else
{
if(NULL != command->signal)
printf(" signal : %s\n",command->signal);
-
- printf(" expected signal : %s\n",command->context->signal);
+ else
+ printf(" no signal caugth\n");
}
/* if the command has out put and the metacommand display output is specified display it */
void
command_handle_failure(command_t command, cs_reason_t reason)
{
-
unit_t root = command->root;
xbt_os_mutex_acquire(command->mutex);