mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	use fstat when we can
This avoids having things change between the stat and open.
This commit is contained in:
		
							parent
							
								
									45c62dfde6
								
							
						
					
					
						commit
						ff4a314022
					
				
					 2 changed files with 18 additions and 21 deletions
				
			
		| 
						 | 
					@ -59,21 +59,7 @@ int spa_v4l2_open(struct spa_v4l2_device *dev, const char *path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_log_debug(dev->log, "v4l2: Playback device is '%s'", path);
 | 
						spa_log_debug(dev->log, "v4l2: Playback device is '%s'", path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (stat(path, &st) < 0) {
 | 
					 | 
				
			||||||
		err = errno;
 | 
					 | 
				
			||||||
		spa_log_error(dev->log, "v4l2: Cannot identify '%s': %d, %s",
 | 
					 | 
				
			||||||
				path, err, strerror(err));
 | 
					 | 
				
			||||||
		goto error;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (!S_ISCHR(st.st_mode)) {
 | 
					 | 
				
			||||||
		spa_log_error(dev->log, "v4l2: %s is no device", path);
 | 
					 | 
				
			||||||
		err = ENODEV;
 | 
					 | 
				
			||||||
		goto error;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	dev->fd = open(path, O_RDWR | O_NONBLOCK, 0);
 | 
						dev->fd = open(path, O_RDWR | O_NONBLOCK, 0);
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (dev->fd == -1) {
 | 
						if (dev->fd == -1) {
 | 
				
			||||||
		err = errno;
 | 
							err = errno;
 | 
				
			||||||
		spa_log_error(dev->log, "v4l2: Cannot open '%s': %d, %s",
 | 
							spa_log_error(dev->log, "v4l2: Cannot open '%s': %d, %s",
 | 
				
			||||||
| 
						 | 
					@ -81,6 +67,19 @@ int spa_v4l2_open(struct spa_v4l2_device *dev, const char *path)
 | 
				
			||||||
		goto error;
 | 
							goto error;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (fstat(dev->fd, &st) < 0) {
 | 
				
			||||||
 | 
							err = errno;
 | 
				
			||||||
 | 
							spa_log_error(dev->log, "v4l2: Cannot identify '%s': %d, %s",
 | 
				
			||||||
 | 
									path, err, strerror(err));
 | 
				
			||||||
 | 
							goto error_close;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!S_ISCHR(st.st_mode)) {
 | 
				
			||||||
 | 
							spa_log_error(dev->log, "v4l2: %s is no device", path);
 | 
				
			||||||
 | 
							err = ENODEV;
 | 
				
			||||||
 | 
							goto error_close;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (xioctl(dev->fd, VIDIOC_QUERYCAP, &dev->cap) < 0) {
 | 
						if (xioctl(dev->fd, VIDIOC_QUERYCAP, &dev->cap) < 0) {
 | 
				
			||||||
		err = errno;
 | 
							err = errno;
 | 
				
			||||||
		spa_log_error(dev->log, "v4l2: '%s' QUERYCAP: %m", path);
 | 
							spa_log_error(dev->log, "v4l2: '%s' QUERYCAP: %m", path);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -139,17 +139,15 @@ static int open_read(struct midi_file *mf, const char *filename, struct midi_fil
 | 
				
			||||||
	uint16_t i;
 | 
						uint16_t i;
 | 
				
			||||||
	struct stat st;
 | 
						struct stat st;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (stat(filename, &st) < 0) {
 | 
					 | 
				
			||||||
		res = -errno;
 | 
					 | 
				
			||||||
		goto exit;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	mf->size = st.st_size;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if ((mf->fd = open(filename, O_RDONLY)) < 0) {
 | 
						if ((mf->fd = open(filename, O_RDONLY)) < 0) {
 | 
				
			||||||
		res = -errno;
 | 
							res = -errno;
 | 
				
			||||||
		goto exit;
 | 
							goto exit;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if (fstat(mf->fd, &st) < 0) {
 | 
				
			||||||
 | 
							res = -errno;
 | 
				
			||||||
 | 
							goto exit_close;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						mf->size = st.st_size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mf->data = mmap(NULL, mf->size, PROT_READ, MAP_SHARED, mf->fd, 0);
 | 
						mf->data = mmap(NULL, mf->size, PROT_READ, MAP_SHARED, mf->fd, 0);
 | 
				
			||||||
	if (mf->data == MAP_FAILED) {
 | 
						if (mf->data == MAP_FAILED) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue