I want to find the source file of pause and sigsuspend in the glibc-2.14.1 package. I grep the package and find the file sysdeps/posix/pause.c has a definition of function pause, the code is

__libc_pause (void) 
   sigset_t set; 

   __sigemptyset (&set); 
   __sigprocmask (SIG_BLOCK, NULL, &set); 

   /* pause is a cancellation point, but so is sigsuspend. 
       So no need for anything special here.  */ 

   return __sigsuspend (&set); 
 weak_alias (__libc_pause, pause) 

I also grep the package for the definition of sigsuspend function and several files have the definition, such as sysdeps/posix/sigsuspend.c and sysdeps/unix/sysv/linux/sigsuspend.c.

The definition of sigsuspend in sysdeps/posix/sigsuspend.c is

__sigsuspend (set) 
    const sigset_t *set; 
   sigset_t oset; 
  int save; 

  if (set == NULL) 
     __set_errno (EINVAL); 
      return -1; 

  if (sigprocmask (SIG_SETMASK, set, &oset) < 0) 
     return -1; 

   (void) pause(); 
   save = errno; 

  if (sigprocmask (SIG_SETMASK, &oset, (sigset_t *) NULL) < 0) 
    return -1; 

   __set_errno (save); 
  return -1; 
libc_hidden_def (__sigsuspend) 
weak_alias (__sigsuspend, sigsuspend) 

I found a problem that pause in sysdeps/posix/pause.c call function sigsuspend and sigsuspend in sysdeps/posix/sigsuspend.c call function pause. It seems to be a cycle. So I think that I don't find the proper souce files of pause and sigsuspend. Can any people tell me where is the source files of these functions. Thanks in advance.


There are several definitions of pause() and sigsuspend() in the glibc tree. The definitions actually used depend on which system and architecture glibc was built for. On older Unix systems where pause() is a system call, sigsuspend() is implemented by calling pause(). On systems where sigsuspend() is a system call, pause() is implemented by calling sigsuspend(). The system calls themselves are implemented in assembly language, either triggering an interrupt or executing a special instruction to get the kernel to take over. The glibc build process makes sure that the right combination of C and assembly language source files are used to build the final library.

System calls that don't have their own source files have definitions generated by the build process using a shell script called make-syscalls.sh, whose actions are driven by syscalls.list. The code for the system call is generated by this script. The code generation part of the script is about as impenetrable as shell code gets, and says near the outset "The best way to understand what's going on here is to examine the output in BUILDDIR/sysd-syscalls." So you'll have to build glibc to see the generated source files for system calls that do not have hand-coded versions.

|improve this answer|||||
  • Thank you for your answer. Can you tell me where is the assembly language source files. I can't find any files named like pause.S or sigsuspend.S in glibc 2.14.1package. – Jerome Feb 24 '12 at 11:23
  • I've edited the answer to address this question. – Kyle Jones Feb 24 '12 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.