1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-12 09:58:36 +00:00

Properly use .Nm, .Em, .Pa etc. Make usage() a simplier function.

This commit is contained in:
Philippe Charnier 2000-03-26 14:37:47 +00:00
parent eb257e6ec5
commit c097456602
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=58609
2 changed files with 60 additions and 45 deletions

View File

@ -57,7 +57,7 @@ environment variables like
.Xr env 1 .Xr env 1
and run a program with the selected resources. and run a program with the selected resources.
Three uses of the Three uses of the
.Nm limits .Nm
command are possible: command are possible:
.Pp .Pp
.Bl -hang -width indent .Bl -hang -width indent
@ -99,9 +99,9 @@ format, suitable for the calling shell.
The calling shell is determined by examining the entries in the The calling shell is determined by examining the entries in the
.Pa /proc .Pa /proc
filesystem for the parent process. filesystem for the parent process.
If the shell is known (ie. it is one of sh, csh, bash, tcsh, ksh, If the shell is known (i.e. it is one of sh, csh, bash, tcsh, ksh,
pdksh or rc), pdksh or rc),
.Nm limits .Nm
emits 'limit' or 'ulimit' commands in the format understood by emits 'limit' or 'ulimit' commands in the format understood by
that shell. that shell.
If the name of the shell cannot be determined, then the 'ulimit' If the name of the shell cannot be determined, then the 'ulimit'
@ -116,13 +116,13 @@ global configuration of maximum resource usage by maintaining a
central database of settings in the login class database. central database of settings in the login class database.
.Pp .Pp
Within a shell script, Within a shell script,
.Nm limits .Nm
will normally be used with eval within backticks as follows: will normally be used with eval within backticks as follows:
.Pp .Pp
.Dl eval `limits -e -C daemon` .Dl eval `limits -e -C daemon`
.Pp .Pp
which causes the output of which causes the output of
.Nm limits .Nm
to be evaluated and set by the current shell. to be evaluated and set by the current shell.
.El .El
.Pp .Pp
@ -140,7 +140,7 @@ If the user does not belong to a class, then the resource capabilities
for the "default" class are used, if it exists, or the "root" class if for the "default" class are used, if it exists, or the "root" class if
the user is a superuser account. the user is a superuser account.
.It Fl S .It Fl S
Selects display or setting of "soft" (or current) resource limits. Select display or setting of "soft" (or current) resource limits.
If specific limits settings follow this switch, only soft limits are If specific limits settings follow this switch, only soft limits are
affected unless overridden later with either the affected unless overridden later with either the
.Fl H .Fl H
@ -148,7 +148,7 @@ or
.Fl B .Fl B
flags. flags.
.It Fl H .It Fl H
Selects display or setting of "hard" (or maximum) resource limits. Select display or setting of "hard" (or maximum) resource limits.
If specific limits settings follow this switch, only hard limits are If specific limits settings follow this switch, only hard limits are
affected until overridden later with either the affected until overridden later with either the
.Fl S .Fl S
@ -156,7 +156,7 @@ or
.Fl B .Fl B
flags. flags.
.It Fl B .It Fl B
Selects display or setting of both "soft" (current) or "hard" (maximum) Select display or setting of both "soft" (current) or "hard" (maximum)
resource limits. resource limits.
If specific limits settings follow this switch, both soft and hard If specific limits settings follow this switch, both soft and hard
limits are affected until overridden later with either the limits are affected until overridden later with either the
@ -165,40 +165,40 @@ or
.Fl H .Fl H
flags. flags.
.Fl e .Fl e
Selects "eval mode" formatting for output. Select "eval mode" formatting for output.
This is valid only on display mode and cannot be used when running a This is valid only on display mode and cannot be used when running a
command. command.
The exact syntax used for output depends upon the type of shell from The exact syntax used for output depends upon the type of shell from
which which
.Nm limits .Nm
is invoked. is invoked.
.It Fl b Op Ar limit .It Fl b Op Ar limit
Selects or sets the Selects or sets the
.Em sbsize .Em sbsize
resource limit. resource limit.
.It Fl c Op Ar limit .It Fl c Op Ar limit
Selects or sets (if 'limit' is specified) the Select or set (if 'limit' is specified) the
.Em coredumpsize .Em coredumpsize
resource limit. resource limit.
A value of 0 disables core dumps. A value of 0 disables core dumps.
.It Fl d Op Ar limit .It Fl d Op Ar limit
Selects or sets (if 'limit' is specified) the Select or set (if 'limit' is specified) the
.Em datasize .Em datasize
resource limit. resource limit.
.It Fl f Op Ar limit .It Fl f Op Ar limit
Selects or sets the Select or set the
.Em filesize .Em filesize
resource limit. resource limit.
.It Fl l Op Ar limit .It Fl l Op Ar limit
Selects or sets the Select or set the
.Em memorylocked .Em memorylocked
resource limit. resource limit.
.It Fl m Op Ar limit .It Fl m Op Ar limit
Selects or sets the Select or set the
.Em memoryuse .Em memoryuse
size limit. size limit.
.It Fl n Op Ar limit .It Fl n Op Ar limit
Selects or sets the Select or set the
.Em openfiles .Em openfiles
resource limit. The system-wide limit on the maximum number of resource limit. The system-wide limit on the maximum number of
open files per process can be viewed using the 'sysctl kern.maxfilesperproc' open files per process can be viewed using the 'sysctl kern.maxfilesperproc'
@ -206,15 +206,15 @@ command. The total number of simultaneously open files in the entire
system is limited to the value displayed by the 'sysctl kern.maxfiles' system is limited to the value displayed by the 'sysctl kern.maxfiles'
command. command.
.It Fl s Op Ar limit .It Fl s Op Ar limit
Selects or sets the Select or set the
.Em stacksize .Em stacksize
resource limit. resource limit.
.It Fl t Op Ar limit .It Fl t Op Ar limit
Selects or sets the Select or set the
.Em cputime .Em cputime
resource limit. resource limit.
.It Fl u Op Ar limit .It Fl u Op Ar limit
Selects or sets the Select or set the
.Em maxproc .Em maxproc
resource limit. The system-wide limit on the maximum number of processes resource limit. The system-wide limit on the maximum number of processes
allowed per UID can be viewed using the 'sysctl kern.maxprocperuid' command. allowed per UID can be viewed using the 'sysctl kern.maxprocperuid' command.
@ -222,8 +222,16 @@ The maximum number of processes that can be running simultaneously
in the entire system is limited to the value given by in the entire system is limited to the value given by
the 'sysctl kern.maxproc' command. the 'sysctl kern.maxproc' command.
.Pp .Pp
Valid values for 'limit' in the above set of flags consist of either the Valid values for
string 'infinity' or 'inf' for an infinite (or kernel-defined maximum) .Ar limit
in the above set of flags consist of either the
string
.Em infinity ,
.Em inf ,
.Em unlimited
or
.Em unlimit
for an infinite (or kernel-defined maximum)
limit, or a numeric value maybe followed by a suffix. limit, or a numeric value maybe followed by a suffix.
Values which relate to size default to a value in bytes, or one of the Values which relate to size default to a value in bytes, or one of the
following suffixes may be used as a multiplier: following suffixes may be used as a multiplier:
@ -265,7 +273,7 @@ weeks.
The option The option
.Sq Fl E .Sq Fl E
causes causes
.Nm limits .Nm
to completely ignore the environment it inherits. to completely ignore the environment it inherits.
.It Fl a .It Fl a
This option forces all resource settings to be displayed even if This option forces all resource settings to be displayed even if
@ -282,17 +290,17 @@ call, only the superuser may raise process "hard" resource limits.
Non-root users may, however, lower them or change "soft" resource limits Non-root users may, however, lower them or change "soft" resource limits
within to any value below the hard limit. within to any value below the hard limit.
When invoked to execute a program, the failure of When invoked to execute a program, the failure of
.Nm limits .Nm
to raise a hard limit is considered a fatal error. to raise a hard limit is considered a fatal error.
.El .El
.Sh DIAGNOSTICS .Sh DIAGNOSTICS
.Nm Limits .Nm Limits
exits with EXIT_FAILURE if usage is incorrect in any way; ie. an invalid exits with EXIT_FAILURE if usage is incorrect in any way; i.e. an invalid
option, or set/display options are selected in the same invocation, option, or set/display options are selected in the same invocation,
.Fl e .Fl e
is used when running a program, etc. is used when running a program, etc.
When run in display or eval mode, When run in display or eval mode,
.Nm limits .Nm
exits with a status of EXIT_SUCCESS. exits with a status of EXIT_SUCCESS.
When run in command mode and execution of the command succeeds, the exit status When run in command mode and execution of the command succeeds, the exit status
will be whatever the executed program returns. will be whatever the executed program returns.
@ -311,18 +319,26 @@ will be whatever the executed program returns.
does not handle commands with equal (``='') signs in their does not handle commands with equal (``='') signs in their
names, for obvious reasons. names, for obvious reasons.
.Pp .Pp
When eval output is selected, the /proc filesystem must be installed When eval output is selected, the
.Pa /proc
filesystem must be installed
and mounted for the shell to be correctly determined, and therefore and mounted for the shell to be correctly determined, and therefore
output syntax correct for the running shell. output syntax correct for the running shell.
The default output is valid for /bin/sh, so this means that any The default output is valid for
.Pa /bin/sh ,
so this means that any
usage of usage of
.Nm limits .Nm
in eval mode prior mounting /proc may only occur in standard bourne in eval mode prior mounting
.Pa /proc
may only occur in standard bourne
shell scripts. shell scripts.
.Pp .Pp
.Nm Limits .Nm Limits
makes no effort to ensure that resource settings emitted or displayed makes no effort to ensure that resource settings emitted or displayed
are valid and settable by the current user. are valid and settable by the current user.
Only a superuser account may raise hard limits, and when doing so Only a superuser account may raise hard limits, and when doing so
the FreeBSD kernel will silently lower limits to values less than the
.Fx
kernel will silently lower limits to values less than
specified if the values given are too high. specified if the values given are too high.

