1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1982-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * David Korn <dgk@research.att.com> *
19 ***********************************************************************/
22 * ulimit [-HSacdfmnstuv] [limit]
37 # define SH_DICT "libshell"
41 int b_ulimit(int argc
,char *argv
[],void *extra
)
46 errormsg(SH_DICT
,ERROR_exit(2),e_nosupport
);
51 static int infof(Opt_t
* op
, Sfio_t
* sp
, const char* s
, Optdisc_t
* dp
)
53 register const Limit_t
* tp
;
55 for (tp
= shtab_limits
; tp
->option
; tp
++)
57 sfprintf(sp
, "[%c=%d:%s?The %s", tp
->option
, tp
- shtab_limits
+ 1, tp
->name
, tp
->description
);
58 if(tp
->type
!= LIM_COUNT
)
59 sfprintf(sp
, " in %ss", e_units
[tp
->type
]);
68 int b_ulimit(int argc
,char *argv
[],void *extra
)
71 register int mode
=0, n
;
72 register unsigned long hit
= 0;
73 Shell_t
*shp
= ((Shbltin_t
*)extra
)->shp
;
76 #endif /* _lib_getrlimit */
79 int label
, unit
, nosupport
;
83 memset(&disc
, 0, sizeof(disc
));
84 disc
.version
= OPT_VERSION
;
86 opt_info
.disc
= &disc
;
87 while((n
= optget(argv
,sh_optulimit
))) switch(n
)
100 hit
|= (1L<<(-(n
+1)));
102 errormsg(SH_DICT
,2, e_notimp
, opt_info
.name
);
105 errormsg(SH_DICT
,2, "%s", opt_info
.arg
);
108 errormsg(SH_DICT
,ERROR_usage(2), "%s", opt_info
.arg
);
113 limit
= argv
[opt_info
.index
];
115 for(n
=0; shtab_limits
[n
].option
; n
++)
116 if(shtab_limits
[n
].index
== RLIMIT_FSIZE
)
121 /* only one option at a time for setting */
122 label
= (hit
&(hit
-1));
123 if(error_info
.errors
|| (limit
&& label
) || argc
>opt_info
.index
+1)
124 errormsg(SH_DICT
,ERROR_usage(2),optusage((char*)0));
127 for(tp
= shtab_limits
; tp
->option
&& hit
; tp
++,hit
>>=1)
131 nosupport
= (n
= tp
->index
) == RLIMIT_UNKNOWN
;
132 unit
= shtab_units
[tp
->type
];
135 if(shp
->subshell
&& !shp
->subshare
)
137 if(strcmp(limit
,e_unlimited
)==0)
142 if((i
=sh_strnum(limit
,&last
,2))==INFINITY
|| *last
)
143 errormsg(SH_DICT
,ERROR_system(1),e_number
,limit
);
147 errormsg(SH_DICT
,ERROR_system(1),e_readonly
,tp
->name
);
150 #ifdef _lib_getrlimit
151 if(getrlimit(n
,&rlp
) <0)
152 errormsg(SH_DICT
,ERROR_system(1),e_number
,limit
);
157 if(setrlimit(n
,&rlp
) <0)
158 errormsg(SH_DICT
,ERROR_system(1),e_overlimit
,limit
);
160 if((i
=vlimit(n
,i
)) < 0)
161 errormsg(SH_DICT
,ERROR_system(1),e_number
,limit
);
162 #endif /* _lib_getrlimit */
169 #ifdef _lib_getrlimit
170 if(getrlimit(n
,&rlp
) <0)
171 errormsg(SH_DICT
,ERROR_system(1),e_number
,limit
);
179 # endif /* _lib_ulimit */
181 if((i
=vlimit(n
,i
)) < 0)
182 errormsg(SH_DICT
,ERROR_system(1),e_number
,limit
);
183 #endif /* _lib_getrlimit */
187 if(tp
->type
!= LIM_COUNT
)
188 sfsprintf(tmp
,sizeof(tmp
),"%s (%ss)", tp
->description
, e_units
[tp
->type
]);
190 sfsprintf(tmp
,sizeof(tmp
),"%s", tp
->name
);
191 sfprintf(sfstdout
,"%-30s (-%c) ",tmp
,tp
->option
);
195 if(!tp
->conf
|| !*(conf
= astconf(tp
->conf
, NiL
, NiL
)))
196 conf
= (char*)e_nosupport
;
197 sfputr(sfstdout
,conf
,'\n');
202 sfprintf(sfstdout
,"%I*d\n",sizeof(i
),i
/unit
);
205 sfputr(sfstdout
,e_unlimited
,'\n');
210 #endif /* _no_ulimit */