Skip to content

Commit 70e99a2

Browse files
mdouchametan-ucw
authored andcommitted
Move executable code out of tst_safe_macros.h
Signed-off-by: Martin Doucha <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]>
1 parent edbbccc commit 70e99a2

File tree

2 files changed

+49
-39
lines changed

2 files changed

+49
-39
lines changed

include/tst_safe_macros.h

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,8 @@ int safe_chroot(const char *file, const int lineno, const char *path);
4545
#define SAFE_DIRNAME(path) \
4646
safe_dirname(__FILE__, __LINE__, NULL, (path))
4747

48-
static inline int safe_dup(const char *file, const int lineno,
49-
int oldfd)
50-
{
51-
int rval;
52-
53-
rval = dup(oldfd);
54-
if (rval == -1) {
55-
tst_brk_(file, lineno, TBROK | TERRNO,
56-
"dup(%i) failed", oldfd);
57-
}
48+
int safe_dup(const char *file, const int lineno, int oldfd);
5849

59-
return rval;
60-
}
6150
#define SAFE_DUP(oldfd) \
6251
safe_dup(__FILE__, __LINE__, (oldfd))
6352

@@ -439,21 +428,8 @@ static inline int safe_setrlimit(const char *file, const int lineno,
439428
safe_setrlimit(__FILE__, __LINE__, (resource), (rlim))
440429

441430
typedef void (*sighandler_t)(int);
442-
static inline sighandler_t safe_signal(const char *file, const int lineno,
443-
int signum, sighandler_t handler)
444-
{
445-
sighandler_t rval;
446-
447-
rval = signal(signum, handler);
448-
449-
if (rval == SIG_ERR) {
450-
tst_brk_(file, lineno, TBROK | TERRNO,
451-
"signal(%d,%p) failed",
452-
signum, handler);
453-
}
454-
455-
return rval;
456-
}
431+
sighandler_t safe_signal(const char *file, const int lineno,
432+
int signum, sighandler_t handler);
457433

458434
#define SAFE_SIGNAL(signum, handler) \
459435
safe_signal(__FILE__, __LINE__, (signum), (handler))
@@ -601,19 +577,9 @@ int safe_unshare(const char *file, const int lineno, int flags);
601577
int safe_setns(const char *file, const int lineno, int fd, int nstype);
602578
#define SAFE_SETNS(fd, nstype) safe_setns(__FILE__, __LINE__, (fd), (nstype))
603579

604-
static inline void safe_cmd(const char *file, const int lineno, const char *const argv[],
605-
const char *stdout_path, const char *stderr_path)
606-
{
607-
int rval;
580+
void safe_cmd(const char *file, const int lineno, const char *const argv[],
581+
const char *stdout_path, const char *stderr_path);
608582

609-
switch ((rval = tst_cmd(argv, stdout_path, stderr_path,
610-
TST_CMD_PASS_RETVAL | TST_CMD_TCONF_ON_MISSING))) {
611-
case 0:
612-
break;
613-
default:
614-
tst_brk(TBROK, "%s:%d: %s failed (%d)", file, lineno, argv[0], rval);
615-
}
616-
}
617583
#define SAFE_CMD(argv, stdout_path, stderr_path) \
618584
safe_cmd(__FILE__, __LINE__, (argv), (stdout_path), (stderr_path))
619585
/*

lib/tst_safe_macros.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,47 @@ int safe_pipe2(const char *file, const int lineno, int fildes[2], int flags)
397397

398398
return ret;
399399
}
400+
401+
int safe_dup(const char *file, const int lineno, int oldfd)
402+
{
403+
int rval;
404+
405+
rval = dup(oldfd);
406+
if (rval == -1) {
407+
tst_brk_(file, lineno, TBROK | TERRNO,
408+
"dup(%i) failed", oldfd);
409+
}
410+
411+
return rval;
412+
}
413+
414+
sighandler_t safe_signal(const char *file, const int lineno,
415+
int signum, sighandler_t handler)
416+
{
417+
sighandler_t rval;
418+
419+
rval = signal(signum, handler);
420+
421+
if (rval == SIG_ERR) {
422+
tst_brk_(file, lineno, TBROK | TERRNO,
423+
"signal(%d,%p) failed",
424+
signum, handler);
425+
}
426+
427+
return rval;
428+
}
429+
430+
void safe_cmd(const char *file, const int lineno, const char *const argv[],
431+
const char *stdout_path, const char *stderr_path)
432+
{
433+
int rval;
434+
435+
switch ((rval = tst_cmd(argv, stdout_path, stderr_path,
436+
TST_CMD_PASS_RETVAL | TST_CMD_TCONF_ON_MISSING))) {
437+
case 0:
438+
break;
439+
default:
440+
tst_brk(TBROK, "%s:%d: %s failed (%d)", file, lineno, argv[0],
441+
rval);
442+
}
443+
}

0 commit comments

Comments
 (0)