Exemplo n.º 1
0
bool wxDoSetEnv(const wxString& var, const wxChar *value)
{
    // update the CRT environment if possible as people expect getenv() to also
    // work and it is not affected by Win32 SetEnvironmentVariable() call (OTOH
    // the CRT does use Win32 call to update the process environment block so
    // there is no need to call it)
    //
    // TODO: add checks for the other compilers (and update wxSetEnv()
    //       documentation in interface/wx/utils.h accordingly)
#if defined(__VISUALC__) || defined(__MINGW32__)
    // notice that Microsoft _putenv() has different semantics from POSIX
    // function with almost the same name: in particular it makes a copy of the
    // string instead of using it as part of environment so we can safely call
    // it here without going through all the troubles with wxSetEnvModule as in
    // src/unix/utilsunx.cpp
    wxString envstr = var;
    envstr += '=';
    if ( value )
        envstr += value;
    if ( _tputenv(envstr.t_str()) != 0 )
        return false;
#else // other compiler
    if ( !::SetEnvironmentVariable(var.t_str(), value) )
    {
        wxLogLastError(wxT("SetEnvironmentVariable"));

        return false;
    }
#endif // compiler

    return true;
}
Exemplo n.º 2
0
int main(int argc, char *argv[]) {
    static struct WSAData wsa_state;
    TCHAR *c, stunnel_exe_path[MAX_PATH];

    tls_init(); /* initialize thread-local storage */

    /* set current working directory and engine path */
    GetModuleFileName(0, stunnel_exe_path, MAX_PATH);
    c=_tcsrchr(stunnel_exe_path, TEXT('\\')); /* last backslash */
    if(c) /* found */
        c[1]=TEXT('\0'); /* truncate program name */
#ifndef _WIN32_WCE
    if(!SetCurrentDirectory(stunnel_exe_path)) {
        /* log to stderr, as s_log() is not initialized */
        _ftprintf(stderr, TEXT("Cannot set directory to %s"),
            stunnel_exe_path);
        return 1;
    }
#endif
    _tputenv(str_tprintf(TEXT("OPENSSL_ENGINES=%s"), stunnel_exe_path));

    if(WSAStartup(MAKEWORD(1, 1), &wsa_state))
        return 1;
    resolver_init();
    main_init();
    if(!main_configure(argc>1 ? argv[1] : NULL, argc>2 ? argv[2] : NULL))
        daemon_loop();
    main_cleanup();
    return 0;
}
Exemplo n.º 3
0
bool PathReadWriter::SetPathInRegistry(const CStdString& sPath) const
{
	_tputenv(_T("PATH=") + sPath);
	bool bRet = RegUtils::SetRegExpandStringValue(HKEY_LOCAL_MACHINE, REG_ENVIRONMENT, REG_PATH_VALUE, sPath);
	BroadcastPathChangeNotification();
	return bRet;
}
Exemplo n.º 4
0
CTortoiseProcApp::CTortoiseProcApp()
{
	SetDllDirectory(L"");
	// prevent from inheriting %GIT_DIR% from parent process by resetting it,
	// use MSVC function instead of Windows API because MSVC runtime caches environment variables
	_tputenv(_T("GIT_DIR="));
	CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
	EnableHtmlHelp();
	SYS_IMAGE_LIST();
	CHooks::Create();
	m_bLoadUserToolbars = FALSE;
	m_bSaveState = FALSE;
	retSuccess = false;
	m_gdiplusToken = NULL;
}
Exemplo n.º 5
0
CTortoiseGitBlameApp::CTortoiseGitBlameApp()
{
    SetDllDirectory(L"");
    SetTaskIDPerUUID();
    // prevent from inheriting %GIT_DIR% from parent process by resetting it,
    // use MSVC function instead of Windows API because MSVC runtime caches environment variables
    _tputenv(_T("GIT_DIR="));
#if ENABLE_CRASHHANLDER
    CCrashReportTGit crasher(L"TortoiseGitBlame " _T(APP_X64_STRING), TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD, TGIT_VERDATE);
    CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
#endif
    EnableHtmlHelp();

    m_nAppLook = 0;
    m_gdiplusToken = NULL;
    m_bHiColorIcons = TRUE;
}
Exemplo n.º 6
0
CTortoiseProcApp::CTortoiseProcApp()
{
	CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) _T(": Constructor\n"));
	SetDllDirectory(L"");
	// prevent from inheriting %GIT_DIR% from parent process by resetting it,
	// use MSVC function instead of Windows API because MSVC runtime caches environment variables
	_tputenv(_T("GIT_DIR="));
	CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
	EnableHtmlHelp();
	SYS_IMAGE_LIST();
	CHooks::Create();
	git_threads_init();
	m_bLoadUserToolbars = FALSE;
	m_bSaveState = FALSE;
	retSuccess = false;
	m_gdiplusToken = NULL;
