1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 4f08c3bdfSopenharmony_ci * 07/2001 Ported by Wayne Boyer 5f08c3bdfSopenharmony_ci * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com> 6f08c3bdfSopenharmony_ci */ 7f08c3bdfSopenharmony_ci 8f08c3bdfSopenharmony_ci/*\ 9f08c3bdfSopenharmony_ci * [Description] 10f08c3bdfSopenharmony_ci * 11f08c3bdfSopenharmony_ci * Verify that session IDs returned by getsid() (with argument pid=0) 12f08c3bdfSopenharmony_ci * are same in parent and child process. 13f08c3bdfSopenharmony_ci */ 14f08c3bdfSopenharmony_ci 15f08c3bdfSopenharmony_ci 16f08c3bdfSopenharmony_ci#include "tst_test.h" 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_cistatic pid_t p_sid; 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_cistatic void run(void) 21f08c3bdfSopenharmony_ci{ 22f08c3bdfSopenharmony_ci pid_t pid, c_sid; 23f08c3bdfSopenharmony_ci 24f08c3bdfSopenharmony_ci TEST(getsid(0)); 25f08c3bdfSopenharmony_ci if (TST_RET == -1) { 26f08c3bdfSopenharmony_ci tst_res(TFAIL | TTERRNO, "getsid(0) failed in parent"); 27f08c3bdfSopenharmony_ci return; 28f08c3bdfSopenharmony_ci } 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_ci p_sid = TST_RET; 31f08c3bdfSopenharmony_ci 32f08c3bdfSopenharmony_ci pid = SAFE_FORK(); 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_ci if (pid == 0) { 35f08c3bdfSopenharmony_ci TEST(getsid(0)); 36f08c3bdfSopenharmony_ci if (TST_RET == -1) { 37f08c3bdfSopenharmony_ci tst_res(TFAIL | TTERRNO, "getsid(0) failed in child"); 38f08c3bdfSopenharmony_ci return; 39f08c3bdfSopenharmony_ci } 40f08c3bdfSopenharmony_ci c_sid = TST_RET; 41f08c3bdfSopenharmony_ci TST_EXP_EQ_LI(p_sid, c_sid); 42f08c3bdfSopenharmony_ci } else { 43f08c3bdfSopenharmony_ci SAFE_WAITPID(pid, NULL, 0); 44f08c3bdfSopenharmony_ci } 45f08c3bdfSopenharmony_ci} 46f08c3bdfSopenharmony_ci 47f08c3bdfSopenharmony_cistatic struct tst_test test = { 48f08c3bdfSopenharmony_ci .test_all = run, 49f08c3bdfSopenharmony_ci .forks_child = 1 50f08c3bdfSopenharmony_ci}; 51