Beispiel #1
0
void jack_raw_output::stop ()
{
    check_running ();
    jack_deactivate (_client);
    set_state (async_state::idle);
}
Beispiel #2
0
/* This function creates a lock file.
 * Return values:
 *	TRUE:		Successful.
 *	FALSE:		The locker process died.
 *	-1:			No permission to lock.
 */
static	int
create_lock_file(char *lock_file,char *sn_host,char *sn_pid)
{
	int	fd;
	char	status_buf[500];
	int	status_len;
	int	write_ret;

	/* It is importan, that the pid is expanded with 0
	 * because the zeros are space holders.
	 */
	sprintf(status_buf,"%s %s %7lu\n",
		sn_pid,
		sn_host,
		(unsigned long)getpid());
	status_len = strlen(status_buf);

	while (!killed)
	{
		/* Check whether we can create the file! */
		if ((fd = open(lock_file,O_RDWR|O_CREAT|O_EXCL,0666)) == -1)
		{
			if (errno == EINTR)		/* Interrupted ? */
				continue;
			if (errno != EEXIST)
			{						/* Even the file does not exist, it */
				return -1;			/* was not possible to create it. */
			}

			switch (check_running(lock_file))
			{
			case TRUE:
				/* Lets try it again! */
#if TTY_TRACE
				if (tty)
					fprintf(tty,"trying %d\n",(int)getpid());
#endif /* TTY_TRACE */
				sleep(1);
				break;

			case FALSE:
#if TTY_TRACE
				if (tty)
					fprintf(tty,"removing lock file %d\n",(int)getpid());
#endif /* TTY_TRACE */
				unlink(lock_file);
				break;

			case -1:		/* The locker process died. */
#if TTY_TRACE
				if (tty)
					fprintf(tty,"The locker process died.\n");
#endif /* TTY_TRACE */
				return FALSE;
				break;
			}
			continue;
		}

		/* We could create the file, now we write into it. */
		write_ret = write(fd,status_buf,status_len);
		if (write_ret == -1)
			return -1;
		if (write_ret == status_len)
		{
			char	read_buf[1000];

			lseek(fd,(off_t)0,SEEK_SET);		/* Rewind ! */

			if (read(fd,read_buf,sizeof(read_buf)) == status_len &&
				memcmp(status_buf,read_buf,status_len) == 0)
			{
				close(fd);

#if TTY_TRACE
				if (tty)
					fprintf(tty,"Lock created %d.\n",(int)getpid());
#endif /* TTY_TRACE */
				return TRUE;	/* We read what we wrote. */
			}
		}
		/* Lets try it again! */
#if TTY_TRACE
		if (tty)
			fprintf(tty,"Trying again %d...\n",(int)getpid());
#endif /* TTY_TRACE */
		sleep(1);
	}

	return FALSE;		/* Reached, only when killed. */
}