head 1.3; access; symbols pkgsrc-2026Q1:1.3.0.98 pkgsrc-2026Q1-base:1.3 pkgsrc-2025Q4:1.3.0.96 pkgsrc-2025Q4-base:1.3 pkgsrc-2025Q3:1.3.0.94 pkgsrc-2025Q3-base:1.3 pkgsrc-2025Q2:1.3.0.92 pkgsrc-2025Q2-base:1.3 pkgsrc-2025Q1:1.3.0.90 pkgsrc-2025Q1-base:1.3 pkgsrc-2024Q4:1.3.0.88 pkgsrc-2024Q4-base:1.3 pkgsrc-2024Q3:1.3.0.86 pkgsrc-2024Q3-base:1.3 pkgsrc-2024Q2:1.3.0.84 pkgsrc-2024Q2-base:1.3 pkgsrc-2024Q1:1.3.0.82 pkgsrc-2024Q1-base:1.3 pkgsrc-2023Q4:1.3.0.80 pkgsrc-2023Q4-base:1.3 pkgsrc-2023Q3:1.3.0.78 pkgsrc-2023Q3-base:1.3 pkgsrc-2023Q2:1.3.0.76 pkgsrc-2023Q2-base:1.3 pkgsrc-2023Q1:1.3.0.74 pkgsrc-2023Q1-base:1.3 pkgsrc-2022Q4:1.3.0.72 pkgsrc-2022Q4-base:1.3 pkgsrc-2022Q3:1.3.0.70 pkgsrc-2022Q3-base:1.3 pkgsrc-2022Q2:1.3.0.68 pkgsrc-2022Q2-base:1.3 pkgsrc-2022Q1:1.3.0.66 pkgsrc-2022Q1-base:1.3 pkgsrc-2021Q4:1.3.0.64 pkgsrc-2021Q4-base:1.3 pkgsrc-2021Q3:1.3.0.62 pkgsrc-2021Q3-base:1.3 pkgsrc-2021Q2:1.3.0.60 pkgsrc-2021Q2-base:1.3 pkgsrc-2021Q1:1.3.0.58 pkgsrc-2021Q1-base:1.3 pkgsrc-2020Q4:1.3.0.56 pkgsrc-2020Q4-base:1.3 pkgsrc-2020Q3:1.3.0.54 pkgsrc-2020Q3-base:1.3 pkgsrc-2020Q2:1.3.0.50 pkgsrc-2020Q2-base:1.3 pkgsrc-2020Q1:1.3.0.30 pkgsrc-2020Q1-base:1.3 pkgsrc-2019Q4:1.3.0.52 pkgsrc-2019Q4-base:1.3 pkgsrc-2019Q3:1.3.0.48 pkgsrc-2019Q3-base:1.3 pkgsrc-2019Q2:1.3.0.46 pkgsrc-2019Q2-base:1.3 pkgsrc-2019Q1:1.3.0.44 pkgsrc-2019Q1-base:1.3 pkgsrc-2018Q4:1.3.0.42 pkgsrc-2018Q4-base:1.3 pkgsrc-2018Q3:1.3.0.40 pkgsrc-2018Q3-base:1.3 pkgsrc-2018Q2:1.3.0.38 pkgsrc-2018Q2-base:1.3 pkgsrc-2018Q1:1.3.0.36 pkgsrc-2018Q1-base:1.3 pkgsrc-2017Q4:1.3.0.34 pkgsrc-2017Q4-base:1.3 pkgsrc-2017Q3:1.3.0.32 pkgsrc-2017Q3-base:1.3 pkgsrc-2017Q2:1.3.0.28 pkgsrc-2017Q2-base:1.3 pkgsrc-2017Q1:1.3.0.26 pkgsrc-2017Q1-base:1.3 pkgsrc-2016Q4:1.3.0.24 pkgsrc-2016Q4-base:1.3 pkgsrc-2016Q3:1.3.0.22 pkgsrc-2016Q3-base:1.3 pkgsrc-2016Q2:1.3.0.20 pkgsrc-2016Q2-base:1.3 pkgsrc-2016Q1:1.3.0.18 pkgsrc-2016Q1-base:1.3 pkgsrc-2015Q4:1.3.0.16 pkgsrc-2015Q4-base:1.3 pkgsrc-2015Q3:1.3.0.14 pkgsrc-2015Q3-base:1.3 pkgsrc-2015Q2:1.3.0.12 pkgsrc-2015Q2-base:1.3 pkgsrc-2015Q1:1.3.0.10 pkgsrc-2015Q1-base:1.3 pkgsrc-2014Q4:1.3.0.8 pkgsrc-2014Q4-base:1.3 pkgsrc-2014Q3:1.3.0.6 pkgsrc-2014Q3-base:1.3 pkgsrc-2014Q2:1.3.0.4 pkgsrc-2014Q2-base:1.3 pkgsrc-2014Q1:1.3.0.2 pkgsrc-2014Q1-base:1.3 pkgsrc-2013Q4:1.2.0.4 pkgsrc-2013Q4-base:1.2 pkgsrc-2013Q3:1.2.0.2 pkgsrc-2013Q3-base:1.2 pkgsrc-2013Q2:1.1.0.62 pkgsrc-2013Q2-base:1.1 pkgsrc-2013Q1:1.1.0.60 pkgsrc-2013Q1-base:1.1 pkgsrc-2012Q4:1.1.0.58 pkgsrc-2012Q4-base:1.1 pkgsrc-2012Q3:1.1.0.56 pkgsrc-2012Q3-base:1.1 pkgsrc-2012Q2:1.1.0.54 pkgsrc-2012Q2-base:1.1 pkgsrc-2012Q1:1.1.0.52 pkgsrc-2012Q1-base:1.1 pkgsrc-2011Q4:1.1.0.50 pkgsrc-2011Q4-base:1.1 pkgsrc-2011Q3:1.1.0.48 pkgsrc-2011Q3-base:1.1 pkgsrc-2011Q2:1.1.0.46 pkgsrc-2011Q2-base:1.1 pkgsrc-2011Q1:1.1.0.44 pkgsrc-2011Q1-base:1.1 pkgsrc-2010Q4:1.1.0.42 pkgsrc-2010Q4-base:1.1 pkgsrc-2010Q3:1.1.0.40 pkgsrc-2010Q3-base:1.1 pkgsrc-2010Q2:1.1.0.38 pkgsrc-2010Q2-base:1.1 pkgsrc-2010Q1:1.1.0.36 pkgsrc-2010Q1-base:1.1 pkgsrc-2009Q4:1.1.0.34 pkgsrc-2009Q4-base:1.1 pkgsrc-2009Q3:1.1.0.32 pkgsrc-2009Q3-base:1.1 pkgsrc-2009Q2:1.1.0.30 pkgsrc-2009Q2-base:1.1 pkgsrc-2009Q1:1.1.0.28 pkgsrc-2009Q1-base:1.1 pkgsrc-2008Q4:1.1.0.26 pkgsrc-2008Q4-base:1.1 pkgsrc-2008Q3:1.1.0.24 pkgsrc-2008Q3-base:1.1 cube-native-xorg:1.1.0.22 cube-native-xorg-base:1.1 pkgsrc-2008Q2:1.1.0.20 pkgsrc-2008Q2-base:1.1 cwrapper:1.1.0.18 pkgsrc-2008Q1:1.1.0.16 pkgsrc-2008Q1-base:1.1 pkgsrc-2007Q4:1.1.0.14 pkgsrc-2007Q4-base:1.1 pkgsrc-2007Q3:1.1.0.12 pkgsrc-2007Q3-base:1.1 pkgsrc-2007Q2:1.1.0.10 pkgsrc-2007Q2-base:1.1 pkgsrc-2007Q1:1.1.0.8 pkgsrc-2007Q1-base:1.1 pkgsrc-2006Q4:1.1.0.6 pkgsrc-2006Q4-base:1.1 pkgsrc-2006Q3:1.1.0.4 pkgsrc-2006Q3-base:1.1 pkgsrc-2006Q2:1.1.0.2 pkgsrc-2006Q2-base:1.1; locks; strict; comment @# @; 1.3 date 2014.03.06.15.44.21; author joerg; state Exp; branches; next 1.2; commitid sZNIsGftF6UuAErx; 1.2 date 2013.09.10.14.26.49; author joerg; state Exp; branches; next 1.1; commitid m8QZAji1uj6yQT4x; 1.1 date 2006.06.30.16.17.27; author tron; state Exp; branches; next ; desc @@ 1.3 log @Drop pointless pointer compare. @ text @$NetBSD: patch-ab,v 1.2 2013/09/10 14:26:49 joerg Exp $ --- tty.c.orig 1995-06-30 23:41:05.000000000 +0000 +++ tty.c @@@@ -140,9 +140,10 @@@@ int tty_nomesg ( void ) int tty_lock ( char *path, int mode ) { +#define MAX_LOCK_ATTEMPTS 3 struct passwd *pw; - - int fd; + char number[12], *temp_path; + int fd, i, saved_errno; if ( mode ) /* locking on ? */ @@@@ -152,32 +153,71 @@@@ int tty_lock ( char *path, int mode ) return 0; /* standard input */ } - if ( saved_path != NULL ) + temp_path = (char*) malloc ( sizeof ( PATH_LOCKD ) + + strlen("TMP..") + 10); /* max PID */ + + (void) sprintf ( number, "%u", (unsigned)getpid() ); + (void) strcpy ( temp_path, PATH_LOCKD ); + (void) strcat ( temp_path, "TMP.." ); + (void) strcat ( temp_path, number ); + + if ( opt_debg ) + printf ( "DIP: tty: trying to create lock temp file %s\n", temp_path ); + if ( ( fd = open ( temp_path, O_CREAT|O_TRUNC|O_WRONLY, 0644 ) ) < 0) { - free ( saved_path ); - saved_path = NULL; + (void) fprintf ( stderr, "DIP: tty: lock: (%s): %s\n", + temp_path, strerror ( errno ) ); + free(temp_path); + return -1; } + /* + * now enter our PID; + * Note: the 10 digits + newline are convention and cannot be changed + */ + (void) sprintf ( number, "%10u\n", getpid() ); + if ( opt_debg ) + printf ( "DIP: tty: writing \"%10u\" into lock temp file\n", getpid() ); + if ( write (fd, number, 11) != 11 ) + { + (void) fprintf ( stderr, "DIP: tty: lock write error: %s\n", + strerror ( errno ) ); + free(temp_path); + return -1; + } + (void) close ( fd ); + + free ( saved_path ); /* just in case [NB: free(NULL) is legal] */ saved_path = (char*) malloc ( sizeof ( PATH_LOCKD ) + - strlen ( path ) + 1 ); + strlen ( path ) + 3 ); (void) strcpy ( saved_path, PATH_LOCKD ); + (void) strcat ( saved_path, ".." ); (void) strcat ( saved_path, path ); - - if ( ( fd = creat ( saved_path, 0644 ) ) < 0) - { - if ( errno != EEXIST ) + if ( opt_debg ) + printf ( "DIP: tty: linking %s to %s\n", temp_path, saved_path ); + for ( i = 0; i < MAX_LOCK_ATTEMPTS; i++ ) { - (void) fprintf ( stderr, "DIP: tty: lock: (%s): %s\n", - saved_path, strerror ( errno ) ); + /* now attempt to actually get the lock */ + if ( link ( temp_path, saved_path ) == 0 ) + break; + sleep(2 * (i + 1)); + } + saved_errno = errno; + (void) unlink ( temp_path ); + free(temp_path); + + if ( i >= MAX_LOCK_ATTEMPTS ) + { + /* did not get it */ + if ( saved_errno != EEXIST ) + (void) fprintf ( stderr, "DIP: tty: lock: (%s): %s\n", + saved_path, strerror ( saved_errno ) ); + else if ( opt_debg ) + printf ( "DIP: tty: lock attempt failed, EEXIST\n" ); + return -1; } - - return -1; - } - - (void) close ( fd ); - /* * Make sure UUCP owns the lockfile. Required by some packages. @@@@ -215,7 +255,26 @@@@ int tty_lock ( char *path, int mode ) return 0; } +/* + * Enter daemon's PID into the lock file; + * This is icky. + */ +void tty_relock ( void ) +{ + int fd; + char number[12]; + if ( saved_path == NULL ) + return; + + (void) sprintf ( number, "%10u\n", (unsigned)getpid() ); + if ( opt_debg ) + printf ( "DIP: tty: rewriting lock file (PID = %u)\n", getpid() ); + if ( (fd = open ( saved_path, O_WRONLY, 0 )) == -1 ) + return; + (void) write ( fd, number, 11); + (void) close ( fd ); +} /* * Find a serial speed code in the table. @@@@ -482,7 +541,7 @@@@ int tty_set_disc ( int disc ) } - if ( ( disc == SLIPDISC ) ) + if ( disc == SLIPDISC ) { int tmp_unit = -1; @@@@ -965,7 +1024,6 @@@@ int tty_open ( char *name ) char *sp; char path [ MAXPATHLEN ]; - /* * Try opening the TTY device. */ @@@@ -985,8 +1043,10 @@@@ int tty_open ( char *name ) else sp = name; - - if ( ( fd = open ( path, O_RDWR | O_NONBLOCK ) ) < 0 ) + if ( tty_lock ( sp, 1 ) == -1 ) + return -1; + + if ( ( fd = open ( path, O_RDWR | O_NONBLOCK | O_EXCL ) ) < 0 ) { (void) fprintf ( stderr, "DIP: tty: open(%s, RW): %s\n", path, strerror ( errno ) ); @@@@ -1080,8 +1140,7 @@@@ int tty_open ( char *name ) /* * If we are running in MASTER mode, set the default speed. */ - if ( ( path != NULL ) - && ( tty_set_speed ( &tty_current, "9600" ) != 0 ) ) + if ( ( tty_set_speed ( &tty_current, "9600" ) != 0 ) ) { (void) fprintf ( stderr, "DIP: tty: open: cannot set 9600 bps!\n" ); @@@@ -1118,10 +1177,5 @@@@ int tty_open ( char *name ) { return 0 ; } - - - /* - * OK, all done. Lock this terminal line. - */ - return tty_lock ( sp, 1 ); + return 0; } @ 1.2 log @Split patch. Add missing return. Fix cast away of value. @ text @d1 1 a1 1 $NetBSD: patch-ab,v 1.1 2006/06/30 16:17:27 tron Exp $ d163 11 a173 1 @@@@ -1118,10 +1178,5 @@@@ int tty_open ( char *name ) @ 1.1 log @Move "bsddip" package to "bsddip" directory. @ text @d1 1 a1 1 $NetBSD: patch-ab,v 1.2 1998/08/07 11:10:38 agc Exp $ d3 3 a5 3 --- tty.c.orig Sat Jul 1 01:41:05 1995 +++ tty.c Sat Sep 9 08:37:14 1995 @@@@ -140,9 +140,10 @@@@ d18 1 a18 1 @@@@ -152,32 +153,71 @@@@ d106 1 a106 1 @@@@ -215,7 +255,26 @@@@ d133 10 a142 1 @@@@ -965,7 +1024,6 @@@@ d150 1 a150 1 @@@@ -985,8 +1043,10 @@@@ d163 1 a163 1 @@@@ -1118,10 +1178,4 @@@@ d173 1 a174 11 --- daemon.c.orig Sat Jul 1 01:41:05 1995 +++ daemon.c Sat Sep 9 08:20:00 1995 @@@@ -168,6 +168,8 @@@@ openlog ( "DIP", LOG_PID, LOG_DAEMON ); } + /* note the race condition here; ick! */ + tty_relock(); (void) signal ( SIGALRM, sig_catcher ); (void) alarm ( mydip.timeout ); @