85c247161b
function old new delta bbunpack 358 366 +8 passwd_main 1070 1072 +2 handle_incoming_and_exit 2651 2653 +2 getpty 88 86 -2 script_main 975 972 -3 inetd_main 2036 2033 -3 dname_enc 377 373 -4 make_new_session 474 462 -12 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/5 up/down: 12/-24) Total: -12 bytes text data bss dec hex filename 797429 658 7428 805515 c4a8b busybox_old 797417 658 7428 805503 c4a7f busybox_unstripped
61 lines
1.1 KiB
C
61 lines
1.1 KiB
C
/* vi: set sw=4 ts=4: */
|
|
/*
|
|
* Mini getpty implementation for busybox
|
|
* Bjorn Wesen, Axis Communications AB (bjornw@axis.com)
|
|
*
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
|
*/
|
|
|
|
#include "libbb.h"
|
|
|
|
#define DEBUG 0
|
|
|
|
#define DEBUG 0
|
|
|
|
int getpty(char *line)
|
|
{
|
|
int p;
|
|
#if ENABLE_FEATURE_DEVPTS
|
|
p = open("/dev/ptmx", O_RDWR);
|
|
if (p > 0) {
|
|
const char *name;
|
|
grantpt(p);
|
|
unlockpt(p);
|
|
name = ptsname(p);
|
|
if (!name) {
|
|
bb_perror_msg("ptsname error (is /dev/pts mounted?)");
|
|
return -1;
|
|
}
|
|
safe_strncpy(line, name, GETPTY_BUFSIZE);
|
|
return p;
|
|
}
|
|
#else
|
|
struct stat stb;
|
|
int i;
|
|
int j;
|
|
|
|
strcpy(line, "/dev/ptyXX");
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
line[8] = "pqrstuvwxyzabcde"[i];
|
|
line[9] = '0';
|
|
if (stat(line, &stb) < 0) {
|
|
continue;
|
|
}
|
|
for (j = 0; j < 16; j++) {
|
|
line[9] = j < 10 ? j + '0' : j - 10 + 'a';
|
|
if (DEBUG)
|
|
fprintf(stderr, "Trying to open device: %s\n", line);
|
|
p = open(line, O_RDWR | O_NOCTTY);
|
|
if (p >= 0) {
|
|
line[5] = 't';
|
|
return p;
|
|
}
|
|
}
|
|
}
|
|
#endif /* FEATURE_DEVPTS */
|
|
return -1;
|
|
}
|
|
|
|
|