/* minopen.c - Runs a shell on the first unused tty */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/vt.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
int main (int argc, const char **argv) {
int vtnum;
int vtfd;
struct vt_stat vtstat;
char device[32];
int child;
vtfd = open("/dev/tty", O_RDWR, 0);
if (vtfd < 0) {
perror("minopen: could not open /dev/tty");
exit (1);
}
if (ioctl(vtfd, VT_GETSTATE, &vtstat) < 0) {
perror("minopen: tty is not virtual console");
exit (1);
}
if (ioctl(vtfd, VT_OPENQRY, &vtnum) < 0) {
perror("minopen: no free virtual consoles");
exit (1);
}
sprintf(device, "/dev/tty%d", vtnum);
if (access(device, (W_OK|R_OK)) < 0) {
perror("minopen: insufficient permission on tty");
exit (1);
}
child = fork();
if (child == 0) {
ioctl(vtfd, VT_ACTIVATE, vtnum);
ioctl(vtfd, VT_WAITACTIVE, vtnum);
setsid();
close (0); close (1); close (2);
close (vtfd);
vtfd = open(device, O_RDWR, 0); dup(vtfd); dup(vtfd);
execlp("/bin/bash", "bash", NULL);
}
wait (&child);
ioctl(vtfd, VT_ACTIVATE, vtstat.v_active);
ioctl(vtfd, VT_WAITACTIVE, vtstat.v_active);
ioctl(vtfd, VT_DISALLOCATE, vtnum);
exit(0);
}
没有合适的资源?快使用搜索试试~ 我知道了~
minopen.rar_The First
共1个文件
c:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 42 浏览量
2022-09-22
18:13:59
上传
评论
收藏 642B RAR 举报
温馨提示
Runs a shell on the first unused tty。。。
资源推荐
资源详情
资源评论
收起资源包目录
minopen.rar (1个子文件)
minopen.c 1KB
共 1 条
- 1
资源评论
APei
- 粉丝: 65
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功