vold_action.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 <stdlib.h>
#include <string.h>
#include <pwd.h>
#include <unistd.h>
#include <sys/resource.h>
#include <regex.h>
#include <errno.h>
#include "vold.h"
/*
* Declarations of externally defined functions
*/
/*
* Volume Daemon action support.
*/
typedef struct action {
char *a_re; /* original regex */
} action_t;
struct q reapq;
char *actnames[] = {
{ "" },
{ "insert" },
{ "eject" },
{ "notify" },
{ "error" },
{ "remount" },
{ "close" },
};
/*
* length of buffer used to create environment variables
*/
#define VOLD_ENVBUFLEN 512
/*
* length of buffer for printing numbers
*/
#define VOLD_NUMBUFLEN 512
int
{
char *path;
int nacts;
int re_ret;
#ifdef DEBUG
#endif
switch (act) {
case ACT_NOTIFY:
break;
case ACT_INSERT:
break;
case ACT_EJECT:
break;
case ACT_ERROR:
break;
case ACT_REMOUNT:
break;
case ACT_CLOSE:
break;
default:
return (0);
}
}
return (0);
}
nacts = 0;
0)) == REG_OK) {
nacts++;
} else if (re_ret != REG_NOMATCH) {
debug(1,
"action: can't compare RE \"%s\" to \"%s\" (ret %d)\n",
}
}
}
if (act != ACT_NOTIFY) {
}
return (nacts);
}
/*
* Add a new action
*/
{
int regcomp_ret;
switch (act) {
case ACT_NOTIFY:
break;
case ACT_INSERT:
break;
case ACT_EJECT:
break;
case ACT_ERROR:
break;
case ACT_REMOUNT:
break;
default:
return (FALSE);
}
/* compile the regular expression */
re, regcomp_ret);
free(a);
return (FALSE);
}
/* stick it on our list */
*list = a;
} else {
*list = a;
}
return (TRUE);
}
/*
* Remove all actions.
*/
static void
{
action_t *a;
int i;
free(a);
}
}
}
}
void
action_flush(void)
{
/* flush 'insert' events */
/* flush 'notify' events */
/* flush 'eject' events */
/* flush 'action error' events */
/* flush 'action remount' events */
}
static void
{
struct reap *r;
r->r_v = v;
}
static int
{
extern int errno;
/* about to launch an ejection action */
v->v_eject++;
}
/* child */
/*
* the execution of binaries running in BCP mode.
* Since the daemon increases the number of available
* file descriptors, they need to be reset here or it
* screws up old binaries that couldn't support as many
* fd's.
*/
perror("vold; setrlimit");
}
#ifdef DEBUG_EXECS
#endif
exit(0);
} else if (pid == -1) {
v->v_eject--;
return (1);
} else {
}
return (0);
}
static void
{
extern char *dev_getpath(dev_t);
static void vol_putenv(char *);
char *user;
char *symname;
/*
* Since we only do this in the child,
* we don't worry about losing the memory we're
* about to allocate.
*/
switch (v->v_fstype) {
case V_HSFS:
"VOLUME_FSTYPE=%s", "HSFS");
break;
case V_PCFS:
"VOLUME_FSTYPE=%s", "PCFS");
break;
case V_UDFS:
"VOLUME_FSTYPE=%s", "UDFS");
break;
case V_UFS:
"VOLUME_FSTYPE=%s", "UFS");
break;
default:
"VOLUME_FSTYPE=%s", "UNKNOWN");
}
/*
* mount mode can be one of the following
* rw: read write
* ro: read only
* pp: password protected (can't mount)
* pw: password protected for write only (mount ro)
*/
"VOLUME_MOUNT_MODE=%s", v->v_mount_mode);
/* do not use pcfs id for floppies */
/*
* we have pcfs with fdisk,
*/
"VOLUME_PCFS_ID=%s", v->v_pcfs_part_id);
} else {
/*
* Must create VOLUME_PCFS_ID as null to be sure a previous
* value is not around for rmmount
*/
}
"VOLUME_SYMDEV=%s", symname);
} else {
vol_putenv("VOLUME_SYMDEV=");
}
} else {
vol_putenv("VOLUME_DEVICE=");
vol_putenv("VOLUME_SYMDEV=");
}
} else {
}
"VOLUME_USER=%s", user);
#ifdef VOLMGT_DEV_TO_TTY_WORKED
/*
* Converting a dev_t into a path name is a very
* expensive operation, so we only do it if the
* user has told us to by sticking the maptty
* flag on his action.
*/
} else {
vol_putenv("VOLUME_USERTTY=");
}
#else /* VOLMGT_DEV_TO_TTY_WORKED */
/* devtotty() has some bugs right now */
#endif /* VOLMGT_DEV_TO_TTY_WORKED */
} else {
vol_putenv("VOLUME_USER=");
vol_putenv("VOLUME_USERTTY=");
}
"VOLUME_MEDIATYPE=%s", v->v_mtype);
if (v->v_ej_force == TRUE) {
vol_putenv("VOLUME_FORCEDEJECT=true");
} else {
vol_putenv("VOLUME_FORCEDEJECT=false");
}
}
static void
vol_putenv(char *env_str)
{
#ifdef DEBUG
#endif
}