public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 4/5] SAFE_MACROS: Add SAFE_PRCTL()
Date: Thu, 15 Dec 2016 18:17:37 +0800	[thread overview]
Message-ID: <58526DC1.7070208@cn.fujitsu.com> (raw)
In-Reply-To: <20161205144005.GG22344@rei.lan>

Hi!

On 12/05/2016 10:40 PM, Cyril Hrubis wrote:
> Hi!
>> +int safe_prctl(const char *file, const int lineno, int opt, ...);
>> +#define SAFE_PRCTL(opt, ...) \
>> +	safe_prctl(__FILE__, __LINE__, (opt), ##__VA_ARGS__)
>> +
>>  #endif /* SAFE_MACROS_H__ */
>> diff --git a/lib/safe_macros.c b/lib/safe_macros.c
>> index 1c89b8c..c8c5383 100644
>> --- a/lib/safe_macros.c
>> +++ b/lib/safe_macros.c
>> @@ -807,3 +807,23 @@ int safe_system(const char *file, const int lineno, const char *cmd)
>>  
>>  	return rval;
>>  }
>> +
>> +int safe_prctl(const char *file, const int lineno, int opt, ...)
>> +{
>> +	va_list ap;
>> +	int rval;
>> +	unsigned long arg;
>> +
>> +	va_start(ap, opt);
>> +	arg = va_arg(ap, unsigned long);
>> +	va_end(ap);
> 
> This is broken by design. The prctl() can have up to four long arguments
> but here we use only the first one unconditionally.
> 
> 
> I'm not sure how we can fix this easily. Either we can count number of
> arguments passed to the SAFE_PRCTL() by hacky preprocessor counting[1]
> and pass it as a first agument.
> 
> Or we can switch on the opt to figure out the number of expected arguments,
> which is ugly as well, but we can at least start small by adding only
> opts that we use.
> 
> [1]
> https://groups.google.com/forum/?_escaped_fragment_=topic/comp.std.c/d-6Mj5Lko_s#!topic/comp.std.c/d-6Mj5Lko_s
> 

Thanks for your review and kindly suggestion.

I see the prctl()'s arguments is variable in prctl.h, just like the fcntl() and ioctl(),
so I think maybe I can do it just as fcntl() and ioctl() did?

Best Regards,
Guangwen Feng

>> +	rval = prctl(opt, arg);
>> +	if (rval < 0) {
>> +		tst_brkm(TBROK | TERRNO, NULL,
>> +			 "%s:%d prctl(%i, %lu) failed",
>> +			 file, lineno, opt, arg);
>> +	}
>> +
>> +	return rval;
>> +}
>> -- 
>> 1.8.4.2
>>
>>
>>
>>
>> -- 
>> Mailing list info: https://lists.linux.it/listinfo/ltp
> 



  reply	other threads:[~2016-12-15 10:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-30 12:12 [LTP] [PATCH 1/5] Cleanup && Drop redundant space in safe macros Guangwen Feng
2016-11-30 12:12 ` [LTP] [PATCH 2/5] SAFE_MACROS: Add SAFE_SETPRIORITY() Guangwen Feng
2016-11-30 12:12 ` [LTP] [PATCH 3/5] SAFE_MACROS: Add SAFE_SYSTEM() Guangwen Feng
2016-12-05 14:33   ` Cyril Hrubis
2016-12-06 10:02     ` Guangwen Feng
2016-11-30 12:12 ` [LTP] [PATCH 4/5] SAFE_MACROS: Add SAFE_PRCTL() Guangwen Feng
2016-12-05 14:40   ` Cyril Hrubis
2016-12-15 10:17     ` Guangwen Feng [this message]
2016-12-15 10:43       ` Cyril Hrubis
2016-12-15 10:49         ` [LTP] [PATCH v2 1/4] Cleanup && Drop redundant space in safe macros Guangwen Feng
2016-12-15 10:49           ` [LTP] [PATCH v2 2/4] SAFE_MACROS: Add SAFE_SETPRIORITY() Guangwen Feng
2016-12-15 10:49           ` [LTP] [PATCH v2 3/4] SAFE_MACROS: Add SAFE_PRCTL() Guangwen Feng
2016-12-15 10:49           ` [LTP] [PATCH v2 4/4] syscalls/setpriority01: Use new user id to avoid messing system environment Guangwen Feng
2017-01-04 12:13             ` Cyril Hrubis
2016-11-30 12:12 ` [LTP] [PATCH 5/5] " Guangwen Feng
2016-12-05 14:45   ` Cyril Hrubis
2016-12-06 10:27     ` Guangwen Feng
2016-12-06 10:34       ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=58526DC1.7070208@cn.fujitsu.com \
    --to=fenggw-fnst@cn.fujitsu.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox