Re: stat(1) (was Re: mergemaster(8) broken -- uses Perl
On Wed, 05 Jun 2002 23:58:14 MST, Doug Barton wrote: > I'm currently testing a buildworld prior to importing NetBSD's stat(1) > into the tree. Once that's done, if you have suggestions for > improvements I'm sure that they would be interested. I'll be happy to > work with you on adding useful bits to it in our tree as well. You can > see what I'm importing at > http://cvsweb.netbsd.org/bsdweb.cgi/basesrc/usr.bin/stat/ I really like the fact that you're trying to maintain NetBSD compatibility with tools imported from NetBSD. Ciao, Sheldon. To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: stat(1) (was Re: mergemaster(8) broken -- uses Perl
Bakul Shah wrote: > > > the trick nicely (but is too ``complicated'', and I'd still like > > having a tool that allows userland to call stat/fstat(2): I'm currently testing a buildworld prior to importing NetBSD's stat(1) into the tree. Once that's done, if you have suggestions for improvements I'm sure that they would be interested. I'll be happy to work with you on adding useful bits to it in our tree as well. You can see what I'm importing at http://cvsweb.netbsd.org/bsdweb.cgi/basesrc/usr.bin/stat/ My reasons for choosing to import this version are the obvious benefits of working closely with the NetBSD folks, as well as the fact that it has a large number of features, compiles cleanly on our system (even with WARNS=2), etc. Doug -- "We have known freedom's price. We have shown freedom's power. And in this great conflict, ... we will see freedom's victory." - George W. Bush, President of the United States State of the Union, January 28, 2002 Do YOU Yahoo!? To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: mergemaster(8) broken -- uses Perl
On 2002-05-19 11:05, David O'Brien wrote: > On Sun, May 19, 2002 at 05:29:22AM +0300, Giorgos Keramidas wrote: > > Part of the problems I had when I tried to replace perl in > > mergemaster.sh with something `native' was that the perl code uses > > stat(2) to obtain the permission bits of a directory/file and I can't > > think of a way to do this with tools in the base system without > > resorting to ugly awk scripts that parse and translate ls(1) output. > > What is so ugly about it? It is not that many lines, and it is very easy > to read and understand what you are doing. Make it an sh function. > There is most likely code like this in the Perl binary. If this is so > ugly lets gut it out of perl also. Alright. I'll probably use this or the sed stuff I posted as a followup to Alfred's mail. I haven't had much time to spend on FreeBSD today since I was trying to install NetBSD on a spare disk and start getting acquainted, but thanks for the positive feedback ;) -- Giorgos Keramidas- http://www.FreeBSD.org [EMAIL PROTECTED] - The Power to Serve To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
stat(1) (was Re: mergemaster(8) broken -- uses Perl
> the trick nicely (but is too ``complicated'', and I'd still like > having a tool that allows userland to call stat/fstat(2): You are not alone; a number of stat(1) commands seemed to have popped up over the years. My friend @ SGI told me IRIX also has such a command. I liked its options so I modified mine to match its options as well as kept the option to specify output format. New options: -a atime -c ctime -d dev -g group -i inode -k kind (dir/file/fifo/symlnk/char/block/socket/whiteout) -l links -m mtime -p permissions -r rdev -s size -t all three times -u user -q quite (print numeric values, no syntactic sugar) -f fstat on file descr. For BSD stuff I added -F flags -G generation -b blocks -B blocksize Also, -L use lstat instead of stat -n print name -% user specified format specification as shown in my previous email, except use %k for kind and %t for printing all three times. By default it prints all the stat fields instead of mimicing "ls -lTd" as before. You can specify STATFMT env. var for a default format. Example: $ stat -p stat rwxr-xr-x $ stat -p -q stat 755 Not having used SGI's stat command I don't know what output format it uses. Paul Herman asks in a separate email if there is a happy medium. I don't think so. One can use ls(1) for a more human readable format. stat(1) is really for script use. Even the -% format is for that (to avoid having to pull out the ginsu knife of awk/sed/perl for common uses). About the best I can do in 300 or so lines of code and that is already a lot of lines for something like this. -- bakul To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: mergemaster(8) broken -- uses Perl
On Sun, May 19, 2002 at 05:29:22AM +0300, Giorgos Keramidas wrote: > Part of the problems I had when I tried to replace perl in > mergemaster.sh with something `native' was that the perl code uses > stat(2) to obtain the permission bits of a directory/file and I can't > think of a way to do this with tools in the base system without > resorting to ugly awk scripts that parse and translate ls(1) output. What is so ugly about it? It is not that many lines, and it is very easy to read and understand what you are doing. Make it an sh function. There is most likely code like this in the Perl binary. If this is so ugly lets gut it out of perl also. To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: new fstat(1) feature (was Re: mergemaster(8) broken -- uses Perl)
On 2002-05-19 00:01, Paul Herman wrote: > > OK, here's a patch to fstat(1) which adds an "-s" option to stat(2) > a list of files on the command line. It's against -STABLE but > should still apply to -CURRENT. Comments are appreciated. When building with WARNS=2 I also saw a few 'long int format, int argument' warnings, which can be fixed by using %u instead of %lu in printf's for st.a_time and friends. Style(9) put aside, this seems to work for me in CURRENT (but prints a few of the columns unaligned, see ATIME below): hades+root:/tmp/fstat# ./fstat -s fstat INODE DEVSIZE BLOCKS MODE FLAGS LNK UID GID ATIME MTIME CTIME NAME 14134 160768 1771436 100755 00 1 1001 0 1021809739 1021809739 1021809739 fstat -- Giorgos Keramidas- http://www.FreeBSD.org [EMAIL PROTECTED] - The Power to Serve To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: mergemaster(8) broken -- uses Perl
On 2002-05-19 02:13, Alfred Perlstein wrote: > * Bakul Shah <[EMAIL PROTECTED]> [020519 00:30] wrote: > > > $ stat -a stat > > > > Oops! A few lines got eaten! > > > > $ stat -a stat > > May 19 00:24:42 2002|48|May 19 00:24:42 2002|291846|-|bakul|0|262301|1|May 19 >00:24:42 2002|rwxr-xr-x|1095744|23996|-|bakul|stat > > $ stat -a -n stat > > >1021793082|48|1021793082|291846|0|1001|0|262301|1|1021793082|755|1095744|23996|10|1001|stat > > Bow to me. > > echo 'ibase=2\nobase=8\n' \ > `ls -ld ${FILE} | cut -f 1 -d " " | \ > sed -e 's/[rwx]/1/g' -e 's/[^rwx1]/0/g'` | \ > bc Great idea to use bc(1) ;-) It doesn't really parse sticky, suid or sgid bits, but it's smaller than the awk version. The following did the trick nicely (but is too ``complicated'', and I'd still like having a tool that allows userland to call stat/fstat(2): hades+charon:/tmp$ cat foo.sh #!/bin/sh echo 'ibase=2;obase=8;' \ ` ls -ld "$1" | \ cut -c2-10 | \ sed -e '/^..[sS]/ s/^.*$/&+1000/' \ -e '/^.[sS]/ s/^.*$/&+100/' \ -e '/^[tT]/ s/^.*$/&+10/' | \ sed -e 's/[st]/x/g' -e 's/ST/-/g' | \ sed -e 's/[rwx]/1/g' | \ sed -e 's/[^1+]/0/g' ` | bc % sh foo.sh /tmp hades+charon:/tmp$ sh foo.sh /tmp 1777 -- Giorgos Keramidas- http://www.FreeBSD.org [EMAIL PROTECTED] - The Power to Serve To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: mergemaster(8) broken -- uses Perl
On 2002-05-19 06:26, Dima Dorfman wrote: > Paul Herman <[EMAIL PROTECTED]> wrote: > > > > bash$ /usr/obj/usr/src/usr.bin/fstat/fstat -s /tmp /kernel > > INODE DEVSIZE BLOCKS MODE FLAGS LNK UID GID ATIME MTIME CTIME > NAME > > 235226304 4114305 8096 100555 40 1 0 0 1021779222 >10217403541021740354 /kernel > > 56651 226304 512 4 041777 00 6 0 0 1021787523 >10217876571021787657 /tmp > > > > so you can parse it however you like. Either way, ls(1) or > > fstat(1), as long as you can get the info you need. :-) > > This looks much better than my extention. I look forward to seeing > this get into the tree. True. And it's only logical to have fstat print the `struct stat' fields. That would make things a *lot* easier, when trying to make mergemaster.sh avoid all kinds of perl ;-) -- Giorgos Keramidas- http://www.FreeBSD.org [EMAIL PROTECTED] - The Power to Serve To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: mergemaster(8) broken -- uses Perl
* Bakul Shah <[EMAIL PROTECTED]> [020519 00:30] wrote: > > $ stat -a stat > > Oops! A few lines got eaten! > > $ stat -a stat > May 19 00:24:42 2002|48|May 19 00:24:42 2002|291846|-|bakul|0|262301|1|May 19 >00:24:42 2002|rwxr-xr-x|1095744|23996|-|bakul|stat > $ stat -a -n stat > >1021793082|48|1021793082|291846|0|1001|0|262301|1|1021793082|755|1095744|23996|10|1001|stat Bow to me. echo 'ibase=2\nobase=8\n' \ `ls -ld ${FILE} | cut -f 1 -d " " | \ sed -e 's/[rwx]/1/g' -e 's/[^rwx1]/0/g'` | \ bc -- -Alfred Perlstein [[EMAIL PROTECTED]] To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: mergemaster(8) broken -- uses Perl
> $ stat -a stat Oops! A few lines got eaten! $ stat -a stat May 19 00:24:42 2002|48|May 19 00:24:42 2002|291846|-|bakul|0|262301|1|May 19 00:24:42 2002|rwxr-xr-x|1095744|23996|-|bakul|stat $ stat -a -n stat 1021793082|48|1021793082|291846|0|1001|0|262301|1|1021793082|755|1095744|23996|10|1001|stat To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: mergemaster(8) broken -- uses Perl
> Paul Herman <[EMAIL PROTECTED]> wrote: > > On Sun, 19 May 2002, Dima Dorfman wrote: > > > > > How about fixing ls(1) to output the numeric mode if asked to? > > > > That's good, but while you're at it you'd probably want to get > > *everything* out of (struct stat) and print it numerically (device, > > flags, atime since epoch, etc.) You could do this in ls(1), but > > I'll have a patch for fstat(1) soon (working on it) that gives you: > > > > bash$ /usr/obj/usr/src/usr.bin/fstat/fstat -s /tmp /kernel > > INODE DEVSIZE BLOCKS MODE FLAGS LNK UID GID ATIME MTIME CTIME > NAME > > 235226304 4114305 8096 100555 40 1 0 0 1021779222 >10217403541021740354 /kernel > > 56651 226304 512 4 041777 00 6 0 0 1021787523 >10217876571021787657 /tmp > > > > so you can parse it however you like. Either way, ls(1) or > > fstat(1), as long as you can get the info you need. :-) > > This looks much better than my extention. I look forward to seeing > this get into the tree. I have a yet another variation, called `stat'. It is like ls(1) except you specify what stat fields you want using a printf style format string. I added -n flag to print out numeric values instead of symbolic ones where it makes sense. I originally wrote it many years ago because access to stat fields from shell scripts is such a pain. Yours for asking. $ stat -h Usage: stat [-a | -f format] [-h] [-n] [-L] files... where options are: -a print all attributes -f format print using a printf like format -h this help message -L follow symbolic links -n prints numeric values not symbolic values The -f format is as follows: \ escapes are as in printf any other non % char is printed as is, %% prints a single % a stat field is printed using %[-][width][.width] format. - for left justification, width[.width] is as for %s format of printf can be one of: a file access time b allocated blocks c inode change time d dev f flags g group G generation l links m file modify time n file name p permissions: r=read w=write x=exec S=suid/sgid s=suid/sgid+x T=sticky t=sticky+x r raw dev s size t type: b=block c=char d=dir -=file p=fifo s=socket l=symlink w=whiteout u user The default format is "%t%p %2l %-6u %-6g %9s %m %n\n" Format for the -a option is "%a|%b|%c|%d|%f|%g|%G|%i|%l|%m|%p|%r|%s|%t|%u|%n\n" $ stat stat -rwxr-xr-x 1 bakul bakul 22523 May 18 23:46:16 2002 stat $ stat -a stat -- bakul To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
new fstat(1) feature (was Re: mergemaster(8) broken -- uses Perl)
OK, here's a patch to fstat(1) which adds an "-s" option to stat(2) a list of files on the command line. It's against -STABLE but should still apply to -CURRENT. Comments are appreciated. The only other addition I would like to have is have "-n" option display everything numericaly as it does now, whereas no "-n" would display everything in human readable format (users, groups, modes, dates, etc.) If someone else would like to do that, please patch away! :-) Otherwise, I'll see if I can't get around to it some other time. -Paul. Index: fstat.1 === RCS file: /u02/ncvs/src/usr.bin/fstat/fstat.1,v retrieving revision 1.9.2.6 diff -u -r1.9.2.6 fstat.1 --- fstat.1 16 Apr 2002 19:53:35 - 1.9.2.6 +++ fstat.1 19 May 2002 06:35:41 - @@ -87,6 +87,10 @@ and print the mode of the file in octal instead of symbolic form. .It Fl p Report all files open by the specified process. +.It Fl s +Print +.Xr stat 2 +contents of files given on the command line. .It Fl u Report all files open by the specified user. .It Fl v @@ -181,6 +185,40 @@ .Xr ln 1 ) , the name printed may not be the actual name that the process originally used to open that file. +.El +.Pp +unless the +.Fl s +option is given in which case the following is printed: +.Bl -tag -width BLOCKS +.It Li INODE +The inode number of the file. +.It Li DEV +The device number the file resides on. +.It Li SIZE +The size in bytes of the file. +.It Li BLOCKS +The number of blocks used by the file. +.It Li MODE +The file's protection mode. +.It Li FLAGS +The file's +.Xr chflags 2 +flags. +.It Li LNK +The number of hard links. +.It Li UID +The user ID of the file's owner. +.It Li GID +The group ID of the file's group. +.It Li ATIME +The time of last access. +.It Li MTIME +The time of last data modification. +.It Li CTIME +The time of last file status change. +.It Li NAME +The file name. .El .Sh SOCKETS The formating of open sockets depends on the protocol domain. Index: fstat.c === RCS file: /u02/ncvs/src/usr.bin/fstat/fstat.c,v retrieving revision 1.21.2.7 diff -u -r1.21.2.7 fstat.c --- fstat.c 21 Nov 2001 10:49:37 - 1.21.2.7 +++ fstat.c 19 May 2002 06:10:58 - @@ -121,6 +121,7 @@ intnflg; /* (numerical) display f.s. and rdev as dev_t */ intvflg; /* display errors in locating kernel data objects etc... */ intmflg; /* include memory-mapped files */ +intsflg; /* display inode information */ struct file **ofiles; /* buffer of pointers to file structures */ @@ -137,6 +138,7 @@ kvm_t *kd; +void dostats __P((void)); void dofiles __P((struct kinfo_proc *kp)); void dommap __P((struct kinfo_proc *kp)); void vtrans __P((struct vnode *vp, int i, int flag)); @@ -165,7 +167,7 @@ arg = 0; what = KERN_PROC_ALL; nlistf = memf = NULL; - while ((ch = getopt(argc, argv, "fmnp:u:vN:M:")) != -1) + while ((ch = getopt(argc, argv, "fmnp:su:vN:M:")) != -1) switch((char)ch) { case 'f': fsflg = 1; @@ -192,6 +194,9 @@ what = KERN_PROC_PID; arg = atoi(optarg); break; + case 's': + sflg = 1; + break; case 'u': if (uflg++) usage(); @@ -241,12 +246,24 @@ #endif if ((p = kvm_getprocs(kd, what, arg, &cnt)) == NULL) errx(1, "%s", kvm_geterr(kd)); - if (nflg) + if (sflg) { + if (!checkfile) { + warnx("must provide a filename"); + usage(); + } printf("%s", +"INODE DEVSIZE BLOCKS MODE FLAGS LNK UID GID ATIME MTIME CTIME +NAME\n"); + dostats(); + exit(0); + } + else { + if (nflg) + printf("%s", "USER CMD PID FD DEVINUM MODE SZ|DV R/W"); - else - printf("%s", + else + printf("%s", "USER CMD PID FD MOUNT INUM MODE SZ|DV R/W"); + } if (checkfile && fsflg == 0) printf(" NAME\n"); else @@ -288,6 +305,31 @@ } /* + * print inode information for all files in devs + */ +void +dostats() { + struct stat s; + register DEVS *d; + for (d = devs; d != NULL; d = d->next) { + if (d->name == NULL)/* does this ever happen? */ + errx(1, "invalid filename"); + if (stat(d->name, &s) == -1) { + warnx("couldn't stat file %s", d->name); + continue; + } + (void)printf("%-6u %-6d %-8qd %-6qd %-6.6o %-6.6o %-3
Re: mergemaster(8) broken -- uses Perl
Paul Herman <[EMAIL PROTECTED]> wrote: > On Sun, 19 May 2002, Dima Dorfman wrote: > > > How about fixing ls(1) to output the numeric mode if asked to? > > That's good, but while you're at it you'd probably want to get > *everything* out of (struct stat) and print it numerically (device, > flags, atime since epoch, etc.) You could do this in ls(1), but > I'll have a patch for fstat(1) soon (working on it) that gives you: > > bash$ /usr/obj/usr/src/usr.bin/fstat/fstat -s /tmp /kernel > INODE DEVSIZE BLOCKS MODE FLAGS LNK UID GID ATIME MTIME CTIME > NAME > 235226304 4114305 8096 100555 40 1 0 0 1021779222 >10217403541021740354 /kernel > 56651 226304 512 4 041777 00 6 0 0 1021787523 >10217876571021787657 /tmp > > so you can parse it however you like. Either way, ls(1) or > fstat(1), as long as you can get the info you need. :-) This looks much better than my extention. I look forward to seeing this get into the tree. Thanks. To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: mergemaster(8) broken -- uses Perl
On Sun, 19 May 2002, Dima Dorfman wrote: > How about fixing ls(1) to output the numeric mode if asked to? That's good, but while you're at it you'd probably want to get *everything* out of (struct stat) and print it numerically (device, flags, atime since epoch, etc.) You could do this in ls(1), but I'll have a patch for fstat(1) soon (working on it) that gives you: bash$ /usr/obj/usr/src/usr.bin/fstat/fstat -s /tmp /kernel INODE DEVSIZE BLOCKS MODE FLAGS LNK UID GID ATIME MTIME CTIME NAME 235226304 4114305 8096 100555 40 1 0 0 1021779222 1021740354 1021740354 /kernel 56651 226304 512 4 041777 00 6 0 0 1021787523 1021787657 1021787657 /tmp so you can parse it however you like. Either way, ls(1) or fstat(1), as long as you can get the info you need. :-) -Paul. To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: mergemaster(8) broken -- uses Perl
Giorgos Keramidas <[EMAIL PROTECTED]> wrote: > On 2002-05-18 11:54, David O'Brien wrote: > > Anyone got a patch? > > Part of the problems I had when I tried to replace perl in > mergemaster.sh with something `native' was that the perl code uses > stat(2) to obtain the permission bits of a directory/file and I can't > think of a way to do this with tools in the base system without > resorting to ugly awk scripts that parse and translate ls(1) output. How about fixing ls(1) to output the numeric mode if asked to? E.g., instead of > % /bin/ls -ld /tmp | sed -e 's/[[:space:]].*$//' |\ > awk -v mode=0 '{ >[...] /bin/ls -ldN /tmp | awk '{ print $1 }' A proof-of-concept (i.e., not polished or fully-tested (in particular, it lacks a manual page update)) patch to implement ls -N is attached below. I've wanted this feature a number of times in the past, but never had occasion to actually implement it until now. Note also that if this is used in mergemaster, we need to deal with the issue of what to do if mergemaster is run on a system that doesn't have this option yet (perhaps try it first, and fall back to Perl (which should exist on systems without ls -N) if it doesn't work?). Index: ls.c === RCS file: /ref/cvsf/src/bin/ls/ls.c,v retrieving revision 1.56 diff -u -r1.56 ls.c --- ls.c19 Feb 2002 00:05:50 - 1.56 +++ ls.c19 May 2002 05:49:53 - @@ -106,6 +106,7 @@ static int f_nosort; /* don't sort output */ int f_notabs; /* don't use tab-separated multi-col output */ static int f_numericonly; /* don't convert uid/gid to name */ + int f_numeric_mode; /* don't convert file modes to a string */ int f_octal;/* show unprintables as \xxx */ int f_octal_escape; /* like f_octal but use C escapes if possible */ static int f_recursive;/* ls subdirectories also */ @@ -167,7 +168,7 @@ f_listdot = 1; fts_options = FTS_PHYSICAL; - while ((ch = getopt(argc, argv, "1ABCFGHLPRTWZabcdfghiklnoqrstuw")) != -1) { + while ((ch = getopt(argc, argv, "1ABCFGHLNPRTWZabcdfghiklnoqrstuw")) != -1) { switch (ch) { /* * The -1, -C and -l options all override each other so shell @@ -246,6 +247,9 @@ break; case 'n': f_numericonly = 1; + break; + case 'N': + f_numeric_mode = 1; break; case 'o': f_flags = 1; Index: ls.h === RCS file: /ref/cvsf/src/bin/ls/ls.h,v retrieving revision 1.17 diff -u -r1.17 ls.h --- ls.h3 Feb 2002 19:11:32 - 1.17 +++ ls.h19 May 2002 05:49:07 - @@ -48,6 +48,7 @@ extern int f_lomac;/* show LOMAC attributes */ extern int f_inode;/* print inode */ extern int f_longform; /* long listing format */ +extern int f_numeric_mode; /* don't convert file modes to a string */ extern int f_octal;/* print unprintables in octal */ extern int f_octal_escape; /* like f_octal but use C escapes if possible */ extern int f_nonprint; /* show unprintables as ? */ Index: print.c === RCS file: /ref/cvsf/src/bin/ls/print.c,v retrieving revision 1.53 diff -u -r1.53 print.c --- print.c 25 Feb 2002 01:36:59 - 1.53 +++ print.c 19 May 2002 05:49:30 - @@ -177,7 +177,10 @@ if (f_size) (void)printf("%*lld ", dp->s_block, howmany(sp->st_blocks, blocksize)); - strmode(sp->st_mode, buf); + if (f_numeric_mode) + snprintf(buf, sizeof(buf), "%.6o", sp->st_mode); + else + strmode(sp->st_mode, buf); np = p->fts_pointer; (void)printf("%s %*u %-*s %-*s ", buf, dp->s_nlink, sp->st_nlink, dp->s_user, np->user, dp->s_group, Index: util.c === RCS file: /ref/cvsf/src/bin/ls/util.c,v retrieving revision 1.29 diff -u -r1.29 util.c --- util.c 28 Feb 2002 18:52:47 - 1.29 +++ util.c 19 May 2002 05:50:08 - @@ -158,9 +158,9 @@ { (void)fprintf(stderr, #ifdef COLORLS - "usage: ls [-ABCFGHLPRTWZabcdfghiklnoqrstu1]" + "usage: ls [-ABCFGHLNPRTWZabcdfghiklnoqrstu1]" #else - "usage: ls [-ABCFHLPRTWZabcdfghiklnoqrstu1]" + "usage: ls [-ABCFHLNPRTWZabcdfghiklnoqrstu1]" #endif " [file ...]\n"); exit(1); To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: mergemaster(8) broken -- uses Perl
On 2002-05-19 00:04, Benjamin P. Grubin wrote: > Dear god, you guys really like hurting yourselves. > > If filetest doesn't do it, why not just something on the order of: > > #include > #include I was looking for a scriptable version of exactly this :) -- Giorgos Keramidas- http://www.FreeBSD.org [EMAIL PROTECTED] - The Power to Serve To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
RE: mergemaster(8) broken -- uses Perl
Dear god, you guys really like hurting yourselves. If filetest doesn't do it, why not just something on the order of: #include #include main (argc, argv) int argc; char *argv[]; { struct stat stbuf; if (!stat(argv[1], &stbuf)) printf("%o\n", stbuf.st_mode); else printf("error: stat failed\n"); } Cheers, Ben > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED]] On Behalf Of Paul Herman > Sent: Saturday, May 18, 2002 11:45 PM > To: Giorgos Keramidas > Cc: Benjamin P. Grubin; [EMAIL PROTECTED] > Subject: Re: mergemaster(8) broken -- uses Perl > > > On Sun, 19 May 2002, Giorgos Keramidas wrote: > > > On 2002-05-18 23:11, Benjamin P. Grubin wrote: > > > Giorgos Keramidas wrote: > > > > > > > > [ The above should print in stdout just 01777 as a number. ] > > > > ... > > > > Does anyone know of any other (possibly more elegant way) of > > > > reading the numeric value of the permission bits for a file? > > Hmmm, it's ugly but perhaps not as ugly: > > bash$ fstat -n /kernel < /kernel | grep -v PID > pherman fstat9420 116,196608235 100555 > 4114305 r /kernel > > (the 100555). The bad side is that you'd have to do a little > trickery to catch the correct process. It'd probably be better > just to add an option to fstat to display /usr/ports/sysutils/stat > type info... > > -Paul. > > > To Unsubscribe: send mail to [EMAIL PROTECTED] > with "unsubscribe freebsd-current" in the body of the message > > > To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: mergemaster(8) broken -- uses Perl
On Sun, 19 May 2002, Giorgos Keramidas wrote: > On 2002-05-18 23:11, Benjamin P. Grubin wrote: > > Giorgos Keramidas wrote: > > > > > > [ The above should print in stdout just 01777 as a number. ] > > > ... > > > Does anyone know of any other (possibly more elegant way) of > > > reading the numeric value of the permission bits for a file? Hmmm, it's ugly but perhaps not as ugly: bash$ fstat -n /kernel < /kernel | grep -v PID pherman fstat9420 116,196608235 100555 4114305 r /kernel (the 100555). The bad side is that you'd have to do a little trickery to catch the correct process. It'd probably be better just to add an option to fstat to display /usr/ports/sysutils/stat type info... -Paul. To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: mergemaster(8) broken -- uses Perl
On 2002-05-18 23:11, Benjamin P. Grubin wrote: > Giorgos Keramidas wrote: > > > > [ The above should print in stdout just 01777 as a number. ] > > ... > > Does anyone know of any other (possibly more elegant way) of > > reading the numeric value of the permission bits for a file? > > Is [t]csh's `filetest` builtin viable here? Ah, very good hint. Unfortunately even with -P: I can't get the `special' bits like sticky, etc. as I can see: $ /bin/tcsh -c 'filetest -P: /tmp' 0777 and mergemaster.sh uses this as an argument to `install -m num' to set the mode of installed files :-/ - Giorgos [ That was a VERY good hint, BTW. I didn't know about `filetest' and it seems a rather useful feature of tcsh. ] To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
RE: mergemaster(8) broken -- uses Perl
Is [t]csh's `filetest` builtin viable here? Relurking, Ben > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED]] On Behalf Of > Giorgos Keramidas > Sent: Saturday, May 18, 2002 10:29 PM > To: [EMAIL PROTECTED] > Subject: Re: mergemaster(8) broken -- uses Perl > > > On 2002-05-18 11:54, David O'Brien wrote: > > Anyone got a patch? > > Part of the problems I had when I tried to replace perl in > mergemaster.sh with something `native' was that the perl code uses > stat(2) to obtain the permission bits of a directory/file and I can't > think of a way to do this with tools in the base system without > resorting to ugly awk scripts that parse and translate ls(1) output. > > Any ideas? I am not really sure I like something like: > > % /bin/ls -ld /tmp | sed -e 's/[[:space:]].*$//' |\ > awk -v mode=0 '{ > if (match($0, "^.r")) { mode += 00400; } > if (match($0, "^..w...")) { mode += 00200; } > if (match($0, "^...S..")) { mode += 04000; } > if (match($0, "^...s..")) { mode += 04100; } > if (match($0, "^...x..")) { mode += 00100; } > if (match($0, "^r.")) { mode += 00040; } > if (match($0, "^.w")) { mode += 00020; } > if (match($0, "^..S...")) { mode += 02000; } > if (match($0, "^..s...")) { mode += 02010; } > if (match($0, "^..x...")) { mode += 00010; } > if (match($0, "^...r..")) { mode += 4; } > if (match($0, "^w.")) { mode += 2; } > if (match($0, "^.T")) { mode += 01000; } > if (match($0, "^.t")) { mode += 01001; } > if (match($0, "^.x")) { mode += 1; } > } > END { printf "0%o\n", mode; }' > > [ The above should print in stdout just 01777 as a number. ] > > It seems to work, but it's a bit ugly for my taste. Plus it will > break if the permission bits ever change representation (although this > is unlikely to happen any time real soon). > > Does anyone know of any other (possibly more elegant way) of reading > the numeric value of the permission bits for a file? > > -- > Giorgos Keramidas- http://www.FreeBSD.org > [EMAIL PROTECTED] - The Power to Serve > > To Unsubscribe: send mail to [EMAIL PROTECTED] > with "unsubscribe freebsd-current" in the body of the message > > > To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message
Re: mergemaster(8) broken -- uses Perl
On 2002-05-18 11:54, David O'Brien wrote: > Anyone got a patch? Part of the problems I had when I tried to replace perl in mergemaster.sh with something `native' was that the perl code uses stat(2) to obtain the permission bits of a directory/file and I can't think of a way to do this with tools in the base system without resorting to ugly awk scripts that parse and translate ls(1) output. Any ideas? I am not really sure I like something like: % /bin/ls -ld /tmp | sed -e 's/[[:space:]].*$//' |\ awk -v mode=0 '{ if (match($0, "^.r")) { mode += 00400; } if (match($0, "^..w...")) { mode += 00200; } if (match($0, "^...S..")) { mode += 04000; } if (match($0, "^...s..")) { mode += 04100; } if (match($0, "^...x..")) { mode += 00100; } if (match($0, "^r.")) { mode += 00040; } if (match($0, "^.w")) { mode += 00020; } if (match($0, "^..S...")) { mode += 02000; } if (match($0, "^..s...")) { mode += 02010; } if (match($0, "^..x...")) { mode += 00010; } if (match($0, "^...r..")) { mode += 4; } if (match($0, "^w.")) { mode += 2; } if (match($0, "^.T")) { mode += 01000; } if (match($0, "^.t")) { mode += 01001; } if (match($0, "^.x")) { mode += 1; } } END { printf "0%o\n", mode; }' [ The above should print in stdout just 01777 as a number. ] It seems to work, but it's a bit ugly for my taste. Plus it will break if the permission bits ever change representation (although this is unlikely to happen any time real soon). Does anyone know of any other (possibly more elegant way) of reading the numeric value of the permission bits for a file? -- Giorgos Keramidas- http://www.FreeBSD.org [EMAIL PROTECTED] - The Power to Serve To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-current" in the body of the message