Question

I have a exe file that I run in a worker role with the following code in my worker role:

 try
        {
            //Get local storage path
            var locRes = RoleEnvironment.GetLocalResource("data");
            var localStoragePath = String.Format(locRes.RootPath);

            var p = new Process();
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
            p.StartInfo.FileName = this._processorExecutable;
            p.StartInfo.EnvironmentVariables["TEMP"] = localStoragePath;
            p.StartInfo.EnvironmentVariables.Add("transparency", "1");
            p.StartInfo.EnvironmentVariables.Add("verbose", "1");
            p.StartInfo.EnvironmentVariables.Add("in", _inFile);
            p.StartInfo.EnvironmentVariables.Add("format", filetype);
            p.StartInfo.EnvironmentVariables.Add("out", localStoragePath + msg.flameOutFile);
            msg.flameOutFile = localStoragePath + msg.flameOutFile;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.Start();
            _cloudUtil.StoreNewLogMessage(new LogMessage(p.StandardOutput.ReadToEnd()));
            _cloudUtil.StoreNewLogMessage(new LogMessage(p.StandardError.ReadToEnd()));
            p.WaitForExit();
            var fi = new FileInfo(msg.flameOutFile);
        }
        catch (Exception ex)
        {
            _cloudUtil.StoreNewLogMessage(new LogMessage("Error: " + ex));
        }

The exe in question is a a command line program for rendering flame fractals and can be found here: https://code.google.com/p/flam3/downloads/list

It works as expected locally in the emulator. I am able to supply a xml file to the program which it will use to render a flame fractal and output a image file. Happy days.

My problem is when I run it in the cloud production environment I get an error from the program that I am not able to interpret.

The error I get is:

FLAM3: reading string from temp file: Invalid argument

Which stems from the following code in the fractal program:

    char *flam3_print_to_string(flam3_genome *cp) {

   FILE *tmpflame;
   long stringbytes;
   char *genome_string;

   int using_tmpdir = 0;
   char *tmp_path;
   char tmpnam[256];

   tmpflame = tmpfile();
   if (NULL==tmpflame) {
#ifdef _WIN32       
       // This might be a permissions problem, so let's try to open a
       // tempfile in the env var TEMP's area instead
       tmp_path = getenv("TEMP");

       if (tmp_path != NULL) {
          strcpy(tmpnam, tmp_path);
          strcat(tmpnam, "\\fr0st.tmp");
          tmpflame = fopen(tmpnam, "w+");
          if (tmpflame != NULL) {
             using_tmpdir = 1;
          }
       }
#endif
       if (using_tmpdir == 0) {
          perror("FLAM3: opening temporary file");
          return (NULL);
       }
   }
   flam3_print(tmpflame,cp,NULL,flam3_dont_print_edits);
   stringbytes = ftell(tmpflame);
   fseek(tmpflame,0L, SEEK_SET);
   genome_string = (char *)calloc(stringbytes+1,1);
   if (stringbytes != fread(genome_string, 1, stringbytes, tmpflame)) {
       perror("FLAM3: reading string from temp file");
   }
   fclose(tmpflame);

   if (using_tmpdir)
      unlink(tmpnam);

   return(genome_string);
}

The full source can be found here: https://code.google.com/p/flam3/source/browse/trunk/src/flam3.c

I hoping someone can shed some light on why the program fails to render images in the production environment. My thoughts where going in the direction of something with permissions or similar security issues.

Any help would be appreciated.


UPDATE:


I've tried to figure out what tmp_path might be. But Im struggeling quite a bit with that. I can't compile the program I have problems with, event though I have the source code. As an alternative I have create a small c++ program that emulates the section with the issue. Put it does not output anything to standard output:

#include "stdafx.h"
#include<stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
#pragma warning(push)
#pragma warning(disable: 4996) //4996 for _CRT_SECURE_NO_WARNINGS equivalent

    cout << "Entering debugger\n";

    FILE *tmpflame;
    long stringbytes;
    char *genome_string;

    int using_tmpdir = 0;
    char *tmp_path;
    char tmpnam[256];

    // deprecated code here
    tmpflame = tmpfile();

    //strcpy (tmpflame->_tmpfname,tmpnam);
    if (NULL==tmpflame) {
#ifdef _WIN32       
        cout <<"Entering branch 1\n";

        // This might be a permissions problem, so let's try to open a
        // tempfile in the env var TEMP's area instead
        tmp_path = getenv("TEMP");

        if (tmp_path != NULL) {
            cout <<"Entering branch 2\n";

            strcpy(tmpnam, tmp_path);
            strcat(tmpnam, "\\fr0st.tmp");
            tmpflame = fopen(tmpnam, "w+");
            if (tmpflame != NULL) {
                cout <<"Entering branch 3\n";
                using_tmpdir = 1;
            }
        }
#endif
    }
    cout <<tmpflame->_tmpfname;
    return 0;
#pragma warning(pop)

}
Était-ce utile?

La solution

Right. The problem turned out to be a permission issue. Somehow the exe file does not get the right credentials. I solved it by elevating the worker role with: Adding <Runtime executionContext="elevated" /> to the .csdef inside the <WorkerRole>

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top