리눅스 read_write.c 수정

gag2012의 이미지

안녕하세요 리눅스 공부 중인 대학생입니다.

현재 fs/read_write.c에서

sys_write 시스템콜을 변경해서

write함수가 호출 됐을 때

asmlinkage ssize_t sys_write(unsigned int fd, const cht __user * buf, size_t count)
{
        printk("Test from read_write.c\n");
	struct file * file;
	ssize_t ret = -EBADF;
	int fput_needed;
 
	file = fget_light(fd, &fput_needed);
	if(file) {
             loff_t pos = file_pos_read(file);
             ret = vfs_write(file, buf, count, &pos);
             file_pos_write(file, buf, count, &pos);
             fput_light(file, fput_needed);
	}
 
	return ret;
}

위의 함수가 실행되는 걸로 알고있습니다.

그래서 위 함수가 실행되는지 확인하고 싶어서 다음과 같이

        printk("Test from read_write.c\n");

printk를 위 함수 내에 넣었습니다. (맨위에)

그리고 bzImage를 컴파일하고 리부팅을 했습니다.

이후, /proc/sys/kernel/printk 에서 1 4 1 7 을 8 4 1 7 로 바꾸어주었습니다.

그리고 일정 코드를 실행했습니다.

#include <stdio.h>
 
int main(){
 
       printf("hello");
       return 0;
}

그런데 제가 예상한 것은 이를 실행했을 때 printf 함수가 실행되니

Test from read_write.c
hello

이렇게 찍혀야하는데

Test from read_write
Test from read_write
Test from read_write
Test from read_write

와 같이 반복해서 무한으로 화면에 출력됩니다.

이유가 뭘까요?

허접한 질문 죄송합니다.

세벌의 이미지

ssize_t sys_write 가 계속 호출되는 건 아닌지요?

shint의 이미지


- 일단. 옵션 값이 다르네요. ㅇ_ㅇ;;
1234 / 01234567

//---------------------------------
printk 로그 레벨 설정
https://cafe.naver.com/newchany/701

커널프로그래밍 모듈올리기 sys_open,sys_write,proc사용하기 ++Linux Net Prog++
https://blog.naver.com/corona78/30013176172

[Linux] 커널 메세지 출력(printk log level) 및 수정 방법 정리 Uboot, Linux
https://blog.naver.com/daetery/220986021601

커널메시지 출력 함수(printk) 로그 레벨
http://sisyphus13.tistory.com/entry/커널메시지-출력-함수printk-로그-레벨

http://ok2513.tistory.com/9

printk log level 설정 Linux / Android / Embedded System
http://blog.naver.com/PostView.nhn?blogId=agnazz&logNo=100122290010&categoryNo=40&viewDate=&currentPage=1&listtype=0

커널 메세지 콘솔로 안나오게 하려면....?
https://kldp.org/node/50970

http://kkangstory.tistory.com/entry/LDD-커널-메시지-출미미미

http://uniwide.kr/18

//------------------------------
Description of fget_light and fput_light
http://vikasjadhav-lkp.blogspot.com/2012/04/description-of-fgetlight-and-fputlight.html

http://gh0stsp1der.tistory.com/24

What does fget_light in Linux work?
https://stackoverflow.com/questions/12751167/what-does-fget-light-in-linux-work

----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.

매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.

각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.