소스 검색

看门狗支持读状态

qidong.liu 3 주 전
부모
커밋
19d540f1b2
1개의 변경된 파일13개의 추가작업 그리고 3개의 파일을 삭제
  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;
 }