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