#if defined (_WIN64) && _MSC_VER >= 1800
	_set_FMA3_enable(0);
#endif
}
Exemplo n.º 7
0
bool CSubprocess::CreateProcess(LPCTSTR pszCmdline)
{
  m_idProcess=0;
  int fdchild=-1; // the file descriptor for the child (slave) half of the pseudo-tty pair

  // Try the Unix98 scheme to get a pseudo-tty pair
  String strMasterTty("/dev/ptmx"), strChildTty;
  m_tty=open(strMasterTty, O_RDWR | O_NOCTTY);
  if (-1!=m_tty) {
    if ((0 == grantpt(m_tty)) && (0 == unlockpt(m_tty))) {
      strChildTty = ptsname(m_tty);
      if (!strChildTty.empty()) {
        fdchild = open(strChildTty, O_RDWR);
      }
    }
    if (-1==fdchild) {
      close(m_tty);
      m_tty=fdchild=-1;
    } else {
      VTRACE("opened %s - fd=%d\n",(LPCTSTR)strMasterTty,m_tty);
    }
  }
  
  if (-1==m_tty) {
    // Try the BSD scheme to get a free /dev/ptyp0 (master) and /dev/ttyp0 (slave) tty pair
    for(unsigned int c=0;c<64;c++){
      strMasterTty.Format("/dev/pty%c%x",'p'+c/16,c%16);
    
      m_tty=open(strMasterTty, O_RDWR | O_NOCTTY);
      if (-1!=m_tty) { 
        strChildTty.Format("/dev/tty%c%x",'p'+c/16,c%16);	
      
        fdchild = open(strChildTty, O_RDWR);
        if (-1==fdchild) {
          close(m_tty);
          m_tty=fdchild=-1;
        } else {
          VTRACE("opened %s - fd=%d\n",(LPCTSTR)strMasterTty,m_tty);
          break;
        }
      }
    }
  }

  if(-1==m_tty){
    ERROR(_T("Failed to get a pty\n"));
    return false;
  }  
  
  TRACE(_T("Master pty %s (fd %d) slave pty %s (fd %d)\n"),(LPCTSTR)strMasterTty,m_tty,(LPCTSTR)strChildTty,fdchild);

  m_idProcess=fork();
  
  switch (m_idProcess) {
    // Fork failed
    case -1:
      TRACE(_T("Failed to create process - %s\n"),strerror(errno));
      m_idProcess=0;
      break;
    case 0:
      // Process is created (we're the child)
      {
        // Close all descriptors except the slave side of the pseudo-terminal
        for (int fd = 0; fd < (int) sysconf(_SC_OPEN_MAX); fd++) {
          if(fd!=fdchild){
            close(fd);
          }
        }
        setsid();
        
        dup2(fdchild, 0);
        dup2(fdchild, 1);
        dup2(fdchild, 2);
        
        close(fdchild);

        if(!m_strDir.empty()){
          if(0!=chdir(m_strDir)){
            if(m_bVerbose){
              fprintf(stderr,_T("*** Failed to change directory to %s\n"),(LPCTSTR)m_strDir);
            }
            exit (5);
          }
        }
        if(m_bVerbose){
          fprintf(stderr,_T("*** Process %d created \"%s\"\n"),m_idProcess,pszCmdline);
        }

        StringArray ar;
        int argc=String(pszCmdline).Chop(ar,_TCHAR(' '),true);
        TCHAR **argv=new TCHAR *[1+argc];
        for(int i=0;i<argc;i++){
          argv[i]=new TCHAR[1+strlen(ar[i])];  
          strcpy(argv[i],ar[i]);
        }
        argv[argc]=0;
        if(!m_strPath.empty()){
          _tputenv(String::SFormat(_T("PATH=%s"),(LPCTSTR)m_strPath));
        }
        _texecvp(argv[0], argv);  
      }

      fprintf(stderr,"exec error - %s\n",strerror(errno));
      exit(4);

    default:
      // Process is created (we're the parent)
      TRACE(_T("Closing fd %d\n"),fdchild);
      close(fdchild);
      TRACE(_T("Forked to create process %s - process id <%d>\n"), pszCmdline, m_idProcess);
      break;
  }
  return 0!=m_idProcess;
}
Exemplo n.º 8
0
int WINAPI WinMain(HINSTANCE this_instance, HINSTANCE prev_instance,
#ifdef _WIN32_WCE
        LPWSTR lpCmdLine,
#else
        LPSTR lpCmdLine,
#endif
        int nCmdShow) {
    TCHAR stunnel_exe_path[MAX_PATH];
    LPTSTR c;
#ifndef _WIN32_WCE
    LPTSTR errmsg;
#endif

    (void)prev_instance; /* squash the unused parameter warning */
    (void)lpCmdLine; /* squash the unused parameter warning */
    (void)nCmdShow; /* squash the unused parameter warning */

    tls_init(); /* initialize thread-local storage */
    ghInst=this_instance;
    gui_cmdline(); /* setup global cmdline structure */
    GetModuleFileName(0, stunnel_exe_path, MAX_PATH);

#ifndef _WIN32_WCE
    /* find previous instances of the same executable */
    if(!cmdline.service && !cmdline.install && !cmdline.uninstall &&
            !cmdline.reload && !cmdline.reopen &&
            !cmdline.start && !cmdline.stop) {
        EnumWindows(enum_windows, (LPARAM)stunnel_exe_path);
        if(cmdline.exit)
            return 1; /* in case EnumWindows didn't find a previous instance */
    }
#endif

    /* set current working directory and engine path */
    c=_tcsrchr(stunnel_exe_path, TEXT('\\')); /* last backslash */
    if(c) { /* found */
        *c=TEXT('\0'); /* truncate the program name */
        c=_tcsrchr(stunnel_exe_path, TEXT('\\')); /* previous backslash */
        if(c && !_tcscmp(c+1, TEXT("bin")))
            *c=TEXT('\0'); /* truncate "bin" */
    }
#ifndef _WIN32_WCE
    if(!SetCurrentDirectory(stunnel_exe_path)) {
        errmsg=str_tprintf(TEXT("Cannot set directory to %s"),
            stunnel_exe_path);
        message_box(errmsg, MB_ICONERROR);
        str_free(errmsg);
        return 1;
    }
    /* try to enter the "config" subdirectory, ignore the result */
    SetCurrentDirectory(TEXT("config"));
#endif
    _tputenv(str_tprintf(TEXT("OPENSSL_ENGINES=%s\\engines"),
        stunnel_exe_path));

    if(initialize_winsock())
        return 1;

#ifndef _WIN32_WCE
    if(cmdline.service) /* "-service" must be processed before "-install" */
        return service_initialize();
    if(cmdline.install)
        return service_install();
    if(cmdline.uninstall)
        return service_uninstall();
    if(cmdline.start)
        return service_start();
    if(cmdline.stop)
        return service_stop();
    if(cmdline.reload)
        return service_user(SIGNAL_RELOAD_CONFIG);
    if(cmdline.reopen)
        return service_user(SIGNAL_REOPEN_LOG);
#endif
    return gui_loop();
}