comparison src/editors.c @ 737:8a8873e7a552

Make shell command and its option rc file options instead of hardcoded strings. This allows users to modify the shell command that execute "editors". Two new options appear in rc file: - shell.path (default to "/bin/sh") - shell.options (default to "-c") These options can only be changed from the rc file, not at runtime. Tests are made to check that shell.path is not empty and lead to an executable file.
author zas_
date Thu, 22 May 2008 20:22:13 +0000
parents fa8f7d7396cf
children 477f48ba28d8
comparison
equal deleted inserted replaced
736:a7289f9e8d29 737:8a8873e7a552
25 25
26 26
27 #define EDITOR_WINDOW_WIDTH 500 27 #define EDITOR_WINDOW_WIDTH 500
28 #define EDITOR_WINDOW_HEIGHT 300 28 #define EDITOR_WINDOW_HEIGHT 300
29 29
30 #define COMMAND_SHELL "/bin/sh"
31 #define COMMAND_OPT "-c"
32 30
33 31
34 typedef struct _EditorVerboseData EditorVerboseData; 32 typedef struct _EditorVerboseData EditorVerboseData;
35 struct _EditorVerboseData { 33 struct _EditorVerboseData {
36 GenericDialog *gd; 34 GenericDialog *gd;
577 575
578 ok = !(ed->flags & EDITOR_ERROR_MASK); 576 ok = !(ed->flags & EDITOR_ERROR_MASK);
579 577
580 if (ok) 578 if (ok)
581 { 579 {
580 ok = (options->shell.path && *options->shell.path);
581 if (!ok) log_printf("ERROR: empty shell command\n");
582
583 if (ok)
584 {
585 ok = (access(options->shell.path, X_OK) == 0);
586 if (!ok) log_printf("ERROR: cannot execute shell command '%s'\n", options->shell.path);
587 }
588
589 if (!ok) ed->flags |= EDITOR_ERROR_CANT_EXEC;
590 }
591
592 if (ok)
593 {
582 gchar *working_directory; 594 gchar *working_directory;
583 gchar *args[4]; 595 gchar *args[4];
596 guint n = 0;
584 597
585 working_directory = remove_level_from_path(fd->path); 598 working_directory = remove_level_from_path(fd->path);
586 args[0] = COMMAND_SHELL; 599 args[n++] = options->shell.path;
587 args[1] = COMMAND_OPT; 600 if (options->shell.options && *options->shell.options)
588 args[2] = command; 601 args[n++] = options->shell.options;
589 args[3] = NULL; 602 args[n++] = command;
603 args[n] = NULL;
590 604
591 ok = g_spawn_async_with_pipes(working_directory, args, NULL, 605 ok = g_spawn_async_with_pipes(working_directory, args, NULL,
592 G_SPAWN_DO_NOT_REAP_CHILD, /* GSpawnFlags */ 606 G_SPAWN_DO_NOT_REAP_CHILD, /* GSpawnFlags */
593 NULL, NULL, 607 NULL, NULL,
594 &pid, 608 &pid,