예제 #1
0
void CAgentService::Reset()
{
#if defined(__TI_AM335X__)
    // Battery Check
    CheckBattery();
    return;
#endif

    SystemExec("sync");
    SystemExec("sync");
    SystemExec("sync");
    SystemExec("reboot");
}
예제 #2
0
파일: suspend.c 프로젝트: suborb/reelvdr
cQuickShutdownCtl::~cQuickShutdownCtl()
{
    m_Active = false;
    cStatus::MsgOsdClear();
    cPlugin *p = cPluginManager::GetPlugin("graphlcd");

    /* runScript==false means, vdr going into standby/shutdown,
     *  so donot switch the video and audio back
     */
    if (p && cQuickShutdownCtl::runScript) 
    {
        p->SetupParse("PluginActive", "1");

        //LCD
        //SystemExec("/sbin/reelfpctl -clearled 1");      // only standby-led
        //SystemExec("/sbin/reelfpctl -toptext \"\" -displaymode 0");
        SystemExec("quickshutdown.sh end" );
    
        /* since hdctrld -o DVI (in script) does not send 
         * audio through HDMI, reset settings in Reelbox-plugin
         */
        cPluginManager::CallAllServices("ReInit", NULL);


        // make sure volume is "on"
        cDevice::PrimaryDevice()->SetVolume(0); 

        //Get brightness set by user from graphlcd plugin and reset to that value
        int LCDbrightness = 8;
        p->Service("Get LCDBrightness Active", &LCDbrightness);

        char buffer[128];
        sprintf(buffer, "/sbin/reelfpctl -brightness %i", LCDbrightness);
        PRINTF("%s\n", buffer);
        SystemExec(buffer);
    }

    /*switch ON hdplayer */
    ToggleVideoOutput(1);

    p = cPluginManager::GetPlugin("osdteletext");

    if (p)
        p->Service("StartReceiver");


    DELETENULL(m_QuickShutdown);
}
예제 #3
0
파일: remote.c 프로젝트: suborb/reelvdr
bool cRemote::PutMacro(eKeys Key)
// returns true it opens a menu
// returns false if it is a command that has no menu
{
  const cKeyMacro *km = KeyMacros.Get(Key);
  if (km) {
     keyMacroPlugin = km->Plugin();
     if(km->Command()) {
         dsyslog("Executing keymacros.conf-command: \"%s\"\n", km->Command());
         SystemExec(km->Command());
         return false;
     } else {
         cMutexLock MutexLock(&mutex);
         for (int i = km->NumKeys(); --i > 0; ) {
            if (!Put(km->Macro()[i], true))
               return true;
            }
         }
     }
  else if (Key == kTT)
      Skins.Message(mtError, tr("Teletext not available!"));
  else if (Key == kPiP)
      Skins.Message(mtError, tr("PiP not available!"));
  return true;
}
예제 #4
0
파일: suspend.c 프로젝트: suborb/reelvdr
void cQuickShutdownLive::Action(void)
{
#if VDRVERSNUM < 10300
    isyslog("VDR: QuickShutdown Live thread started (pid = %d)", getpid());
#endif

    // give time for change in player before switching OFF the HDE output
    // else at times the Video frame remain on Screen
    cCondWait::SleepMs(250);

    // show any images HERE before blanking the screen
    // eg. Screen informing the user, it is "Quick-Shutdown"

    /*switch off hdplayer */
    ToggleVideoOutput(0);

    // Call external quickshutdown to prepare frontpanel etc.
    SystemExec("quickshutdown.sh start");

    m_Active = true;
    while (m_Active)
    {
        //DeviceStillPicture(suspend_mpg, sizeof(suspend_mpg));

        // this player does nothing, so sleep
        cCondWait::SleepMs(250);
    }

#if VDRVERSNUM < 10300
    isyslog("VDR: QuickShutdown Live thread stopped");
#endif
}
static void CallIdleHook(const char *IdleHook, const char *DevPath, bool Idle)
{
  cString idleHookCmd = cString::sprintf("%s --idle=%s --device=%s", IdleHook, (Idle ? "on" : "off"), DevPath);
  isyslog("dynamite: calling idle hook %s", *idleHookCmd);
  int status = SystemExec(*idleHookCmd, false);
  if (!WIFEXITED(status) || WEXITSTATUS(status))
     esyslog("SystemExec() failed with status %d", status);
}
예제 #6
0
void CMeterUploader::ReduceDataDirectory()
{
	DIR		*dir_fdesc;
	dirent	*dp;
	time_t	now, old;
	struct	tm	when;
	char	szPath[128];
	char	szDate[20];

	time(&now);
	if ((now-m_nLastReduce) <= (60*60))
		return;

	when = *localtime(&now);
	/** 매 0시에만 파일을 지우던 것을 매시간 지우도록 변경
      * if ((when.tm_hour != 0) || (when.tm_min < 50))
      */
	if (when.tm_min < 50)
		return;

	time(&old);
	old -= m_nDataSaveDay * (24*(60*60));
	when = *localtime(&old);
	sprintf(szDate, "%04d%02d%02d%02d",
			when.tm_year+1900,
			when.tm_mon+1,
			when.tm_mday,
			when.tm_hour);

	time(&m_nLastReduce);
	dir_fdesc = opendir("/app/data");
	if (dir_fdesc == NULL)
		return;

	for(; (dp=readdir(dir_fdesc));)
	{
#if     defined(_DIRENT_HAVE_D_TYPE)
		if (dp->d_type == DT_DIR)
			continue;
#endif

		if (dp->d_name[0] == '.')
			continue;

		if (strncmp(dp->d_name, szDate, strlen(szDate)) >= 0)
			continue;

		XDEBUG("Reduce /app/data/%s (%s)...\xd\xa", dp->d_name, szDate);
		sprintf(szPath, "/app/data/%s", dp->d_name);
		unlink(szPath);
	}

	closedir(dir_fdesc);
	SystemExec("sync");
}
예제 #7
0
파일: commands.c 프로젝트: suborb/reelvdr
eOSState cCMD::Eject(bool close)
{
  char *cmd = NULL;
  asprintf(&cmd, "eject %s %s", close ? "-t" : "", DVDSwitchSetup.DVDLinkOrg);
  MYDEBUG("Eject: %i - %s", close, cmd);
  int rc = SystemExec(cmd);
  MYDEBUG("Eject-Rückgabe: %i", rc);
  free(cmd);

  return osContinue;
}
예제 #8
0
void cShutdownHandler::CallShutdownCommand(time_t WakeupTime, int Channel, const char *File, bool UserShutdown)
{
  time_t Delta = WakeupTime ? WakeupTime - time(NULL) : 0;
  cString cmd = cString::sprintf("%s %ld %ld %d \"%s\" %d", shutdownCommand, WakeupTime, Delta, Channel, *strescape(File, "\\\"$"), UserShutdown);
  isyslog("executing '%s'", *cmd);
  int Status = SystemExec(cmd, true);
  if (!WIFEXITED(Status) || WEXITSTATUS(Status))
     esyslog("SystemExec() failed with status %d", Status);
  else {
     Setup.NextWakeupTime = WakeupTime; // Remember this wakeup time for comparison on reboot
     Setup.Save();
     }
}
eDynamicDeviceReturnCode cDynamicDevice::DetachDevice(const char *DevPath, bool Force)
{
  if (!DevPath)
     return ddrcNotSupported;

  cMutexLock lock(&arrayMutex);
  int freeIndex = -1;
  int index = -1;
  if (isnumber(DevPath))
     index = strtol(DevPath, NULL, 10) - 1;
  else
     index = IndexOf(DevPath, freeIndex, -1);

  if ((index < 0) || (index >= numDynamicDevices)) {
     esyslog("dynamite: device %s not found", DevPath);
     return ddrcNotFound;
     }

  cString realDevPath(dynamicdevice[index]->GetDevPath());
  if (!Force) {
     if (!dynamicdevice[index]->isDetachable) {
        esyslog("dynamite: detaching of device %s is not allowed", *realDevPath);
        return ddrcNotAllowed;
        }

     if (dynamicdevice[index] == PrimaryDevice()) {
        esyslog("dynamite: detaching of primary device %s is not supported", *realDevPath);
        return ddrcIsPrimaryDevice;
        }

     if (dynamicdevice[index]->Receiving(false)) {
        esyslog("dynamite: can't detach device %s, it's receiving something important", *realDevPath);
        return ddrcIsReceiving;
        }
     }

  dynamicdevice[index]->DeleteSubDevice();
  isyslog("dynamite: detached device %s%s", *realDevPath, (Force ? " (forced)" : ""));
  if (enableOsdMessages) {
     cString osdMsg = cString::sprintf(tr("detached %s"), *realDevPath);
     Skins.QueueMessage(mtInfo, *osdMsg);
     }
  if (attachHook != NULL) {
     cString hookCmd = cString::sprintf("%s --action=detach --device=%s", **attachHook, *realDevPath);
     isyslog("dynamite: calling hook %s", *hookCmd);
     int status = SystemExec(*hookCmd, true);
     if (!WIFEXITED(status) || WEXITSTATUS(status))
        esyslog("SystemExec() failed with status %d", status);
     }
  return ddrcSuccess;
}
예제 #10
0
/*
 * returns true if the given device has partition table type as GPT
 * else returns false
 */
