dos2unix: tiny shrink

login,su: fix setup_environment() so that it works as intended
          (parameter names were a bit misleading)
fdisk: shrink
help text: shrink

function                                             old     new   delta
login_main                                          1658    1701     +43
setup_environment                                    206     203      -3
dos_compatible_flag                                    4       1      -3
dos2unix_main                                        383     375      -8
get_boot                                            1724    1702     -22
fdisk_main                                          2949    2889     -60
packed_usage                                       24250   23948    -302
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/6 up/down: 43/-398)          Total: -355 bytes
   text    data     bss     dec     hex filename
 798768     661    7428  806857   c4fc9 busybox_old
 798327     658    7428  806413   c4e0d busybox_unstripped
This commit is contained in:
Denis Vlasenko 2008-03-17 08:42:43 +00:00
parent 107fe7c081
commit cdf62770af
8 changed files with 204 additions and 208 deletions

View File

@ -24,19 +24,19 @@ static void convert(char *fn, int conv_type)
{ {
FILE *in, *out; FILE *in, *out;
int i; int i;
#define name_buf bb_common_bufsiz1 char *name_buf = name_buf; /* for compiler */
in = stdin; in = stdin;
out = stdout; out = stdout;
if (fn != NULL) { if (fn != NULL) {
in = xfopen(fn, "rw"); in = xfopen(fn, "r");
/* /*
The file is then created with mode read/write and The file is then created with mode read/write and
permissions 0666 for glibc 2.0.6 and earlier or permissions 0666 for glibc 2.0.6 and earlier or
0600 for glibc 2.0.7 and later. 0600 for glibc 2.0.7 and later.
*/ */
snprintf(name_buf, sizeof(name_buf), "%sXXXXXX", fn); name_buf = xasprintf("%sXXXXXX", fn);
i = mkstemp(&name_buf[0]); i = mkstemp(name_buf);
if (i == -1 if (i == -1
|| fchmod(i, 0600) == -1 || fchmod(i, 0600) == -1
|| !(out = fdopen(i, "w+")) || !(out = fdopen(i, "w+"))
@ -48,12 +48,9 @@ static void convert(char *fn, int conv_type)
while ((i = fgetc(in)) != EOF) { while ((i = fgetc(in)) != EOF) {
if (i == '\r') if (i == '\r')
continue; continue;
if (i == '\n') { if (i == '\n')
if (conv_type == CT_UNIX2DOS) if (conv_type == CT_UNIX2DOS)
fputc('\r', out); fputc('\r', out);
fputc('\n', out);
continue;
}
fputc(i, out); fputc(i, out);
} }
@ -62,7 +59,9 @@ static void convert(char *fn, int conv_type)
unlink(name_buf); unlink(name_buf);
bb_perror_nomsg_and_die(); bb_perror_nomsg_and_die();
} }
// TODO: destroys symlinks. See how passwd handles this
xrename(name_buf, fn); xrename(name_buf, fn);
free(name_buf);
} }
} }

View File

@ -941,20 +941,20 @@ extern void selinux_or_die(void);
extern int restricted_shell(const char *shell); extern int restricted_shell(const char *shell);
/* setup_environment: /* setup_environment:
* if loginshell = 1: cd(pw->pw_dir), clear environment, then set * if clear_env = 1: cd(pw->pw_dir), clear environment, then set
* TERM=(old value) * TERM=(old value)
* USER=pw->pw_name, LOGNAME=pw->pw_name * USER=pw->pw_name, LOGNAME=pw->pw_name
* PATH=bb_default_[root_]path * PATH=bb_default_[root_]path
* HOME=pw->pw_dir * HOME=pw->pw_dir
* SHELL=shell * SHELL=shell
* else if changeenv = 1: * else if change_env = 1:
* if not root (if pw->pw_uid != 0): * if not root (if pw->pw_uid != 0):
* USER=pw->pw_name, LOGNAME=pw->pw_name * USER=pw->pw_name, LOGNAME=pw->pw_name
* HOME=pw->pw_dir * HOME=pw->pw_dir
* SHELL=shell * SHELL=shell
* else does nothing * else does nothing
*/ */
extern void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw); extern void setup_environment(const char *shell, int clear_env, int change_env, const struct passwd *pw);
extern int correct_password(const struct passwd *pw); extern int correct_password(const struct passwd *pw);
/* Returns a ptr to static storage */ /* Returns a ptr to static storage */
extern char *pw_encrypt(const char *clear, const char *salt); extern char *pw_encrypt(const char *clear, const char *salt);

View File

