/*logou_tty.c
*注销用户,在utemp文件中将指定的tty注销。
*/
#include <stdio.h>
#include <utmp.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <sys/types.h>
#include <string.h>
int logout_tty(char *);
int main(int argc, char **argv)
{
if (argc==1){
printf("Errro: no tty.\n");
exit(1);
}
else{
while(--argc){
if(logout_tty(*++argv) != -1)
printf("Logout:%s\n",*argv);
else
printf("Fail to logout:%s\n",*argv);
}
}
return 0;
}
int logout_tty( char *line )
{
int fd;
struct utmp rec;
int len = sizeof(struct utmp);
int retval = -1;
if(( fd = open(UTMP_FILE,O_RDWR)) == -1)
return -1;
while(read(fd, &rec, len) == len){
if(strncmp(rec.u
《UNIX/LINUX编程实践教程》实例注释chapt2 - logout_tty
最新推荐文章于 2022-03-18 17:56:07 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)