Browse Source

Merge commit 'bd3612c' into cg_merges_20130818a

Conflicts:
	util.c
Luke Dashjr 12 years ago
parent
commit
a16ff9404b
6 changed files with 55 additions and 26 deletions
  1. 1 1
      driver-avalon.c
  2. 2 2
      driver-bitforce.c
  3. 1 1
      driver-opencl.c
  4. 22 0
      logging.h
  5. 1 1
      miner.c
  6. 28 21
      util.c

+ 1 - 1
driver-avalon.c

@@ -667,7 +667,7 @@ static bool avalon_prepare(struct thr_info *thr)
 	avalon->works = calloc(info->miner_count * sizeof(struct work *),
 	avalon->works = calloc(info->miner_count * sizeof(struct work *),
 			       AVALON_ARRAY_SIZE);
 			       AVALON_ARRAY_SIZE);
 	if (!avalon->works)
 	if (!avalon->works)
-		quit(1, "Failed to calloc avalon works in avalon_prepare");
+		quithere(1, "Failed to calloc avalon works");
 	if (avalon->device_fd == -1)
 	if (avalon->device_fd == -1)
 		avalon_init(avalon);
 		avalon_init(avalon);
 	else
 	else

+ 2 - 2
driver-bitforce.c

@@ -696,9 +696,9 @@ bool bitforce_job_prepare(struct thr_info *thr, struct work *work, __maybe_unuse
 	switch (data->proto)
 	switch (data->proto)
 	{
 	{
 		case BFP_BQUEUE:
 		case BFP_BQUEUE:
-			quit(1, "%"PRIpreprv": Impossible BFP_BQUEUE in bitforce_job_prepare", bitforce->proc_repr);
+			quithere(1, "%"PRIpreprv": Impossible BFP_BQUEUE", bitforce->proc_repr);
 		case BFP_PQUEUE:
 		case BFP_PQUEUE:
-			quit(1, "%"PRIpreprv": Impossible BFP_PQUEUE in bitforce_job_prepare", bitforce->proc_repr);
+			quithere(1, "%"PRIpreprv": Impossible BFP_PQUEUE", bitforce->proc_repr);
 		case BFP_RANGE:
 		case BFP_RANGE:
 		{
 		{
 			uint32_t *ob_nonce = (uint32_t*)&(ob_dt[32]);
 			uint32_t *ob_nonce = (uint32_t*)&(ob_dt[32]);

+ 1 - 1
driver-opencl.c

@@ -1306,7 +1306,7 @@ select_cgpu:
 
 
 		thr->q = tq_new();
 		thr->q = tq_new();
 		if (!thr->q)
 		if (!thr->q)
-			quit(1, "Failed to tq_new in reinit_gpu");
+			quithere(1, "Failed to tq_new");
 
 
 		/* Lose this ram cause we may dereference in the dying thread! */
 		/* Lose this ram cause we may dereference in the dying thread! */
 		//free(clState);
 		//free(clState);

+ 22 - 0
logging.h

@@ -43,6 +43,8 @@ extern int opt_log_level;
 
 
 extern void _applog(int prio, const char *str);
 extern void _applog(int prio, const char *str);
 
 
+#define IN_FMT_FFL " in %s %s():%d"
+
 #define applog(prio, fmt, ...) do { \
 #define applog(prio, fmt, ...) do { \
 	if (opt_debug || prio != LOG_DEBUG) { \
 	if (opt_debug || prio != LOG_DEBUG) { \
 			char tmp42[LOGBUFSIZ]; \
 			char tmp42[LOGBUFSIZ]; \
@@ -68,6 +70,26 @@ extern void _bfg_clean_up(void);
 	_quit(status); \
 	_quit(status); \
 } while (0)
 } while (0)
 
 
+#define quithere(status, fmt, ...) do { \
+	if (fmt) { \
+		char tmp42[LOGBUFSIZ]; \
+		snprintf(tmp42, sizeof(tmp42), fmt IN_FMT_FFL, \
+				##__VA_ARGS__, __FILE__, __func__, __LINE__); \
+		_applog(LOG_ERR, tmp42); \
+	} \
+	_quit(status); \
+} while (0)
+
+#define quitfrom(status, _file, _func, _line, fmt, ...) do { \
+	if (fmt) { \
+		char tmp42[LOGBUFSIZ]; \
+		snprintf(tmp42, sizeof(tmp42), fmt IN_FMT_FFL, \
+				##__VA_ARGS__, _file, _func, _line); \
+		_applog(LOG_ERR, tmp42); \
+	} \
+	_quit(status); \
+} while (0)
+
 #ifdef HAVE_CURSES
 #ifdef HAVE_CURSES
 
 
 #define wlog(fmt, ...) do { \
 #define wlog(fmt, ...) do { \

+ 1 - 1
miner.c

@@ -4202,7 +4202,7 @@ static void push_curl_entry(struct curl_ent *ce, struct pool *pool)
 {
 {
 	mutex_lock(&pool->pool_lock);
 	mutex_lock(&pool->pool_lock);
 	if (!ce || !ce->curl)
 	if (!ce || !ce->curl)
-		quit(1, "Attempted to add NULL in push_curl_entry");
+		quithere(1, "Attempted to add NULL");
 	LL_PREPEND(pool->curllist, ce);
 	LL_PREPEND(pool->curllist, ce);
 	cgtime(&ce->tv);
 	cgtime(&ce->tv);
 	pthread_cond_broadcast(&pool->cr_cond);
 	pthread_cond_broadcast(&pool->cr_cond);

+ 28 - 21
util.c

@@ -1468,7 +1468,7 @@ static void recalloc_sock(struct pool *pool, size_t len)
 	// applog(LOG_DEBUG, "Recallocing pool sockbuf to %lu", (unsigned long)new);
 	// applog(LOG_DEBUG, "Recallocing pool sockbuf to %lu", (unsigned long)new);
 	pool->sockbuf = realloc(pool->sockbuf, new);
 	pool->sockbuf = realloc(pool->sockbuf, new);
 	if (!pool->sockbuf)
 	if (!pool->sockbuf)
-		quit(1, "Failed to realloc pool sockbuf in recalloc_sock");
+		quithere(1, "Failed to realloc pool sockbuf");
 	memset(pool->sockbuf + old, 0, new - old);
 	memset(pool->sockbuf + old, 0, new - old);
 	pool->sockbuf_size = new;
 	pool->sockbuf_size = new;
 }
 }
@@ -1574,18 +1574,18 @@ char *json_dumps_ANY(json_t *json, size_t flags)
 	size_t len;
 	size_t len;
 	
 	
 	if (!tmp)
 	if (!tmp)
-		quit(1, "json_dumps_ANY failed to allocate json array");
+		quithere(1, "Failed to allocate json array");
 	if (json_array_append(tmp, json))
 	if (json_array_append(tmp, json))
-		quit(1, "json_dumps_ANY failed to append temporary array");
+		quithere(1, "Failed to append temporary array");
 	s = json_dumps(tmp, flags);
 	s = json_dumps(tmp, flags);
 	if (!s)
 	if (!s)
 		return NULL;
 		return NULL;
 	for (i = 0; s[i] != '['; ++i)
 	for (i = 0; s[i] != '['; ++i)
 		if (unlikely(!(s[i] && isCspace(s[i]))))
 		if (unlikely(!(s[i] && isCspace(s[i]))))
-			quit(1, "json_dumps_ANY failed to find opening bracket in array dump");
+			quithere(1, "Failed to find opening bracket in array dump");
 	len = strlen(&s[++i]) - 1;
 	len = strlen(&s[++i]) - 1;
 	if (unlikely(s[i+len] != ']'))
 	if (unlikely(s[i+len] != ']'))
-		quit(1, "json_dumps_ANY failed to find closing bracket in array dump");
+		quithere(1, "Failed to find closing bracket in array dump");
 	rv = malloc(len + 1);
 	rv = malloc(len + 1);
 	memcpy(rv, &s[i], len);
 	memcpy(rv, &s[i], len);
 	rv[len] = '\0';
 	rv[len] = '\0';
@@ -1980,7 +1980,7 @@ static bool setup_stratum_curl(struct pool *pool)
 		curl_easy_cleanup(pool->stratum_curl);
 		curl_easy_cleanup(pool->stratum_curl);
 	pool->stratum_curl = curl_easy_init();
 	pool->stratum_curl = curl_easy_init();
 	if (unlikely(!pool->stratum_curl))
 	if (unlikely(!pool->stratum_curl))
-		quit(1, "Failed to curl_easy_init in initiate_stratum");
+		quithere(1, "Failed to curl_easy_init");
 	if (pool->sockbuf)
 	if (pool->sockbuf)
 		pool->sockbuf[0] = '\0';
 		pool->sockbuf[0] = '\0';
 
 
@@ -1989,7 +1989,7 @@ static bool setup_stratum_curl(struct pool *pool)
 	if (!pool->sockbuf) {
 	if (!pool->sockbuf) {
 		pool->sockbuf = calloc(RBUFSIZE, 1);
 		pool->sockbuf = calloc(RBUFSIZE, 1);
 		if (!pool->sockbuf)
 		if (!pool->sockbuf)
-			quit(1, "Failed to calloc pool sockbuf in initiate_stratum");
+			quithere(1, "Failed to calloc pool sockbuf");
 		pool->sockbuf_size = RBUFSIZE;
 		pool->sockbuf_size = RBUFSIZE;
 	}
 	}
 
 
@@ -2312,7 +2312,7 @@ void *realloc_strcat(char *ptr, char *s)
 
 
 	ret = malloc(len);
 	ret = malloc(len);
 	if (unlikely(!ret))
 	if (unlikely(!ret))
-		quit(1, "Failed to malloc in realloc_strcat");
+		quithere(1, "Failed to malloc");
 
 
 	sprintf(ret, "%s%s", ptr, s);
 	sprintf(ret, "%s%s", ptr, s);
 	free(ptr);
 	free(ptr);
@@ -2399,16 +2399,16 @@ struct bfgtls_data *get_bfgtls()
 	
 	
 	bfgtls = malloc(sizeof(*bfgtls));
 	bfgtls = malloc(sizeof(*bfgtls));
 	if (!bfgtls)
 	if (!bfgtls)
-		quit(1, "malloc bfgtls failed");
+		quithere(1, "malloc bfgtls failed");
 	p = malloc(64);
 	p = malloc(64);
 	if (!p)
 	if (!p)
-		quit(1, "malloc bfg_strerror_result failed");
+		quithere(1, "malloc bfg_strerror_result failed");
 	*bfgtls = (struct bfgtls_data){
 	*bfgtls = (struct bfgtls_data){
 		.bfg_strerror_resultsz = 64,
 		.bfg_strerror_resultsz = 64,
 		.bfg_strerror_result = p,
 		.bfg_strerror_result = p,
 	};
 	};
 	if (pthread_setspecific(key_bfgtls, bfgtls))
 	if (pthread_setspecific(key_bfgtls, bfgtls))
-		quit(1, "pthread_setspecific failed");
+		quithere(1, "pthread_setspecific failed");
 	
 	
 	return bfgtls;
 	return bfgtls;
 }
 }
@@ -2416,7 +2416,7 @@ struct bfgtls_data *get_bfgtls()
 void bfg_init_threadlocal()
 void bfg_init_threadlocal()
 {
 {
 	if (pthread_key_create(&key_bfgtls, NULL))
 	if (pthread_key_create(&key_bfgtls, NULL))
-		quit(1, "pthread_key_create failed");
+		quithere(1, "pthread_key_create failed");
 }
 }
 
 
 static
 static
@@ -2429,7 +2429,7 @@ bool bfg_grow_buffer(char ** const bufp, size_t * const bufszp, size_t minimum)
 		*bufszp = 2;
 		*bufszp = 2;
 	*bufp = realloc(*bufp, *bufszp);
 	*bufp = realloc(*bufp, *bufszp);
 	if (unlikely(!*bufp))
 	if (unlikely(!*bufp))
-		quit(1, "realloc failed in bfg_grow_buffer");
+		quithere(1, "realloc failed");
 	
 	
 	return true;
 	return true;
 }
 }
@@ -2536,10 +2536,12 @@ void notifier_init(notifier_t pipefd)
 	SOCKET listener, connecter, acceptor;
 	SOCKET listener, connecter, acceptor;
 	listener = socket(AF_INET, SOCK_STREAM, 0);
 	listener = socket(AF_INET, SOCK_STREAM, 0);
 	if (listener == INVALID_SOCKET)
 	if (listener == INVALID_SOCKET)
-		quit(1, "Failed to create listener socket in create_notifier: %s", WindowsErrorStr(WSAGetLastError()));
+		quit(1, "Failed to create listener socket"IN_FMT_FFL": %s",
+		     __FILE__, __func__, __LINE__, WindowsErrorStr(WSAGetLastError()));
 	connecter = socket(AF_INET, SOCK_STREAM, 0);
 	connecter = socket(AF_INET, SOCK_STREAM, 0);
 	if (connecter == INVALID_SOCKET)
 	if (connecter == INVALID_SOCKET)
-		quit(1, "Failed to create connect socket in create_notifier: %s", WindowsErrorStr(WSAGetLastError()));
+		quit(1, "Failed to create connect socket"IN_FMT_FFL": %s",
+		     __FILE__, __func__, __LINE__, WindowsErrorStr(WSAGetLastError()));
 	struct sockaddr_in inaddr = {
 	struct sockaddr_in inaddr = {
 		.sin_family = AF_INET,
 		.sin_family = AF_INET,
 		.sin_addr = {
 		.sin_addr = {
@@ -2552,25 +2554,30 @@ void notifier_init(notifier_t pipefd)
 		setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse));
 		setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse));
 	}
 	}
 	if (bind(listener, (struct sockaddr*)&inaddr, sizeof(inaddr)) == SOCKET_ERROR)
 	if (bind(listener, (struct sockaddr*)&inaddr, sizeof(inaddr)) == SOCKET_ERROR)
