proc-env.scm 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. ; Copyright (c) 1993-2007 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; Access to Posix process environment
  3. ; We multiplex a bunch of these to save typing.
  4. ;----------------
  5. ; 4.1 Process Identification
  6. (define (get-process-id)
  7. (call-imported-binding posix-get-pid #f))
  8. (define (get-parent-process-id)
  9. (call-imported-binding posix-get-pid #t))
  10. ;----------------
  11. ; 4.2 User Identification and 4.3 Process Groups
  12. (define (get-user-id)
  13. (call-imported-binding posix-get-id #t #t))
  14. (define (get-effective-user-id)
  15. (call-imported-binding posix-get-id #t #f))
  16. (define (get-group-id)
  17. (call-imported-binding posix-get-id #f #t))
  18. (define (get-effective-group-id)
  19. (call-imported-binding posix-get-id #f #f))
  20. (define (set-user-id! user-id)
  21. (call-imported-binding posix-set-id! #t user-id))
  22. (define (set-group-id! group-id)
  23. (call-imported-binding posix-set-id! #f group-id))
  24. (import-definition posix-get-pid)
  25. (import-definition posix-get-id)
  26. (import-definition posix-set-id! "posix_set_id")
  27. (define (get-groups)
  28. (call-imported-binding posix-get-groups))
  29. (define (get-login-name)
  30. (call-imported-binding posix-get-login))
  31. (import-definition posix-get-groups)
  32. (import-definition posix-get-login)
  33. (import-lambda-definition posix-set-sid ())
  34. ;----------------
  35. ; 4.4 System Identification
  36. ;
  37. ; The five values returned by uname().
  38. (import-lambda-definition posix-sys-name (which))
  39. (define (os-name) (posix-sys-name 0))
  40. (define (os-node-name) (posix-sys-name 1))
  41. (define (os-release-name) (posix-sys-name 2))
  42. (define (os-version-name) (posix-sys-name 3))
  43. (define (machine-name) (posix-sys-name 4))
  44. ;----------------
  45. ; 4.5 Get Process Times
  46. ;
  47. ;----------------
  48. ; 4.6 Environment Variables
  49. ; We cheat here by using one type for both the variable names and
  50. ; their values. The rules are the same for both, after all.
  51. (define (lookup-environment-variable name)
  52. (cond
  53. ((external-lookup-environment-variable
  54. (os-string->byte-vector
  55. (x->os-string name)))
  56. => x->os-string)
  57. (else #f)))
  58. (define (lookup-environment-variable->string name)
  59. (cond
  60. ((lookup-environment-variable name)
  61. => os-string->string)
  62. (else #f)))
  63. (define (environment-alist)
  64. (map (lambda (pair)
  65. (cons (x->os-string (car pair))
  66. (x->os-string (cdr pair))))
  67. (external-environment-alist)))
  68. (define (environment-alist-as-strings)
  69. (map (lambda (pair)
  70. (cons (os-string->string (car pair))
  71. (os-string->string (cdr pair))))
  72. (environment-alist)))
  73. (import-lambda-definition external-lookup-environment-variable (name) "posix_get_env")
  74. (import-lambda-definition external-environment-alist () "posix_get_env_alist")
  75. ;----------------
  76. ; 4.7 Terminal Identification
  77. ; See io.scm.
  78. ;----------------
  79. ; 4.8 Configurable System Variables