Display version information and add --version command line option, and make sure we flush stdout.
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
diff --git a/ccan/opt/helpers.c b/ccan/opt/helpers.c
index e657ebf..315b7e4 100644
--- a/ccan/opt/helpers.c
+++ b/ccan/opt/helpers.c
@@ -120,12 +120,14 @@ char *opt_inc_intval(int *i)
char *opt_version_and_exit(const char *version)
{
printf("%s\n", version);
+ fflush(stdout);
exit(0);
}
char *opt_usage_and_exit(const char *extra)
{
printf("%s", opt_usage(opt_argv0, extra));
+ fflush(stdout);
exit(0);
}
diff --git a/main.c b/main.c
index 0fb28b5..2aa7422 100644
--- a/main.c
+++ b/main.c
@@ -46,8 +46,6 @@
#include <sys/types.h>
#endif
-#define PROGRAM_NAME "cgminer"
-
#ifdef __linux /* Linux specific policy and affinity management */
#include <sched.h>
static inline void drop_policy(void)
@@ -174,6 +172,8 @@ static const sha256_func sha256_funcs[] = {
#endif
};
+static char packagename[255];
+
bool opt_debug = false;
bool opt_protocol = false;
static bool want_longpoll = true;
@@ -331,7 +331,7 @@ void get_timestamp(char *f, struct timeval *tv)
static void applog_and_exit(const char *fmt, ...)
{
va_list ap;
-
+
va_start(ap, fmt);
vapplog(LOG_ERR, fmt, ap);
va_end(ap);
@@ -1252,6 +1252,22 @@ static char *print_ndevs_and_exit(int *ndevs)
}
#endif
+extern const char *opt_argv0;
+
+static char *opt_verusage_and_exit(const char *extra)
+{
+ printf("%s\n"
+#ifdef HAVE_OPENCL
+ "Built with CPU and GPU mining support.\n"
+#else
+ "Built with CPU mining support only.\n"
+#endif
+ , packagename);
+ printf("%s", opt_usage(opt_argv0, extra));
+ fflush(stdout);
+ exit(0);
+}
+
/* These options are available from commandline only */
static struct opt_table opt_cmdline_table[] = {
OPT_WITH_ARG("--config|-c",
@@ -1259,18 +1275,16 @@ static struct opt_table opt_cmdline_table[] = {
"Load a JSON-format configuration file\n"
"See example-cfg.json for an example configuration."),
OPT_WITHOUT_ARG("--help|-h",
- opt_usage_and_exit,
-#ifdef HAVE_OPENCL
- "\nBuilt with CPU and GPU mining support.\n",
-#else
- "\nBuilt with CPU mining support only.\n",
-#endif
+ opt_verusage_and_exit, NULL,
"Print this message"),
#ifdef HAVE_OPENCL
OPT_WITHOUT_ARG("--ndevs|-n",
print_ndevs_and_exit, &nDevs,
"Enumerate number of detected GPUs and exit"),
#endif
+ OPT_WITHOUT_ARG("--version|-V",
+ opt_version_and_exit, packagename,
+ "Display version and exit"),
OPT_ENDTABLE
};
@@ -1373,7 +1387,7 @@ static void curses_print_status(int thr_id)
wmove(statuswin, 0, 0);
wattron(statuswin, A_BOLD);
- wprintw(statuswin, " " PROGRAM_NAME " version " VERSION " - Started: %s", datestamp);
+ wprintw(statuswin, " " PACKAGE " version " VERSION " - Started: %s", datestamp);
if (opt_n_threads)
wprintw(statuswin, " CPU Algo: %s", algo_names[opt_algo]);
wattroff(statuswin, A_BOLD);
@@ -4494,6 +4508,8 @@ int main (int argc, char *argv[])
if (unlikely(pthread_rwlock_init(&blk_lock, NULL)))
quit(1, "Failed to pthread_rwlock_init");
+ sprintf(packagename, "%s %s", PACKAGE, VERSION);
+
init_max_name_len();
handler.sa_handler = &sighandler;
@@ -4570,6 +4586,8 @@ int main (int argc, char *argv[])
if (argc != 1)
quit(1, "Unexpected extra commandline arguments");
+ applog(LOG_WARNING, "Started %s", packagename);
+
if (opt_nogpu)
nDevs = 0;
@@ -4703,7 +4721,7 @@ int main (int argc, char *argv[])
#ifdef HAVE_SYSLOG_H
if (use_syslog)
- openlog(PROGRAM_NAME, LOG_PID, LOG_USER);
+ openlog(PACKAGE, LOG_PID, LOG_USER);
#endif
#if defined(unix)