4 * This contains a simple multithreaded TCP server manager. It sits around
5 * waiting on the specified port for incoming HTTP connections. When a
6 * connection is established, it calls context_loop() from context_loop.c.
11 #include "webserver.h"
16 #include "modules_init.h"
18 int vsnprintf(char *buf, size_t max, const char *fmt, va_list argp);
21 int verbosity = 9; /* Logging level */
22 int msock; /* master listening socket */
23 int is_https = 0; /* Nonzero if I am an HTTPS service */
24 int follow_xff = 0; /* Follow X-Forwarded-For: header */
25 int home_specified = 0; /* did the user specify a homedir? */
26 int time_to_die = 0; /* Nonzero if server is shutting down */
27 extern void *context_loop(int);
28 extern void *housekeeping_loop(void);
29 extern pthread_mutex_t SessionListMutex;
30 extern pthread_key_t MyConKey;
33 char ctdl_key_dir[PATH_MAX]=SSL_DIR;
34 char file_crpt_file_key[PATH_MAX]="";
35 char file_crpt_file_csr[PATH_MAX]="";
36 char file_crpt_file_cer[PATH_MAX]="";
38 char socket_dir[PATH_MAX]; /* where to talk to our citadel server */
39 static const char editor_absolut_dir[PATH_MAX]=EDITORDIR; /* nailed to what configure gives us. */
40 static char static_dir[PATH_MAX]; /* calculated on startup */
41 static char static_local_dir[PATH_MAX]; /* calculated on startup */
42 static char static_icon_dir[PATH_MAX]; /* where should we find our mime icons? */
43 char *static_dirs[]={ /* needs same sort order as the web mapping */
44 (char*)static_dir, /* our templates on disk */
45 (char*)static_local_dir, /* user provided templates disk */
46 (char*)editor_absolut_dir, /* the editor on disk */
47 (char*)static_icon_dir /* our icons... */
51 * Subdirectories from which the client may request static content
53 * (If you add more, remember to increment 'ndirs' below)
55 char *static_content_dirs[] = {
56 "static", /* static templates */
57 "static.local", /* site local static templates */
58 "tiny_mce" /* rich text editor */
64 char *server_cookie = NULL; /* our Cookie connection to the client */
65 int http_port = PORT_NUM; /* Port to listen on */
66 char *ctdlhost = DEFAULT_HOST; /* our name */
67 char *ctdlport = DEFAULT_PORT; /* our Port */
68 int setup_wizard = 0; /* should we run the setup wizard? \todo */
69 char wizard_filename[PATH_MAX]; /* where's the setup wizard? */
70 int running_as_daemon = 0; /* should we deamonize on startup? */
74 * This is a generic function to set up a master socket for listening on
75 * a TCP port. The server shuts down if the bind fails.
77 * ip_addr IP address to bind
78 * port_number port number to bind
79 * queue_len number of incoming connections to allow in the queue
81 int ig_tcp_server(char *ip_addr, int port_number, int queue_len)
83 struct sockaddr_in sin;
86 memset(&sin, 0, sizeof(sin));
87 sin.sin_family = AF_INET;
88 if (ip_addr == NULL) {
89 sin.sin_addr.s_addr = INADDR_ANY;
91 sin.sin_addr.s_addr = inet_addr(ip_addr);
94 if (sin.sin_addr.s_addr == INADDR_NONE) {
95 sin.sin_addr.s_addr = INADDR_ANY;
98 if (port_number == 0) {
99 lprintf(1, "Cannot start: no port number specified.\n");
102 sin.sin_port = htons((u_short) port_number);
104 s = socket(PF_INET, SOCK_STREAM, (getprotobyname("tcp")->p_proto));
106 lprintf(1, "Can't create a socket: %s\n", strerror(errno));
109 /* Set some socket options that make sense. */
111 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
113 fcntl(s, F_SETFL, O_NONBLOCK); /* maide: this statement is incorrect
114 there should be a preceding F_GETFL
115 and a bitwise OR with the previous
118 if (bind(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
119 lprintf(1, "Can't bind: %s\n", strerror(errno));
122 if (listen(s, queue_len) < 0) {
123 lprintf(1, "Can't listen: %s\n", strerror(errno));
132 * Create a Unix domain socket and listen on it
133 * sockpath - file name of the unix domain socket
134 * queue_len - Number of incoming connections to allow in the queue
136 int ig_uds_server(char *sockpath, int queue_len)
138 struct sockaddr_un addr;
141 int actual_queue_len;
143 actual_queue_len = queue_len;
144 if (actual_queue_len < 5) actual_queue_len = 5;
146 i = unlink(sockpath);
147 if (i != 0) if (errno != ENOENT) {
148 lprintf(1, "webcit: can't unlink %s: %s\n",
149 sockpath, strerror(errno));
153 memset(&addr, 0, sizeof(addr));
154 addr.sun_family = AF_UNIX;
155 safestrncpy(addr.sun_path, sockpath, sizeof addr.sun_path);
157 s = socket(AF_UNIX, SOCK_STREAM, 0);
159 lprintf(1, "webcit: Can't create a socket: %s\n",
164 if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
165 lprintf(1, "webcit: Can't bind: %s\n",
170 if (listen(s, actual_queue_len) < 0) {
171 lprintf(1, "webcit: Can't listen: %s\n",
176 chmod(sockpath, 0777);
184 * Read data from the client socket.
186 * sock socket fd to read from
187 * buf buffer to read into
188 * bytes number of bytes to read
189 * timeout Number of seconds to wait before timing out
191 * Possible return values:
192 * 1 Requested number of bytes has been read.
193 * 0 Request timed out.
194 * -1 Connection is broken, or other error.
196 int client_read_to(int sock, char *buf, int bytes, int timeout)
206 return (client_read_ssl(buf, bytes, timeout));
211 while (len < bytes) {
217 retval = select((sock) + 1, &rfds, NULL, NULL, &tv);
218 if (FD_ISSET(sock, &rfds) == 0) {
222 rlen = read(sock, &buf[len], bytes - len);
225 lprintf(2, "client_read() failed: %s\n",
233 write(2, "\033[32m", 5);
234 write(2, buf, bytes);
235 write(2, "\033[30m", 5);
241 * \brief Begin buffering HTTP output so we can transmit it all in one write operation later.
243 void begin_burst(void)
245 if (WC->WBuf == NULL)
246 WC->WBuf = NewStrBufPlain(NULL, 32768);
251 * \brief Finish buffering HTTP output. [Compress using zlib and] output with a Content-Length: header.
255 struct wcsession *WCC = WC;
256 const char *ptr, *eptr;
263 /* Perform gzip compression, if enabled and supported by client */
264 if ((WCC->gzip_ok) && CompressBuffer(WCC->WBuf))
266 hprintf("Content-encoding: gzip\r\n");
268 #endif /* HAVE_ZLIB */
270 hprintf("Content-length: %d\r\n\r\n", StrLength(WCC->WBuf));
272 ptr = ChrPtr(WCC->HBuf);
273 count = StrLength(WCC->HBuf);
278 client_write_ssl(WCC->HBuf);
279 client_write_ssl(WCC->WBuf);
287 write(2, "\033[34m", 5);
288 write(2, ptr, StrLength(WCC->WBuf));
289 write(2, "\033[30m", 5);
291 fdflags = fcntl(WC->http_sock, F_GETFL);
294 if ((fdflags & O_NONBLOCK) == O_NONBLOCK) {
296 FD_SET(WCC->http_sock, &wset);
297 if (select(WCC->http_sock + 1, NULL, &wset, NULL, NULL) == -1) {
298 lprintf(2, "client_write: Socket select failed (%s)\n", strerror(errno));
303 if ((res = write(WCC->http_sock,
306 lprintf(2, "client_write: Socket write failed (%s)\n", strerror(errno));
313 ptr = ChrPtr(WCC->WBuf);
314 count = StrLength(WCC->WBuf);
319 write(2, "\033[34m", 5);
320 write(2, ptr, StrLength(WCC->WBuf));
321 write(2, "\033[30m", 5);
325 if ((fdflags & O_NONBLOCK) == O_NONBLOCK) {
327 FD_SET(WCC->http_sock, &wset);
328 if (select(WCC->http_sock + 1, NULL, &wset, NULL, NULL) == -1) {
329 lprintf(2, "client_write: Socket select failed (%s)\n", strerror(errno));
334 if ((res = write(WCC->http_sock,
337 lprintf(2, "client_write: Socket write failed (%s)\n", strerror(errno));
344 return StrLength(WCC->WBuf);
350 * \brief Read data from the client socket with default timeout.
351 * (This is implemented in terms of client_read_to() and could be
352 * justifiably moved out of sysdep.c)
353 * \param sock the socket fd to read from
354 * \param buf the buffer to write to
355 * \param bytes Number of bytes to read
357 int client_read(int sock, char *buf, int bytes)
359 return (client_read_to(sock, buf, bytes, SLEEPING));
364 * \brief Get a LF-terminated line of text from the client.
365 * (This is implemented in terms of client_read() and could be
366 * justifiably moved out of sysdep.c)
367 * \param sock socket fd to get client line from
368 * \param buf buffer to write read data to
369 * \param bufsiz how many bytes to read
370 * \return number of bytes read???
372 int client_getln(int sock, char *buf, int bufsiz)
376 /* Read one character at a time.*/
378 retval = client_read(sock, &buf[i], 1);
379 if (retval != 1 || buf[i] == '\n' || i == (bufsiz-1))
381 if ( (!isspace(buf[i])) && (!isprint(buf[i])) ) {
382 /* Non printable character recieved from client */
387 /* If we got a long line, discard characters until the newline. */
389 while (buf[i] != '\n' && retval == 1)
390 retval = client_read(sock, &buf[i], 1);
393 * Strip any trailing non-printable characters.
396 while ((i > 0) && (!isprint(buf[i - 1]))) {
403 * \brief Shut us down the regular way.
404 * \param signum the signal we want to forward
407 void graceful_shutdown_watcher(int signum) {
408 lprintf (1, "bye; shutting down watcher.");
409 kill(current_child, signum);
410 if (signum != SIGHUP)
415 * \brief shut us down the regular way.
416 * \param signum the signal we want to forward
419 void graceful_shutdown(int signum) {
420 // kill(current_child, signum);
425 lprintf (1, "bye going down gracefull.[%d][%s]\n", signum, wd);
437 * \brief Start running as a daemon.
439 * param do_close_stdio Only close stdio if set.
443 * Start running as a daemon.
445 void start_daemon(char *pid_file)
454 /* Close stdin/stdout/stderr and replace them with /dev/null.
455 * We don't just call close() because we don't want these fd's
456 * to be reused for other files.
460 signal(SIGHUP, SIG_IGN);
461 signal(SIGINT, SIG_IGN);
462 signal(SIGQUIT, SIG_IGN);
471 freopen("/dev/null", "r", stdin);
472 freopen("/dev/null", "w", stdout);
473 freopen("/dev/null", "w", stderr);
474 signal(SIGTERM, graceful_shutdown_watcher);
475 signal(SIGHUP, graceful_shutdown_watcher);
478 current_child = fork();
481 if (current_child < 0) {
483 ShutDownLibCitadel ();
487 else if (current_child == 0) { // child process
488 // signal(SIGTERM, graceful_shutdown);
489 signal(SIGHUP, graceful_shutdown);
491 return; /* continue starting webcit. */
494 else { // watcher process
495 // signal(SIGTERM, SIG_IGN);
496 // signal(SIGHUP, SIG_IGN);
498 fp = fopen(pid_file, "w");
500 fprintf(fp, "%d\n", getpid());
504 waitpid(current_child, &status, 0);
509 /* Did the main process exit with an actual exit code? */
510 if (WIFEXITED(status)) {
512 /* Exit code 0 means the watcher should exit */
513 if (WEXITSTATUS(status) == 0) {
517 /* Exit code 101-109 means the watcher should exit */
518 else if ( (WEXITSTATUS(status) >= 101) && (WEXITSTATUS(status) <= 109) ) {
522 /* Any other exit code means we should restart. */
528 /* Any other type of termination (signals, etc.) should also restart. */
533 } while (do_restart);
538 ShutDownLibCitadel ();
539 exit(WEXITSTATUS(status));
543 * \brief Spawn an additional worker thread into the pool.
545 void spawn_another_worker_thread()
547 pthread_t SessThread; /*< Thread descriptor */
548 pthread_attr_t attr; /*< Thread attributes */
551 lprintf(3, "Creating a new thread\n");
553 /* set attributes for the new thread */
554 pthread_attr_init(&attr);
555 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
558 * Our per-thread stacks need to be bigger than the default size, otherwise
559 * the MIME parser crashes on FreeBSD, and the IMAP service crashes on
562 if ((ret = pthread_attr_setstacksize(&attr, 1024 * 1024))) {
563 lprintf(1, "pthread_attr_setstacksize: %s\n",
565 pthread_attr_destroy(&attr);
568 /* now create the thread */
569 if (pthread_create(&SessThread, &attr,
570 (void *(*)(void *)) worker_entry, NULL)
572 lprintf(1, "Can't create thread: %s\n", strerror(errno));
575 /* free up the attributes */
576 pthread_attr_destroy(&attr);
579 //#define DBG_PRINNT_HOOKS_AT_START
580 #ifdef DBG_PRINNT_HOOKS_AT_START
581 const char foobuf[32];
582 const char *nix(void *vptr) {snprintf(foobuf, 32, "%0x", (long) vptr); return foobuf;}
584 void InitTemplateCache(void);
586 extern void LoadZoneFiles(void);
588 * \brief Here's where it all begins.
589 * \param argc number of commandline args
590 * \param argv the commandline arguments
592 int main(int argc, char **argv)
594 pthread_t SessThread; /*< Thread descriptor */
595 pthread_attr_t attr; /*< Thread attributes */
596 int a, i; /*< General-purpose variables */
597 char tracefile[PATH_MAX];
598 char ip_addr[256]="0.0.0.0";
599 char dirbuffer[PATH_MAX]="";
602 int home_specified=0;
603 char relhome[PATH_MAX]="";
604 char webcitdir[PATH_MAX] = DATADIR;
605 char *pidfile = NULL;
611 #endif /* ENABLE_NLS */
612 char uds_listen_path[PATH_MAX]; /*< listen on a unix domain socket? */
614 HandlerHash = NewHash(1, NULL);
615 PreferenceHooks = NewHash(1, NULL);
616 WirelessTemplateCache = NewHash(1, NULL);
617 WirelessLocalTemplateCache = NewHash(1, NULL);
618 LocalTemplateCache = NewHash(1, NULL);
619 TemplateCache = NewHash(1, NULL);
620 GlobalNS = NewHash(1, NULL);
621 Iterators = NewHash(1, NULL);
625 #ifdef DBG_PRINNT_HOOKS_AT_START
626 dbg_PrintHash(HandlerHash, nix, NULL);
629 /* Ensure that we are linked to the correct version of libcitadel */
630 if (libcitadel_version_number() < LIBCITADEL_VERSION_NUMBER) {
631 fprintf(stderr, " You are running libcitadel version %d.%02d\n",
632 (libcitadel_version_number() / 100), (libcitadel_version_number() % 100));
633 fprintf(stderr, "WebCit was compiled against version %d.%02d\n",
634 (LIBCITADEL_VERSION_NUMBER / 100), (LIBCITADEL_VERSION_NUMBER % 100));
638 strcpy(uds_listen_path, "");
640 /* Parse command line */
642 while ((a = getopt(argc, argv, "h:i:p:t:x:dD:cfs")) != EOF)
644 while ((a = getopt(argc, argv, "h:i:p:t:x:dD:cf")) != EOF)
648 hdir = strdup(optarg);
650 if (!relh) safestrncpy(webcitdir, hdir,
653 safestrncpy(relhome, relhome,
655 /* free(hdir); TODO: SHOULD WE DO THIS? */
660 running_as_daemon = 1;
663 pidfile = strdup(optarg);
664 running_as_daemon = 1;
667 safestrncpy(ip_addr, optarg, sizeof ip_addr);
670 http_port = atoi(optarg);
671 if (http_port == 0) {
672 safestrncpy(uds_listen_path, optarg, sizeof uds_listen_path);
676 safestrncpy(tracefile, optarg, sizeof tracefile);
677 freopen(tracefile, "w", stdout);
678 freopen(tracefile, "w", stderr);
679 freopen(tracefile, "r", stdin);
682 verbosity = atoi(optarg);
688 server_cookie = malloc(256);
689 if (server_cookie != NULL) {
690 safestrncpy(server_cookie,
691 "Set-cookie: wcserver=",
694 (&server_cookie[strlen(server_cookie)],
696 lprintf(2, "gethostname: %s\n",
706 fprintf(stderr, "usage: webcit "
707 "[-i ip_addr] [-p http_port] "
708 "[-t tracefile] [-c] [-f] "
713 "[remotehost [remoteport]]\n");
718 ctdlhost = argv[optind];
720 ctdlport = argv[optind];
723 /* daemonize, if we were asked to */
724 if (running_as_daemon) {
725 start_daemon(pidfile);
728 /// signal(SIGTERM, graceful_shutdown);
729 signal(SIGHUP, graceful_shutdown);
732 /* Tell 'em who's in da house */
733 lprintf(1, PACKAGE_STRING "\n");
734 lprintf(1, "Copyright (C) 1996-2008 by the Citadel development team.\n"
735 "This software is distributed under the terms of the "
736 "GNU General Public License.\n\n"
740 /* initialize the International Bright Young Thing */
742 initialize_locales();
744 locale = setlocale(LC_ALL, "");
746 mo = malloc(strlen(webcitdir) + 20);
747 lprintf(9, "Message catalog directory: %s\n", bindtextdomain("webcit", LOCALEDIR"/locale"));
749 lprintf(9, "Text domain: %s\n", textdomain("webcit"));
750 lprintf(9, "Text domain Charset: %s\n", bind_textdomain_codeset("webcit","UTF8"));
755 /* calculate all our path on a central place */
756 /* where to keep our config */
758 #define COMPUTE_DIRECTORY(SUBDIR) memcpy(dirbuffer,SUBDIR, sizeof dirbuffer);\
759 snprintf(SUBDIR,sizeof SUBDIR, "%s%s%s%s%s%s%s", \
760 (home&!relh)?webcitdir:basedir, \
761 ((basedir!=webcitdir)&(home&!relh))?basedir:"/", \
762 ((basedir!=webcitdir)&(home&!relh))?"/":"", \
764 (relhome[0]!='\0')?"/":"",\
766 (dirbuffer[0]!='\0')?"/":"");
768 COMPUTE_DIRECTORY(socket_dir);
769 basedir=WWWDIR "/static";
770 COMPUTE_DIRECTORY(static_dir);
771 basedir=WWWDIR "/static/icons";
772 COMPUTE_DIRECTORY(static_icon_dir);
773 basedir=WWWDIR "/static.local";
774 COMPUTE_DIRECTORY(static_local_dir);
776 snprintf(file_crpt_file_key,
777 sizeof file_crpt_file_key,
780 snprintf(file_crpt_file_csr,
781 sizeof file_crpt_file_csr,
784 snprintf(file_crpt_file_cer,
785 sizeof file_crpt_file_cer,
789 /* we should go somewhere we can leave our coredump, if enabled... */
790 lprintf(9, "Changing directory to %s\n", socket_dir);
791 if (chdir(webcitdir) != 0) {
794 LoadIconDir(static_icon_dir);
797 initialise_modules();
798 initialize_viewdefs();
802 * Set up a place to put thread-specific data.
803 * We only need a single pointer per thread - it points to the
804 * wcsession struct to which the thread is currently bound.
806 if (pthread_key_create(&MyConKey, NULL) != 0) {
807 lprintf(1, "Can't create TSD key: %s\n", strerror(errno));
809 InitialiseSemaphores ();
812 * Set up a place to put thread-specific SSL data.
813 * We don't stick this in the wcsession struct because SSL starts
814 * up before the session is bound, and it gets torn down between
818 if (pthread_key_create(&ThreadSSL, NULL) != 0) {
819 lprintf(1, "Can't create TSD key: %s\n", strerror(errno));
824 * Bind the server to our favorite port.
825 * There is no need to check for errors, because ig_tcp_server()
826 * exits if it doesn't succeed.
829 if (!IsEmptyStr(uds_listen_path)) {
830 lprintf(2, "Attempting to create listener socket at %s...\n", uds_listen_path);
831 msock = ig_uds_server(uds_listen_path, LISTEN_QUEUE_LENGTH);
834 lprintf(2, "Attempting to bind to port %d...\n", http_port);
835 msock = ig_tcp_server(ip_addr, http_port, LISTEN_QUEUE_LENGTH);
838 lprintf(2, "Listening on socket %d\n", msock);
839 signal(SIGPIPE, SIG_IGN);
841 pthread_mutex_init(&SessionListMutex, NULL);
844 * Start up the housekeeping thread
846 pthread_attr_init(&attr);
847 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
848 pthread_create(&SessThread, &attr,
849 (void *(*)(void *)) housekeeping_loop, NULL);
853 * If this is an HTTPS server, fire up SSL
861 /* Start a few initial worker threads */
862 for (i = 0; i < (MIN_WORKER_THREADS); ++i) {
863 spawn_another_worker_thread();
866 /* now the original thread becomes another worker */
868 ShutDownLibCitadel ();
869 DeleteHash(&HandlerHash);
870 DeleteHash(&PreferenceHooks);
876 * Entry point for worker threads
878 void worker_entry(void)
882 int fail_this_transaction = 0;
885 fd_set readset, tempset;
890 FD_SET(msock, &readset);
893 /* Only one thread can accept at a time */
894 fail_this_transaction = 0;
898 ret = -1; /* just one at once should select... */
899 begin_critical_section(S_SELECT);
902 if (msock > 0) FD_SET(msock, &tempset);
905 if (msock > 0) ret = select(msock+1, &tempset, NULL, NULL, &tv);
906 end_critical_section(S_SELECT);
907 if ((ret < 0) && (errno != EINTR) && (errno != EAGAIN))
908 {// EINTR and EAGAIN are thrown but not of interest.
909 lprintf(2, "accept() failed:%d %s\n",
910 errno, strerror(errno));
912 else if ((ret > 0) && (msock > 0) && FD_ISSET(msock, &tempset))
913 {// Successfully selected, and still not shutting down? Accept!
914 ssock = accept(msock, NULL, 0);
917 } while ((msock > 0) && (ssock < 0) && (time_to_die == 0));
919 if ((msock == -1)||(time_to_die))
920 {// ok, we're going down.
923 /* the first to come here will have to do the cleanup.
924 * make shure its realy just one.
926 begin_critical_section(S_SHUTDOWN);
932 end_critical_section(S_SHUTDOWN);
934 {// we're the one to cleanup the mess.
935 lprintf(2, "I'm master shutdown: tagging sessions to be killed.\n");
937 lprintf(2, "master shutdown: waiting for others\n");
938 sleeeeeeeeeep(1); // wait so some others might finish...
939 lprintf(2, "master shutdown: cleaning up sessions\n");
941 lprintf(2, "master shutdown: cleaning up libical\n");
942 free_zone_directory ();
943 icaltimezone_release_zone_tab ();
944 icalmemory_free_ring ();
945 ShutDownLibCitadel ();
946 DeleteHash(&HandlerHash);
947 DeleteHash(&PreferenceHooks);
948 DeleteHash(&GlobalNS);
949 DeleteHash(&WirelessTemplateCache);
950 DeleteHash(&WirelessLocalTemplateCache);
951 DeleteHash(&TemplateCache);
952 DeleteHash(&LocalTemplateCache);
953 DeleteHash(&Iterators);
955 void ShutdownLocale(void);
957 lprintf(2, "master shutdown exiting!.\n");
962 if (ssock < 0 ) continue;
965 if (ssock > 0) close (ssock);
966 lprintf(2, "inbetween.");
968 } else { // Got it? do some real work!
969 /* Set the SO_REUSEADDR socket option */
971 setsockopt(ssock, SOL_SOCKET, SO_REUSEADDR,
974 /* If we are an HTTPS server, go crypto now. */
977 if (starttls(ssock) != 0) {
978 fail_this_transaction = 1;
984 if (fail_this_transaction == 0) {
986 /* Perform an HTTP transaction... */
989 /* Shut down SSL/TLS if required... */
996 /* ...and close the socket. */
997 lingering_close(ssock);
1002 } while (!time_to_die);
1004 lprintf (1, "bye\n");
1009 * \brief print log messages
1010 * logs to stderr if loglevel is lower than the verbosity set at startup
1011 * \param loglevel level of the message
1012 * \param format the printf like format string
1013 * \param ... the strings to put into format
1015 int lprintf(int loglevel, const char *format, ...)
1019 if (loglevel <= verbosity) {
1020 va_start(ap, format);
1021 vfprintf(stderr, format, ap);
1030 * \brief print the actual stack frame.
1032 void wc_backtrace(void)
1034 #ifdef HAVE_BACKTRACE
1035 void *stack_frames[50];
1040 size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
1041 strings = backtrace_symbols(stack_frames, size);
1042 for (i = 0; i < size; i++) {
1043 if (strings != NULL)
1044 lprintf(1, "%s\n", strings[i]);
1046 lprintf(1, "%p\n", stack_frames[i]);