getty can run ttysize on startup, I guess

This commit is contained in:
K. Lange 2018-08-01 10:03:34 +09:00
parent ccf29a98d9
commit 43da728a6b
2 changed files with 21 additions and 5 deletions

View File

@ -30,6 +30,8 @@ int main(int argc, char * argv[]) {
dup2(fd_slave, 1);
dup2(fd_slave, 2);
system("ttysize -q");
char * tokens[] = {"/bin/login",NULL};
execvp(tokens[0], tokens);
exit(1);

View File

@ -1,6 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <syscall.h>
@ -62,12 +64,22 @@ _done:
int main(int argc, char * argv[]) {
int width, height;
int opt;
int quiet = 0;
if (argc < 3) {
divine_size(&width, &height);
while ((opt = getopt(argc, argv, "q")) != -1) {
switch (opt) {
case 'q':
quiet = 1;
break;
}
}
if (optind + 2 == argc) {
width = atoi(argv[optind]);
height = atoi(argv[optind+1]);
} else {
width = atoi(argv[1]);
height = atoi(argv[2]);
divine_size(&width, &height);
}
struct winsize w;
@ -77,7 +89,9 @@ int main(int argc, char * argv[]) {
w.ws_ypixel = 0;
ioctl(0, TIOCSWINSZ, &w);
fprintf(stderr, "%dx%d\n", width, height);
if (!quiet) {
fprintf(stderr, "%dx%d\n", width, height);
}
return 0;
}