-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix test failure when running inside a new session via setsid() and start spliting its internal tests cases implementations into multiple files. Fixes: linux-test-project/kirk#28 Reviewed-by: Petr Vorel <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]> Signed-off-by: Andrea Cervesato <[email protected]>
- Loading branch information
Showing
2 changed files
with
105 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/* | ||
* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> | ||
*/ | ||
|
||
#ifndef PTEM_H | ||
#define PTEM_H | ||
|
||
#define _GNU_SOURCE | ||
|
||
#include "tst_test.h" | ||
|
||
#define MASTERCLONE "/dev/ptmx" | ||
|
||
static inline int open_master(void) | ||
{ | ||
int masterfd; | ||
|
||
if (access(MASTERCLONE, F_OK)) | ||
tst_brk(TCONF, "%s device doesn't exist", MASTERCLONE); | ||
|
||
tst_res(TINFO, "opening master %s", MASTERCLONE); | ||
|
||
masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR); | ||
|
||
if (grantpt(masterfd) == -1) | ||
tst_brk(TBROK | TERRNO, "grantpt() error"); | ||
|
||
if (unlockpt(masterfd) == -1) | ||
tst_brk(TBROK | TERRNO, "unlockpt() error"); | ||
|
||
return masterfd; | ||
} | ||
|
||
static inline int open_slave(const int masterfd) | ||
{ | ||
int slavefd; | ||
char *slavename; | ||
|
||
slavename = SAFE_PTSNAME(masterfd); | ||
|
||
tst_res(TINFO, "opening slave %s", slavename); | ||
|
||
#ifndef __BIONIC__ | ||
/* grantpt() is a no-op in bionic. */ | ||
struct stat st; | ||
|
||
SAFE_STAT(slavename, &st); | ||
|
||
uid_t uid = getuid(); | ||
|
||
if (st.st_uid != uid) { | ||
tst_brk(TBROK, "uid mismatch st.st_uid(%d) != getuid(%d)", | ||
st.st_uid, uid); | ||
} | ||
|
||
if (st.st_mode != (S_IFCHR | 0620)) { | ||
tst_brk(TBROK, "unexpected slave device permission: %o", | ||
st.st_mode); | ||
} | ||
#endif | ||
|
||
slavefd = SAFE_OPEN(slavename, O_RDWR); | ||
|
||
return slavefd; | ||
} | ||
|
||
#endif |
Oops, something went wrong.