1998-02-27 07:54:42 +03:00
|
|
|
/* {{{ Copyright */
|
|
|
|
|
|
|
|
/* Background support.
|
|
|
|
Copyright (C) 1996 The Free Software Foundation
|
|
|
|
|
|
|
|
Written by: 1996 Miguel de Icaza
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2000-08-23 02:50:00 +04:00
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
#include <config.h>
|
2003-10-26 01:54:55 +04:00
|
|
|
|
|
|
|
#ifdef WITH_BACKGROUND
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2001-09-03 09:07:40 +04:00
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
#include "global.h"
|
2001-09-03 09:07:40 +04:00
|
|
|
#include "tty.h"
|
2003-10-25 03:20:30 +04:00
|
|
|
#include "dialog.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "widget.h"
|
|
|
|
#include "wtools.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We currenlty only support one way of comunicating the background
|
|
|
|
* and foreground process by using the socketpair system call
|
|
|
|
*/
|
2003-10-26 01:54:55 +04:00
|
|
|
#include <sys/socket.h>
|
1999-01-14 04:10:32 +03:00
|
|
|
#include "fileopctx.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "key.h" /* For add_select_channel(), delete_select_channel() */
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
#include "eregex.h"
|
1998-11-18 05:31:23 +03:00
|
|
|
#include "file.h"
|
|
|
|
#include "filegui.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* If true, this is a background process */
|
|
|
|
int we_are_background = 0;
|
|
|
|
|
|
|
|
#ifndef HAVE_SOCKETPAIR
|
|
|
|
int socketpair(int, int, int, int fd[2]);
|
2003-10-08 09:16:58 +04:00
|
|
|
#endif /* HAVE_SOCKETPAIR */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* File descriptor for talking to our parent */
|
|
|
|
static int parent_fd;
|
|
|
|
|
|
|
|
#define MAXCALLARGS 4 /* Number of arguments supported */
|
|
|
|
|
|
|
|
struct TaskList *task_list = NULL;
|
1999-01-14 04:10:32 +03:00
|
|
|
|
|
|
|
static int background_attention (int fd, void *closure);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-01-14 04:10:32 +03:00
|
|
|
static void
|
|
|
|
register_task_running (FileOpContext *ctx, pid_t pid, int fd, char *info)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
TaskList *new;
|
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
new = g_new (TaskList, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
new->pid = pid;
|
|
|
|
new->info = info;
|
|
|
|
new->state = Task_Running;
|
|
|
|
new->next = task_list;
|
|
|
|
new->fd = fd;
|
|
|
|
task_list = new;
|
|
|
|
|
1999-01-14 04:10:32 +03:00
|
|
|
add_select_channel (fd, background_attention, ctx);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
unregister_task_running (pid_t pid, int fd)
|
|
|
|
{
|
|
|
|
TaskList *p = task_list;
|
|
|
|
TaskList *prev = 0;
|
|
|
|
|
|
|
|
while (p){
|
|
|
|
if (p->pid == pid){
|
|
|
|
if (prev)
|
|
|
|
prev->next = p->next;
|
|
|
|
else
|
|
|
|
task_list = p->next;
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (p->info);
|
|
|
|
g_free (p);
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
prev = p;
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
delete_select_channel (fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to make the Midnight Commander a background job
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 1 for parent
|
|
|
|
* 0 for child
|
|
|
|
* -1 on failure
|
|
|
|
*/
|
|
|
|
int
|
2003-10-24 22:28:32 +04:00
|
|
|
do_background (struct FileOpContext *ctx, char *info)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2003-10-08 09:16:58 +04:00
|
|
|
int comm[2]; /* control connection stream */
|
1999-03-26 23:37:48 +03:00
|
|
|
pid_t pid;
|
1999-01-14 04:10:32 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (socketpair (AF_UNIX, SOCK_STREAM, 0, comm) == -1)
|
|
|
|
return -1;
|
1999-01-14 04:10:32 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if ((pid = fork ()) == -1)
|
|
|
|
return -1;
|
1999-01-14 04:10:32 +03:00
|
|
|
|
2003-10-08 09:16:58 +04:00
|
|
|
if (pid == 0) {
|
1998-02-27 07:54:42 +03:00
|
|
|
int nullfd;
|
|
|
|
|
2003-10-08 09:16:58 +04:00
|
|
|
parent_fd = comm[1];
|
1998-02-27 07:54:42 +03:00
|
|
|
we_are_background = 1;
|
1999-01-14 04:10:32 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Make stdin/stdout/stderr point somewhere */
|
|
|
|
close (0);
|
|
|
|
close (1);
|
|
|
|
close (2);
|
|
|
|
|
2003-10-08 09:16:58 +04:00
|
|
|
if ((nullfd = open ("/dev/null", O_RDONLY)) != -1) {
|
|
|
|
while (dup2 (nullfd, 0) == -1 && errno == EINTR);
|
|
|
|
while (dup2 (nullfd, 1) == -1 && errno == EINTR);
|
|
|
|
while (dup2 (nullfd, 2) == -1 && errno == EINTR);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} else {
|
2003-10-08 09:16:58 +04:00
|
|
|
close (comm[1]);
|
1999-01-14 04:10:32 +03:00
|
|
|
ctx->pid = pid;
|
2003-10-08 09:16:58 +04:00
|
|
|
register_task_running (ctx, pid, comm[0], info);
|
1998-02-27 07:54:42 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* {{{ Parent handlers */
|
|
|
|
|
|
|
|
/* Parent/child protocol
|
|
|
|
*
|
|
|
|
* the child (the background) process send the following:
|
|
|
|
* void *routine -- routine to be invoked in the parent
|
|
|
|
* int nargc -- number of arguments
|
|
|
|
* int type -- Return argument type.
|
|
|
|
*
|
|
|
|
* If the routine is zero, then it is a way to tell the parent
|
|
|
|
* that the process is dying.
|
|
|
|
*
|
|
|
|
* nargc arguments in the following format:
|
|
|
|
* int size of the coming block
|
|
|
|
* size bytes with the block
|
|
|
|
*
|
|
|
|
* Now, the parent loads all those and then invokes
|
|
|
|
* the routine with pointers to the information passed
|
|
|
|
* (we just support pointers).
|
|
|
|
*
|
|
|
|
* If the return type is integer:
|
|
|
|
*
|
|
|
|
* the parent then writes an int to the child with
|
|
|
|
* the return value from the routine and the values
|
|
|
|
* of any global variable that is modified in the parent
|
|
|
|
* currently: do_append and recursive_result.
|
|
|
|
*
|
|
|
|
* If the return type is a string:
|
|
|
|
*
|
2003-06-02 22:13:42 +04:00
|
|
|
* the parent writes the resulting string length
|
1998-02-27 07:54:42 +03:00
|
|
|
* if the result string was NULL or the empty string,
|
2003-06-02 22:13:42 +04:00
|
|
|
* then the length is zero.
|
|
|
|
* The parent then writes the string length and frees
|
1998-02-27 07:54:42 +03:00
|
|
|
* the result string.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Receive requests from background process and invoke the
|
|
|
|
* specified routine
|
|
|
|
*/
|
|
|
|
|
1999-01-14 04:10:32 +03:00
|
|
|
static int
|
|
|
|
background_attention (int fd, void *closure)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1999-01-14 04:10:32 +03:00
|
|
|
FileOpContext *ctx;
|
|
|
|
int have_ctx;
|
1998-02-27 07:54:42 +03:00
|
|
|
void *routine;
|
|
|
|
int argc, i, result, status;
|
|
|
|
char *data [MAXCALLARGS];
|
|
|
|
int bytes;
|
|
|
|
enum ReturnType type;
|
1999-01-14 04:10:32 +03:00
|
|
|
|
|
|
|
ctx = closure;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
bytes = read (fd, &routine, sizeof (routine));
|
|
|
|
if (bytes < (sizeof (routine))){
|
2000-08-08 20:21:25 +04:00
|
|
|
char *background_process_error = _(" Background process error ");
|
|
|
|
|
2003-10-25 11:19:31 +04:00
|
|
|
unregister_task_running (ctx->pid, fd);
|
|
|
|
waitpid (ctx->pid, &status, 0);
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (errno == ECHILD)
|
1998-03-25 08:16:00 +03:00
|
|
|
message (1, background_process_error, _(" Child died unexpectedly "));
|
1998-02-27 07:54:42 +03:00
|
|
|
else
|
1998-03-25 08:16:00 +03:00
|
|
|
message (1, background_process_error, _(" Unknown error in child "));
|
2003-10-25 11:19:31 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the routine is zero, then the child is telling us that he is dying */
|
2002-02-21 04:49:29 +03:00
|
|
|
if ((long) routine == MSG_CHILD_EXITING){
|
1999-01-14 04:10:32 +03:00
|
|
|
unregister_task_running (ctx->pid, fd);
|
|
|
|
waitpid (ctx->pid, &status, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
1999-01-14 04:10:32 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
read (fd, &argc, sizeof (argc));
|
|
|
|
if (argc > MAXCALLARGS){
|
1998-03-25 08:16:00 +03:00
|
|
|
message (1, _(" Background protocol error "),
|
|
|
|
_(" Background process sent us a request for more arguments \n"
|
|
|
|
" than we can handle. \n"));
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
read (fd, &type, sizeof (type));
|
1999-01-14 04:10:32 +03:00
|
|
|
read (fd, &have_ctx, sizeof (have_ctx));
|
|
|
|
if (have_ctx)
|
|
|
|
read (fd, ctx, sizeof (FileOpContext));
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
for (i = 0; i < argc; i++){
|
|
|
|
int size;
|
1999-01-14 04:10:32 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
read (fd, &size, sizeof (size));
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
data [i] = g_malloc (size+1);
|
1998-02-27 07:54:42 +03:00
|
|
|
read (fd, data [i], size);
|
1999-01-14 04:10:32 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
data [i][size] = 0; /* NULL terminate the blocks (they could be strings) */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle the call */
|
|
|
|
if (type == Return_Integer){
|
2002-09-28 09:10:29 +04:00
|
|
|
if (!have_ctx)
|
1999-01-14 04:10:32 +03:00
|
|
|
switch (argc){
|
|
|
|
case 1:
|
|
|
|
result = (*(int (*)(int, char *))routine)(Background, data [0]);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
result = (*(int (*)(int, char *, char *))routine)
|
|
|
|
(Background, data [0], data [1]);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
result = (*(int (*)(int, char *, char *, char *))routine)
|
|
|
|
(Background, data [0], data [1], data [2]);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
result = (*(int (*)(int, char *, char *, char *, char *))routine)
|
|
|
|
(Background, data [0], data [1], data [2], data [3]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
switch (argc){
|
|
|
|
case 1:
|
|
|
|
result = (*(int (*)(FileOpContext *, int, char *))routine)
|
|
|
|
(ctx, Background, data [0]);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
result = (*(int (*)(FileOpContext *, int, char *, char *))routine)
|
|
|
|
(ctx, Background, data [0], data [1]);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
result = (*(int (*)(FileOpContext *, int, char *, char *, char *))routine)
|
|
|
|
(ctx, Background, data [0], data [1], data [2]);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
result = (*(int (*)(FileOpContext *, int, char *, char *, char *, char *))routine)
|
|
|
|
(ctx, Background, data [0], data [1], data [2], data [3]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Send the result code and the value for shared variables */
|
1999-01-14 04:10:32 +03:00
|
|
|
write (fd, &result, sizeof (int));
|
|
|
|
if (have_ctx)
|
|
|
|
write (fd, ctx, sizeof (FileOpContext));
|
1998-02-27 07:54:42 +03:00
|
|
|
} else if (type == Return_String) {
|
|
|
|
int len;
|
2000-08-08 20:21:25 +04:00
|
|
|
char *resstr = NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* FIXME: string routines should also use the Foreground/Background
|
|
|
|
* parameter. Currently, this is not used here
|
|
|
|
*/
|
|
|
|
switch (argc){
|
|
|
|
case 1:
|
|
|
|
resstr = (*(char * (*)(char *))routine)(data [0]);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
resstr = (*(char * (*)(char *, char *))routine)
|
|
|
|
(data [0], data [1]);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
resstr = (*(char * (*)(char *, char *, char *))routine)
|
|
|
|
(data [0], data [1], data [2]);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
resstr = (*(char * (*)(char *, char *, char *, char *))routine)
|
|
|
|
(data [0], data [1], data [2], data [3]);
|
|
|
|
break;
|
2000-04-10 02:37:50 +04:00
|
|
|
default: g_assert_not_reached();
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
if (resstr){
|
|
|
|
len = strlen (resstr);
|
|
|
|
write (fd, &len, sizeof (len));
|
|
|
|
if (len){
|
|
|
|
write (fd, resstr, len);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (resstr);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
len = 0;
|
|
|
|
write (fd, &len, sizeof (len));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < argc; i++)
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
g_free (data [i]);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
do_refresh ();
|
|
|
|
mc_refresh ();
|
|
|
|
doupdate ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ client RPC routines */
|
1999-01-14 04:10:32 +03:00
|
|
|
|
|
|
|
/* Sends the header for a call to a routine in the parent process. If the file
|
|
|
|
* operation context is not NULL, then it requests that the first parameter of
|
|
|
|
* the call be a file operation context.
|
|
|
|
*/
|
1998-12-03 00:27:27 +03:00
|
|
|
static void
|
1999-01-14 04:10:32 +03:00
|
|
|
parent_call_header (void *routine, int argc, enum ReturnType type, FileOpContext *ctx)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1999-01-14 04:10:32 +03:00
|
|
|
int have_ctx;
|
|
|
|
|
|
|
|
have_ctx = (ctx != NULL);
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
write (parent_fd, &routine, sizeof (routine));
|
|
|
|
write (parent_fd, &argc, sizeof (int));
|
|
|
|
write (parent_fd, &type, sizeof (type));
|
1999-01-14 04:10:32 +03:00
|
|
|
write (parent_fd, &have_ctx, sizeof (have_ctx));
|
|
|
|
|
|
|
|
if (have_ctx)
|
|
|
|
write (parent_fd, ctx, sizeof (FileOpContext));
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-10-24 22:28:32 +04:00
|
|
|
parent_call (void *routine, struct FileOpContext *ctx, int argc, ...)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int i;
|
1999-01-14 04:10:32 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
va_start (ap, argc);
|
1999-01-14 04:10:32 +03:00
|
|
|
parent_call_header (routine, argc, Return_Integer, ctx);
|
|
|
|
for (i = 0; i < argc; i++) {
|
1998-02-27 07:54:42 +03:00
|
|
|
int len;
|
|
|
|
void *value;
|
|
|
|
|
|
|
|
len = va_arg (ap, int);
|
|
|
|
value = va_arg (ap, void *);
|
|
|
|
write (parent_fd, &len, sizeof (int));
|
|
|
|
write (parent_fd, value, len);
|
|
|
|
}
|
1999-01-14 04:10:32 +03:00
|
|
|
read (parent_fd, &i, sizeof (int));
|
|
|
|
if (ctx)
|
|
|
|
read (parent_fd, ctx, sizeof (FileOpContext));
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2003-10-26 01:54:55 +04:00
|
|
|
char *
|
1998-02-27 07:54:42 +03:00
|
|
|
parent_call_string (void *routine, int argc, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char *str;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
va_start (ap, argc);
|
1999-01-14 04:10:32 +03:00
|
|
|
parent_call_header (routine, argc, Return_String, NULL);
|
1998-02-27 07:54:42 +03:00
|
|
|
for (i = 0; i < argc; i++){
|
|
|
|
int len;
|
|
|
|
void *value;
|
|
|
|
|
|
|
|
len = va_arg (ap, int);
|
|
|
|
value = va_arg (ap, void *);
|
|
|
|
write (parent_fd, &len, sizeof (int));
|
|
|
|
write (parent_fd, value, len);
|
|
|
|
}
|
1999-01-14 04:10:32 +03:00
|
|
|
read (parent_fd, &i, sizeof (int));
|
1998-02-27 07:54:42 +03:00
|
|
|
if (!i)
|
|
|
|
return NULL;
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
str = g_malloc (i + 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
read (parent_fd, str, i);
|
|
|
|
str [i] = 0;
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tell_parent (int msg)
|
|
|
|
{
|
|
|
|
write (parent_fd, &msg, sizeof (int));
|
|
|
|
}
|
|
|
|
|
2003-10-25 23:54:24 +04:00
|
|
|
#endif /* WITH_BACKGROUND */
|