Adding custom ("Hello") system call: help


 
Thread Tools Search this Thread
Top Forums Programming Adding custom ("Hello") system call: help
# 1  
Old 01-09-2011
Adding custom ("Hello") system call: help

I'm trying to add a custom ("Hello world" Smilie) system call.
In /usr/src/linux/hello/ I put simple hello.c ...
Code:
#include "linux/linkage.h" // for linking a system call
#include "linux/kernel.h" // for "printk"

asmlinkage int sys_hello() 
{
	printk(KERN_ALERT "Hello!");
	return 1;
}

... and in home directory helloTest.c:
Code:
#include <stdio.h>
#include <sys/syscall.h>
#include <linux/unistd.h>

#define __NR_hello	338

int main()
{
	syscall(__NR_hello);
	return 0;
}

I compiled helloTest.c and ran ./a.out: in /var/log/messages nothing gets written! Smilie

Before "compile & install & reboot" I did these steps (linux is symbolic link to linux-2.6.35.10):
  1. In /usr/src/linux/arch/x86/include/asm/unistd_32.h, I've added/changed:
    Code:
    #define __NR_hello	 338
    #define __NR_syscalls	 339

  2. In /usr/src/linux/arch/x86/kernel/syscall_table.S, I've added (on the last line):
    Code:
    .long sys_hello

  3. In /usr/src/linux/hello, I've created a Makefile:
    Code:
    obj-y += hello.o

    ... and in /usr/src/linux, I've modified Makefile and added hello/ directory:
    Code:
    core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ hello/

  4. In /usr/src/linux/include/linux/syscalls.h, I've added (on the last line):
    Code:
    asmlinkage long sys_hello(void)


Last edited by courteous; 01-09-2011 at 04:41 PM..
# 2  
Old 01-10-2011
check if 'hello' actually ended up in System.map

And just to rule out the obvious you did reboot into your new kernel yes?
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 01-13-2011
"Hello!" IS in dmesg but NOT in /var/log/messages

Yes, 'hello' is in System.map (in /boot directory):
Code:
c015c3c0 T sys_hello

Yes, I did reboot (into the new kernel). Smilie

As 'hello' is in System.map, does that mean that something is wrong with the test function helloTest.c? Smilie

EDIT: dmesg* does print "Hello!" on the last line, but there is nothing in /var/log/messages file.


* dmesg - prints or controls the kernel ring buffer


EDIT2: I've compared output of dmesg and tail -f /var/log/messages commands: equal lines are in bold red, Hello! is the last line of dmesg.
Code:
blaise@blaise-E520 ~/Documents/seminar $ dmesg
[ 5364.127763] [... snipped... ]
[ 5379.250373] usb 2-3: USB disconnect, address 4
[10619.880053] usb 2-3: new high speed USB device using ehci_hcd and address 5
[10620.016622] scsi6 : usb-storage 2-3:1.0
[10621.889492] scsi 6:0:0:0: Direct-Access     USB      FLASH DRIVE      1100 PQ: 0 ANSI: 0 CCS
[10621.891282] sd 6:0:0:0: Attached scsi generic sg2 type 0
[10621.897073] sd 6:0:0:0: [sdb] 7831552 512-byte logical blocks: (4.00 GB/3.73 GiB)
[10621.897837] sd 6:0:0:0: [sdb] Write Protect is off
[10621.897841] sd 6:0:0:0: [sdb] Mode Sense: 43 00 00 00
[10621.897844] sd 6:0:0:0: [sdb] Assuming drive cache: write through
[10621.901956] sd 6:0:0:0: [sdb] Assuming drive cache: write through
[10621.901964]  sdb: sdb1
[10621.905319] sd 6:0:0:0: [sdb] Assuming drive cache: write through
[10621.905324] sd 6:0:0:0: [sdb] Attached SCSI removable disk
[10645.191905] usb 2-3: USB disconnect, address 5
[11121.593000] Hello!
blaise@blaise-E520 ~/Documents/seminar $ tail -f /var/log/messages
Jan 13 14:56:59 blaise-E520 sudo: pam_sm_authenticate: username = [blaise]
Jan 13 15:15:04 blaise-E520 kernel: [10619.880053] usb 2-3: new high speed USB device using ehci_hcd and address 5
Jan 13 15:15:04 blaise-E520 kernel: [10620.016622] scsi6 : usb-storage 2-3:1.0
Jan 13 15:15:06 blaise-E520 kernel: [10621.889492] scsi 6:0:0:0: Direct-Access     USB      FLASH DRIVE      1100 PQ: 0 ANSI: 0 CCS
Jan 13 15:15:06 blaise-E520 kernel: [10621.891282] sd 6:0:0:0: Attached scsi generic sg2 type 0
Jan 13 15:15:06 blaise-E520 kernel: [10621.897073] sd 6:0:0:0: [sdb] 7831552 512-byte logical blocks: (4.00 GB/3.73 GiB)
Jan 13 15:15:06 blaise-E520 kernel: [10621.897837] sd 6:0:0:0: [sdb] Write Protect is off
Jan 13 15:15:06 blaise-E520 kernel: [10621.901964]  sdb: sdb1
Jan 13 15:15:06 blaise-E520 kernel: [10621.905324] sd 6:0:0:0: [sdb] Attached SCSI removable disk
Jan 13 15:15:29 blaise-E520 kernel: [10645.191905] usb 2-3: USB disconnect, address 5