@ -6,6 +6,8 @@
* 2. Do not use \t in messages, use real tab character. * 2. Do not use \t in messages, use real tab character.
* 3. Start each source line with message as follows: * 3. Start each source line with message as follows:
* |<7 spaces>"text with tabs".... * |<7 spaces>"text with tabs"....
* or
* |<5 spaces>"\ntext with tabs"....
*/ */
#ifndef __BB_USAGE_H__ #ifndef __BB_USAGE_H__
@ -14,14 +16,14 @@
#define addgroup_trivial_usage \ #define addgroup_trivial_usage \
"[-g GID]"USE_FEATURE_ADDUSER_TO_GROUP(" [user_name]")" group_name" "[-g GID]"USE_FEATURE_ADDUSER_TO_GROUP(" [user_name]")" group_name"
#define addgroup_full_usage \ #define addgroup_full_usage \
"Add a group to the system"USE_FEATURE_ADDUSER_TO_GROUP(" or add an user to a group") \ "Add a group"USE_FEATURE_ADDUSER_TO_GROUP(" or add an user to a group") \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -g GID Group id" " -g GID Group id"
#define adduser_trivial_usage \ #define adduser_trivial_usage \
"[OPTIONS] user_name" "[OPTIONS] user_name"
#define adduser_full_usage \ #define adduser_full_usage \
"Add a user to the system" \ "Add an user" \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -h DIR Home directory\n" \ " -h DIR Home directory\n" \
" -g GECOS GECOS field\n" \ " -g GECOS GECOS field\n" \
@ -63,17 +65,17 @@
"[-v] [-H type] [-i if] -s hostname hw_addr [netmask nm] pub\n" \ "[-v] [-H type] [-i if] -s hostname hw_addr [netmask nm] pub\n" \
"[-v] [-H type] [-i if] -Ds hostname ifa [netmask nm] pub\n" "[-v] [-H type] [-i if] -Ds hostname ifa [netmask nm] pub\n"
#define arp_full_usage \ #define arp_full_usage \
"Manipulate the system ARP cache" \ "Manipulate ARP cache" \
"\n\nOptions:" \ "\n\nOptions:" \
"\n -a Display (all) hosts" \ "\n -a Display (all) hosts" \
"\n -s Set a new ARP entry" \ "\n -s Set new ARP entry" \
"\n -d Delete a specified entry" \ "\n -d Delete a specified entry" \
"\n -v Verbose" \ "\n -v Verbose" \
"\n -n Don't resolve names" \ "\n -n Don't resolve names" \
"\n -i if Network interface (e.g. eth0)" \ "\n -i IF Network interface" \
"\n -D Read <hwaddr> from given device" \ "\n -D Read <hwaddr> from given device" \
"\n -A, -p Protocol family" \ "\n -A, -p AF Protocol family" \
"\n -H hwtype Hardware address type" "\n -H HWTYPE Hardware address type"
#define arping_trivial_usage \ #define arping_trivial_usage \
"[-fqbDUA] [-c count] [-w timeout] [-I dev] [-s sender] target" "[-fqbDUA] [-c count] [-w timeout] [-I dev] [-s sender] target"
@ -96,7 +98,7 @@
"[FILE]...\n" \ "[FILE]...\n" \
"or: ash -c command [args]..." "or: ash -c command [args]..."
#define ash_full_usage \ #define ash_full_usage \
"The ash shell (command interpreter)" "The ash shell"
#define awk_trivial_usage \ #define awk_trivial_usage \
"[OPTION]... [program-text] [FILE...]" "[OPTION]... [program-text] [FILE...]"
@ -124,38 +126,38 @@
#define brctl_full_usage \ #define brctl_full_usage \
"Manage ethernet bridges." \ "Manage ethernet bridges." \
"\n\nCommands:\n" \ "\n\nCommands:\n" \
" addbr <bridge> Create <bridge>\n" \ " addbr BRIDGE Create BRIDGE\n" \
" delbr <bridge> Delete <bridge>\n" \ " delbr BRIDGE Delete BRIDGE\n" \
" addif <bridge> <iface> Add <iface> to <bridge>\n" \ " addif BRIDGE IFACE Add IFACE to BRIDGE\n" \
" delif <bridge> <iface> Delete <iface> from <bridge>" \ " delif BRIDGE IFACE Delete IFACE from BRIDGE" \
USE_FEATURE_BRCTL_FANCY("\n" \ USE_FEATURE_BRCTL_FANCY("\n" \
" setageing <bridge <time> set ageing time\n" \ " setageing BRIDGE TIME Set ageing time\n" \
" setfd <bridge <time> set bridge forward delay\n" \ " setfd BRIDGE TIME Set bridge forward delay\n" \
" sethello <bridge <time> set hello time\n" \ " sethello BRIDGE TIME Set hello time\n" \
" setmaxage <bridge <time> set max message age\n" \ " setmaxage BRIDGE TIME Set max message age\n" \
" setpathcost <bridge <cost> set path cost\n" \ " setpathcost BRIDGE COST Set path cost\n" \
" setportprio <bridge <prio> set port priority\n" \ " setportprio BRIDGE PRIO Set port priority\n" \
" setbridgeprio <bridge <prio> set bridge priority\n" \ " setbridgeprio BRIDGE PRIO Set bridge priority\n" \
" stp <bridge> [1|0] turn stp on/off\n" \ " stp BRIDGE [1|0] STP on/off\n" \
) )
#define bunzip2_trivial_usage \ #define bunzip2_trivial_usage \
"[OPTION]... [FILE]" "[OPTION]... [FILE]"
#define bunzip2_full_usage \ #define bunzip2_full_usage \
"Uncompress FILE (or standard input if FILE is '-' or omitted)" \ "Uncompress FILE (or standard input if FILE is '-' or omitted)" \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -c Write output to standard output\n" \ " -c Write to standard output\n" \
" -f Force" " -f Force"
#define bzip2_trivial_usage \ #define bzip2_trivial_usage \
"[OPTION]... [FILE]..." "[OPTION]... [FILE]..."
#define bzip2_full_usage \ #define bzip2_full_usage \
"Compress FILE(s) with bzip2 algorithm.\n" \ "Compress FILE(s) with bzip2 algorithm.\n" \
"When FILE is '-' or unspecified, reads standard input. Implies -c." \ "When FILE is '-' or unspecified, reads standard input. Implies -c.\n" \
"\n\nOptions:" \ "\nOptions:" \
"\n -c Write output to standard output instead of FILE.bz2" \ "\n -c Write to standard output" \
"\n -d Decompress" \ "\n -d Decompress" \
"\n -f Force" \ "\n -f Force" \
"\n -1..-9 Compression level" "\n -1..-9 Compression level"
#define busybox_notes_usage \ #define busybox_notes_usage \
"Hello world!\n" "Hello world!\n"
@ -170,7 +172,7 @@ USE_FEATURE_BRCTL_FANCY("\n" \
#define unlzma_full_usage \ #define unlzma_full_usage \
"Uncompress FILE (or standard input if FILE is '-' or omitted)" \ "Uncompress FILE (or standard input if FILE is '-' or omitted)" \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -c Write output to standard output\n" \ " -c Write to standard output\n" \
" -f Force" " -f Force"
#define lzmacat_trivial_usage \ #define lzmacat_trivial_usage \
@ -742,7 +744,7 @@ USE_FEATURE_BRCTL_FANCY("\n" \
#define dnsd_trivial_usage \ #define dnsd_trivial_usage \
"[-c config] [-t seconds] [-p port] [-i iface-ip] [-d]" "[-c config] [-t seconds] [-p port] [-i iface-ip] [-d]"
#define dnsd_full_usage \ #define dnsd_full_usage \
"Small and static DNS server daemon" \ "Small static DNS server daemon" \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -c Config filename\n" \ " -c Config filename\n" \
" -t TTL in seconds\n" \ " -t TTL in seconds\n" \
@ -753,12 +755,11 @@ USE_FEATURE_BRCTL_FANCY("\n" \
#define dos2unix_trivial_usage \ #define dos2unix_trivial_usage \
"[option] [FILE]" "[option] [FILE]"
#define dos2unix_full_usage \ #define dos2unix_full_usage \
"Convert FILE from dos format to unix format. When no option\n" \ "Convert FILE from dos to unix format.\n" \
"is given, the input is converted to the opposite output format.\n" \ "When no file is given, use stdin/stdout.\n" \
"When no file is given, use stdin for input and stdout for output." \ "\nOptions:\n" \
"\n\nOptions:\n" \ "\n -u dos2unix" \
" -u Output will be in UNIX format\n" \ "\n -d unix2dos"
" -d Output will be in DOS format"
#define dpkg_trivial_usage \ #define dpkg_trivial_usage \
"[-ilCPru] [-F option] package_name" "[-ilCPru] [-F option] package_name"
@ -795,19 +796,19 @@ USE_FEATURE_BRCTL_FANCY("\n" \
SKIP_FEATURE_DU_DEFAULT_BLOCKSIZE_1K("512") \ SKIP_FEATURE_DU_DEFAULT_BLOCKSIZE_1K("512") \
" bytes." \ " bytes." \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -a Show sizes of files in addition to directories\n" \ " -a Show file sizes too\n" \
" -H Follow symlinks that are FILE command line args\n" \ " -H Follow symlinks on command line\n" \
" -L Follow all symlinks encountered\n" \ " -L Follow all symlinks\n" \
" -d N Limit output to directories (and files with -a) of depth < N\n" \ " -d N Limit output to directories (and files with -a) of depth < N\n" \
" -c Output a grand total\n" \ " -c Show grand total\n" \
" -l Count sizes many times if hard linked\n" \ " -l Count sizes many times if hard linked\n" \
" -s Display only a total for each argument\n" \ " -s Display only a total for each argument\n" \
" -x Skip directories on different filesystems\n" \ " -x Skip directories on different filesystems\n" \
USE_FEATURE_HUMAN_READABLE( \ USE_FEATURE_HUMAN_READABLE( \
" -h Print sizes in human readable format (e.g., 1K 243M 2G )\n" \ " -h Sizes in human readable format (e.g., 1K 243M 2G )\n" \
" -m Print sizes in megabytes\n" \ " -m Sizes in megabytes\n" \
) \ ) \
" -k Print sizes in kilobytes" \ " -k Sizes in kilobytes" \
USE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K("(default)") USE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K("(default)")
#define du_example_usage \ #define du_example_usage \
"$ du\n" \ "$ du\n" \
@ -1012,19 +1013,27 @@ USE_FEATURE_BRCTL_FANCY("\n" \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -n Don't verify after format" " -n Don't verify after format"
/* Looks like someone forgot to add this to config system */
#ifndef ENABLE_FEATURE_FDISK_BLKSIZE
# define ENABLE_FEATURE_FDISK_BLKSIZE 0
# define USE_FEATURE_FDISK_BLKSIZE(a)
#endif
#define fdisk_trivial_usage \ #define fdisk_trivial_usage \
"[-luv] [-C CYLINDERS] [-H HEADS] [-S SECTORS] [-b SSZ] DISK" "[-ul" USE_FEATURE_FDISK_BLKSIZE("s") "] " \
"[-C CYLINDERS] [-H HEADS] [-S SECTORS] [-b SSZ] DISK"
#define fdisk_full_usage \ #define fdisk_full_usage \
"Change partition table" \ "Change partition table\n" \
"\n\nOptions:\n" \ "\nOptions:\n" \
" -l List partition table(s)\n" \ "\n -u Start and End are in sectors (instead of cylinders)" \
" -u Give Start and End in sector (instead of cylinder) units\n" \ "\n -l Show partition table for each DISK, then exit" \
" -s PARTITION Give partition size(s) in blocks\n" \ USE_FEATURE_FDISK_BLKSIZE( \
" -b 2048 (for certain MO disks) use 2048-byte sectors\n" \ "\n -s Show partition sizes in kb for each DISK, then exit" \
" -C CYLINDERS Set the number of cylinders\n" \ ) \
" -H HEADS Set the number of heads\n" \ "\n -b 2048 (for certain MO disks) use 2048-byte sectors" \
" -S SECTORS Set the number of sectors\n" \ "\n -C CYLINDERS Set number of cylinders/heads/sectors" \
" -v Give fdisk version" "\n -H HEADS\n" \
"\n -S SECTORS" \
#define fetchmail_trivial_usage \ #define fetchmail_trivial_usage \
"[-w timeout] [-U user] -P password [-X] [-t] [-z] server[:port] maildir [prog]" "[-w timeout] [-U user] -P password [-X] [-t] [-z] server[:port] maildir [prog]"
@ -1032,25 +1041,25 @@ USE_FEATURE_BRCTL_FANCY("\n" \
"Fetch content of remote mailbox to local Maildir." \ "Fetch content of remote mailbox to local Maildir." \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -w timeout Set timeout on network operations\n" \ " -w timeout Set timeout on network operations\n" \
" -U username Authenticate with specified username\n" \ " -U username Authenticate with specified username/password\n" \
" -P password Authenticate with specified password\n" \ " -P password\n" \
" -X Use openssl connection helper for secured servers\n" \ " -X Use openssl connection helper for secured servers\n" \
" -t Get only headers\n" \ " -t Get only headers\n" \
" -z Delete messages on server\n" \ " -z Delete messages on server\n" \
" prog Run prog <message file> on message delivery" " prog Run prog <message_file> on message delivery"
#define findfs_trivial_usage \ #define findfs_trivial_usage \
"LABEL=label or UUID=uuid" "LABEL=label or UUID=uuid"
#define findfs_full_usage \ #define findfs_full_usage \
"Finds a filesystem device based on a label or UUID." "Find a filesystem device based on a label or UUID."
#define findfs_example_usage \ #define findfs_example_usage \
"$ findfs LABEL=MyDevice" "$ findfs LABEL=MyDevice"
#define find_trivial_usage \ #define find_trivial_usage \
"[PATH...] [EXPRESSION]" "[PATH...] [EXPRESSION]"
#define find_full_usage \ #define find_full_usage \
"Search for files in a directory hierarchy. The default PATH is\n" \ "Search for files. The default PATH is the current directory,\n" \
"the current directory, default EXPRESSION is '-print'\n" \ "default EXPRESSION is '-print'\n" \
"\nEXPRESSION may consist of:" \ "\nEXPRESSION may consist of:" \
"\n -follow Dereference symlinks" \ "\n -follow Dereference symlinks" \
USE_FEATURE_FIND_XDEV( \ USE_FEATURE_FIND_XDEV( \
@ -1202,15 +1211,15 @@ USE_FEATURE_BRCTL_FANCY("\n" \
) )
#define fuser_trivial_usage \ #define fuser_trivial_usage \
"[options] file OR port/proto" "[options] FILE or PORT/PROTO"
#define fuser_full_usage \ #define fuser_full_usage \
"Options:\n" \ "Options:\n" \
" -m Show all processes on the same mounted fs\n" \ " -m Show all processes on the same mounted fs\n" \
" -k Kill all processes that match\n" \
" -s Don't print or kill anything\n" \ " -s Don't print or kill anything\n" \
" -4 When using port/proto only search IPv4 space\n" \ " -4 Search only IPv4 space\n" \
" -6 When using port/proto only search IPv6 space\n" \ " -6 Search only IPv6 space\n" \
" -SIGNAL When used with -k, this signal will be used to kill" " -k Kill all processes that match\n" \
" -SIGNAL Signal to send (default: TERM)"
#define getenforce_trivial_usage #define getenforce_trivial_usage
#define getenforce_full_usage #define getenforce_full_usage
@ -1274,7 +1283,7 @@ USE_FEATURE_BRCTL_FANCY("\n" \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -h Enable hardware (RTS/CTS) flow control\n" \ " -h Enable hardware (RTS/CTS) flow control\n" \
" -i Do not display /etc/issue before running login\n" \ " -i Do not display /etc/issue before running login\n" \
" -L Local line, so do not do carrier detect\n" \ " -L Local line, do not do carrier detect\n" \
" -m Get baud rate from modem's CONNECT status message\n" \ " -m Get baud rate from modem's CONNECT status message\n" \
" -w Wait for a CR or LF before sending /etc/issue\n" \ " -w Wait for a CR or LF before sending /etc/issue\n" \
" -n Do not prompt the user for a login name\n" \ " -n Do not prompt the user for a login name\n" \
@ -1330,9 +1339,9 @@ USE_FEATURE_BRCTL_FANCY("\n" \
#define gunzip_full_usage \ #define gunzip_full_usage \
"Uncompress FILE (or standard input if FILE is '-')" \ "Uncompress FILE (or standard input if FILE is '-')" \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -c Write output to standard output\n" \ " -c Write to standard output\n" \
" -f Force\n" \ " -f Force\n" \
" -t Test compressed file integrity" " -t Test file integrity"
#define gunzip_example_usage \ #define gunzip_example_usage \
"$ ls -la /tmp/BusyBox*\n" \ "$ ls -la /tmp/BusyBox*\n" \
"-rw-rw-r-- 1 andersen andersen 557009 Apr 11 10:55 /tmp/BusyBox-0.43.tar.gz\n" \ "-rw-rw-r-- 1 andersen andersen 557009 Apr 11 10:55 /tmp/BusyBox-0.43.tar.gz\n" \
@ -1346,7 +1355,7 @@ USE_FEATURE_BRCTL_FANCY("\n" \
"Compress FILE(s) with maximum compression.\n" \ "Compress FILE(s) with maximum compression.\n" \
"When FILE is '-' or unspecified, reads standard input. Implies -c." \ "When FILE is '-' or unspecified, reads standard input. Implies -c." \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -c Write output to standard output instead of FILE.gz\n" \ " -c Write to standard output\n" \
" -d Decompress\n" \ " -d Decompress\n" \
" -f Force" " -f Force"
#define gzip_example_usage \ #define gzip_example_usage \
@ -1521,12 +1530,12 @@ USE_FEATURE_BRCTL_FANCY("\n" \
#define hwclock_full_usage \ #define hwclock_full_usage \
"Query and set a hardware clock (RTC)" \ "Query and set a hardware clock (RTC)" \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -r Read hardware clock and print result\n" \ " -r Show time from hardware clock\n" \
" -s Set the system time from the hardware clock\n" \ " -s Set system time from hardware clock\n" \
" -w Set the hardware clock to the system time\n" \ " -w Set hardware clock to system time\n" \
" -u The hardware clock is kept in coordinated universal time\n" \ " -u Hardware clock is in UTC\n" \
" -l The hardware clock is kept in local time\n" \ " -l Hardware clock is in local time\n" \
" -f FILE Use the specified clock (e.g. /dev/rtc2)" " -f FILE Use specified device (e.g. /dev/rtc2)"
#define id_trivial_usage \ #define id_trivial_usage \
"[OPTIONS]... [USERNAME]" "[OPTIONS]... [USERNAME]"
@ -1974,17 +1983,16 @@ USE_FEATURE_BRCTL_FANCY("\n" \
"5\n" "5\n"
#define less_trivial_usage \ #define less_trivial_usage \
"[-EMNmh~?] FILE1 FILE2..." "[-EMNmh~?] [FILE...]"
#define less_full_usage \ #define less_full_usage \
"View a file or list of files. The position within files can be\n" \ "View a file or list of files. The position within files can be\n" \
"changed, and files can be manipulated in various ways." \ "changed, and files can be manipulated in various ways." \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -E Quit once the end of a file is reached\n" \ " -E Quit once the end of a file is reached\n" \
" -M,-m Display a status line containing the current line numbers\n" \ " -M,-m Display a status line containing the line numbers\n" \
" and the percentage through the file\n" \ " and percentage through the file\n" \
" -N Prefix line numbers to each line\n" \ " -N Prefix line numbers to each line\n" \
" -~ Suppress ~s displayed when input past the end of the file is\n" \ " -~ Suppress ~s displayed past the end of the file" \
" reached"
#define setarch_trivial_usage \ #define setarch_trivial_usage \
"personality program [args...]" "personality program [args...]"
@ -2034,18 +2042,18 @@ USE_FEATURE_BRCTL_FANCY("\n" \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -s Log to stderr as well as the system log\n" \ " -s Log to stderr as well as the system log\n" \
" -t TAG Log using the specified tag (defaults to user name)\n" \ " -t TAG Log using the specified tag (defaults to user name)\n" \
" -p PRIO Enter the message with the specified priority.\n" \ " -p PRIO Priority (numeric or facility.level pair)"
" This may be numerical or a 'facility.level' pair."
#define logger_example_usage \ #define logger_example_usage \
"$ logger \"hello\"\n" "$ logger \"hello\"\n"
#define login_trivial_usage \ #define login_trivial_usage \
"[OPTION]... [username] [ENV=VAR...]" "[-p] [-h HOST] [[-f] USER]"
#define login_full_usage \ #define login_full_usage \
"Begin a new session on the system" \ "Begin a new session on the system" \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -f Do not authenticate (user already authenticated)\n" \ " -f Do not authenticate (user already authenticated)\n" \
" -h Name of the remote host for this login\n" \ " -h Name of the remote host\n" \
" -p Preserve environment" " -p Preserve environment"
#define logname_trivial_usage \ #define logname_trivial_usage \
@ -2059,9 +2067,9 @@ USE_FEATURE_BRCTL_FANCY("\n" \
#define logread_trivial_usage \ #define logread_trivial_usage \
"[OPTION]..." "[OPTION]..."
#define logread_full_usage \ #define logread_full_usage \
"Show the messages from syslogd (using circular buffer)" \ "Show messages in syslogd's circular buffer" \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -f Output data as the log grows" " -f Output data as log grows"
#define losetup_trivial_usage \ #define losetup_trivial_usage \
"[-o OFS] LOOPDEV FILE - associate loop devices\n" \ "[-o OFS] LOOPDEV FILE - associate loop devices\n" \
@ -2384,7 +2392,7 @@ USE_FEATURE_BRCTL_FANCY("\n" \
" -n [14|30] Maximum length of filenames\n" \ " -n [14|30] Maximum length of filenames\n" \
" -i INODES Number of inodes for the filesystem\n" \ " -i INODES Number of inodes for the filesystem\n" \
" -l FILENAME Read bad blocks list from FILENAME\n" \ " -l FILENAME Read bad blocks list from FILENAME\n" \
" -v Make a Minix version 2 filesystem" " -v Make version 2 filesystem"
#define mknod_trivial_usage \ #define mknod_trivial_usage \
"[OPTIONS] NAME TYPE MAJOR MINOR" "[OPTIONS] NAME TYPE MAJOR MINOR"
@ -2809,30 +2817,28 @@ USE_FEATURE_BRCTL_FANCY("\n" \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -l Show command name too\n" \ " -l Show command name too\n" \
" -f Match against entire command line\n" \ " -f Match against entire command line\n" \
" -n Signal the newest process only\n" \ " -n Show the newest process only\n" \
" -o Signal the oldest process only\n" \ " -o Show the oldest process only\n" \
" -v Negate the matching\n" \ " -v Negate the matching\n" \
" -x Match whole name (not substring)" " -x Match whole name (not substring)"
#if (ENABLE_FEATURE_PIDOF_SINGLE || ENABLE_FEATURE_PIDOF_OMIT) #if (ENABLE_FEATURE_PIDOF_SINGLE || ENABLE_FEATURE_PIDOF_OMIT)
#define USAGE_PIDOF "Options:"
#else
#define USAGE_PIDOF "\nThis version of pidof accepts no options."
#endif
#define pidof_trivial_usage \ #define pidof_trivial_usage \
"process-name [OPTION] [process-name...]" "[OPTION] [NAME...]"
#define USAGE_PIDOF "\n\nOptions:"
#else
#define pidof_trivial_usage \
"[NAME...]"
#define USAGE_PIDOF /* none */
#endif
#define pidof_full_usage \ #define pidof_full_usage \
"List the PIDs of all processes with names that match the\n" \ "List PIDs of all processes with names that match NAMEs" \
"names on the command line\n" \
USAGE_PIDOF \ USAGE_PIDOF \
USE_FEATURE_PIDOF_SINGLE( \ USE_FEATURE_PIDOF_SINGLE( \
"\n -s Display only a single PID") \ "\n -s Show only one PID") \
USE_FEATURE_PIDOF_OMIT( \ USE_FEATURE_PIDOF_OMIT( \
"\n -o PID Omit given pid") \ "\n -o PID Omit given pid" \
USE_FEATURE_PIDOF_OMIT( \ "\n Use %PPID to omit pid of pidof's parent")
"\n Use %PPID to omit the parent pid of pidof itself")
#define pidof_example_usage \ #define pidof_example_usage \
"$ pidof init\n" \ "$ pidof init\n" \
"1\n" \ "1\n" \
@ -3090,12 +3096,12 @@ USE_FEATURE_BRCTL_FANCY("\n" \
#define rm_trivial_usage \ #define rm_trivial_usage \
"[OPTION]... FILE..." "[OPTION]... FILE..."
#define rm_full_usage \ #define rm_full_usage \
"Remove (unlink) the FILE(s). You may use '--' to\n" \ "Remove (unlink) the FILE(s). Use '--' to\n" \
"indicate that all following arguments are non-options." \ "indicate that all following arguments are non-options." \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -i Always prompt before removing each destination\n" \ " -i Always prompt before removing\n" \
" -f Remove existing destinations, never prompt\n" \ " -f Never prompt\n" \
" -r,-R Remove the contents of directories recursively" " -r,-R Remove directories recursively"
#define rm_example_usage \ #define rm_example_usage \
"$ rm -rf /tmp/foo\n" "$ rm -rf /tmp/foo\n"
@ -3189,12 +3195,14 @@ USE_FEATURE_BRCTL_FANCY("\n" \
#define run_parts_trivial_usage \ #define run_parts_trivial_usage \
"[-t] "USE_FEATURE_RUN_PARTS_FANCY("[-l] ")"[-a ARG] [-u MASK] DIRECTORY" "[-t] "USE_FEATURE_RUN_PARTS_FANCY("[-l] ")"[-a ARG] [-u MASK] DIRECTORY"
#define run_parts_full_usage \ #define run_parts_full_usage \
"Run a bunch of scripts in a directory" \ "Run a bunch of scripts in a directory\n" \
"\n\nOptions:\n" \ "\nOptions:" \
" -t Prints what would be run, but does not actually run anything\n" \ "\n -t Print what would be run, but don't actually run anything" \
" -a ARG Pass ARG as an argument for every program invoked\n" \ "\n -a ARG Pass ARG as argument for every program" \
" -u MASK Set the umask to MASK before executing every program" \ "\n -u MASK Set the umask to MASK before running every program" \
USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when they are not executable") USE_FEATURE_RUN_PARTS_FANCY( \
"\n -l Print names of all matching files even if they are not executable" \
)
#define run_parts_example_usage \ #define run_parts_example_usage \
"$ run-parts -a start /etc/init.d\n" \ "$ run-parts -a start /etc/init.d\n" \
@ -3251,7 +3259,7 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
#define sed_full_usage \ #define sed_full_usage \
"Options:\n" \ "Options:\n" \
" -e script Add the script to the commands to be executed\n" \ " -e script Add the script to the commands to be executed\n" \
" -f scriptfile Add script-file contents to the\n" \ " -f scriptfile Add scriptfile contents to the\n" \
" commands to be executed\n" \ " commands to be executed\n" \
" -i Edit files in-place\n" \ " -i Edit files in-place\n" \
" -n Suppress automatic printing of pattern space\n" \ " -n Suppress automatic printing of pattern space\n" \
@ -3276,9 +3284,9 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
"Send an email with optional attachments." \ "Send an email with optional attachments." \
"\n\nOptions:\n" \ "\n\nOptions:\n" \
" -w timeout Set timeout on network operations\n" \ " -w timeout Set timeout on network operations\n" \
" -U username Authenticate with specified username\n" \ " -U username Authenticate with specified username/password\n" \
" -P password Authenticate with specified password\n" \ " -P password\n" \
" -t address Recipient(s). May be multiple\n" \ " -t address Recipient(s). May be repeated\n" \
" -X Use openssl connection helper for secured servers\n" \ " -X Use openssl connection helper for secured servers\n" \
" -n Request delivery notification to sender\n" \ " -n Request delivery notification to sender\n" \
" -s subject Subject\n" \ " -s subject Subject\n" \
@ -3813,19 +3821,15 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
#define telnet_trivial_usage \ #define telnet_trivial_usage \
"[-a] [-l USER] HOST [PORT]" "[-a] [-l USER] HOST [PORT]"
#define telnet_full_usage \ #define telnet_full_usage \
"Connect to remote telnet server" \ "Connect to telnet server\n" \
"\n\nOptions:\n" \ "\nOptions:" \
" -a Attempt an automatic login with the USER variable\n" \ "\n -a Attempt an automatic login with USER variable" \
" -l USER Attempt an automatic login with the USER argument\n" \ "\n -l USER Attempt an automatic login with USER argument"
" HOST The official name, alias or the IP address of the\n" \
" remote host\n" \
" PORT The remote port number to connect to. If it is not\n" \
" specified, the default telnet (23) port is used."
#else #else
#define telnet_trivial_usage \ #define telnet_trivial_usage \
"HOST [PORT]" "HOST [PORT]"
#define telnet_full_usage \ #define telnet_full_usage \
"Connect to remote telnet server" "Connect to telnet server"
#endif #endif
#define telnetd_trivial_usage \ #define telnetd_trivial_usage \
@ -3869,9 +3873,8 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
/* with not-implemented options: */ /* with not-implemented options: */
/* "[-hpEvv] [-c n] [-C n:msg] [-b n] [-u user] [-l name] [-i dir|-x cdb] [-t sec] ip port prog..." */ /* "[-hpEvv] [-c n] [-C n:msg] [-b n] [-u user] [-l name] [-i dir|-x cdb] [-t sec] ip port prog..." */
#define tcpsvd_full_usage \ #define tcpsvd_full_usage \
"Creates TCP socket, binds it to ip:port and listens on it\n" \ "Create TCP socket, bind it to ip:port and listen\n" \
"for incoming connections. For each connection it runs prog." \ "for incoming connection. Run PROG for each connection.\n" \
"\n" \
"\nip IP to listen on. '0' = all" \ "\nip IP to listen on. '0' = all" \
"\nport Port to listen on" \ "\nport Port to listen on" \
"\nprog [arg] Program to run" \ "\nprog [arg] Program to run" \
@ -3889,10 +3892,9 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
#define udpsvd_trivial_usage \ #define udpsvd_trivial_usage \
"[-hEv] [-c n] [-u user] [-l name] ip port prog" "[-hEv] [-c n] [-u user] [-l name] ip port prog"
#define udpsvd_full_usage \ #define udpsvd_full_usage \
"Creates UDP socket, binds it to ip:port and listens on it\n" \ "Create UDP socket, bind it to ip:port and wait\n" \
"for incoming packets. For each packet it runs prog\n" \ "for incoming packets. Run PROG for each packet,\n" \
"(redirecting all further packets with same peer ip:port to it)." \ "redirecting all further packets with same peer ip:port to it\n" \
"\n" \
"\nip IP to listen on. '0' = all" \ "\nip IP to listen on. '0' = all" \
"\nport Port to listen on" \ "\nport Port to listen on" \
"\nprog [arg] Program to run" \ "\nprog [arg] Program to run" \
@ -3928,10 +3930,10 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
" -v Verbose" " -v Verbose"
#define top_trivial_usage \ #define top_trivial_usage \
"[-b] [-n count] [-d seconds]" "[-b] [-n COUNT] [-d SECONDS]"
#define top_full_usage \ #define top_full_usage \
"Provide a view of process activity in real time.\n" \ "Provide a view of process activity in real time.\n" \
"Read the status of all processes from /proc each <seconds>\n" \ "Read the status of all processes from /proc each SECONDS\n" \
"and show the status for however many processes will fit on the screen." "and show the status for however many processes will fit on the screen."
#define touch_trivial_usage \ #define touch_trivial_usage \
@ -4164,12 +4166,11 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
#define unix2dos_trivial_usage \ #define unix2dos_trivial_usage \
"[option] [FILE]" "[option] [FILE]"
#define unix2dos_full_usage \ #define unix2dos_full_usage \
"Convert FILE from unix format to dos format. When no option\n" \ "Convert FILE from unix to dos format.\n" \
"is given, the input is converted to the opposite output format.\n" \ "When no file is given, use stdin/stdout.\n" \
"When no file is given, use stdin/stdout." \ "\nOptions:\n" \
"\n\nOptions:\n" \ "\n -u dos2unix" \
" -u Output will be in UNIX format\n" \ "\n -d unix2dos"
" -d Output will be in DOS format"
#define unzip_trivial_usage \ #define unzip_trivial_usage \
"[-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]" "[-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]"

View File

@ -30,16 +30,16 @@
#include "libbb.h" #include "libbb.h"
void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw) void setup_environment(const char *shell, int clear_env, int change_env, const struct passwd *pw)
{ {
if (loginshell) { if (clear_env) {
const char *term; const char *term;
/* Change the current working directory to be the home directory /* Change the current working directory to be the home directory
* of the user */ * of the user */
if (chdir(pw->pw_dir)) { if (chdir(pw->pw_dir)) {
xchdir("/"); xchdir("/");
fputs("warning: cannot change to home directory\n", stderr); bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir);
} }
/* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH. /* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH.
@ -56,7 +56,7 @@ void setup_environment(const char *shell, int loginshell, int changeenv, const s
//xsetenv("HOME", pw->pw_dir); //xsetenv("HOME", pw->pw_dir);
//xsetenv("SHELL", shell); //xsetenv("SHELL", shell);
} }
else if (changeenv) { else if (change_env) {
/* Set HOME, SHELL, and if not becoming a super-user, /* Set HOME, SHELL, and if not becoming a super-user,
USER and LOGNAME. */ USER and LOGNAME. */
if (pw->pw_uid) { if (pw->pw_uid) {

View File

@ -237,8 +237,8 @@ int login_main(int argc, char **argv)
unsigned opt; unsigned opt;
int count = 0; int count = 0;
struct passwd *pw; struct passwd *pw;
char *opt_host = NULL; char *opt_host = opt_host; /* for compiler */
char *opt_user = NULL; char *opt_user = opt_user; /* for compiler */
char full_tty[TTYNAME_SIZE]; char full_tty[TTYNAME_SIZE];
USE_SELINUX(security_context_t user_sid = NULL;) USE_SELINUX(security_context_t user_sid = NULL;)
USE_FEATURE_UTMP(struct utmp utent;) USE_FEATURE_UTMP(struct utmp utent;)
@ -287,7 +287,7 @@ int login_main(int argc, char **argv)
read_or_build_utent(&utent, !amroot); read_or_build_utent(&utent, !amroot);
if (opt_host) { if (opt & LOGIN_OPT_h) {
USE_FEATURE_UTMP( USE_FEATURE_UTMP(
safe_strncpy(utent.ut_host, opt_host, sizeof(utent.ut_host)); safe_strncpy(utent.ut_host, opt_host, sizeof(utent.ut_host));
) )
@ -450,9 +450,12 @@ int login_main(int argc, char **argv)
xsetenv("LOGIN_UID", utoa(pw->pw_uid)); xsetenv("LOGIN_UID", utoa(pw->pw_uid));
xsetenv("LOGIN_GID", utoa(pw->pw_gid)); xsetenv("LOGIN_GID", utoa(pw->pw_gid));
xsetenv("LOGIN_SHELL", pw->pw_shell); xsetenv("LOGIN_SHELL", pw->pw_shell);
xspawn(t_argv); /* NOMMU-friendly */ spawn_and_wait(t_argv); /* NOMMU-friendly */
/* All variables are unset by setup_environment */ unsetenv("LOGIN_TTY" );
wait(NULL); unsetenv("LOGIN_USER" );
unsetenv("LOGIN_UID" );
unsetenv("LOGIN_GID" );
unsetenv("LOGIN_SHELL");
} }
} }
@ -460,9 +463,8 @@ int login_main(int argc, char **argv)
tmp = pw->pw_shell; tmp = pw->pw_shell;
if (!tmp || !*tmp) if (!tmp || !*tmp)
tmp = DEFAULT_SHELL; tmp = DEFAULT_SHELL;
/* setup_environment params: shell, loginshell, changeenv, pw */ /* setup_environment params: shell, clear_env, change_env, pw */
setup_environment(tmp, 1, !(opt & LOGIN_OPT_p), pw); setup_environment(tmp, !(opt & LOGIN_OPT_p), 1, pw);
/* FIXME: login shell = 1 -> 3rd parameter is ignored! */
motd(); motd();

View File

@ -93,7 +93,7 @@ int su_main(int argc, char **argv)
opt_shell = pw->pw_shell; opt_shell = pw->pw_shell;
change_identity(pw); change_identity(pw);
/* setup_environment params: shell, loginshell, changeenv, pw */ /* setup_environment params: shell, clear_env, change_env, pw */
setup_environment(opt_shell, flags & SU_OPT_l, !(flags & SU_OPT_mp), pw); setup_environment(opt_shell, flags & SU_OPT_l, !(flags & SU_OPT_mp), pw);
USE_SELINUX(set_current_security_context(NULL);) USE_SELINUX(set_current_security_context(NULL);)

View File

@ -72,8 +72,9 @@ int pgrep_main(int argc, char **argv)
first_arg = argv[first_arg_idx]; first_arg = argv[first_arg_idx];
if (!first_arg) if (!first_arg)
break; break;
/* not "-<small_letter>..."? */
if (first_arg[0] != '-' || first_arg[1] < 'a' || first_arg[1] > 'z') { if (first_arg[0] != '-' || first_arg[1] < 'a' || first_arg[1] > 'z') {
argv[first_arg_idx] = NULL; argv[first_arg_idx] = NULL; /* terminate argv here */
break; break;
} }
first_arg_idx++; first_arg_idx++;

View File

@ -318,6 +318,23 @@ struct globals {
} while (0) } while (0)
/* TODO: move to libbb? */
static ullong bb_BLKGETSIZE_sectors(void)
{
uint64_t v64;
unsigned long longsectors;
if (ioctl(fd, BLKGETSIZE64, &v64) == 0) {
/* got bytes, convert to 512 byte sectors */
return (v64 >> 9);
}
/* Needs temp of type long */
if (ioctl(fd, BLKGETSIZE, &longsectors))
longsectors = 0;
return longsectors;
}
#define IS_EXTENDED(i) \ #define IS_EXTENDED(i) \
((i) == EXTENDED || (i) == WIN98_EXTENDED || (i) == LINUX_EXTENDED) ((i) == EXTENDED || (i) == WIN98_EXTENDED || (i) == LINUX_EXTENDED)
@ -624,12 +641,12 @@ get_nr_sects(const struct partition *p)
/* normally O_RDWR, -l option gives O_RDONLY */ /* normally O_RDWR, -l option gives O_RDONLY */
static int type_open = O_RDWR; static int type_open = O_RDWR;
static int ext_index; /* the prime extended partition */ static int ext_index; /* the prime extended partition */
static smallint listing; /* no aborts for fdisk -l */ static smallint listing; /* no aborts for fdisk -l */
static int dos_compatible_flag = ~0; static smallint dos_compatible_flag = 1;
#if ENABLE_FEATURE_FDISK_WRITABLE #if ENABLE_FEATURE_FDISK_WRITABLE
//static int dos_changed; //static int dos_changed;
static smallint nowarn; /* no warnings for fdisk -l/-s */ static smallint nowarn; /* no warnings for fdisk -l/-s */
#endif #endif
static unsigned user_cylinders, user_heads, user_sectors; static unsigned user_cylinders, user_heads, user_sectors;
@ -1184,7 +1201,6 @@ static void
get_geometry(void) get_geometry(void)
{ {
int sec_fac; int sec_fac;
uint64_t v64;
get_sectorsize(); get_sectorsize();
sec_fac = sector_size / 512; sec_fac = sector_size / 512;
@ -1204,15 +1220,7 @@ get_geometry(void)
g_sectors = user_sectors ? user_sectors : g_sectors = user_sectors ? user_sectors :
pt_sectors ? pt_sectors : pt_sectors ? pt_sectors :
kern_sectors ? kern_sectors : 63; kern_sectors ? kern_sectors : 63;
if (ioctl(fd, BLKGETSIZE64, &v64) == 0) { total_number_of_sectors = bb_BLKGETSIZE_sectors();
/* got bytes, convert to 512 byte sectors */
total_number_of_sectors = (v64 >> 9);
} else {
unsigned long longsectors; /* need temp of type long */
if (ioctl(fd, BLKGETSIZE, &longsectors))
longsectors = 0;
total_number_of_sectors = longsectors;
}
sector_offset = 1; sector_offset = 1;
if (dos_compatible_flag) if (dos_compatible_flag)
@ -1576,7 +1584,7 @@ toggle_active(int i)
static void static void
toggle_dos_compatibility_flag(void) toggle_dos_compatibility_flag(void)
{ {
dos_compatible_flag = ~dos_compatible_flag; dos_compatible_flag = 1 - dos_compatible_flag;
if (dos_compatible_flag) { if (dos_compatible_flag) {
sector_offset = g_sectors; sector_offset = g_sectors;
printf("DOS Compatibility flag is set\n"); printf("DOS Compatibility flag is set\n");
@ -2732,7 +2740,8 @@ tryprocpt(void)
if (sscanf(line, " %d %d %d %[^\n ]", if (sscanf(line, " %d %d %d %[^\n ]",
&ma, &mi, &sz, ptname) != 4) &ma, &mi, &sz, ptname) != 4)
continue; continue;
for (s = ptname; *s; s++); for (s = ptname; *s; s++)
continue;
if (isdigit(s[-1])) if (isdigit(s[-1]))
continue; continue;
sprintf(devname, "/dev/%s", ptname); sprintf(devname, "/dev/%s", ptname);
@ -2798,28 +2807,19 @@ int fdisk_main(int argc, char **argv)
if (opt & OPT_u) if (opt & OPT_u)
display_in_cyl_units = 0; // -u display_in_cyl_units = 0; // -u
if (user_set_sector_size && argc != 1)
printf("Warning: the -b (set sector size) option should"
" be used with one specified device\n");
#if ENABLE_FEATURE_FDISK_WRITABLE #if ENABLE_FEATURE_FDISK_WRITABLE
if (opt & OPT_l) { if (opt & OPT_l) {
nowarn = 1; nowarn = 1;
#endif #endif
type_open = O_RDONLY; type_open = O_RDONLY;
if (argc > 0) { if (*argv) {
int k;
#if defined(__GNUC__)
/* avoid gcc warning:
variable `k' might be clobbered by `longjmp' */
(void)&k;
#endif
listing = 1; listing = 1;
for (k = 0; k < argc; k++) do {
trydev(argv[k], 1); trydev(*argv, 1);
} while (*++argv);
} else { } else {
/* we no longer have default device names */ /* we don't have device names, */
/* but, we can use /proc/partitions instead */ /* use /proc/partitions instead */
tryprocpt(); tryprocpt();
} }
return 0; return 0;
@ -2829,27 +2829,20 @@ int fdisk_main(int argc, char **argv)
#if ENABLE_FEATURE_FDISK_BLKSIZE #if ENABLE_FEATURE_FDISK_BLKSIZE
if (opt & OPT_s) { if (opt & OPT_s) {
long size;
int j; int j;
nowarn = 1; nowarn = 1;
type_open = O_RDONLY;
if (argc <= 0) if (argc <= 0)
bb_show_usage(); bb_show_usage();
for (j = 0; j < argc; j++) { for (j = 0; j < argc; j++) {
disk_device = argv[j]; unsigned long long size;
fd = open(disk_device, type_open); fd = xopen(argv[j], O_RDONLY);
if (fd < 0) size = bb_BLKGETSIZE_sectors() / 2;
fdisk_fatal(unable_to_open);
if (ioctl(fd, BLKGETSIZE, &size))
fdisk_fatal(ioctl_error);
close(fd); close(fd);
if (argc == 1) if (argc == 1)
printf("%ld\n", size/2); printf("%lld\n", size);
else else
printf("%s: %ld\n", argv[j], size/2); printf("%s: %lld\n", argv[j], size);
} }
return 0; return 0;
} }