Writing Log during greeter login

mj1240

New Member
Joined
Dec 31, 2020
Messages
4
Reaction score
0
Credits
45
Hi,

I am new to Linux programming.
I am trying to add a module that will be run as additional rule to PAM.

My current goal is to create a logging system, but I am having problem on permission on writing my log.

PAM_EXTERN int pam_sm_authenticate( pam_handle_t *pamh, int flags,int argc, const char **argv ) {
FILE * fp = fopen("/var/log/fmepam.log","a");

if(fp != NULL)
{
fprintf(fp, "Hello World!\n");
fclose(fp);
}
else
{
printf("failed to create file\n");
}


return PAM_SUCCESS;
}

Actually I will face more permission problem later on my code, since I will be needing to run an executable,
that will run my custom Face Detection in user space. But I think, first step is to have logging system so I can know what problems am i facing on actual log in.

I hope I can find any leads to solve my problem. Thank in advance.
 


temporarily, this works for me:

Terminal:
logger [My Logs]

Programmatically in my user-space program:
system("logger [My Logs..]");

Then I can fin my logs at /var/logs/syslogs

I can just grep my keyword in the logs i think.

so far I could not yet find a way how can I make it variable.
But at this point, I think I can use it to check which branch of my program was executed.

But if you have other idea, please advice me.

Thank you in advance.
 
temporarily, this works for me:

Terminal:
logger [My Logs]

Programmatically in my user-space program:
system("logger [My Logs..]");

Then I can fin my logs at /var/logs/syslogs

I can just grep my keyword in the logs i think.

so far I could not yet find a way how can I make it variable.
But at this point, I think I can use it to check which branch of my program was executed.

But if you have other idea, please advice me.

Thank you in advance.


I found more efficient way here:

 

Members online


Latest posts

Top