patch-2.1.68 linux/fs/autofs/waitq.c

Next file: linux/fs/buffer.c
Previous file: linux/drivers/sound/pss.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.67/linux/fs/autofs/waitq.c linux/fs/autofs/waitq.c
@@ -42,30 +42,34 @@
 
 static int autofs_write(struct file *file, const void *addr, int bytes)
 {
-	unsigned long fs;
-	unsigned long old_signal;
+	unsigned long fs, sigpipe, flags;
 	const char *data = (const char *)addr;
-	int written = 0;
+	ssize_t wr = 0;
 
 	/** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
 
+	sigpipe = sigismember(&current->signal, SIGPIPE);
+
 	/* Save pointer to user space and point back to kernel space */
 	fs = get_fs();
 	set_fs(KERNEL_DS);
 
-	old_signal = current->signal;
-
-	while ( bytes && (written = file->f_op->write(file,data,bytes,&file->f_pos)) > 0 ) {
-		data += written;
-		bytes -= written;
+	while (bytes &&
+	       (wr = file->f_op->write(file,data,bytes,&file->f_pos)) > 0) {
+		data += wr;
+		bytes -= wr;
 	}
 
-	if ( written == -EPIPE && !(old_signal & (1 << (SIGPIPE-1))) ) {
-		/* Keep the currently executing process from receiving a
-		   SIGPIPE unless it was already supposed to get one */
-		current->signal &= ~(1 << (SIGPIPE-1));
-	}
 	set_fs(fs);
+
+	/* Keep the currently executing process from receiving a
+	   SIGPIPE unless it was already supposed to get one */
+	if (wr == -EPIPE && !sigpipe) {
+		spin_lock_irqsave(&current->sigmask_lock, flags);
+		sigdelset(&current->signal, SIGPIPE);
+		recalc_sigpending(current);
+		spin_unlock_irqrestore(&current->sigmask_lock, flags);
+	}
 
 	return (bytes > 0);
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov