Index: Makefile =================================================================== RCS file: /usr/CVS-Repository/src/usr.bin/bluetooth/rfcomm_sppd/Makefile,v retrieving revision 1.3 diff -u -r1.3 Makefile --- Makefile 28 Jan 2005 16:08:07 -0000 1.3 +++ Makefile 18 May 2008 07:25:58 -0000 @@ -6,6 +6,6 @@ WARNS?= 2 DPADD= ${LIBBLUETOOTH} ${LIBSDP} -LDADD= -lbluetooth -lsdp +LDADD= -lbluetooth -lsdp -lutil .include Index: rfcomm_sppd.1 =================================================================== RCS file: /usr/CVS-Repository/src/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.1,v retrieving revision 1.10 diff -u -r1.10 rfcomm_sppd.1 --- rfcomm_sppd.1 25 Jan 2007 20:54:59 -0000 1.10 +++ rfcomm_sppd.1 18 May 2008 09:52:04 -0000 @@ -33,10 +33,9 @@ .Nd RFCOMM Serial Port Profile daemon .Sh SYNOPSIS .Nm -.Op Fl bhS +.Op Fl bhSt .Fl a Ar address .Fl c Ar channel -.Op Fl t Ar tty .Sh DESCRIPTION The .Nm @@ -56,7 +55,7 @@ .Xr pty 4 interface if .Fl t -option was specified. +option is specified. .Pp If the .Fl S @@ -72,8 +71,8 @@ The .Fl t option must be specified; -the server side of the virtual serial port is attached to the pseudo-terminal -.Ar tty . +the server side of the virtual serial port is attached to an allocated +pseudo-terminal. .Nm should be run as root in order to communicate with .Xr sdp 8 @@ -139,8 +138,8 @@ .It Fl S Server mode; see .Sx DESCRIPTION . -.It Fl t Ar tty -Slave pseudo tty name. +.It Fl t +Allocate a PTY. If not set stdin/stdout will be used. This option is required if .Fl b @@ -158,7 +157,7 @@ .Sh EXIT STATUS .Ex -std .Sh EXAMPLES -.Dl "rfcomm_sppd -a 00:01:02:03:04:05 -c 1 -t /dev/ttyp1" +.Dl "rfcomm_sppd -a 00:01:02:03:04:05 -c 1 -t" .Pp Will start the .Nm @@ -166,8 +165,7 @@ .Li 00:01:02:03:04:05 and channel .Li 1 . -Once the connection has been established, -.Pa /dev/ttyp1 +Once the connection has been established a PTY will be allocated which can be used to talk to the remote serial port on the server. .Sh SEE ALSO .Xr bluetooth 3 , Index: rfcomm_sppd.c =================================================================== RCS file: /usr/CVS-Repository/src/usr.bin/bluetooth/rfcomm_sppd/rfcomm_sppd.c,v retrieving revision 1.10 diff -u -r1.10 rfcomm_sppd.c --- rfcomm_sppd.c 11 Sep 2007 01:59:00 -0000 1.10 +++ rfcomm_sppd.c 18 May 2008 09:54:53 -0000 @@ -47,6 +47,8 @@ #include #include #include +#include +#include #define SPPD_IDENT "rfcomm_sppd" #define SPPD_BUFFER_SIZE 1024 @@ -56,7 +58,7 @@ bdaddr_t const *remote, int service, int *channel, int *error); -static int sppd_ttys_open (char const *tty, int *amaster, int *aslave); +static int sppd_ttys_open (char *tty, int *amaster, int *aslave); static int sppd_read (int fd, char *buffer, int size); static int sppd_write (int fd, char *buffer, int size); static void sppd_sighandler (int s); @@ -82,7 +84,7 @@ doserver = 0; /* Parse command line options */ - while ((n = getopt(argc, argv, "a:bc:t:hS")) != -1) { + while ((n = getopt(argc, argv, "a:bc:hSt")) != -1) { switch (n) { case 'a': /* BDADDR */ if (!bt_aton(optarg, &addr)) { @@ -128,11 +130,8 @@ background = 1; break; - case 't': /* Slave TTY name */ - if (optarg[0] != '/') - asprintf(&tty, "%s%s", _PATH_DEV, optarg); - else - tty = optarg; + case 't': /* Allocate PTY */ + tty = malloc(MAXPATHLEN); break; case 'S': @@ -294,7 +293,7 @@ } openlog(SPPD_IDENT, LOG_NDELAY|LOG_PERROR|LOG_PID, LOG_DAEMON); - syslog(LOG_INFO, "Starting on %s...", (tty != NULL)? tty : "stdin/stdout"); + syslog(LOG_INFO, "Starting on %s", (tty != NULL)? tty : "stdin/stdout"); for (done = 0; !done; ) { FD_ZERO(&rfd); @@ -368,59 +367,12 @@ /* Open TTYs */ static int -sppd_ttys_open(char const *tty, int *amaster, int *aslave) +sppd_ttys_open(char *tty, int *amaster, int *aslave) { - char pty[PATH_MAX], *slash; - struct group *gr = NULL; - gid_t ttygid; struct termios tio; - /* - * Construct master PTY name. The slave tty name must be less then - * PATH_MAX characters in length, must contain '/' character and - * must not end with '/'. - */ - - if (strlen(tty) >= sizeof(pty)) { - syslog(LOG_ERR, "Slave tty name is too long"); - return (-1); - } - - strlcpy(pty, tty, sizeof(pty)); - slash = strrchr(pty, '/'); - if (slash == NULL || slash[1] == '\0') { - syslog(LOG_ERR, "Invalid slave tty name (%s)", tty); - return (-1); - } - - slash[1] = 'p'; - - if (strcmp(pty, tty) == 0) { - syslog(LOG_ERR, "Master and slave tty are the same (%s)", tty); - return (-1); - } - - if ((*amaster = open(pty, O_RDWR, 0)) < 0) { - syslog(LOG_ERR, "Could not open(%s). %s", pty, strerror(errno)); - return (-1); - } - - /* - * Slave TTY - */ - - if ((gr = getgrnam("tty")) != NULL) - ttygid = gr->gr_gid; - else - ttygid = -1; - - (void) chown(tty, getuid(), ttygid); - (void) chmod(tty, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP); - (void) revoke(tty); - - if ((*aslave = open(tty, O_RDWR, 0)) < 0) { - syslog(LOG_ERR, "Could not open(%s). %s", tty, strerror(errno)); - close(*amaster); + if (openpty(amaster, aslave, tty, &tio, NULL) == -1) { + syslog(LOG_ERR, "openpty() failed: %m"); return (-1); } @@ -505,8 +457,8 @@ "\t-a address Peer address (required in client mode)\n" \ "\t-b Run in background\n" \ "\t-c channel RFCOMM channel to connect to or listen on\n" \ -"\t-t tty TTY name (required in background or server mode)\n" \ "\t-S Server mode\n" \ +"\t-t Allocate a PTY (required in background or server mode)\n" \ "\t-h Display this message\n", SPPD_IDENT); exit(255); } /* usage */