action_dvdvideo.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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms..
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <malloc.h>
#include <sys/systeminfo.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include <pwd.h>
#include <limits.h>
#include <signal.h>
#include <string.h>
#include <libintl.h>
#include <rmmount.h>
#include <volmgt.h>
#define DEFAULT_DSODIR "/usr/lib/rmmount"
/*
* the number of video files to be found to meet dvd standards
*/
#define VFILE_NUM 3
typedef enum result_code {
ACTION_FAILURE = 0,
static action_result_t
start_player(struct action_arg **, int, char **);
static void
setup_user(void);
static int
setup_user_environment(void);
static bool_t
video_present(struct action_arg **);
/*
* action_dvdvideo.c is a shared library loaded by rmmount. The interface
* is private with rmmount and all input parameters are assumed to
* be valid.
*
* struct action_arg {
* char *aa_path; path to vol's block special file
* char *aa_rawpath; path to vol's character special file
* char *aa_type; file system type
* char *aa_media; class of media
* char *aa_partname; iff a partition, partition name
* char *aa_mountpoint; path this file system mounted on
* int aa_clean; is the file system stable
* };
*
* argc: the number of items passed in the argv list
* argv: the program and it's arguments to be started
*
* Returns:
* FAILURE 0
* SUCCESS 1
*
* action() is an external public interface that follows the action.so
* interface spec. action() is the entry point for action_dvdvideo.so
*/
int
{
int result;
/*
* if this is an eject, get out
*/
dprintf("%s[%d]: don't start video unless inserting\n",
}
/*
* We are provided a mount point only if media or a partition
* has been mounted. If there is not one, we fail right away
*/
if ((action_result == ACTION_SUCCESS) &&
}
/*
* Determine if the mounted file system has
* video files based on the dvd standard.
*/
if (action_result == ACTION_SUCCESS) {
if (have_video == FALSE) {
}
}
/*
* If this .so is being called because of an eject, we needed
* to check for valid video files. If we found them we do not want
* to start the video player.
*
* We only want to start the video player when we find the correct
* video files and the action is an 'insert'.
*/
if (action_result == ACTION_SUCCESS) {
/*
* Start the video player.
*/
dprintf("%s[%d]: Found video files, starting player\n",
/*
* if player failed, we still want to stop future actions
* so we need to change action_result to ACTION_SUCCESS
*/
if (action_result == ACTION_FAILURE) {
dprintf("%s[%d]:Failed to start video, However\
the media contains video\n",
}
}
if (action_result == ACTION_SUCCESS) {
} else {
}
return (result);
}
/*
* setup_user_environment():
* no parameters.
*
* Sets up basic user environment to run the player
* Sets up the DISPLAY, setup library path,
* the X file search path, the X user files search path.
*
* Finally sets the xwindow home
*
* The only failure within this function is not enough memory
* resulting from calls to 'putenv()'.
*/
static int
setup_user_environment(void)
{
int rc;
/*
* Set DISPLAY environment variable to ":0.0"
*
* cde sets DISPLAY, however, we still set it because
* cde may not be running.
*
* If the user set the display in the argv list,
* the user's setting will override this setting of DISPLAY
*/
/*
* Set up the library path so the player can find any required
* runtine libraries.
*/
if (rc == 0) {
}
/*
* Set up the X files search path so the window application
* can be found.
*/
if (rc == 0) {
/usr/openwin/lib/app-defaults/%L/%N, \
/usr/opwnwin/lib/app-defaults/%N");
}
/*
* Set up the X user File search path, it happens that
* it value is the same as the previous variable. However,
* window applications still use this variable.
*/
if (rc == 0) {
/usr/openwin/lib/app-defaults/%L/%N, \
/usr/opwnwin/lib/app-defaults/%N");
}
/*
* Set the openwin home environment variable.
*/
if (rc == 0) {
}
return (rc);
}
/*
* setup_user()
* no parameters
*
* This process runs as root and when the player is started
* it should not be owned by root. However, if we are not able
* to get the uid of the user, we allow the root uid to be set.
*
* Therefor this procedure sets the uid to the user that
* owns the console and resets the gid also.
*
* The users home environment variable is set as well.
*/
static void
setup_user(void)
{
struct passwd *passwd_ent;
static char env_buf[MAXNAMELEN];
/*
* Want to get the uid of the user who has
* the console. The assumption is the console
* owner is the user wanting to play the video
*/
}
}
/*
* Set the home environment variable to
* the users home.
*/
} else {
/* uid is left to be root, use /tmp as home */
(void) putenv("HOME=/tmp");
}
perror("Failed to set gid");
}
perror("Failed to set uid");
}
}
/*
* start_player
* input: acton_arg (from rmm.c) and the argv list used
* when starting the player.
*
* forks
* Child: calls the fcns that set up the appropriate env var's
* and user values.
*
* We need to append the mount point of the dvd media to the
* arg list. Because argv[0] points to the name of this dso,
* the argv list is moved up 1 and the mountpoint is added
* at argv[argc -1].
*
* Parent: Checks if the exec'd process is alive and if so
* return ACTION_SUCCESS otherwise returns ACTION_FAILURE
*/
static action_result_t
{
/*
* Set the ENXIO eject attribute so the video
* into another window.
*/
/* child */
int fd;
int rc;
int i;
/*
* Change our running dir to /tmp directory
*/
(void) chdir("/tmp");
/*
* Redirect all output to go to the console.
*/
}
/*
* Set user's id and group id
* change 'HOME' to the users home directory.
*/
(void) setup_user();
/*
* Set up the user environment for running
* the video player.
*/
rc = setup_user_environment();
/*
* The first arg in argv is this dso, and we want to
* append the mountpoint at then end of the argv.
* We shift up all args, replacing argv[0] with the
* player name. The last argv entry will point to the
* path to the dvd mount point.
*/
if (rc == 0) {
for (i = 0; i < (argc -1); i++) {
}
} else {
}
/*
* If we get this far, the execv failed
* and we must exit.
*/
gettext("exec of '%s' failed: %s\n"),
exit(1);
/* NOTREACHED */
}
/*
* Sleep for a brief moment to give the player time to
* start and fail.
*/
(void) sleep(1);
/* Check to see if the program is running */
}
return (action_result);
}
static bool_t
{
int required_files = 0;
char video_dirname[PATH_MAX];
/*
* Lets make sure we have a mount point to work with.
*/
return (FALSE);
}
dprintf("No VIDEO_TS director found\n");
return (FALSE);
}
/*
* We need an .IFO a .BUP and at least one .VOB file.
*/
required_files == VFILE_NUM) {
}
return (required_files >= VFILE_NUM);
}