Inline Macro issue
Valdis.Kletnieks at vt.edu
Valdis.Kletnieks at vt.edu
Mon Jul 15 10:22:30 EDT 2013
On Mon, 15 Jul 2013 17:39:15 +0530, Mandeep Sandhu said:
> #define push_root() \
> recursive_mutex_lock(&context->id_lock); \
> context->uid = current->fsuid; \
> context->gid = current->fsgid; \
> do { \
> struct cred *new1 = prepare_creds(); \
> //make changes to any member of this structure \
> commit_creds(new1); \
> } while(0);
Actually, this has 3 problems:
1) You have a call to mutex_loc() that doesn't get unlocked. This Is Bad.
2) If you're using the 'do { foo } while (0)' trick, you want to
put the *whole thing* inside the { } (Hint - you can put local variable
definitions inside the curlies as well).
3) Leave the ; off the 'while (0)' in the macro definition, because:
> int main()
> {
> printf("in main\n");
> pushme
> return 0;
> }
Somebody will forget and put a ; after pushme - and in some contexts, the
additional ; will then cause issues.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130715/a39eed75/attachment-0001.bin
More information about the Kernelnewbies
mailing list