[LTP] [PATCH v2 1/3] syscalls/setgroups01: Convert to new API

Yang Xu (Fujitsu) xuyang2018.jy@fujitsu.com
Mon Aug 14 13:22:49 CEST 2023


Hi,Cyril
> Hi!
>> -#include <errno.h>
>> -#include <string.h>
>> -#include <signal.h>
>> -#include <sys/param.h>
>> -#include <unistd.h>
>> -#include <grp.h>
>> -
>> -#include "test.h"
>> -
>> -#include "compat_16.h"
>> +/*\
>> + * [Description]
>> + *
>> + * Check the basic functionality of the setgroups() system call.
>> + */
>>   
>> -void setup();
>> -void cleanup();
>> +#include "tst_test.h"
>> +#include "compat_tst_16.h"
>>   
>> -TCID_DEFINE(setgroups01);
>> -int TST_TOTAL = 1;
>> +static int len = NGROUPS, ngrps;
>>   
>> -int len = NGROUPS, ngrps = 0;
>> -GID_T list[NGROUPS];
>> +static GID_T list[NGROUPS];
>>   
>> -int main(int ac, char **av)
>> +static void verify_setgroups(void)
>>   {
>> -	int lc;
>> -
>> -    /***************************************************************
>> -     * parse standard options
>> -     ***************************************************************/
>> -	tst_parse_opts(ac, av, NULL, NULL);
>> -
>> -    /***************************************************************
>> -     * perform global setup for test
>> -     ***************************************************************/
>> -	setup();
>> -
>> -    /***************************************************************
>> -     * check looping state if -c option given
>> -     ***************************************************************/
>> -	for (lc = 0; TEST_LOOPING(lc); lc++) {
>> -
>> -		tst_count = 0;
>> -
>> -		/*
>> -		 * Call setgroups(2)
>> -		 */
>> -		TEST(SETGROUPS(cleanup, ngrps, list));
>> -
>> -		/* check return code */
>> -		if (TEST_RETURN == -1) {
>> -			tst_resm(TFAIL,
>> -				 "setgroups(%d, list) Failed, errno=%d : %s",
>> -				 len, TEST_ERRNO, strerror(TEST_ERRNO));
>> -		} else {
>> -			tst_resm(TPASS,
>> -				 "setgroups(%d, list) returned %ld",
>> -				 len, TEST_RETURN);
>> -		}
>> -
>> -	}
>> -
>> -	cleanup();
>> -	tst_exit();
>> +	TST_EXP_POSITIVE(SETGROUPS(ngrps, list),
>> +			 "setgroups(%d, list)", len);
>>   }
>>   
>> -/***************************************************************
>> - * setup() - performs all ONE TIME setup for this test.
>> - ***************************************************************/
>> -void setup(void)
>> +static void setup(void)
>>   {
>> -
>> -	tst_require_root();
>> -
>> -	tst_sig(NOFORK, DEF_HANDLER, cleanup);
>> -
>> -	TEST_PAUSE;
>> -
>> -	ngrps = GETGROUPS(cleanup, len, list);
>> -	if (ngrps == -1) {
>> -		tst_brkm(TBROK, cleanup,
>> -			 "getgroups(%d, list) Failure. errno=%d : %s",
>> -			 len, errno, strerror(errno));
>> +	if (GETGROUPS(len, list) < 0) {
>> +		tst_brk(TBROK,
>> +			"getgroups(%d, list) Failure. errno=%d : %s",
>> +			len, errno, strerror(errno));
>                               ^
> 			     use TERRNO instead of printing the values
> 			     by hand
>
>
>>   	}
> Also after this change the ngrps is no loger set and we pass 0 as the
> number of groups to the setgroups call.
>
>
> The rest of the changes looks good.
I agree with your suggestion and I will update it.


More information about the ltp mailing list