mesh_driver/lunix-attach.c
static int tty_lock(char *path, int mode)
{
	int fd;
	int ret;
	char apid[16];
	struct passwd *pw;
	static int saved_lock = 0;
	static char saved_path[PATH_MAX];

	/* We do not lock standard input. */
	if (mode == 1) {	/* lock */
		sprintf(saved_path, "%s/LCK..%s", _PATH_LOCKD, path);
		if (tty_already_locked(saved_path)) {
			fprintf(stderr, "/dev/%s already locked\n", path);
			return -1;
		}
		if ((fd = creat(saved_path, 0644)) < 0) {
			if (errno != EEXIST) {
				fprintf(stderr, "tty_lock: (%s): %s\n",
						saved_path, strerror(errno));
			}
			return -1;
		}
		sprintf(apid, "%10d\n", getpid());
		if ((ret = write(fd, apid, strlen(apid))) != strlen(apid)) {
			fprintf(stderr, "write to PID file incomplete, ret = %d\n", ret);
			close(fd);
			unlink(saved_path);
			return -1;
		}
		(void) close(fd);

		/* Make sure UUCP owns the lockfile.  Required by some packages. */
		if ((pw = getpwnam(_UID_UUCP)) == NULL) {
			fprintf(stderr, "tty_lock: UUCP user %s unknown\n", _UID_UUCP);
			return 0;
		}
		(void) chown(saved_path, pw->pw_uid, pw->pw_gid);
		saved_lock = 1;
	} else {	/* unlock */
		if (saved_lock != 1)
			return 0;
		if (unlink(saved_path) < 0) {
			fprintf(stderr, "tty_unlock: (%s): %s\n",
				saved_path, strerror(errno));
			return -1;
		}
		saved_lock = 0;
	}
	
	return 0;
}
/* Lock or unlock a terminal line. */
Lock or unlock a terminal line.
Lock or unlock a terminal line .
static int tty_lock(char *path, int mode)
{
	int fd;
	int ret;
	char apid[16];
	struct passwd *pw;
	static int saved_lock = 0;
	static char saved_path[PATH_MAX];
	if (mode == 1) {	
		sprintf(saved_path, "%s/LCK..%s", _PATH_LOCKD, path);
		if (tty_already_locked(saved_path)) {
			fprintf(stderr, "/dev/%s already locked\n", path);
			return -1;
		}
		if ((fd = creat(saved_path, 0644)) < 0) {
			if (errno != EEXIST) {
				fprintf(stderr, "tty_lock: (%s): %s\n",
						saved_path, strerror(errno));
			}
			return -1;
		}
		sprintf(apid, "%10d\n", getpid());
		if ((ret = write(fd, apid, strlen(apid))) != strlen(apid)) {
			fprintf(stderr, "write to PID file incomplete, ret = %d\n", ret);
			close(fd);
			unlink(saved_path);
			return -1;
		}
		(void) close(fd);
		if ((pw = getpwnam(_UID_UUCP)) == NULL) {
			fprintf(stderr, "tty_lock: UUCP user %s unknown\n", _UID_UUCP);
			return 0;
		}
		(void) chown(saved_path, pw->pw_uid, pw->pw_gid);
		saved_lock = 1;
	} else {	
		if (saved_lock != 1)
			return 0;
		if (unlink(saved_path) < 0) {
			fprintf(stderr, "tty_unlock: (%s): %s\n",
				saved_path, strerror(errno));
			return -1;
		}
		saved_lock = 0;
	}
	return 0;
}
static int tty_lock ( char * path , int mode ) { int fd ; int ret ; char apid [ 16 ] ; struct passwd * pw ; static int saved_lock = 0 ; static char saved_path [ PATH_MAX ] ; if ( mode == 1 ) { sprintf ( saved_path , " " , _PATH_LOCKD , path ) ; if ( tty_already_locked ( saved_path ) ) { fprintf ( stderr , " \n " , path ) ; return -1 ; } if ( ( fd = creat ( saved_path , 0644 ) ) < 0 ) { if ( errno != EEXIST ) { fprintf ( stderr , " \n " , saved_path , strerror ( errno ) ) ; } return -1 ; } sprintf ( apid , " \n " , getpid ( ) ) ; if ( ( ret = write ( fd , apid , strlen ( apid ) ) ) != strlen ( apid ) ) { fprintf ( stderr , " \n " , ret ) ; close ( fd ) ; unlink ( saved_path ) ; return -1 ; } ( void ) close ( fd ) ; if ( ( pw = getpwnam ( _UID_UUCP ) ) == NULL ) { fprintf ( stderr , " \n " , _UID_UUCP ) ; return 0 ; } ( void ) chown ( saved_path , pw -> pw_uid , pw -> pw_gid ) ; saved_lock = 1 ; } else { if ( saved_lock != 1 ) return 0 ; if ( unlink ( saved_path ) < 0 ) { fprintf ( stderr , " \n " , saved_path , strerror ( errno ) ) ; return -1 ; } saved_lock = 0 ; } return 0 ; }
Lock or unlock a terminal line.
Lock or unlock a terminal line .
/* We do not lock standard input. */ /* lock */ /* Make sure UUCP owns the lockfile.  Required by some packages. */ /* unlock */