<div dir="ltr">This program is compiling fine on the same compiler.<div><br></div><div>Output:</div><div>in main..</div><div>Hi<br><br></div><div>I think than Mandeep's code should also compile<br>#define push_root()\{<br>
recursive_mutex_lock(&context->id_lock);\<br>context->uid = current_fsuid();\<br>context->gid = current_fsgid();\ <br>do{\<br> struct cred *new2 = prepare_creds();\<br> commit_creds(new2);\<br>
}while(0) <br></div><div><br></div><div>Regards,</div><div>Saket Sinha</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 15, 2013 at 5:45 PM, Murali Annamneni <span dir="ltr"><<a href="mailto:a.murali@hcl.com" target="_blank">a.murali@hcl.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Saket Sinha<br>
<br>
Just try as below example -<br>
<br>
#include <stdio.h><br>
<br>
#define pushme \<br>
do \<br>
{ \<br>
printf("Hi...\n"); \<br>
} while(0);<br>
<br>
int main()<br>
{<br>
printf("in main\n");<br>
pushme<br>
return 0;<br>
}<br>
<br>
<br>
<br>
Thanks & Regards<br>
Murali Annamneni<br>
<br>
<br>
-----Original Message-----<br>
From: <a href="mailto:kernelnewbies-bounces@kernelnewbies.org">kernelnewbies-bounces@kernelnewbies.org</a> [mailto:<a href="mailto:kernelnewbies-bounces@kernelnewbies.org">kernelnewbies-bounces@kernelnewbies.org</a>] On Behalf Of <a href="mailto:kernelnewbies-request@kernelnewbies.org">kernelnewbies-request@kernelnewbies.org</a><br>
Sent: Monday, July 15, 2013 5:03 PM<br>
To: <a href="mailto:kernelnewbies@kernelnewbies.org">kernelnewbies@kernelnewbies.org</a><br>
Subject: Kernelnewbies Digest, Vol 32, Issue 20<br>
<br>
Send Kernelnewbies mailing list submissions to<br>
<a href="mailto:kernelnewbies@kernelnewbies.org">kernelnewbies@kernelnewbies.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
or, via email, send a message with subject or body 'help' to<br>
<a href="mailto:kernelnewbies-request@kernelnewbies.org">kernelnewbies-request@kernelnewbies.org</a><br>
<br>
You can reach the person managing the list at<br>
<a href="mailto:kernelnewbies-owner@kernelnewbies.org">kernelnewbies-owner@kernelnewbies.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific than "Re: Contents of Kernelnewbies digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
1. Re: Inline Macro issue (Saket Sinha)<br>
2. Re: Inline Macro issue (Mandeep Sandhu)<br>
3. Re: Inline Macro issue (anish singh)<br>
4. Re: Inline Macro issue (Saket Sinha)<br>
5. Re: Inline Macro issue (Saket Sinha)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Mon, 15 Jul 2013 15:54:55 +0530<br>
From: Saket Sinha <<a href="mailto:saket.sinha89@gmail.com">saket.sinha89@gmail.com</a>><br>
Subject: Re: Inline Macro issue<br>
To: Srinivas Ganji <<a href="mailto:srinivasganji.kernel@gmail.com">srinivasganji.kernel@gmail.com</a>><br>
Cc: <a href="mailto:kernelnewbies@kernelnewbies.org">kernelnewbies@kernelnewbies.org</a><br>
Message-ID:<br>
<<a href="mailto:CAK25hWO3zbFu8MgXtPSpGq_0uj%2Bqv07hGJjp018heGTDABN7nA@mail.gmail.com">CAK25hWO3zbFu8MgXtPSpGq_0uj+qv07hGJjp018heGTDABN7nA@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
Dear Srinivas,<br>
<br>
If you are suggesting something like<br>
<br>
#define push_root \ *{*<br>
new1 =prepare_creds(); \<br>
new1->uid = 0; \<br>
new1->gid = 0; \<br>
commit_creds(new1)<br>
*}*<br>
*<br>
*<br>
Sorry I am still getting a compiler error.<br>
<br>
Regards,<br>
Saket Sinha<br>
*<br>
*<br>
<br>
<br>
On Mon, Jul 15, 2013 at 2:25 PM, Srinivas Ganji < <a href="mailto:srinivasganji.kernel@gmail.com">srinivasganji.kernel@gmail.com</a>> wrote:<br>
<br>
> A small suggestion, use begin { and end } braces for declaring your macro.<br>
> May be I am wrong, but you can try this. Then, the declaration become<br>
> local to that block.<br>
><br>
> Regards,<br>
> Srinivas<br>
><br>
><br>
> On Mon, Jul 15, 2013 at 1:03 AM, Saket Sinha <<a href="mailto:saket.sinha89@gmail.com">saket.sinha89@gmail.com</a>>wrote:<br>
><br>
>> "current" in kernel is a global macro, that always point to the<br>
>> "struct task_struct * " of the currently executing task (for details<br>
>> on task_struct, ref Robert Love, pg 24-27).<br>
>><br>
>> Now I have a macro called push root which has the following purpose-<br>
>> "to push root user and group to current context so to set current<br>
>> uid and gid to 0."<br>
>><br>
>> Now in kernel 3.8.3, I would do something like<br>
>><br>
>> struct cred *new1;<br>
>> new1 =prepare_creds();<br>
>> new1->uid = 0;<br>
>> new1->gid = 0;<br>
>> commit_creds(new1);<br>
>><br>
>> So macro definition of push root, according to what I have proposed<br>
>> above, should be<br>
>> #define push_root \<br>
>> new1 =prepare_creds(); \<br>
>> new1->uid = 0; \<br>
>> new1->gid = 0; \<br>
>> commit_creds(new1)<br>
>><br>
>> But I am getting errors like multiple declaration of new1 etc.<br>
>><br>
>> Even if I declare prepare_creds outside macro definition like<br>
>><br>
>> new1 =prepare_creds();<br>
>> #define push_root \<br>
>> new1->uid = 0; \<br>
>> new1->gid = 0; \<br>
>> commit_creds(new1)<br>
>><br>
>> I think I am facing the issue that the macros are inlined during<br>
>> compilation, so when the compiler wants to replace them, it raises issues.<br>
>><br>
>> I could think of two ways to solve this issue-<br>
>><br>
>> 1. define a new macro like #define prep_root() which defines the var<br>
>> once for all, and that I have to put it at the begin of each function<br>
>> needing push_root. This is not a very good method.<br>
>><br>
>> 2. I should still try to go with inlined functions but how ?<br>
>><br>
>> Can someone suggest anything<br>
>><br>
>> Regards,<br>
>> Saket Sinha<br>
>><br>
>> _______________________________________________<br>
>> Kernelnewbies mailing list<br>
>> <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
>> <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
>><br>
>><br>
><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <a href="http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130715/d360136c/attachment-0001.html" target="_blank">http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130715/d360136c/attachment-0001.html</a><br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Mon, 15 Jul 2013 16:24:18 +0530<br>
From: Mandeep Sandhu <<a href="mailto:mandeepsandhu.chd@gmail.com">mandeepsandhu.chd@gmail.com</a>><br>
Subject: Re: Inline Macro issue<br>
To: Saket Sinha <<a href="mailto:saket.sinha89@gmail.com">saket.sinha89@gmail.com</a>><br>
Cc: Srinivas Ganji <<a href="mailto:srinivasganji.kernel@gmail.com">srinivasganji.kernel@gmail.com</a>>, kernelnewbies<br>
<<a href="mailto:kernelnewbies@kernelnewbies.org">kernelnewbies@kernelnewbies.org</a>><br>
Message-ID:<br>
<CAC+QLdQbBuNEW7EKZk4vUTNuu2LGSZ6gJhf4bde3gC+=<a href="mailto:D9FP8w@mail.gmail.com">D9FP8w@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
On Mon, Jul 15, 2013 at 3:54 PM, Saket Sinha <<a href="mailto:saket.sinha89@gmail.com">saket.sinha89@gmail.com</a>>wrote:<br>
<br>
> Dear Srinivas,<br>
><br>
> If you are suggesting something like<br>
><br>
> #define push_root \ *{*<br>
> new1 =prepare_creds(); \<br>
> new1->uid = 0; \<br>
> new1->gid = 0; \<br>
> commit_creds(new1)<br>
> *}*<br>
> *<br>
> *<br>
> Sorry I am still getting a compiler error.<br>
><br>
<br>
What errors is the compiler giving?<br>
<br>
Last time you mentioned that it's saying new1 has multiple def's.<br>
<br>
Is it possible your macro has a declaration of new1 in it. So if you use the macro in the same scope, you'll get re-def errors.<br>
<br>
You can also try and look at the intermediate file for your source code, i.e after the pre-processing is done (*.i files).<br>
<br>
I don't remember the exact gcc option. Try --save-temps and look at the <source file name>.i file.<br>
<br>
HTH,<br>
-mandeep<br>
<br>
<br>
<br>
><br>
> Regards,<br>
> Saket Sinha<br>
> *<br>
> *<br>
><br>
><br>
> On Mon, Jul 15, 2013 at 2:25 PM, Srinivas Ganji <<br>
> <a href="mailto:srinivasganji.kernel@gmail.com">srinivasganji.kernel@gmail.com</a>> wrote:<br>
><br>
>> A small suggestion, use begin { and end } braces for declaring your<br>
>> macro. May be I am wrong, but you can try this. Then, the declaration<br>
>> become local to that block.<br>
>><br>
>> Regards,<br>
>> Srinivas<br>
>><br>
>><br>
>> On Mon, Jul 15, 2013 at 1:03 AM, Saket Sinha <<a href="mailto:saket.sinha89@gmail.com">saket.sinha89@gmail.com</a>>wrote:<br>
>><br>
>>> "current" in kernel is a global macro, that always point to the<br>
>>> "struct task_struct * " of the currently executing task (for details<br>
>>> on task_struct, ref Robert Love, pg 24-27).<br>
>>><br>
>>> Now I have a macro called push root which has the following<br>
>>> purpose- "to push root user and group to current context so to set<br>
>>> current uid and gid to 0."<br>
>>><br>
>>> Now in kernel 3.8.3, I would do something like<br>
>>><br>
>>> struct cred *new1;<br>
>>> new1 =prepare_creds();<br>
>>> new1->uid = 0;<br>
>>> new1->gid = 0;<br>
>>> commit_creds(new1);<br>
>>><br>
>>> So macro definition of push root, according to what I have proposed<br>
>>> above, should be<br>
>>> #define push_root \<br>
>>> new1 =prepare_creds(); \<br>
>>> new1->uid = 0; \<br>
>>> new1->gid = 0; \<br>
>>> commit_creds(new1)<br>
>>><br>
>>> But I am getting errors like multiple declaration of new1 etc.<br>
>>><br>
>>> Even if I declare prepare_creds outside macro definition like<br>
>>><br>
>>> new1 =prepare_creds();<br>
>>> #define push_root \<br>
>>> new1->uid = 0; \<br>
>>> new1->gid = 0; \<br>
>>> commit_creds(new1)<br>
>>><br>
>>> I think I am facing the issue that the macros are inlined during<br>
>>> compilation, so when the compiler wants to replace them, it raises issues.<br>
>>><br>
>>> I could think of two ways to solve this issue-<br>
>>><br>
>>> 1. define a new macro like #define prep_root() which defines the var<br>
>>> once for all, and that I have to put it at the begin of each<br>
>>> function needing push_root. This is not a very good method.<br>
>>><br>
>>> 2. I should still try to go with inlined functions but how ?<br>
>>><br>
>>> Can someone suggest anything<br>
>>><br>
>>> Regards,<br>
>>> Saket Sinha<br>
>>><br>
>>> _______________________________________________<br>
>>> Kernelnewbies mailing list<br>
>>> <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
>>> <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
>>><br>
>>><br>
>><br>
><br>
> _______________________________________________<br>
> Kernelnewbies mailing list<br>
> <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
> <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
><br>
><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <a href="http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130715/66b262f1/attachment-0001.html" target="_blank">http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130715/66b262f1/attachment-0001.html</a><br>
<br>
------------------------------<br>
<br>
Message: 3<br>
Date: Mon, 15 Jul 2013 16:54:33 +0530<br>
From: anish singh <<a href="mailto:anish198519851985@gmail.com">anish198519851985@gmail.com</a>><br>
Subject: Re: Inline Macro issue<br>
To: Saket Sinha <<a href="mailto:saket.sinha89@gmail.com">saket.sinha89@gmail.com</a>><br>
Cc: Srinivas Ganji <<a href="mailto:srinivasganji.kernel@gmail.com">srinivasganji.kernel@gmail.com</a>>, Mandeep Sandhu<br>
<<a href="mailto:mandeepsandhu.chd@gmail.com">mandeepsandhu.chd@gmail.com</a>>, kernelnewbies<br>
<<a href="mailto:kernelnewbies@kernelnewbies.org">kernelnewbies@kernelnewbies.org</a>><br>
Message-ID:<br>
<<a href="mailto:CAK7N6vp2BCz_B5K2PNvdRJpt-xoqhfNSW9MmavohG1__p9CFiA@mail.gmail.com">CAK7N6vp2BCz_B5K2PNvdRJpt-xoqhfNSW9MmavohG1__p9CFiA@mail.gmail.com</a>><br>
Content-Type: text/plain; charset=UTF-8<br>
<br>
Do one simple thing.Write a test code<br>
which uses that macro and paste it<br>
here in <a href="http://ideone.com" target="_blank">ideone.com</a><br>
<br>
On Mon, Jul 15, 2013 at 4:50 PM, Saket Sinha <<a href="mailto:saket.sinha89@gmail.com">saket.sinha89@gmail.com</a>> wrote:<br>
> Mandip:<br>
> Error is expected error or declaration at the end of input<br>
> Anish:<br>
> that '\' should not be there first of all and even if I put it same<br>
> error<br>
><br>
<br>
<br>
<br>
------------------------------<br>
<br>
Message: 4<br>
Date: Mon, 15 Jul 2013 16:50:34 +0530<br>
From: Saket Sinha <<a href="mailto:saket.sinha89@gmail.com">saket.sinha89@gmail.com</a>><br>
Subject: Re: Inline Macro issue<br>
To: Mandeep Sandhu <<a href="mailto:mandeepsandhu.chd@gmail.com">mandeepsandhu.chd@gmail.com</a>>,<br>
<a href="mailto:anish198519851985@gmail.com">anish198519851985@gmail.com</a><br>
Cc: Srinivas Ganji <<a href="mailto:srinivasganji.kernel@gmail.com">srinivasganji.kernel@gmail.com</a>>, kernelnewbies<br>
<<a href="mailto:kernelnewbies@kernelnewbies.org">kernelnewbies@kernelnewbies.org</a>><br>
Message-ID:<br>
<<a href="mailto:CAK25hWMLndvytwZ0YVFMXhrd44Jb479HmiYLZ48Umozz1pz7vQ@mail.gmail.com">CAK25hWMLndvytwZ0YVFMXhrd44Jb479HmiYLZ48Umozz1pz7vQ@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
Mandip:<br>
Error is expected error or declaration at the end of input<br>
Anish:<br>
that '\' should not be there first of all and even if I put it same error<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <a href="http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130715/41316b0d/attachment-0001.html" target="_blank">http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130715/41316b0d/attachment-0001.html</a><br>
<br>
------------------------------<br>
<br>
Message: 5<br>
Date: Mon, 15 Jul 2013 17:02:49 +0530<br>
From: Saket Sinha <<a href="mailto:saket.sinha89@gmail.com">saket.sinha89@gmail.com</a>><br>
Subject: Re: Inline Macro issue<br>
To: anish singh <<a href="mailto:anish198519851985@gmail.com">anish198519851985@gmail.com</a>><br>
Cc: Srinivas Ganji <<a href="mailto:srinivasganji.kernel@gmail.com">srinivasganji.kernel@gmail.com</a>>, Mandeep Sandhu<br>
<<a href="mailto:mandeepsandhu.chd@gmail.com">mandeepsandhu.chd@gmail.com</a>>, kernelnewbies<br>
<<a href="mailto:kernelnewbies@kernelnewbies.org">kernelnewbies@kernelnewbies.org</a>><br>
Message-ID:<br>
<<a href="mailto:CAK25hWMvjdABa-KS1Ru1bBWaETd7JHKOGXdqhyY8ROLksSKi3w@mail.gmail.com">CAK25hWMvjdABa-KS1Ru1bBWaETd7JHKOGXdqhyY8ROLksSKi3w@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
Dear Anish,<br>
<br>
Actually its kernel module, so then I will have to write all the dummy equivalent of the structures and functions involved.<br>
<br>
I can do this....give my system on remote.<br>
<br>
Regards,<br>
Saket Sinha<br>
<br>
<br>
<br>
On Mon, Jul 15, 2013 at 4:54 PM, anish singh <<a href="mailto:anish198519851985@gmail.com">anish198519851985@gmail.com</a>>wrote:<br>
<br>
> Do one simple thing.Write a test code<br>
> which uses that macro and paste it<br>
> here in <a href="http://ideone.com" target="_blank">ideone.com</a><br>
><br>
> On Mon, Jul 15, 2013 at 4:50 PM, Saket Sinha <<a href="mailto:saket.sinha89@gmail.com">saket.sinha89@gmail.com</a>><br>
> wrote:<br>
> > Mandip:<br>
> > Error is expected error or declaration at the end of input<br>
> > Anish:<br>
> > that '\' should not be there first of all and even if I put it same<br>
> > error<br>
> ><br>
><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <a href="http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130715/1281ba32/attachment.html" target="_blank">http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130715/1281ba32/attachment.html</a><br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
<br>
<br>
End of Kernelnewbies Digest, Vol 32, Issue 20<br>
*********************************************<br>
<br>
<br>
::DISCLAIMER::<br>
----------------------------------------------------------------------------------------------------------------------------------------------------<br>
<br>
The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only.<br>
E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted,<br>
lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents<br>
(with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates.<br>
Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the<br>
views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification,<br>
distribution and / or publication of this message without the prior written consent of authorized representative of<br>
HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately.<br>
Before opening any email and/or attachments, please check them for viruses and other defects.<br>
<br>
----------------------------------------------------------------------------------------------------------------------------------------------------<br>
<br>
</blockquote></div><br></div>