Mercurial > hg > orthanc
comparison Core/SystemToolbox.cpp @ 2954:d924f9bb61cc
taking advantage of details in OrthancException
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 03 Dec 2018 14:35:34 +0100 |
parents | 4a38d7d4f0e0 |
children | db8f360fcb41 |
comparison
equal
deleted
inserted
replaced
2953:210d5afd8f2b | 2954:d924f9bb61cc |
---|---|
214 void SystemToolbox::ReadFile(std::string& content, | 214 void SystemToolbox::ReadFile(std::string& content, |
215 const std::string& path) | 215 const std::string& path) |
216 { | 216 { |
217 if (!IsRegularFile(path)) | 217 if (!IsRegularFile(path)) |
218 { | 218 { |
219 LOG(ERROR) << "The path does not point to a regular file: " << path; | 219 throw OrthancException(ErrorCode_RegularFileExpected, |
220 throw OrthancException(ErrorCode_RegularFileExpected); | 220 "The path does not point to a regular file: " + path); |
221 } | 221 } |
222 | 222 |
223 boost::filesystem::ifstream f; | 223 boost::filesystem::ifstream f; |
224 f.open(path, std::ifstream::in | std::ifstream::binary); | 224 f.open(path, std::ifstream::in | std::ifstream::binary); |
225 if (!f.good()) | 225 if (!f.good()) |
242 const std::string& path, | 242 const std::string& path, |
243 size_t headerSize) | 243 size_t headerSize) |
244 { | 244 { |
245 if (!IsRegularFile(path)) | 245 if (!IsRegularFile(path)) |
246 { | 246 { |
247 LOG(ERROR) << "The path does not point to a regular file: " << path; | 247 throw OrthancException(ErrorCode_RegularFileExpected, |
248 throw OrthancException(ErrorCode_RegularFileExpected); | 248 "The path does not point to a regular file: " + path); |
249 } | 249 } |
250 | 250 |
251 boost::filesystem::ifstream f; | 251 boost::filesystem::ifstream f; |
252 f.open(path, std::ifstream::in | std::ifstream::binary); | 252 f.open(path, std::ifstream::in | std::ifstream::binary); |
253 if (!f.good()) | 253 if (!f.good()) |
482 int pid = fork(); | 482 int pid = fork(); |
483 | 483 |
484 if (pid == -1) | 484 if (pid == -1) |
485 { | 485 { |
486 // Error in fork() | 486 // Error in fork() |
487 #if ORTHANC_ENABLE_LOGGING == 1 | 487 throw OrthancException(ErrorCode_SystemCommand, "Cannot fork a child process"); |
488 LOG(ERROR) << "Cannot fork a child process"; | |
489 #endif | |
490 | |
491 throw OrthancException(ErrorCode_SystemCommand); | |
492 } | 488 } |
493 else if (pid == 0) | 489 else if (pid == 0) |
494 { | 490 { |
495 // Execute the system command in the child process | 491 // Execute the system command in the child process |
496 execvp(command.c_str(), &args[0]); | 492 execvp(command.c_str(), &args[0]); |
505 } | 501 } |
506 #endif | 502 #endif |
507 | 503 |
508 if (status != 0) | 504 if (status != 0) |
509 { | 505 { |
510 #if ORTHANC_ENABLE_LOGGING == 1 | 506 throw OrthancException(ErrorCode_SystemCommand, |
511 LOG(ERROR) << "System command failed with status code " << status; | 507 "System command failed with status code " + |
512 #endif | 508 boost::lexical_cast<std::string>(status)); |
513 | |
514 throw OrthancException(ErrorCode_SystemCommand); | |
515 } | 509 } |
516 } | 510 } |
517 | 511 |
518 | 512 |
519 int SystemToolbox::GetProcessId() | 513 int SystemToolbox::GetProcessId() |