1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| pipe_name = "\\\\.\\pipe\\pgsqlrestore";
// Socket creation and connection
// Reads data on the Socket
error_test = RecvFromSocket(restore_data);
if(error_test != 0)
{
printf("Error during the database restore\n");
return 12;
}
// Named Pipe creation
pipe = CreateNamedPipe(
pipe_name, // name of the pipe
PIPE_ACCESS_DUPLEX, // Read/Write
PIPE_TYPE_BYTE, // send data as a byte stream
1, // only allow 1 instance of this pipe
0, // no outbound buffer
0, // no inbound buffer
0, // use default wait time
NULL // use default security attributes
);
if(pipe == NULL || pipe == INVALID_HANDLE_VALUE)
{
printf("Failed to create the named pipe '%s'!\n", pipe_name);
CloseHandle(pipe);
return 6;
}
// Creation of the execute_string
pgrestore_instance_string = (char*)malloc(27+strlen(ConSQL->repertory)+strlen(ConSQL->login)+strlen(ConSQL->instance)+strlen(pipe_name));
if(pgrestore_instance_string == NULL)
{
printf("Memory error!\n");
return 1;
}
sprintf(pgrestore_instance_string, "\"\"%spsql.exe\" -U %s -p %s -f \"%s\"\"", ConSQL->repertory, ConSQL->login, ConSQL->instance, pipe_name);
// Execute the mysqlrestore using a thread
thread = CreateThread(NULL, 0, Thread_PGSQLRestore, (LPVOID)pgrestore_instance_string, 0, NULL);
if( thread == NULL )
{
printf("Failed to launch the PGSQLRestore Thread!\n");
return 8;
}
Sleep(600); // Ici le timing en question dont je vous parlait
// Write the restore_data on the named pipe
result = WriteFile(
pipe, // handle to our generic write pipe
restore_data, // data to send
strlen(restore_data), // length of data to send (bytes)
&numBytesWritten, // will store actual amount of data sent
NULL // not using overlapped IO
);
if(!result)
{
printf("Error while sending data to the named pipe: %d\n", GetLastError());
CloseHandle(pipe);
return 2;
}
CloseHandle(pipe);
free(pgrestore_instance_string); |
Partager