coreadm.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <fcntl.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>
#include <libintl.h>
#include <locale.h>
#include <libproc.h>
#define E_SUCCESS 0 /* Exit status for success */
static const char PATH_CONFIG[] = "/etc/coreadm.conf";
#define CF_OWNER 0 /* Uid 0 (root) */
static char *command;
static char *glob_pattern;
static char *init_pattern;
static char *proc_pattern;
static int enable;
static int disable;
static int report_settings(void);
static int do_processes(int, char **);
static int do_modify(void);
static int do_update(void);
static int write_config(int);
static void
usage(void)
{
"usage:\n"));
" %s [ -g pattern ] [ -i pattern ] [ -G content ] [ -I content ]\n"),
command);
" [ -e {global | process | global-setid | proc-setid | log} ]\n"));
" [ -d {global | process | global-setid | proc-setid | log} ]\n"));
" %s [ -p pattern ] [ -P content ] [ pid ... ]\n"), command);
" %s -u\n"), command);
}
static int
perm(void)
{
"exercise the -[GIgiedu] options\n"), command);
return (E_USAGE);
}
int
{
int flag;
int opt;
int modify;
int update = 0;
int error = 0;
int npids;
char **pidlist;
char curpid[11];
char *curpid_ptr = &curpid[0];
(void) textdomain(TEXT_DOMAIN);
/* command name (e.g., "coreadm") */
command++;
else
switch (opt) {
case 'g':
break;
case 'i':
break;
case 'p':
break;
case 'G':
"content string '%s'\n"), optarg);
error = 1;
}
break;
case 'I':
"content string '%s'\n"), optarg);
error = 1;
}
break;
case 'P':
"content string '%s'\n"), optarg);
error = 1;
}
break;
case 'e':
case 'd':
else {
flag = 0;
error = 1;
}
if (opt == 'e') {
} else {
}
break;
case 'u':
update = 1;
break;
case '?':
default:
error = 1;
break;
}
}
if (error)
usage();
/*
* If 'modify' is true, we must modify the system settings
* and update the configuration file with the new parameters.
*/
"%s: the -u option must stand alone\n"),
command);
usage();
}
if (modify &&
"%s: -[GIgied] and -[Pp] options are mutually exclusive\n"),
command);
usage();
}
"%s: -[GIgied] options cannot have a process-id list\n"),
command);
usage();
}
npids == 0) {
npids = 1;
pidlist = &curpid_ptr;
}
if (update)
return (do_update());
if (modify)
return (do_modify());
if (npids != 0)
return (report_settings());
}
static int
report_settings(void)
{
int options;
char global_path[PATH_MAX];
char content_str[80];
perror("core_get_options()");
return (E_ERROR);
}
perror("core_get_global_path()");
return (E_ERROR);
}
perror("core_get_default_path()");
return (E_ERROR);
}
if (core_get_global_content(&gcontent) != 0) {
perror("core_get_global_content()");
return (E_ERROR);
}
if (core_get_default_content(&icontent) != 0) {
perror("core_get_default_content()");
return (E_ERROR);
}
return (E_SUCCESS);
}
static int
{
char process_path[PATH_MAX];
char *next;
char content_str[80];
while (npids-- > 0) {
gettext("%s: invalid process-id\n"),
*pidlist);
} else if (core_get_process_path(process_path,
sizeof (process_path), pid) != 0 ||
} else {
sizeof (content_str));
}
pidlist++;
}
} else {
while (npids-- > 0) {
if (*next != '\0') {
gettext("%s: invalid process-id\n"),
*pidlist);
} else {
if (proc_pattern != NULL &&
}
if (proc_content != CC_CONTENT_INVALID &&
&proc_content, pid) != 0) {
}
}
pidlist++;
}
}
return (rc);
}
static int
do_modify(void)
{
int options;
perror("core_get_options()");
return (E_ERROR);
}
if (core_set_options(options) != 0) {
return (perm());
perror("core_set_options()");
return (E_ERROR);
}
if (glob_pattern != NULL &&
return (perm());
perror("core_set_global_path()");
return (E_ERROR);
}
if (glob_content != CC_CONTENT_INVALID &&
core_set_global_content(&glob_content) != 0) {
return (perm());
perror("core_set_global_content()");
return (E_ERROR);
}
if (init_pattern != NULL &&
return (perm());
perror("core_set_default_path()");
return (E_ERROR);
}
if (init_content != CC_CONTENT_INVALID &&
core_set_default_content(&init_content) != 0) {
return (perm());
perror("core_set_default_content()");
return (E_ERROR);
}
return (write_config(0));
}
/*
* BUFSIZE must be large enough to contain the longest path plus some more.
*/
static int
{
return (1);
return (0);
"\"%s\", line %d: warning: value must be yes or no: %s=%s\n"),
return (0);
}
static int
do_update(void)
{
int line;
int options;
int n;
int len;
/* defaults */
gpattern[0] = '\0';
/*
* No config file, just accept the current settings.
*/
return (write_config(1));
}
/*
* Skip comment lines and empty lines.
*/
continue;
/*
* Look for "name=value", with optional whitespace on either
* side, terminated by a newline, and consuming the whole line.
*/
/* LINTED - unbounded string specifier */
if (n == 1)
value[0] = '\0';
continue;
}
continue;
}
continue;
}
continue;
}
continue;
}
else
options &= ~CC_PROCESS_PATH;
continue;
}
continue;
}
continue;
}
options |= CC_GLOBAL_LOG;
continue;
}
"\"%s\", line %d: warning: invalid token: %s\n"),
} else {
gettext("\"%s\", line %d: syntax error\n"),
PATH_CONFIG, line);
}
}
if (core_set_options(options) != 0) {
return (perm());
perror("core_set_options()");
return (E_ERROR);
}
return (perm());
perror("core_set_global_path()");
return (E_ERROR);
}
return (perm());
perror("core_set_default_path()");
return (E_ERROR);
}
if (core_set_global_content(&gcontent) != 0) {
return (perm());
perror("core_set_global_content()");
return (E_ERROR);
}
if (core_set_default_content(&icontent) != 0) {
return (perm());
perror("core_set_default_content()");
return (E_ERROR);
}
return (write_config(1));
}
static int
write_config(int justtry)
{
int fd;
int options;
char global_path[PATH_MAX];
char content_str[PRCONTENTBUFSZ];
CF_PERM)) == -1) {
/*
* If we're updating the kernel settings from the contents
* of the config file, it's not essential that we rewrite
* that file.
*/
if (justtry)
return (E_SUCCESS);
return (E_SUCCESS);
}
return (E_ERROR);
}
perror("core_get_options()");
goto err;
}
perror("core_get_global_path()");
goto err;
}
perror("core_get_default_path()");
goto err;
}
if (core_get_global_content(&gcontent) != 0) {
perror("core_get_global_content()");
goto err;
}
if (core_get_default_content(&icontent) != 0) {
perror("core_get_default_content()");
goto err;
}
gettext("failed to open stream for %s: %s\n"),
goto err;
}
(void) fputs(
"#\n"
"# coreadm.conf\n"
"#\n"
"# Parameters for system core file configuration.\n"
"# Do NOT edit this file by hand -- use coreadm(1) instead.\n"
"#\n",
fp);
return (0);
err:
return (E_ERROR);
}