diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-11-21 19:14:06 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-11-21 19:21:34 +0200 |
commit | e6927c46013d391242d76b63cdb7b044d9ba8065 (patch) | |
tree | bc78c457286b5aa7b3d6edbbdc2293149b3db7e8 /mh/mh_whatnow.c | |
parent | 597404315ba308889ea2776c56c184d1eb9b02fc (diff) | |
download | mailutils-e6927c46013d391242d76b63cdb7b044d9ba8065.tar.gz mailutils-e6927c46013d391242d76b63cdb7b044d9ba8065.tar.bz2 |
mh: Fix compatibility issues in the draftfolder facility. Implement whatnowproc.
* mh/whatnowenv.c: New source.
* mh/Makefile.am (libmh_a_SOURCES): Add whatnowenv.c
* mh/TODO: Update.
* mh/comp.c: Implement draftfolder, whatnowproc and the -use option.
* mh/forw.c: Likewise.
* mh/repl.c: Likewise.
* mh/compcommon.c (check_draft_disposition): Fix typo.
* mh/mh.h (mh_whatnow_env) <draftfolder>: Remove.
<mbox>: New member.
(mh_whatnowproc): New proto.
(mh_whatnow_env_from_environ)
(mh_whatnow_env_to_environ): New proto.
* mh/mh_global.c (prop_merger): Bugfix: initialize dst.
* mh/mh_init.c (mh_draft_message): Update cur msg.
* mh/mh_whatnow.c (mh_whatnowproc): New function.
* mh/whatnow.c (opt_handler): Do not read Draft-Folder variable.
(main): Initialize data from the environment.
Diffstat (limited to 'mh/mh_whatnow.c')
-rw-r--r-- | mh/mh_whatnow.c | 78 |
1 files changed, 75 insertions, 3 deletions
diff --git a/mh/mh_whatnow.c b/mh/mh_whatnow.c index 9ba2195bc..0d8dd61d7 100644 --- a/mh/mh_whatnow.c +++ b/mh/mh_whatnow.c @@ -17,6 +17,14 @@ #include <mh.h> +#if defined (HAVE_SYSCONF) && defined (_SC_OPEN_MAX) +# define getmaxfd() sysconf (_SC_OPEN_MAX) +#elif defined (HAVE_GETDTABLESIZE) +# define getmaxfd() getdtablesize () +#else +# define getmaxfd() 64 +#endif + typedef int (*handler_fp) (struct mh_whatnow_env *wh, int argc, char **argv, int *status); @@ -342,10 +350,11 @@ _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab) printf ("%s ", wh->prompt); fflush (stdout); - status = mu_stream_getline (in, &line, &size, NULL); + rc = mu_stream_getline (in, &line, &size, NULL); if (rc) { mu_error (_("cannot read input stream: %s"), mu_strerror (rc)); + status = 1; break; } @@ -355,6 +364,7 @@ _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab) { mu_error (_("cannot split line `%s': %s"), line, mu_wordsplit_strerror (&ws)); + status = 1; break; } wsflags |= MU_WRDSF_REUSE; @@ -554,8 +564,8 @@ static struct action_tab whatnow_tab[] = { { NULL } }; -int -mh_whatnow (struct mh_whatnow_env *wh, int initial_edit) +static void +set_default_editor (struct mh_whatnow_env *wh) { if (!wh->editor) { @@ -565,6 +575,12 @@ mh_whatnow (struct mh_whatnow_env *wh, int initial_edit) p : (p = (getenv ("EDITOR"))) ? p : "prompter"); } +} + +int +mh_whatnow (struct mh_whatnow_env *wh, int initial_edit) +{ + set_default_editor (wh); if (initial_edit) mh_spawnp (wh->editor, wh->file); @@ -575,6 +591,62 @@ mh_whatnow (struct mh_whatnow_env *wh, int initial_edit) return _whatnow (wh, whatnow_tab); } +int +mh_whatnowproc (struct mh_whatnow_env *wh, int initial_edit, const char *prog) +{ + int rc; + pid_t pid; + + if (!prog) + return mh_whatnow (wh, initial_edit); + + pid = fork (); + if (pid == -1) + { + mu_diag_funcall (MU_DIAG_ERROR, "fork", NULL, errno); + return 1; + } + + if (pid == 0) + { + struct mu_wordsplit ws; + int i; + + if (mu_wordsplit (prog, &ws, + MU_WRDSF_DEFFLAGS & ~MU_WRDSF_CESCAPES)) + { + mu_error (_("cannot parse command line (%s): %s"), prog, + mu_wordsplit_strerror (&ws)); + _exit (127); + } + + set_default_editor (wh); + mh_whatnow_env_to_environ (wh); + for (i = getmaxfd (); i > 2; i--) + close (i); + execvp (ws.ws_wordv[0], ws.ws_wordv); + mu_diag_funcall (MU_DIAG_ERROR, "execvp", prog, errno); + _exit (127); + } + + /* Master */ + rc = 0; + while (1) + { + int status; + + if (waitpid (pid, &status, 0) == (pid_t)-1) + { + if (errno == EINTR) + continue; + mu_diag_funcall (MU_DIAG_ERROR, "waitpid", prog, errno); + rc = 1; + } + break; + } + return rc; +} + /* Disposition shell */ static struct action_tab disp_tab[] = { { "help", disp_help }, |