2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-09-05 08:45:49 +00:00
Files
criu/test/zdtm/lib/msg.c
Laurent Dufour 5a34ae1891 test/zdtm: Fix test_msg massive stack usage
In test_msg() a buffer is allocated on stack to cook the outputed message.
This buffer's size was defined using the PAGE_SIZE constant defined in
zdtmtst.h file.

On some system like ppc64, the page size is large (64K), leading to massive
stack allocation, which may be too large in case of alternate stack like
the one used in the sigaltstack test.

This fix, defines a 2048 characters buffer for test_msg, and expose a
constant to allocate stack accordingly in the sigaltstack test.

Signed-off-by: Laurent Dufour <ldufour@linux.vnet.ibm.com>
Acked-by: Andrew Vagin <avagin@odin.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-07-13 14:52:25 +03:00

63 lines
1.2 KiB
C

#include <stdarg.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/user.h>
#include <string.h>
#include <linux/limits.h>
#include <sys/time.h>
#include <time.h>
#include "zdtmtst.h"
int test_log_init(const char *fname, const char *suffix)
{
char path[PATH_MAX];
int logfd;
snprintf(path, sizeof(path), "%s%s", fname, suffix);
logfd = open(path, O_WRONLY | O_EXCL | O_CREAT | O_APPEND, 0644);
if (logfd < 0) {
err("Can't open file %s", fname);
return -1;
}
dup2(logfd, STDERR_FILENO);
dup2(logfd, STDOUT_FILENO);
close(logfd);
setbuf(stdout, NULL);
setbuf(stderr, NULL);
return 0;
}
void test_msg(const char *format, ...)
{
va_list arg;
int off = 0;
char buf[TEST_MSG_BUFFER_SIZE];
int __errno = errno;
struct timeval tv;
struct tm *tm;
gettimeofday(&tv, NULL);
tm = localtime(&tv.tv_sec);
if (tm == NULL) {
err("localtime() failed");
} else {
off += strftime(buf, sizeof(buf), "%H:%M:%S", tm);
}
off += sprintf(buf + off, ".%.3ld: ", tv.tv_usec / 1000);
off += sprintf(buf + off, "%5d: ", getpid());
va_start(arg, format);
off += vsnprintf(buf + off, sizeof(buf) - off, format, arg);
va_end(arg);
fprintf(stderr, "%s", buf);
errno = __errno;
}