| |
| /pliant/language/context/computer.pli |
| |
| 1 |
# Copyright Hubert Tonneau hubert.tonneau@pliant.cx | |
| 2 |
# | |
| 3 |
# This program is free software; you can redistribute it and/or | |
| 4 |
# modify it under the terms of the GNU General Public License version 2 | |
| 5 |
# as published by the Free Software Foundation. | |
| 6 |
# | |
| 7 |
# This program is distributed in the hope that it will be useful, | |
| 8 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 9 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 10 |
# GNU General Public License for more details. | |
| 11 |
# | |
| 12 |
# You should have received a copy of the GNU General Public License | |
| 13 |
# version 2 along with this program; if not, write to the Free Software | |
| 14 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 15 |
| |
| 16 |
abstract | |
| 17 |
[Sets the 'computer_name' and 'computer_domain' context variables.] | |
| 18 |
| |
| 19 |
scope "/pliant/language/" | |
| 20 |
module "internals.pli" | |
| 21 |
module "/pliant/install/ring2.pli" | |
| 22 |
module "/pliant/language/stream.pli" | |
| 23 |
module "/pliant/language/stream/filesystembase.pli" | |
| 24 |
module "/pliant/language/stream/multi.pli" | |
| 25 |
module "/pliant/storage/database/light.pli" | |
| 26 |
| |
| 27 |
| |
| 28 |
gvar Str computer_name computer_domain computer_fullname | |
| 29 |
gvar Str security data | |
| 30 |
| |
| 31 |
if os_api="posix" | |
| 32 |
function gethostname phname size -> err | |
| 33 |
arg Address phname ; arg Int size err | |
| 34 |
external os_libc_filename "gethostname" | |
| 35 |
| |
| 36 |
function find_computer_name p fh | |
| 37 |
arg Address p ; arg Int fh | |
| 38 |
if pliant_root_path="/usr/share/pliant/" | |
| 39 |
security := "/etc/pliant/" | |
| 40 |
data := "/var/lib/pliant/" | |
| 41 |
else | |
| 42 |
var Str prefix := pliant_root_path 0 ((pliant_root_path 0 pliant_root_path:len-1) search_last "/" 0) | |
| 43 |
security :=prefix+"/pliant_security/" | |
| 44 |
data := prefix+"/pliant_data/" | |
| 45 |
pliant_multi_file_system mount "security:/" security "direcory_mode "+(string 7*8^2)+" file_mode "+(string 6*8^2) pliant_os_file_system | |
| 46 |
pliant_multi_file_system mount "data:/" data "" pliant_os_file_system | |
| 47 |
if os_api="posix" | |
| 48 |
os_constant os_MAXHOSTNAMELEN "sys/param.h" MAXHOSTNAMELEN | |
| 49 |
(var Str n) set (memory_allocate os_MAXHOSTNAMELEN+1 null) os_MAXHOSTNAMELEN+1 true | |
| 50 |
if (gethostname n:characters os_MAXHOSTNAMELEN+1)<>0 | |
| 51 |
computer_name := "" | |
| 52 |
computer_domain := "" | |
| 53 |
else | |
| 54 |
n := n 0 (n search "[0]" n:len) | |
| 55 |
var Int dot_pos := n search "." n:len | |
| 56 |
computer_name := n 0 dot_pos | |
| 57 |
computer_domain := n dot_pos+1 n:len | |
| 58 |
if os_api="linux" or os_api="posix" | |
| 59 |
(var Stream s) open "file:/proc/sys/kernel/hostname" in+safe | |
| 60 |
var Str n := s readline | |
| 61 |
if n<>"" and n<>"(none)" | |
| 62 |
computer_name := n | |
| 63 |
s open "file:/proc/sys/kernel/domainname" in+safe | |
| 64 |
var Str d := s readline | |
| 65 |
if d<>"" and d<>"(none)" | |
| 66 |
computer_domain := d | |
| 67 |
if (data_read "security:/this_computer.pdb" "/env/pliant/identity/name" (var Str n))=success | |
| 68 |
computer_name := n | |
| 69 |
if (data_read "security:/this_computer.pdb" "/env/pliant/identity/domain" (var Str d))=success | |
| 70 |
computer_domain := d | |
| 71 |
computer_fullname := computer_name+(shunt computer_domain<>"" "." "")+computer_domain | |
| 72 |
| |
| 73 |
find_computer_name null 0 | |
| 74 |
gvar DelayedAction da | |
| 75 |
da function :> the_function find_computer_name Address Int | |
| 76 |
pliant_restore_actions insert_after pliant_restore_actions:first addressof:da | |
| 77 |
| |
| 78 |
module "/pliant/language/debug/compile_log.pli" | |
| 79 |
compile_log "this computer name is "+computer_name+" in domain "+computer_domain | |
| 80 |
compile_log "security path is file:"+security | |
| 81 |
compile_log "data path is file:"+data | |
| 82 |
| |
| 83 |
export computer_name computer_domain computer_fullname | |
| |