Explorar o código

看门狗支持读状态

qidong.liu hai 3 semanas
pai
achega
19d540f1b2
Modificáronse 1 ficheiros con 13 adicións e 3 borrados
  1. 13 3
      watchdog.c

+ 13 - 3
watchdog.c

@@ -277,8 +277,8 @@ static ssize_t watchdog_read(struct file *file, char __user *user_buf,
 	char status_buf[64];
 	int len;
 	
-	if (*ppos > 0)
-		return 0;
+	// if (*ppos > 0)
+	// 	return 0;
 	
 	mutex_lock(&watchdog_mutex);
 	if (watchdog_state)
@@ -287,12 +287,22 @@ static ssize_t watchdog_read(struct file *file, char __user *user_buf,
 	else
 		len = snprintf(status_buf, sizeof(status_buf),
 			       "The watchdog is off\nThe args value is 0\n");
+	memset(status_buf, 0, sizeof(status_buf));
+	if( watchdog_state == 1)
+	{
+		status_buf[0] = '1';
+	}
+	else
+	{
+	    status_buf[0] = '0';
+	}
+	len = 1;
 	mutex_unlock(&watchdog_mutex);
 	
 	if (copy_to_user(user_buf, status_buf, len))
 		return -EFAULT;
 	
-	*ppos += len;
+	// *ppos += len;
 	return len;
 }