tst_status.c 860 字节
Newer Older
M
m00302376 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
 */

#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#define TST_NO_DEFAULT_MAIN
#include "tst_test.h"

static char buf[32];

const char *exited(int status)
{
	snprintf(buf, sizeof(buf), "exited with %i", WEXITSTATUS(status));

	return buf;
}

const char *signaled(int status)
{
	snprintf(buf, sizeof(buf), "killed by %s", tst_strsig(status));

	return buf;
}

const char *invalid(int status)
{
	snprintf(buf, sizeof(buf), "invalid status 0x%x", status);

	return buf;
}

const char *tst_strstatus(int status)
{
	if (WIFEXITED(status))
		return exited(status);

	if (WIFSIGNALED(status))
		return signaled(status);

	if (WIFSTOPPED(status))
		return "is stopped";

	if (WIFCONTINUED(status))
		return "is resumed";

	return invalid(status);
}