<div dir="ltr">Dear Srinivas,<div><br></div><div>If you are suggesting something like</div><div><br></div><div> <span style="font-family:arial,sans-serif;font-size:13px">#define push_root \ <b>{</b></span></div>
<span style="font-family:arial,sans-serif;font-size:13px">new1 =prepare_creds(); \</span><br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px">new1->uid = 0; \ </span><br style="font-family:arial,sans-serif;font-size:13px">
<span style="font-family:arial,sans-serif;font-size:13px">new1->gid = 0; \</span><br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px">commit_creds(new1) </span><div>
<font face="arial, sans-serif"><b>}</b></font></div><div><font face="arial, sans-serif"><b><br></b></font></div><div><font face="arial, sans-serif">Sorry I am still getting a compiler error.</font></div><div><font face="arial, sans-serif"><br>
</font></div><div><font face="arial, sans-serif">Regards,</font></div><div><font face="arial, sans-serif">Saket Sinha</font></div><div><font face="arial, sans-serif"><b><br></b></font></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Mon, Jul 15, 2013 at 2:25 PM, Srinivas Ganji <span dir="ltr"><<a href="mailto:srinivasganji.kernel@gmail.com" target="_blank">srinivasganji.kernel@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>A small suggestion, use begin { and end } braces for declaring your macro. May be I am wrong, but you can try this. Then, the declaration become local to that block.<br>
</div><div><br></div><div>Regards,</div>
<div>Srinivas</div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">On Mon, Jul 15, 2013 at 1:03 AM, Saket Sinha <span dir="ltr"><<a href="mailto:saket.sinha89@gmail.com" target="_blank">saket.sinha89@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div><div>"current" in kernel is a global macro, that always point to the "struct task_struct * " of the currently executing task (for details 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 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 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 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 once for all, and that I have to put it at the begin of each 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></div>Regards,<br></div>Saket Sinha<br></div>
<br></div></div>_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">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></blockquote></div><br></div>
</blockquote></div><br></div>