Skip to content

Commit b772eed

Browse files
committed
handle signals
HAndle signals to close the miner
1 parent eff66ca commit b772eed

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

xmrstak/backend/amd/amd_gpu/gpu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ size_t InitOpenCLGpu(cl_context opencl_ctx, GpuContext* ctx, const char* source_
607607
return 0;
608608
}
609609

610-
size_t FinalizeOpenCL(GpuContext* ctx)
610+
void FinalizeOpenCL(GpuContext* ctx)
611611
{
612612
xmrstak_algo miner_algo[2] = {
613613
::jconf::inst()->GetCurrentCoinSelection().GetDescription(1).GetMiningAlgo(),

xmrstak/backend/amd/amd_gpu/gpu.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int getAMDPlatformIdx();
5252
std::vector<GpuContext> getAMDDevices(int index);
5353

5454
size_t InitOpenCL(GpuContext* ctx, size_t num_gpus, size_t platform_idx);
55-
size_t FinalizeOpenCL(GpuContext* ctx);
55+
void FinalizeOpenCL(GpuContext* ctx);
5656
size_t XMRSetJob(GpuContext* ctx, uint8_t* input, size_t input_len, uint64_t target, xmrstak_algo miner_algo);
5757
size_t XMRRunJob(GpuContext* ctx, cl_uint* HashOutput, xmrstak_algo miner_algo);
5858

xmrstak/cli/cli-miner.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@
5555
# include "xmrstak/misc/uac.hpp"
5656
#endif // _WIN32
5757

58+
#include <csignal>
59+
60+
// exit miner if we receive a signal e.g. CTRL+C
61+
void signal_handler(int signal)
62+
{
63+
executor::inst()->shutdown();
64+
}
65+
5866
int do_benchmark(int block_version, int wait_sec, int work_sec);
5967

6068
void help()
@@ -747,6 +755,10 @@ int main(int argc, char *argv[])
747755
if(strlen(jconf::inst()->GetOutputFile()) != 0)
748756
printer::inst()->open_logfile(jconf::inst()->GetOutputFile());
749757

758+
std::signal(SIGINT, signal_handler);
759+
std::signal(SIGABRT, signal_handler);
760+
std::signal(SIGTERM, signal_handler);
761+
750762
if (!BackendConnector::self_test())
751763
{
752764
printer::inst()->print_msg(L0, "Self test not passed!");
@@ -814,7 +826,6 @@ int main(int argc, char *argv[])
814826
while(!forceQuit && !exec->isShutdownFinished())
815827
{
816828
key = get_key();
817-
818829
switch(key)
819830
{
820831
case 'h':

xmrstak/misc/executor.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include <assert.h>
4646
#include <time.h>
4747

48-
4948
#ifdef _WIN32
5049
#define strncasecmp _strnicmp
5150
#endif // _WIN32
@@ -488,7 +487,7 @@ inline void disable_sigpipe() {}
488487
#endif
489488

490489
void executor::ex_main()
491-
{
490+
{
492491
disable_sigpipe();
493492

494493
assert(1000 % iTickTime == 0);
@@ -599,7 +598,7 @@ void executor::ex_main()
599598
// If the user requested it, start the autohash printer
600599
if(jconf::inst()->GetVerboseLevel() >= 4)
601600
push_timed_event(ex_event(EV_HASHRATE_LOOP), jconf::inst()->GetAutohashTime());
602-
601+
603602
size_t cnt = 0;
604603
while(!bQuit)
605604
{

0 commit comments

Comments
 (0)