home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / unix / volume07 / csh.pch < prev    next >
Encoding:
Text File  |  1988-09-11  |  7.6 KB  |  307 lines

  1. Subject:  v07i094:  Two CSH patches
  2. Newsgroups: mod.sources
  3. Approved: mirror!rs
  4.  
  5. Submitted by: Arnold D. Robbins <emoryu1!arnold>
  6. Mod.sources: Volume 7, Issue 94
  7. Archive-name: csh.patch
  8.  
  9. [  These changes slip right into the 4.2 CSH also.  --r$  ]
  10.  
  11. Here are context diffs for changes I have made to the 4.3 csh. There are two
  12. changes. 1) If it is a login shell, the csh will read the file /etc/login
  13. before reading either ~/.chsrc or ~/.login. This allows the system administrator
  14. to do global stuff in one file. It is very useful in my environment.
  15.  
  16. The second change is a new csh variable, 'autologout', which, if set, is the
  17. number of minutes the csh will wait when prompting, before timing out. We use
  18. it to keep idle users from tieing up our ports.
  19.  
  20. Enjoy,
  21.  
  22. Arnold Robbins
  23. CSNET:    arnold@emory    BITNET:    arnold@emoryu1
  24. ARPA:    arnold%emory.csnet@csnet-relay.arpa
  25. UUCP:    { akgua, decvax, gatech, sb1, sb6, sunatl }!emory!arnold
  26. One of these days:    arnold@EMORY.EDU
  27. ---- copy the csh man page to /usr/src/bin/csh, cut here, feed to patch ------
  28. RCS file: RCS/csh.1,v
  29. retrieving revision 1.1
  30. diff -c -r1.1 csh.1
  31. *** /tmp/,RCSt1006418    Wed Oct 22 17:10:28 1986
  32. --- csh.1    Wed Oct 22 17:07:53 1986
  33. ***************
  34. *** 1,7 ****
  35.   .\"
  36. ! .\" $Header: csh.1,v 1.1 86/10/22 16:55:48 root Exp $
  37.   .\" 
  38.   .\" $Log:    csh.1,v $
  39.   .\" Revision 1.1  86/10/22  16:55:48  root
  40.   .\" Initial revision
  41.   .\" 
  42. --- 1,10 ----
  43.   .\"
  44. ! .\" $Header: csh.1,v 1.2 86/10/22 16:57:22 root Locked $
  45.   .\" 
  46.   .\" $Log:    csh.1,v $
  47. + .\" Revision 1.2  86/10/22  16:57:22  root
  48. + .\" Documented /etc/login and autologout variable. ADR.
  49. + .\" 
  50.   .\" Revision 1.1  86/10/22  16:55:48  root
  51.   .\" Initial revision
  52.   .\" 
  53. ***************
  54. *** 66,71 ****
  55. --- 69,88 ----
  56.   .IR tset (1)
  57.   there.
  58.   .PP
  59. + .B NOTE:
  60. + The
  61. + .I csh
  62. + has been modified locally to read the file
  63. + .B /etc/login
  64. + as the very first file it reads, if it is a login shell.
  65. + This happens
  66. + .I before
  67. + reading the user's `.cshrc' and `.login' files.
  68. + After
  69. + .B /etc/login
  70. + has been read, the other `dot' files are processed as described
  71. + in the previous paragraph.
  72. + .PP
  73.   In the normal case, the shell will then begin reading commands from the
  74.   terminal, prompting with `% '.
  75.   Processing of arguments and the use of the shell to process files
  76. ***************
  77. *** 1890,1895 ****
  78. --- 1907,1924 ----
  79.   positional parameters are substituted, i.e. `$1' is replaced by
  80.   `$argv[1]', etc.
  81.   .TP 15
  82. + .B autologout
  83. + \c
  84. + If set by the user, contains the number of
  85. + .I minutes
  86. + that the shell should wait for input, when it is prompting.
  87. + If that number of minutes passes without any input being read, the shell
  88. + will timeout and exit.
  89. + (This is most conveniently set in
  90. + .B /etc/login
  91. + by the system administrator to prevent idle users from tieing up
  92. + scarce terminal lines.)
  93. + .TP 15
  94.   .B cdpath
  95.   \c
  96.   Gives a list of alternate directories searched to find subdirectories
  97. ***************
  98. *** 2249,2254 ****
  99. --- 2278,2284 ----
  100.   .SH FILES
  101.   .ta 1.75i
  102.   .nf
  103. + /etc/login    Read at beginning of execution by login shell, before `.cshrc'.
  104.   ~/.cshrc    Read at beginning of execution by each shell.
  105.   ~/.login    Read by login shell, after `.cshrc' at login.
  106.   ~/.logout    Read by login shell, at logout.
  107. RCS file: RCS/sh.c,v
  108. retrieving revision 1.1
  109. diff -c -r1.1 sh.c
  110. *** /tmp/,RCSt1006913    Wed Oct 22 17:56:12 1986
  111. --- sh.c    Wed Oct 22 17:53:41 1986
  112. ***************
  113. *** 1,9 ****
  114.   #ifndef lint
  115. ! static char *RCSid = "$Header: sh.c,v 1.1 86/08/11 12:10:26 root Exp $";
  116.   #endif
  117.   
  118.   /*
  119.    * $Log:    sh.c,v $
  120.    * Revision 1.1  86/08/11  12:10:26  root
  121.    * Initial revision
  122.    * 
  123. --- 1,12 ----
  124.   #ifndef lint
  125. ! static char *RCSid = "$Header: sh.c,v 1.2 86/09/22 15:05:12 root Locked $";
  126.   #endif
  127.   
  128.   /*
  129.    * $Log:    sh.c,v $
  130. +  * Revision 1.2  86/09/22  15:05:12  root
  131. +  * Changes to support /etc/login reading upon startup. ADR.
  132. +  * 
  133.    * Revision 1.1  86/08/11  12:10:26  root
  134.    * Initial revision
  135.    * 
  136. ***************
  137. *** 34,39 ****
  138. --- 37,43 ----
  139.   char    *pathlist[] =    { ".", "/usr/ucb", "/bin", "/usr/bin", 0 };
  140.   char    *dumphist[] =    { "history", "-h", 0, 0 };
  141.   char    *loadhist[] =    { "source", "-h", "~/.history", 0 };
  142. + char    *etclogin[] =    { "source", "/etc/login", 0 };
  143.   char    HIST = '!';
  144.   char    HISTSUB = '^';
  145.   bool    nofile;
  146. ***************
  147. *** 332,337 ****
  148. --- 336,343 ----
  149.       haderr = 0;        /* In case second time through */
  150.       if (!fast && reenter == 0) {
  151.           reenter++;
  152. +         if (loginsh)
  153. +             dosource(etclogin);    /* ADR */
  154.           /* Will have value("home") here because set fast if don't */
  155.           srccat(value("home"), "/.cshrc");
  156.           if (!fast && !arginp && !onelflg && !havhash)
  157. ===================================================================
  158. RCS file: RCS/sh.lex.c,v
  159. retrieving revision 1.1
  160. diff -c -r1.1 sh.lex.c
  161. *** /tmp/,RCSt1006913    Wed Oct 22 17:56:19 1986
  162. --- sh.lex.c    Wed Oct 22 17:53:40 1986
  163. ***************
  164. *** 1,9 ****
  165.   #ifndef lint
  166. ! static char *RCSid = "$Header: sh.lex.c,v 1.1 86/09/22 13:54:31 root Exp $";
  167.   #endif
  168.   
  169.   /*
  170.    * $Log:    sh.lex.c,v $
  171.    * Revision 1.1  86/09/22  13:54:31  root
  172.    * Initial revision
  173.    * 
  174. --- 1,12 ----
  175.   #ifndef lint
  176. ! static char *RCSid = "$Header: sh.lex.c,v 1.2 86/09/22 15:05:44 root Locked $";
  177.   #endif
  178.   
  179.   /*
  180.    * $Log:    sh.lex.c,v $
  181. +  * Revision 1.2  86/09/22  15:05:44  root
  182. +  * Changes to support autologout. ADR.
  183. +  * 
  184.    * Revision 1.1  86/09/22  13:54:31  root
  185.    * Initial revision
  186.    * 
  187. ***************
  188. *** 21,27 ****
  189. --- 24,34 ----
  190.   
  191.   #include "sh.h"
  192.   #include <sgtty.h>
  193. + #include <signal.h>
  194.   
  195. + #define ON    1    /* for autlogoff code -- ADR */
  196. + #define OFF    0
  197.   /*
  198.    * C shell
  199.    */
  200. ***************
  201. *** 1228,1239 ****
  202. --- 1235,1250 ----
  203.           off = (int) feobp % BUFSIZ;
  204.   #ifndef FILEC
  205.           for (;;) {
  206. +             autologoff (ON);
  207.               c = read(SHIN, fbuf[buf] + off, BUFSIZ - off);
  208. +             autologoff (OFF);
  209.   #else
  210.           roomleft = BUFSIZ - off;
  211.           for (;;) {
  212. +             autologoff (ON);
  213.               if (filec && intty) {
  214.                   c = numleft ? numleft : tenex(ttyline, BUFSIZ);
  215. +                 autologoff (OFF);
  216.                   if (c > roomleft) {
  217.                       /* start with fresh buffer */
  218.                       feobp = fseekp = fblocks * BUFSIZ;
  219. ***************
  220. *** 1245,1250 ****
  221. --- 1256,1262 ----
  222.                   numleft = 0;
  223.               } else
  224.                   c = read(SHIN, fbuf[buf] + off, roomleft);
  225. +             autologoff (OFF);
  226.   #endif
  227.               if (c >= 0)
  228.                   break;
  229. ***************
  230. *** 1346,1348 ****
  231. --- 1358,1389 ----
  232.       cantell = 1;
  233.   }
  234.   #endif
  235. + static bombout ()
  236. + {
  237. +     exiterr = 1;        /* kludge to force exit in error() */
  238. +     error ("shell timeout");
  239. + }
  240. + static autologoff (whichway)
  241. + int whichway;
  242. + {
  243. +     char *cp = value ("autologout");
  244. +     int minutes = 0;
  245. +     static int first = 1;
  246. +     if (whichway == OFF) {
  247. +         alarm (0);
  248. +         return;
  249. +     }
  250. +     if (cp && *cp && (minutes = atoi (cp))) {
  251. +         if (first) {
  252. +             signal (SIGALRM, bombout);
  253. +             first = 0;
  254. +         }
  255. +         if (whichway == ON)
  256. +             alarm (minutes * 60);
  257. +     }
  258. + }
  259. ===================================================================
  260. RCS file: RCS/sh.set.c,v
  261. retrieving revision 1.1
  262. diff -c -r1.1 sh.set.c
  263. *** /tmp/,RCSt1006913    Wed Oct 22 17:56:28 1986
  264. --- sh.set.c    Wed Oct 22 17:53:38 1986
  265. ***************
  266. *** 1,9 ****
  267.   #ifndef lint
  268. ! static char *RCSid = "$Header: sh.set.c,v 1.1 86/09/22 14:28:54 root Exp $";
  269.   #endif
  270.   
  271.   /*
  272.    * $Log:    sh.set.c,v $
  273.    * Revision 1.1  86/09/22  14:28:54  root
  274.    * Initial revision
  275.    * 
  276. --- 1,12 ----
  277.   #ifndef lint
  278. ! static char *RCSid = "$Header: sh.set.c,v 1.2 86/09/22 15:06:29 root Locked $";
  279.   #endif
  280.   
  281.   /*
  282.    * $Log:    sh.set.c,v $
  283. +  * Revision 1.2  86/09/22  15:06:29  root
  284. +  * Changes to support autologout. ADR.
  285. +  * 
  286.    * Revision 1.1  86/09/22  14:28:54  root
  287.    * Initial revision
  288.    * 
  289. ***************
  290. *** 446,451 ****
  291. --- 449,456 ----
  292.           HIST = '!';
  293.           HISTSUB = '^';
  294.       }
  295. +     if (adrof("autologout") == 0)
  296. +         alarm (0);
  297.   #ifdef FILEC
  298.       if (adrof("filec") == 0)
  299.           filec = 0;
  300.  
  301.