-		quit(1, "Failed to bind listener socket in create_notifier: %s", WindowsErrorStr(WSAGetLastError()));
+		quit(1, "Failed to bind listener socket"IN_FMT_FFL": %s",
+		     __FILE__, __func__, __LINE__, WindowsErrorStr(WSAGetLastError()));
 	socklen_t inaddr_sz = sizeof(inaddr);
 	socklen_t inaddr_sz = sizeof(inaddr);
 	if (getsockname(listener, (struct sockaddr*)&inaddr, &inaddr_sz) == SOCKET_ERROR)
 	if (getsockname(listener, (struct sockaddr*)&inaddr, &inaddr_sz) == SOCKET_ERROR)
-		quit(1, "Failed to getsockname in create_notifier: %s", WindowsErrorStr(WSAGetLastError()));
+		quit(1, "Failed to getsockname"IN_FMT_FFL": %s",
+		     __FILE__, __func__, __LINE__, WindowsErrorStr(WSAGetLastError()));
 	if (listen(listener, 1) == SOCKET_ERROR)
 	if (listen(listener, 1) == SOCKET_ERROR)
-		quit(1, "Failed to listen in create_notifier: %s", WindowsErrorStr(WSAGetLastError()));
+		quit(1, "Failed to listen"IN_FMT_FFL": %s",
+		     __FILE__, __func__, __LINE__, WindowsErrorStr(WSAGetLastError()));
 	inaddr.sin_family = AF_INET;
 	inaddr.sin_family = AF_INET;
 	inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
 	inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
 	if (connect(connecter, (struct sockaddr*)&inaddr, inaddr_sz) == SOCKET_ERROR)
 	if (connect(connecter, (struct sockaddr*)&inaddr, inaddr_sz) == SOCKET_ERROR)
-		quit(1, "Failed to connect in create_notifier: %s", WindowsErrorStr(WSAGetLastError()));
+		quit(1, "Failed to connect"IN_FMT_FFL": %s",
+		     __FILE__, __func__, __LINE__, WindowsErrorStr(WSAGetLastError()));
 	acceptor = accept(listener, NULL, NULL);
 	acceptor = accept(listener, NULL, NULL);
 	if (acceptor == INVALID_SOCKET)
 	if (acceptor == INVALID_SOCKET)
-		quit(1, "Failed to accept in create_notifier: %s", WindowsErrorStr(WSAGetLastError()));
+		quit(1, "Failed to accept"IN_FMT_FFL": %s",
+		     __FILE__, __func__, __LINE__, WindowsErrorStr(WSAGetLastError()));
 	closesocket(listener);
 	closesocket(listener);
 	pipefd[0] = connecter;
 	pipefd[0] = connecter;
 	pipefd[1] = acceptor;
 	pipefd[1] = acceptor;
 #else
 #else
 	if (pipe(pipefd))
 	if (pipe(pipefd))
-		quit(1, "Failed to create pipe in create_notifier");
+		quithere(1, "Failed to create pipe");
 #endif
 #endif
 }
 }