Use ptsname(), not ptsname_r(), for portability
This commit is contained in:
parent
10745bbabf
commit
9463e22481
4 changed files with 14 additions and 11 deletions
|
@ -54,16 +54,16 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
if (isatty(info.fd) && grantpt(info.fd) == 0 && unlockpt(info.fd) == 0) {
|
||||
char name[256];
|
||||
char *pts;
|
||||
|
||||
if (ptsname_r(info.fd, name, sizeof(name)) < 0) {
|
||||
if ((pts = ptsname(info.fd)) == NULL) {
|
||||
fprintf(stderr, "%s: %s: %s: %s\n",
|
||||
argv[0], argv[1], "ptsname_r()", strerror(errno));
|
||||
argv[0], argv[1], "ptsname()", strerror(errno));
|
||||
|
||||
goto error_open;
|
||||
}
|
||||
|
||||
fprintf(stderr, "pts %s\n", name);
|
||||
fprintf(stderr, "pts %s\n", pts);
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
|
|
|
@ -73,7 +73,7 @@ typedef struct _patty_ax25_sock {
|
|||
flags_hdlc;
|
||||
|
||||
int fd;
|
||||
char path[PATTY_AX25_SOCK_PATH_SIZE];
|
||||
char pty[PATTY_AX25_SOCK_PATH_SIZE];
|
||||
|
||||
void *tx_buf,
|
||||
*rx_buf;
|
||||
|
|
|
@ -555,7 +555,7 @@ static int server_socket(patty_ax25_server *server, int client) {
|
|||
response.ret = sock->fd;
|
||||
response.eno = 0;
|
||||
|
||||
memcpy(response.path, sock->path, sizeof(response.path));
|
||||
memcpy(response.path, patty_ax25_sock_pty(sock), sizeof(response.path));
|
||||
|
||||
return write(client, &response, sizeof(response));
|
||||
|
||||
|
@ -1201,7 +1201,7 @@ static int handle_sabm(patty_ax25_server *server,
|
|||
|
||||
fd_watch(server, remote->fd);
|
||||
|
||||
if (respond_accept(client, 0, 0, &frame->src, remote->path) < 0) {
|
||||
if (respond_accept(client, 0, 0, &frame->src, remote->pty) < 0) {
|
||||
goto error_respond_accept;
|
||||
}
|
||||
|
||||
|
|
11
src/sock.c
11
src/sock.c
|
@ -14,6 +14,7 @@
|
|||
|
||||
static int bind_pty(patty_ax25_sock *sock) {
|
||||
struct termios t;
|
||||
char *pty;
|
||||
|
||||
if ((sock->fd = open("/dev/ptmx", O_RDWR)) < 0) {
|
||||
goto error_open;
|
||||
|
@ -27,10 +28,12 @@ static int bind_pty(patty_ax25_sock *sock) {
|
|||
goto error_unlockpt;
|
||||
}
|
||||
|
||||
if (ptsname_r(sock->fd, sock->path, sizeof(sock->path)) < 0) {
|
||||
goto error_ptsname_r;
|
||||
if ((pty = ptsname(sock->fd)) == NULL) {
|
||||
goto error_ptsname;
|
||||
}
|
||||
|
||||
(void)strncpy(sock->pty, pty, sizeof(sock->pty));
|
||||
|
||||
if (tcgetattr(sock->fd, &t) < 0) {
|
||||
goto error_tcgetattr;
|
||||
}
|
||||
|
@ -45,7 +48,7 @@ static int bind_pty(patty_ax25_sock *sock) {
|
|||
|
||||
error_tcsetattr:
|
||||
error_tcgetattr:
|
||||
error_ptsname_r:
|
||||
error_ptsname:
|
||||
error_unlockpt:
|
||||
error_grantpt:
|
||||
close(sock->fd);
|
||||
|
@ -299,7 +302,7 @@ error_invalid:
|
|||
}
|
||||
|
||||
char *patty_ax25_sock_pty(patty_ax25_sock *sock) {
|
||||
return sock->path;
|
||||
return sock->pty;
|
||||
}
|
||||
|
||||
int patty_ax25_sock_bind_if(patty_ax25_sock *sock,
|
||||
|
|
Loading…
Add table
Reference in a new issue