File: run.c

package info (click to toggle)
libfiu 1.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 768 kB
  • sloc: ansic: 2,633; python: 973; makefile: 599; sh: 309
file content (51 lines) | stat: -rw-r--r-- 1,290 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
49
50
51

#include <getopt.h> /* getopt() */
#include <stdio.h>  /* printf() */
#include <stdlib.h> /* atoi(), atol() */
#include <string.h> /* strtok(), memset(), strncpy() */
#include <unistd.h> /* execve() */

#include <fiu-control.h>
#include <fiu.h>

static void __attribute__((constructor)) fiu_run_init(void)
{
	char *fiu_fifo_env, *fiu_enable_env;

	fiu_init(0);

	fiu_fifo_env = getenv("FIU_CTRL_FIFO");
	if (fiu_fifo_env && *fiu_fifo_env != '\0') {
		if (fiu_rc_fifo(fiu_fifo_env) < 0) {
			perror("fiu_run_preload: Error opening RC fifo");
		}
	}

	fiu_enable_env = getenv("FIU_ENABLE");
	if (fiu_enable_env && *fiu_enable_env != '\0') {
		/* FIU_ENABLE can contain more than one command, separated by
		 * a newline, so we split them and call fiu_rc_string()
		 * accordingly. */
		char *tok, *state;
		char *env_copy;
		char *rc_error = "no error returned";

		env_copy = strdup(fiu_enable_env);
		if (env_copy == NULL) {
			perror("fiu_run_preload: Error in strdup()");
			return;
		}

		tok = strtok_r(env_copy, "\n", &state);
		while (tok) {
			if (fiu_rc_string(tok, &rc_error) != 0) {
				fprintf(stderr,
				        "fiu_run_preload: Error applying "
				        "FIU_ENABLE commands: %s\n",
				        rc_error);
				return;
			}
			tok = strtok_r(NULL, "\n", &state);
		}
	}
}