Fix uucp locking
Remove unnecesary TIOCSETD Move SLIO* before startup script call
This commit is contained in:
parent
5ab506f0f1
commit
dbfd470885
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=10889
@ -30,7 +30,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: startslip.c,v 1.14 1995/09/17 21:47:24 ache Exp $
|
* $Id: startslip.c,v 1.15 1995/09/18 14:01:11 ache Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
@ -292,18 +292,6 @@ main(argc, argv)
|
|||||||
}
|
}
|
||||||
printd(" %d", fd);
|
printd(" %d", fd);
|
||||||
signal(SIGHUP, sighup);
|
signal(SIGHUP, sighup);
|
||||||
if (debug) {
|
|
||||||
if (ioctl(fd, TIOCGETD, &disc) < 0)
|
|
||||||
syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
|
|
||||||
else
|
|
||||||
printd(" (disc was %d)", disc);
|
|
||||||
}
|
|
||||||
disc = TTYDISC;
|
|
||||||
if (ioctl(fd, TIOCSETD, &disc) < 0) {
|
|
||||||
syslog(LOG_ERR, "%s: ioctl (TIOCSETD 0): %m\n",
|
|
||||||
devicename);
|
|
||||||
down(2);
|
|
||||||
}
|
|
||||||
if (ioctl(fd, TIOCSCTTY, 0) < 0) {
|
if (ioctl(fd, TIOCSCTTY, 0) < 0) {
|
||||||
syslog(LOG_ERR, "ioctl (TIOCSCTTY): %m");
|
syslog(LOG_ERR, "ioctl (TIOCSCTTY): %m");
|
||||||
down(2);
|
down(2);
|
||||||
@ -430,17 +418,12 @@ main(argc, argv)
|
|||||||
syslog(LOG_ERR, "ioctl(SLIOCSUNIT): %m");
|
syslog(LOG_ERR, "ioctl(SLIOCSUNIT): %m");
|
||||||
down(2);
|
down(2);
|
||||||
}
|
}
|
||||||
if (ioctl(fd, SLIOCGUNIT, (caddr_t)&unitnum) < 0) {
|
if (ioctl(fd, SLIOCGUNIT, &unitnum) < 0) {
|
||||||
syslog(LOG_ERR, "ioctl(SLIOCGUNIT): %m");
|
syslog(LOG_ERR, "ioctl(SLIOCGUNIT): %m");
|
||||||
down(2);
|
down(2);
|
||||||
}
|
}
|
||||||
sprintf(unitname, "sl%d", unitnum);
|
sprintf(unitname, "sl%d", unitnum);
|
||||||
|
|
||||||
sprintf(buf, "LINE=%d %s %s up",
|
|
||||||
diali ? (dialc - 1) % diali : 0,
|
|
||||||
upscript ? upscript : "/sbin/ifconfig" , unitname);
|
|
||||||
(void) system(buf);
|
|
||||||
|
|
||||||
if (keepal > 0) {
|
if (keepal > 0) {
|
||||||
signal(SIGURG, sigurg);
|
signal(SIGURG, sigurg);
|
||||||
if (ioctl(fd, SLIOCSKEEPAL, &keepal) < 0) {
|
if (ioctl(fd, SLIOCSKEEPAL, &keepal) < 0) {
|
||||||
@ -452,6 +435,12 @@ main(argc, argv)
|
|||||||
syslog(LOG_ERR, "ioctl(SLIOCSOUTFILL): %m");
|
syslog(LOG_ERR, "ioctl(SLIOCSOUTFILL): %m");
|
||||||
down(2);
|
down(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sprintf(buf, "LINE=%d %s %s up",
|
||||||
|
diali ? (dialc - 1) % diali : 0,
|
||||||
|
upscript ? upscript : "/sbin/ifconfig" , unitname);
|
||||||
|
(void) system(buf);
|
||||||
|
|
||||||
printd(", ready\n");
|
printd(", ready\n");
|
||||||
if (!first)
|
if (!first)
|
||||||
syslog(LOG_INFO, "reconnected on %s (%d tries).\n", unitname, tries);
|
syslog(LOG_INFO, "reconnected on %s (%d tries).\n", unitname, tries);
|
||||||
@ -565,11 +554,8 @@ carrier()
|
|||||||
|
|
||||||
down(code)
|
down(code)
|
||||||
{
|
{
|
||||||
int disc = TTYDISC;
|
if (fd > -1)
|
||||||
|
close(fd);
|
||||||
if (fd > -1 && ioctl(fd, TIOCSETD, &disc) < 0)
|
|
||||||
syslog(LOG_ERR, "%s: ioctl (TIOCSETD 0): %m",
|
|
||||||
devicename);
|
|
||||||
if (pfd)
|
if (pfd)
|
||||||
unlink(pidfile);
|
unlink(pidfile);
|
||||||
if (locked)
|
if (locked)
|
||||||
|
@ -40,12 +40,16 @@ static char sccsid[] = "@(#)uucplock.c 8.1 (Berkeley) 6/6/93";
|
|||||||
#include <sys/dir.h>
|
#include <sys/dir.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define _PATH_LOCKDIRNAME "/var/spool/lock/LCK..%s"
|
#define _PATH_LOCKDIRNAME "/var/spool/lock/LCK..%s"
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
static int put_pid (int fd, int pid);
|
static int put_pid (int fd, pid_t pid);
|
||||||
static int get_pid (int fd);
|
static pid_t get_pid (int fd);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* uucp style locking routines
|
* uucp style locking routines
|
||||||
@ -53,11 +57,11 @@ static int get_pid (int fd);
|
|||||||
* -1 - failure
|
* -1 - failure
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uu_lock (char *ttyname)
|
int uu_lock (char *ttyname)
|
||||||
{
|
{
|
||||||
int fd, pid;
|
int fd;
|
||||||
|
pid_t pid;
|
||||||
char tbuf[sizeof(_PATH_LOCKDIRNAME) + MAXNAMLEN];
|
char tbuf[sizeof(_PATH_LOCKDIRNAME) + MAXNAMLEN];
|
||||||
off_t lseek();
|
|
||||||
|
|
||||||
(void)sprintf(tbuf, _PATH_LOCKDIRNAME, ttyname);
|
(void)sprintf(tbuf, _PATH_LOCKDIRNAME, ttyname);
|
||||||
fd = open(tbuf, O_RDWR|O_CREAT|O_EXCL, 0660);
|
fd = open(tbuf, O_RDWR|O_CREAT|O_EXCL, 0660);
|
||||||
@ -71,9 +75,9 @@ uu_lock (char *ttyname)
|
|||||||
syslog(LOG_ERR, "lock open: %m");
|
syslog(LOG_ERR, "lock open: %m");
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
if (get_pid (fd) == -1) {
|
if ((pid = get_pid (fd)) == -1) {
|
||||||
(void)close(fd);
|
|
||||||
syslog(LOG_ERR, "lock read: %m");
|
syslog(LOG_ERR, "lock read: %m");
|
||||||
|
(void)close(fd);
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,24 +90,24 @@ uu_lock (char *ttyname)
|
|||||||
* we'll lock it ourselves
|
* we'll lock it ourselves
|
||||||
*/
|
*/
|
||||||
if (lseek(fd, 0L, L_SET) < 0) {
|
if (lseek(fd, 0L, L_SET) < 0) {
|
||||||
(void)close(fd);
|
|
||||||
syslog(LOG_ERR, "lock lseek: %m");
|
syslog(LOG_ERR, "lock lseek: %m");
|
||||||
|
(void)close(fd);
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
/* fall out and finish the locking process */
|
/* fall out and finish the locking process */
|
||||||
}
|
}
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
if (!put_pid (fd, pid)) {
|
if (!put_pid (fd, pid)) {
|
||||||
|
syslog(LOG_ERR, "lock write: %m");
|
||||||
(void)close(fd);
|
(void)close(fd);
|
||||||
(void)unlink(tbuf);
|
(void)unlink(tbuf);
|
||||||
syslog(LOG_ERR, "lock write: %m");
|
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
(void)close(fd);
|
(void)close(fd);
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uu_unlock (char *ttyname)
|
int uu_unlock (char *ttyname)
|
||||||
{
|
{
|
||||||
char tbuf[sizeof(_PATH_LOCKDIRNAME) + MAXNAMLEN];
|
char tbuf[sizeof(_PATH_LOCKDIRNAME) + MAXNAMLEN];
|
||||||
|
|
||||||
@ -111,19 +115,20 @@ uu_unlock (char *ttyname)
|
|||||||
return(unlink(tbuf));
|
return(unlink(tbuf));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int put_pid (int fd, int pid)
|
static int put_pid (int fd, pid_t pid)
|
||||||
{
|
{
|
||||||
char buf [32];
|
char buf [32];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
len = sprintf (buf, "%10ld\n", (long) pid);
|
len = sprintf (buf, "%10ld\n", pid);
|
||||||
return write (fd, buf, len) == len;
|
return write (fd, buf, len) == len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_pid (int fd)
|
static pid_t get_pid (int fd)
|
||||||
{
|
{
|
||||||
int bytes_read, pid;
|
int bytes_read;
|
||||||
char buf [32];
|
char buf [32];
|
||||||
|
pid_t pid;
|
||||||
|
|
||||||
bytes_read = read (fd, buf, sizeof (buf) - 1);
|
bytes_read = read (fd, buf, sizeof (buf) - 1);
|
||||||
if (bytes_read > 0) {
|
if (bytes_read > 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user