Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
![Reply](https://www.linuxquestions.org/questions/images/buttons/reply.gif) |
02-05-2002, 01:42 AM
|
#1
|
LQ Newbie
Registered: Feb 2002
Location: tx =/
Distribution: Slackware, SuSE
Posts: 14
Rep:
|
c prog that logs user off...
ok, heres what i want i need....well want, hehe...
in a c program, its a simple menu, i need to log the user running the program off...back to the login prompt. this is not a super user, just a normal account.
i know i could just set the program to be the users login shell..but i'd rather do it this way. im not sure if this is possible. and i know it may not be that secure. but is there a way to do this?
if its not possible from within a c prog, what about from a shell script?
any one? ![Frown](https://www.linuxquestions.org/questions/images/smilies/frown.gif)
|
|
|
02-05-2002, 02:06 AM
|
#2
|
Senior Member
Registered: Jun 2001
Posts: 1,635
Rep:
|
well... i'm sure it's possible. compiling against the kernel headers might be one way to go (and you'd be totally on your own there ![Smilie](https://www.linuxquestions.org/questions/images/smilies/smile.gif) ), but running "exit" or "logout" using an exec variant would probably be the easiest way to go outside of a shell script. i'm not sure the shell script would even work.
|
|
|
02-05-2002, 02:43 AM
|
#3
|
LQ Newbie
Registered: Feb 2002
Location: tx =/
Distribution: Slackware, SuSE
Posts: 14
Original Poster
Rep:
|
yeah, ive tried using exit..but i couldnt get it to work. maybe (dont hate me =) you could give me an example. pretty please...
you know you cant resist ![Big Grin](https://www.linuxquestions.org/questions/images/smilies/biggrin.gif)
|
|
|
02-05-2002, 02:56 AM
|
#4
|
Senior Member
Registered: Jun 2001
Posts: 1,635
Rep:
|
Quote:
Originally posted by acromi
yeah, ive tried using exit..but i couldnt get it to work. maybe (dont hate me =) you could give me an example. pretty please...
you know you cant resist
|
lol - you don't know how true that is. this is gonna bug me for days.
anyway, i tried writing a quick shell script, and all that happened was that it exited from itself. nothing exciting.
offhand, if you want to write this prog, then you're going to need to learn more about the login process than i currently know. all i know is something vague about gettys and virtual consoles. i was wondering if it might be that a user-space prog can't access that particular function... it might be a security risk somehow.
ummm... try checking out the source to "su" - that seems like it might have something useful or similar.
|
|
|
02-05-2002, 03:00 AM
|
#5
|
Senior Member
Registered: Jun 2001
Posts: 1,635
Rep:
|
or... (this just occured to me) you could just kill your user's main process and see what happens. i think that would work. (haven't tried it ![Smilie](https://www.linuxquestions.org/questions/images/smilies/smile.gif) )
|
|
|
02-05-2002, 03:04 AM
|
#6
|
LQ Newbie
Registered: Feb 2002
Location: tx =/
Distribution: Slackware, SuSE
Posts: 14
Original Poster
Rep:
|
heh...sorry i got you interested =)
im faily new to programming in a unix environment. i've been running a linux box for about a year i guess now, and im just trying to think of ways to get more familiar with how it ticks...and this is one of those ways...
let me know if you find anything, or if you get bored looking. in the meantime i will keep lookin for a solution (after i sleep a little)
thx alot
|
|
|
02-05-2002, 11:16 AM
|
#7
|
LQ Newbie
Registered: Jan 2002
Posts: 9
Rep:
|
Instead of checking the source of su. Wouldn´t it be better to check the source for logout?
|
|
|
02-05-2002, 03:50 PM
|
#8
|
Senior Member
Registered: Jun 2001
Posts: 1,635
Rep:
|
logout isn't a program - it's a function in a shell program to terminate the shell. afaik, the login just activates a shell program, like bash, csh, tsh, ect, which then goes on to do all the other stuff, like X - after the original shell dies, the login terminates. so, we're looking for a way to kill the first shell after login. you can't call logout because it's a function inside the shell, and you don't have access to it if you're operating outside of it, as we hypotheticially are.
|
|
|
02-05-2002, 11:40 PM
|
#9
|
Senior Member
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821
Rep: ![Reputation: 121](https://www.linuxquestions.org/questions/images/reputation/reputation_pos.gif)
|
If you start the program from your login shell, this program will kill it. It gets the pid of its parent and calls kill on that pid.
Code:
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
main()
{
pid_t iParentPid = 0;
iParentPid = getppid();
kill( ParentPid, SIGHUP );
}
|
|
|
02-06-2002, 12:34 AM
|
#10
|
Senior Member
Registered: Jun 2001
Posts: 1,635
Rep:
|
that would only work from the first shell - it wouldn't work inside X. what would work is to grep the output of 'ps -f' to get the shell program belonging to your user that has the lowest pid - that would be the first shell called after login, send it the SIGHUP.
|
|
|
02-06-2002, 12:49 AM
|
#11
|
LQ Newbie
Registered: Feb 2002
Location: tx =/
Distribution: Slackware, SuSE
Posts: 14
Original Poster
Rep:
|
i pretty much wanted this to work from the console. so that will work. but now that intrigues me to get it to work in X
thanks for the help guys
|
|
|
02-06-2002, 12:54 AM
|
#12
|
Senior Member
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821
Rep: ![Reputation: 121](https://www.linuxquestions.org/questions/images/reputation/reputation_pos.gif)
|
I thought about a popen( "ps" ) type of deal, but you would really have to kill all the users processes. There is no guarantee that the lowest pid is the login shell especially on a busy system.
|
|
|
All times are GMT -5. The time now is 02:45 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|