[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH] lsof reworked
From:       Tito <farmatito () tiscali ! it>
Date:       2012-03-29 12:26:13
Message-ID: 201203291426.14084.farmatito () tiscali ! it
[Download RAW message or body]

On Thursday 29 March 2012 08:06:24 you wrote:
> On Mar 26, 2012 10:37 PM, "Tito" <farmatito@tiscaliit> wrote:
> >
> > On Monday 26 March 2012 20:47:57 souf wrote:
> > > Le 25/03/2012 18:47, Sven Oliver Moll a écrit :
> > > > Hello!
> > > >
> > > > Again another offer for an lsof applet. To make it as small as
> possible,
> > > > now all memory is allocated on the stack. If the complete path to an
> > > > opened file
> > > > is larger that PATH_MAX, it will get truncated. On my x86_64 box,
> > > > size(1) of
> > > > lsof.o reports 573 bytes.
> > > >
> > > > Greetings,
> > > > SvOlli
> > > >
> > > >
> > > > _______________________________________________
> > > > busybox mailing list
> > > > busybox@busybox.net
> > > > http://lists.busybox.net/mailman/listinfo/busybox
> > > Hi,
> > > You can try this :
> > >
> > > int lsof_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
> > > int lsof_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
> > > {
> > >       DIR *d_fd;
> > >       char *tmp, *tmp2;
> > >       char *fdlink;
> > >       struct dirent *entry;
> > >       int scan_mask;
> > >       procps_status_t *proc = NULL;
> > >
> > >       scan_mask = PSSCAN_PID|PSSCAN_EXE;
> > >
> > >       while ((proc = procps_scan(proc, scan_mask))) {
> >                if (getpid() == proc->pid))
> >                        continue;
> > >               tmp = xasprintf("/proc/%d/fd/", proc->pid);
> > >               d_fd = opendir(tmp);
> 
> Does recursive_action help here?
> thanks,

Hi,
I thougth about it but found no obvious way to use it

int FAST_FUNC recursive_action(const char *fileName,
		unsigned flags,
		int FAST_FUNC (*fileAction)(const char *fileName, struct stat *statbuf, void* userData, int depth),
		int FAST_FUNC (*dirAction)(const char *fileName, struct stat *statbuf, void* userData, int depth),
		void* userData,
		unsigned depth)

and passing all that args (most of which useless) looks like overkill to me.
Maybe if the code in the loop is refactored as a function it could be fed
to recursive action, but i doubt this will bring any size optimization.

Ciao,
Tito
> 
> > >               if (d_fd) {
> > >                       while ((entry = readdir(d_fd))) {
> > >                               if (entry->d_type == DT_LNK) {
> > >                                       //tmp2 = xasprintf("%s%s", tmp,
> entry->d_name);
> >                                        //saves a few bytes.
> >                                        tmp2 = concat_path_file(tmp,
> entry->d_name);
> > >
> > >                                       fdlink = xmalloc_readlink(tmp2);
> > >                                       free(tmp2);
> > >                                       printf("%d\t%s\t%s\n", proc->pid,
> proc->exe, fdlink);
> > >                                       free(fdlink);
> > >                               }
> > >                       }
> > >                       closedir(d_fd);
> > >               }
> > >               free(tmp);
> > >       }
> > >
> > >       return EXIT_SUCCESS;
> > > }
> > >
> > >
> >
> > Hi,
> > Looks good, but the output is not same as before because it is listing
> also the files
> > that lsof itself opens. I don't know if this behaviour is acceptable.
> > With this little fix it is as before and bloatometer is still good:
> >
> > scripts/bloat-o-meter busybox_old busybox_unstripped
> > function                                             old     new   delta
> > .rodata                                           139563  139550     -13
> > lsof_main                                            385     174    -211
> >
> ------------------------------------------------------------------------------
> > (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-224)           Total: -224
> bytes
> >
> > Ciao,
> > Tito
> >
> > _______________________________________________
> > busybox mailing list
> > busybox@busybox.net
> > http://lists.busybox.net/mailman/listinfo/busybox
> 
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic