Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

int 
__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

int 
__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.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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