Exemplo n.º 1
0
void s_debug_debugf (unsigned short flags, char *file, int line, char *func, char *fmt, ...)
{
	int n;
	int s;
	char *p;
	va_list args;

#if !defined(CONFIG_DEBUG)
	if ((flags & DFAT) == 0) {
		return;
	}
#endif
	fprintf(stderr, "[0x%08X] ", s_thread_self());

	if (flags & DFAT) { fprintf(stderr, "FATAL : ");   }
	if (flags & DSYS) { fprintf(stderr, "SYSERR : ");  }
	if (flags & DSER) { fprintf(stderr, "SERVER :: "); }
	if (flags & DCLI) { fprintf(stderr, "CLIENT :: "); }
	
	s = 100;
	if ((p = s_malloc(sizeof(char) * s)) == NULL) {
		goto err;
	}

	while (1) {
		va_start(args, fmt);
		n = vsnprintf(p, s, fmt, args);
		va_end(args);
		if (n > -1 && n < s) {
			break;
		}
		if (n > -1) {
			s = n + 1;
		} else {
			s *= 2;
		}
		if ((p = s_realloc(p, s))  == NULL) {
			goto err;
		}
	}

	fprintf(stderr, p);
	s_free(p);

	if (flags & DSYS) {
		fprintf(stderr, " : %s", strerror(errno));
	}
	fprintf(stderr, " [%s (%s:%d)]\n", func, file, line);
	if (flags & DFAT) {
		goto err;
	}
	return;
err:	exit(1);
}
Exemplo n.º 2
0
void S_thread_init() {
  if (S_boot_time) {
    S_protect(&S_G.threadno);
    S_G.threadno = FIX(0);

#ifdef PTHREADS
   /* this is also reset in main.c after heap restoration */
    s_thread_mutex_init(&S_tc_mutex.pmutex);
    S_tc_mutex.owner = s_thread_self();
    S_tc_mutex.count = 0;
    s_thread_cond_init(&S_collect_cond);
    S_tc_mutex_depth = 0;
#endif /* PTHREADS */
  }
}