{"id":4981,"date":"2025-11-07T18:09:08","date_gmt":"2025-11-07T17:09:08","guid":{"rendered":"https:\/\/workboot.fr\/ciela\/?page_id=4981"},"modified":"2025-11-07T18:32:21","modified_gmt":"2025-11-07T17:32:21","slug":"rpi-module","status":"publish","type":"page","link":"https:\/\/workboot.fr\/ciela\/rpi-module\/","title":{"rendered":"rpi module"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Bonjour Module<\/strong>&nbsp;est un module simple pour le noyau Linux qui a pour objectif principal de journaliser son activit\u00e9 dans un fichier texte. Il sert de d\u00e9monstration pratique pour comprendre les bases de la programmation de modules noyau sous Debian 12 (Bookworm).<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Journalisation au Chargement<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Cr\u00e9e ou ouvre le fichier&nbsp;<code>\/tmp\/bonjour.txt<\/code><\/li>\n\n\n\n<li>Ins\u00e8re le message :&nbsp;<code>\"Module charg\u00e9 - en fonction\\n\"<\/code><\/li>\n\n\n\n<li>Utilise les appels syst\u00e8me du noyau pour l&rsquo;\u00e9criture fichier<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Journalisation au D\u00e9chargement<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Rouvre le m\u00eame fichier \u00e0 la suppression du module<\/li>\n\n\n\n<li>Ajoute le message : \u00ab\u00a0Module d\u00e9charg\u00e9 &#8211; hors fonction\\n\u00a0\u00bb<\/li>\n\n\n\n<li>Garantit une trace de l&rsquo;\u00e9tat du module<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Archive du projet <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/workboot.fr\/Download\/Module\/bonjour_module.tar\">bonjour_module.tar<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">bonjour_module.c<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;linux\/init.h>\n#include &lt;linux\/module.h>\n#include &lt;linux\/kernel.h>\n#include &lt;linux\/fs.h>\n#include &lt;linux\/uaccess.h>\n\nMODULE_LICENSE(\"GPL\");\nMODULE_AUTHOR(\"Votre Nom\");\nMODULE_DESCRIPTION(\"Un module simple qui log dans \/tmp\/bonjour.txt\");\n\n\/\/ Fonction d'initialisation du module\nstatic int __init bonjour_init(void)\n{\n    struct file *fichier;\n    loff_t pos = 0;\n    char *message = \"Module charge - en fonction\\n\";\n    \n    printk(KERN_INFO \"BonjourModule: Initialisation du module\\n\");\n    \n    \/\/ Ouvrir le fichier en \u00e9criture (cr\u00e9ation si n\u00e9cessaire)\n    fichier = filp_open(\"\/tmp\/bonjour.txt\", O_WRONLY | O_CREAT | O_APPEND, 0644);\n    \n    if (IS_ERR(fichier)) {\n        printk(KERN_ERR \"BonjourModule: Erreur d'ouverture du fichier\\n\");\n        return PTR_ERR(fichier);\n    }\n    \n    \/\/ \u00c9crire dans le fichier\n    kernel_write(fichier, message, strlen(message), &amp;pos);\n    \n    \/\/ Fermer le fichier\n    filp_close(fichier, NULL);\n    \n    printk(KERN_INFO \"BonjourModule: Message ecrit dans \/tmp\/bonjour.txt\\n\");\n    \n    return 0;\n}\n\n\/\/ Fonction de nettoyage du module\nstatic void __exit bonjour_exit(void)\n{\n    struct file *fichier;\n    loff_t pos = 0;\n    char *message = \"Module decharge - hors fonction\\n\";\n    \n    printk(KERN_INFO \"BonjourModule: Dechargement du module\\n\");\n    \n    \/\/ Ouvrir le fichier en \u00e9criture\n    fichier = filp_open(\"\/tmp\/bonjour.txt\", O_WRONLY | O_APPEND, 0644);\n    \n    if (IS_ERR(fichier)) {\n        printk(KERN_ERR \"BonjourModule: Erreur d'ouverture du fichier a la sortie\\n\");\n        return;\n    }\n    \n    \/\/ \u00c9crire dans le fichier\n    kernel_write(fichier, message, strlen(message), &amp;pos);\n    \n    \/\/ Fermer le fichier\n    filp_close(fichier, NULL);\n    \n    printk(KERN_INFO \"BonjourModule: Module decharge\\n\");\n}\n\nmodule_init(bonjour_init);\nmodule_exit(bonjour_exit);<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Makefile<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>obj-m += bonjour_module.o\n\nKDIR := \/lib\/modules\/$(shell uname -r)\/build\nPWD := $(shell pwd)\n\nall:\n\t$(MAKE) -C $(KDIR) M=$(PWD) modules\n\nclean:\n\t$(MAKE) -C $(KDIR) M=$(PWD) clean\n\ninstall:\n\t$(MAKE) -C $(KDIR) M=$(PWD) modules_install<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Installation des pr\u00e9requis  , headers de fichier du noyau ,et les build-essential so pas encore mis.<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt install linux-headers-$(uname -r) build-essential\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">compilation et test<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># Compiler le module\nmake\n\n# Charger le module\nsudo insmod bonjour_module.ko\n\n# V\u00e9rifier que le module est charg\u00e9\nlsmod | grep bonjour_module\n\n# V\u00e9rifier le contenu du fichier log\ncat \/tmp\/bonjour.txt\n\n# Voir les messages du noyau\ndmesg | tail\n\n# D\u00e9charger le module\nsudo rmmod bonjour_module\n\n# V\u00e9rifier \u00e0 nouveau le fichier log\ncat \/tmp\/bonjour.txt<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Usage typique<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># Chargement manuel\nsudo insmod bonjour_module.ko\n\n# V\u00e9rification\ncat \/tmp\/bonjour.txt\ndmesg | tail\n\n# D\u00e9chargement\nsudo rmmod bonjour_module<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">mais encore<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dmesg\n..\n&#91;506409.469558] bonjour_module: loading out-of-tree module taints kernel.\n&#91;506409.472225] BonjourModule: Initialisation du module\n&#91;506409.472488] BonjourModule: Message ecrit dans \/tmp\/bonjour.txt\nbruno@work:~\/Works\/module\/bonjour_module $ <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd27 M\u00e9canismes Techniques<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Fonctions Noyau Utilis\u00e9es<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>filp_open()<\/code>\u00a0: Ouverture\/cr\u00e9ation de fichier<\/li>\n\n\n\n<li><code>kernel_write()<\/code>\u00a0: \u00c9criture dans le fichier<\/li>\n\n\n\n<li><code>filp_close()<\/code>\u00a0: Fermeture propre du fichier<\/li>\n\n\n\n<li><code>printk()<\/code>\u00a0: Journalisation interne du noyau<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Bonjour Module&nbsp;est un module simple pour le noyau Linux qui a pour objectif principal de journaliser son activit\u00e9 dans un fichier texte. Il sert de d\u00e9monstration pratique pour comprendre les [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","_uag_custom_page_level_css":"","footnotes":""},"class_list":["post-4981","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>rpi module - workboot<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/workboot.fr\/ciela\/rpi-module\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"rpi module - workboot\" \/>\n<meta property=\"og:description\" content=\"Bonjour Module&nbsp;est un module simple pour le noyau Linux qui a pour objectif principal de journaliser son activit\u00e9 dans un fichier texte. Il sert de d\u00e9monstration pratique pour comprendre les [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/workboot.fr\/ciela\/rpi-module\/\" \/>\n<meta property=\"og:site_name\" content=\"workboot\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-07T17:32:21+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/rpi-module\\\/\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/rpi-module\\\/\",\"name\":\"rpi module - workboot\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#website\"},\"datePublished\":\"2025-11-07T17:09:08+00:00\",\"dateModified\":\"2025-11-07T17:32:21+00:00\",\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/workboot.fr\\\/ciela\\\/rpi-module\\\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#website\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/\",\"name\":\"workboot\",\"description\":\"Open Source, Open Minds \",\"publisher\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#organization\",\"name\":\"workboot\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/logo_ciel-dorian-1.png\",\"contentUrl\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/logo_ciel-dorian-1.png\",\"width\":1024,\"height\":950,\"caption\":\"workboot\"},\"image\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"rpi module - workboot","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/workboot.fr\/ciela\/rpi-module\/","og_locale":"fr_FR","og_type":"article","og_title":"rpi module - workboot","og_description":"Bonjour Module&nbsp;est un module simple pour le noyau Linux qui a pour objectif principal de journaliser son activit\u00e9 dans un fichier texte. Il sert de d\u00e9monstration pratique pour comprendre les [&hellip;]","og_url":"https:\/\/workboot.fr\/ciela\/rpi-module\/","og_site_name":"workboot","article_modified_time":"2025-11-07T17:32:21+00:00","twitter_misc":{"Dur\u00e9e de lecture estim\u00e9e":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/workboot.fr\/ciela\/rpi-module\/","url":"https:\/\/workboot.fr\/ciela\/rpi-module\/","name":"rpi module - workboot","isPartOf":{"@id":"https:\/\/workboot.fr\/ciela\/#website"},"datePublished":"2025-11-07T17:09:08+00:00","dateModified":"2025-11-07T17:32:21+00:00","inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/workboot.fr\/ciela\/rpi-module\/"]}]},{"@type":"WebSite","@id":"https:\/\/workboot.fr\/ciela\/#website","url":"https:\/\/workboot.fr\/ciela\/","name":"workboot","description":"Open Source, Open Minds ","publisher":{"@id":"https:\/\/workboot.fr\/ciela\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/workboot.fr\/ciela\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Organization","@id":"https:\/\/workboot.fr\/ciela\/#organization","name":"workboot","url":"https:\/\/workboot.fr\/ciela\/","logo":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/workboot.fr\/ciela\/#\/schema\/logo\/image\/","url":"https:\/\/workboot.fr\/ciela\/wp-content\/uploads\/2025\/05\/logo_ciel-dorian-1.png","contentUrl":"https:\/\/workboot.fr\/ciela\/wp-content\/uploads\/2025\/05\/logo_ciel-dorian-1.png","width":1024,"height":950,"caption":"workboot"},"image":{"@id":"https:\/\/workboot.fr\/ciela\/#\/schema\/logo\/image\/"}}]}},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"admin","author_link":"https:\/\/workboot.fr\/ciela\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"Bonjour Module&nbsp;est un module simple pour le noyau Linux qui a pour objectif principal de journaliser son activit\u00e9 dans un fichier texte. Il sert de d\u00e9monstration pratique pour comprendre les [&hellip;]","_links":{"self":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/4981","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/comments?post=4981"}],"version-history":[{"count":9,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/4981\/revisions"}],"predecessor-version":[{"id":4993,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/4981\/revisions\/4993"}],"wp:attachment":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/media?parent=4981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}