Commit 1ac8dfab authored by Robey Pointer's avatar Robey Pointer
Browse files

add _RUN_LS command to TrilobiteRootHelper and eazel-helper, for eskil to use in testing

parent c4953124
2000-07-10 Robey Pointer <robey@eazel.com>
* components/services/trilobite/helper/eazel-helper.c:
(do_command), (main):
*
components/services/trilobite/libtrilobite/trilobite-root-helper.c:
(trilobite_root_helper_run_program), (trilobite_root_helper_run):
*
components/services/trilobite/libtrilobite/trilobite-root-helper.h:
Add _RUN_LS command to TrilobiteRootHelper and eazel-helper, for
Eskil to use for testing.
2000-07-10 Pavel Cisler <set EMAIL_ADDRESS environment variable>
* libnautilus-extensions/nautilus-icon-container.c:
......
......@@ -79,14 +79,46 @@ find_path_to (const char *filename)
return NULL;
}
static void
do_command (char *command, int args)
{
char *filename;
const char *path;
char buffer[256];
char **pargv;
int i;
pargv = g_new0 (char *, args + 2);
path = find_path_to (command);
if (! path) {
printf ("* Can't find %s. :(\n", command);
exit (1);
}
filename = g_strdup_printf ("%s/%s", path, command);
pargv[0] = command;
for (i = 0; i < args; i++) {
fgets (buffer, 256, stdin);
chomp (buffer);
pargv[i + 1] = g_strdup (buffer);
}
pargv[args + 1] = NULL;
/* we never free any of the args, but it doesn't matter, because
* if the exec succeeds, this all suddenly vanishes. :)
*/
execv (filename, pargv);
printf ("* Can't run %s :(\n", command);
exit (1);
}
int
main (int argc, char **argv)
{
char buffer[256];
const char *path;
char *filename;
char **pargv;
int args, i;
int args;
time_t new_time;
printf ("* OK.\n");
......@@ -107,30 +139,7 @@ main (int argc, char **argv)
/* (followed by N lines of parameters) */
if (g_strncasecmp (buffer, "rpm ", 4) == 0) {
args = atoi (buffer + 4);
pargv = g_new0 (char *, args + 2);
path = find_path_to ("rpm");
if (! path) {
printf ("* Can't find RPM. :(\n");
exit (1);
}
filename = g_strdup_printf ("%s/%s", path, "rpm");
pargv[0] = "rpm";
for (i = 0; i < args; i++) {
fgets (buffer, 256, stdin);
chomp (buffer);
pargv[i + 1] = g_strdup (buffer);
}
pargv[args + 1] = NULL;
/* we never free any of the args, but it doesn't matter, because
* if the exec succeeds, this all suddenly vanishes. :)
*/
execv (filename, pargv);
printf ("* Can't run RPM. :(\n");
exit (1);
do_command ("rpm", args);
}
/* set-time <time_t> */
......@@ -145,6 +154,12 @@ main (int argc, char **argv)
exit (0);
}
/* ls <# of parameters> */
if (g_strncasecmp (buffer, "ls ", 3) == 0) {
args = atoi (buffer + 3);
do_command ("ls", args);
}
printf ("* What?\n");
exit (1);
}
......@@ -383,7 +383,7 @@ failed:
* on failure, returns -1.
*/
static TrilobiteRootHelperStatus
trilobite_root_helper_rpm (TrilobiteRootHelper *root_helper, GList *argv, int *fd)
trilobite_root_helper_run_program (TrilobiteRootHelper *root_helper, const char *program, GList *argv, int *fd)
{
GList *item;
char *p, *out;
......@@ -393,15 +393,15 @@ trilobite_root_helper_rpm (TrilobiteRootHelper *root_helper, GList *argv, int *f
for (item = g_list_first (argv); item; item = g_list_next (item)) {
for (p = (char *)item->data; *p; p++) {
if ((*p < ' ') || (*p == 127)) {
g_warning ("TrilobiteRootHelper: RPM: argument %d contained an "
g_warning ("TrilobiteRootHelper: run %s: argument %d contained an "
"unprintable character: %02X",
g_list_position (argv, item), *p);
program, g_list_position (argv, item), *p);
return TRILOBITE_ROOT_HELPER_BAD_ARGS;
}
}
}
out = g_strdup_printf ("rpm %u\n", g_list_length (argv));
out = g_strdup_printf ("%s %u\n", program, g_list_length (argv));
if (write (root_helper->pipe_stdin, out, strlen (out)) < strlen (out)) {
g_free (out);
goto bail;
......@@ -489,9 +489,11 @@ trilobite_root_helper_run (TrilobiteRootHelper *root_helper, TrilobiteRootHelper
switch (command) {
case TRILOBITE_ROOT_HELPER_RUN_RPM:
return trilobite_root_helper_rpm (root_helper, argv, fd);
return trilobite_root_helper_run_program (root_helper, "rpm", argv, fd);
case TRILOBITE_ROOT_HELPER_RUN_SET_TIME:
return trilobite_root_helper_set_time (root_helper, argv, fd);
case TRILOBITE_ROOT_HELPER_RUN_LS:
return trilobite_root_helper_run_program (root_helper, "ls", argv, fd);
default:
g_warning ("unknown TrilobiteRootHelper command: 0x%02X", command);
return TRILOBITE_ROOT_HELPER_BAD_COMMAND;
......
......@@ -64,7 +64,8 @@ typedef enum {
/* commands that can be sent to the root helper, once it's running */
typedef enum {
TRILOBITE_ROOT_HELPER_RUN_RPM = 1, /* argv: args to rpm -- fd: pipe from rpm */
TRILOBITE_ROOT_HELPER_RUN_SET_TIME /* argv: list of 1 string containing a time_t -- fd: unused */
TRILOBITE_ROOT_HELPER_RUN_SET_TIME, /* argv: list of 1 string containing a time_t -- fd: unused */
TRILOBITE_ROOT_HELPER_RUN_LS = 23 /* argv: args to ls -- fd: pipe from ls [DEMO] */
} TrilobiteRootHelperCommand;
struct _TrilobiteRootHelperClass
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment