[Toybox] IFCONFIG doubt

2016-06-28 Thread Ashwini Sharma
Hello enh,

Android's original ifconfig was only showing the ip address for interface
and flags.

Otherwise ifconfig on other platforms gives out lot of other details. Does
it do so on Android?

I  interested in how to get the MAC address at the ndk level. As earlier i
saw that SIOCGIFHWADDR is not supported.

Is there a way to get the mac address.

Thanks,
Ashwini
On 27 Jun 2016 20:58, "enh"  wrote:

---
 toys/android/start.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] sed {N;N;} cmd test failure

2014-12-02 Thread Ashwini Sharma
Hi Rob,

While testing thru busybox sed tests, it failed at this test case.

# first three lines are deleted; 4th line is matched and printed by 2,3
and by 4 ranges
testing sed with N skipping lines past ranges on next cmds \
  sed -n '1{N;N;d};1p;2,3p;3p;4p' \


  4\n4\n  1\n2\n3\n4\n

My observation is with single N, this is working fine, but with multiple N
it doesn't give the same results.

Is the toybox behavior right or busybox/GNU's?

Thanks,
Ashwini
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] What does the du.c patch do?

2014-12-01 Thread Ashwini Sharma
Hi Rob,

My patch was


+// is recursive tree
+static int is_recursive_loop(struct dirtree *node)
+{
+  struct dirtree *tmp = node;
+
+  while ((tmp = tmp-parent)) {
+if ((tmp-st.st_ino == node-st.st_ino) 
+(tmp-st.st_dev == node-st.st_dev))
+  return 1;
+  }
+  return 0;
+}
+
 // dirtree callback, comput/display size of node
 static int do_du(struct dirtree *node)
 {
@@ -114,6 +127,8 @@
   if (!(toys.optflags  FLAG_l)  !node-again)
 if (seen_inode(TT.inodes, node-st)) return 0;

+  if (is_recursive_loop(node)) goto ADD;
+
   // Collect child info before printing directory size
   if (S_ISDIR(node-st.st_mode)) {
 if (!node-again) {
@@ -121,7 +136,7 @@
   return DIRTREE_COMEAGAIN | (DIRTREE_SYMFOLLOW*!!(toys.optflags 
FLAG_L));
 } else TT.depth--;
   }
-
+ADD:
   node-extra += node-st.st_blocks;
   if (node-parent) node-parent-extra += node-extra;

and not the one you mentioned.

This patch is handling the case, of self point symlinks.

$ mkdir sub
$ cd sub
$ ln -s ../sub lnk
$ cd ../
$ du -L sub

without my patch it will keep looping. This patch stops from this looping.

Thanks,
Ashwini

On Sun, Nov 30, 2014 at 6:03 AM, Rob Landley r...@landley.net wrote:

 Going through Ashwini's patch stack from last month. (Sorry for the delay,
 but I think I applied all the trivial ones in earlier passes.)

 What does the du.c patch do?

   $ mkdir sub
   $ ln -s . sub/here
   $ ln -s loop sub/loop
   $ ./toybox du sub
   4 sub

 There's also a hardlink filter (disabled via -l)...

 I'm tempted to add the following to lib/dirtree.c

 +// Have we already seen this node?
 +int dirtree_seen(struct dirtree *try, struct stat *st)
 +{
 +  while (try) {
 +if (try-st.st_ino==st-st_ino  try-st.st_dev==st-st_dev) return
 1;
 +try = try-parent;
 +  }
 +
 +  return 0;
 +}
 +

 But the existing user I can think of that's already doing this is in cp.c:

 // Detect recursive copies via repeated top node (cp -R .. .) or
 // identical source/target (fun with hardlinks).
 if ((TT.top.st_dev == try-st.st_dev  TT.top.st_ino == try-st.st_ino
   (catch = TT.destname))
 || (!fstatat(cfd, catch, cst, 0)  cst.st_dev == try-st.st_dev
   cst.st_ino == try-st.st_ino))
 {
   error_msg('%s' is '%s', catch, err = dirtree_path(try, 0));
   free(err);

   return 0;
 }

 Which seems to work?

 Anyway, could you give me a testcase where the du.c patch you submitted
 makes a
 difference?

 Rob

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [PATCH] New toys TR CRONTAB

2014-10-28 Thread Ashwini Sharma
Hi Rob, list



 Attached are new toys TR and CRONTAB.  Any inputs welcome.



 * tr.c*:  It translate, squezze and delete characters.

Supported classes are alpha, alnum, digit, lower, upper

space, blank, puct, cntrl and xdigit.

  *crontab.c*: Companion of crond. It maintains crontab files.



Regards

Ashwini


tr.c.patch
Description: Binary data


crontab.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] bunzip2 - bzcat as bunzip2

2014-10-16 Thread Ashwini Sharma
I plan to do this as an alias of bzcat, with changes required to
create/overwrite/error on writing to file.
Restoring the original file modes. As this is all that I need for the
moment.

regards,
Ashwini

