title: Building system calls in Linux. Kernel > 3.x.x
body: <p>My initial attempts to build a system call with the help of this <a href="https://stackoverflow.com/questions/12469836/how-to-write-system-calls-on-debian-ubuntu">question</a> </p>
  
  <p>My distro information: <code>Linux linux-epq2.site 3.7.10-1.16-default #1 SMP Fri May 31 20:21:23 UTC 2013 (97c14ba) x86_64 x86_64 x86_64 GNU/Linux</code></p>
  
  <p>In the current version of my program, that will allow me to embed this as a system call does have a main (stupidity to even say that, but just to make things 
  more explicit). </p>
  
  <p><b>In my current program:</b></p>
  
  <p>It takes in two inputs from the user, and does some calculations and gives the output as the graph and some data.</p>
  
  <p>My initial attempt was to call that program via <code>execlp</code> available in <code>unistd</code> library like this:</p>
  
  <pre><code>#include&lt;linux/linkage.h&gt;
  #include&lt;linux/kernel.h&gt;
  #include&lt;unistd.h&gt;
  
  asmlinkage long graph(const char* granularity, char* application)
  {
          pid_t child;
          child = fork();
          if (!child) {
                  execlp("./system-call", granularity, application, NULL);
          }
          sleep(0.2);
          return 0;
  }
  </code></pre>
  
  <p>But when I am trying to compile the kernel (note: same kernel version) and the old config file (if necessary i'll also upload the config file). 
  I get the following error:</p>
  
  <pre><code>linux-3.7.10 % make             
  make[1]: Nothing to be done for `all'.
  make[1]: Nothing to be done for `relocs'.
    CHK     include/generated/uapi/linux/version.h
    CHK     include/generated/utsrelease.h
    CALL    scripts/checksyscalls.sh
    CHK     include/generated/compile.h
  make[3]: `arch/x86/realmode/rm/realmode.bin' is up to date.
    CHK     kernel/config_data.h
    CC      test/graph.o
  test/graph.c:10:19: fatal error: unistd.h: No such file or directory
  compilation terminated.
  make[1]: *** [test/graph.o] Error 1
  make: *** [test] Error 2
  make  4.50s user 1.27s system 75% cpu 7.626 total`
  </code></pre>
  
  <p>I checked if <code>glibc</code> was installed or no, i see that all the kernel header files ARE available.</p>
  
  <pre><code>zypper search glibc      
  Loading repository data...
  Reading installed packages...
  
  S | Name                     | Summary                                               | Type   
  --+--------------------------+-------------------------------------------------------+--------
  i | glibc                    | Standard Shared Libraries (from the GNU C Library)    | package
  i | glibc-32bit              | Standard Shared Libraries (from the GNU C Library)    | package
  i | glibc-devel              | Include Files and Libraries Mandatory for Development | package
  i | glibc-devel-32bit        | Include Files and Libraries Mandatory for Development | package
  i | glibc-devel-static       | C library static libraries for -static linking        | package
  i | glibc-devel-static-32bit | C library static libraries for -static linking        | package
  i | glibc-extra              | Extra binaries from GNU C Library                     | package
  i | glibc-info               | Info Files for the GNU C Library                      | package
  i | glibc-locale             | Locale Data for Localized Programs                    | package
  i | glibc-locale-32bit       | Locale Data for Localized Programs                    | package
  i | glibc-utils              | Development utilities from GNU C library              | package
  i | linux-glibc-devel        | Linux headers for userspace development               | package
  </code></pre>
  
  <p>I checked to see if it is availble in the new kernel dump, and it is not available. </p>
  
  <p>IS IT safe to copy <code>unistd.h</code> from <code>/usr/include/unistd.h</code> to the new kernel dump which I want to compile?</p>
  
  <p>OR is there another way around it?</p>
  
  <p>Here is an update: <b> EDIT </b></p>
  
  <p>I had to change it from <code>#include&lt;unistd.h&gt;</code> to <code>#include&lt;asm/unistd.h&gt;</code>
  But I still get the error</p>
  
  <pre><code>error: implicit declaration of function ‘fork’ [-Werror=implicit-function-declaration]
  error: implicit declaration of function ‘execlp’ [-Werror=implicit-function-declaration]
  warning: incompatible implicit declaration of built-in function ‘execlp’ [enabled by default]
  </code></pre>
  
  <p>Really not sure what the problem is.</p>