This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

bgexec.mod problem

Old posts that have not been replied to for several years.
Locked
c
cinder
Voice
Posts: 10
Joined: Sun Apr 14, 2002 8:00 pm
Location: Gloucester, UK
Contact:

bgexec.mod problem

Post by cinder »

Right, I decided (and a bit of boredom) I was going to update the bgexec.mod, originally meant for eggdrop 1.3.x, to the latest 1.6.x series. After going through every error with a fine-tooth comb, there's all but one error left which I have no idea how to fix. The problem occurs when I use the Tcl command "bgexec tmpfilename commandname" e.g. bgexec ps.tmp ps x, with the bot sending a private message containing: "sh: Avps: command not found". As you can see there is an added "Av" coming from the actual bgexec command. I've managed to whittle down the problem to the source code for the bgexec binary, so here's the code:

Code: Select all

/*
** Background Execution for Eggdrop
** Written by Fosters@G0
**
** (c) Copyright 1998 Eden Developments
**     All Rights Reserved
**
** Usage:
**
**  bgexec filename command [args]
**
** Compile With:
**
**  gcc bgexec.c -o bgexec
*/

#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

extern void bgexec(char *file, char *command);

int main(int ac, char *av[])
{
        char buf[512];
        int loop;

        if(ac < 3)
        {
                fprintf(stderr, "Usage: %s filename command [args]\n", av[0]);
                return(20);
        }

        /* Build string for system() */
        for(loop = 2;loop < ac;loop++)
        {
                strcat(buf, av[loop]);
                strcat(buf, " ");
        }

        bgexec(av[1], buf);

        exit(0);
}

void bgexec(char *file, char *command)
{
        char buf[1024], tmp[256], cbuf[512];
        FILE *ip, *op;

        if(fork() == 0)
        {
                tmpnam(tmp);
                sprintf(buf, "%s >>%s 2>>%s", command, tmp, tmp);
                system(buf);

                if(ip = fopen(tmp, "r"))
                {
                        if(op = fopen(file, "w"))
                        {
                                while(fgets(cbuf, sizeof(cbuf), ip))
                                {
                                        fputs(cbuf, op);
                                }
                                fclose(op);
                        }
                        fclose(ip);
                }

                remove(tmp);
        }

        return;
}
Apart from this, it seems to work fine. The eggdrop module runs the bgexec binary just fine, but for some reason the executable adds "Av" to the command when it runs it. Any help much appreciated :)
- Cinder
l
lordares
Voice
Posts: 15
Joined: Fri Dec 20, 2002 4:47 am

Post by lordares »

ps is hashed (/bin/ps)

Try calling it with path.
c
cinder
Voice
Posts: 10
Joined: Sun Apr 14, 2002 8:00 pm
Location: Gloucester, UK
Contact:

Post by cinder »

Do you mean using "/bin/ps x" as opposed to just "ps x"?
- Cinder
Locked