diff options
Diffstat (limited to 'src/xine-utils/xine_check.c')
-rw-r--r-- | src/xine-utils/xine_check.c | 265 |
1 files changed, 265 insertions, 0 deletions
diff --git a/src/xine-utils/xine_check.c b/src/xine-utils/xine_check.c new file mode 100644 index 000000000..6fd65515d --- /dev/null +++ b/src/xine-utils/xine_check.c @@ -0,0 +1,265 @@ +#include "xine_check.h" +#include <stdio.h> +#include "xineutils.h" +#include <sys/stat.h> +#include <sys/ioctl.h> +#include <sys/utsname.h> +#include <fcntl.h> +#include <stdlib.h> +#include <linux/major.h> +#include <linux/hdreg.h> +#include <errno.h> + +typedef struct { + FILE *fd; + char *filename; + char *ln; + char buf[256]; +} file_info_t; + +int xine_health_check() +{ + int retval = 0; + +#if 0 + if (xine_health_check_os() < 0) + { + retval = -1; + } +#endif + + if (xine_health_check_kernel() < 0) + { + retval = -1; + } + +#if ARCH_X86 + if (xine_health_check_mtrr() < 0) + { + retval = -1; + } +#endif /* ARCH_X86 */ + + if (xine_health_check_cdrom() < 0) + { + retval = -1; + } + + if (xine_health_check_dvdrom() < 0) + { + retval = -1; + } + +#if 0 + if (xine_health_check_dma() < 0) + { + retval = -1; + } +#endif + + if (xine_health_check_x() < 0) + { + retval = -1; + } + + if (xine_health_check_xv() < 0) + { + retval = -1; + } + + return retval; +} + +int xine_health_check_os(void) +{ + fprintf(stdout, "xine health_check (OS): "); + int retval = 0; + + return retval; +} + +int xine_health_check_kernel(void) +{ + fprintf(stdout, "xine health_check (Kernel):\n"); + + struct utsname kernel; + if (uname(&kernel) == 0) + { + fprintf(stdout," sysname: %s\n", kernel.sysname); + fprintf(stdout," release: %s\n", kernel.release); + fprintf(stdout," machine: %s\n", kernel.machine); + } + else + { + fprintf(stdout," FAILURE - Could not get kernel information.\n"); + return -1; + } + return 0; +} + +int xine_health_check_mtrr(void) +{ + fprintf(stdout, "xine health_check (MTRR):\n"); + + char *file = "/proc/mtrr"; + FILE *fd; + fd = fopen(file, "r"); + if (fd < 0) + { + fprintf(stdout, " FAILED: mtrr is not enabled.\n"); + return -1; + } + else { + fprintf(stdout, " SUCCESS: mtrr is enabled.\n"); + fclose(fd); + } + return 0; +} + +int xine_health_check_cdrom(void) +{ + fprintf(stdout, "xine health_check (CDROM):\n"); + char* cdrom_name = "/dev/cdrom"; + struct stat cdrom_st; + + if (stat(cdrom_name,&cdrom_st) < 0) + { + fprintf(stdout, " FAILED - could not cdrom: %s.\n", cdrom_name); + return -1; + } + else + { + fprintf(stdout, " SUCCESS - cdrom link %s is present.\n",cdrom_name); + } + + if ((cdrom_st.st_mode & S_IFMT) != S_IFBLK) + { + fprintf(stdout, " FAILED - %s is not a block device.\n", cdrom_name); + return -1; + } + else + { + fprintf(stdout, " SUCCESS - %s is a block device.\n", cdrom_name); + } + + if ((cdrom_st.st_mode & S_IFMT & S_IRWXU & S_IRWXG & S_IRWXO) != (S_IRUSR & S_IXUSR & S_IRGRP & S_IXGRP & S_IROTH & S_IXOTH)) + { + fprintf(stdout, " FAILED - %s permissions are not 'rwxrwxrx'.\n",cdrom_name); + } + else { + fprintf(stdout, " SUCCESS - %s does have proper permission.\n",cdrom_name); + } + + return 0; +} + +int xine_health_check_dvdrom(void) +{ + fprintf(stdout, "xine health_check (DVDROM):\n"); + char* dvdrom_name = "/dev/dvd"; + struct stat dvdrom_st; + + if (stat(dvdrom_name,&dvdrom_st) < 0) + { + fprintf(stdout, " FAILED - could not dvdrom: %s.\n", dvdrom_name); + return -1; + } + else + { + fprintf(stdout, " SUCCESS - dvdrom link %s is present.\n",dvdrom_name); + } + + if ((dvdrom_st.st_mode & S_IFMT) != S_IFBLK) + { + fprintf(stdout, " FAILED - %s is not a block device.\n", dvdrom_name); + return -1; + } + else + { + fprintf(stdout, " SUCCESS - %s is a block device.\n", dvdrom_name); + } + + if ((dvdrom_st.st_mode & S_IFMT & S_IRWXU & S_IRWXG & S_IRWXO) != (S_IRUSR & S_IXUSR & S_IRGRP & S_IXGRP & S_IROTH & S_IXOTH)) + { + fprintf(stdout, " FAILED - %s permissions are not 'rwxrwxrx'.\n",dvdrom_name); + } + else { + fprintf(stdout, " SUCCESS - %s does have proper permission.\n",dvdrom_name); + } + + return 0; +} + +int xine_health_check_dma(void) +{ + fprintf(stdout, "xine health_check (DMA):\n"); + int retval = 0; + int is_scsi_dev = 0; + int fd = 0; + static long param = 0; + + /* If /dev/dvd points to /dev/scd0 but the drive is IDE (e.g. /dev/hdc) and not scsi + * how do we detect the correct one */ + char* name = "/dev/hdc"; + struct stat st; + if (stat(name, &st)){ + perror(name); + exit(errno); + } + + if (major(st.st_rdev) == LVM_BLK_MAJOR){ + is_scsi_dev = 1; + fprintf(stdout, " SKIPPED - Operation not supported on SCSI disks.\n"); + } + + /* At this time due to the way my system is setup user 'root' must be runnning xine */ + fd = open(name, O_RDONLY | O_NONBLOCK); + if (fd < 0) + { + perror(name); + exit(errno); + } + + if (!is_scsi_dev){ + if(ioctl(fd, HDIO_GET_DMA, ¶m)) + { + fprintf(stdout, " FAILED - HDIO_GET_DMA failed. Ensure the permissions for %s are 0664.\n", name); + } + if (param != 1) + { + fprintf(stdout, " FAILED - DMA not turned on for %s.\n", name); + } + else + { + fprintf(stdout, " SUCCESS - DMA turned on for %s.\n", name); + close(fd); + } + } + + return retval; +} + +int xine_health_check_x(void) +{ + fprintf(stdout, "xine health_check (X):\n"); + char* env_display = getenv("DISPLAY"); + if (strlen(env_display) == 0) + { + fprintf(stdout, " FAILED - DISPLAY environment variable not set.\n"); + return -1; + } + else + { + fprintf(stdout, " SUCCESS - DISPLAY environment variable is set.\n"); + } + return 0; +} + +int xine_health_check_xv(void) +{ + fprintf(stdout, "xine health_check (XV):\n"); + int retval = 0; + + return retval; +} + |