action_workman.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 (c) 1998 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* if this cdrom has audio tracks, start up workman
*/
#include <malloc.h>
#include <sys/systeminfo.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <pwd.h>
#include <limits.h>
#include <signal.h>
#include <string.h>
#include <libintl.h>
#include <rmmount.h>
#include <volmgt.h>
static void setup_user(void);
static void set_user_env(int, char **);
static void add_to_args(int *, char ***, int, char **);
static void clean_args(int *, char **);
/* for debug messages -- from rmmount */
extern char *prog_name;
/* name of the config file */
extern char *rmm_config;
#ifdef DEBUG
static void print_args(char *, int, char **);
#endif
int
{
struct cdrom_tochdr th;
struct cdrom_tocentry te;
uchar_t i;
int fd;
int found_audio = FALSE;
extern char *rmm_dsodir;
/* we don't care about removes, just inserts */
goto dun;
}
/*
* XXX if we have a mounted file system, for now
* we do not want to run workman
*/
/* can't do anything without a path */
dprintf("action_workman: no rawpath\n");
goto dun;
}
/* ensure something to exec was passed in */
if (argc < 2) {
"%s(%d) error: workman pathname not supplied in %s\n"),
goto dun;
}
/* open the device and read the table of contents */
dprintf("action_workman: open failed; %m\n");
goto dun;
}
dprintf("action_workman: ioctl failed; %m\n");
goto dun;
}
te.cdte_track = i;
/* can't read an entry -- just try the next */
continue;
}
found_audio = TRUE;
break;
}
}
/* if we didn't find any audio then give up now */
if (found_audio == FALSE) {
dprintf("action_workman: no audio\n");
goto dun;
}
dprintf("action_workman: found audio (track %d, %d tracks ttl)\n",
/*
* Set the ENXIO on eject attribute. This causes workman
* to get an ENXIO if someone types eject from another
* window. Workman, when started with the -X flag, exits
* as soon as it ejects the media, or if it ever sees an
* ENXIO from an ioctl.
*/
/* start workman: don't care about errors just fire and forget */
if (fork() == 0) {
int fd;
int argc_new = 0;
char *argv_new[MAX_NEWARGS];
char sympath[MAXNAMELEN];
#ifdef DEBUG
#endif
/* child */
/* stick their error messages out on the console */
}
/* clean up args */
setup_user();
#ifdef DEBUG
dprintf("DEBUG: child: after setting up env\n");
#endif
/* remove leading shared-object name (ours!) */
/* set up path to use (instead of rawpath) */
getenv("VOLUME_SYMDEV"));
/* add to argv passed in */
#ifdef DEBUG
dprintf("DEBUG: child: about to add to args ...\n");
#endif
/* combine our argv and the new list */
#ifdef DEBUG
#endif
/* bummer, it failed -- EXIT, don't return!! */
gettext("%s(%ld) error: exec of \"%s\" failed; %s\n"),
exit(1);
/*NOTREACHED*/
}
dun:
return (result);
}
/*
* setup_user:
* set a reasonable user and group to run workman as. The default
* The other thing we want to do is make the cwd to be
* the user's home directory so all the nice workman databases
* work right.
*/
void
setup_user(void)
{
char namebuf[MAXNAMELEN];
/*
* The assumption is that a workstation is being used by
* the person that's logged into the console and that they
* just inserted the cdrom. This breaks down on servers,
* but the most common case (by far) is someone listening
* to a cdrom at thier desk, while logged in and running the
* window system.
*/
}
}
/* set HOME env. var. */
} else {
(void) putenv("HOME=/tmp");
}
perror("Failed to set gid:");
}
perror("Failed to set uid:");
}
}
/*
* set_user_env -- set up user environment
*/
{
int i;
#ifdef DEBUG
dprintf("DEBUG: set_user_env(): entering\n");
#endif
/* only set display if it wasn't passed in */
for (i = 0; i < ac; i++) {
(ac > (i+1))) {
break;
}
}
#ifdef DEBUG
dprintf("DEBUG: set_user_env(): display found = %s\n",
#endif
if (!display_specified) {
}
(void) putenv(ld_lib_path);
"/usr/openwin/lib/app-defaults/%L/%N",
"/usr/openwin/lib/app-defaults/%N");
"/usr/openwin/lib/app-defaults/%L/%N",
"/usr/openwin/lib/app-defaults/%N");
#ifdef DEBUG
dprintf("DEBUG: set_user_env(): leaving\n");
#endif
}
/*
* add src args to dest arg list
*/
static void
int *dest_argcp, /* ptr to dest argc */
char ***dest_argvp, /* ptr to dest argv */
int src_argc, /* src argc */
char **src_argv) /* src argv */
{
int dest_argc = *dest_argcp;
char **dest_argv = *dest_argvp;
int amt;
char **arr;
int ind;
int i;
/* find size of new array */
/* allocate array */
gettext("%s(%ld) error: can't allocate space; %s\n"),
return; /* just return the orig array ?? */
}
/* copy old and new array into our new space */
ind = 0;
for (i = 0; i < dest_argc; i++) {
}
for (i = 0; i < src_argc; i++) {
}
/* return result in place of dest junk */
*dest_argcp = amt;
*dest_argvp = arr;
}
/*
* clean up args:
* - ensure av[0] == av[1]
* - ensure that *acp is correct
* - correct the device crap -- NOT YET IMPLEMENTED
*/
static void
{
int i;
/* ensure count is correct */
for (i = 0; i < *acp; i++) {
*acp = i;
break;
}
}
}
#ifdef DEBUG
static char *
{
static char *ohoh = "<null ptr>";
return (str);
}
return (ohoh);
}
static void
{
int i;
for (i = 0; i < ac; i++) {
}
}
#endif /* DEBUG */