### Plan9 Environment Variables -- Notes of Introduction to OS Abstractions Using Plan 9 from Bell Labs(III)

The
interface for using environment variables in Plan 9 is a file
interface.
All interfaces of environment variables can be found
under /env.

To
obtain the value for a environment variable, from a C program, we can
use the
getenv
system call. If the variable is not defined,
getenv
returns a null string. A related call is
putenv,
which accepts a name and a value, and set the corresponding
environment variable accordingly.

#include <u.h>
#include <libc.h>
void main()
{
char * path;
path=getenv("path");
if(path==nil)
sysfatal("path not defined!");
print("PATH is %s /n", path);
exits(nil);
}

In
some cases it is convenient to define an environment variable just
for a command. This can be
done by defining it in the same command
line, before the command, like in the following exam-ple:

; temp=/tmp/foobar echo $temp /tmp/foobar ; echo$temp
;


Useful
Environment Variables:

status
is updated by the shell once it finds out how it went to the last
command it executed.

path
is a list of paths where the shell should
look for executable files
to run the user commands.

user
contains the user name
.

sysname
contains the machine name.

The
file /dev/text represents
the
text shown in the window (when used within that window). To make
a copy of your shell session,
you already know what to do:

;


### Plan 9安装Go

I、安装python和mercurial(hg)

% 9fs sources
% /n/sources/contrib/fgb/root/rc/bin/contrib/install fgb/contrib
% contrib/install -f bichued/python
% contrib/install -f bichued/hg

% bunzip2 python.iso.bz2
% 9660srv -f python.iso
% 9fs 9660
% cd /n/9660
% cat README

II、安装Go

% hg clone -r release https://go.googlecode.com/hg/ go



should return "xterm". If it works as intended (do 'toe' to check whether the terminfo dir you specified is indeed used, toe will return a list of available terminfo types, only xterm in this case), you can run tic as root, which will copy the file to

/etc/terminfo/x/xterm


(debian) or

/usr/lib/terminfo/x/xterm


(redhatslackware). Make backups first, and test it before you replace any files!

## Xterm

The xterm (and friends) only needs little configuration. In the /etc/X11/Xresources or ~/.Xdefaults (or wherever it's merged with the other xresources) add the line:

*VT100.Translations: #override /
<Key>BackSpace: string(0x7F)/n/
<Key>Delete:    string("/033[3~")/n/
<Key>Home:      string("/033[1~")/n/
<Key>End:       string("/033[4~")
*ttyModes: erase ^?



Rxvt only uses Xresources if it is compiled with this option. Since rxvt uses readline, to get home and end to work you will have to edit .inputrc, see the Bash section). Redhat users can pick up the SRPM (source) and compile rxvt themselves with this feature.h, ensuring the right keybindings.

Putting xterm or nxterm in front of *vt100.translations makes the settings specific for xterm or nxterm. Sometimes this does not seem to work properly, in that case try using bothnxterm*VT100.Translations and xterm*VT100.Translations.

