rmvolmgr.c revision 44991a1c1bb35cccb6bf99cb6dce14864dcee19c
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* rmvolmgr daemon
*/
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
#include <strings.h>
#include <errno.h>
#include <libintl.h>
#include <libscf.h>
#include <priv_utils.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <libhal.h>
#include "rmm_common.h"
char *progname = "rmvolmgr";
#define RMVOLMGR_FMRI "svc:/system/filesystem/rmvolmgr:default"
typedef struct managed_volume {
char *udi;
struct action_arg aa;
static GSList *managed_volumes;
static LibHalContext *hal_ctx;
static int sigexit_pipe[2];
static GIOChannel *sigexit_ioch;
/* SMF property "eject_button" */
static void get_smf_properties();
static void rmm_mount_all();
static void rmm_unmount_all();
static void
usage()
{
}
static int
{
const char *opts = "chnsv";
int c;
switch (c) {
case 'c':
break;
case 'n':
break;
case 's':
break;
case 'v':
rmm_debug = 1;
break;
case '?':
case 'h':
usage();
return (0);
default:
usage();
return (1);
}
}
if (opt_s) {
if (geteuid() != 0) {
gettext("system instance must have euid 0\n"));
return (1);
}
if (opt_c) {
}
if (opt_n) {
}
/*
* Drop unused privileges. Remain root for HAL interaction
* and to create legacy symlinks.
*
* Need PRIV_FILE_DAC_WRITE to write to users'
*/
0, 0,
NULL) == -1) {
gettext("failed to drop privileges"));
return (1);
}
/* basic privileges we don't need */
NULL);
} else {
if (opt_c) {
}
if (opt_n) {
}
}
return (1);
}
if (opt_s) {
}
/*
* signal mainloop integration using pipes
*/
if (pipe(sigexit_pipe) != 0) {
return (1);
}
if (sigexit_ioch == NULL) {
dprintf("g_io_channel_unix_new failed\n");
return (1);
}
return (1);
}
/* user instance should claim devices */
if (!opt_s) {
gettext("cannot claim branch\n"));
return (1);
}
}
dprintf("Cannot create main loop\n");
return (1);
}
return (0);
}
static void
{
rmm_vold_mountpoints_enabled = (*val != 0);
}
}
rmm_vold_actions_enabled = (*val != 0);
}
}
rmm_prop_eject_button = (*val != 0);
}
}
}
/* ARGSUSED */
static void
{
}
/* ARGSUSED */
static gboolean
{
return (TRUE);
}
dprintf("signal to exit\n");
return (TRUE);
}
static managed_volume_t *
{
managed_volume_t *v;
return (NULL);
}
free(v);
return (NULL);
}
free(v);
return (NULL);
}
return (v);
}
static void
{
rmm_volume_aa_free(&v->aa);
free(v);
}
static gint
{
const managed_volume_t *va = a;
const char *udi = b;
}
static boolean_t
volume_should_mount(const char *udi)
{
char *storage_device = NULL;
"volume.ignore", NULL)) {
goto out;
}
/* get the backing storage device */
goto out;
}
/* we handle either removable or hotpluggable */
"storage.removable", NULL) &&
goto out;
}
/* ignore if claimed by another volume manager */
goto out;
}
out:
return (ret);
}
static void
volume_added(const char *udi)
{
GSList *l;
managed_volume_t *v;
if (v != NULL) {
return;
}
if (!volume_should_mount(udi)) {
return;
}
return;
}
} else {
rmm_managed_free(v);
}
}
static void
volume_removed(const char *udi)
{
GSList *l;
managed_volume_t *v;
if (v == NULL) {
return;
}
/* HAL will unmount, just do the vold legacy stuff */
rmm_managed_free(v);
}
/* ARGSUSED */
static void
{
}
}
/* ARGSUSED */
static void
{
}
}
/* ARGSUSED */
static void
{
GSList *l;
managed_volume_t *v;
return;
}
if (is_mounted) {
if (v != NULL) {
/* volume mounted by us is already taken care of */
if (v->my) {
return;
}
} else {
return;
}
}
} else {
if (v == NULL) {
return;
}
rmm_managed_free(v);
}
}
static void
storage_eject_pressed(const char *udi)
{
/* ignore if disabled via SMF or claimed by another volume manager */
if (!rmm_prop_eject_button ||
NULL)) {
return;
}
}
/* ARGSUSED */
static void
{
}
}
/*
* Mount all mountable volumes
*/
static void
{
int num_udis;
int i;
managed_volume_t *v;
/* get all volumes */
dprintf("mount_all: no volumes found\n");
goto out;
}
for (i = 0; i < num_udis; i++) {
/* skip if already mounted */
"volume.is_mounted", NULL)) {
continue;
}
if (!volume_should_mount(udis[i])) {
continue;
}
continue;
}
} else {
rmm_managed_free(v);
}
}
out:
}
}
/*
* Mount all volumes mounted by this program
*/
static void
{
GSList *i;
managed_volume_t *v;
v = (managed_volume_t *)i->data;
"volume.is_mounted", NULL)) {
&v->aa, 0, 0, 0);
}
rmm_managed_free(v);
}
}
int
{
}