LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 04-20-2011, 03:52 AM   #1
guanx
Senior Member
 
Registered: Dec 2008
Posts: 1,176

Rep: Reputation: 233Reputation: 233Reputation: 233
Add "LC_ALL=C" to pktools


Hello Maintainers, Since pkgtools uses dd output, and the output text is not what pkgtools expected in some cases, it would be better to add "LC_ALL=C" to the beginning of the script.
 
Old 04-20-2011, 08:32 AM   #2
bonixavier
Member
 
Registered: Sep 2010
Distribution: Slackware
Posts: 320

Rep: Reputation: 69
Isn't C already set as LC_COLLATE by default to all shells?
 
Old 04-20-2011, 10:13 AM   #3
guanx
Senior Member
 
Registered: Dec 2008
Posts: 1,176

Original Poster
Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by bonixavier View Post
Isn't C already set as LC_COLLATE by default to all shells?
The problem with dd is LC_MESSAGES.
 
Old 04-20-2011, 02:58 PM   #4
wildwizard
Member
 
Registered: Apr 2009
Location: Oz
Distribution: slackware64-14.0
Posts: 875

Rep: Reputation: 282Reputation: 282Reputation: 282
Have you got the latest pkgtools?

Quote:
pkgtools-13.37-noarch-7
if [ ! "$LC_MESSAGES=C $TAR --version)" = "tar (GNU tar 1.13
 
Old 04-20-2011, 03:09 PM   #5
guanx
Senior Member
 
Registered: Dec 2008
Posts: 1,176

Original Poster
Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by wildwizard View Post
Have you got the latest pkgtools?
Yes. But the problem is with dd (as mentioned above), not tar.
 
Old 04-21-2011, 04:39 AM   #6
wildwizard
Member
 
Registered: Apr 2009
Location: Oz
Distribution: slackware64-14.0
Posts: 875

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by guanx View Post
Yes. But the problem is with dd (as mentioned above), not tar.
Argh read the line wrong it tests tar with it set, I though it was testing it as well as tar.

Anyway some checking and I can't see how it would ever be a problem.

installpkg is the one that uses it and it only looks at the first line and only the data up to the + sign everything else is discarded.

eg LC_MESSAGES=ja_JP.UTF-8
Code:
260+0 ??????
260+0 ??????
133120 ??? (133 kB) ????????? 0.00577092 ?? 23.1 MB/?
Normal output
Code:
260+0 records in
260+0 records out
133120 bytes (133 kB) copied, 0.00428188 s, 31.1 MB/s
If you can give a locale where that first part of the first line is different could you actually tell us which one?
 
Old 04-21-2011, 05:53 AM   #7
hello.freeman
Member
 
Registered: Apr 2010
Posts: 38

Rep: Reputation: 23
Here's the shell code from 'installpkg' :
Code:
  cat $package | $packagecompression -dc | dd 2> $TMP/tmpsize$$ | $TAR tf - 1> $TMP/tmplist$$ 2> /dev/null
  TARERROR=$?
  if [ ! "$TARERROR" = "0" ]; then
    EXITSTATUS=1 # tar file corrupt
    if [ "$MODE" = "install" ]; then
      echo "Unable to install $package:  tar archive is corrupt (tar returned error code $TARERROR)"
    fi
    rm -f $TMP/tmplist$$ $TMP/tmpsize$$
    continue
  fi
  UNCOMPRESSED="$(expr $(cat $TMP/tmpsize$$ | head -n 1 | cut -f 1 -d +) / 2)"
  if [ $UNCOMPRESSED -lt 1024 ]; then
    UNCOMPRESSED="${UNCOMPRESSED}K"
  elif [ $UNCOMPRESSED -lt 10239 ]; then
    UNCOMPRESSED="$(expr $UNCOMPRESSED \* 1000 / 1024 | cut -b1).$(expr $UNCOMPRESSED \* 1000 / 1024 | cut -b2)M"
  else
    UNCOMPRESSED="$(expr $UNCOMPRESSED / 1024)M"
  fi
  rm -f $TMP/tmpsize$$

Here's my dd output :
Code:
bash$ LC_MESSAGES=zh_CN.UTF-8 dd if=/dev/zero of=/dev/null bs=1024 count=2
记录了2+0 的读入
记录了2+0 的写出
2048字节(2.0 kB)已复制,1.824e-05 秒,112 MB/秒
bash$ LC_MESSAGES=ja_JP.UTF-8 dd if=/dev/zero of=/dev/null bs=1024 count=2
2+0 records in
2+0 records out
2048 bytes (2.0 kB) copied, 1.78e-05 s, 115 MB/s
bash$ dd if=/dev/zero of=/dev/null bs=1024 count=2
2+0 records in
2+0 records out
2048 bytes (2.0 kB) copied, 1.64e-05 s, 125 MB/s
bash$
There's something wrong in 'installpkg' when LC_MESSAGES become zh_CN.UTF-8 :
Code:
UNCOMPRESSED="$(expr $(cat $TMP/tmpsize$$ | head -n 1 | cut -f 1 -d +) / 2)"

bash$ LC_MESSAGES=zh_CN.UTF-8 dd if=/dev/zero of=/dev/null bs=1024 count=2 2>&1 | head -n 1 | cut -f 1 -d +
记录了2
bash$
 
1 members found this post helpful.
Old 04-21-2011, 05:57 AM   #8
hello.freeman
Member
 
Registered: Apr 2010
Posts: 38

Rep: Reputation: 23
BTW, the 'pkgtools' version is 13.37-noarch-7
 
Old 04-21-2011, 06:01 AM   #9
hello.freeman
Member
 
Registered: Apr 2010
Posts: 38

Rep: Reputation: 23
I don't think this is a bug.

Isn't C already set as LC_MESSAGES by default to all shells?
 
Old 04-21-2011, 06:17 AM   #10
guanx
Senior Member
 
Registered: Dec 2008
Posts: 1,176

Original Poster
Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by hello.freeman View Post
I don't think this is a bug.

Isn't C already set as LC_MESSAGES by default to all shells?
Yes. But nearly nobody runs a system with all defaults. It'll be better to explicitly set locale to C, POSIX, or en_US.UTF-8 if UTF is necessary.
BTW, the LANGUAGE environment variable also affects message locale.

Last edited by guanx; 04-21-2011 at 06:19 AM.
 
Old 04-21-2011, 06:18 AM   #11
guanx
Senior Member
 
Registered: Dec 2008
Posts: 1,176

Original Poster
Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by hello.freeman View Post
Here's the shell code from 'installpkg' :
...
Here's my dd output :
Code:
bash$ LC_MESSAGES=zh_CN.UTF-8 dd if=/dev/zero of=/dev/null bs=1024 count=2
记录了2+0 的读入
记录了2+0 的写出
2048字节(2.0 kB)已复制,1.824e-05 秒,112 MB/秒
bash$ LC_MESSAGES=ja_JP.UTF-8 dd if=/dev/zero of=/dev/null bs=1024 count=2
2+0 records in
2+0 records out
2048 bytes (2.0 kB) copied, 1.78e-05 s, 115 MB/s
bash$ dd if=/dev/zero of=/dev/null bs=1024 count=2
2+0 records in
2+0 records out
2048 bytes (2.0 kB) copied, 1.64e-05 s, 125 MB/s
bash$
...
That's it. -- And similar problem in lg (Luganda).
 
Old 04-21-2011, 11:33 AM   #12
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
All script writers are going to have to do settings like this for just about any program they capture output from. The complication will be the cases where they need to either have some programs just output to the user, or need to echo the captured output to the user.

Capturing output in a script has always been risky because some output formats change for other reasons, too, or portable scripts end up with different outputs on different systems. For decades, I've said we need programs specific for scripts, or at least special options to get script output somewhere. But even that doesn't handle the cases of output to be interpreted and shown to the user. The output probably needs a markup, isolating the informational parts from the display parts, along with the appropriate script tool to isolate them.

That, or switch to another scripting language that has built in methods to access data and perform functions otherwise giving to programs like dd. I'll suggest Python.
 
1 members found this post helpful.
Old 04-21-2011, 11:58 AM   #13
rg3
Member
 
Registered: Jul 2007
Distribution: Fedora
Posts: 527

Rep: Reputation: Disabled
I set LANG=C on all my slackbuild scripts for this reason. I've encountered a few cases where the "configure" script expects a given program output in this locale and wouldn't work or properly detect something in that case. I also change the locale in slackroll, which in turn calls installpkg, upgradepkg, etc. As mentioned above, this is a risk you have with every program that needs to parse the output of some other, and the program user may have changed the locale to their needs. The exact locale change I use in slackroll is pretty paranoid and conservative:

* Remove LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_MESSAGES, LC_NUMERIC, LC_TIME, LC_ALL, LANGUAGE, LANG from the environment.
* Set LANG to "C".
 
1 members found this post helpful.
Old 04-21-2011, 11:59 AM   #14
Darth Vader
Senior Member
 
Registered: May 2008
Location: Romania
Distribution: DARKSTAR Linux 2008.1
Posts: 2,727

Rep: Reputation: 1247Reputation: 1247Reputation: 1247Reputation: 1247Reputation: 1247Reputation: 1247Reputation: 1247Reputation: 1247Reputation: 1247
Quote:
Originally Posted by Skaperen View Post
I'll suggest Python.
Come on!

Nothing is better (and faster) for package management than some programs written in C/C++ and linked full-static. They depend only on the Kernel and maybe Shell.

Slackware specifications for package management are very simple. If Slackware team is interested, I can write an equivalent installpkg / upgradepkg / removekg in a few weeks, using libarchive.

And the changes were minor in Slackware. For a full-static build, the static libraries would be needed since libarchive. So most likely, libarchive, XZ and libxml should be rebuilded with '--enable-static'.

Last edited by Darth Vader; 04-21-2011 at 12:05 PM.
 
Old 04-21-2011, 12:41 PM   #15
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
There's already a good C version called spkg (don't confuse it with a shell version of the same name).
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting this error "Unable to set LC_ALL to default locale" Nabeel Mandriva 3 12-16-2009 04:33 AM
/etc/rc.d/rc.sysinit: line 46: 819 Segmentation fault LC_ALL=C fgrep -q "/dev " /proc RMLinux Linux - Newbie 1 12-01-2008 02:53 AM
can't open "add/remove software" or "software updater" windows 7trek Fedora 1 06-12-2007 09:06 PM
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 08:31 AM
add "Artist" and "Album Title" to mp3 files powah Linux - Software 2 04-05-2005 03:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 11:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration