[Openib-windows] Installing WSD from a directory without write permissions.

Tzachi Dar tzachid at mellanox.co.il
Wed Jun 14 08:49:25 PDT 2006


Here is the patch.
 
Please note that there is probably another small issue here. Currently
we create the files on install and remove them on un-install. 
 
I think that the correct logic is to remove the files on the install or
never to remove them. (They are in the temp after all).
 
Thanks
Tzachi
 
Index: installsp.c
===================================================================
--- installsp.c (revision 385)
+++ installsp.c (working copy)
@@ -133,25 +133,71 @@
 #define IBSP_PM_NUM_SYMBOLS
(sizeof(_pm_symbols)/sizeof(pm_symbol_def_t))
 #define IBSP_PM_LANGUAGE "009" /* good for English */
 
+static CHAR *
+_IBSPGenerateFileName(char *header, char *file )
+{
+ DWORD size1, size;
+ CHAR *full_file_name;
+ int header_len = header == NULL ? 0 : strlen(header);
 
+ size = GetTempPath(0, NULL);
+ if (size == 0)
+ {
+  fprintf( stderr, "GetTempPath  failed\n" );
+  return NULL;
+ }
+ size1 = size + strlen(file) + header_len;
+ full_file_name = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY,
size1);
+ if ( full_file_name == NULL )
+ {
+  fprintf( stderr, "GetTempPath  failed\n" );
+  return NULL;
+ }
+ size1 = GetTempPath(size, full_file_name + header_len);
+ if (size != size1 + 1) 
+ {
+  fprintf( stderr, "Very strange, GetTempPath  returned something
different\n" );
+  HeapFree (GetProcessHeap (), 0, full_file_name);
+  return NULL;
+ }
+ if (header_len != 0)
+ {
+  memcpy(full_file_name, header, header_len);
+ }
+ strcat(full_file_name, file);
+ return full_file_name;
+}
+
+
 static DWORD
 _IBSPPerfmonIniFilesGenerate( void )
 {
  FILE *f_handle;
  DWORD num;
+ DWORD ret = ERROR_SUCCESS;
+ char *ibsp_pm_sym_file = NULL;
+ char *ibsp_pm_ini_file = NULL;
 
  /* create ".h" file first */
- f_handle = fopen( IBSP_PM_SYM_H_FILE, "w+" );
+ ibsp_pm_sym_file = _IBSPGenerateFileName(NULL, IBSP_PM_SYM_H_FILE);
+ if( !ibsp_pm_sym_file )
+ {
+  fprintf( stderr, "_IBSPGenerateFileName  failed\n" );
+  ret = ERROR_NOT_ENOUGH_MEMORY;
+  goto Cleanup;
+ }
 
+ f_handle = fopen( ibsp_pm_sym_file, "w+" );
+
  if( !f_handle )
  {
-  fprintf(
-   stderr, "Create Header file %s  failed\n", IBSP_PM_SYM_H_FILE );
-  return ERROR_FILE_INVALID;
+  fprintf( stderr, "Create Header file %s failed\n", ibsp_pm_sym_file
);
+  ret = ERROR_FILE_INVALID;
+  goto Cleanup;
  }
 
  fprintf(
-  f_handle, "/* %s Generated by program */ \r\n", IBSP_PM_SYM_H_FILE );
+  f_handle, "/* %s Generated by program */ \r\n", ibsp_pm_sym_file );
   
  
  for( num = 0; num < IBSP_PM_NUM_SYMBOLS; num++ )
@@ -164,16 +210,24 @@
  fclose( f_handle );
 
  /* create 'ini' file next */
- f_handle = fopen( IBSP_PM_INI_FILE, "w+" );
+ ibsp_pm_ini_file = _IBSPGenerateFileName(NULL, IBSP_PM_INI_FILE);
+ if( !ibsp_pm_sym_file )
+ {
+  fprintf( stderr, "_IBSPGenerateFileName  failed\n" );
+  ret = ERROR_NOT_ENOUGH_MEMORY;
+  goto Cleanup;
+ }
+ f_handle = fopen( ibsp_pm_ini_file, "w+" );
 
  if( !f_handle )
  {
-  fprintf( stderr, "Create INI file %s  failed\n", IBSP_PM_INI_FILE );
-  return ERROR_FILE_INVALID;
+  fprintf( stderr, "Create INI file %s  failed\n", ibsp_pm_ini_file );
+  ret = ERROR_FILE_INVALID;
+  goto Cleanup;
  }
  
  fprintf( f_handle, "[info]\r\ndrivername=" IBSP_PM_SUBKEY_NAME
-  "\r\nsymbolfile=" IBSP_PM_SYM_H_FILE "\r\n\r\n" );
+  "\r\nsymbolfile=%s\r\n\r\n", ibsp_pm_sym_file );
  fprintf( f_handle,"[languages]\r\n" IBSP_PM_LANGUAGE
   "=language" IBSP_PM_LANGUAGE "\r\n\r\n" );
 
