Skip to content

Commit

Permalink
Merge branch 'improvements' into issues/issue16
Browse files Browse the repository at this point in the history
* improvements:
  Makefile: Build and run tests by default
  mx_log: Fix typo "ALERT"
  mxq_log: Use mx_streq()
  README: update install section
  mx_log: Add mx_logva*() to use va lists when logging
  mx_log: Fix return value of mx_log_printf()
  test_mx_util: Fix renamed function
  README: Update mysql section
  • Loading branch information
mariux committed Oct 26, 2015
2 parents 86dc801 + e345231 commit c40fc6e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ manpages/%: manpages/%.xml
.PHONY: all
.PHONY: build

all: build
all: build test

.PHONY: devel
devel: CFLAGS += -DMXQ_DEVELOPMENT
Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,37 @@ https://github.com/mariux/mxq
## Installation
### Install using `GNU make`
```
make
make install
```

or to specify a prefix:
```
make PREFIX=...
make PREFIX=... [DESTDIR=...] install
```
### Install using `bee`
```
bee init $(bee download git://github.molgen.mpg.de/mariux64/mxq.git) --execute
bee update mxq
```

or to specify a prefix
```
bee init $(bee download git://github.molgen.mpg.de/mariux64/mxq.git) --prefix=... --execute
bee update mxq
```

## Initial setup
Definitions of the tables and triggers for the MySQL database can be found in
Definitions of the tables for the MySQL database can be found in
[mysql/create_tables.sql](https://github.molgen.mpg.de/mariux64/mxq/blob/master/mysql/create_tables.sql)
and
[mysql/create_trigger.sql](https://github.molgen.mpg.de/mariux64/mxq/blob/master/mysql/create_trigger.sql)
Be sure to create those once and check the same
[directory for alter_tables*.sql`](https://github.molgen.mpg.de/mariux64/mxq/blob/master/mysql/)
files when upgrading.

```
mysql [options] [database] <mysql/create_tables.sql
mysql [options] [database] <mysql/create_trigger.sql
```

## Development builds
The `devel` target in the Makefile will enable all devolopment features
Expand Down
21 changes: 15 additions & 6 deletions mx_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int mx_log_printf(const char *fmt, ...)
res = fflush(stderr);
mx_free_null(msg);

if (len2 != len)
if (len2 != len+1)
return -(errno=EIO);

if (!res)
Expand All @@ -109,7 +109,7 @@ static int log_log(int level, int loglevel, char *file, unsigned long line, cons
prefix = "EMERGENCY: ";
break;
case MX_LOG_ALERT:
prefix = "AKERT: ";
prefix = "ALERT: ";
break;
case MX_LOG_CRIT:
prefix = "CRITCAL ERROR: ";
Expand Down Expand Up @@ -137,12 +137,11 @@ static int log_log(int level, int loglevel, char *file, unsigned long line, cons
return mx_log_printf("%s%s", prefix, msg);
}

int mx_log_do(int level, char *file, unsigned long line, const char *func, const char *fmt, ...)
int mx_logva_do(int level, char *file, unsigned long line, const char *func, const char *fmt, va_list ap)
{
int loglevel;
int len;
char *msg = NULL;
va_list ap;
int res;
int preserved_errno = errno;

Expand All @@ -153,9 +152,7 @@ int mx_log_do(int level, char *file, unsigned long line, const char *func, const
return 0;
}

va_start(ap, fmt);
len = vasprintf(&msg, fmt, ap);
va_end(ap);

if (len == -1) {
errno = preserved_errno;
Expand All @@ -173,6 +170,18 @@ int mx_log_do(int level, char *file, unsigned long line, const char *func, const
return res;
}

int mx_log_do(int level, char *file, unsigned long line, const char *func, const char *fmt, ...)
{
va_list ap;
int res;

va_start(ap, fmt);
res = mx_logva_do(level, file, line, func, fmt, ap);
va_end(ap);

return res;
}

int mx_log_finish(void)
{
if (mx_log_log)
Expand Down
11 changes: 11 additions & 0 deletions mx_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define MX_LOG_DEBUG MX_LOG_SYSLOG_TO_MXLOG(LOG_DEBUG) /* debug-level messages */

#define mx_log(level, fmt, ...) mx_log_do((level), __FILE__, __LINE__, __func__, (fmt), ##__VA_ARGS__)
#define mx_logva(level, fmt, ap) mx_logva_do((level), __FILE__, __LINE__, __func__, (fmt), (ap))

#define mx_log_fatal(fmt, ...) mx_log(MX_LOG_EMERG, (fmt), ##__VA_ARGS__)
#define mx_log_emerg(fmt, ...) mx_log(MX_LOG_EMERG, (fmt), ##__VA_ARGS__)
Expand All @@ -33,6 +34,16 @@
#define mx_log_info(fmt, ...) mx_log(MX_LOG_INFO, (fmt), ##__VA_ARGS__)
#define mx_log_debug(fmt, ...) mx_log(MX_LOG_DEBUG, (fmt), ##__VA_ARGS__)

#define mx_logva_fatal(fmt, ap) mx_log(MX_LOG_EMERG, (fmt), (ap))
#define mx_logva_emerg(fmt, ap) mx_log(MX_LOG_EMERG, (fmt), (ap))
#define mx_logva_alert(fmt, ap) mx_log(MX_LOG_ALERT, (fmt), (ap))
#define mx_logva_crit(fmt, ap) mx_log(MX_LOG_CRIT, (fmt), (ap))
#define mx_logva_err(fmt, ap) mx_log(MX_LOG_ERR, (fmt), (ap))
#define mx_logva_warning(fmt, ap) mx_log(MX_LOG_WARNING, (fmt), (ap))
#define mx_logva_notice(fmt, ap) mx_log(MX_LOG_NOTICE, (fmt), (ap))
#define mx_logva_info(fmt, ap) mx_log(MX_LOG_INFO, (fmt), (ap))
#define mx_logva_debug(fmt, ap) mx_log(MX_LOG_DEBUG, (fmt), (ap))

int mx_log_log(int level, int loglevel, char *file, unsigned long line, const char *func, const char *msg) __attribute__ ((weak));
int mx_log_print(char *msg, size_t len) __attribute__ ((weak));

Expand Down
6 changes: 3 additions & 3 deletions mxq_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <unistd.h>

#include "mx_log.h"
#include "mx_util.h"

#ifndef mx_free_null
#include <stdlib.h>
#define mx_free_null(a) do { free((a)); (a) = NULL; } while(0)
Expand Down Expand Up @@ -42,7 +44,6 @@ static int timetag(char *buf, size_t size)

int mx_log_print(char *msg, size_t len)
{
int res;
char timebuf[1024];

static char *lastmsg = NULL;
Expand All @@ -61,8 +62,7 @@ int mx_log_print(char *msg, size_t len)
return -(errno=EINVAL);

if (lastmsg && lastlen == len) {
res = strcmp(msg, lastmsg);
if (res == 0) {
if (mx_streq(msg, lastmsg)) {
cnt++;
mx_free_null(msg);
return 2;
Expand Down
2 changes: 1 addition & 1 deletion test_mx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ static void test_mx_strscan(void)
assert(pps->ppid == getppid());
assert(pps->state == 'R');
assert(mx_streq(pps->comm, program_invocation_short_name) || mx_streq(pps->comm, "memcheck-amd64-"));
mx_proc_pid_stat_free(pps);
mx_proc_pid_stat_free_content(pps);
}

static void test_mx_strvec() {
Expand Down

0 comments on commit c40fc6e

Please sign in to comment.