RE: Kernelnewbies Digest, Vol 32, Issue 20
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@kernelnewbies.org [mailto:kernelnewbies-bounces@kernelnewbies.org] On Behalf Of kernelnewbies-request@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-request@kernelnewbies.org You can reach the person managing the list at kernelnewbies-owner@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.sinha89@gmail.com> Subject: Re: Inline Macro issue To: Srinivas Ganji <srinivasganji.kernel@gmail.com> Cc: kernelnewbies@kernelnewbies.org Message-ID: <CAK25hWO3zbFu8MgXtPSpGq_0uj+qv07hGJjp018heGTDABN7nA@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@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.sinha89@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
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.murali@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-bounces@kernelnewbies.org [mailto: kernelnewbies-bounces@kernelnewbies.org] On Behalf Of kernelnewbies-request@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-request@kernelnewbies.org
You can reach the person managing the list at kernelnewbies-owner@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.sinha89@gmail.com> Subject: Re: Inline Macro issue To: Srinivas Ganji <srinivasganji.kernel@gmail.com> Cc: kernelnewbies@kernelnewbies.org Message-ID: < CAK25hWO3zbFu8MgXtPSpGq_0uj+qv07hGJjp018heGTDABN7nA@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@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.sinha89@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
participants (2)
-
Murali Annamneni -
Saket Sinha