BTW, have I told you that Ctrl-v <key> will tell you what sequence is sent to the shell? Try Ctrl-v [Delete], it should give a ^[[3~ in your xterm or console (try it with [ESC] and you'll find ^[, which corresponds to /e for readline apps, and /033 for Xresources).

1. The syntax of the Xresources files is very strict, make sure you don't leave blank spaces after the backslash on each line. Also watch the newline (/n/) sequences, there shouldn't be one at the last line of an entry.
2. The sections are named, if you only use *VT100.Translations it will work for all xterm and friends.
3. For info about Xresources and other X related stuff refer to 'man X'.

## X

If you use XFree86, make sure you have enable the XKB extensions in /etc/X11/XF86Config. It is enable by default, so it should be okay. Note the different keyboard layout-options. Now XFree86 will translate the console mapping, and everything should work in X. If you have problems, or want to fiddle with additional characters and things, create an Xmodmap. Also if you want the keyboard to generate special characters in X, xmodmap can also be used to configure the function-keys. This is adequately described in the manual page ('man xmodmap'. Make sure that the following lines are included in yourXmodmap:

keycode 22 = BackSpace
keycode 107 = Delete

Note that the keycodes in X are not the same as in a VT. Use showkey to see the keycodes generated by the keyboard in a VT, and xev in X. There is an excellent graphical front end for X-keyboard configuration: xkeycaps. Refer to the Netscape section.

Another way of generating special characters in X (without using xmodmap) is by defining a Compose-key (for use as a "dead key") in XF86Config in the Keyboard section:

  RightCtl        Compose



Now you have a compose-key with the same properties as the one described in the VT section. Remember to set the environment variable LC_CTYPE=iso-8859-1 (see VT optional...). Consult 'man XF86Config' if you want to know more. Note: this doesn't seem work rxvt.
Alternatively, owners of a windows keyboard (one with extra buttons, it need not be a M$natural keyboard) can enable the XKEYBOARD extension (enabled per default) in XF86Config and uncomment the line (follow the instructions in the file):  XkbModel "microsoft"   Now you can use the button with the windows flag on it to produce a great number of exotic characters, just press it in combination with e.g. a, producing á (a clear disadvantage is that there is no logic in the location of the special characters at all...). Yet another way to use "dead keys" in X is by installing a modified version of libX11 which includes support for dead keys (transparent for all apps). First, get the modified version of libX11 (make sure you get the right version, if you use glibc replace both libX11, ELF-libc5 and ELF-libc6). Now, deactivate the XKB extension of XFree86 (edit XF86Config and run xmodmap on a Xmodmap file with dead keys like dead_acute, dead_grave, dead_cedilla, dead_ogonek and a Multi_keys one too. A special case is if you use xdm, you need to deactivate XKB from the /etc/X11/xdm/Xservers file, passing a -kb parameter to the server like this: :0 local /usr/X11R6/bin/X -kb   then in /etc/X11/xdm/Xsetup_0 file add a line to load the Xmodmap, like this: if [ -r /etc/X11/xinit/.Xmodmap ]; then /usr/X11R6/bin/xmodmap /etc/X11/xinit/.Xmodmap fi   Now chars accesible by AltGr, dead keys or compose are usable in xdm too. #### More Composing Talk A problem common to all compose schemes is that while some composing systems make more sense than others, none of them make all of the iso_8859_1 characters readily accessible, simply because it is impossible to remember the combinations for all characters. So instead of, or in addition to getting special libraries, it is often desirable to simply have a list of characters you can copy from, a poor man's iso_8859_1 table so to speak. Just grab you favorite editor, open a file called iso_8859_1 (or any other name, but check the name and path) and put in all iso_8859_1 characters. Wait, here they are (you may want to create a different order): ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± &sup2; &sup3; ´ µ ¶ · ¸ &sup1; º » &frac14; &frac12; &frac34; ¿ À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ   Now you need a way to display them (millions of options here, I bet you can do all kinds of crazy things with fonts, colors, pixmaps, borders...). The script assumes the file with the characters is in/usr/local/lib.    Feb 16, 2011 9vx tutorial: running a cpu server from kfs (RFC) 原文： http://groups.google.com/group/comp.os.plan9/browse_thread/thread/2db7a483a46f9acd 【说明】 本文是yiyus发布在9fans上的一篇教程。文中用到的9vx是yiyus维护的分支：http://bytebucket.org/yiyus/vx32/overview。根据yiyus在9fans中的说明，他的9vx分支是从ron的分支上更改的。vx32/9vx的创始人Russ Cox最近在9fans中声明他本人已经放弃了对9vx的维护，准备将所有权限转交给ron minnich（八卦一下：Russ Cox现在是Google Go语言的核心成员之一，正与Rob Pike，Ken Tompson等原plan9的元老一起维护Go……）。 ------------------------------------------------------- 9vx tutorial: running a cpu server from kfs (RFC) This tutorial is a work in progress (it will eventually be added to the 9vx documentation and probably to the Plan 9 wiki). Please let me know if you see anything I'm doing wrong (unfortunately I don't have too much experience with real Plan 9 systems of more than one machine). In particular, I don't know why I could not use mkfs instead of dircp. The line % disk/mkfs -s /n/9660 /sys/lib/sysconfig/proto/allproto gave me this error: mkfs: /sys/lib/sysconfig/proto/allproto:1: can't move tmp file to /n/kfs/dist/replica/plan9.compressed.db: wstat -- unknown type/mode Anyway, these instructions are working here. Please, let me know if they work for you too. By the way, this tutorial is only the first one, but I'd like to have some more. For example, to run several 9vx instances in a private network using the tap device and to run 9vx from fossil backed up by p9p's venti. Contributions are welcomed ;-) ----------------------------------------------------------------------​ This is a brief tutorial on how to run a 9vx cpu server from a kfs file system. You will need 9vx, a plan9.iso and some free disk space. First, go to the destination directory and install 9vx:$ hg clone http://bitbucket.org/yiyus/vx32/ $cd vx32/src/$ make 9vx/9vx && sudo make 9vx/install   (Commands run on the host are preceded by $, commands run from inside 9vx are preceded with %) You can check that 9vx is working running the minimal system embedded in the executable. The rcvx script should take you to a vx32% rc prompt in the current directory. Once you have played a bit with a rootless 9vx type exit to go back to your host system. rcvx is cool but you will want a full Plan 9 tree to have real fun. Let's boot from the iso file:$ 9vx -r plan9.iso -u glenda "CWD=#Zpwd" "nvram=#Zpwd/plan9.nvr"   You should be in rio now, have an acme and a rio window, stats, faces... This is the live system in the iso that you probably already know. The CWD=... and nvram=... arguments are interpreted as plan9.ini lines and passed as environment variables, we will use them later.  Open a new rio window:       % cd $CWD % dd -if /dev/random -of plan9.nvr -bs 512 -count 1 % dd -if /dev/zero -of plan9.kfs -bs 1024 -count 320000 Those files will be our nvram and kfs partitions (check the size of your kfs file, 320Mb is not too much, but will be enough). Nvram needs to be initialized: % auth/wrkey authid: bootes authdom: 9vx secstore key: password: We can populate the file system now: % 9660srv -f plan9.iso % 9fs 9660 % disk/kfs -f plan9.kfs File system main inconsistent Would you like to ream it (y/n)? y % 9fs kfs % dircp /n/9660 /n/kfs The system is now installed. You should be able to open a new 9vx instance from your new root:$ 9vx "nvram=#Zpwd/plan9.nvr" -r plan9.kfs -u glenda   You can also boot a cpu server. We will use the canopenpath option, so that only the files which begin with pwd/plan9 can be opened from 9vx, the -ic flags tell 9vx to pass -c to /386/init:     \$ 9vx -gic -r plan9.kfs "nvram=#Zpwd/plan9.nvr" "canopenpath=pwd/plan9" -u bootes   When you see the vx32# prompt add a key so that you can cpu as glenda:       vx32# echo 'key proto=p9sk1 dom=9vx user=glenda !password=password' >/mnt/factotum/ctl   Now you can cpu to your new server. From another 9vx instance (for example, booted from the iso):       % cpu -h 127.0.0.1     If it worked we are done.    Now you will probably want to adjust to your needs the 9vxc script to launch cpu servers (also, think about adding a /cfg/vx32/cpurc file).  You could be interested in the options localroot, canopenpath, cpulimit and memsize. Or maybe you want to setup a virtual ethernet device (have a look at the tap script and the 9vx man page).  Have fun! (and please, report bugs)    --  - yiyus || JGL . 4l77.com      Jan 19, 2011 Tools for Manipulating Object Files   There are a number of tools available on Unix systems to help you understand and manipulate object files. In particular, the GNU binutils package is especially helpful and runs on every Unix platform.   AR : Creates static libraries, and inserts, deletes, lists, and extracts members. STRINGS: Lists all of the printable strings contained in an object file. STRIP: Deletes symbol table information from an object file. NM : Lists the symbols defined in the symbol table of an object file. SIZE: Lists the names and sizes of the sections in an object file. READELF: Displays the complete structure of an object file, including all of the information encoded in the ELF header. Subsumes the functionality of SIZE and NM. OBJDUMP: The mother of all binary tools. Can display all of the information in an object file. Its most useful function is disassembling the binary instructions in the .text section. LDD : Lists the shared libraries that an executable needs at run time. --- From Computer Systems: A Programmer's Perspective. PS: A very good webpage introducing Linux libraries: Static, Shared Dynamic and Loadable Linux Libraries How to Write Shared Libraries? http://www.akkadia.org/drepper/dsohowto.pdf Program Library HOWTO: http://tldp.org/HOWTO/Program-Library-HOWTO/index.html Jan 18, 2011 Commenting out a range of lines in VIM Reference: http://vim.wikia.com/wiki/Commenting_out_a_range_of_lines   A -VISUAL BLOCK- can also be used to comment out lines.    Start by typing "Ctrl-V" and then highlight a strip downwards by hitting "down/j".   After that, type capital "I" to insert for all highlighted lines. Type the comment, in this case "#<Space>". Then hit "Esc". 
 ← Newer Page: 12 of 24 Older → (adsbygoogle = window.adsbygoogle || []).push({}); 
 
 Sometimes life is going to hit you in the head with a brick. Don't lose faith. Recent Posts How to terminate a C++ std::thread? My First Taste of Computational Stock Analysis Python - Run Command With Timeout Shared-memory Based Ring Buffer Coredump Decode (adsbygoogle = window.adsbygoogle || []).push({}); 
 
 © 2007-2018 Bo Yang. Powered by Jekyll   (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', '', 'auto'); ga('send', 'pageview');