File: systemf.c

package info (click to toggle)
libite 2.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,188 kB
  • sloc: sh: 4,665; ansic: 4,165; makefile: 141
file content (48 lines) | stat: -rw-r--r-- 878 bytes parent folder | download | duplicates (2)
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
#include <err.h>
#include "check.h"

/*
 * Depending on the system and default shell, `kill -QUIT $$` (below)
 * may leave a core file, so we need to clean that up here to prevent
 * the distcleancheck target from failing.
 */
static void cleanup(void)
{
	remove("core");
}

int main(void)
{
	struct { char *cmd; int rc; } list[] = {
		{ "/app/enoent",  127 },
		{ "false",          1 },
		{ "true",           0 },
		{ "kill -9 $$",    -1 },
		{ "kill -QUIT $$", -1 },
		{ "kill -INT $$",  -1 }
	};

	atexit(cleanup);

	for (size_t i = 0; i < NELEMS(list); i++) {
		int rc;

		rc = systemf("%s", list[i].cmd);
		if (rc != list[i].rc) {
			if (rc == -1)
				err(rc, "Failed %s", list[i].cmd);
			else
				errx(rc, "Failed %s, rc %d vs %d", list[i].cmd, rc, list[i].rc);
		}
	}

	return 0;
}

/**
 * Local Variables:
 *  indent-tabs-mode: t
 *  c-file-style: "linux"
 * End:
 */