comparison src/process-nt.c @ 288:e11d67e05968 r21-0b42

Import from CVS: tag r21-0b42
author cvs
date Mon, 13 Aug 2007 10:35:54 +0200
parents 57709be46d1b
children c9fe270a4101
comparison
equal deleted inserted replaced
287:13a0bd77a29d 288:e11d67e05968
218 /*-----------------------------------------------------------------------*/ 218 /*-----------------------------------------------------------------------*/
219 219
220 /* 220 /*
221 * We handle the following signals: 221 * We handle the following signals:
222 * 222 *
223 * SIGKILL, SIGTERM, SIGQUIT - These three translate to ExitProcess 223 * SIGKILL, SIGTERM, SIGQUIT, SIGHUP - These four translate to ExitProcess
224 * executed by the remote process 224 * executed by the remote process
225 * SIGINT - The remote process is sent CTRL_BREAK_EVENT 225 * SIGINT - The remote process is sent CTRL_BREAK_EVENT
226 */ 226 */
227 227
228 /* 228 /*
309 switch (signo) 309 switch (signo)
310 { 310 {
311 case SIGKILL: 311 case SIGKILL:
312 case SIGTERM: 312 case SIGTERM:
313 case SIGQUIT: 313 case SIGQUIT:
314 case SIGHUP:
314 { 315 {
315 sigkill_data d; 316 sigkill_data d;
316 d.adr_ExitProcess = GetProcAddress (h_kernel, "ExitProcess"); 317 d.adr_ExitProcess = GetProcAddress (h_kernel, "ExitProcess");
317 assert (d.adr_ExitProcess); 318 assert (d.adr_ExitProcess);
318 retval = run_in_other_process (h_process, 319 retval = run_in_other_process (h_process,
364 */ 365 */
365 static void 366 static void
366 validate_signal_number (int signo) 367 validate_signal_number (int signo)
367 { 368 {
368 if (signo != SIGKILL && signo != SIGTERM 369 if (signo != SIGKILL && signo != SIGTERM
369 && signo != SIGQUIT && signo != SIGINT) 370 && signo != SIGQUIT && signo != SIGINT
371 && signo != SIGHUP)
370 signal_simple_error ("Signal number not supported", make_int (signo)); 372 signal_simple_error ("Signal number not supported", make_int (signo));
371 } 373 }
372 374
373 /*-----------------------------------------------------------------------*/ 375 /*-----------------------------------------------------------------------*/
374 /* Process methods */ 376 /* Process methods */
415 */ 417 */
416 418
417 /* #### This function completely ignores Vprocess_environment */ 419 /* #### This function completely ignores Vprocess_environment */
418 420
419 static void 421 static void
420 signal_cannot_launch (char* image_file, DWORD err) 422 signal_cannot_launch (Lisp_Object image_file, DWORD err)
421 { 423 {
422 mswindows_set_errno (err); 424 mswindows_set_errno (err);
423 error ("Starting \"%s\": %s", image_file, strerror (errno)); 425 error ("Starting \"%S\": %s", image_file, strerror (errno));
424 } 426 }
425 427
426 static int 428 static int
427 nt_create_process (struct Lisp_Process *p, 429 nt_create_process (struct Lisp_Process *p,
428 char **argv, CONST char *current_dir) 430 Lisp_Object *argv, int nargv,
431 Lisp_Object program, Lisp_Object cur_dir)
429 { 432 {
430 HANDLE hmyshove, hmyslurp, hprocin, hprocout; 433 HANDLE hmyshove, hmyslurp, hprocin, hprocout;
431 LPTSTR command_line; 434 LPTSTR command_line;
432 BOOL do_io, windowed; 435 BOOL do_io, windowed;
433 436
434 /* Find out whether the application is windowed or not */ 437 /* Find out whether the application is windowed or not */
435 { 438 {
436 /* SHGetFileInfo tends to return ERROR_FILE_NOT_FOUND on most 439 /* SHGetFileInfo tends to return ERROR_FILE_NOT_FOUND on most
437 errors. This leads to bogus error message. */ 440 errors. This leads to bogus error message. */
438 DWORD image_type = SHGetFileInfo (argv[0], 0, NULL, 0, SHGFI_EXETYPE); 441 DWORD image_type = SHGetFileInfo ((char *)XSTRING_DATA (program), 0,NULL,
442 0, SHGFI_EXETYPE);
439 if (image_type == 0) 443 if (image_type == 0)
440 signal_cannot_launch (argv[0], (GetLastError () == ERROR_FILE_NOT_FOUND 444 signal_cannot_launch (program, (GetLastError () == ERROR_FILE_NOT_FOUND
441 ? ERROR_BAD_FORMAT : GetLastError ())); 445 ? ERROR_BAD_FORMAT : GetLastError ()));
442 windowed = HIWORD (image_type) != 0; 446 windowed = HIWORD (image_type) != 0;
443 } 447 }
444 448
445 /* Decide whether to do I/O on process handles, or just mark the 449 /* Decide whether to do I/O on process handles, or just mark the
473 } 477 }
474 478
475 /* Convert an argv vector into Win32 style command line by a call to 479 /* Convert an argv vector into Win32 style command line by a call to
476 lisp function `nt-quote-process-args' which see (in winnt.el)*/ 480 lisp function `nt-quote-process-args' which see (in winnt.el)*/
477 { 481 {
478 char** thisarg; 482 int i;
479 Lisp_Object args_or_ret = Qnil; 483 Lisp_Object args_or_ret = Qnil;
480 struct gcpro gcpro1; 484 struct gcpro gcpro1;
481 485
482 GCPRO1 (args_or_ret); 486 GCPRO1 (args_or_ret);
483 487
484 for (thisarg = argv; *thisarg; ++thisarg) 488 for (i = 0; i < nargv; ++i)
485 args_or_ret = Fcons (build_string (*thisarg), args_or_ret); 489 args_or_ret = Fcons (*argv++, args_or_ret);
486 args_or_ret = Fnreverse (args_or_ret); 490 args_or_ret = Fnreverse (args_or_ret);
491 args_or_ret = Fcons (program, args_or_ret);
487 492
488 args_or_ret = call1 (Qnt_quote_process_args, args_or_ret); 493 args_or_ret = call1 (Qnt_quote_process_args, args_or_ret);
489 494
490 if (!STRINGP (args_or_ret)) 495 if (!STRINGP (args_or_ret))
491 /* Luser wrote his/her own clever version */ 496 /* Luser wrote his/her own clever version */
492 error ("Bogus return value from `nt-quote-process-args'"); 497 error ("Bogus return value from `nt-quote-process-args'");
493 498
494 command_line = alloca_array (char, (strlen (argv[0]) 499 command_line = alloca_array (char, (XSTRING_LENGTH (program)
495 + XSTRING_LENGTH (args_or_ret) + 2)); 500 + XSTRING_LENGTH (args_or_ret) + 2));
496 strcpy (command_line, argv[0]); 501 strcpy (command_line, XSTRING_DATA (program));
497 strcat (command_line, " "); 502 strcat (command_line, " ");
498 strcat (command_line, XSTRING_DATA (args_or_ret)); 503 strcat (command_line, XSTRING_DATA (args_or_ret));
499 504
500 UNGCPRO; /* args_or_ret */ 505 UNGCPRO; /* args_or_ret */
501 } 506 }
518 } 523 }
519 524
520 err = (CreateProcess (NULL, command_line, NULL, NULL, TRUE, 525 err = (CreateProcess (NULL, command_line, NULL, NULL, TRUE,
521 CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP 526 CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP
522 | CREATE_SUSPENDED, 527 | CREATE_SUSPENDED,
523 NULL, current_dir, &si, &pi) 528 NULL, (char *) XSTRING_DATA (cur_dir), &si, &pi)
524 ? 0 : GetLastError ()); 529 ? 0 : GetLastError ());
525 530
526 if (do_io) 531 if (do_io)
527 { 532 {
528 /* These just have been inherited; we do not need a copy */ 533 /* These just have been inherited; we do not need a copy */
536 if (do_io) 541 if (do_io)
537 { 542 {
538 CloseHandle (hmyshove); 543 CloseHandle (hmyshove);
539 CloseHandle (hmyslurp); 544 CloseHandle (hmyslurp);
540 } 545 }
541 signal_cannot_launch (argv[0], GetLastError ()); 546 signal_cannot_launch (program, GetLastError ());
542 } 547 }
543 548
544 /* The process started successfully */ 549 /* The process started successfully */
545 if (do_io) 550 if (do_io)
546 { 551 {
943 948
944 void 949 void
945 vars_of_process_nt (void) 950 vars_of_process_nt (void)
946 { 951 {
947 } 952 }
948