Pass callback parameters as separate arguments.

This commit is contained in:
darin%meer.net 2005-06-23 04:04:36 +00:00
Родитель 56a4c4bb6b
Коммит 6fc855b9cb
1 изменённых файлов: 22 добавлений и 33 удалений

Просмотреть файл

@ -75,6 +75,8 @@
// however, given the way most operating systems recycle PIDs. We'll take our // however, given the way most operating systems recycle PIDs. We'll take our
// chances ;-) // chances ;-)
// //
// A similar #define lives in updater.cpp and should be kept in sync with this.
//
#if defined(XP_UNIX) && !defined(XP_MACOSX) #if defined(XP_UNIX) && !defined(XP_MACOSX)
#define USE_EXECV #define USE_EXECV
#endif #endif
@ -107,18 +109,6 @@ DoubleQuoteIfNeeded(nsCString &str)
} }
#endif #endif
static void
MakeCommandLine(char **argv, nsCString &result)
{
result.Truncate();
while (*argv) {
result.Append(*argv);
++argv;
if (*argv)
result.Append(' ');
}
}
PR_STATIC_CALLBACK(int) PR_STATIC_CALLBACK(int)
ScanDirComparator(nsIFile *a, nsIFile *b, void *unused) ScanDirComparator(nsIFile *a, nsIFile *b, void *unused)
{ {
@ -320,11 +310,6 @@ ApplyUpdate(nsIFile *appDir, nsIFile *updateDir, nsILocalFile *statusFile,
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return; return;
// Form the command line that will be used to call us back.
nsCAutoString commandLine;
MakeCommandLine(appArgv, commandLine);
LOG(("callback command line: %s\n", commandLine.get()));
if (!SetStatus(statusFile, "applying")) { if (!SetStatus(statusFile, "applying")) {
LOG(("failed setting status to 'applying'\n")); LOG(("failed setting status to 'applying'\n"));
return; return;
@ -337,26 +322,30 @@ ApplyUpdate(nsIFile *appDir, nsIFile *updateDir, nsILocalFile *statusFile,
DoubleQuoteIfNeeded(commandLine); DoubleQuoteIfNeeded(commandLine);
#endif #endif
char **argv = new char*[5]; // Construct the PID argument for this process. If we are using execv, then
// we pass "0" which is then ignored by the updater.
#if defined(USE_EXECV)
NS_NAMED_LITERAL_CSTRING(pid, "0");
#else
nsCAutoString pid;
pid.AppendInt((PRInt32)
# if defined(XP_WIN)
GetCurrentProcessId()
# else
getpid()
# endif
);
#endif
char **argv = new char*[4 + appArgc];
if (!argv) if (!argv)
return; return;
argv[0] = (char*) updaterPath.get(); argv[0] = (char*) updaterPath.get();
argv[1] = (char*) updateDirPath.get(); argv[1] = (char*) updateDirPath.get();
argv[2] = (char*) commandLine.get(); argv[2] = (char*) pid.get();
#if defined(USE_EXECV) for (int i = 0; i < appArgc; ++i)
argv[3] = nsnull; argv[3 + i] = appArgv[i];
#else argv[3 + appArgc] = nsnull;
nsCAutoString pid;
pid.AppendInt((PRInt32)
#if defined(XP_WIN)
GetCurrentProcessId()
#else
getpid()
#endif
);
argv[3] = (char*) pid.get();
argv[4] = nsnull;
#endif
LOG(("spawning updater process [%s]\n", updaterPath.get())); LOG(("spawning updater process [%s]\n", updaterPath.get()));