mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-25 22:14:36 +00:00
Numerous style police clean ups in cgminer.c
This commit is contained in:
parent
1e9421475c
commit
830f2902b9
163
cgminer.c
163
cgminer.c
@ -445,6 +445,7 @@ struct pool *current_pool(void)
|
|||||||
char *set_int_range(const char *arg, int *i, int min, int max)
|
char *set_int_range(const char *arg, int *i, int min, int max)
|
||||||
{
|
{
|
||||||
char *err = opt_set_intval(arg, i);
|
char *err = opt_set_intval(arg, i);
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
@ -594,7 +595,7 @@ static char *set_userpass(const char *arg)
|
|||||||
static char *enable_debug(bool *flag)
|
static char *enable_debug(bool *flag)
|
||||||
{
|
{
|
||||||
*flag = true;
|
*flag = true;
|
||||||
/* Turn out verbose output, too. */
|
/* Turn on verbose output, too. */
|
||||||
opt_log_output = true;
|
opt_log_output = true;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -609,8 +610,8 @@ static char *set_schedtime(const char *arg, struct schedtime *st)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char*
|
static char* set_sharelog(char *arg)
|
||||||
set_sharelog(char *arg) {
|
{
|
||||||
char *r = "";
|
char *r = "";
|
||||||
long int i = strtol(arg, &r, 10);
|
long int i = strtol(arg, &r, 10);
|
||||||
|
|
||||||
@ -662,11 +663,11 @@ static void load_temp_cutoffs()
|
|||||||
|
|
||||||
devices[device]->cutofftemp = val;
|
devices[device]->cutofftemp = val;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
for (i = device; i < total_devices; ++i) {
|
||||||
for (i = device; i < total_devices; ++i)
|
|
||||||
if (!devices[i]->cutofftemp)
|
if (!devices[i]->cutofftemp)
|
||||||
devices[i]->cutofftemp = opt_cutofftemp;
|
devices[i]->cutofftemp = opt_cutofftemp;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (device <= 1) {
|
if (device <= 1) {
|
||||||
@ -1025,6 +1026,7 @@ static char *parse_config(json_t *config, bool fileconf)
|
|||||||
name = strdup(opt->names);
|
name = strdup(opt->names);
|
||||||
for (p = strtok(name, "|"); p; p = strtok(NULL, "|")) {
|
for (p = strtok(name, "|"); p; p = strtok(NULL, "|")) {
|
||||||
char *err = NULL;
|
char *err = NULL;
|
||||||
|
|
||||||
/* Ignore short options. */
|
/* Ignore short options. */
|
||||||
if (p[1] != '-')
|
if (p[1] != '-')
|
||||||
continue;
|
continue;
|
||||||
@ -1117,8 +1119,7 @@ static void load_default_config(void)
|
|||||||
if (getenv("HOME") && *getenv("HOME")) {
|
if (getenv("HOME") && *getenv("HOME")) {
|
||||||
strcpy(cnfbuf, getenv("HOME"));
|
strcpy(cnfbuf, getenv("HOME"));
|
||||||
strcat(cnfbuf, "/");
|
strcat(cnfbuf, "/");
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
strcpy(cnfbuf, "");
|
strcpy(cnfbuf, "");
|
||||||
strcat(cnfbuf, ".cgminer/");
|
strcat(cnfbuf, ".cgminer/");
|
||||||
#else
|
#else
|
||||||
@ -4800,71 +4801,72 @@ out:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(unix)
|
#if defined(unix)
|
||||||
static void fork_monitor()
|
static void fork_monitor()
|
||||||
{
|
{
|
||||||
// Make a pipe: [readFD, writeFD]
|
// Make a pipe: [readFD, writeFD]
|
||||||
int pfd[2];
|
int pfd[2];
|
||||||
int r = pipe(pfd);
|
int r = pipe(pfd);
|
||||||
if (r<0) {
|
|
||||||
perror("pipe - failed to create pipe for --monitor");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make stderr write end of pipe
|
if (r < 0) {
|
||||||
fflush(stderr);
|
perror("pipe - failed to create pipe for --monitor");
|
||||||
r = dup2(pfd[1], 2);
|
exit(1);
|
||||||
if (r<0) {
|
|
||||||
perror("dup2 - failed to alias stderr to write end of pipe for --monitor");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
r = close(pfd[1]);
|
|
||||||
if (r<0) {
|
|
||||||
perror("close - failed to close write end of pipe for --monitor");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't allow a dying monitor to kill the main process
|
|
||||||
sighandler_t sr0 = signal(SIGPIPE, SIG_IGN);
|
|
||||||
sighandler_t sr1 = signal(SIGPIPE, SIG_IGN);
|
|
||||||
if (SIG_ERR==sr0 || SIG_ERR==sr1) {
|
|
||||||
perror("signal - failed to edit signal mask for --monitor");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fork a child process
|
|
||||||
forkpid = fork();
|
|
||||||
if (forkpid<0) {
|
|
||||||
perror("fork - failed to fork child process for --monitor");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Child: launch monitor command
|
|
||||||
if (0==forkpid) {
|
|
||||||
// Make stdin read end of pipe
|
|
||||||
r = dup2(pfd[0], 0);
|
|
||||||
if (r<0) {
|
|
||||||
perror("dup2 - in child, failed to alias read end of pipe to stdin for --monitor");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
close(pfd[0]);
|
|
||||||
if (r<0) {
|
|
||||||
perror("close - in child, failed to close read end of pipe for --monitor");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Launch user specified command
|
|
||||||
execl("/bin/bash", "/bin/bash", "-c", opt_stderr_cmd, (char*)NULL);
|
|
||||||
perror("execl - in child failed to exec user specified command for --monitor");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parent: clean up unused fds and bail
|
|
||||||
r = close(pfd[0]);
|
|
||||||
if (r<0) {
|
|
||||||
perror("close - failed to close read end of pipe for --monitor");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make stderr write end of pipe
|
||||||
|
fflush(stderr);
|
||||||
|
r = dup2(pfd[1], 2);
|
||||||
|
if (r < 0) {
|
||||||
|
perror("dup2 - failed to alias stderr to write end of pipe for --monitor");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
r = close(pfd[1]);
|
||||||
|
if (r < 0) {
|
||||||
|
perror("close - failed to close write end of pipe for --monitor");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't allow a dying monitor to kill the main process
|
||||||
|
sighandler_t sr0 = signal(SIGPIPE, SIG_IGN);
|
||||||
|
sighandler_t sr1 = signal(SIGPIPE, SIG_IGN);
|
||||||
|
if (SIG_ERR == sr0 || SIG_ERR == sr1) {
|
||||||
|
perror("signal - failed to edit signal mask for --monitor");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fork a child process
|
||||||
|
forkpid = fork();
|
||||||
|
if (forkpid < 0) {
|
||||||
|
perror("fork - failed to fork child process for --monitor");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Child: launch monitor command
|
||||||
|
if (0 == forkpid) {
|
||||||
|
// Make stdin read end of pipe
|
||||||
|
r = dup2(pfd[0], 0);
|
||||||
|
if (r < 0) {
|
||||||
|
perror("dup2 - in child, failed to alias read end of pipe to stdin for --monitor");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
close(pfd[0]);
|
||||||
|
if (r < 0) {
|
||||||
|
perror("close - in child, failed to close read end of pipe for --monitor");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Launch user specified command
|
||||||
|
execl("/bin/bash", "/bin/bash", "-c", opt_stderr_cmd, (char*)NULL);
|
||||||
|
perror("execl - in child failed to exec user specified command for --monitor");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parent: clean up unused fds and bail
|
||||||
|
r = close(pfd[0]);
|
||||||
|
if (r < 0) {
|
||||||
|
perror("close - failed to close read end of pipe for --monitor");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif // defined(unix)
|
#endif // defined(unix)
|
||||||
|
|
||||||
#ifdef HAVE_CURSES
|
#ifdef HAVE_CURSES
|
||||||
@ -4946,8 +4948,7 @@ bool add_cgpu(struct cgpu_info*cgpu)
|
|||||||
HASH_FIND_STR(devids, cgpu->api->name, d);
|
HASH_FIND_STR(devids, cgpu->api->name, d);
|
||||||
if (d)
|
if (d)
|
||||||
cgpu->device_id = ++d->lastid;
|
cgpu->device_id = ++d->lastid;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
d = malloc(sizeof(*d));
|
d = malloc(sizeof(*d));
|
||||||
memcpy(d->name, cgpu->api->name, sizeof(d->name));
|
memcpy(d->name, cgpu->api->name, sizeof(d->name));
|
||||||
cgpu->device_id = d->lastid = 0;
|
cgpu->device_id = d->lastid = 0;
|
||||||
@ -5106,14 +5107,16 @@ int main(int argc, char *argv[])
|
|||||||
opt_log_output = true;
|
opt_log_output = true;
|
||||||
|
|
||||||
#ifdef WANT_CPUMINE
|
#ifdef WANT_CPUMINE
|
||||||
if (0<=opt_bench_algo) {
|
if (0 <= opt_bench_algo) {
|
||||||
double rate = bench_algo_stage3(opt_bench_algo);
|
double rate = bench_algo_stage3(opt_bench_algo);
|
||||||
if (!skip_to_bench) {
|
|
||||||
|
if (!skip_to_bench)
|
||||||
printf("%.5f (%s)\n", rate, algo_names[opt_bench_algo]);
|
printf("%.5f (%s)\n", rate, algo_names[opt_bench_algo]);
|
||||||
} else {
|
else {
|
||||||
// Write result to shared memory for parent
|
// Write result to shared memory for parent
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
char unique_name[64];
|
char unique_name[64];
|
||||||
|
|
||||||
if (GetEnvironmentVariable("CGMINER_SHARED_MEM", unique_name, 32)) {
|
if (GetEnvironmentVariable("CGMINER_SHARED_MEM", unique_name, 32)) {
|
||||||
HANDLE map_handle = CreateFileMapping(
|
HANDLE map_handle = CreateFileMapping(
|
||||||
INVALID_HANDLE_VALUE, // use paging file
|
INVALID_HANDLE_VALUE, // use paging file
|
||||||
@ -5123,7 +5126,7 @@ int main(int argc, char *argv[])
|
|||||||
4096, // size: low 32-bits
|
4096, // size: low 32-bits
|
||||||
unique_name // name of map object
|
unique_name // name of map object
|
||||||
);
|
);
|
||||||
if (NULL!=map_handle) {
|
if (NULL != map_handle) {
|
||||||
void *shared_mem = MapViewOfFile(
|
void *shared_mem = MapViewOfFile(
|
||||||
map_handle, // object to map view of
|
map_handle, // object to map view of
|
||||||
FILE_MAP_WRITE, // read/write access
|
FILE_MAP_WRITE, // read/write access
|
||||||
@ -5131,13 +5134,13 @@ int main(int argc, char *argv[])
|
|||||||
0, // low offset: beginning
|
0, // low offset: beginning
|
||||||
0 // default: map entire file
|
0 // default: map entire file
|
||||||
);
|
);
|
||||||
if (NULL!=shared_mem)
|
if (NULL != shared_mem)
|
||||||
CopyMemory(shared_mem, &rate, sizeof(rate));
|
CopyMemory(shared_mem, &rate, sizeof(rate));
|
||||||
(void)UnmapViewOfFile(shared_mem);
|
(void)UnmapViewOfFile(shared_mem);
|
||||||
}
|
}
|
||||||
(void)CloseHandle(map_handle);
|
(void)CloseHandle(map_handle);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user