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 <a.mur...@hcl.com> 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-boun...@kernelnewbies.org [mailto: > kernelnewbies-boun...@kernelnewbies.org] On Behalf Of > kernelnewbies-requ...@kernelnewbies.org > Sent: Monday, July 15, 2013 5:03 PM > To: kernelnewbies@kernelnewbies.org > Subject: Kernelnewbies Digest, Vol 32, Issue 20 > > Send Kernelnewbies mailing list submissions to > kernelnewbies@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-requ...@kernelnewbies.org > > You can reach the person managing the list at > kernelnewbies-ow...@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 <saket.sinh...@gmail.com> > Subject: Re: Inline Macro issue > To: Srinivas Ganji <srinivasganji.ker...@gmail.com> > Cc: kernelnewbies@kernelnewbies.org > Message-ID: > < > cak25hwo3zbfu8mgxtpspgq_0uj+qv07hgjjp018hegtdabn...@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.ker...@gmail.com> wrote: > > > 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.sinh...@gmail.com > >wrote: > > > >> "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 raises > issues. > >> > >> 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@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 <mandeepsandhu....@gmail.com> > Subject: Re: Inline Macro issue > To: Saket Sinha <saket.sinh...@gmail.com> > Cc: Srinivas Ganji <srinivasganji.ker...@gmail.com>, kernelnewbies > <kernelnewbies@kernelnewbies.org> > Message-ID: > <CAC+QLdQbBuNEW7EKZk4vUTNuu2LGSZ6gJhf4bde3gC+= > d9f...@mail.gmail.com> > Content-Type: text/plain; charset="iso-8859-1" > > On Mon, Jul 15, 2013 at 3:54 PM, Saket Sinha <saket.sinh...@gmail.com > >wrote: > > > 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, > -mandeep > > > > > > > Regards, > > Saket Sinha > > * > > * > > > > > > On Mon, Jul 15, 2013 at 2:25 PM, Srinivas Ganji < > > srinivasganji.ker...@gmail.com> wrote: > > > >> 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.sinh...@gmail.com > >wrote: > >> > >>> "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 raises > issues. > >>> > >>> 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@kernelnewbies.org > >>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies > >>> > >>> > >> > > > > _______________________________________________ > > Kernelnewbies mailing list > > Kernelnewbies@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 <anish198519851...@gmail.com> > Subject: Re: Inline Macro issue > To: Saket Sinha <saket.sinh...@gmail.com> > Cc: Srinivas Ganji <srinivasganji.ker...@gmail.com>, Mandeep Sandhu > <mandeepsandhu....@gmail.com>, kernelnewbies > <kernelnewbies@kernelnewbies.org> > Message-ID: > < > cak7n6vp2bcz_b5k2pnvdrjpt-xoqhfnsw9mmavohg1__p9c...@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 <saket.sinh...@gmail.com> > wrote: > > 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 <saket.sinh...@gmail.com> > Subject: Re: Inline Macro issue > To: Mandeep Sandhu <mandeepsandhu....@gmail.com>, > anish198519851...@gmail.com > Cc: Srinivas Ganji <srinivasganji.ker...@gmail.com>, kernelnewbies > <kernelnewbies@kernelnewbies.org> > Message-ID: > < > cak25hwmlndvytwz0yvfmxhrd44jb479hmiylz48umozz1pz...@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 <saket.sinh...@gmail.com> > Subject: Re: Inline Macro issue > To: anish singh <anish198519851...@gmail.com> > Cc: Srinivas Ganji <srinivasganji.ker...@gmail.com>, Mandeep Sandhu > <mandeepsandhu....@gmail.com>, kernelnewbies > <kernelnewbies@kernelnewbies.org> > Message-ID: > < > cak25hwmvjdaba-ks1ru1bbwaetd7jhkogxdqhyy8rolkssk...@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 <anish198519851...@gmail.com > >wrote: > > > 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 <saket.sinh...@gmail.com> > > wrote: > > > 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@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. > > > ---------------------------------------------------------------------------------------------------------------------------------------------------- > >
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies