Source file src/os/proc.go

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Process etc.
     6  
     7  package os
     8  
     9  import (
    10  	"internal/testlog"
    11  	"runtime"
    12  	"syscall"
    13  )
    14  
    15  // Args hold the command-line arguments, starting with the program name.
    16  var Args []string
    17  
    18  func init() {
    19  	if runtime.GOOS == "windows" {
    20  		// Initialized in exec_windows.go.
    21  		return
    22  	}
    23  	Args = runtime_args()
    24  }
    25  
    26  func runtime_args() []string // in package runtime
    27  
    28  // Getuid returns the numeric user id of the caller.
    29  //
    30  // On Windows, it returns -1.
    31  func Getuid() int { return syscall.Getuid() }
    32  
    33  // Geteuid returns the numeric effective user id of the caller.
    34  //
    35  // On Windows, it returns -1.
    36  func Geteuid() int { return syscall.Geteuid() }
    37  
    38  // Getgid returns the numeric group id of the caller.
    39  //
    40  // On Windows, it returns -1.
    41  func Getgid() int { return syscall.Getgid() }
    42  
    43  // Getegid returns the numeric effective group id of the caller.
    44  //
    45  // On Windows, it returns -1.
    46  func Getegid() int { return syscall.Getegid() }
    47  
    48  // Getgroups returns a list of the numeric ids of groups that the caller belongs to.
    49  //
    50  // On Windows, it returns [syscall.EWINDOWS]. See the [os/user] package
    51  // for a possible alternative.
    52  func Getgroups() ([]int, error) {
    53  	gids, e := syscall.Getgroups()
    54  	return gids, NewSyscallError("getgroups", e)
    55  }
    56  
    57  // Exit causes the current program to exit with the given status code.
    58  // Conventionally, code zero indicates success, non-zero an error.
    59  // The program terminates immediately; deferred functions are not run.
    60  //
    61  // For portability, the status code should be in the range [0, 125].
    62  func Exit(code int) {
    63  	if code == 0 && testlog.PanicOnExit0() {
    64  		// We were told to panic on calls to os.Exit(0).
    65  		// This is used to fail tests that make an early
    66  		// unexpected call to os.Exit(0).
    67  		panic("unexpected call to os.Exit(0) during test")
    68  	}
    69  
    70  	// Inform the runtime that os.Exit is being called. If -race is
    71  	// enabled, this will give race detector a chance to fail the
    72  	// program (racy programs do not have the right to finish
    73  	// successfully). If coverage is enabled, then this call will
    74  	// enable us to write out a coverage data file.
    75  	runtime_beforeExit(code)
    76  
    77  	syscall.Exit(code)
    78  }
    79  
    80  func runtime_beforeExit(exitCode int) // implemented in runtime
    81  

View as plain text