On Fri, Sep 16, 2005 at 10:39:40PM +0200, Przemek Iskra wrote:
 
> > could do inline lua scripting i believe?
> > 
> > %triggerpostin -p <lua>
> > LUA SCRIPTING LANGUAGE HERE.
> > 
> > i don't know lua, i only know it's possible, as i had similiar situation 
> > with 
> > glibc package :)
there's yes annother problem with lua, it requires recent rpm
i've written something like thah in c, requires some cosmetics but what
do you think ?


-- 
 ____  Sparky{PI] -- Przemyslaw _  ___  _  _  ..Mail,MSN  LANG...Pl..Ca..Es..En
/____) ___  ___  _ _ || Iskra  |  | _ \| |  | : WWW........ppcrcd.pld-linux.org
\____\| -_)'___| ||^'||//\\// <   |  _/| |  | : JID......sparky<at>jabberes.org
(____/||   (_-_|_||  ||\\ ||   |_ |_|  |_| _| :..sparky<at>sparky.homelinux.org
/*
 * adds devmode and devgid to usbfs in fstab
 *
 * sole small parts from joinpasswd by malekith 
 */

#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

void eputs(const char *msg)
{
        write(2, msg, strlen(msg));
}

void fatal(const char *msg)
{
        eputs(msg);
        eputs("\n");
        exit(1);
}

int main()
{
        char *old, *id;
        char *name = "/etc/fstab";
        char *backup_name = "/etc/fstab.bak";
        int i, fd;
        int old_sz;
        char *add = ",devmode=0664,devgid=78";

        struct stat st;

        fd = open(name, O_RDONLY);
        if (fd == -1)
                return 1;
        fstat(fd, &st);
        old = (char *) malloc(st.st_size);
        read(fd, old, st.st_size);
        close(fd);
        old_sz = st.st_size;
        
        fd = open(backup_name, O_WRONLY|O_CREAT|O_TRUNC, 0600);
        if (fd < 0)
                fatal("cannot make backup");
        write(fd, old, old_sz);
        close(fd);
        
        
        // find usbfs
        for (i = 0; i < old_sz; i++) {
                if ( old[i] == 'u' && old[i+1] == 's' && old[i+2] == 'b'
                                && old[i+3] == 'f' && old[i+4] == 's')
                        break;
        }
        // find defau(lts)
        for (;i < old_sz; i++) {
                if ( old[i] == 'd' && old[i+1] == 'e' && old[i+2] == 'f' && 
old[i+3] == 'a' && old[i+4] == 'u' )
                        break;
        }
        // find first space
        for (;i < old_sz; i++) {
                if ( old[i] == ' ' || old[i] == '\t' )
                        break;
        }
        if ( i >= old_sz )
                fatal("can't find correct usbfs entry");
        
        fd = open(name, O_WRONLY|O_CREAT|O_TRUNC);
        write(fd, old, i);
        write(fd, add, strlen(add));
        write(fd, old + i, old_sz - i);
        close(fd);
        
        return 0;
}

_______________________________________________
pld-devel-en mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-devel-en

Reply via email to