bool IsGPT(std::string device)
{
    char command[512];
    snprintf(command, 512, "LANG=\"C\" fdisk -l %s | grep GPT", device.c_str());
    int ret = SystemExec(command);

    isyslog("SystemExec('%s') returns %d", command, ret);

    if (ret == 0) {
        isyslog("device: %s has GPT partition table", device.c_str());
        return true;
    }

    isyslog("device: %s does not have GPT partition table", device.c_str());
    return false;
}
예제 #11
0
파일: commands.c 프로젝트: suborb/reelvdr
void cCMDImageBurnThread::Action(void) {
  MYDEBUG("BurnThread gestartet");
  if(File && FileType != tNone) {
    MYDEBUG("Aktion wird ausgefuehrt");
    char *cmd;
    asprintf(&cmd,
              "'%s' '%s' '%s'",
              DVDSwitchSetup.DVDWriteScript,
              File,
              FileType == tFile ? "IMAGE" : "DIR");
    MYDEBUG("Aufruf: %s", &cmd);
    int rc = SystemExec(cmd);
    cStatusThread* burn_status = new cStatusThread(BurnMode,"/var/log/dvdswitch_burn.log","Writing DVD");
    burn_status->Start();
    MYDEBUG("Rueckgabe Aufruf: %i", rc);
    FREENULL(cmd);
  }
  delete(this);
};
예제 #12
0
int cPartition::ResizeEXT3()
{
    int result = 0;
    char command[256];
    char fdisk[256];
    char path[256];
    std::ofstream file;

    if(number_ < 5)
    {
        if(PrimaryPartitionsFull())
            snprintf(fdisk, 256, "d\n%i\nn\np\n\n\nw\n", number_);
        else
            snprintf(fdisk, 256, "d\n%i\nn\np\n%i\n\n\nw\n", number_, number_);
    }
    else
    {
        if(PrimaryPartitionsFull())
            snprintf(fdisk, 256, "d\n%i\nn\n\n\nx\nf\nw\n", number_);
        else
            snprintf(fdisk, 256, "d\n%i\nn\nl\n\n\nx\nf\nw\n", number_);
    }
    snprintf(command, 256, "LANG=\"C\" echo \"%s\" | fdisk /dev/sd%c 1>/dev/null 2>/dev/null", fdisk, letter_);
    //printf("\033[0;93m %s \033[0m\n", command);
    result = SystemExec(command);

    mkdir(SCRIPT_PATH, 0755);
    snprintf(path, 256, "%splugin-setup-resize.sh", SCRIPT_PATH);
    file.open(path);

    file << "#!/bin/sh\n\n";

    snprintf(command, 256, "resize2fs /dev/sd%c%i", letter_, number_);
    file << command;

    file.close();
    chmod(path, 0755);

    return 0;
}
예제 #13
0
파일: commands.c 프로젝트: suborb/reelvdr
eOSState cCMDMenu::ProcessKey(eKeys Key)
{
  eOSState ret = osUnknown;

  if(!HasSubMenu())
  {
    cCMDImage *CMDImage = NULL;
    cOsdItem *item = NULL;
    eCMDs cmd = cmdNone;
    std::string scmd;

	//int current = Current();  // remove

    switch(Key)
    {
      case kOk:
        item = Get(Current());
        if(strstr(item->Text(),tr("Directory management")))
          cmd = cmdDirManage;
	if(strstr(item->Text(),tr("Burn image")))
	  cmd = cmdImgBurn;
        if(strstr(item->Text(),tr("Open DVD-tray")))
          cmd = cmdDVDopen;
        if(strstr(item->Text(),tr("Close DVD-tray")))
          cmd = cmdDVDclose;
/*
        if(strstr(item->Text(),tr("Play")))
          cmd = cmdImgPlay;
*/
        if(strstr(item->Text(),tr("Rename image")))
          cmd = cmdImgRename;

        if(strstr(item->Text(),tr("Delete cache")))
          cmd = cmdDeleteCache;

        if(strstr(item->Text(),tr("Format DVD-RW")))
          cmd = cmdDVDRWFormat;
/*
        if(strstr(item->Text(),tr("Image move")))
          cmd = cmdImgMove;
        if(strstr(item->Text(),tr("Image delete")))
          cmd = cmdImgDelete;
        if(strstr(item->Text(),tr("Image burn")))
          cmd = cmdImgBurn;
        if(strstr(item->Text(),tr("DVD reading")))
          cmd = cmdImgRead;
*/
        switch(cmd)
        {
          case cmdDirManage:
            return AddSubMenu(new cCMDDir(OsdObject));
            break;
	   case cmdImgBurn:
	     CMDImage = new cCMDImage(OsdObject);
	     ret = CMDImage->Burn(iItem->FileName());
	     DELETENULL(CMDImage);
	     return ret;
	     break;
          case cmdDVDopen:
            return cCMD::Eject(false);
            break;
          case cmdDVDclose:
            return cCMD::Eject(true);
            break;
          case cmdImgPlay:
            return cCMD::Play(iItem);
            break;
          case cmdImgRename:
            OsdObject->SetState(mmsImgRename);
            item = OsdObject->Get(OsdObject->Current());
            item->ProcessKey(kRight);
            return osBack;
            break;
          case cmdImgMove:
            return AddSubMenu(new cCMDMove(iItem->FileName(), OsdObject, false));
            break;
          case cmdImgDelete:
            CMDImage = new cCMDImage(OsdObject);
            ret = CMDImage->Delete(iItem->FileName());
            DELETENULL(CMDImage);
            return ret;
            break;
          case cmdDeleteCache:
            scmd = "/usr/bin/sudo rm -f /etc/vdr/DVD.db";
            system(scmd.c_str());
            Skins.Message(mtInfo,tr("Success..."));
            break;
          case cmdImgRead:
            /* MARKUS */
            //DvdRead();
            //return osBack;
            return  AddSubMenu(new cCMDImageRead);
            break;
          case cmdDVDRWFormat:
            SystemExec("/usr/sbin/dvd-rw-format.sh");
            ////Skins.Message(mtInfo, tr("Formating started"));
            break;
          default:
            break;
        }
        break;
      default:
        break;
    }
  }

  return cOsdMenu::ProcessKey(Key);
}
예제 #14
0
파일: commands.c 프로젝트: suborb/reelvdr
void cCMDImageReadThread::Action(void) {
  MYDEBUG("ReadThread gestartet");
  if(File && Dir && FileType != tNone) {
    MYDEBUG("Aktion wird ausgefuehrt");
    char *cmd = NULL;
    char *output = NULL;
    char *mountpoint = NULL;
    int step = 0;
    cTokenizer *token = NULL;
    //char buffer[MaxFileName];
    char *buffer = NULL;
    //MYDEBUG("vor realpath '%s'", DVDSwitchSetup.DVDLinkOrg);

    if (DVDSwitchSetup.DVDLinkOrg == NULL)
    {
	esyslog("DVDSwitchSetup.DVDLinkOrg is empty. Cannot continue");
	return;
    }
    if (realpath(DVDSwitchSetup.DVDLinkOrg, buffer)== NULL)
        buffer[0] = '\0';

    while(!mountpoint && step < 2) {
      step++;
      asprintf(&cmd, "cat /etc/fstab | grep -e \"%s\" | grep -e \"^[^#]\"", step == 1 ? DVDSwitchSetup.DVDLinkOrg : buffer);
      MYDEBUG("Command: %s", cmd);

      FILE *p = popen(cmd, "r");
      if(p) {
#if VDRVERSNUM >= 10318
        cReadLine rl;
        output = rl.Read(p);
#else
        output = readline(p);
#endif
        pclose(p);
      }
      token = new cTokenizer(output, " ");
      if(token->Count() > 1)
        mountpoint = strdup(stripspace(token->GetToken(2)));
      DELETENULL(token);
    }
    FREENULL(cmd);
    asprintf(&cmd, "'%s' '%s' '%s' '%s' '%s' '%s'",
              DVDSwitchSetup.DVDReadScript,
              Dir, // /media/hd/movies
              File, // leer
              buffer, (mountpoint==NULL) ? " ":mountpoint,
              (FileType == tFile) ? "IMAGE" : "DIR");
    MYDEBUG("Aufruf: %s", cmd);
    // Start thread here
    int rc = SystemExec(cmd);
    cStatusThread* read_status = new cStatusThread(ReadMode,"/tmp/vobcopy_1.1.0.log",tr("Copying DVD"));
    read_status->Start();
    MYDEBUG("Aufruf: %s DONE with %d", cmd, rc);
    MYDEBUG("Rueckgabe Aufruf: %i", rc);
    FREENULL(cmd);
    FREENULL(mountpoint);
    FREENULL(buffer);
  }
  delete(this);
};
eDynamicDeviceReturnCode cDynamicDevice::AttachDevice(const char *DevPath, int Delayed)
{
  if (!DevPath)
     return ddrcNotSupported;

  cMutexLock lock(&arrayMutex);
  int freeIndex = -1;
  int index = -1;
  bool isDvbDevice = false;
  int adapter = -1;
  int frontend = -1;
  int wishIndex = -1;
  int attachDelay = 0;
  bool attachDelayPreopen = false;
  GetUdevAttributesForAttach(DevPath, wishIndex, attachDelay, attachDelayPreopen);
  if (wishIndex >= 0)
     isyslog("dynamite: %s wants card index %d", DevPath, wishIndex);
  else if (sscanf(DevPath, "/dev/dvb/adapter%d/frontend%d", &adapter, &frontend) == 2) {
     isDvbDevice = false;
     wishIndex = adapter;
     isyslog("dynamite: %s is a dvb adapter trying to set card index to %d", DevPath, wishIndex);
     }
  index = IndexOf(DevPath, freeIndex, wishIndex);

  if (index >= 0) {
     isyslog("dynamite: %s is already attached", DevPath);
     return ddrcAlreadyAttached;
     }

  if (freeIndex < 0) {
     esyslog("dynamite: no more free slots for %s", DevPath);
     return ddrcNoFreeDynDev;
     }

  if ((attachDelay > 0) && (Delayed > 1)) {
     if (attachDelayPreopen) {
        // trigger firmware load
        isyslog("dynamite: open %s before attach", DevPath);
        int fd = open(DevPath, O_RDWR | O_NONBLOCK);
        if (fd > 0) {
           close(fd);
           isyslog("dynamite: close %s", DevPath);
           }
        }
     commandRequeue.Add(new cDynamicDeviceProbe::cDynamicDeviceProbeItem(ddpcAttach, new cString(DevPath)));
     new cDelayedDeviceItems(DevPath, attachDelay);
     return ddrcAttachDelayed;
     }

  cUdevDevice *dev = cUdev::GetDeviceFromDevName(DevPath);
  if (dev != NULL) {
     bool ignore = false;
     const char *tmp;
     if (((tmp = dev->GetPropertyValue("dynamite_attach")) != NULL)
      && ((strcmp(tmp, "0") == 0) || (strcasecmp(tmp, "n") == 0)
       || (strcasecmp(tmp, "no") == 0) || (strcasecmp(tmp, "ignore") == 0))) {
        isyslog("dynamite: udev says don't attach %s", DevPath);
        ignore = true;
        }
     else if (((tmp = dev->GetPropertyValue("dynamite_instanceid")) != NULL) && isnumber(tmp)) {
        int devInstanceId = strtol(tmp, NULL, 10);
        if (devInstanceId != InstanceId) {
           isyslog("dynamite: device %s is for vdr instance %d, we are %d", DevPath, devInstanceId, InstanceId);
           ignore = true;
           }
        }
     delete dev;
     if (ignore)
        return ddrcNotSupported;
     }

  cDevice::nextParentDevice = dynamicdevice[freeIndex];
  
  for (cDynamicDeviceProbe *ddp = DynamicDeviceProbes.First(); ddp; ddp = DynamicDeviceProbes.Next(ddp)) {
      if (ddp->Attach(dynamicdevice[freeIndex], DevPath))
         goto attach; // a plugin has created the actual device
      }

  // if it's a dvbdevice try the DvbDeviceProbes as a fallback for unpatched plugins
  if (isDvbDevice || (sscanf(DevPath, "/dev/dvb/adapter%d/frontend%d", &adapter, &frontend) == 2)) {
     for (cDvbDeviceProbe *dp = DvbDeviceProbes.First(); dp; dp = DvbDeviceProbes.Next(dp)) {
         if (dp != dvbprobe) {
            if (dp->Probe(adapter, frontend))
               goto attach;
            }
         }
     new cDvbDevice(adapter, frontend, dynamicdevice[freeIndex]);
     goto attach;
     }

  esyslog("dynamite: can't attach %s", DevPath);
  return ddrcNotSupported;

attach:
  int retry = 3;
  do {
     dynamicdevice[freeIndex]->lastCloseDvr = time(NULL);
     for (time_t t0 = time(NULL); time(NULL) - t0 < SUBDEVICEREADYTIMEOUT; ) {
         if (dynamicdevice[freeIndex]->Ready()) {
            retry = -1;
            break;
            }
         cCondWait::SleepMs(100);
         }
     if (!dynamicdevice[freeIndex]->Ready() && dynamicdevice[freeIndex]->HasCi() && (retry > 0)) {
        retry--;
        isyslog("dynamite: device %s not ready after %d seconds - resetting CAMs (retry == %d)", DevPath, SUBDEVICEREADYTIMEOUT, retry);
        for (cCamSlot* cs = CamSlots.First(); cs; cs = CamSlots.Next(cs)) {
            if ((cs->Device() == dynamicdevice[freeIndex]) || (cs->Device() == NULL))
               cs->Reset();
            }
        }
     else
        break;
     } while (retry >= 0);
  dynamicdevice[freeIndex]->devpath = new cString(DevPath);
  isyslog("dynamite: attached device %s to dynamic device slot %d", DevPath, freeIndex + 1);
  dynamicdevice[freeIndex]->ReadUdevProperties();
  cPluginManager::CallAllServices("dynamite-event-DeviceAttached-v0.1", (void*)DevPath);
  cDvbDevice::BondDevices(Setup.DeviceBondings); // "re-bond"
  if (enableOsdMessages) {
     cString osdMsg = cString::sprintf(tr("attached %s"), DevPath);
     Skins.QueueMessage(mtInfo, *osdMsg);
     }
  cDynamiteStatus::SetStartupChannel();
  if (attachHook != NULL) {
     cString hookCmd = cString::sprintf("%s --action=attach --device=%s", **attachHook, DevPath);
     isyslog("dynamite: calling hook %s", *hookCmd);
     int status = SystemExec(*hookCmd, true);
     if (!WIFEXITED(status) || WEXITSTATUS(status))
        esyslog("SystemExec() failed with status %d", status);
     }
  dynamicdevice[freeIndex]->subDeviceIsReady = true;
  return ddrcSuccess;
}
예제 #16
0
cString cPluginDynamite::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
{
  if ((strcasecmp(Command, "ATTD") == 0) || (strcasecmp(Command, "AttachDevice") == 0)) {
     cDynamicDeviceProbe::QueueDynamicDeviceCommand(ddpcAttach, Option);
     return cString::sprintf("queued command for attaching %s", Option);
     }

  if ((strcasecmp(Command, "DETD") == 0) || (strcasecmp(Command, "DetachDevice") == 0)) {
     cDynamicDeviceProbe::QueueDynamicDeviceCommand(ddpcDetach, Option);
     return cString::sprintf("queued command for detaching %s", Option);
     }

  if ((strcasecmp(Command, "FDTD") == 0) || (strcasecmp(Command, "ForceDetachDevice") == 0)) {
     cDynamicDevice::DetachDevice(Option, true);
     return cString::sprintf("forced detaching of %s", Option);
     }

  if ((strcasecmp(Command, "DTAD") == 0) || (strcasecmp(Command, "DetachAllDevices") == 0)) {
     bool force = false;
     if (Option && (strcasecmp(Option, "force") == 0))
        force = true;
     cDynamicDevice::DetachAllDevices(force);
     return cString::sprintf("detaching all devices...");
     }

  if ((strcasecmp(Command, "SCND") == 0) || (strcasecmp(Command, "ScanDevices") == 0))
     return cDynamicDevice::AttachDevicePattern(Option);

  if ((strcasecmp(Command, "LSTD") == 0) || (strcasecmp(Command, "ListDevices") == 0))
     return cDynamicDevice::ListAllDevices(ReplyCode);

  int lock = 0;
  if ((strcasecmp(Command, "LCKD") == 0) || (strcasecmp(Command, "LockDevice") == 0))
     lock = 1;
  else if ((strcasecmp(Command, "UNLD") == 0) || (strcasecmp(Command, "UnlockDevice") == 0))
     lock = 2;
  if (lock > 0) {
     switch (cDynamicDevice::SetLockDevice(Option, lock == 1)) {
       case ddrcSuccess:
         return cString::sprintf("%slocked device %s", (lock == 2) ? "un" : "", Option);
       case ddrcNotFound:
        {
          ReplyCode = 550;
          return cString::sprintf("device %s not found", Option);
        }
       default:
        {
          ReplyCode = 550;
          return cString::sprintf("can't %slock device %s and I don't know why...", (lock == 2) ? "un" : "", Option);
        }
       }
     }

  int idle = 0;
  if (strcasecmp(Command, "SetIdle") == 0)
     idle = 1;
  else if (strcasecmp(Command, "SetNotIdle") == 0)
     idle = 2;
  if (idle > 0) {
     switch (cDynamicDevice::SetIdle(Option, (idle == 1))) {
       case ddrcSuccess:
         return cString::sprintf("device %s is %s", Option, (idle == 1 ? "idle" : "not idle"));
       case ddrcNotFound:
        {
          ReplyCode = 550;
          return cString::sprintf("device %s not found", Option);
        }
       default:
        {
          ReplyCode = 550;
          return cString::sprintf("can't set device %s to %s and I don't know why...", Option, (idle == 1 ? "idle" : "not idle"));
        }
       }
     }

  int autoidle = 0;
  if (strcasecmp(Command, "DisableAutoIdle") == 0)
     autoidle = 1;
  else if (strcasecmp(Command, "EnableAutoIdle") == 0)
     autoidle = 2;
  if (autoidle > 0) {
     switch (cDynamicDevice::SetAutoIdle(Option, (autoidle == 1))) {
       case ddrcSuccess:
         return cString::sprintf("%s auto-idle mode on device %s", (autoidle == 1 ? "disabled" : "enabled"), Option);
       case ddrcNotFound:
        {
          ReplyCode = 550;
          return cString::sprintf("device %s not found", Option);
        }
       default:
        {
          ReplyCode = 550;
          return cString::sprintf("can't %s auto-idle mode on device %s and I don't know why...", (autoidle == 1 ? "disable" : "enable"), Option);
        }
       }
     }

  if ((strcasecmp(Command, "SGTT") == 0) || (strcasecmp(Command, "SetGetTSTimeout") == 0)) {
     cString ret;
     int len = strlen(Option);
     if (len > 0) {
        char *devPath = new char[len];
        int seconds = -1;
        if ((sscanf(Option, "%s %d", devPath, &seconds) == 2) && (seconds >= 0)) {
           cDynamicDevice::SetGetTSTimeout(devPath, seconds);
           if (seconds > 0)
              ret = cString::sprintf("set GetTS-Timeout on device %s to %d seconds", devPath, seconds);
           else
              ret = cString::sprintf("disable GetTS-Timeout on device %s", devPath);
           }
        delete [] devPath;
        }
     return ret;
     }

  if ((strcasecmp(Command, "SDGT") == 0) || (strcasecmp(Command, "SetDefaultGetTSTimeout") == 0)) {
     if (isnumber(Option)) {
        int seconds = strtol(Option, NULL, 10);
        cDynamicDevice::SetDefaultGetTSTimeout(seconds);
        return cString::sprintf("set default GetTS-Timeout on all devices to %d seconds", seconds);
        }
     }

  if ((strcasecmp(Command, "AUDM") == 0) || (strcasecmp(Command, "AddUdevMonitor") == 0)) {
     int maxlen = strlen(Option);
     if (maxlen > 0) {
        char *subsystem = new char[maxlen + 1];
        char *devnode = new char[maxlen + 1];
        subsystem[0] = '\0';
        devnode[0] = '\0';
        cString msg;
        if ((sscanf(Option, "%s %s", subsystem, devnode) == 2) && cUdevPatternFilter::AddFilter(subsystem, devnode))
           msg = cString::sprintf("add udev-filter for %s %s", subsystem, devnode);
        else {
           ReplyCode = 550;
           msg = cString::sprintf("can't add udev-filter for %s %s", subsystem, devnode);
           }
        delete [] subsystem;
        delete [] devnode;
        return msg;
        }
     }

  if (strcasecmp(Command, "SetGetTSTimeoutHandlerArg") == 0) {
     cString ret;
     int len = strlen(Option);
     if (len > 0) {
        cString devPath(Option);
        const char *arg = strchr(*devPath, ' ');
        if (arg && (arg < (*devPath + len + 1))) {
           devPath.Truncate(arg - *devPath);
           arg++;
           cDynamicDevice::SetGetTSTimeoutHandlerArg(*devPath, arg);
           ret = cString::sprintf("set GetTS-Timeout-Handler-Arg on device %s to %s", *devPath, arg);
           }
        }
     return ret;
     }

  if (strcasecmp(Command, "CallGetTSTimeoutHandler") == 0) {
     if (getTSTimeoutHandler == NULL) {
        cString msg = cString::sprintf("no GetTSTimeoutHandler configured, arg: %s", Option);
        isyslog("dynamite: %s", *msg);
        return cString::sprintf("no GetTSTimeoutHandler configured, arg: %s", Option);
        }
     isyslog("dynamite: executing %s %s", **getTSTimeoutHandler, Option);
     if (SystemExec(*cString::sprintf("%s %s", **getTSTimeoutHandler, Option), true) < 0) {
        cString msg = cString::sprintf("error (%d) on executing %s %s", errno, **getTSTimeoutHandler, Option);
        isyslog("dynamite: %s", *msg);
        return msg;
        }
     cString msg = cString::sprintf("success on executing %s %s", **getTSTimeoutHandler, Option);
     isyslog("dynamite: %s", *msg);
     return msg;
     }

  if ((strcasecmp(Command, "SIDT") == 0) || (strcasecmp(Command, "SetIdleTimeout") == 0)) {
     if (isnumber(Option)) {
        int minutes = strtol(Option, NULL, 10);
        if (minutes >= 0) {
           cDynamicDevice::idleTimeoutMinutes = minutes;
           return cString::sprintf("set Idle-Timeout to %d minutes", minutes);
           }
        ReplyCode = 550;
        return cString::sprintf("minutes must be greater than or equal to 0");
        }
     }

  if ((strcasecmp(Command, "SIDW") == 0) || (strcasecmp(Command, "SetIdleWakeup") == 0)) {
     if (isnumber(Option)) {
        int hours = strtol(Option, NULL, 10);
        if (hours > 0) {
           cDynamicDevice::idleWakeupHours = hours;
           return cString::sprintf("set Idle-Wakeup to %d hours", hours);
           }
        ReplyCode = 550;
        return cString::sprintf("hours must be greater than 0");
        }
     }

  return NULL;
}
예제 #17
0
파일: cam_menu.c 프로젝트: suborb/reelvdr
		virtual void Action() {
			char uuid[UUID_SIZE];
			while(Running() && m_menu && m_state) {
				switch(m_state) {
					case 1: {
						m_statestr=tr("Updating configuration...");
						m_state = 0;
						for(cOsdItem *i=m_menu->First(); i; i=m_menu->Next(i)) {
							cCamMtd *m = dynamic_cast<cCamMtd *>(i);
							if(m && m->MtdModified()) {
								strcpy(uuid, m->m_uuid);
								m_state = 2;
								break;
							} // if
						} // for
						if(!m_state) m_statestr=tr("Configuration is up to date...");
						break;
					} // case 1
					case 2: {
						m_statestr = cString::sprintf(tr("Getting configuration from Netceiver %s"), uuid);
						cString c = cString::sprintf("rm -f %s; cd %s; netcvupdate -i %s%s%s -D", TMP_FILE, TMP_PATH, uuid, m_iface ? " -d " : "", m_iface ? m_iface : "");
//isyslog("EXEC1 %s", (const char *)c);
						if(SystemExec(c)) {
							m_statestr = cString::sprintf(tr("Failed to get configuration from Netceiver %s"), uuid);
							m_state = 0;
							continue;
						} // if
						m_state = 3;
						break;
					} // case 2
					case 3: {
						m_statestr = cString::sprintf(tr("Changing configuration for Netceiver %s"), uuid);
						xmlDocPtr doc = xmlReadFile(TMP_FILE, NULL, 0);
						if(doc == NULL) {
							m_statestr = cString::sprintf(tr("Failed to parse configuration from Netceiver %s"), uuid);
							m_state = 0;
							continue;
						} // if
						if(!PatchAllCamFlags(doc, uuid)) {
							xmlFreeDoc(doc);
							m_statestr = cString::sprintf(tr("Failed to set configuration for Netceiver %s"), uuid);
							m_state = 0;
							continue;
						} // if
						if(xmlSaveFormatFileEnc(TMP_FILE, doc, "UTF-8", 1)==-1) {
							xmlFreeDoc(doc);
							m_statestr = cString::sprintf(tr("Failed to save configuration for Netceiver %s"), uuid);
							m_state = 0;
							continue;
						} // if
						xmlFreeDoc(doc);
						m_state=4;
						break;
					} // case 3
					case 4: { 
						m_statestr = cString::sprintf(tr("Saving configuration for Netceiver %s"), uuid);
						cString c = cString::sprintf("netcvupdate -i %s%s%s -U %s -K", uuid, m_iface ? " -d " : "", m_iface ? m_iface : "", TMP_FILE);
//isyslog("EXEC2 %s", (const char *)c);
						if(SystemExec(c)) {
							m_statestr = cString::sprintf(tr("Failed to save configuration for Netceiver %s"), uuid);
							m_state = 0;
							continue;
						} // if
						m_state=1;
						break;
					} // case 4
				} // switch
			} // while
			m_state = 0;
		}; // Action