On Thu, Oct 16, 2014 at 4:38 PM, Rob Landley r...@landley.net wrote:

 On 10/15/14 23:53, Ashwini Sharma wrote:
  Hi Rob, List,
 
  I was looking into 'bzcat' code.
  Can't this be used as bunzip2 or as __base__ to bunzip2, as I am
  interested in
  bunzip2 utility.
 
  At a glance it looked to me that it can be used, please share your
 opinion.

 Yes, it can.

 The only reason I haven't done so yet is busybox tar requires the gunzip
 and bunzip it uses to be built-in, so I can't drop the decompression
 utilities from the busybox config in aboriginal linux (my main test
 harness for toybox) until I switch over to using toybox tar.

 Also, I need to implement the relevant compression-side utilities. I
 have about 1/3 of a gzip compressor implemented here (got distracted
 while researching when to do dictionary resets; nobody quite seems to
 agree on that one), and I did half a bzip2 implementation ages ago (the
 fiddly bit is that the string sorting algorithms in the original are
 kind of magic and unexplained; it seems to get constant time out of a
 somewhat arbitrary set of sorting algorithms which give up and fall back
 to the next one after doing a certain amount of work, but I don't
 understand how/why it's set up that way. I need to stare at it some more.)

 And then there's the whole cleanup xz decompression, implement xz
 compression part to look forward to...

 If you want to do a proper bunzip wrapper, be my guest. I did bzcat to
 prove the engine works and left the rest on the todo list. I have a note
 that loopfiles() needs a replace mode so bunzip and sed -i and maybe
 patch can share code, but I can clean that up later. (And I need test
 suite code to check that bunzip blah.bz2 fails when blah already
 exists...)

  Thanks,
  Ashwini

 Rob

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [Patches] - Some more static analysis fixes

2014-10-12 Thread Ashwini Sharma
Hi Rob,

--- cp.c.patch:

Why this change?

-if (CFG_CP_MV  toys.which-name[0] == 'm') rc = rename(src,
TT.destname);
+if (CFG_CP_MV  toys.which-name[0] == 'm'  (toys.optflags 
FLAG_f))
+  rc = rename(src, TT.destname);

$ strace mv umount umount.old 21 | grep rename
rename(umount, umount.old)  = 0

in case of mv __rename()__ is tried at first. The issue handled is in case
when user
gives option __-i__

thats why this extra check for mv.

regards,
Ashwini

On Fri, Oct 10, 2014 at 8:10 PM, Rob Landley r...@landley.net wrote:

 On 10/10/14 00:20, David Seikel wrote:
  On Thu, 09 Oct 2014 23:43:25 -0500 Rob Landley r...@landley.net wrote:
 
  --- getty.c.patch:
 
  I actually have a pending cleanup to getty I haven't checked in for
  ages because I haven't got a serial port setup lying around to test.
  It redoes the speed calculatons to look like:
 
  Er, serial port console on a VM isn't good enough to test with?

 Emulated serial console doesn't care about bit rate, because it's not
 breaking things down into bits. (It works at the byte level.)

 And yes, this sometimes has side effects:

 http://lkml.iu.edu/hypermail/linux/kernel/0802.0/2142.html

 Rob
 ___
 Toybox mailing list
 Toybox@lists.landley.net
 http://lists.landley.net/listinfo.cgi/toybox-landley.net

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [Patches] - Issue fixes

2014-10-07 Thread Ashwini Sharma
Hi Rob, List,

While verifying toybox on one of our products, came across few issues.
Attached are the patches to those.

1. cp.c : For __mv__ with __-f__ and __-i__ user was prompted.

2. date.c: added support for additional date format parsing, a SIGSEGV for
setdate,   output in __-u__.

3. df.c: Output format and strings as specified in Posix and a correction
when a
device name is given. e.g. df /dev/sda1

4. du.c: stop the traversal on a self pointing link.

5. expr.c: Added '==' sign into list of operations. Also added support for
regex pattern match.

6. ifconfig.c: stop parsing if interface name is encountered first.

7. killall.c: output formatting corrected. It was right justifying 4000
places.

8. kill.c: printing signal numbers along with names while listing.
 Also listing the signals on command line, if name is given
list the number
 and vice-versa.
   e.g$ ./toybox kill -l ABRT 2 ILL
6
INT
4
9 lib.c:  A static analysis issue fix for retrun value check.
   supporting change for kill.c.
   A Change in string_to_mode, while parsing sticky/suid bit for u, g, o.
   e.g chmod u+s,o+s,g+s file
   And a correction in  human_readable().

Few more will follow..

rgds,
Ashwini


cp.c.patch
Description: Binary data


date.c.patch
Description: Binary data


df.c.patch
Description: Binary data


du.c.patch
Description: Binary data


expr.c.patch
Description: Binary data


ifconfig.c.patch
Description: Binary data


kill.c.patch
Description: Binary data


killall.c.patch
Description: Binary data


lib.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [Patches] - Some more static analysis fixes

2014-10-06 Thread Ashwini Sharma
Hi Rob, List,

Attached are few more static analysis fixes. This includes issues like
resource leaks, logical dead codes etc...

chgrp.c: Issue is in case when CFG_FREE and verbose mode enabled. Garbage
output was there.

comm.c: loop error

id.c: single build issue for OLD_TOYs, same issue is there with some other,
e.g. __mv__

mountpoint.c : logically dead code, as __temp __ is initialized with 1

Do have a look, your inputs are welcome.

regards,
Ashwini


chgrp.c.patch
Description: Binary data


comm.c.patch
Description: Binary data


fdisk.c.patch
Description: Binary data


getty.c.patch
Description: Binary data


id.c.patch
Description: Binary data


insmod.c.patch
Description: Binary data


losetup.c.patch
Description: Binary data


modprobe.c.patch
Description: Binary data


netcat.c.patch
Description: Binary data


nohup.c.patch
Description: Binary data


tftpd.c.patch
Description: Binary data


xwrap.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [Patch] - touch, kill and umount fixes

2014-09-18 Thread Ashwini Sharma
Hi Rob,

Attached are the patches. This has fixes for

touch:
1.  while setting access or modify times of a file, this was causing a hang
due to non-increment of ss.

2.  handling the time format for __-d__ option as per the spec (
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html).

kill:

3. prints signal number along with signal names while listing and
vice-versa if an argument is given to the __-l__ option. This has changes
in lib.c + kill.c

umount:

4. __-n__, as per the LSB spec, it will skip updating /etc/mtab. In toybox
case, you
   skipped reading mount list. This doesn't resolve if the device is given
to umount.

   // We use the list both for -a, and to umount /dev/name or do losetup -d
-  if ( !access(pm, R_OK))
+  if (!(toys.optflags  FLAG_n)  !access(pm, R_OK))
 mlrev = dlist_terminate(mlsave = xgetmountlist(pm));


e.g. umount -n /dev/sda1,

this fails, as this doesn't figure out the mountpoint to be umount'ed.

thanks,
Ashwini


touch.c.patch
Description: Binary data


kill.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [New Toy] - ip

2014-09-18 Thread Ashwini Sharma
Hi Rob,

Earlier had sent a version of ip, which had many TODO items.
Attached is the updated version, having complete support for
ip _link_, _addr_, _rule_, _route_ and _tunnel_ options.

Please see to it, if this can be added to the hg.

regards,
Ashwini


ip.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [Patch] - touch, kill and umount fixes

2014-09-18 Thread Ashwini Sharma
Attached is the updated patch.

On Fri, Sep 19, 2014 at 12:33 AM, Rob Landley r...@landley.net wrote:

 On 09/18/14 05:38, Ashwini Sharma wrote:
  Hi Rob,

 Hi. Your last round of fixes (which I've applied a little over half of)
 touched some of the files needing cleanup outside of the pending
 directory. (I.E. command contributions that predated pending.) I
 updated the toys/pedning/README file listing them (so it's not just my
 private list), and have been looking at a few. (Yesterday it was touch
 and cut I think.)

  Attached are the patches. This has fixes for
 
  touch:
  1.  while setting access or modify times of a file, this was causing a
  hang due to non-increment of ss.

 I actually have more fixes to touch pending: the logic is wrong for file
 create. I think if you combine touch -a -d when creating a file, it
 should set the access time to what you specified with -d but leave the
 modification time at the current (creation) time? I need to read the
 spec and test what the ubuntu version does.

 Query: this patch replaces the stanza I just took _out_ that tries to
 work around a libc bug. Which libc is having the problem?

 Does the for loop not work?

2 use cases here.

1. update access or modify time one at a time.
__fetch()__ was checking for __TT.file__ instead of input parameter
__file__. Failure
here as TT.file = NULL, causes a jump to open statement in loop. Success
here results in endless loop.

2. file to be touched is existing and owned by other user.
 In this open(O_CREAT) did succeed, but utimes() fail returning EPERM.
Again the endless loop.


  2.  handling the time format for __-d__ option as per the spec
  (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html).

 The majority of this patch affects the -t case, not the -d case?


for -d case, it is taking into account the UTC time zone.


 -  strcpy(toybuf, %Y%m%d%H%M);
date = TT.time;
 -  for (i=0;i3;i++) {
 -s = strptime(date, toybuf+(i2), tm);
 -if (s) break;
 -toybuf[1]='y';
 -  }
 +  i = ((s = strchr(date, '.'))) ? s-date : strlen(date);
 +  if (i == 8) strcpy(toybuf, %m%d%H%M);
 +  else if (i == 10) strcpy(toybuf, %y%m%d%H%M);
 +  else if (i == 12) strcpy(toybuf, %Y%m%d%H%M);
 +  else perror_exit(bad '%s', date);
 +
if (s  *s=='.') {
 -int count = sscanf(s, .%2d%u%n, (tm.tm_sec), i, len);
 -
 -if (count==2) tv-tv_usec = i;
 -s += len;
 +if ((sscanf(s+1, %2u%n, (tm.tm_sec), i) != 1) || *(s+i+1))
 +  error_exit(bad '%s', date);
 +s += (i+1);

 Where did the call to strptime go? This new code seems to set up toybuf
 (using three separate strings instead of three cases on one string), and
 then... not call strptime? I'm confused...

 my bad, attached is the updated patch. I preferred if..else over loop
calling strptime() 3 times. Though the loop is kept intact now.

__for__ loop works fine, but as per spec it should accept
[[CC]YY]mmddMMHH[.SS], all the fields in pairs of two digits.
strptime() doesn't care for this two digit format, leading '0' may or may
not be there.
Finally [.SS] can be in the range [00, 60] and no further fractions.
sscanf(.%2d%u%n) would fail when input is like 1910200240.24 or
1910200240. (Segfault)
as len is not updated properly and s is advanced by the same.


(Yesterday I was looking at whether or not I could combine the date
 parsing logic there with the stuff in date. The answer is currently
 no, but I want to give it another look...)

 Have to answer the rest later, errand...

 Rob



touch.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [Issue] - mounting a device again

2014-09-16 Thread Ashwini Sharma
Hi Rob,

What I meant was trying to mount an already mounted device on a different
mountpoint.

In my use case, this is snapshot of my /proc/filesystems
nodev inotifyfs
nodev devpts
ext3
ext4
nodev ramfs

and following is the results when I mount /dev/loop0 (an ext4 formatted
image) on /mnt/one

gvfs-fuse-daemon on /home/ashwini/.gvfs type fuse.gvfs-fuse-daemon
(rw,nosuid,nodev,relatime,user_id=500,group_id=500)
/dev/loop0 on /mnt/one type ext4 (rw,relatime,barrier=1,data=ordered)

Now try to mount the same /dev/loop0 on /mnt/two
result is
# sudo ./toybox mount /dev/loop0 /mnt/two
mount: '/dev/loop0'-'/mnt/two': Device or resource busy

At this point of time, mount tried with ext3 first, got EBUSY and exited.
Whereas it should loop through other filesystems for autodetection
and try to mount with ext4 (in this case) as is present in
/proc/filesystems.

regards,
Ashwini

On Tue, Sep 16, 2014 at 6:20 PM, Rob Landley r...@landley.net wrote:

 On 09/15/14 23:14, Ashwini Sharma wrote:
  Hi Rob,
 
  Encountered an issue while mounting a device which is already mounted.
 
  when __-t__ is not specified, the mount tries with the first device
  filesystem it finds from /proc/filesystems.

 To autodetect filesystem type, yes.

  __mount()__ return an EBUSY, at this point no other file system is tried
  for mounting instead mount breaks out of the loop with a Device Busy
 error.

 With the ubuntu host mount:

 mount -t proc /proc /proc
 mount -t proc /proc /proc
 mount: proc already mounted

 If the syscall is returning -EBUSY, what is the userspace tool supposed
 to do about that?

  Shouldn't it try for another filesystem mount in this case, as this is
  also the behavior from GNU mount.

 A) Does it result in a successful mount?

 B) I thought the gnu version was doing a variant of blkid to try to
 identify the filesystem type?

  Use case.
 
  Lets have a disk image, formatted ext4 setup at /dev/loop0.
 
  mount /dev/loop0 /tmp
 
  this mounts loop0 on /tmp with __ext4__
 
  try again, mount tries with first fs in /proc/filesystems, e.g. ext3. An
  error is reported and mount breaks out without trying further.
 
  What should be the right thing.

 $ truncate -s 1G walrus.img
 $ mkfs.ext4 walrus.img
 $ sudo mount walrus.img /mnt
 $ sudo mount walrus.img /mnt
 mount: according to mtab /home/landley/toybox/toybox/walrus.img is
 already mounted on /mnt as loop

 I'm open to suggestions but I don't understand the desired behavior?

 Now note that if I mount it over /tmp instead of /mnt it works, even
 though /tmp is already a mount point. The kernel objects to placing the
 _same_ mount over itself, but stacking mounts is fine.

 I am, however, kind of amused that gnu mount has copied the loop
 autodetect stuff I added to busybox in 2006. (Which, at the time, was
 the only mount that did that.

 Ah, I see:

 ./mount walrus.img /mnt
 ./mount walrus.img /mnt
 /dev/loop0 /mnt ext4 rw,relatime,user_xattr,barrier=1,data=ordered 0 0
 /dev/loop1 /mnt ext4 rw,relatime,user_xattr,barrier=1,data=ordered 0 0

 You're objecting that I'm _not_ autodetecting the existing mount in the
 loopback mount case, because loop0 and loop1 are different devices.
 However the _kernel_ catches it if I go:

 $ sudo ./mount /dev/loop1 /mnt
 mount: '/dev/loop1'-'/mnt': Device or resource busy

 Indeed. I'm sure there are corner cases in this mount command where it's
 not doing the right thing yet. I'll try to work out a way to check that.
 (The problem is losetup -j is using a field that only stores 64 bytes
 of information... Oh wait, I can match on device and inode. I think
 losetup -j is already doing this right...)

 The _tricky_ bit is that an existing loopback association could have an
 offset or size limitation (or encryption, or different -c capacity), so
 it might not _be_ quite the same as a fresh losetup. Then again for
 autodetect mode, I'm not sure that's our problem?

 (Did I understand your objection correctly?)

  regards,
  Ashwini

 Rob

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [Issue] - mounting a device again

2014-09-15 Thread Ashwini Sharma
Hi Rob,

Encountered an issue while mounting a device which is already mounted.

when __-t__ is not specified, the mount tries with the first device
filesystem
it finds from /proc/filesystems.

__mount()__ return an EBUSY, at this point no other file system is tried
for mounting
instead mount breaks out of the loop with a Device Busy error.

Shouldn't it try for another filesystem mount in this case, as this is also
the behavior
from GNU mount.

Use case.

Lets have a disk image, formatted ext4 setup at /dev/loop0.

mount /dev/loop0 /tmp

this mounts loop0 on /tmp with __ext4__

try again, mount tries with first fs in /proc/filesystems, e.g. ext3. An
error is
reported and mount breaks out without trying further.

What should be the right thing.

regards,
Ashwini
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [Patches] - Static analysis fixes

2014-09-05 Thread Ashwini Sharma
Hi Rob,

Attached are few fixes for issues reported in static analysis. Do have a
look and
share your inputs.

regards,
Ashwini


bootchartd.c.patch
Description: Binary data


cpio.c.patch
Description: Binary data


cut.c.patch
Description: Binary data


find.c.patch
Description: Binary data


fsck.c.patch
Description: Binary data


init.c.patch
Description: Binary data


nbd_client.c.patch
Description: Binary data


netstat.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [Issue] - single build

2014-09-04 Thread Ashwini Sharma
Hi Rob,

When doing a single build toy_list is populated with the command to be built
and all it __aliases__ in the chronological ascending order.

This is creating issue, use case is __grep__

this enables __egrep__, __fgrep__ and __grep__. The default selected
command is egrep, as it is first in the list.

While testing 'grep -e' it shouts.

May be doing toy_find() is required while doing singleinit().

regards,
Ashwini
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [Issues] - grep

2014-08-28 Thread Ashwini Sharma
Hi List,

While verifying the command grep and analysing/comparing the behavior
with GNU and busybox. I notices following

1. __-H__ and __-h__ options, we prefer -H over -h, GNU and Busybox prefer
the last one mentioned on command line.

2. links are not followed for doing grep, i.e. grep search linkToFile or
Dir -r
no results are shown. Shouldn't the link be followed.

3. searching in binary files, toybox gives very minimal or no results, e.g.
grep toy toybox_unstripped, reports 4-5 lines whereas GNU/BBox fills
the scroll   buffer.

The spec http://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html

doesn't mention anything for these behavior  or options.

Do have a look and give your inputs on
What is the right one to be followed?

Thanks,
Ashwini
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [Patch] - args.c failure for group [-abc]

2014-08-12 Thread Ashwini Sharma
Hi Rob,

For the group __ [-abc] __ handling, while clearing the flags for the
options
to be disabled, it cleared args, for any of the set options until then.

Additional check is added to determine the options arg to be cleared.

 for (clr=gof-opts, i=1; clr; clr = clr-next, i=1)
-  if (clr-arg  (i  toys.optflags)) *clr-arg = 0;
+  if (clr-arg  (i  toys.optflags) 
+  (clr-dex[1]  opt-dex[0])) *clr-arg = 0;
 toys.optflags = ~opt-dex[0];

Patch is attached for the same.

regards,
Ashwini


args.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [Patches] - Static analysis fixes

2014-08-11 Thread Ashwini Sharma
Hi Rob, List,

Attached are the patches to commands for issues reported from static
analysis tool.

portability.h.patch - it is for O_CLOEXEC, as compiler complained of it.
Makefile.patch - for cleaning generated/*.o files and libopts.dat file


regards,
Ashwini


arp.c.patch
Description: Binary data


fsck.c.patch
Description: Binary data


ftpget.c.patch
Description: Binary data


ifconfig.c.patch
Description: Binary data


Makefile.patch
Description: Binary data


modprobe.c.patch
Description: Binary data


portability.h.patch
Description: Binary data


tar.c.patch
Description: Binary data


uniq.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [Patches] - Static analysis fixes

2014-08-11 Thread Ashwini Sharma
compiler I used is gcc version 4.4.3 on ubuntu 64-bit with
linux kernel 2.6.32. This complained of undeclared O_CLOEXEC.

Ashwini



On Mon, Aug 11, 2014 at 6:47 PM, Rob Landley r...@landley.net wrote:

 On 08/11/2014 04:27 AM, Ashwini Sharma wrote:
  Hi Rob, List,
 
  Attached are the patches to commands for issues reported from static
  analysis tool.

 Still reading through that part.

  portability.h.patch - it is for O_CLOEXEC, as compiler complained of it.

 Which compiler? It was added to the kernel in linux commit f23513e8 back
 in 2007, leading up to the 2.6.22 kernel, so it's been in the linux for
 7 years now.

 *shrug* I can add the code to portability.h, I'm just curious what
 compiler still in use wouldn't have it. (Says the guy still maintaining
 a gcc 4.2.1 fork with binutils 2.17...)

  Makefile.patch - for cleaning generated/*.o files and libopts.dat file

 I actually made this change locally yesterday, but haven't pushed it yet.

 Thanks, reading through the rest of this now...

 Rob

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [Patches] - Static analysis fixes

2014-08-11 Thread Ashwini Sharma
Hi Andre,

I used _prevent_ by Coverity and also a proprietary tool.

regards,
Ashwini


On Tue, Aug 12, 2014 at 1:07 AM, Andre Renaud an...@bluewatersys.com
wrote:

 Hi Ashwini,
  Attached are the patches to commands for issues reported from static
  analysis tool.

 Just out of curiosity, which static analysis tool did you use to find
 these?

 I've done some investigation into these recently, and found them to be
 quite nice to integrate into the build system, although the open
 source ones (cppcheck, sparse and frama-c) don't seem to be nearly as
 comprehensive as the commercial ones. I think it's something that
 every C project should run at least periodically, if not on every
 build.

 Regards,
 Andre

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [New Toy] - Blockdev

2014-08-11 Thread Ashwini Sharma
Hi Rob, List,

A patch for a toy _BLOCKDEV_ to get/set block device properties is attached
here with.

Your inputs are welcome.


regards,
Ashwini


blockdev.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [New toys] - diff, userdel

2014-08-04 Thread Ashwini Sharma
Hi Rob,

Wasn't aware of your comments on diff,
An algorithm by Hunt  McIlory ( http://cm.bell-labs.com/cm/cs/cstr/41.pdf)
is used for this diff implementation.

Will have a look at Patience Diff and see if current implementation can be
patched.

regards,
Ashwini


On Mon, Aug 4, 2014 at 7:44 PM, Rob Landley r...@landley.net wrote:

 On 08/03/14 15:39, Bobby Bingham wrote:
  On Sat, Aug 02, 2014 at 11:39:21AM -0500, Rob Landley wrote:
  On 08/01/14 06:08, Ashwini Sharma wrote:
  Hi Rob, List,
 
  Attached are the new toys unified DIFF and USERDEL.
 
  Your inputs are welcome.
 
  Query, is this diff using Brahm Cohen's patience algorithm?
 
  Backstory: the guy who wrote bittorrent invented his own diff algorithm
 
  Patience diff is not a diff algorithm.  It's pre-processing for feeding
  the input into another diff algorithm.  Step #3 in the algorithm
  description amounts to feed the remaining lines into a real diff
  algorithm.

 Cool, that makes a bit more sense now.

  I have actually implemented patience diff and several underlying diff
  algorithms for $DAYJOB.  I've been tempted to contribute a diff
  implementation here, but I can't just take that code and submit it ...
 
  I will try though to take a look at the patch at some point in the next
  couple days and see if I have any comments about the diff algorithm
  used.

 I look forward to this. Thanks.

 Rob
 ___
 Toybox mailing list
 Toybox@lists.landley.net
 http://lists.landley.net/listinfo.cgi/toybox-landley.net

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [New toys] - diff, userdel

2014-08-01 Thread Ashwini Sharma
Hi Rob, List,

Attached are the new toys unified DIFF and USERDEL.

Your inputs are welcome.

regards,
Ashwini


diff.c.patch
Description: Binary data


userdel.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [Patches] - fsck, fdisk and ftpget

2014-07-09 Thread Ashwini Sharma
Hi Rob,

Attached are the patches for

fdisk : partitions  60, are deleted, offset entry for extended partitions
was wrong.
fsck: memory leak/segfault resolved.
ftpget : warning for unused variable 'ptr' removed.

Thanks,
Ashwini


fdisk.c.patch
Description: Binary data


fsck.c.patch
Description: Binary data


ftpget.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [CLEANUP] groupdel

2014-07-07 Thread Ashwini Sharma
On Mon, Jul 7, 2014 at 10:25 AM, Rob Landley r...@landley.net wrote:

 Haven't checked this in yet because it needs more testing, but patch is
 attached:

 GROUP is always toys.optargs[toys.optc-1] so let's move the getgrnam()
 before the two if/else cases so it's not duplicated. (Speaking of which,
 in the original code getgrnam() with the corresponding error message
 gets called twice in a row?)

 First question: are we ok hardwiring in the colon-separated /etc/groups
 file? (Because I thought android had some magic database instead?) I'm
 going to assume that's ok for now...

 I got confused by the man page for getgrnam pointing me to man 5 group,
 the second of which said that gr_mem is a comma separated list. But in
 the first it's a char *array[] which I _assume_ has a null terminator at
 the end, but it never SAYS so. (That's what the man page in Ubuntu 12.04


The second one explain about the format of the /etc/group file, where
gr_mem si a comma
separated list. The first one is the structure representation of the same,
as a *array[].
The null termination is not mentioned but is observed to be there.

says, anyway. Maybe it's stale?) That tangent got me to write a
 comma_find() function that should at least be useful elsewhere.


 The found == -1 part is using xprintf() instead of error_exit() because
 it wants to exit with status 0? And to print to stdout instead of
 stderr? And while we're at it, removing a user from a group that has no
 users in it doesn't produce this message either?

 Why do we call getpwnam() at all? Just to confirm it's an actual user?
 (Not being there is an error, can it be there and _not_ be a valid user?)


when  a user is added to the group, it is validated for its existence,  On
deletion
of a user from system it is removed from all the groups it belongs to, may
be due
to this __it__ not being there in case of removal from group is treated as
error.


 Ooh, _subtle_: due to xexec() not necessarily doing an actual exec()
 each time, we should call setpwent() before our first getpwent() because
 it's yet more process state that doesn't necessarily get reset between
 calls. (Possibly endpwent() should be part of the toy_init() stuff?) Or
 maybe endpwent() is better?

 ___
 Toybox mailing list
 Toybox@lists.landley.net
 http://lists.landley.net/listinfo.cgi/toybox-landley.net


___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [Patch] - last, typo issue

2014-05-23 Thread Ashwini Sharma
Hi Rob, List,

Due to a type in last.c the build is broken.
The callback function to __llist_traverse()__ is typed wrong.

diff -Naur b/toybox-ee18ddbb783b/toys/pending/last.c
a/toybox-ee18ddbb783b/toys/pending/last.c
--- b/toybox-ee18ddbb783b/toys/pending/last.c 2014-05-23 08:03:10.0
+0530
+++ a/toybox-ee18ddbb783b/toys/pending/last.c 2014-05-23 11:45:20.059411741
+0530
@@ -36,7 +36,7 @@
 static void free_list()
 {
   if (TT.list) {
-llist_traverse(TT.list, free_arg_list);
+llist_traverse(TT.list, llist_free_arg);
 TT.list = NULL;
   }
 }

attached is the fix patch.

regards,
Ashwini


last.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [Patch] dhcp client - crash fix

2014-05-21 Thread Ashwini Sharma
Hi Rob, list,

dhcp client had a segfault, when DHCP message contained 'pad' option.

The parsing logic kept checking for other options beyond __pad__ option,
without
checking if it was __end__ option after that or not.

--- a/toys/pending/dhcp.c 2014-05-14 06:15:01.0 +0530
+++ b/toys/pending/dhcp.c 2014-05-21 14:11:22.396020084 +0530
@@ -1101,7 +1101,10 @@
   }

   while (*optptr != DHCP_OPTION_END) {
-while (*optptr == DHCP_OPTION_PADDING) optptr++;
+if (*optptr == DHCP_OPTION_PADDING) {
+  optptr++;
+  continue;
+}
 if (*optptr == DHCP_OPTION_OVERLOAD) {
   overloaded = optptr[2];
   optptr += optptr[1] + 2;

Please apply the attched fix patch to dhcp.c

regards,
Ashwini


dhcp.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [New Toy] - lsattr chattr

2014-05-02 Thread Ashwini Sharma
Hi Rob, List,

Attached is the patch for __lsattr__ and __chattr__ implementation.

This is the modified and better version from the last one I sent.
It is having the both the mains (__lsattr_main()__ and __chattr_main()__ )
in single file.

Also removed the dependency of additional file in lib, as common code is in
the
same __.c__ file.

Have a look, your inputs are welcome.

regards,
Ashwini


lsattr.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] Sorry about the build breakage...

2014-04-16 Thread Ashwini Sharma
Hi Rob,

I was about to send it across... anyways.
Attached is the patch for build break fix.

regards,
Ashwini


On Thu, Apr 17, 2014 at 4:47 AM, Rob Landley r...@landley.net wrote:

 Should be fixed now. I _still_ get bitten by hg import checking in
 every modified file in my entire tree. It's an enormous design flaw I
 complained about on the mercurial list months ago, and Matt Mackall went
 I don't understand what you mean, the code's doing what I wrote.

 I agree that he doesn't understand what I mean...

 Doing the release notes for 0.4.8 now. (Started them yesterday morning,
 had the perfect tax day quote and everything, but as always preparing a
 release uncovered stuff I had to fix...)

 Rob
 ___
 Toybox mailing list
 Toybox@lists.landley.net
 http://lists.landley.net/listinfo.cgi/toybox-landley.net



date.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [New Toy] - printf

2014-04-07 Thread Ashwini Sharma
Hello Rob, List,

An implementation of __printf__ is attached.
Would love to have your inputs on the same.

__PATCH__:

An issue in ifconfig while verifying the HW Address, which is assumed
to be of the format __C2:79:38:95:CD:AB__ but can be of form
__C2:79:38:95:D:A__. In this case the HW address is reported as bad.

 if (*hw_addr == ':') hw_addr++;
 sscanf(hw_addr, %2x%n, val, len);
-if (len != 2) break;
+if (!len || len  2) break; // 1 nibble can be set e.g.
C2:79:38:95:D:A
 hw_addr += len;
 *p++ = val;

patch for same is attached.

regards,
Ashwini

PS: A reminder again!! about the commands lost in mailing list.
__getty__ and __modprobe__ implementations are still hanging around in
there.
/* printf.c - Format and Print the data.
 *
 * Copyright 2014 Sandeep Sharma sandeep.jack2...@gmail.com
 * Copyright 2014 Kyungwan Han asura...@gmail.com
 *
 * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html

USE_PRINTF(NEWTOY(printf, 1, TOYFLAG_USR|TOYFLAG_BIN))

config PRINTF 
bool printf
default n
help
usage: printf Format [Arguments..]

Format and print ARGUMENT(s) according to FORMAT.
Format is 'C' control output as 'C' printf.
*/
#define FOR_printf
#include toys.h

GLOBALS(
  char *hv_w;
  char *hv_p;
  int encountered;
)

// Calculate width and precision from format string
static int get_w_p()
{
  char *ptr, *str = *toys.optargs;
  
  errno = 0;
  if (*str == '-') str++;
  long value = strtol(str, ptr, 10);
  if (errno || (ptr  (*ptr != '\0' || ptr == str)))
perror_msg(Invalid num %s, *toys.optargs);
  if (*--str == '-') return (int)(-1 * value);
  return value;
}

// Add ll and L to Interger and floating point formats respectively.
static char *get_format(char *f)
{
  int len = strlen(f);
  char last = f[--len], *post = ;

  f[len] = '\0';
  if (strchr(diouxX, last)) post = ll;  // add ll to integer modifier.
  else if (strchr(feEgG, last)) post = L; // add L to float modifier.
  return xmprintf(%s%s%c, f, post, last);
}

// Print arguments with corresponding conversion and width and precision.
static void print(char *fmt, int w, int p, int l)
{
  char *ptr = (fmt+l-1), *ep = NULL, *format = NULL;
  long long val;
  long double dval;
  
  errno = 0;
  switch (*ptr) {
case 'd': /*FALL_THROUGH*/
case 'i': /*FALL_THROUGH*/
case 'o': /*FALL_THROUGH*/
case 'u': /*FALL_THROUGH*/
case 'x': /*FALL_THROUGH*/
case 'X':
  if (!*toys.optargs) val = 0;
  else {
if (**toys.optargs == '\'' || **toys.optargs == '')
  val = *((*toys.optargs) + 1);
else {
  val = strtoll(*toys.optargs, ep, 0);
  if (errno || (ep  (*ep != '\0' || ep == *toys.optargs))) {
perror_msg(Invalid num %s, *toys.optargs);
val = 0;
  }
}
  }
  format = get_format(fmt);
  TT.hv_w ? (TT.hv_p ? printf(format, w, p, val) : printf(format, w, val))
: (TT.hv_p ? printf(format, p, val) : printf(format, val));
  break;
case 'g': /*FALL_THROUGH*/
case 'e': /*FALL_THROUGH*/
case 'E': /*FALL_THROUGH*/
case 'G': /*FALL_THROUGH*/
case 'f':
  if (*toys.optargs) {
dval = strtold(*toys.optargs, ep);
if (errno || (ep  (*ep != '\0' || ep == *toys.optargs))) {
  perror_msg(Invalid num %s, *toys.optargs);
  dval = 0;
}
  } else dval = 0;
  format = get_format(fmt);
  TT.hv_w ? (TT.hv_p ? printf(format, w, p, dval):printf(format, w, dval))
: (TT.hv_p ? printf(format, p, dval) :  printf(format, dval));
  break;
case 's':
  {
char *str = (*toys.optargs ? *toys.optargs : );
TT.hv_w ? (TT.hv_p ? printf(fmt,w,p,str): printf(fmt, w, str))
  : (TT.hv_p ? printf(fmt, p, str) : printf(fmt, str));
  }
  break;
case 'c':
  printf(fmt, (*toys.optargs ? **toys.optargs : '\0'));
  break;
  }
  if (format) free(format);
}

// Handle the escape sequences.
static int handle_slash(char **esc_val)
{
  char *ptr = *esc_val;
  int esc_length = 0;
  unsigned  base = 0, num = 0, result = 0, count = 0;
  
  /*
   * Hex escape sequence have only 1 or 2 digits, xHH. Oct escape sequence 
   * have 1,2 or 3 digits, xHHH. Leading 0 (\0HHH) we are ignoring.
   */
  if (*ptr == 'x') {
ptr++;
esc_length++;
base = 16;
  } else if (isdigit(*ptr)) base = 8;

  while (esc_length  3  base) {
num = tolower(*ptr) - '0';
if (num  10) num += ('0' - 'a' + 10);
if (num = base) {
  if (base == 16) {
esc_length--;
if (!esc_length) {// Invalid hex value eg. /xvd, print as it is /xvd
  result = '\\';
  ptr--;
}
  }
  break;
}
esc_length++;
count = result = (count * base) + num;
ptr++;
  }
  if (base) {
ptr--;
*esc_val = ptr;
return (char)result;
  } else {
switch (*ptr) {
  case 'n':  result = '\n'; break;
  case 't':  result = 

[Toybox] [New Toy] - reset

2014-04-07 Thread Ashwini Sharma
Hi List,

A tool to reset the terminal.
This implementation depends on the _stty_ 'sane' settings.

Is this approach fine, or should the _stty_  __sane__ stuff be done in
__reset__
command itself.

Your inputs are welcome.

regards,
Ashwini
/* reset.c - A program to reset the terminal.
 *
 * Copyright 2014 Ashwini Kumar ak.ashw...@gmail.com
 * Copyright 2014 Kyungwan Han asura...@gmail.com
 *
 * No Standard.

USE_RESET(NEWTOY(reset, NULL, TOYFLAG_USR|TOYFLAG_BIN))

config RESET
  bool reset
  default n
  help
usage: reset

A program to reset the terminal.
*/
#define FOR_reset
#include toys.h

void reset_main(void)
{
  char *args[] = {stty, sane, NULL};

  /* \033c - reset the terminal with default setting
   * \033(B - set the G0 character set (B=US)
   * \033[2J - clear the whole screen
   * \033[0m - Reset all attributes
   */
  if (isatty(1)) xprintf(\033c\033(B\033[0m\033[J\033[?25h);
  fflush(stdout);
  // set the terminal to sane settings
  xexec(args);
}
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [Patch] - ifconfig hw address Makefile clean target

2014-02-26 Thread Ashwini Sharma
Hi Rob, List,

Encountered couple of issues,

1. ifconfig - while setting hw address, the condition check was wrong.
2. Makefile - Clean target didn't remove generated/globals.h and testdir.

attached are the patches for the same.

regards,
Ashwini


Makefile.patch
Description: Binary data


ifconfig.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [New toy] rudimentary getty

2013-12-19 Thread Ashwini Sharma
Hi,

What a coincidence, even I was about to send getty implementation in this
forum.

Attached is a little largeish version of getty.
Supporting TERM settings, baud rate setting, issue file, updating utmp
entries

if this suits, can add to the tree.
Looking forward to your inputs.

regards,
Ashwini


On Thu, Dec 19, 2013 at 12:49 PM, ibid...@gmail.com wrote:

 Here's a basic getty.
 It just reopens the current tty in such a way as to allow blocking code
 to work, then calls the login program of your choice (-l).
 /etc/issue is ignored, so -i is a nop.
 It does NOT modify the environment (including setting TERM), support
 baud rate setting or autodetection, do anything with modems, prompt for
 any user input, or open new ttys.
 Supporting
 getty ttyN $TERM
 should be something like this...
 char * prepend(char *arg, char *pfix)
 {
   if (!arg) return NULL;
   int alen = strlen(arg), plen = strlen(pfix);
   char * ret = xzalloc(alen + plen + 1);
   strcpy(ret, pfix);
   strcpy(ret+plen, arg);
   return ret;
 }


   char *tty = prepend(toys.optargs[0], /dev/)
   if (!tty) tty = ttyname(0);
   if (toys.optc  1) {
 char *termname = prepend(toys.optargs[1], TERM=);
 if (termname) putenv(termname);
   }

 --
 With this, I can boot to a login prompt using only a shell and a toybox
 binary (with several pending applets enabled, and a hacked version of
 one of the many submissions for mount).

 I also have a small applet (resolve_modalias) that is mainly useful for
 testing, which I've sent a couple times to illustrate issues;
 maybe sometime I should see about putting the core code into a library
 function so modprobe and modinfo can share it

 Thanks,
 Isaac Dunham

 ___
 Toybox mailing list
 Toybox@lists.landley.net
 http://lists.landley.net/listinfo.cgi/toybox-landley.net


/* getty.c - A getty program to get controlling terminal.
 *
 * Copyright 2012 Sandeep Sharma sandeep.jack2...@gamil.com
 * Copyright 2013 Kyungwan Han asura...@gmail.com
 *
 * No Standard.

USE_GETTY(NEWTOY(getty, 2t#0H:I:l:f:iwnmLh,TOYFLAG_SBIN))

config GETTY
  bool getty
  default n
  help
Usage: getty [OPTIONS] BAUD_RATE[,BAUD_RATE]... TTY [TERMTYPE]

-hEnable hardware RTS/CTS flow control
-LSet CLOCAL (ignore Carrier Detect state)
-mGet baud rate from modem's CONNECT status message
-nDon't prompt for login name
-wWait for CR or LF before sending /etc/issue
-iDon't display /etc/issue
-f ISSUE_FILE  Display ISSUE_FILE instead of /etc/issue
-l LOGIN  Invoke LOGIN instead of /bin/login
-t SECTerminate after SEC if no login name is read
-I INITSTR  Send INITSTR before anything else
-H HOSTLog HOST into the utmp file as the hostname
*/
#define FOR_getty
#include toys.h
#include utmp.h

GLOBALS(
  char *issue_str;
  char *login_str;
  char *init_str;
  char *host_str; 
  long timeout;
  
  char *tty_name;  
  int  speeds[20];
  int  sc;  
  struct termios termios;
  char buff[128];
)

#define CTL(x)((x) ^ 0100) 
#define HOSTNAME_SIZE 32

typedef void (*sighandler_t)(int);
struct speed_mapper {
  long speed;
  speed_t code;
};

struct speed_mapper speedtab[] = {
  {50, B50}, {75, B75}, {110, B110}, {134, B134}, {150, B150}, {200, B200},
  {300, B300}, {600, B600}, {1200, B1200}, {1800, B1800}, {2400, B2400},
  {4800, B4800}, {9600, B9600},
#ifdef  B19200
  {19200, B19200},
#endif
#ifdef  B38400
  {38400, B38400},
#endif
#ifdef  EXTA
  {19200, EXTA},
#endif
#ifdef  EXTB
  {38400, B38400},
#endif
#ifdef B57600
  {57600, B57600},
#endif
#ifdef B115200
  {115200, B115200},
#endif
#ifdef B230400
  {230400, B230400},
#endif
  {0, 0},
};

// Find speed from mapper array 
static speed_t encode(char *s)
{
  struct speed_mapper *sp;
  long speed = atolx(s);

  if (!speed) return 0;
  for (sp = speedtab; sp-speed; sp++) if (sp-speed == speed) return sp-code;
  return (speed_t) -1;
}

static void get_speed(char *sp)
{
  char *ptr;

  TT.sc = 0;
  while ((ptr = strsep(sp, ,))) {
TT.speeds[TT.sc] = encode(ptr);
if (TT.speeds[TT.sc]  0) perror_exit(Bad Speed);
if (++TT.sc  10) perror_exit(Too many alternate speeds, Max is 10);
  }
}

// Parse args and set TERM env. variable
static void parse_arguments(void)
{
  if (isdigit(**toys.optargs)) {
get_speed(*toys.optargs);
if (*++toys.optargs) TT.tty_name = xmsprintf(%s, *toys.optargs);
  } else {
TT.tty_name = xmsprintf(%s, *toys.optargs);
if (*++toys.optargs) get_speed(*toys.optargs);
  } 
  if (*++toys.optargs) setenv(TERM, *toys.optargs, 1);
}

// Get controlling terminal and redirect stdio 
static void open_tty(void)
{
  if (strcmp(TT.tty_name, -)) {
if (*(TT.tty_name) != '/') TT.tty_name = xmsprintf(/dev/%s, TT.tty_name);
// Sends SIGHUP to all foreground process if Session leader don't die,Ignore
sighandler_t sig = signal(SIGHUP, SIG_IGN); 
ioctl(0, TIOCNOTTY, 0); // Giveup if there is any controlling 

[Toybox] [New Toy] - modprobe

2013-12-17 Thread Ashwini Sharma
Hi List,

An implementation for modprobe is attached.
go thru the same and let me know your inputs.

regards,
Ashwini
/* modprobe.c - modprobe utility.
 *
 * Copyright 2012 Madhur Verma mad.fl...@gmail.com
 * Copyright 2013 Kyungwan Han asura...@gmail.com
 *
 * No Standard.

USE_MODPROBE(NEWTOY(modprobe, alrqvsDb, TOYFLAG_SBIN))

config MODPROBE
  bool modprobe
  default y
  help
usage: modprobe [-alrqvsDb] MODULE [symbol=value][...]

modprobe utility - inserts modules and dependencies.

-a  Load multiple MODULEs
-l  List (MODULE is a pattern)
-r  Remove MODULE (stacks) or do autoclean
-q  Quiet
-v  Verbose
-s  Log to syslog
-D  Show dependencies
-b  Apply blacklist to module names too
*/
#define FOR_modprobe
#include toys.h
#include sys/syscall.h
#include fnmatch.h

GLOBALS(
  struct arg_list *probes;
  struct arg_list *dbase[256];
  char *cmdopts;
  int nudeps;
  uint8_t symreq;
)

/* Note: if #define DBASE_SIZE modified, 
 * Please update GLOBALS dbase[256] accordingly.
 */
#define DBASE_SIZE  256
#define MODNAME_LEN 256

// Modules flag definations
#define MOD_ALOADED   0x0001
#define MOD_BLACKLIST 0x0002
#define MOD_FNDDEPMOD 0x0004
#define MOD_NDDEPS0x0008

static void (*dbg)(char *format, ...);
// dummy interface for debugging.
static void dummy(char *format, ...)
{
}

// Current probing modules info
struct module_s {
  uint32_t flags;
  char *cmdname, *name, *depent, *opts;
  struct arg_list *rnames, *dep;
};

// Converts path name FILE to module name.
static char *path2mod(char *file, char *mod)
{
	int i;
	char *from, *lslash;

	if (!file) return NULL;
	if (!mod) mod = xmalloc(MODNAME_LEN);
	
  lslash = strrchr(file, '/');
  if (!lslash || (lslash == file  !lslash[1])) from = file;
  else from = lslash + 1;
  
  for (i = 0; i  (MODNAME_LEN-1)  from[i]  from[i] != '.'; i++)
		mod[i] = (from[i] == '-') ? '_' : from[i];
	mod[i] = '\0';
	return mod;
}

// locate character in string.
static char *strchr_nul(char *s, int c)
{
  while(*s != '\0'  *s != c) s++;
  return (char*)s;
}

// Add options in opts from toadd.
static char *add_opts(char *opts, char *toadd)
{
  if (toadd) {
int optlen = 0;

if (opts) optlen = strlen(opts);
opts = xrealloc(opts, optlen + strlen(toadd) + 2);
sprintf(opts + optlen,  %s, toadd);
  }
  return opts;
}

// Remove first element from the list and return it.
static void *llist_popme(struct arg_list **head)
{
  char *data = NULL;
  struct arg_list *temp = *head;

  if (temp) {
data = temp-arg;
*head = temp-next;
free(temp);
  }
  return data;
}

// Add new node at the beginning of the list.
static void llist_add(struct arg_list **old, void *data)
{
  struct arg_list *new = xmalloc(sizeof(struct arg_list));

  new-arg = (char*)data;
  new-next = *old;
  *old = new;
}

// Add new node at tail of list.
static void llist_add_tail(struct arg_list **head, void *data)
{
  while (*head) head = (*head)-next;
  *head = xzalloc(sizeof(struct arg_list));
  (*head)-arg = (char*)data;
}

// Reverse list order.
static struct arg_list *llist_rev(struct arg_list *list)
{
  struct arg_list *rev = NULL;

  while (list) {
struct arg_list *next = list-next;

list-next = rev;
rev = list;
list = next;
  }
  return rev;
}

/*
 * Returns struct module_s from the data base if found, NULL otherwise.
 * if ps - create module entry, add it to data base and return the same mod.
 */
static struct module_s *get_mod(char *mod, uint8_t ps)
{
  char name[MODNAME_LEN];
  struct module_s *modentry;
  struct arg_list *temp;
  unsigned i, hash = 0;

  path2mod(mod, name);
  for (i = 0; name[i]; i++) hash = ((hash*31) + hash) + name[i];
  hash %= DBASE_SIZE;
  for (temp = TT.dbase[hash]; temp; temp = temp-next) {
modentry = (struct module_s *) temp-arg;
if (!strcmp(modentry-name, name)) return modentry;
  }
  if (!ps) return NULL;
  modentry = xzalloc(sizeof(*modentry));
  modentry-name = xstrdup(name);
  llist_add(TT.dbase[hash], modentry);
  return modentry;
}

/*
 * Read a line from file with \ continuation and escape commented line.
 * Return the line in allocated string (*li)
 */
static int read_line(FILE *fl, char **li)
{
  char *nxtline = NULL, *line;
  int len, nxtlen, linelen, nxtlinelen;

  while (1) {
line = NULL;
linelen = nxtlinelen = 0;
len = getline(line, (size_t*)linelen, fl);
if (len = 0) return len;
// checking for commented lines.
if (line[0] != '#') break;
free(line);
  }
  for (;;) {
if (line[len - 1] == '\n') len--;
// checking line continuation.
if (!len || line[len - 1] != '\\') break;
len--;
nxtlen = getline(nxtline, (size_t*)nxtlinelen, fl);
if (nxtlen = 0) break;
if (linelen  len + nxtlen + 1) {
  linelen = len + nxtlen + 1;
  line = xrealloc(line, linelen);
}
memcpy(line[len], nxtline, nxtlen);
len += nxtlen;
  }
  line[len] = '\0';
  *li = xstrdup(line);
  if (line) free(line);
  if (nxtline) free(nxtline);
  return 

[Toybox] [New Toy] - brctl

2013-12-17 Thread Ashwini Sharma
Hi List,

An implementation for brctl (ethernet bridge control) is attached here with.
Open to your comments on this.

regards,
Ashwini
/* brctl.c - ethernet bridge control
 *
 * Copyright 2013 Ashwini Kumar ak.ashwini1...@gmail.com
 * Copyright 2013 Kyungwan Han asura...@gmail.com
 *
 * No Standard

USE_BRCTL(NEWTOY(brctl, 1, TOYFLAG_USR|TOYFLAG_SBIN))

config BRCTL
  bool brctl
  default y
  help
Usage: brctl COMMAND [BRIDGE [INTERFACE]]

Manage ethernet bridges

Commands:
show  Show a list of bridges
addbr BRIDGE  Create BRIDGE
delbr BRIDGE  Delete BRIDGE
addif BRIDGE IFACEAdd IFACE to BRIDGE
delif BRIDGE IFACEDelete IFACE from BRIDGE
setageing BRIDGE TIME Set ageing time
setfd BRIDGE TIME Set bridge forward delay
sethello BRIDGE TIME  Set hello time
setmaxage BRIDGE TIME Set max message age
setpathcost BRIDGE PORT COST   Set path cost
setportprio BRIDGE PORT PRIO   Set port priority
setbridgeprio BRIDGE PRIO  Set bridge priority
stp BRIDGE [1/yes/on|0/no/off] STP on/off
*/

#define FOR_brctl
#include toys.h
#include linux/if_bridge.h

GLOBALS(
int sockfd;
)
#define MAX_BRIDGES 1024 //same is no of ports supported

static void get_ports(char *bridge, int *indices)
{
  struct ifreq ifr;  
  int ifindices[MAX_BRIDGES];
  unsigned long args[4] = { BRCTL_GET_PORT_LIST,
(unsigned long) ifindices, MAX_BRIDGES, 0 };

  memset(ifindices, 0, MAX_BRIDGES);
  args[1] = (unsigned long)ifindices;
  strncpy(ifr.ifr_name, bridge, IFNAMSIZ);
  ifr.ifr_data = (char *)args;
  xioctl(TT.sockfd, SIOCDEVPRIVATE, ifr);
  if (indices) memcpy(indices, ifindices, sizeof(ifindices));
}

void get_br_info(char *bridge, struct __bridge_info *info)
{
  struct ifreq ifr;
  unsigned long args[4] = { BRCTL_GET_BRIDGE_INFO,
(unsigned long) info, 0, 0 };

  memset(info, 0, sizeof(*info));
  strncpy(ifr.ifr_name, bridge, IFNAMSIZ);
  ifr.ifr_data = (char *)args;

  if (ioctl(TT.sockfd, SIOCDEVPRIVATE, ifr)  0) {
perror_msg(%s: can't get info %s\n, bridge, strerror(errno));
return;
  }
}

void br_show(char **argv)
{
  struct __bridge_info info;
  int num, cnt, i, j, ifindices[MAX_BRIDGES], pindices[MAX_BRIDGES];
  unsigned long args[4] = { BRCTL_GET_BRIDGES,
(unsigned long)ifindices, MAX_BRIDGES,0 };
  char br[IF_NAMESIZE], ifn[IF_NAMESIZE];

  num = ioctl(TT.sockfd, SIOCGIFBR, args); //ret is num of bridges found
  if (num  0) error_exit(get bridges fail);
  printf(bridge name\tbridge id\t\tSTP enabled\tinterfaces\n);

  for (i = 0; i  num; i++) {
unsigned char *id;

if (!if_indextoname(ifindices[i], br)) perror_exit(interface not found);
get_br_info(br, info);
id = (unsigned char*)(info.bridge_id);
printf(%s\t\t,br);
printf(%.2x%.2x.%.2x%.2x%.2x%.2x%.2x%.2x, id[0], id[1], 
id[2], id[3], id[4], id[5], id[6], id[7]);
printf(\t%s\t\t,(info.stp_enabled)?yes : no);

memset(pindices, 0, sizeof(pindices));
get_ports(br, pindices);
for (j = 0, cnt = 0; j  MAX_BRIDGES; j++) {
  if (!pindices[j]) continue;
  if (!if_indextoname(pindices[j], ifn)) {
error_msg(no name for index :%d, pindices[j]);
continue;
  }
  if (cnt) printf(\n\t\t\t\t\t\t\t);
  printf(%s, ifn);
  cnt++;
}
xputc('\n');
  }
}

void br_addbr(char **argv)
{
  char br[IFNAMSIZ];
  unsigned long args[4] = {BRCTL_ADD_BRIDGE, (unsigned long) br, 0, 0};

#ifdef SIOCBRADDBR
  xioctl(TT.sockfd, SIOCBRADDBR, argv[0]);
#else
  strncpy(br, argv[0], IFNAMSIZ);   
  xioctl(TT.sockfd, SIOCSIFBR, args);
#endif
}

void br_delbr(char **argv)
{
  char br[IFNAMSIZ];
  unsigned long args[4] = {BRCTL_DEL_BRIDGE, (unsigned long) br, 0, 0};

#ifdef SIOCBRDELBR
  xioctl(TT.sockfd, SIOCBRDELBR, argv[0]);
#else
  strncpy(br, argv[0], IFNAMSIZ);
  xioctl(TT.sockfd, SIOCSIFBR, args);
#endif
}

void br_addif(char **argv)
{
  int index;
  struct ifreq ifr;
  unsigned long args[4] = {BRCTL_ADD_IF, 0, 0, 0};

  if (!(index = if_nametoindex(argv[1]))) perror_exit(interface %s, argv[1]);
#ifdef SIOCBRADDIF
  ifr.ifr_ifindex = index;
  xioctl(TT.sockfd, SIOCBRADDIF, ifr);
#else
  args[1] = index;
  strncpy(ifr.ifr_name, argv[0], IFNAMSIZ);
  ifr.ifr_data = (char *)args;
  xioctl(TT.sockfd, SIOCDEVPRIVATE, ifr);
#endif
}

void br_delif(char **argv)
{
  int index; 
  struct ifreq ifr;  
  unsigned long args[4] = {BRCTL_DEL_IF, 0, 0, 0};

  if (!(index = if_nametoindex(argv[1]))) perror_exit(interface %s,argv[1]);
#ifdef SIOCBRDELIF
  ifr.ifr_ifindex = ifindex;
  xioctl(TT.sockfd, SIOCBRDELIF, ifr);
#else
  args[1] = index; 
  strncpy(ifr.ifr_name, argv[0], IFNAMSIZ);
  ifr.ifr_data = (char *)args;  
  xioctl(TT.sockfd, SIOCDEVPRIVATE, ifr);
#endif
}

static void strtotimeval(struct timeval *tv, char *time)
{
  double secs;

  if (sscanf(time, %lf, secs) != 1) error_exit(time format 

Re: [Toybox] Issue with names_to_pid(), pidof, killall

2013-12-17 Thread Ashwini Sharma
Its good to see you back on the list!!

there was a typo!!, I did mean __non-existing__ process instead of
__non-exiting__

-Ashwini

On Tue, Dec 17, 2013 at 7:50 PM, Rob Landley r...@landley.net wrote:

 On 11/22/2013 12:26:14 AM, Ashwini Sharma wrote:

 Hi All,

 Due to some issue with my email account, changing my email to
 ak.ashwini1...@gmail.com


 Finally catching up on my email myself. :)


  I came across a bug in pidof command. The issue is
 with _-o_ option. callback function returns _1_ for omit
 list, to names_to_pid().


 Sigh. names_to_pid() is in pending, a command not in pending is calling
 it...

 (My bad.)


  names_to_pid(), breaks the internal _for_ loop, at the same
 time it also breaks out of the _while(readdir())_ loop.
 Which is causing the issue, as other pids are not searched for.


 Indeed, it should return 0 not 1.


  for (curname = names; *curname; curname++)
   if (**curname == '/' ? !strcmp(cmd, *curname)
   : !strcmp(basename(cmd), basename(*curname)))
 if (callback(u, *curname)) break;
 -if (*curname) break;
 }

 Why break from _while_ loop, as there can be other processes in the list
 waiting for actioin.
 removing this fixes the issue.


 Returning nonzero says to abort the loop. We shouldn't return nonzero if
 we want additional callbacks callbacks.


  _names_to_pid()_ is also used by _killall_. killall also has issues,

 1. the exit status is always  0, thats because of toys.exitval++
 in _main() function. Exit status need to be corrected.


 Actually it's supposed to exit 1 if no processes were found, and 0 if it
 could kill at least one process. I'll have it zero out the exit code if a
 signal could successfully be delivered.


  2. No error/warning message is displayed for a non-exiting process.
 as is one by GNU implementation. instead due to the _toys.exitval++_
 its always printing __ No such process __ without any process name.


 Actually it prints (bad %u, pid)?

   ret = kill(pid, TT.signum);
   if (ret == -1  !(toys.optflags  FLAG_q))
 error_msg(bad %u, (unsigned)pid);

 That looks like it should be perror_msg() so it reports the errno reason.

 The no such process message was always printed because the exit value
 was never cleared.

No, the problem is if you kill things that don't exist in the ubuntu
 version:

   $ killall whackamole froglegs
   whackamole: no process found
   froglegs: no process found

 You get an error message for each one. And this infrastructure isn't
 tracking that. Although to be honest, the upstream infrastructure is lying:

   $ killall init whackamole
   init(1): Operation not permitted
   init: no process found
   whackamole: no process found

 And the errno behavior is slightly non-obvious:

   $ sleep  
   [1] 8016
   $ killall init sleep whackamole
   init(1): Operation not permitted
   init: no process found
   whackamole: no process found
   [1]+  Terminated  sleep 
   $ echo $?
   1

 Rummage, rummage... Ok, if there was a command it couldn't kill (including
 not found), errno is 1. Order doesn't matter.

 Ideally I'd save the errno of each entry so the message was right, but I
 don't want to mark up optargs[] (and if I did it'd screw up killing a
 second command with the same name), and can't conveniently use toybuf as a
 bitfield for two reasons (already used for a message right now, not
 necessarily long enough).

 Speaking of not necessarily long enough:

   if (toys.optflags  FLAG_i) {
 sprintf(toybuf, Signal %s(%d) ?, name, pid);

 Bad because toybuf is 4k and name is environment data that could be 128k,
 so somebody can trivially manipulate a heap overflow out of that.

 Right, if I switch that to xsmprintf() I can use toybuf. I can save the
 start of the name array into the globals and then do name-start to get
 the offset into the array. If I use it as a bitfield I can reproduce the
 original (broken) behavior, and can track 32768 commands, which is probably
 more than anyone will ever use. (With 128k environment space they'd all
 have to be 3 character command names to _fill_ that, you'd need 2 chars to
 surpass it...)

 If I use it as an array to store the errno... does it need to be short or
 char?

   $ cat arch/*/include/uapi/asm/errno* | awk '{print $3}' | sort -n
   ...
   255
   256
   257
   516
   1133

 Sigh. Those last few aren't relevant (I grepped, they won't be produced by
 kill(2)), but from a complexity level I don't want to have to explain it in
 a giant comment, nor am I quite comfortable with 4096 entries as a limit
 where behavior magically changes.

 Screw it: malloc an array.

 The next question is, how do I get the position in the array? I was
 thinking I could do pointer subtraction but that gives me how many bytes of
 string data were used. Hack up names_to_pid() to pass it? (Only currently
 two users...) Do a for loop checking?

 Eh, I'll just do a for loop. Pathological case is less than 60k command
 line, and I don't have

Re: [Toybox] FTP commands

2013-12-12 Thread Ashwini Sharma
Hi,

The input parameter port was kept as string, so that the
 user can also give service name like ftp instead of numeric PORT.

Which will be resolved by getaddrinfo() using /etc/services.

regards,
Ashwini


On Thu, Dec 12, 2013 at 1:27 PM, ibid...@gmail.com wrote:

 Thanks!
 Noticed a few differences from standard help messages, plus a small
 problem with the port number handling:
 when no port was specified, it failed.
 The solution ended up dropping a couple lines.

 Attached is the diff from your second version.

 Thanks,
 Isaac Dunham

 ___
 Toybox mailing list
 Toybox@lists.landley.net
 http://lists.landley.net/listinfo.cgi/toybox-landley.net


___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [New Toys] - chattr and lsattr

2013-12-11 Thread Ashwini Sharma
Hi Rob, list,

attached is a patch implementing __chattr__ and __lsattr__.

For this, few macros are added into __e2fs.h__ and a new file lib/e2fs.c
implementing a function, used in both chattr and lsattr, for getting the
file
attributes is added.

Your inputs are welcome.

regards,
Ashwini

PS:- Community seems to be sleeping big time. Buck up guys :-)


chattr.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] FTP commands

2013-12-10 Thread Ashwini Sharma
Hi List,

The last attachment was not the proper version.
Please use the latest one attached here with.

regards,
Ashwini


On Tue, Dec 10, 2013 at 11:22 AM, Ashwini Sharma
ak.ashwini1...@gmail.comwrote:

 Hi Rob, List,

 Attached is an implementation for ftpget/put commands.
 Your inputs are welcome.

 regards,
 Ashwini


 On Thu, Nov 28, 2013 at 12:41 AM, Rob Landley r...@landley.net wrote:

 On 11/05/2013 10:19:32 PM, David Seikel wrote:

 On Tue, 5 Nov 2013 20:06:10 -0800 ibid...@gmail.com wrote:

  On Fri, Oct 18, 2013 at 01:05:50AM +0200, Bertold Van den Bergh wrote:
  
   Can commands be accepted that are not on the roadmap? I will
   certainly need 'ntpdate' which for embedded systems is better than
   a full blown ntpd.
 
  That would be a question for Rob.
 
  That said, I'd be in favor of it. Having *not* examined NTP in
  detail, I get the impression that it might be possible to have ntpd
  and ntpdate share much of their code.

 Aboriginal Linux uses rdate, which is also not on the toybox roadmap.
 I would have thought that rdate or ntpdate would have been.


 Either would be good. I vaguely recall that rdate uses a simpler but
 semi-deprecated network standard. Figuring out what to do there is
 somewhere way down on my todo list. :)

 (If either was in toolbox, it would be on the roadmap...)

 Rob
 ___
 Toybox mailing list
 Toybox@lists.landley.net
 http://lists.landley.net/listinfo.cgi/toybox-landley.net



/* ftpget.c - Get a remote file from FTP.
 *
 * Copyright 2013 Ranjan Kumar ranjankumar@gmail.com
 * Copyright 2013 Kyungwan Han asura...@gmail.com
 *
 * No Standard.
 * 
USE_FTPGET(NEWTOY(ftpget, 2cvu:p:P:, TOYFLAG_BIN))
USE_FTPGET(OLDTOY(ftpput,ftpget, 2vu:p:P:, TOYFLAG_BIN))

config FTPGET
  bool ftpget/ftpput
  default y
  help
usage: ftpget [-cv] [-u username -p password -P PortNumber] HOST_NAME [LOCAL_FILENAME] REMOTE_FILENAME
usage: ftpput [-v] [-u username -p password -P PortNumber] HOST_NAME [REMOTE_FILENAME] LOCAL_FILENAME

ftpget - Get a remote file from FTP.
ftpput - Upload a local file on remote machine through FTP.

-c Continue previous transfer.
-v Verbose.
-u User name.
-p Password.
-P Port Number.
*/
#define FOR_ftpget
#include toys.h

GLOBALS(
  char *port;
  char *password;
  char *username;

  FILE *sockfp;
  int c;
  int isget;
  char buf[sizeof(struct sockaddr_storage)];
)

#define DATACONNECTION_OPENED   125
#define FTPFILE_STATUSOKAY  150
#define FTP_COMMAND_OKAY200
#define FTPFILE_STATUS  213
#define FTPSERVER_READY 220
#define CLOSE_DATACONECTION 226
#define PASSIVE_MODE227
#define USERLOGGED_SUCCESS  230
#define PASSWORD_REQUEST331
#define REQUESTED_PENDINGACTION 350


static void setport(unsigned port_num)
{
  int af = ((struct sockaddr *)TT.buf)-sa_family;

  if (af == AF_INET) ((struct sockaddr_in*)TT.buf)-sin_port = port_num;
  else if (af == AF_INET6) ((struct sockaddr_in6*)TT.buf)-sin6_port = port_num;
}

static int connect_to_stream()
{
  int sockfd, af = ((struct sockaddr *)TT.buf)-sa_family;

  sockfd = xsocket(af, SOCK_STREAM, 0);
  if (connect(sockfd, (struct sockaddr*)TT.buf,((af == AF_INET)? 
  sizeof(struct sockaddr_in):sizeof(struct sockaddr_in6)))  0) {
close(sockfd);
perror_exit(can't connect to remote host);
  }
  return sockfd;
}

//close ftp connection and print the message.
static void close_stream(char *msg_str)
{
  char *str = toybuf; //toybuf holds response data.

  //Remove garbage chars (from ' ' space to '\x7f') DEL remote server response.
  while ((*str = 0x20)  (*str  0x7f)) str++; 
  *str = '\0';
  if (TT.sockfp) fclose(TT.sockfp);
  error_exit(%s server response: %s, (msg_str) ? msg_str:, toybuf);
}

//send command to ftp and get return status.
static int get_ftp_response(char *command, char *param)
{
  unsigned cmd_status = 0;
  char *fmt = %s %s\r\n;

  if (command) {
if (!param) fmt += 3;
fprintf(TT.sockfp, fmt, command, param);
fflush(TT.sockfp);
if (toys.optflags  FLAG_v) 
  fprintf(stderr, FTP Request: %s %s\r\n, command, param);
  }

  do {
if (!fgets(toybuf, sizeof(toybuf)-1, TT.sockfp)) close_stream(NULL);
  } while (!isdigit(toybuf[0]) || toybuf[3] != ' ');

  toybuf[3] = '\0';
  cmd_status = atolx_range(toybuf, 0, INT_MAX);
  toybuf[3] = ' ';
  return cmd_status;
}

static void send_requests(void)
{
  int cmd_status = 0;

  //FTP connection request.
  if (get_ftp_response(NULL, NULL) != FTPSERVER_READY) close_stream(NULL);

  //230 User authenticated, password please; 331 Password request.
  cmd_status = get_ftp_response(USER, TT.username);
  if (cmd_status == PASSWORD_REQUEST) { //user logged in. Need Password.
if (get_ftp_response(PASS, TT.password) != USERLOGGED_SUCCESS) 
  close_stream(PASS);
  } else if (cmd_status == USERLOGGED_SUCCESS); //do nothing
  else close_stream(USER);
  //200 Type Binary. Command okay

[Toybox] [Patch] - vconfig use atolx_range() instead of strtorange()

2013-12-09 Thread Ashwini Sharma
Hi List,

atolx_range() is already added into lib/lib.c,
in vconfig.c, __ atolx_range()__  can be used in place of locally
defined __ strtorange()__ function.

Attached is the patch for the same.

regards,
Ashwini


vconfig.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [Patch] - adding '-B' to grep

2013-12-06 Thread Ashwini Sharma
Hi Rob, list,

_-B_ option support for printing leading context lines, before the match, is
added to grep command.

The implementation is based on the queue. Used sys/queue for the purpose.

Have a glance at the same.

Regards,
Ashwini


grep.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [New Toys] - telnet daemon and client

2013-12-03 Thread Ashwini Sharma
Hi List,

attached is a patch for the telnet daemon and client implementation.

Have a look at the same and pass on your inputs.

Thanks,
Ashwini


telnet.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [New Toys] - More and Last commands

2013-12-03 Thread Ashwini Sharma
Hi All,

An implementation for More and last commands is attached.

Your inputs are welcome.

regards,
Ashwini
/* last.c - Show listing of last logged in users.
 *
 * Copyright 2013 Ranjan Kumar ranjankumar@gmail.com
 * Copyright 2013 Kyungwan Han asura...@gmail.com
 *
 * No Standard.

USE_LAST(NEWTOY(last, f:W, TOYFLAG_BIN))

config LAST
  bool last
  default y
  help
Usage: last [-W] [-f FILE]

Show listing of last logged in users.

-W  Display the information without host-column truncation.
-f FILE Read from file FILE instead of /var/log/wtmp.
*/
#define FOR_last

#include toys.h
#include utmp.h

#ifndef SHUTDOWN_TIME
#define SHUTDOWN_TIME 254
#endif

GLOBALS(
  char *file;
  struct arg_list *list;
)

static void free_node(void *data)
{
  void *arg = ((struct arg_list*)data)-arg;
  
  if (arg) free(arg);
  free(data);
}

static void free_list()
{
  if (TT.list) {
llist_traverse(TT.list, free_node);
TT.list = NULL;
  }
}

static void llist_add_node(struct arg_list **old, void *data)
{
  struct arg_list *new = xmalloc(sizeof(struct arg_list));
  
  new-arg = (char*)data;
  new-next = *old;
  *old = new;
}

// Find a node and dlink it from the list.
static struct arg_list *find_and_dlink(struct arg_list **list, char *devname)
{
  struct arg_list *l = *list;
  
  while (*list) {
struct utmp *ut = (struct utmp *)l-arg;

if (!strncmp(ut-ut_line, devname, UT_LINESIZE)) {
  *list = (*list)-next;
  return l;
}
list = (*list)-next;
l = *list;
  }
  return NULL;
}

// Compute login, logout and duration of login.
static void seize_duration(time_t tm0, time_t tm1)
{
  unsigned days, hours, mins;
  double diff = difftime(tm1, tm0);
  
  diff = (diff  0) ? (tm1 - tm0) : 0;
  toybuf[0] = toybuf[18] = toybuf[28] = '\0';
  strncpy(toybuf, ctime(tm0), 16); // Login Time.
  snprintf(toybuf+18, 8, - %s, ctime(tm1) + 11); // Logout Time.
  days = (mins = diff/60)/(24*60);
  hours = (mins = (mins%(24*60)))/60;
  mins = mins%60;
  sprintf(toybuf+28, (%u+%02u:%02u), days, hours, mins); // Duration.
}

void last_main(void)
{
  struct utmp ut;
  struct stat sb;
  time_t tm[3] = {0,}; //array for time avlues, previous, current
  char *file = /var/log/wtmp;
  int fd, pwidth, curlog_type = EMPTY;
  off_t loc;

  if (toys.optflags  FLAG_f) file = TT.file;

  TT.list = NULL;
  pwidth = (toys.optflags  FLAG_W) ? 46 : 16;
  time(tm[1]);
  fd = xopen(file, O_RDONLY);
  loc = xlseek(fd, 0, SEEK_END);
  // in case of empty file or 'filesize  sizeof(ut)'
  fstat(fd, sb);
  if (sizeof(ut)  sb.st_size) {
xclose(fd);
printf(\n%s begins %-24.24s\n, basename(file), ctime(sb.st_ctime));
return;
  }
  loc = xlseek(fd, loc - sizeof(ut), SEEK_SET);

  while (1) {
xreadall(fd, ut, sizeof(ut));
tm[0] = (time_t)ut.ut_tv.tv_sec;
if (ut.ut_line[0] == '~') {
  if (!strcmp(ut.ut_user, runlevel)) ut.ut_type = RUN_LVL;
  else if (!strcmp(ut.ut_user, reboot)) ut.ut_type = BOOT_TIME;
  else if (!strcmp(ut.ut_user, shutdown)) ut.ut_type = SHUTDOWN_TIME;
} 
else if (ut.ut_user[0] == '\0') ut.ut_type = DEAD_PROCESS;
else if (ut.ut_user[0]  ut.ut_line[0]  (ut.ut_type != DEAD_PROCESS)
 (strcmp(ut.ut_user, LOGIN)) ) ut.ut_type = USER_PROCESS;
/* The pair of terminal names '|' / '}' logs the
 * old/new system time when date changes it.
 */ 
if (!strcmp(ut.ut_user, date)) {
  if (ut.ut_line[0] == '|') ut.ut_type = OLD_TIME;
  if (ut.ut_line[0] == '{') ut.ut_type = NEW_TIME;
}
if ( (ut.ut_type == SHUTDOWN_TIME) || ((ut.ut_type == RUN_LVL)  
(((ut.ut_pid  255) == '0') || ((ut.ut_pid  255) == '6' {
  tm[1] = tm[2] = (time_t)ut.ut_tv.tv_sec;
  free_list();
  curlog_type = RUN_LVL;
} else if (ut.ut_type == BOOT_TIME) {
  seize_duration(tm[0], tm[1]);
  strncpy(ut.ut_line, system boot, sizeof(system boot));
  free_list();
  printf(%-8.8s %-12.12s %-*.*s %-16.16s %-7.7s %s\n, ut.ut_user, 
  ut.ut_line, pwidth, pwidth, ut.ut_host, 
  toybuf, toybuf+18, toybuf+28);
  curlog_type = BOOT_TIME;
  tm[2] = (time_t)ut.ut_tv.tv_sec;
} else if (ut.ut_type == USER_PROCESS  *ut.ut_line) {
  struct arg_list *l = find_and_dlink(TT.list, ut.ut_line);
  if (l) {
struct utmp *u = (struct utmp *)l-arg;
seize_duration(tm[0], u-ut_tv.tv_sec);
printf(%-8.8s %-12.12s %-*.*s %-16.16s %-7.7s %s\n, ut.ut_user, 
ut.ut_line, pwidth, pwidth, ut.ut_host, 
toybuf, toybuf+18, toybuf+28);
free(l-arg);
free(l);
  } else {
int type = !tm[2] ? EMPTY : curlog_type;
if (!tm[2]) { //check process's current status (alive or dead).
  if ((ut.ut_pid  0)  (kill(ut.ut_pid, 0)!=0)  (errno == ESRCH))
type = INIT_PROCESS;
}
seize_duration(tm[0], tm[2]);
switch (type) {
  case EMPTY:
strncpy(toybuf+18,   still, sizeof(  still));

[Toybox] [Patch] - Traceroute with IPv6 support

2013-11-25 Thread Ashwini Sharma
Hi All,

IPv6 support is added into traceroute command.
traceroute6 is made as an old toy of traceroute.

Attached is the updated file.
Have a look at the same and let me know for inputs.

Thanks,
Ashwini Sharma
/* traceroute - trace the route to host.
 *
 * Copyright 2012 Madhur Verma mad.fl...@gmail.com
 * Copyright 2013 Kyungwan Han asura...@gmail.com
 * Copyright 2013 Bilal Qureshi bilal@gmail.com
 * Copyright 2013 Ashwini Kumar ak.ashw...@gmail.com
 *
 * No Standard

USE_TRACEROUTE(NEWTOY(traceroute, 12i:f#1255=1z#086400=0g*w#086400=5t#0255=0s:q#1255=3p#165535=33434m#1255=30rvndlIUF64, TOYFLAG_STAYROOT|TOYFLAG_USR|TOYFLAG_BIN))
USE_TRACEROUTE(OLDTOY(traceroute6,traceroute, OPTSTR_traceroute, TOYFLAG_STAYROOT|TOYFLAG_USR|TOYFLAG_BIN))
config TRACEROUTE
  bool traceroute
  default y
  help
usage: traceroute [-46FUIldnvr] [-f 1ST_TTL] [-m MAXTTL] [-p PORT] [-q PROBES]
[-s SRC_IP] [-t TOS] [-w WAIT_SEC] [-g GATEWAY] [-i IFACE] [-z PAUSE_MSEC] HOST [BYTES]

traceroute6 [-dnrv] [-m MAXTTL] [-p PORT] [-q PROBES][-s SRC_IP] [-t TOS] [-w WAIT_SEC] 
  [-i IFACE] HOST [BYTES]

Trace the route to HOST

-4,-6 Force IP or IPv6 name resolution 
-FSet the don't fragment bit (supports IPV4 only)
-UUse UDP datagrams instead of ICMP ECHO (supports IPV4 only)
-IUse ICMP ECHO instead of UDP datagrams (supports IPV4 only)
-lDisplay the TTL value of the returned packet (supports IPV4 only)
-dSet SO_DEBUG options to socket
-nPrint numeric addresses
-vverbose
-rBypass routing tables, send directly to HOST
-mMax time-to-live (max number of hops)(RANGE 1 to 255)
-pBase UDP port number used in probes(default 33434)(RANGE 1 to 65535)
-qNumber of probes per TTL (default 3)(RANGE 1 to 255)
-sIP address to use as the source address
-tType-of-service in probe packets (default 0)(RANGE 0 to 255)
-wTime in seconds to wait for a response (default 3)(RANGE 0 to 86400)
-gLoose source route gateway (8 max) (supports IPV4 only)
-zPause Time in milisec (default 0)(RANGE 0 to 86400) (supports IPV4 only)
-fStart from the 1ST_TTL hop (instead from 1)(RANGE 1 to 255) (supports IPV4 only)
-iSpecify a network interface to operate with
*/
#define FOR_traceroute
#include toys.h
#include netinet/udp.h
#include netinet/ip_icmp.h
#include netinet/ip6.h
#include netinet/icmp6.h

GLOBALS(
  long max_ttl;
  long port;
  long ttl_probes;
  char *src_ip;
  long tos;
  long wait_time;
  struct arg_list *loose_source;
  long pause_time;
  long first_ttl;
  char *iface;

  uint32_t gw_list[9];
  int recv_sock;
  int snd_sock;
  unsigned msg_len;
  char *packet;
  uint32_t ident;
  int istraceroute6;
)

#ifndef SOL_IPV6
# define SOL_IPV6 IPPROTO_IPV6
#endif

#define ICMP_HD_SIZE4  8
#define USEC   100ULL

struct payload_s {
  uint32_t seq;
  uint32_t ident;
};

char addr_str[INET6_ADDRSTRLEN];
struct sockaddr_storage dest;

//Compute checksum SUM of buffer P of length LEN
static u_int16_t in_cksum(u_int16_t *p, u_int len)
{
  u_int32_t sum = 0;
  int nwords = len  1;

  while (nwords-- != 0) sum += *p++;
  if (len  1) {
union {
  u_int16_t w;
  u_int8_t c[2];
} u;
u.c[0] = *(u_char *) p;
u.c[1] = 0;
sum += u.w;
  }
  // end-around-carry 
  sum = (sum  16) + (sum  0x);
  sum += (sum  16);
  return (~sum);
}

//sends a single probe packet with sequence(SEQ) and time-to-live(TTL)
static void send_probe4(int seq, int ttl)
{
  int res, len;
  void *out;
  struct payload_s *send_data4 = (struct payload_s *)(TT.packet);
  struct icmp *send_icmp4 = (struct icmp *)(TT.packet);

  if (toys.optflags  FLAG_U) {
send_data4-seq = seq;
send_data4-ident = TT.ident;
((struct sockaddr_in *)dest)-sin_port = TT.port + seq;
out = send_data4;
  } else {
send_icmp4-icmp_type = ICMP_ECHO;
send_icmp4-icmp_id = htons(TT.ident);
send_icmp4-icmp_seq = htons(seq);
send_icmp4-icmp_cksum = 0;
send_icmp4-icmp_cksum = in_cksum((uint16_t *) send_icmp4, TT.msg_len);
if (send_icmp4-icmp_cksum == 0) send_icmp4-icmp_cksum = 0x;
out = send_icmp4;
  }

  res = setsockopt(TT.snd_sock, IPPROTO_IP, IP_TTL, ttl, sizeof(ttl));
  if (res  0) perror_exit(setsockopt ttl %d, ttl);

  len = TT.msg_len;
  res = sendto(TT.snd_sock, out, len, 0, (struct sockaddr *) dest, 
  sizeof(struct sockaddr_in));
  if (res != len) perror_exit( sendto);
}

//sends a single probe packet with sequence(SEQ) and time-to-live(TTL)
static void send_probe6(int seq, int ttl)
{
  void *out;
  struct payload_s *send_data6 = (struct payload_s *) (TT.packet);

  send_data6-seq = seq;
  send_data6-ident = TT.ident;
  ((struct sockaddr_in6 *)dest)-sin6_port = TT.port;

  if (setsockopt(TT.snd_sock, SOL_IPV6, IPV6_UNICAST_HOPS, ttl, 
sizeof(ttl))  0) error_exit(setsockopt ttl %d, ttl);

  out = send_data6;

  if (sendto(TT.snd_sock, out, TT.msg_len, 0

[Toybox] [New Toy] - groupdel

2013-11-25 Thread Ashwini Sharma
Hi Rob, list,

Attached is an implementation for groupdel.

This is aliased to delgroup, for a requirement at my end.
Also lib/password.c is modified to along with.

Have a look at this and give your inputs on the same.

regards,
Ashwini


groupdel.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [Patch] - Traceroute with IPv6 support

2013-11-25 Thread Ashwini Sharma
Thanks Jeroen.

Updating the email id in Copyright.

Thanks,
Ashwini


On Mon, Nov 25, 2013 at 5:24 PM, Ashwini Sharma ak.ashwini1...@gmail.comwrote:

 Hi All,

 IPv6 support is added into traceroute command.
 traceroute6 is made as an old toy of traceroute.

 Attached is the updated file.
 Have a look at the same and let me know for inputs.

 Thanks,
 Ashwini Sharma

/* traceroute - trace the route to host.
 *
 * Copyright 2012 Madhur Verma mad.fl...@gmail.com
 * Copyright 2013 Kyungwan Han asura...@gmail.com
 * Copyright 2013 Bilal Qureshi bilal@gmail.com
 * Copyright 2013 Ashwini Kumar ak.ashwini1...@gmail.com
 *
 * No Standard

USE_TRACEROUTE(NEWTOY(traceroute, 12i:f#1255=1z#086400=0g*w#086400=5t#0255=0s:q#1255=3p#165535=33434m#1255=30rvndlIUF64, TOYFLAG_STAYROOT|TOYFLAG_USR|TOYFLAG_BIN))
USE_TRACEROUTE(OLDTOY(traceroute6,traceroute, OPTSTR_traceroute, TOYFLAG_STAYROOT|TOYFLAG_USR|TOYFLAG_BIN))
config TRACEROUTE
  bool traceroute
  default y
  help
usage: traceroute [-46FUIldnvr] [-f 1ST_TTL] [-m MAXTTL] [-p PORT] [-q PROBES]
[-s SRC_IP] [-t TOS] [-w WAIT_SEC] [-g GATEWAY] [-i IFACE] [-z PAUSE_MSEC] HOST [BYTES]

traceroute6 [-dnrv] [-m MAXTTL] [-p PORT] [-q PROBES][-s SRC_IP] [-t TOS] [-w WAIT_SEC] 
  [-i IFACE] HOST [BYTES]

Trace the route to HOST

-4,-6 Force IP or IPv6 name resolution 
-FSet the don't fragment bit (supports IPV4 only)
-UUse UDP datagrams instead of ICMP ECHO (supports IPV4 only)
-IUse ICMP ECHO instead of UDP datagrams (supports IPV4 only)
-lDisplay the TTL value of the returned packet (supports IPV4 only)
-dSet SO_DEBUG options to socket
-nPrint numeric addresses
-vverbose
-rBypass routing tables, send directly to HOST
-mMax time-to-live (max number of hops)(RANGE 1 to 255)
-pBase UDP port number used in probes(default 33434)(RANGE 1 to 65535)
-qNumber of probes per TTL (default 3)(RANGE 1 to 255)
-sIP address to use as the source address
-tType-of-service in probe packets (default 0)(RANGE 0 to 255)
-wTime in seconds to wait for a response (default 3)(RANGE 0 to 86400)
-gLoose source route gateway (8 max) (supports IPV4 only)
-zPause Time in milisec (default 0)(RANGE 0 to 86400) (supports IPV4 only)
-fStart from the 1ST_TTL hop (instead from 1)(RANGE 1 to 255) (supports IPV4 only)
-iSpecify a network interface to operate with
*/
#define FOR_traceroute
#include toys.h
#include netinet/udp.h
#include netinet/ip_icmp.h
#include netinet/ip6.h
#include netinet/icmp6.h

GLOBALS(
  long max_ttl;
  long port;
  long ttl_probes;
  char *src_ip;
  long tos;
  long wait_time;
  struct arg_list *loose_source;
  long pause_time;
  long first_ttl;
  char *iface;

  uint32_t gw_list[9];
  int recv_sock;
  int snd_sock;
  unsigned msg_len;
  char *packet;
  uint32_t ident;
  int istraceroute6;
)

#ifndef SOL_IPV6
# define SOL_IPV6 IPPROTO_IPV6
#endif

#define ICMP_HD_SIZE4  8
#define USEC   100ULL

struct payload_s {
  uint32_t seq;
  uint32_t ident;
};

char addr_str[INET6_ADDRSTRLEN];
struct sockaddr_storage dest;

//Compute checksum SUM of buffer P of length LEN
static u_int16_t in_cksum(u_int16_t *p, u_int len)
{
  u_int32_t sum = 0;
  int nwords = len  1;

  while (nwords-- != 0) sum += *p++;
  if (len  1) {
union {
  u_int16_t w;
  u_int8_t c[2];
} u;
u.c[0] = *(u_char *) p;
u.c[1] = 0;
sum += u.w;
  }
  // end-around-carry 
  sum = (sum  16) + (sum  0x);
  sum += (sum  16);
  return (~sum);
}

//sends a single probe packet with sequence(SEQ) and time-to-live(TTL)
static void send_probe4(int seq, int ttl)
{
  int res, len;
  void *out;
  struct payload_s *send_data4 = (struct payload_s *)(TT.packet);
  struct icmp *send_icmp4 = (struct icmp *)(TT.packet);

  if (toys.optflags  FLAG_U) {
send_data4-seq = seq;
send_data4-ident = TT.ident;
((struct sockaddr_in *)dest)-sin_port = TT.port + seq;
out = send_data4;
  } else {
send_icmp4-icmp_type = ICMP_ECHO;
send_icmp4-icmp_id = htons(TT.ident);
send_icmp4-icmp_seq = htons(seq);
send_icmp4-icmp_cksum = 0;
send_icmp4-icmp_cksum = in_cksum((uint16_t *) send_icmp4, TT.msg_len);
if (send_icmp4-icmp_cksum == 0) send_icmp4-icmp_cksum = 0x;
out = send_icmp4;
  }

  res = setsockopt(TT.snd_sock, IPPROTO_IP, IP_TTL, ttl, sizeof(ttl));
  if (res  0) perror_exit(setsockopt ttl %d, ttl);

  len = TT.msg_len;
  res = sendto(TT.snd_sock, out, len, 0, (struct sockaddr *) dest, 
  sizeof(struct sockaddr_in));
  if (res != len) perror_exit( sendto);
}

//sends a single probe packet with sequence(SEQ) and time-to-live(TTL)
static void send_probe6(int seq, int ttl)
{
  void *out;
  struct payload_s *send_data6 = (struct payload_s *) (TT.packet);

  send_data6-seq = seq;
  send_data6-ident = TT.ident;
  ((struct sockaddr_in6 *)dest)-sin6_port = TT.port;

  if (setsockopt(TT.snd_sock, SOL_IPV6

[Toybox] [patch] - add '-v' for ln and mkdir

2013-11-22 Thread Ashwini Sharma
Hi Rob, list,

  I know _-v_ option is not mentioned in the posix specs for
_ln_ and _mkdir_ commands.

I had an use case for these options at my end, so modified _ln.c_
and _mkdir.c_ to have them. Would you mind adding these to the tree.

Attached are the patches for _ln_ and _mkdir_.

regards,
Ashwini Sharma


ln.c.patch
Description: Binary data


mkdir.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [Patch] - killall fixed, -l requiring argument and added -s SIGNAL

2013-11-22 Thread Ashwini Sharma
Hi Rob, list,

 killall implementation had a requirement to pass an argument
even if user wanted to list the signals using _ -l _ option.

Modified the code to not require argument for _ -l _ option.

Also added the support for killall to accept _ -s SIGNAL _ option
on the lines of _kill_ command, also I had the use case for using
 killall -s SIGNAL pid 

Attached is the patch for killall. Any inputs are welcome.

If it goes fine with you, add it to the tree.

regards,
Ashwini


killall.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [Patch] - ifconfig, fixes for IPv6 and SEGFAULT

2013-11-22 Thread Ashwini Sharma
Hi Rob, list,

I knwo its too many mails in one day, but thats due to malfunctioned
mail I had.

Attacehd is the patch for ifconfig.c, fixing issues

1. show_help(), only prints help and continues the execution.
ifconfig had a SEGFAULT due to this very thing. Modified the
the ifconfig_main() to return after showing help for ifconfig.

2. In __ display_ifconfig() _ there was typo, corrected the filename to
/proc/net/if_inet6.

3. in __ show_iface() _ data was read into toybuf. after this _name_
pointed inside the toybuf.  This function passed name to __
display_ifconfig() _
function, which again used the toybuf to read data into. Hence
corrupting the
_name_. Fixed this by making a copy of name and then freeing it after use.

Your inputs are welcome.

regards,
Ashwini Sharma


ifconfig.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] Issue with names_to_pid(), pidof, killall

2013-11-21 Thread Ashwini Sharma
Hi All,

Due to some issue with my email account, changing my email to
ak.ashwini1...@gmail.com

I came across a bug in pidof command. The issue is
with _-o_ option. callback function returns _1_ for omit
list, to names_to_pid().

names_to_pid(), breaks the internal _for_ loop, at the same
time it also breaks out of the _while(readdir())_ loop.
Which is causing the issue, as other pids are not searched for.

for (curname = names; *curname; curname++)
  if (**curname == '/' ? !strcmp(cmd, *curname)
  : !strcmp(basename(cmd), basename(*curname)))
if (callback(u, *curname)) break;
-if (*curname) break;
}

Why break from _while_ loop, as there can be other processes in the list
waiting for actioin.
removing this fixes the issue.

_names_to_pid()_ is also used by _killall_. killall also has issues,

1. the exit status is always  0, thats because of toys.exitval++
in _main() function. Exit status need to be corrected.
2. No error/warning message is displayed for a non-exiting process.
as is one by GNU implementation. instead due to the _toys.exitval++_
its always printing __ No such process __ without any process name.

In order not to modify the lib function _names_to_pid_ too much, these
killall
issues could be fixed from callback function _kill_process()_.

For printing the warning message for non existent processes, can have a map
for the processes which are signalled thru _kill_process_ and finally once
_names_to_pid_ returns, print the message for non-signalled processes.

Like to have your opinion.

regards,
Ashwini Sharma
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] FTP commands

2013-11-11 Thread Ashwini Sharma
Hi All,

Yes i am having a version of ftpget/put and telnetd (not mature enough yet).
Sometime soon i will be sending it on this list for review/submission.

Thanks,
Ashwini
On Nov 6, 2013 9:36 AM, ibid...@gmail.com wrote:

 On Fri, Oct 18, 2013 at 01:05:50AM +0200, Bertold Van den Bergh wrote:
  Hello,
 
  Is anyone working on ftpget and ftpput? I will likely be able to
 contribute
  these around the start of next month.

 Not that I know of.  If anyone is, it would be Ashwini Sharma; but he
 seems to be working on a different set of commands at the moment.

 
  Maybe I can also provide ftpd and telnetd but this is less certain.
 
  Can commands be accepted that are not on the roadmap? I will certainly
 need
  'ntpdate' which for embedded systems is better than a full blown ntpd.

 That would be a question for Rob.

 That said, I'd be in favor of it. Having *not* examined NTP in detail,
 I get the impression that it might be possible to have ntpd and ntpdate
 share much of their code.

 And I'm guessing that ntpd should be SNTP.


  Sincerely,
  Bertold Van den Bergh

 Thanks,
 Isaac Dunham
 ___
 Toybox mailing list
 Toybox@lists.landley.net
 http://lists.landley.net/listinfo.cgi/toybox-landley.net

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] - Add DD

2013-11-01 Thread Ashwini Sharma
Hi Rob,

In du.c the human readable string for the size was printed in place. To
make a common function
for both du and dd, I compiled this into pending.c. To return the reabable
string
static char[] is used. This could be done with xmalloc and free, but that
will require the user
of function to keep track of the returned pointer and free it.

Other approach could have been to accept and char buffer as _out_ parameter
for holding the string.

your inputs are welcome.

regards,
Ashwini

On Tue, Oct 29, 2013 at 6:32 AM, Rob Landley r...@landley.net wrote:

 This one was deferred due to the common infrastructure changes. Applying
 it also modified a previously done command to use a lib/pending.c
 function, and a quick glance at that new function showed it adding a new
 static/global variable after I finally got rid of the itoa/utoa one. (I
 also need a lib/pending.h to go with lib/pending.c.)

 I appreciate the heads up and I'll try to carve out some time this week to
 at least catch up on the pending merges. (The time I've had recently went
 to build infrastructure fixes, cleaning up nl, and reading about 6000 of my
 16,000 back emails. I'm less than 10,000 emails behind now! Woo!)

 Rob


 On 10/16/2013 01:09:29 AM, Ashwini Sharma wrote:

 Hi Rob,
 incase you missed this mail, just to bring it on the top of ur list.

 regards,
 Ashwini
 On Tue, Sep 3, 2013 at 2:53 PM, Ashwini Sharma ak.ashw...@gmail.com
 wrote:

  Hi Rob,
 
  Attached is the patch for DD.
 
  I have also modified _du.c_, _pending.c_ and _lib.h_ to make a common
  function for converting _size_ into human readable string.
 
  Like to hear from you.
 
  regards,
  Ashwini
 


 --quoted attachment--

 __**_
 Toybox mailing list
 Toybox@lists.landley.net
 http://lists.landley.net/**listinfo.cgi/toybox-landley.**nethttp://lists.landley.net/listinfo.cgi/toybox-landley.net



___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [New Toy] - Add tftpd

2013-10-24 Thread Ashwini Sharma
Hi Rob, All,

Attached is the TFTPD implementation.
Add it to hg, if you find it fine.

Let me know for any comments/improvements.

-Ashwini
/* tftpd.c - TFTP server.
 *
 * Copyright 2013 Ranjan Kumar ranjankumar@gmail.com
 * Copyright 2013 Kyungwan Han asura...@gmail.com
 *
 * No Standard.

USE_TFTPD(NEWTOY(tftpd, rcu:, TOYFLAG_BIN))

config TFTPD
  bool tftpd
  default y
  help
usage: tftpd [-cr] [-u USER] [DIR]

Transfer file from/to tftp server.

-r	Prohibit upload
-c	Allow file creation via upload
-u	Access files as USER
*/
#define FOR_tftpd
#include toys.h
#include toynet.h

GLOBALS(
  char *user;
  long sfd;
  struct passwd *pw;
)

#define TFTPD_BLKSIZE 512  // as per RFC 1350.

// opcodes
#define TFTPD_OP_RRQ  1  // Read Request  RFC 1350, RFC 2090
#define TFTPD_OP_WRQ  2  // Write Request RFC 1350
#define TFTPD_OP_DATA 3  // Data chunkRFC 1350
#define TFTPD_OP_ACK  4  // Acknowledgement   RFC 1350
#define TFTPD_OP_ERR  5  // Error Message RFC 1350
#define TFTPD_OP_OACK 6  // Option acknowledgment RFC 2347

// Error Codes:
#define TFTPD_ER_NOSUCHFILE  1 // File not found
#define TFTPD_ER_ACCESS  2 // Access violation
#define TFTPD_ER_FULL3 // Disk full or allocation exceeded
#define TFTPD_ER_ILLEGALOP   4 // Illegal TFTP operation
#define TFTPD_ER_UNKID   5 // Unknown transfer ID
#define TFTPD_ER_EXISTS  6 // File already exists
#define TFTPD_ER_UNKUSER 7 // No such user
#define TFTPD_ER_NEGOTIATE   8 // Terminate transfer due to option negotiation

/* TFTP Packet Formats
 *  Type   Op # Format without header
 * 2 bytesstring1 bytestring1 byte
 * ---
 *  RRQ/  | 01/02 |  Filename  |   0  |Mode|   0  |
 *  WRQ---
 * 2 bytes2 bytes  n bytes
 * -
 *  DATA  | 03|   Block #  |Data|
 * -
 * 2 bytes2 bytes
 * ---
 *  ACK   | 04|   Block #  |
 * 
 * 2 bytes  2 bytes   string 1 byte
 * 
 *  ERROR | 05|  ErrorCode |   ErrMsg   |   0  |
 * 
 */

static char g_buff[TFTPD_BLKSIZE];
static char g_errpkt[TFTPD_BLKSIZE];

static void bind_and_connect(struct sockaddr *srcaddr,
struct sockaddr *dstaddr, socklen_t socklen)
{
  int set = 1;

  TT.sfd = xsocket(dstaddr-sa_family, SOCK_DGRAM, 0);
  if (setsockopt(TT.sfd, SOL_SOCKET, SO_REUSEADDR, (const void *)set,
sizeof(set))  0) perror_exit(setsockopt failed);
  if (bind(TT.sfd, srcaddr, socklen)) perror_exit(bind);
  if (connect(TT.sfd, dstaddr, socklen)  0)
perror_exit(can't connect to remote host);
}

// Create and send error packet.
static void send_errpkt(struct sockaddr *dstaddr,
socklen_t socklen, char *errmsg)
{
  error_msg(errmsg);
  g_errpkt[1] = TFTPD_OP_ERR;
  strcpy(g_errpkt + 4, errmsg);
  if (sendto(TT.sfd, g_errpkt, strlen(errmsg)+5, 0, dstaddr, socklen)  0)
perror_exit(sendto failed);
}

// Used to send / receive packets.
static void do_action(struct sockaddr *srcaddr, struct sockaddr *dstaddr,
socklen_t socklen, char *file, int opcode, int tsize, int blksize)
{
  int fd, done = 0, retry_count = 12, timeout = 100, len;
  uint16_t blockno = 1, pktopcode, rblockno;
  char *ptr, *spkt, *rpkt;
  struct pollfd pollfds[1];

  spkt = xzalloc(blksize + 4);
  rpkt = xzalloc(blksize + 4);
  ptr = spkt+2; //point after opcode.

  pollfds[0].fd = TT.sfd;
  // initialize groups, setgid and setuid
  if (TT.pw) {
if (change_identity(TT.pw)) perror_exit(Failed to change identity);
endgrent();
  }

  if (opcode == TFTPD_OP_RRQ) fd = open(file, O_RDONLY, 0666);
  else fd = open(file, ((toys.optflags  FLAG_c) ?
(O_WRONLY|O_TRUNC|O_CREAT) : (O_WRONLY|O_TRUNC)) , 0666);
  if (fd  0) {
g_errpkt[3] = TFTPD_ER_NOSUCHFILE;
send_errpkt(dstaddr, socklen, can't open file);
goto CLEAN_APP;
  }
  // For download - blockno will be 1.
  // 1st ACK will be from dst,which will have blockno-=1
  // Create and send ACK packet.
  if (blksize != TFTPD_BLKSIZE || tsize) {
pktopcode = TFTPD_OP_OACK;
// add blksize\000blksize_val\000 in send buffer.
if (blksize != TFTPD_BLKSIZE) {
  strcpy(ptr, blksize);
  ptr += strlen(blksize) + 1;
  ptr += snprintf(ptr, 6, %d, blksize) + 1;
}
if (tsize) {// add tsize\000tsize_val\000 in send buffer.
  struct stat sb;

  sb.st_size = 0;
  fstat(fd, sb);
  strcpy(ptr, tsize);
  ptr += strlen(tsize) + 1;
  ptr += sprintf(ptr, %lu, (unsigned long)sb.st_size)+1;
}
goto SEND_PKT;
  }
  // upload -  ACK 1st packet with filename, as it has blockno 0.
  if (opcode == TFTPD_OP_WRQ) blockno = 0;

  // Prepare DATA and/or ACK pkt and send 

Re: [Toybox] - Add DD

2013-10-16 Thread Ashwini Sharma
Hi Rob,
incase you missed this mail, just to bring it on the top of ur list.

regards,
Ashwini
On Tue, Sep 3, 2013 at 2:53 PM, Ashwini Sharma ak.ashw...@gmail.com wrote:

 Hi Rob,

 Attached is the patch for DD.

 I have also modified _du.c_, _pending.c_ and _lib.h_ to make a common
 function for converting _size_ into human readable string.

 Like to hear from you.

 regards,
 Ashwini

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [New Toys] - groupadd, useradd, mkpasswd and modified passwd, lib/password

2013-10-16 Thread Ashwini Sharma
On Thu, Oct 17, 2013 at 6:46 AM, Rob Landley r...@landley.net wrote:

 On 10/02/2013 03:49:21 AM, Ashwini Sharma wrote:

 Hi list,

 Attached are the implementations for groupadd, useradd and mkpasswd
 commands.


 Ok, I've caught up to this...


  Patches are as follows

 1. __lib.patch__  : this includes changes made to lib/lib.h and
 __lib/password.c__.
 lib/passowrd.c is modified to share the function __update_password()__
 among groupadd, useradd commands.
 This also has the factored out code, common to both, for __passwd__ and
 __mkpasswd__.
 Also has the cosmetic cleanup changes.


 Alas, lib/password.c is one of the pieces that would be in pending if
 login.c didn't predate it. I never got this properly cleaned up. Still,
 adding this doesn't change that, so... first patch applied, and lemme at
 least look at the new bits.

 We add three #defines to the header, which are never used. They should be
 in the patch that actually uses them. (MAX_SALT_LEN of 20 is wrong, the
 largest actual salt is 16, that's the buffer size needed to process...
 something. Right...)


20 is broken into 16 bytes for salt, 3 for $#$, 1 for _nul_ termination of
string.



 The first function in there, random_number_generator(), just reads an int
 from a filehandle. It's only ever called from one place, and that caller is
 what opens and closes /dev/urandom, so having the read in the same place
 doesn't add any new portability constraints. (I.E. let's just inline this
 function at its only callsite.)

 The return value is fed into inttoc(), which is also the only caller of
 that function. inttoc() discards all but 10 bits of it, so we read 32 bits
 of entropy, and discard 21 of those bits? Not idea on devices with limited
 entropy.

 Um, hang on:

   i = 0x3f; // masking for using 10 bits only

 You can't use 10 bits out of an 8 bit byte. And 0x3f is 0011 which is
 6 bits. So the comment is both impossible and wrong.



 Let's see, max salt is actually 16, times 6 is 96 bits which is an even 12
 bytes, so we can read in a buffer of that... this logic is largely the same
 as uuencode by the way.

 All the users are in get_salt(), which is a strange function. Each
 algorithm has a unique digit indicated in the $#$ signature in the hash,
 but we don't use that digit to indicate the algorithm, instead we pass in a
 string which we check and then _set_ the digit. Why do we do that? If it
 was an int we could just use an array to set the salt length. Also, the
 function has an error return value for matching none of the strings, but
 didn't we pass _in_ that string? Not sure of the design goal here, who is
 currently calling this...


Algorithm to be used can be given at command line,  which is verified in
get_salt(). That's why an error return is there at end.



 Um, there's a second copy in toys/lsb/passwd.c...? Ah, I see, the second
 patch in the series removes the function. so it's a move spread across two
 patches. Lemme redo that checkin to do both halves...

 (Sigh. My bad. If I don't clean up code, people extend the non-cleaned-up
 code...)

 I need to set up a test environment for this. Ok, I've inlined
 random_number_generator() and inttoc() and it compiles, but I can't test
 it. I'll check it in anyway and try to come up with a test chroot...

  +  // Grab 6 bit chunks and convert to characters in ./0-9a-zA-Z +  for 
 (i=0; ilen; i++) { +int bitpos = i*6, bits = bitpos/8; + +bits = 
 ((buf[i]+(buf[i+1]8))  (bitpos7))  0x3f; +bits += 46; +if (bits 
  57) bits += 8; +if (bits  90) bits += 7; + +salt[i] = bits; +  }

In this snippet, bits is added with 8 or 7 when it is 57 or 90,
doing this makes it jump to 66 or 98 respectively.

which leaves _A_ or _a_, instead this can be

+if (bits  57) bits += 7;  To jump to _A_+if (bits  90) bits
+= 6;  To jump to _a_


  2. __passwd.c.patch__ : this file is modified due to the common code
 factoring out and cosmetic cleanup changes.


 I checked in this and the previous patch together as one logical unit,
 because it's moving code from one file to another and the result doesn't
 make sense without both of them.

 Rob


Ashwini
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [New Toys] - groupadd, useradd, mkpasswd and modified passwd, lib/password

2013-10-02 Thread Ashwini Sharma
Hi list,

Attached are the implementations for groupadd, useradd and mkpasswd
commands.

Patches are as follows

1. __lib.patch__  : this includes changes made to lib/lib.h and
__lib/password.c__.
lib/passowrd.c is modified to share the function __update_password()__
among groupadd, useradd commands.
This also has the factored out code, common to both, for __passwd__ and
__mkpasswd__.
Also has the cosmetic cleanup changes.

2. __passwd.c.patch__ : this file is modified due to the common code
factoring out and cosmetic cleanup changes.

3. groupadd and useradd has alias for addgroup and adduser, due to the
requirement constraint at my end.
_adduser_ does invoke the passwd utility to set the user password on
creation.

Looking forward to your comments. Add to the tree if it can be.

regards,
Ashwini


lib.patch
Description: Binary data


passwd.c.patch
Description: Binary data
/* groupadd.c - create a new group
 *
 * Copyright 2013 Ashwini Kumar ak.ashw...@gmail.com
 * Copyright 2013 Kyungwan Han asura...@gmail.com
 *
 * See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/groupadd.html

USE_GROUPADD(NEWTOY(groupadd, 12g#0S, TOYFLAG_NEEDROOT|TOYFLAG_SBIN))
USE_GROUPADD(OLDTOY(addgroup, groupadd, OPTSTR_groupadd, TOYFLAG_NEEDROOT|TOYFLAG_SBIN))

config GROUPADD
  bool groupadd
  default y
  help
usage: groupadd [-S] [-g GID] [USER] GROUP

Add a group or add a user to a group

  -g GID Group id
  -S Create a system group
*/

#define FOR_groupadd
#include toys.h

#define GROUP_PATH/etc/group
#define SECURE_GROUP_PATH /etc/gshadow

GLOBALS(
  long gid;
)

/* Add a new group to the system, if GID is given then that is validated
 * to be free, else a free GID is choosen by self.
 * SYSTEM IDs are considered in the range 100 ... 999
 * update_group(), updates the entries in /etc/group, /etc/gshadow files
 */
static void new_group()
{
  char *entry = NULL;
  int max = INT_MAX;

  if (toys.optflags  FLAG_g) {
if (TT.gid  INT_MAX) error_exit(gid should be less than  '%d' , INT_MAX);
if (getgrgid(TT.gid)) error_exit(group '%ld' is in use, TT.gid);
  } else {
if (toys.optflags  FLAG_S) {
  TT.gid = SYS_FIRST_ID;
  max = SYS_LAST_ID;
} else {
  TT.gid = SYS_LAST_ID + 1; //i.e. starting from 1000
  max = 6; // as per config file on Linux desktop
}
//find unused gid
while (TT.gid = max) {
  if (!getgrgid(TT.gid)) break;
  if (TT.gid == max) error_exit(no more free gids left);
  TT.gid++;
}
  }

  entry = xmsprintf(%s:%s:%d:, *toys.optargs, x, TT.gid);
  update_password(GROUP_PATH, *toys.optargs, entry);
  free(entry);
  entry = xmsprintf(%s:%s::, *toys.optargs, !);
  update_password(SECURE_GROUP_PATH, *toys.optargs, entry);
  free(entry);
}

void groupadd_main(void)
{
  struct group *grp = NULL;
  char *entry = NULL;

  if (toys.optflags  toys.optc == 2) {
toys.exithelp = 1;
error_exit(options, user and group can't be together);
  }

  if (toys.optc == 2) {  //add user to group
//toys.optargs[0]- user, toys.optargs[1] - group
if (!getpwnam(toys.optargs[0])) 
  error_exit(user '%s' does not exist, toys.optargs[0]);
if (!(grp = getgrnam(toys.optargs[1]))) 
  error_exit(group '%s' does not exist, toys.optargs[1]);
if (!grp-gr_mem) entry = xmsprintf(%s, *toys.optargs);
else {
  int i;

  for (i = 0; grp-gr_mem[i]; i++)
if (!strcmp(grp-gr_mem[i], *toys.optargs)) return;

  entry = xstrdup();
  for (i=0; grp-gr_mem[i]; i++) {
entry = xrealloc(entry, strlen(entry) + strlen(grp-gr_mem[i]) + 2);
strcat(entry, grp-gr_mem[i]);
strcat(entry, ,);
  }
  entry = xrealloc(entry, strlen(entry) + strlen(*toys.optargs) + 1);
  strcat(entry, *toys.optargs);
}
update_password(GROUP_PATH, grp-gr_name, entry);
update_password(SECURE_GROUP_PATH, grp-gr_name, entry);
free(entry);
  } else {//new group to be created
/* investigate the group to be created */
if ((grp = getgrnam(*toys.optargs))) 
  error_exit(group '%s' is in use, *toys.optargs);
setlocale(LC_ALL, C);
is_valid_username(*toys.optargs);
new_group();
  }
}
/* useradd.c - add a new user
 *
 * Copyright 2013 Ashwini Kumar ak.ashw...@gmail.com
 * Copyright 2013 Kyungwan Han asura...@gmail.com
 *
 * See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/useradd.html

USE_USERADD(NEWTOY(useradd, 12u#0G:s:g:h:SDH, TOYFLAG_NEEDROOT|TOYFLAG_SBIN))
USE_USERADD(OLDTOY(adduser, useradd, OPTSTR_useradd, TOYFLAG_NEEDROOT|TOYFLAG_SBIN))

config USERADD
  bool useradd
  default y
  help
usage: useradd [-SDH] [-hDIR] [-sSHELL] [-G GRP] [-gGECOS] [-uUID] USER [GROUP]

Create new user, or add USER to GROUP

-h DIR   Home directory
-g GECOS GECOS field
-s SHELL Login shell
-G GRP   Add user to existing group
-S   Create a system user
-D   Don't assign a password

[Toybox] [New toy] - top

2013-09-27 Thread Ashwini Sharma
Hi Rob, list,

Attached is the top command implementation.

'-m' option supported is for displaying memory details. This is purely
based on the requirement at hand.

Have a look at the implementation and pass on your comments.

regards,
Ashwini
/* top.c - Provide a view of process activity in real time.
 *
 * Copyright 2013 Bilal Qureshi bilal@gmail.com
 * Copyright 2013 Ashwini Kumar ak.ashw...@gmail.com
 * Copyright 2013 Kyungwan Han asura...@gmail.com
 *
 * No Standard

USE_TOP(NEWTOY(top, 0d#=3n#1mb, TOYFLAG_USR|TOYFLAG_BIN))

config TOP
  bool top
  default y
  help

Usage: top [-mb] [ -d seconds ] [ -n iterations ]

Provide a view of process activity in real time.
Keys
   N/M/P/T show CPU usage, sort by pid/mem/cpu/time
   S   show memory
   R   reverse sort
   H   toggle threads
   C,1 toggle SMP
   Q,^Cexit

Options
   -n Iterations before exiting
   -d Delay between updates
   -m Same as 's' key
   -b Batch mode
*/

#define FOR_top
#include toys.h
#include signal.h
#include poll.h

GLOBALS(
  long iterations;
  long delay;

  long cmp_field;
  long reverse;
  long rows;
  long smp;
  long threads;
  long m_flag;
  long num_new_procs;
  long scroll_offset;
  struct termios inf;
)

#define PROC_NAME_LEN 512 //For long cmdline.
#define INIT_PROCS 50

struct cpu_info {
  long unsigned utime, ntime, stime, itime;
  long unsigned iowtime, irqtime, sirqtime, steal;
  unsigned long long total;
};

enum CODE{
  KEY_UP = 0x100, KEY_DOWN, KEY_HOME,
  KEY_END, KEY_PAGEUP, KEY_PAGEDN,
};

struct keycode_map_s {
  char *key;
  int code;
};

struct proc_info {
  struct proc_info *next;
  pid_t pid, ppid;
  uid_t uid;
  char name[PROC_NAME_LEN];
  char tname[PROC_NAME_LEN];
  char state[4];
  int prs;
  unsigned long utime, stime, delta_utime, delta_stime, delta_time;
  unsigned long vss, vssrw, rss, rss_shr, drt, drt_shr, stack;
};

static struct proc_info *free_procs, **old_procs, **new_procs;
static struct cpu_info old_cpu[10], new_cpu[10]; //1 total, 8 cores, 1 null
static int (*proc_cmp)(const void *a, const void *b);

static struct proc_info *find_old_proc(pid_t pid) 
{
  int i;

  for (i = 0; old_procs  old_procs[i]; i++)
if (old_procs[i]-pid == pid) return old_procs[i];

  return NULL;
}

static void read_stat(char *filename, struct proc_info *proc) 
{
  int nice;
  FILE *file;
  char *open_paren, *close_paren;

  if (!(file = fopen(filename, r))) return;
  fgets(toybuf, sizeof(toybuf), file);
  fclose(file);

  // Split at first '(' and last ')' to get process name.
  open_paren = strchr(toybuf, '(');
  close_paren = strrchr(toybuf, ')');
  if (!open_paren || !close_paren) return;

  *open_paren = *close_paren = '\0';
  snprintf(proc-tname, PROC_NAME_LEN, [%s],open_paren + 1);

  // Scan rest of string.
  sscanf(close_paren + 1,  %c %d %*d %*d %*d %*d %*d %*d %*d %*d %*d 
  %lu %lu %*d %*d %*d %d %*d %*d %*d %lu %ld 
  %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %d,
  proc-state[0], proc-ppid, proc-utime, proc-stime, nice, 
  proc-vss, proc-rss, proc-prs);
  if (!proc-vss  proc-state[0] != 'Z') proc-state[1] = 'W';
  else proc-state[1] = ' ';
  if (nice  0 ) proc-state[2] = '';
  else if (nice) proc-state[2] = 'N';
  else proc-state[2] = ' ';
}

static void read_status(char *filename, struct proc_info *proc) 
{
  FILE *file;

  if (!(file = fopen(filename, r))) return;
  while (fgets(toybuf, sizeof(toybuf), file)) 
if (sscanf(toybuf, Uid: %u, (proc-uid)) == 1) break;

  fclose(file);
}

static void read_cmdline(char *filename, struct proc_info *proc) 
{
  int fd, len, rbytes = 0;
  char *ch, *base, tname[PROC_NAME_LEN];

  if ((fd = open(filename, O_RDONLY)) == -1) return;
  rbytes = readall(fd, toybuf, sizeof(toybuf));
  close(fd);
  if (rbytes = 0) {
strcpy(proc-name, proc-tname);
return;
  }
  toybuf[rbytes] = '\0';
  while (--rbytes = 0  toybuf[rbytes] == '\0') continue;

  snprintf(tname, PROC_NAME_LEN, %s, proc-tname+1);
  tname[strlen(tname) - 1] = '\0';
  ch = strchr(toybuf, ' ');
  if (ch) *ch = '\0';
  base = strrchr(toybuf, '/');
  if (base) base++;
  else base = toybuf;

  for (; rbytes = 0; rbytes--)
if ((unsigned char)toybuf[rbytes]  ' ') toybuf[rbytes] = ' ';

  if (*base == '-') base++;
  len = strlen(tname);
  if (strncmp(base, tname, len)) {
len +=3; //{,}, \0
rbytes = strlen(toybuf);
memmove(toybuf+ len, toybuf, rbytes+1);
snprintf(toybuf, sizeof(toybuf), {%s}, tname);
toybuf[len-1] = ' ';
  } 
  snprintf(proc-name, PROC_NAME_LEN, %s, toybuf);
}

static void add_proc(int proc_num, struct proc_info *proc) 
{
  int i;

  if (proc_num = TT.num_new_procs-1) {
new_procs = xrealloc(new_procs, (INIT_PROCS + TT.num_new_procs) 
* sizeof(struct proc_info *));
for (i = TT.num_new_procs; i  (INIT_PROCS +  TT.num_new_procs); i++)
  new_procs[i] = NULL;
TT.num_new_procs += INIT_PROCS;
  }
  new_procs[proc_num] = proc;
}

void 

Re: [Toybox] [Patch - New Toy] Add traceroute

2013-09-15 Thread Ashwini Sharma
On Sun, Sep 15, 2013 at 1:24 PM, Isaac ibid...@gmail.com wrote:

 On Sun, Sep 15, 2013 at 11:59:42AM +0900, Ashwini Sharma wrote:
  On Fri, Sep 13, 2013 at 11:31 PM, Isaac ibid...@gmail.com wrote:
   I note that it appears to revert one of the recent changes to
   lib/pending.c.
  
   (Would you mind sending new toys as just the *.c file that goes in
 toys/*/
   when it doesn't need to touch lib/?)

  my patch on lib/pending.c is only modifying  get_int_value() function.
  Checking '-' and leading white spaces in the string.
 
  I changed this
  -  if (errno || numstr == ptr || *ptr || rvalue  lowrange || rvalue 
  highrange)
  -perror_exit(bad number '%s', numstr);
 
  to
 
  +  if(errno || *ptr) perror_exit(invalid number '%s', numstr);
  +  if(rvalue  lowrange || rvalue  highrange)
  +error_exit(out of range '%s', numstr);
 
  for having a better error message.
 

 See this patch in commit 1066 (manually munged to indicate intent...):

unsigned long rvalue = 0;
char *ptr;
 -  if(*numstr == '-' || *numstr == '+' || isspace(*numstr))
 perror_exit(invalid number '%s', numstr);
 +
 +  if (!isdigit(*numstr)) perror_exit(bad number '%s', numstr);
errno = 0;
rvalue = strtoul(numstr, ptr, 10);
 -  if(errno || numstr == ptr) perror_exit(invalid number '%s', numstr);
 -   if(*ptr) perror_exit(invalid number '%s', numstr);
 -   if(rvalue = lowrange  rvalue = highrange) return rvalue;
 -   else {
 - perror_exit(invalid number '%s', numstr);
 - return rvalue; //Not reachable; to avoid waring message.
 -   }
 +  if (errno || numstr == ptr || *ptr || rvalue  lowrange || rvalue 
 highrange)
 +perror_exit(bad number '%s', numstr);
 +  return rvalue;
  }


Aah!! when I generated patch, these chages were not reflecting in hg.
Better not to apply my lib/pending.c patch



 Rob's mentioned a few times that simpler messages are preferred;
 http://landley.net/toybox/cleanup.html refers to this message:

 http://lists.landley.net/pipermail/toybox-landley.net/2013-April/000850.html

 And that's part of the rationale listed in the change.

 (however, I don't see how get_int_value can handle negative numbers;
 rvalue and lowrange are unsigned longs...)

 If I were the one doing it, I might use bad number and not in range,
 or maybe even for the latter (if it works! Haven't tested)
 perror_exit('%s' too '%s', numstr, rvalue  lowrange ? low : high);
 But that last might be a little more clever and less clear...
 In general, s/invalid/bad/.

  IPv6 is in fact important. Working on it, but was confused whether to
 have
  the IPv6 support
  in the same traceroute.c or separate. As far as I see, there will be lot
  many if/else checks for IPv4/IPv6 cases.
  Like for the incoming packet parsing.

 Same file. A separate IPv6 command is not desireable (Rob recenty
 mentioned this somewhere--I think in the discussion of Strake's
 mount or sed), though I could see a name6 OLDTOY() for those who
 are accustomed to the two binaries...

  Any suggestions are welcome.
 
  regards,
  Ashwini

 Thanks,
 Isaac Dunham

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [Patch - New Toy] Add traceroute

2013-09-14 Thread Ashwini Sharma
my patch on lib/pending.c is only modifying  get_int_value() function.
Checking '-' and leading white spaces in the string.

I changed this
-  if (errno || numstr == ptr || *ptr || rvalue  lowrange || rvalue 
highrange)
-perror_exit(bad number '%s', numstr);

to

+  if(errno || *ptr) perror_exit(invalid number '%s', numstr);
+  if(rvalue  lowrange || rvalue  highrange)
+error_exit(out of range '%s', numstr);

for having a better error message.

IPv6 is in fact important. Working on it, but was confused whether to have
the IPv6 support
in the same traceroute.c or separate. As far as I see, there will be lot
many if/else checks for IPv4/IPv6 cases.
Like for the incoming packet parsing.

Any suggestions are welcome.

regards,
Ashwini




On Fri, Sep 13, 2013 at 11:31 PM, Isaac ibid...@gmail.com wrote:

 On Fri, Sep 13, 2013 at 03:10:24PM +0900, Ashwini Sharma wrote:
  Hi All,
 
  Attached is the traceroute patch.
 
  This supports IPv4 destination trace.
 
  Have a look at the same and pass on your comments.

 I note that it appears to revert one of the recent changes to
 lib/pending.c.

 (Would you mind sending new toys as just the *.c file that goes in toys/*/
 when it doesn't need to touch lib/?)

 Also, isn't IPv6 rather important these days?

 Thanks,
 Isaac Dunham

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [Patch - New Toy] Add traceroute

2013-09-13 Thread Ashwini Sharma
Hi All,

Attached is the traceroute patch.

This supports IPv4 destination trace.

Have a look at the same and pass on your comments.

Thanks.
Ashwini Kumar


traceroute.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] - Add route

2013-09-07 Thread Ashwini Sharma
On Sat, Sep 7, 2013 at 11:47 PM, Isaac ibid...@gmail.com wrote:

 On Mon, Sep 02, 2013 at 11:15:14AM +0900, Ashwini Sharma wrote:
  HI Rob  list,
 
Attached is the patch for _route_ command. It does display, add and del
  functions for routing tables.
  Have a look at it.
 
  regards,
  Ashwini Kumar

 OK, I took a quick look through it.
 First, thanks for doing route.

 I note that show_route_help is identical to show_help() apart from the
 error message.  That's probably not needed.


Didn't use show_help(), as this doesn't exit whereas an exit is intended
for route.
may be show_help() can be updated to do that.


 Now...
 Hmm, there's an else if (!strcmp) ladder.
 It could be reduced to a switch if we take
 *argv[0]16 + *argv[1]8 + *argv[2]


didn't get your logic here, may be a little more detail can help.



 And the help could use a little modification to make it more commonly
 understandable:
 route [-ne] [-A inet | inet6] [add target | del target]
 ...
 -A inet(6)  Select...
 (note one space between the option and its parameter,
 but two between the parameter and the explanation)


Yes, help message can be updated to the one suggested.


 The rest I don't understand well enough to comment on.

 Thanks,
 Isaac Dunham


Thanks,
Ashwini Kumar
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] Fwd: [New Toy - patch] add ps watch

2013-08-20 Thread Ashwini Sharma
Hi Rob,

  Attached are the patches for _watch_  and _ps_ command.

Sent _ps_ again, just in case you lost the last one. This one also have a
copyright update.

regards,
Ashwini
-- Forwarded message --
From: Ashwini Sharma ak.ashw...@gmail.com
Date: Wed, Aug 7, 2013 at 6:17 PM
Subject: [New Toy - patch] add ps
To: toybox toybox@lists.landley.net


Hi All

  Attached is the patch for PS implementation.
This supports options -T (for displaying threads also) and -o for listing
parameters desired by user.

Have a look at the patch and let me know for any comments.

Thanks,
Ashwini


watch.c.patch
Description: Binary data


ps.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [New Toy] : add udhcpd

2013-08-13 Thread Ashwini Sharma
HI Rob,

Need to include headers, which are added in toynet.h at my end.
The files reuired are

#include netinet/ip.h
#include netinet/udp.h
#include netpacket/packet.h
regards,
Ashwini

On Tue, Aug 13, 2013 at 5:26 PM, Rob Landley r...@landley.net wrote:

  On 08/12/2013 04:29:25 AM, Ashwini Sharma wrote:

 Hi Rob,

  In the continuation to DHCP client sent to you last week, attached here
 with is the DHCP server implementation.

 Have a look at the same and let me know for any comments.


 I'm trying to finish the cleanups for ifconfig and grep before tackling
 anything else. If anyone else wants to post cleanup patches in the
 meantime, I'm all for it.

 (Quick glance: 1500 lines and 1200 lines. Some sort of get_flag macros.
 Its own write_pid() instead of xpidfile()... There are todo items here.)

 I renamed udhcpc to dhcp and udhcpd to dhcpd, because the u versions
 were the micro prefix for the busybox implementations. (There's no
 standard name for this: the isc reference implementation is called
 dhclient, I've also used pump and dhcpcd. The objective here isn't to
 blindly copy busybox, and when I typed dhcp into ubuntu not only did it not
 have such a command but its auto-suggest didn't say there was one in any
 package in the repository...)

 Um, test compile:

 toys/pending/dhcp.c:167:16: error: field 'iph' has incomplete type
 toys/pending/dhcp.c:168:17: error: field 'udph' has incomplete type
 toys/pending/dhcp.c: In function 'mode_raw':
 toys/pending/dhcp.c:592:22: error: storage size of 'sock' isn't known
 toys/pending/dhcp.c:592:22: warning: unused variable 'sock'
 [-Wunused-variable]
 toys/pending/dhcp.c: In function 'read_raw':
 toys/pending/dhcp.c:683:67: error: 'IPVERSION' undeclared (first use in
 this function)
 toys/pending/dhcp.c:683:67: note: each undeclared identifier is reported
 only once for each function it appears in
 toys/pending/dhcp.c:697:56: error: dereferencing pointer to incomplete type
 toys/pending/dhcp.c: In function 'send_raw':
 toys/pending/dhcp.c:732:22: error: storage size of 'dest_sll' isn't known
 toys/pending/dhcp.c:762:21: error: invalid application of 'sizeof' to
 incomplete type 'struct iphdr'

 And so on for a while. Might try again in the morning.

 Rob
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] [New Toy] : add udhcpd

2013-08-12 Thread Ashwini Sharma
Hi Rob,

 In the continuation to DHCP client sent to you last week, attached here
with is the DHCP server implementation.

Have a look at the same and let me know for any comments.

regards,
Ashwini


udhcpd.c.patch
Description: Binary data
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] (no subject)

2013-07-25 Thread Ashwini Sharma
On Fri, Jul 26, 2013 at 4:11 AM, Rob Landley r...@landley.net wrote:

 On 07/19/2013 05:02:40 AM, Ashwini Sharma wrote:

 Hi Rob,

Attached is the syslogd patch. Features supported are

 usage: syslogd  [-a socket] [-p socket] [-O logfile] [-f config file] [-m
 interval]
 [-p socket] [-s SIZE] [-b N] [-R HOST] [-l N] [-nSLKD]

 In this implementation, __/dev/log__ is used as the default input source
 and __/var/log/messages__ as the default
 output destination.


 The second one is in accordance with strikethe prophecy/strike
 Filesystem Hirearchy Standard 2.3:

 http://refspecs.linuxbase.org/**FHS_2.3/fhs-2.3.html#**
 VARLOGLOGFILESANDDIRECTORIEShttp://refspecs.linuxbase.org/FHS_2.3/fhs-2.3.html#VARLOGLOGFILESANDDIRECTORIES

 The first one isn't in FHS, and devtmpfs with Aboriginal's kernel config
 isn't providing log. (It's providing kmsg, but I dunno if that's the
 same thing.) Where does this data source come from and how would I set it
 up in my own system? (I'm not objecting, I'd just like to document how to
 use it.)


/dev/kmsg is used to read/write to the kernel printk ring buffer, which is
read by dmesg or klogd utilities.

/dev/log is an UNIX sockt created by sysogd, when invoked, and listens for
any incoming messgaes on this. The messages are written into it by the
system's syslog functionality.

Syslogd can listen on additional sockets provided through __ -a__ option.



 Please review and apply the patch to hg, and let me know for any comments.


 I applied this and the other two commands to the pending directory. I
 didn't apply the previous batch's libc or makefile changes yet.

 For libc I mentioned that the ordering was used for fatal vs non-fatal
 signals, and restricted itself to the signals specified by POSIX-2008. This
 is adding realtime support (not in posix that I recall), and I need to work
 out how to do that cleanly and test it against glibc, uClibc, musl, and (if
 I can get a fourth test environment set up) bionic.

 As for the makefile changes: it's filtering out space during flag
 generation. Easier thing to do would be to filter out space in getflags, by
 adding a space character to the sed invocation:

 --- a/scripts/make.sh   Thu Jul 25 13:32:06 2013 -0500
 +++ b/scripts/make.sh   Thu Jul 25 13:41:00 2013 -0500
 @@ -64,7 +64,7 @@
sed -n -e s/.*TOY($FLX',[ \t]*\([^]*\)[ \t]*,.*)/\1/' \
   -e 't keep;d;:keep' -e 's/^[=][0-9]//' -e 's/[?^]//' \
   -e 't keep' -e 's/[=][0-9][0-9]*//g' -e 's/+.//g' \
 - -e 's/\[[^]]*\]//g' -e 's/[-?^:#|@*]//g' $@ -e 'p'
 + -e 's/\[[^]]*\]//g' -e 's/[-?^:#|@* ]//g' $@ -e 'p'
  }

 Let's see: grep NEWTOY toys/*/*.c | grep '[^ ]* [^ ]*'

 I see that kill and timeout are both affected by this. Flags look right
 now, and I _really_ need to fill out the test suite to catch this sort of
 thing... Anyway, commiting the smaller fix.

 regards,
 Ashwini


 Thanks,

 Rob
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] toynet.h to be included in toys.h

2013-05-03 Thread Ashwini Sharma
And from 2~3 days I don't see the link to download the latest source from
Mercurial.

-Ashwini


On Fri, May 3, 2013 at 11:35 AM, Ashwini Sharma ak.ashw...@gmail.comwrote:

 Hi Rob,

   I think we should include toynet.h in toys.h, before we include
 #include generated/newtoys.h
 #include generated/globals.h

 so that whenever someone has a variable in GLOBALS ( )
 whose type is declared in networking headers, like a __struct sockaddr_in
 __ will get the type,
  else he will have to keep the variable outside the GLOBALS macro.

 May be this can be included conditionaly, as done for CONFIG_HELP, or
 straight away.

 regards,
 Ashwini

___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


Re: [Toybox] [groups] : ! More than one in group is error

2012-12-27 Thread Ashwini Sharma
Hi Rob,

  With your fix, it doesn't segfault now.
But does it matter, to give the proper option name in error message. If
yes, then the
fix fails in that.
e.g. when running *./toybox touch -d 12 -r f2 f1* it throws the error
message as
*touch: No 'r' with 't'*.

I feel the error message is not explanatory here. it should give the proper
option names in here.
my patch had this fix.

Pls give your inputs.

regards,
Ashwini

On Fri, Dec 28, 2012 at 6:21 AM, Rob Landley r...@landley.net wrote:

 On 12/27/2012 11:06:37 AM, Felix Janda wrote:

 When trying to implement the remaining options for pwd I could also test
 toybox's group option handling.

 The option string I wanted to use is: 0LP[!LP]
 (It's the same for LP[!LP].)

 With the current argparsing I get a segfault for pwd -L -P. When
 enabling
 TOYBOX_DEBUG it says pwd: trailing [!LP]. On the other hand when using
 Ashwini's suggestion with disabled TOYBOX_DEBUG everthing seems to work,
 whereas with enabled TOYBOX_DEBUG I get the same error message as before.


 Ok, this I can reproduce.  Hmmm...

 Ah. You're right, the test was wrong. (It got the condition right, but
 couldn't work out the correct error message due to  vs .)

 Testing for NULL just hid the problem, it didn't fix it. I checked in a
 fix.

 Thanks,

 Rob
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] long options support and yesno()

2012-12-04 Thread Ashwini Sharma
Hi Rob,

 As for the command options FLAG_xxx macros are auto generated. Is the long
options support in there and working?

Another usage issue I came across is in yesno() function.

In that you check for the tty fd. As '0' is also tty, you print the prompt
data onto 'stdin' which doesn't show up on screen.
Putting stdout' instead of fps[i] in fprintf shows the prompt. And reading
from fps[i] is fine.

what is your opinion on the same.

rgds,
Ashwini
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] Compile errors when compiling for ARM

2012-11-26 Thread Ashwini Sharma
Hi Rob,

  I was working on the latest changeset 711.
When I compile it for x86 machine, it works fine, but when building for my
ARM board,
compiler shouts* O_DIRECTORY undecalred in xabspath()*.

Am I missing something or the tree has this issue, please comment.

regards,
Ashwini Kumar
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net


[Toybox] Defect in Argument parsing for # and -

2012-07-02 Thread Ashwini Sharma
Hi Rob,

 I was using '#' for accepting a integer parameter. As per the parsing logic
you used function atolx(), for converting the string to long. This
function assumes suffixes with the supplied string. There are
possibilities that user may not want suffixes to be there, i.e. any
alpha char in the argument should be treated as Invalid Argument.

Also for the cases where user has only supplied a suffix, without any
number, atolx will return 0, which may not be the desired case.

I had a case where depth of traversal was to be defined as cmdline argument.
Giving kmgtpe would return zero, whereas I wanted it to only
integers as argument and no alpha characters.

Hence I am of the opinion that,

  1. It should be treated as Invalid Argument if no number is specified And
  2. It should be configurable, if a feature wants the suffixes to be
handled or not.

Please do provide your opinion.

regards,
Ashwini
___
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net