refactor: more compact log message
[lunaix-os.git] / lunaix-os / kernel / demos / signal_demo.c
index e5f95332f9aa97138a816bf20db0e7fcf60358e9..27d78142ef0129b8d806eb5e6d066c8469061cad 100644 (file)
@@ -2,22 +2,20 @@
 #include <lunaix/proc.h>
 #include <lunaix/signal.h>
 #include <lunaix/spike.h>
-#include <lunaix/syslog.h>
 #include <lunaix/types.h>
-
-LOG_MODULE("SIGDEMO")
+#include <ulibc/stdio.h>
 
 void __USER__
 sigchild_handler(int signum)
 {
-    kprintf(KINFO "SIGCHLD received\n");
+    printf("SIGCHLD received\n");
 }
 
 void __USER__
 sigsegv_handler(int signum)
 {
     pid_t pid = getpid();
-    kprintf(KWARN "SIGSEGV received on process %d\n", pid);
+    printf("SIGSEGV received on process %d\n", pid);
     _exit(signum);
 }
 
@@ -25,13 +23,9 @@ void __USER__
 sigalrm_handler(int signum)
 {
     pid_t pid = getpid();
-    kprintf(KWARN "I, pid %d, have received an alarm!\n", pid);
+    printf("I, pid %d, have received an alarm!\n", pid);
 }
 
-// FIXME: Race condition with signal (though rare!)
-// For some reason, there is a chance that iret in soft_iret path
-//   get unhappy when return from signal handler. Investigation is needed!
-
 void __USER__
 _signal_demo_main()
 {
@@ -44,7 +38,7 @@ _signal_demo_main()
     int status;
     pid_t p = 0;
 
-    kprintf(KINFO "Child sleep 3s, parent pause.\n");
+    printf("Child sleep 3s, parent pause.\n");
     if (!fork()) {
         sleep(3);
         _exit(0);
@@ -52,7 +46,7 @@ _signal_demo_main()
 
     pause();
 
-    kprintf("Parent resumed on SIGCHILD\n");
+    printf("Parent resumed on SIGCHILD\n");
 
     for (int i = 0; i < 5; i++) {
         pid_t pid = 0;
@@ -62,26 +56,22 @@ _signal_demo_main()
             if (i == 3) {
                 i = *(int*)0xdeadc0de; // seg fault!
             }
-            kprintf(KINFO "%d\n", i);
+            printf("%d\n", i);
             _exit(0);
         }
-        kprintf(KINFO "Forked %d\n", pid);
+        printf("Forked %d\n", pid);
     }
 
     while ((p = wait(&status)) >= 0) {
         short code = WEXITSTATUS(status);
         if (WIFSIGNALED(status)) {
-            kprintf(KINFO "Process %d terminated by signal, exit_code: %d\n",
-                    p,
-                    code);
+            printf("Process %d terminated by signal, exit_code: %d\n", p, code);
         } else if (WIFEXITED(status)) {
-            kprintf(KINFO "Process %d exited with code %d\n", p, code);
+            printf("Process %d exited with code %d\n", p, code);
         } else {
-            kprintf(KWARN "Process %d aborted with code %d\n", p, code);
+            printf("Process %d aborted with code %d\n", p, code);
         }
     }
 
-    kprintf("done\n");
-
-    _exit(0);
+    printf("done\n");
 }
\ No newline at end of file