summaryrefslogtreecommitdiff
path: root/app/cwm/util.c
diff options
context:
space:
mode:
authorOkan Demirmen <okan@cvs.openbsd.org>2018-02-02 13:40:56 +0000
committerOkan Demirmen <okan@cvs.openbsd.org>2018-02-02 13:40:56 +0000
commitd70eb640962ea1609b5267be3d0d75ff711007e1 (patch)
tree4fe596e887dd72918fa7304bf27e305e29515e93 /app/cwm/util.c
parent6c840e08917bb23cf9ac3bdb803a31b74f2610a3 (diff)
Add a simple debug logging mechanism.
Diffstat (limited to 'app/cwm/util.c')
-rw-r--r--app/cwm/util.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/app/cwm/util.c b/app/cwm/util.c
index 8d44c2664..6898a267a 100644
--- a/app/cwm/util.c
+++ b/app/cwm/util.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: util.c,v 1.20 2018/01/08 16:21:54 okan Exp $
+ * $OpenBSD: util.c,v 1.21 2018/02/02 13:40:55 okan Exp $
*/
#include <sys/types.h>
@@ -31,6 +31,8 @@
#include "calmwm.h"
+static void log_msg(const char *, va_list);
+
void
u_spawn(char *argstr)
{
@@ -104,3 +106,31 @@ u_argv(char * const *argv)
}
return(p);
}
+
+static void
+log_msg(const char *msg, va_list ap)
+{
+ char *fmt;
+
+ if (asprintf(&fmt, "%s\n", msg) == -1) {
+ vfprintf(stderr, msg, ap);
+ fprintf(stderr, "\n");
+ } else {
+ vfprintf(stderr, fmt, ap);
+ free(fmt);
+ }
+ fflush(stderr);
+}
+
+void
+log_debug(const char *func, const char *msg, ...)
+{
+ char *fmt;
+ va_list ap;
+
+ va_start(ap, msg);
+ if (asprintf(&fmt, "%s: %s", func, msg) == -1)
+ exit(1);
+ log_msg(fmt, ap);
+ va_end(ap);
+}