239 |
int |
int |
240 |
w32_kill(int pid, int sig) |
w32_kill(int pid, int sig) |
241 |
{ |
{ |
242 |
return ((process_kill(pid, sig) == TRUE) ? 0 : -1); |
return ((process_kill((HANDLE)pid, sig) == TRUE) ? 0 : -1); |
243 |
|
} |
244 |
|
|
245 |
|
/* This function creates a temporary file name with the given extension |
246 |
|
* the unixy param controls both the extension and the path separator |
247 |
|
* return an xmalloc'ed string of a newly created temp file or die. */ |
248 |
|
static char * |
249 |
|
create_batch_filename(char const *base, int unixy) |
250 |
|
{ |
251 |
|
const char *const ext = unixy ? "sh" : "bat"; |
252 |
|
const char *error = NULL; |
253 |
|
char temp_path[MAXPATHLEN]; /* need to know its length */ |
254 |
|
unsigned path_size = GetTempPath(sizeof temp_path, temp_path); |
255 |
|
int path_is_dot = 0; |
256 |
|
unsigned uniq = 1; |
257 |
|
const unsigned sizemax = strlen (base) + strlen (ext) + 10; |
258 |
|
|
259 |
|
if (path_size == 0) |
260 |
|
{ |
261 |
|
path_size = GetCurrentDirectory (sizeof temp_path, temp_path); |
262 |
|
path_is_dot = 1; |
263 |
|
} |
264 |
|
|
265 |
|
while (path_size > 0 && |
266 |
|
path_size + sizemax < sizeof temp_path && |
267 |
|
uniq < 0x10000) |
268 |
|
{ |
269 |
|
unsigned size = sprintf (temp_path + path_size, |
270 |
|
"%s%s-%x.%s", |
271 |
|
temp_path[path_size - 1] == '\\' ? "" : "\\", |
272 |
|
base, uniq, ext); |
273 |
|
HANDLE h = CreateFile (temp_path, /* file name */ |
274 |
|
GENERIC_READ | GENERIC_WRITE, /* desired access */ |
275 |
|
0, /* no share mode */ |
276 |
|
NULL, /* default security attributes */ |
277 |
|
CREATE_NEW, /* creation disposition */ |
278 |
|
FILE_ATTRIBUTE_NORMAL | /* flags and attributes */ |
279 |
|
FILE_ATTRIBUTE_TEMPORARY, /* we'll delete it */ |
280 |
|
NULL); /* no template file */ |
281 |
|
|
282 |
|
if (h == INVALID_HANDLE_VALUE) |
283 |
|
{ |
284 |
|
const DWORD er = GetLastError(); |
285 |
|
|
286 |
|
if (er == ERROR_FILE_EXISTS || er == ERROR_ALREADY_EXISTS) |
287 |
|
++uniq; |
288 |
|
|
289 |
|
/* the temporary path is not guaranteed to exist */ |
290 |
|
else if (path_is_dot == 0) |
291 |
|
{ |
292 |
|
path_size = GetCurrentDirectory (sizeof temp_path, temp_path); |
293 |
|
path_is_dot = 1; |
294 |
|
} |
295 |
|
|
296 |
|
else |
297 |
|
{ |
298 |
|
error = map_windows32_error_to_string (er); |
299 |
|
break; |
300 |
|
} |
301 |
|
} |
302 |
|
else |
303 |
|
{ |
304 |
|
const unsigned final_size = path_size + size + 1; |
305 |
|
char *const path = (char *) xmalloc (final_size); |
306 |
|
memcpy (path, temp_path, final_size); |
307 |
|
CloseHandle (h); |
308 |
|
if (unixy) |
309 |
|
{ |
310 |
|
char *p; |
311 |
|
int ch; |
312 |
|
for (p = path; (ch = *p) != 0; ++p) |
313 |
|
if (ch == '\\') |
314 |
|
*p = '/'; |
315 |
|
} |
316 |
|
return path; /* good return */ |
317 |
|
} |
318 |
|
} |
319 |
|
|
320 |
|
if (error == NULL) |
321 |
|
error = _("Cannot create a temporary file\n"); |
322 |
|
fatal (NILF, error); |
323 |
|
|
324 |
|
/* not reached */ |
325 |
|
return NULL; |
326 |
} |
} |
327 |
#endif /* WINDOWS32 */ |
#endif /* WINDOWS32 */ |
328 |
|
|
3332 |
FILE* batch = NULL; |
FILE* batch = NULL; |
3333 |
int id = GetCurrentProcessId(); |
int id = GetCurrentProcessId(); |
3334 |
PATH_VAR(fbuf); |
PATH_VAR(fbuf); |
|
char* fname = NULL; |
|
3335 |
|
|
3336 |
/* create a file name */ |
/* create a file name */ |
3337 |
sprintf(fbuf, "make%d", id); |
sprintf(fbuf, "make%d", id); |
3338 |
fname = tempnam(".", fbuf); |
*batch_filename_ptr = create_batch_filename (fbuf, unixy_shell); |
|
|
|
|
/* create batch file name */ |
|
|
*batch_filename_ptr = xmalloc(strlen(fname) + 5); |
|
|
strcpy(*batch_filename_ptr, fname); |
|
|
|
|
|
/* make sure path name is in DOS backslash format */ |
|
|
if (!unixy_shell) { |
|
|
fname = *batch_filename_ptr; |
|
|
for (i = 0; fname[i] != '\0'; ++i) |
|
|
if (fname[i] == '/') |
|
|
fname[i] = '\\'; |
|
|
strcat(*batch_filename_ptr, ".bat"); |
|
|
} else { |
|
|
strcat(*batch_filename_ptr, ".sh"); |
|
|
} |
|
3339 |
|
|
3340 |
DB (DB_JOBS, (_("Creating temporary batch file %s\n"), |
DB (DB_JOBS, (_("Creating temporary batch file %s\n"), |
3341 |
*batch_filename_ptr)); |
*batch_filename_ptr)); |