@@ -192,23 +246,60 @@
  fflush( f_handle );
  fclose( f_handle );
 
- return ERROR_SUCCESS;
+Cleanup:
+ if ( ibsp_pm_sym_file )
+ {
+  HeapFree (GetProcessHeap (), 0, ibsp_pm_sym_file);
+ }
+ if ( ibsp_pm_ini_file )
+ {
+  HeapFree (GetProcessHeap (), 0, ibsp_pm_ini_file);
+ }
+ return ret;
 }
 
 
 static void
 _IBSPPerfmonIniFilesRemove( void )
 {
- if( !DeleteFile( IBSP_PM_INI_FILE ) )
+ char *ibsp_pm_sym_file = NULL;
+ char *ibsp_pm_ini_file = NULL;
+
+ ibsp_pm_sym_file = _IBSPGenerateFileName(NULL, IBSP_PM_SYM_H_FILE);
+ if( !ibsp_pm_sym_file )
  {
+  fprintf( stderr, "_IBSPGenerateFileName  failed\n" );
+  goto Cleanup;
+ }
+
+ ibsp_pm_ini_file = _IBSPGenerateFileName(NULL, IBSP_PM_INI_FILE);
+ if( !ibsp_pm_sym_file )
+ {
+  fprintf( stderr, "_IBSPGenerateFileName  failed\n" );
+  goto Cleanup;
+ }
+
+ if( !DeleteFile( ibsp_pm_ini_file ) )
+ {
   fprintf( stderr, "Delete file %s failed status %d\n",
-   IBSP_PM_INI_FILE, GetLastError() );
+   ibsp_pm_ini_file, GetLastError() );
  }
- if( !DeleteFile( IBSP_PM_SYM_H_FILE ) )
+ if( !DeleteFile( ibsp_pm_sym_file ) )
  {
   fprintf( stderr,"Delete file %s failed status %d\n",
-   IBSP_PM_SYM_H_FILE, GetLastError() );
+   ibsp_pm_sym_file, GetLastError() );
  }
+
+Cleanup: 
+ if ( ibsp_pm_sym_file )
+ {
+  HeapFree (GetProcessHeap (), 0, ibsp_pm_sym_file);
+ }
+ if ( ibsp_pm_ini_file )
+ {
+  HeapFree (GetProcessHeap (), 0, ibsp_pm_ini_file);
+ }
+ 
 }
 
 
@@ -322,20 +413,34 @@
 _IBSPPerfmonRegisterCounters( void )
 {
  DWORD status;
+ char *ibsp_pm_ini_file = NULL;
+
+ ibsp_pm_ini_file = _IBSPGenerateFileName("unused ", IBSP_PM_INI_FILE);
+ if( !ibsp_pm_ini_file )
+ {
+  fprintf( stderr, "_IBSPGenerateFileName  failed\n" );
+  status = ERROR_NOT_ENOUGH_MEMORY;
+  goto Cleanup;
+ }
+
  /*
   * format commandline string, as per SDK :
   * Pointer to a null-terminated string that consists of one or more 
   * arbitrary letters, a space, and then the name of the initialization
   * file.
   */
- status = LoadPerfCounterTextStrings(
-  TEXT("unused ") TEXT(IBSP_PM_INI_FILE), TRUE );
+ status = LoadPerfCounterTextStrings( ibsp_pm_ini_file, TRUE );
  if( status != ERROR_SUCCESS )
  {
   status = GetLastError();
   fprintf( stderr,
    "IBSPPerfmonRegisterCounters install failed status %d\n", status );
  }
+Cleanup: 
+ if ( ibsp_pm_ini_file )
+ {
+  HeapFree (GetProcessHeap (), 0, ibsp_pm_ini_file);
+ }
 
  return status;
 }
 


________________________________

	From: Tillier, Fabian [mailto:ftillier at silverstorm.com] 
	Sent: Friday, June 09, 2006 12:57 AM
	To: Tzachi Dar; openib-windows at openib.org
	Subject: RE: Installing WSD from a directory without write
permissions.
	
	

	Yes, please.

	 

	Thanks,

	 

	- Fab

	 

	
________________________________


	From: Tzachi Dar [mailto:tzachid at mellanox.co.il] 
	Sent: Thursday, June 08, 2006 2:56 PM
	To: Tillier, Fabian; openib-windows at openib.org
	Subject: Installing WSD from a directory without write
permissions.

	 

	Hi Fab,

	 

	Installing WSD on a directory without write permissions fails to
write the needed data for perfmon.

	The reason for this is that there are files that are written to
the local directory. It seems that the solution

	to this problem is to write the files to the temp directory.

	 

	Should I prepare a patch for that?

	 

	Thanks

	Tzachi 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20060614/f9f24f53/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wsd_installer.patch
Type: application/octet-stream
Size: 5724 bytes
Desc: wsd_installer.patch
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20060614/f9f24f53/attachment.obj>


More information about the ofw mailing list