View File

@ -214,7 +214,7 @@ static struct {
#define RCS_STRING "tfdscmlunb" #define RCS_STRING "tfdscmlunb"
static rlim_t resource_num(int which, int ch, const char *str); static rlim_t resource_num(int which, int ch, const char *str);
static void usage(const char *msg, ...); static void usage(void);
static int getshelltype(void); static int getshelltype(void);
static void print_limit(rlim_t limit, unsigned divisor, const char *inf, static void print_limit(rlim_t limit, unsigned divisor, const char *inf,
const char *pfx, const char *sfx, const char *which); const char *pfx, const char *sfx, const char *which);
@ -266,7 +266,8 @@ main(int argc, char *argv[])
if ((pwd = getpwnam(optarg)) == NULL) { if ((pwd = getpwnam(optarg)) == NULL) {
if (!isdigit(*optarg) || if (!isdigit(*optarg) ||
(pwd = getpwuid(atoi(optarg))) == NULL) { (pwd = getpwuid(atoi(optarg))) == NULL) {
usage("Invalid user `%s'\n", optarg); warnx("invalid user `%s'", optarg);
usage();
} }
} }
break; break;
@ -297,7 +298,7 @@ main(int argc, char *argv[])
} }
/* FALLTHRU */ /* FALLTHRU */
case '?': case '?':
usage(NULL); usage();
} }
optarg = NULL; optarg = NULL;
} }
@ -377,8 +378,10 @@ main(int argc, char *argv[])
* (perhaps) set environment variables and run a program * (perhaps) set environment variables and run a program
*/ */
if (*argv) { if (*argv) {
if (doeval) if (doeval) {
usage("-e cannot be used with `cmd' option\n"); warnx("-e cannot be used with `cmd' option");
usage();
}
login_close(lc); login_close(lc);
@ -394,7 +397,7 @@ main(int argc, char *argv[])
} }
if (*argv == NULL) if (*argv == NULL)
usage(NULL); usage();
execvp(*argv, argv); execvp(*argv, argv);
err(1, "%s", *argv); err(1, "%s", *argv);
@ -450,14 +453,8 @@ main(int argc, char *argv[])
static void static void
usage(char const *msg, ...) usage(void)
{ {
if (msg) {
va_list argp;
va_start(argp, msg);
vfprintf(stderr, msg, argp);
va_end(argp);
}
(void)fprintf(stderr, (void)fprintf(stderr,
"usage: limits [-C class|-U user] [-eaSHBE] [-bcdflmnstu [val]] [[name=val ...] cmd]\n"); "usage: limits [-C class|-U user] [-eaSHBE] [-bcdflmnstu [val]] [[name=val ...] cmd]\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -567,8 +564,10 @@ resource_num(int which, int ch, const char *str)
s = e; s = e;
break; break;
} }
if (*s) if (*s) {
usage("invalid value -%c `%s'\n", ch, str); warnx("invalid value -%c `%s'", ch, str);
usage();
}
} }
return res; return res;
} }