Why isn't Hello! also printed in /var/log/messages? Smilie

Last edited by courteous; 01-13-2011 at 10:40 AM..
# 4  
Old 01-13-2011
What ends up in /var/log/messages is controlled in software by your system logger. It may or may not be syslog-ng. dmesg does end up there in my systems but that's by no means mandatory!

You seem to be getting some parts of dmesg in messages, but not your 'hello', possibly because it's just an 'alert' and not anything critical. the system logger is able to tell the different levels of criticality apart.

So, it's working. Smilie All the really tough stuff actually went as planned. Be happy.
# 5  
Old 01-13-2011
Quote:
Originally Posted by Corona688
You seem to be getting some parts of dmesg in messages, but not your 'hello', possibly because it's just an 'alert' and not anything critical. the system logger is able to tell the different levels of criticality apart.
But KERN_ALERT is on a higher, 2nd, log-level than is KERN_CRIT! Smilie

Snippet from kernel.h:
Code:
#define	KERN_EMERG	"<0>"	/* system is unusable			*/
#define	KERN_ALERT	"<1>"	/* action must be taken immediately	*/
#define	KERN_CRIT	"<2>"	/* critical conditions			*/
#define	KERN_ERR	"<3>"	/* error conditions			*/
#define	KERN_WARNING	"<4>"	/* warning conditions			*/
#define	KERN_NOTICE	"<5>"	/* normal but significant condition	*/
#define	KERN_INFO	"<6>"	/* informational			*/
#define	KERN_DEBUG	"<7>"	/* debug-level messages		        */

# 6  
Old 01-13-2011
I'm afraid I don't know then Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

What does "force devmap reload" as in "multipath -r" means for my system and stability of my system?

Cannot present unpresented disks back again. On a test server tried this as a solution "multipath -r" and it worked. Too worried to try it in production before I know all the information. Any info would be appreciated! Also some links to the documentation on this specific issue could help a... (1 Reply)
Discussion started by: jsteppe
1 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Shell Programming and Scripting

awk "date" and "system" command

Hello experts! I need your help please I have a file.txt of which I want to extract 3rd and 4th columns with date with the form e.g.: 2016-11-25 03:14:50and pass them to "date" command, but also append the 9th column in a file as well. So I want to execute date -d '2016-11-25 03:14:50' ... (2 Replies)
Discussion started by: phaethon
2 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. Post Here to Contact Site Administrators and Moderators

Suggestion: adding two new groups "sed" and "awk"

Majority of the questions are pertaining file/string parsing w.r.t sed or awk It would be nice to have these two as their own sub category under shell-programming-scripting which can avoid lot of duplicate posts. (1 Reply)
Discussion started by: jville
1 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. IP Networking

Configure a range of ports to "socket" system call

Hello ; This what i want to do : I know that in the system call #include <sys/socket.h> int bind(int socket, const struct sockaddr *address, socklen_t address_len); you can specify the local port for your socket, but im using a private library , and im sure that in that library... (0 Replies)
Discussion started by: trutoman
0 Replies

8. Programming

Problem with socket binding - "system" call

Hi, I am having an issue with using sockets. I have a program which binds to a socket and listen on it. Later I spawn a thread to handle some function. In the new thread created I need to call a shell script which executes the specified function. Here I am using a system command to call the... (5 Replies)
Discussion started by: Janardhanbr
5 Replies

9. Shell Programming and Scripting

Adding custom mesg. when redirecting "exec 2>stderr.err" ?

Doubt regarding using "exec" command to redirect the STDERR to a file. e.g I did it this way. mystage.sh #!/bin/sh exec 2>stage.err .... .... cat stage.err mv: cannot move `/root/stage' to a subdirectory of itself, `/root/stage_old/stage' ls: *.zDB: No such file or... (0 Replies)
Discussion started by: snurani
0 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question