예제 #18
0
int cPartition::ResizeJFS()
{
    char path[256];
    int result = 0;
    char command[256];
    char fdisk[256];
    std::ofstream file;

    if(number_ < 5)
    {
        if(PrimaryPartitionsFull())
            snprintf(fdisk, 256, "d\n%i\nn\np\n\n\nw\n", number_);
        else
            snprintf(fdisk, 256, "d\n%i\nn\np\n%i\n\n\nw\n", number_, number_);
    }
    else
    {
        if(PrimaryPartitionsFull())
            snprintf(fdisk, 256, "d\n%i\nn\n\n\nx\nf\nw\n", number_);
        else
            snprintf(fdisk, 256, "d\n%i\nn\nl\n\n\nx\nf\nw\n", number_);
    }
    snprintf(command, 256, "LANG=\"C\" echo \"%s\" | fdisk /dev/sd%c 1>/dev/null 2>/dev/null", fdisk, letter_);
//printf("\033[0;93m %s \033[0m\n", command);
    result = SystemExec(command);

//    sprintf(command, "mount -o remount,resize %s", mountpoint_); // This won't work before the box is rebooted! :(
//printf("\033[0;93m %s \033[0m\n", command);
//    SystemExec(command);

#if 0
//commented out since it won't work. uuid is updated after rebooting :/
    // update uuid
    sprintf(command, "blkid /dev/sd%c%i", letter_, number_);
    file = popen(command, "r");
    free(command);
    if(file)
    {
        cReadLine readline;
        char *buffer = readline.Read(file);
        if(buffer)
        {
            char *keyword = " UUID=\"";
            if(strstr(buffer, keyword))
            {
                char *uuid = strstr(buffer, keyword) + strlen(keyword);
                *(strchr(uuid, '\"')) = '\0';
                strcpy(uuid_, uuid);
            }
        }
        buffer = NULL;
    }
    pclose(file);
#endif

//commented out: This won't work since uuid/partition-letter may change after rebooting :/
//    if(result == 0)
//    {
    // build a script for resizing JFS-partition after rebooting
    mkdir(SCRIPT_PATH, 0755);
    snprintf(path, 256, "%splugin-setup-resize.sh", SCRIPT_PATH);
    file.open(path);

    file << "#!/bin/sh\n\n";
    file << "MP=/media/$$\n";
    file << "mkdir $MP\n";

    snprintf(command, 256, "mount /dev/disk/by-uuid/%s $MP\n\n", uuid_);
    file << command;

    file << "mount -o remount,resize $MP\n";
    file << "umount $MP\n";
    file << "rmdir $MP\n";
    file << "rm $0\n";

    file.close();
    chmod(path, 0755);
//    }

//    return result;
    return 0;
}
예제 #19
0
cInstallPrimLang::cInstallPrimLang() :cInstallSubMenu(tr("Handling"))
{
    for (int k = 0; k < 256; k++)
        city_values[k] = NULL;

    // Language
    osdLanguageIndex = I18nCurrentLanguage();

    askTimeZone = true;
#ifdef RBMINI
    cPlugin *p = cPluginManager::GetPlugin("avahi");
    if (p)
    {
        std::vector < ReelBox_t > ReelBoxes;
        p->Service("Avahi ReelBox-List", &ReelBoxes);

        if (ReelBoxes.size() > 0)
        {
            // save changes in sysconfig variable in vdr into sysconfig file
            cSysConfig_vdr::GetInstance().Save();

            std::string cmd;
            // get the timezone from an AVG
            if (strlen(Setup.NetServerIP))
            {                   // there was already one configured, let's take this one...
                // TB: but only if it's available
                bool serverAvailable = false;
                for (unsigned int i = 0; i < ReelBoxes.size(); i++)
                    if (strcmp(Setup.NetServerIP, ReelBoxes.at(i).Ip.c_str()) == 0)
                        serverAvailable = true;
                if (serverAvailable)
                    cmd = std::string("getConfigsFromAVGServer.sh ") + Setup.NetServerIP + std::string(" sysconfig ; ");
                else
                    cmd = std::string("getConfigsFromAVGServer.sh ") + ReelBoxes.at(0).Ip + std::string(" sysconfig ; ");
            }
            else
                cmd = std::string("getConfigsFromAVGServer.sh ") + ReelBoxes.at(0).Ip + std::string(" sysconfig ; ");
            SystemExec(cmd.c_str());    // changes /etc/default/sysconfig

            cSysConfig_vdr::GetInstance().Load(SYSCONFIGFNAME); // load the changes in file into vdr
            dsyslog("(%s:%d) ... done loading sysconfig.", __FILE__, __LINE__);
        }

        // one or more reelbox avantgarde donot ask for TimeZone
        // it is got from the first avantgarde in the list
        askTimeZone = (ReelBoxes.size() == 0);
    }
#endif
    if (askTimeZone)
    {
        // Timezone
        currentCity = 0;
        nr_city_values = 1;
        DIR *zoneDir = NULL;
        struct dirent *entry = NULL;
        struct stat buf;
        std::string path = "/usr/share/zoneinfo";
        for (int k = 0; k < 256; k++)
        {
            city_values[k] = (char *)malloc(32);
            city_values[k][0] = '\0';
        }

        if ((zoneDir = opendir(path.c_str())) != NULL)
        {
            while ((entry = readdir(zoneDir)) != NULL)
            {
                if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0)
                {
                    std::string tmp = path + "/" + entry->d_name;
                    stat(tmp.c_str(), &buf);
                }
            }
            closedir(zoneDir);
        }
        else
            d(printf("Can not read directory \"%s\" because of error \"%s\"\n", path.c_str(), strerror(errno)))

        cSysConfig_vdr & sysconfig = cSysConfig_vdr::GetInstance();
        char *zoneInfo = strdup((char *)sysconfig.GetVariable("ZONEINFO"));

        char *buf2;
        char *continent = NULL;
        char *city = NULL;

        continent = strdup(strtok_r(zoneInfo, "/", &buf2)); /* go to first '/' */
        city = strdup(strtok_r(NULL, "/", &buf2));  /* get the rest */

        free(zoneInfo);

        if (city != NULL)
        {
            nr_city_values = 0;
            DIR *conDir = NULL;
            struct dirent *entry = NULL;
            struct stat buf;
            std::string path = "/usr/share/zoneinfo/Europe";

            if ((conDir = opendir(path.c_str())) != NULL)
            {
                while ((entry = readdir(conDir)) != NULL)
                {
                    std::string tmp = path + "/" + entry->d_name;
                    stat(tmp.c_str(), &buf);
                    if (S_ISREG(buf.st_mode))
                    {
                        city_values[nr_city_values] = strcpy(city_values[nr_city_values], entry->d_name);
                        nr_city_values++;
                    }
                }
                closedir(conDir);
            }
            else
                d(printf("Can not read directory \"%s\" because of error \"%s\"\n", path.c_str(), strerror(errno)))

            for (int i = 0; i < nr_city_values; i++)
                if (!strcmp(city_values[i], city))
                    currentCity = i;
        }
        free(city);
        free(continent);
    }                           // ask timezone