aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-03-17 08:42:43 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-03-17 08:42:43 +0000
commitcdf62770af9e8bf7d5bb2344ddef8acb3216cfe2 (patch)
treef3c72eba4318ead484dfb36c6e21d55f443c5f6b
parent107fe7c081c2e0ab96628b431d9d812cdf9c82b2 (diff)
downloadbusybox-w32-cdf62770af9e8bf7d5bb2344ddef8acb3216cfe2.tar.gz
busybox-w32-cdf62770af9e8bf7d5bb2344ddef8acb3216cfe2.tar.bz2
busybox-w32-cdf62770af9e8bf7d5bb2344ddef8acb3216cfe2.zip
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
-rw-r--r--coreutils/dos2unix.c15
-rw-r--r--include/libbb.h6
-rw-r--r--include/usage.h277
-rw-r--r--libbb/setup_environment.c8
-rw-r--r--loginutils/login.c20
-rw-r--r--loginutils/su.c2
-rw-r--r--procps/pgrep.c3
-rw-r--r--util-linux/fdisk.c79
8 files changed, 203 insertions, 207 deletions
diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c
index 7776133f4..2db7e11a1 100644
--- a/coreutils/dos2unix.c
+++ b/coreutils/dos2unix.c
@@ -24,19 +24,19 @@ static void convert(char *fn, int conv_type)
24{ 24{
25 FILE *in, *out; 25 FILE *in, *out;
26 int i; 26 int i;
27#define name_buf bb_common_bufsiz1 27 char *name_buf = name_buf; /* for compiler */
28 28
29 in = stdin; 29 in = stdin;
30 out = stdout; 30 out = stdout;
31 if (fn != NULL) { 31 if (fn != NULL) {
32 in = xfopen(fn, "rw"); 32 in = xfopen(fn, "r");
33 /* 33 /*
34 The file is then created with mode read/write and 34 The file is then created with mode read/write and
35 permissions 0666 for glibc 2.0.6 and earlier or 35 permissions 0666 for glibc 2.0.6 and earlier or
36 0600 for glibc 2.0.7 and later. 36 0600 for glibc 2.0.7 and later.
37 */ 37 */
38 snprintf(name_buf, sizeof(name_buf), "%sXXXXXX", fn); 38 name_buf = xasprintf("%sXXXXXX", fn);
39 i = mkstemp(&name_buf[0]); 39 i = mkstemp(name_buf);
40 if (i == -1 40 if (i == -1
41 || fchmod(i, 0600) == -1 41 || fchmod(i, 0600) == -1
42 || !(out = fdopen(i, "w+")) 42 || !(out = fdopen(i, "w+"))
@@ -48,12 +48,9 @@ static void convert(char *fn, int conv_type)
48 while ((i = fgetc(in)) != EOF) { 48 while ((i = fgetc(in)) != EOF) {
49 if (i == '\r') 49 if (i == '\r')
50 continue; 50 continue;
51 if (i == '\n') { 51 if (i == '\n')
52 if (conv_type == CT_UNIX2DOS) 52 if (conv_type == CT_UNIX2DOS)
53 fputc('\r', out); 53 fputc('\r', out);
54 fputc('\n', out);
55 continue;
56 }
57 fputc(i, out); 54 fputc(i, out);
58 } 55 }
59 56
@@ -62,7 +59,9 @@ static void convert(char *fn, int conv_type)
62 unlink(name_buf); 59 unlink(name_buf);
63 bb_perror_nomsg_and_die(); 60 bb_perror_nomsg_and_die();
64 } 61 }
62// TODO: destroys symlinks. See how passwd handles this
65 xrename(name_buf, fn); 63 xrename(name_buf, fn);
64 free(name_buf);
66 } 65 }
67} 66}
68 67
diff --git a/include/libbb.h b/include/libbb.h
index 73638a145..09deba671 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -941,20 +941,20 @@ extern void selinux_or_die(void);
941extern int restricted_shell(const char *shell); 941extern int restricted_shell(const char *shell);
942 942
943/* setup_environment: 943/* setup_environment:
944 * if loginshell = 1: cd(pw->pw_dir), clear environment, then set 944 * if clear_env = 1: cd(pw->pw_dir), clear environment, then set
945 * TERM=(old value) 945 * TERM=(old value)
946 * USER=pw->pw_name, LOGNAME=pw->pw_name 946 * USER=pw->pw_name, LOGNAME=pw->pw_name
947 * PATH=bb_default_[root_]path 947 * PATH=bb_default_[root_]path
948 * HOME=pw->pw_dir 948 * HOME=pw->pw_dir
949 * SHELL=shell 949 * SHELL=shell
950 * else if changeenv = 1: 950 * else if change_env = 1:
951 * if not root (if pw->pw_uid != 0): 951 * if not root (if pw->pw_uid != 0):
952 * USER=pw->pw_name, LOGNAME=pw->pw_name 952 * USER=pw->pw_name, LOGNAME=pw->pw_name
953 * HOME=pw->pw_dir 953 * HOME=pw->pw_dir
954 * SHELL=shell 954 * SHELL=shell
955 * else does nothing 955 * else does nothing
956 */ 956 */
957extern void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw); 957extern void setup_environment(const char *shell, int clear_env, int change_env, const struct passwd *pw);
958extern int correct_password(const struct passwd *pw); 958extern int correct_password(const struct passwd *pw);
959/* Returns a ptr to static storage */ 959/* Returns a ptr to static storage */
960extern char *pw_encrypt(const char *clear, const char *salt); 960extern char *pw_encrypt(const char *clear, const char *salt);
diff --git a/include/usage.h b/include/usage.h
index 76beb176f..fdf96d256 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -6,6 +6,8 @@
6 * 2. Do not use \t in messages, use real tab character. 6 * 2. Do not use \t in messages, use real tab character.
7 * 3. Start each source line with message as follows: 7 * 3. Start each source line with message as follows:
8 * |<7 spaces>"text with tabs".... 8 * |<7 spaces>"text with tabs"....
9 * or
10 * |<5 spaces>"\ntext with tabs"....
9 */ 11 */
10 12
11#ifndef __BB_USAGE_H__ 13#ifndef __BB_USAGE_H__
@@ -14,14 +16,14 @@
14#define addgroup_trivial_usage \ 16#define addgroup_trivial_usage \
15 "[-g GID]"USE_FEATURE_ADDUSER_TO_GROUP(" [user_name]")" group_name" 17 "[-g GID]"USE_FEATURE_ADDUSER_TO_GROUP(" [user_name]")" group_name"
16#define addgroup_full_usage \ 18#define addgroup_full_usage \
17 "Add a group to the system"USE_FEATURE_ADDUSER_TO_GROUP(" or add an user to a group") \ 19 "Add a group"USE_FEATURE_ADDUSER_TO_GROUP(" or add an user to a group") \
18 "\n\nOptions:\n" \ 20 "\n\nOptions:\n" \
19 " -g GID Group id" 21 " -g GID Group id"
20 22
21#define adduser_trivial_usage \ 23#define adduser_trivial_usage \
22 "[OPTIONS] user_name" 24 "[OPTIONS] user_name"
23#define adduser_full_usage \ 25#define adduser_full_usage \
24 "Add a user to the system" \ 26 "Add an user" \
25 "\n\nOptions:\n" \ 27 "\n\nOptions:\n" \
26 " -h DIR Home directory\n" \ 28 " -h DIR Home directory\n" \
27 " -g GECOS GECOS field\n" \ 29 " -g GECOS GECOS field\n" \
@@ -63,17 +65,17 @@
63 "[-v] [-H type] [-i if] -s hostname hw_addr [netmask nm] pub\n" \ 65 "[-v] [-H type] [-i if] -s hostname hw_addr [netmask nm] pub\n" \
64 "[-v] [-H type] [-i if] -Ds hostname ifa [netmask nm] pub\n" 66 "[-v] [-H type] [-i if] -Ds hostname ifa [netmask nm] pub\n"
65#define arp_full_usage \ 67#define arp_full_usage \
66 "Manipulate the system ARP cache" \ 68 "Manipulate ARP cache" \
67 "\n\nOptions:" \ 69 "\n\nOptions:" \
68 "\n -a Display (all) hosts" \ 70 "\n -a Display (all) hosts" \
69 "\n -s Set a new ARP entry" \ 71 "\n -s Set new ARP entry" \
70 "\n -d Delete a specified entry" \ 72 "\n -d Delete a specified entry" \
71 "\n -v Verbose" \ 73 "\n -v Verbose" \
72 "\n -n Don't resolve names" \ 74 "\n -n Don't resolve names" \
73 "\n -i if Network interface (e.g. eth0)" \ 75 "\n -i IF Network interface" \
74 "\n -D Read <hwaddr> from given device" \ 76 "\n -D Read <hwaddr> from given device" \
75 "\n -A, -p Protocol family" \ 77 "\n -A, -p AF Protocol family" \
76 "\n -H hwtype Hardware address type" 78 "\n -H HWTYPE Hardware address type"
77 79
78#define arping_trivial_usage \ 80#define arping_trivial_usage \
79 "[-fqbDUA] [-c count] [-w timeout] [-I dev] [-s sender] target" 81 "[-fqbDUA] [-c count] [-w timeout] [-I dev] [-s sender] target"
@@ -96,7 +98,7 @@
96 "[FILE]...\n" \ 98 "[FILE]...\n" \
97 "or: ash -c command [args]..." 99 "or: ash -c command [args]..."
98#define ash_full_usage \ 100#define ash_full_usage \
99 "The ash shell (command interpreter)" 101 "The ash shell"
100 102
101#define awk_trivial_usage \ 103#define awk_trivial_usage \
102 "[OPTION]... [program-text] [FILE...]" 104 "[OPTION]... [program-text] [FILE...]"
@@ -124,38 +126,38 @@
124#define brctl_full_usage \ 126#define brctl_full_usage \
125 "Manage ethernet bridges." \ 127 "Manage ethernet bridges." \
126 "\n\nCommands:\n" \ 128 "\n\nCommands:\n" \
127 " addbr <bridge> Create <bridge>\n" \ 129 " addbr BRIDGE Create BRIDGE\n" \
128 " delbr <bridge> Delete <bridge>\n" \ 130 " delbr BRIDGE Delete BRIDGE\n" \
129 " addif <bridge> <iface> Add <iface> to <bridge>\n" \ 131 " addif BRIDGE IFACE Add IFACE to BRIDGE\n" \
130 " delif <bridge> <iface> Delete <iface> from <bridge>" \ 132 " delif BRIDGE IFACE Delete IFACE from BRIDGE" \
131USE_FEATURE_BRCTL_FANCY("\n" \ 133USE_FEATURE_BRCTL_FANCY("\n" \
132 " setageing <bridge <time> set ageing time\n" \ 134 " setageing BRIDGE TIME Set ageing time\n" \
133 " setfd <bridge <time> set bridge forward delay\n" \ 135 " setfd BRIDGE TIME Set bridge forward delay\n" \
134 " sethello <bridge <time> set hello time\n" \ 136 " sethello BRIDGE TIME Set hello time\n" \
135 " setmaxage <bridge <time> set max message age\n" \ 137 " setmaxage BRIDGE TIME Set max message age\n" \
136 " setpathcost <bridge <cost> set path cost\n" \ 138 " setpathcost BRIDGE COST Set path cost\n" \
137 " setportprio <bridge <prio> set port priority\n" \ 139 " setportprio BRIDGE PRIO Set port priority\n" \
138 " setbridgeprio <bridge <prio> set bridge priority\n" \ 140 " setbridgeprio BRIDGE PRIO Set bridge priority\n" \
139 " stp <bridge> [1|0] turn stp on/off\n" \ 141 " stp BRIDGE [1|0] STP on/off\n" \
140) 142)
141#define bunzip2_trivial_usage \ 143#define bunzip2_trivial_usage \
142 "[OPTION]... [FILE]" 144 "[OPTION]... [FILE]"
143#define bunzip2_full_usage \ 145#define bunzip2_full_usage \
144 "Uncompress FILE (or standard input if FILE is '-' or omitted)" \ 146 "Uncompress FILE (or standard input if FILE is '-' or omitted)" \
145 "\n\nOptions:\n" \ 147 "\n\nOptions:\n" \
146 " -c Write output to standard output\n" \ 148 " -c Write to standard output\n" \
147 " -f Force" 149 " -f Force"
148 150
149#define bzip2_trivial_usage \ 151#define bzip2_trivial_usage \
150 "[OPTION]... [FILE]..." 152 "[OPTION]... [FILE]..."
151#define bzip2_full_usage \ 153#define bzip2_full_usage \
152 "Compress FILE(s) with bzip2 algorithm.\n" \ 154 "Compress FILE(s) with bzip2 algorithm.\n" \
153 "When FILE is '-' or unspecified, reads standard input. Implies -c." \ 155 "When FILE is '-' or unspecified, reads standard input. Implies -c.\n" \
154 "\n\nOptions:" \ 156 "\nOptions:" \
155 "\n -c Write output to standard output instead of FILE.bz2" \ 157 "\n -c Write to standard output" \
156 "\n -d Decompress" \ 158 "\n -d Decompress" \
157 "\n -f Force" \ 159 "\n -f Force" \
158 "\n -1..-9 Compression level" 160 "\n -1..-9 Compression level"
159 161
160#define busybox_notes_usage \ 162#define busybox_notes_usage \
161 "Hello world!\n" 163 "Hello world!\n"
@@ -170,7 +172,7 @@ USE_FEATURE_BRCTL_FANCY("\n" \
170#define unlzma_full_usage \ 172#define unlzma_full_usage \
171 "Uncompress FILE (or standard input if FILE is '-' or omitted)" \ 173 "Uncompress FILE (or standard input if FILE is '-' or omitted)" \
172 "\n\nOptions:\n" \ 174 "\n\nOptions:\n" \
173 " -c Write output to standard output\n" \ 175 " -c Write to standard output\n" \
174 " -f Force" 176 " -f Force"
175 177
176#define lzmacat_trivial_usage \ 178#define lzmacat_trivial_usage \
@@ -742,7 +744,7 @@ USE_FEATURE_BRCTL_FANCY("\n" \
742#define dnsd_trivial_usage \ 744#define dnsd_trivial_usage \
743 "[-c config] [-t seconds] [-p port] [-i iface-ip] [-d]" 745 "[-c config] [-t seconds] [-p port] [-i iface-ip] [-d]"
744#define dnsd_full_usage \ 746#define dnsd_full_usage \
745 "Small and static DNS server daemon" \ 747 "Small static DNS server daemon" \
746 "\n\nOptions:\n" \ 748 "\n\nOptions:\n" \
747 " -c Config filename\n" \ 749 " -c Config filename\n" \
748 " -t TTL in seconds\n" \ 750 " -t TTL in seconds\n" \
@@ -753,12 +755,11 @@ USE_FEATURE_BRCTL_FANCY("\n" \
753#define dos2unix_trivial_usage \ 755#define dos2unix_trivial_usage \
754 "[option] [FILE]" 756 "[option] [FILE]"
755#define dos2unix_full_usage \ 757#define dos2unix_full_usage \
756 "Convert FILE from dos format to unix format. When no option\n" \ 758 "Convert FILE from dos to unix format.\n" \
757 "is given, the input is converted to the opposite output format.\n" \ 759 "When no file is given, use stdin/stdout.\n" \
758 "When no file is given, use stdin for input and stdout for output." \ 760 "\nOptions:\n" \
759 "\n\nOptions:\n" \ 761 "\n -u dos2unix" \
760 " -u Output will be in UNIX format\n" \ 762 "\n -d unix2dos"
761 " -d Output will be in DOS format"
762 763
763#define dpkg_trivial_usage \ 764#define dpkg_trivial_usage \
764 "[-ilCPru] [-F option] package_name" 765 "[-ilCPru] [-F option] package_name"
@@ -795,19 +796,19 @@ USE_FEATURE_BRCTL_FANCY("\n" \
795 SKIP_FEATURE_DU_DEFAULT_BLOCKSIZE_1K("512") \ 796 SKIP_FEATURE_DU_DEFAULT_BLOCKSIZE_1K("512") \
796 " bytes." \ 797 " bytes." \
797 "\n\nOptions:\n" \ 798 "\n\nOptions:\n" \
798 " -a Show sizes of files in addition to directories\n" \ 799 " -a Show file sizes too\n" \
799 " -H Follow symlinks that are FILE command line args\n" \ 800 " -H Follow symlinks on command line\n" \
800 " -L Follow all symlinks encountered\n" \ 801 " -L Follow all symlinks\n" \
801 " -d N Limit output to directories (and files with -a) of depth < N\n" \ 802 " -d N Limit output to directories (and files with -a) of depth < N\n" \
802 " -c Output a grand total\n" \ 803 " -c Show grand total\n" \
803 " -l Count sizes many times if hard linked\n" \ 804 " -l Count sizes many times if hard linked\n" \
804 " -s Display only a total for each argument\n" \ 805 " -s Display only a total for each argument\n" \
805 " -x Skip directories on different filesystems\n" \ 806 " -x Skip directories on different filesystems\n" \
806 USE_FEATURE_HUMAN_READABLE( \ 807 USE_FEATURE_HUMAN_READABLE( \
807 " -h Print sizes in human readable format (e.g., 1K 243M 2G )\n" \ 808 " -h Sizes in human readable format (e.g., 1K 243M 2G )\n" \
808 " -m Print sizes in megabytes\n" \ 809 " -m Sizes in megabytes\n" \
809 ) \ 810 ) \
810 " -k Print sizes in kilobytes" \ 811 " -k Sizes in kilobytes" \
811 USE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K("(default)") 812 USE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K("(default)")
812#define du_example_usage \ 813#define du_example_usage \
813 "$ du\n" \ 814 "$ du\n" \
@@ -1012,19 +1013,27 @@ USE_FEATURE_BRCTL_FANCY("\n" \
1012 "\n\nOptions:\n" \ 1013 "\n\nOptions:\n" \
1013 " -n Don't verify after format" 1014 " -n Don't verify after format"
1014 1015
1016/* Looks like someone forgot to add this to config system */
1017#ifndef ENABLE_FEATURE_FDISK_BLKSIZE
1018# define ENABLE_FEATURE_FDISK_BLKSIZE 0
1019# define USE_FEATURE_FDISK_BLKSIZE(a)
1020#endif
1021
1015#define fdisk_trivial_usage \ 1022#define fdisk_trivial_usage \
1016 "[-luv] [-C CYLINDERS] [-H HEADS] [-S SECTORS] [-b SSZ] DISK" 1023 "[-ul" USE_FEATURE_FDISK_BLKSIZE("s") "] " \
1024 "[-C CYLINDERS] [-H HEADS] [-S SECTORS] [-b SSZ] DISK"
1017#define fdisk_full_usage \ 1025#define fdisk_full_usage \
1018 "Change partition table" \ 1026 "Change partition table\n" \
1019 "\n\nOptions:\n" \ 1027 "\nOptions:\n" \
1020 " -l List partition table(s)\n" \ 1028 "\n -u Start and End are in sectors (instead of cylinders)" \
1021 " -u Give Start and End in sector (instead of cylinder) units\n" \ 1029 "\n -l Show partition table for each DISK, then exit" \
1022 " -s PARTITION Give partition size(s) in blocks\n" \ 1030 USE_FEATURE_FDISK_BLKSIZE( \
1023 " -b 2048 (for certain MO disks) use 2048-byte sectors\n" \ 1031 "\n -s Show partition sizes in kb for each DISK, then exit" \
1024 " -C CYLINDERS Set the number of cylinders\n" \ 1032 ) \
1025 " -H HEADS Set the number of heads\n" \ 1033 "\n -b 2048 (for certain MO disks) use 2048-byte sectors" \
1026 " -S SECTORS Set the number of sectors\n" \ 1034 "\n -C CYLINDERS Set number of cylinders/heads/sectors" \
1027 " -v Give fdisk version" 1035 "\n -H HEADS\n" \
1036 "\n -S SECTORS" \
1028 1037
1029#define fetchmail_trivial_usage \ 1038#define fetchmail_trivial_usage \
1030 "[-w timeout] [-U user] -P password [-X] [-t] [-z] server[:port] maildir [prog]" 1039 "[-w timeout] [-U user] -P password [-X] [-t] [-z] server[:port] maildir [prog]"
@@ -1032,25 +1041,25 @@ USE_FEATURE_BRCTL_FANCY("\n" \
1032 "Fetch content of remote mailbox to local Maildir." \ 1041 "Fetch content of remote mailbox to local Maildir." \
1033 "\n\nOptions:\n" \ 1042 "\n\nOptions:\n" \
1034 " -w timeout Set timeout on network operations\n" \ 1043 " -w timeout Set timeout on network operations\n" \
1035 " -U username Authenticate with specified username\n" \ 1044 " -U username Authenticate with specified username/password\n" \
1036 " -P password Authenticate with specified password\n" \ 1045 " -P password\n" \
1037 " -X Use openssl connection helper for secured servers\n" \ 1046 " -X Use openssl connection helper for secured servers\n" \
1038 " -t Get only headers\n" \ 1047 " -t Get only headers\n" \
1039 " -z Delete messages on server\n" \ 1048 " -z Delete messages on server\n" \
1040 " prog Run prog <message file> on message delivery" 1049 " prog Run prog <message_file> on message delivery"
1041 1050
1042#define findfs_trivial_usage \ 1051#define findfs_trivial_usage \
1043 "LABEL=label or UUID=uuid" 1052 "LABEL=label or UUID=uuid"
1044#define findfs_full_usage \ 1053#define findfs_full_usage \
1045 "Finds a filesystem device based on a label or UUID." 1054 "Find a filesystem device based on a label or UUID."
1046#define findfs_example_usage \ 1055#define findfs_example_usage \
1047 "$ findfs LABEL=MyDevice" 1056 "$ findfs LABEL=MyDevice"
1048 1057
1049#define find_trivial_usage \ 1058#define find_trivial_usage \
1050 "[PATH...] [EXPRESSION]" 1059 "[PATH...] [EXPRESSION]"
1051#define find_full_usage \ 1060#define find_full_usage \
1052 "Search for files in a directory hierarchy. The default PATH is\n" \ 1061 "Search for files. The default PATH is the current directory,\n" \
1053 "the current directory, default EXPRESSION is '-print'\n" \ 1062 "default EXPRESSION is '-print'\n" \
1054 "\nEXPRESSION may consist of:" \ 1063 "\nEXPRESSION may consist of:" \
1055 "\n -follow Dereference symlinks" \ 1064 "\n -follow Dereference symlinks" \
1056 USE_FEATURE_FIND_XDEV( \ 1065 USE_FEATURE_FIND_XDEV( \
@@ -1202,15 +1211,15 @@ USE_FEATURE_BRCTL_FANCY("\n" \
1202 ) 1211 )
1203 1212
1204#define fuser_trivial_usage \ 1213#define fuser_trivial_usage \
1205 "[options] file OR port/proto" 1214 "[options] FILE or PORT/PROTO"
1206#define fuser_full_usage \ 1215#define fuser_full_usage \
1207 "Options:\n" \ 1216 "Options:\n" \
1208 " -m Show all processes on the same mounted fs\n" \ 1217 " -m Show all processes on the same mounted fs\n" \
1209 " -k Kill all processes that match\n" \
1210 " -s Don't print or kill anything\n" \ 1218 " -s Don't print or kill anything\n" \
1211 " -4 When using port/proto only search IPv4 space\n" \ 1219 " -4 Search only IPv4 space\n" \
1212 " -6 When using port/proto only search IPv6 space\n" \ 1220 " -6 Search only IPv6 space\n" \
1213 " -SIGNAL When used with -k, this signal will be used to kill" 1221 " -k Kill all processes that match\n" \
1222 " -SIGNAL Signal to send (default: TERM)"
1214 1223
1215#define getenforce_trivial_usage 1224#define getenforce_trivial_usage
1216#define getenforce_full_usage 1225#define getenforce_full_usage
@@ -1274,7 +1283,7 @@ USE_FEATURE_BRCTL_FANCY("\n" \
1274 "\n\nOptions:\n" \ 1283 "\n\nOptions:\n" \
1275 " -h Enable hardware (RTS/CTS) flow control\n" \ 1284 " -h Enable hardware (RTS/CTS) flow control\n" \
1276 " -i Do not display /etc/issue before running login\n" \ 1285 " -i Do not display /etc/issue before running login\n" \
1277 " -L Local line, so do not do carrier detect\n" \ 1286 " -L Local line, do not do carrier detect\n" \
1278 " -m Get baud rate from modem's CONNECT status message\n" \ 1287 " -m Get baud rate from modem's CONNECT status message\n" \
1279 " -w Wait for a CR or LF before sending /etc/issue\n" \ 1288 " -w Wait for a CR or LF before sending /etc/issue\n" \
1280 " -n Do not prompt the user for a login name\n" \ 1289 " -n Do not prompt the user for a login name\n" \
@@ -1330,9 +1339,9 @@ USE_FEATURE_BRCTL_FANCY("\n" \
1330#define gunzip_full_usage \ 1339#define gunzip_full_usage \
1331 "Uncompress FILE (or standard input if FILE is '-')" \ 1340 "Uncompress FILE (or standard input if FILE is '-')" \
1332 "\n\nOptions:\n" \ 1341 "\n\nOptions:\n" \
1333 " -c Write output to standard output\n" \ 1342 " -c Write to standard output\n" \
1334 " -f Force\n" \ 1343 " -f Force\n" \
1335 " -t Test compressed file integrity" 1344 " -t Test file integrity"
1336#define gunzip_example_usage \ 1345#define gunzip_example_usage \
1337 "$ ls -la /tmp/BusyBox*\n" \ 1346 "$ ls -la /tmp/BusyBox*\n" \
1338 "-rw-rw-r-- 1 andersen andersen 557009 Apr 11 10:55 /tmp/BusyBox-0.43.tar.gz\n" \ 1347 "-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" \
1346 "Compress FILE(s) with maximum compression.\n" \ 1355 "Compress FILE(s) with maximum compression.\n" \
1347 "When FILE is '-' or unspecified, reads standard input. Implies -c." \ 1356 "When FILE is '-' or unspecified, reads standard input. Implies -c." \
1348 "\n\nOptions:\n" \ 1357 "\n\nOptions:\n" \
1349 " -c Write output to standard output instead of FILE.gz\n" \ 1358 " -c Write to standard output\n" \
1350 " -d Decompress\n" \ 1359 " -d Decompress\n" \
1351 " -f Force" 1360 " -f Force"
1352#define gzip_example_usage \ 1361#define gzip_example_usage \
@@ -1521,12 +1530,12 @@ USE_FEATURE_BRCTL_FANCY("\n" \
1521#define hwclock_full_usage \ 1530#define hwclock_full_usage \
1522 "Query and set a hardware clock (RTC)" \ 1531 "Query and set a hardware clock (RTC)" \
1523 "\n\nOptions:\n" \ 1532 "\n\nOptions:\n" \
1524 " -r Read hardware clock and print result\n" \ 1533 " -r Show time from hardware clock\n" \
1525 " -s Set the system time from the hardware clock\n" \ 1534 " -s Set system time from hardware clock\n" \
1526 " -w Set the hardware clock to the system time\n" \ 1535 " -w Set hardware clock to system time\n" \
1527 " -u The hardware clock is kept in coordinated universal time\n" \ 1536 " -u Hardware clock is in UTC\n" \
1528 " -l The hardware clock is kept in local time\n" \ 1537 " -l Hardware clock is in local time\n" \
1529 " -f FILE Use the specified clock (e.g. /dev/rtc2)" 1538 " -f FILE Use specified device (e.g. /dev/rtc2)"
1530 1539
1531#define id_trivial_usage \ 1540#define id_trivial_usage \
1532 "[OPTIONS]... [USERNAME]" 1541 "[OPTIONS]... [USERNAME]"
@@ -1974,17 +1983,16 @@ USE_FEATURE_BRCTL_FANCY("\n" \
1974 "5\n" 1983 "5\n"
1975 1984
1976#define less_trivial_usage \ 1985#define less_trivial_usage \
1977 "[-EMNmh~?] FILE1 FILE2..." 1986 "[-EMNmh~?] [FILE...]"
1978#define less_full_usage \ 1987#define less_full_usage \
1979 "View a file or list of files. The position within files can be\n" \ 1988 "View a file or list of files. The position within files can be\n" \
1980 "changed, and files can be manipulated in various ways." \ 1989 "changed, and files can be manipulated in various ways." \
1981 "\n\nOptions:\n" \ 1990 "\n\nOptions:\n" \
1982 " -E Quit once the end of a file is reached\n" \ 1991 " -E Quit once the end of a file is reached\n" \
1983 " -M,-m Display a status line containing the current line numbers\n" \ 1992 " -M,-m Display a status line containing the line numbers\n" \
1984 " and the percentage through the file\n" \ 1993 " and percentage through the file\n" \
1985 " -N Prefix line numbers to each line\n" \ 1994 " -N Prefix line numbers to each line\n" \
1986 " -~ Suppress ~s displayed when input past the end of the file is\n" \ 1995 " -~ Suppress ~s displayed past the end of the file" \
1987 " reached"
1988 1996
1989#define setarch_trivial_usage \ 1997#define setarch_trivial_usage \
1990 "personality program [args...]" 1998 "personality program [args...]"
@@ -2034,18 +2042,18 @@ USE_FEATURE_BRCTL_FANCY("\n" \
2034 "\n\nOptions:\n" \ 2042 "\n\nOptions:\n" \
2035 " -s Log to stderr as well as the system log\n" \ 2043 " -s Log to stderr as well as the system log\n" \
2036 " -t TAG Log using the specified tag (defaults to user name)\n" \ 2044 " -t TAG Log using the specified tag (defaults to user name)\n" \
2037 " -p PRIO Enter the message with the specified priority.\n" \ 2045 " -p PRIO Priority (numeric or facility.level pair)"
2038 " This may be numerical or a 'facility.level' pair." 2046
2039#define logger_example_usage \ 2047#define logger_example_usage \
2040 "$ logger \"hello\"\n" 2048 "$ logger \"hello\"\n"
2041 2049
2042#define login_trivial_usage \ 2050#define login_trivial_usage \
2043 "[OPTION]... [username] [ENV=VAR...]" 2051 "[-p] [-h HOST] [[-f] USER]"
2044#define login_full_usage \ 2052#define login_full_usage \
2045 "Begin a new session on the system" \ 2053 "Begin a new session on the system" \
2046 "\n\nOptions:\n" \ 2054 "\n\nOptions:\n" \
2047 " -f Do not authenticate (user already authenticated)\n" \ 2055 " -f Do not authenticate (user already authenticated)\n" \
2048 " -h Name of the remote host for this login\n" \ 2056 " -h Name of the remote host\n" \
2049 " -p Preserve environment" 2057 " -p Preserve environment"
2050 2058
2051#define logname_trivial_usage \ 2059#define logname_trivial_usage \
@@ -2059,9 +2067,9 @@ USE_FEATURE_BRCTL_FANCY("\n" \
2059#define logread_trivial_usage \ 2067#define logread_trivial_usage \
2060 "[OPTION]..." 2068 "[OPTION]..."
2061#define logread_full_usage \ 2069#define logread_full_usage \
2062 "Show the messages from syslogd (using circular buffer)" \ 2070 "Show messages in syslogd's circular buffer" \
2063 "\n\nOptions:\n" \ 2071 "\n\nOptions:\n" \
2064 " -f Output data as the log grows" 2072 " -f Output data as log grows"
2065 2073
2066#define losetup_trivial_usage \ 2074#define losetup_trivial_usage \
2067 "[-o OFS] LOOPDEV FILE - associate loop devices\n" \ 2075 "[-o OFS] LOOPDEV FILE - associate loop devices\n" \
@@ -2384,7 +2392,7 @@ USE_FEATURE_BRCTL_FANCY("\n" \
2384 " -n [14|30] Maximum length of filenames\n" \ 2392 " -n [14|30] Maximum length of filenames\n" \
2385 " -i INODES Number of inodes for the filesystem\n" \ 2393 " -i INODES Number of inodes for the filesystem\n" \
2386 " -l FILENAME Read bad blocks list from FILENAME\n" \ 2394 " -l FILENAME Read bad blocks list from FILENAME\n" \
2387 " -v Make a Minix version 2 filesystem" 2395 " -v Make version 2 filesystem"
2388 2396
2389#define mknod_trivial_usage \ 2397#define mknod_trivial_usage \
2390 "[OPTIONS] NAME TYPE MAJOR MINOR" 2398 "[OPTIONS] NAME TYPE MAJOR MINOR"
@@ -2809,30 +2817,28 @@ USE_FEATURE_BRCTL_FANCY("\n" \
2809 "\n\nOptions:\n" \ 2817 "\n\nOptions:\n" \
2810 " -l Show command name too\n" \ 2818 " -l Show command name too\n" \
2811 " -f Match against entire command line\n" \ 2819 " -f Match against entire command line\n" \
2812 " -n Signal the newest process only\n" \ 2820 " -n Show the newest process only\n" \
2813 " -o Signal the oldest process only\n" \ 2821 " -o Show the oldest process only\n" \
2814 " -v Negate the matching\n" \ 2822 " -v Negate the matching\n" \
2815 " -x Match whole name (not substring)" 2823 " -x Match whole name (not substring)"
2816 2824
2817#if (ENABLE_FEATURE_PIDOF_SINGLE || ENABLE_FEATURE_PIDOF_OMIT) 2825#if (ENABLE_FEATURE_PIDOF_SINGLE || ENABLE_FEATURE_PIDOF_OMIT)
2818#define USAGE_PIDOF "Options:" 2826#define pidof_trivial_usage \
2827 "[OPTION] [NAME...]"
2828#define USAGE_PIDOF "\n\nOptions:"
2819#else 2829#else
2820#define USAGE_PIDOF "\nThis version of pidof accepts no options."
2821#endif
2822
2823#define pidof_trivial_usage \ 2830#define pidof_trivial_usage \
2824 "process-name [OPTION] [process-name...]" 2831 "[NAME...]"
2825 2832#define USAGE_PIDOF /* none */
2833#endif
2826#define pidof_full_usage \ 2834#define pidof_full_usage \
2827 "List the PIDs of all processes with names that match the\n" \ 2835 "List PIDs of all processes with names that match NAMEs" \
2828 "names on the command line\n" \
2829 USAGE_PIDOF \ 2836 USAGE_PIDOF \
2830 USE_FEATURE_PIDOF_SINGLE( \ 2837 USE_FEATURE_PIDOF_SINGLE( \
2831 "\n -s Display only a single PID") \ 2838 "\n -s Show only one PID") \
2832 USE_FEATURE_PIDOF_OMIT( \ 2839 USE_FEATURE_PIDOF_OMIT( \
2833 "\n -o PID Omit given pid") \ 2840 "\n -o PID Omit given pid" \
2834 USE_FEATURE_PIDOF_OMIT( \ 2841 "\n Use %PPID to omit pid of pidof's parent")
2835 "\n Use %PPID to omit the parent pid of pidof itself")
2836#define pidof_example_usage \ 2842#define pidof_example_usage \
2837 "$ pidof init\n" \ 2843 "$ pidof init\n" \
2838 "1\n" \ 2844 "1\n" \
@@ -3090,12 +3096,12 @@ USE_FEATURE_BRCTL_FANCY("\n" \
3090#define rm_trivial_usage \ 3096#define rm_trivial_usage \
3091 "[OPTION]... FILE..." 3097 "[OPTION]... FILE..."
3092#define rm_full_usage \ 3098#define rm_full_usage \
3093 "Remove (unlink) the FILE(s). You may use '--' to\n" \ 3099 "Remove (unlink) the FILE(s). Use '--' to\n" \
3094 "indicate that all following arguments are non-options." \ 3100 "indicate that all following arguments are non-options." \
3095 "\n\nOptions:\n" \ 3101 "\n\nOptions:\n" \
3096 " -i Always prompt before removing each destination\n" \ 3102 " -i Always prompt before removing\n" \
3097 " -f Remove existing destinations, never prompt\n" \ 3103 " -f Never prompt\n" \
3098 " -r,-R Remove the contents of directories recursively" 3104 " -r,-R Remove directories recursively"
3099#define rm_example_usage \ 3105#define rm_example_usage \
3100 "$ rm -rf /tmp/foo\n" 3106 "$ rm -rf /tmp/foo\n"
3101 3107
@@ -3189,12 +3195,14 @@ USE_FEATURE_BRCTL_FANCY("\n" \
3189#define run_parts_trivial_usage \ 3195#define run_parts_trivial_usage \
3190 "[-t] "USE_FEATURE_RUN_PARTS_FANCY("[-l] ")"[-a ARG] [-u MASK] DIRECTORY" 3196 "[-t] "USE_FEATURE_RUN_PARTS_FANCY("[-l] ")"[-a ARG] [-u MASK] DIRECTORY"
3191#define run_parts_full_usage \ 3197#define run_parts_full_usage \
3192 "Run a bunch of scripts in a directory" \ 3198 "Run a bunch of scripts in a directory\n" \
3193 "\n\nOptions:\n" \ 3199 "\nOptions:" \
3194 " -t Prints what would be run, but does not actually run anything\n" \ 3200 "\n -t Print what would be run, but don't actually run anything" \
3195 " -a ARG Pass ARG as an argument for every program invoked\n" \ 3201 "\n -a ARG Pass ARG as argument for every program" \
3196 " -u MASK Set the umask to MASK before executing every program" \ 3202 "\n -u MASK Set the umask to MASK before running every program" \
3197USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when they are not executable") 3203 USE_FEATURE_RUN_PARTS_FANCY( \
3204 "\n -l Print names of all matching files even if they are not executable" \
3205 )
3198 3206
3199#define run_parts_example_usage \ 3207#define run_parts_example_usage \
3200 "$ run-parts -a start /etc/init.d\n" \ 3208 "$ 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
3251#define sed_full_usage \ 3259#define sed_full_usage \
3252 "Options:\n" \ 3260 "Options:\n" \
3253 " -e script Add the script to the commands to be executed\n" \ 3261 " -e script Add the script to the commands to be executed\n" \
3254 " -f scriptfile Add script-file contents to the\n" \ 3262 " -f scriptfile Add scriptfile contents to the\n" \
3255 " commands to be executed\n" \ 3263 " commands to be executed\n" \
3256 " -i Edit files in-place\n" \ 3264 " -i Edit files in-place\n" \
3257 " -n Suppress automatic printing of pattern space\n" \ 3265 " -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
3276 "Send an email with optional attachments." \ 3284 "Send an email with optional attachments." \
3277 "\n\nOptions:\n" \ 3285 "\n\nOptions:\n" \
3278 " -w timeout Set timeout on network operations\n" \ 3286 " -w timeout Set timeout on network operations\n" \
3279 " -U username Authenticate with specified username\n" \ 3287 " -U username Authenticate with specified username/password\n" \
3280 " -P password Authenticate with specified password\n" \ 3288 " -P password\n" \
3281 " -t address Recipient(s). May be multiple\n" \ 3289 " -t address Recipient(s). May be repeated\n" \
3282 " -X Use openssl connection helper for secured servers\n" \ 3290 " -X Use openssl connection helper for secured servers\n" \
3283 " -n Request delivery notification to sender\n" \ 3291 " -n Request delivery notification to sender\n" \
3284 " -s subject Subject\n" \ 3292 " -s subject Subject\n" \
@@ -3813,19 +3821,15 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
3813#define telnet_trivial_usage \ 3821#define telnet_trivial_usage \
3814 "[-a] [-l USER] HOST [PORT]" 3822 "[-a] [-l USER] HOST [PORT]"
3815#define telnet_full_usage \ 3823#define telnet_full_usage \
3816 "Connect to remote telnet server" \ 3824 "Connect to telnet server\n" \
3817 "\n\nOptions:\n" \ 3825 "\nOptions:" \
3818 " -a Attempt an automatic login with the USER variable\n" \ 3826 "\n -a Attempt an automatic login with USER variable" \
3819 " -l USER Attempt an automatic login with the USER argument\n" \ 3827 "\n -l USER Attempt an automatic login with USER argument"
3820 " HOST The official name, alias or the IP address of the\n" \
3821 " remote host\n" \
3822 " PORT The remote port number to connect to. If it is not\n" \
3823 " specified, the default telnet (23) port is used."
3824#else 3828#else
3825#define telnet_trivial_usage \ 3829#define telnet_trivial_usage \
3826 "HOST [PORT]" 3830 "HOST [PORT]"
3827#define telnet_full_usage \ 3831#define telnet_full_usage \
3828 "Connect to remote telnet server" 3832 "Connect to telnet server"
3829#endif 3833#endif
3830 3834
3831#define telnetd_trivial_usage \ 3835#define telnetd_trivial_usage \
@@ -3869,9 +3873,8 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
3869/* with not-implemented options: */ 3873/* with not-implemented options: */
3870/* "[-hpEvv] [-c n] [-C n:msg] [-b n] [-u user] [-l name] [-i dir|-x cdb] [-t sec] ip port prog..." */ 3874/* "[-hpEvv] [-c n] [-C n:msg] [-b n] [-u user] [-l name] [-i dir|-x cdb] [-t sec] ip port prog..." */
3871#define tcpsvd_full_usage \ 3875#define tcpsvd_full_usage \
3872 "Creates TCP socket, binds it to ip:port and listens on it\n" \ 3876 "Create TCP socket, bind it to ip:port and listen\n" \
3873 "for incoming connections. For each connection it runs prog." \ 3877 "for incoming connection. Run PROG for each connection.\n" \
3874 "\n" \
3875 "\nip IP to listen on. '0' = all" \ 3878 "\nip IP to listen on. '0' = all" \
3876 "\nport Port to listen on" \ 3879 "\nport Port to listen on" \
3877 "\nprog [arg] Program to run" \ 3880 "\nprog [arg] Program to run" \
@@ -3889,10 +3892,9 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
3889#define udpsvd_trivial_usage \ 3892#define udpsvd_trivial_usage \
3890 "[-hEv] [-c n] [-u user] [-l name] ip port prog" 3893 "[-hEv] [-c n] [-u user] [-l name] ip port prog"
3891#define udpsvd_full_usage \ 3894#define udpsvd_full_usage \
3892 "Creates UDP socket, binds it to ip:port and listens on it\n" \ 3895 "Create UDP socket, bind it to ip:port and wait\n" \
3893 "for incoming packets. For each packet it runs prog\n" \ 3896 "for incoming packets. Run PROG for each packet,\n" \
3894 "(redirecting all further packets with same peer ip:port to it)." \ 3897 "redirecting all further packets with same peer ip:port to it\n" \
3895 "\n" \
3896 "\nip IP to listen on. '0' = all" \ 3898 "\nip IP to listen on. '0' = all" \
3897 "\nport Port to listen on" \ 3899 "\nport Port to listen on" \
3898 "\nprog [arg] Program to run" \ 3900 "\nprog [arg] Program to run" \
@@ -3928,10 +3930,10 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
3928 " -v Verbose" 3930 " -v Verbose"
3929 3931
3930#define top_trivial_usage \ 3932#define top_trivial_usage \
3931 "[-b] [-n count] [-d seconds]" 3933 "[-b] [-n COUNT] [-d SECONDS]"
3932#define top_full_usage \ 3934#define top_full_usage \
3933 "Provide a view of process activity in real time.\n" \ 3935 "Provide a view of process activity in real time.\n" \
3934 "Read the status of all processes from /proc each <seconds>\n" \ 3936 "Read the status of all processes from /proc each SECONDS\n" \
3935 "and show the status for however many processes will fit on the screen." 3937 "and show the status for however many processes will fit on the screen."
3936 3938
3937#define touch_trivial_usage \ 3939#define touch_trivial_usage \
@@ -4164,12 +4166,11 @@ USE_FEATURE_RUN_PARTS_FANCY("\n -l Prints names of all matching files even when
4164#define unix2dos_trivial_usage \ 4166#define unix2dos_trivial_usage \
4165 "[option] [FILE]" 4167 "[option] [FILE]"
4166#define unix2dos_full_usage \ 4168#define unix2dos_full_usage \
4167 "Convert FILE from unix format to dos format. When no option\n" \ 4169 "Convert FILE from unix to dos format.\n" \
4168 "is given, the input is converted to the opposite output format.\n" \ 4170 "When no file is given, use stdin/stdout.\n" \
4169 "When no file is given, use stdin/stdout." \ 4171 "\nOptions:\n" \
4170 "\n\nOptions:\n" \ 4172 "\n -u dos2unix" \
4171 " -u Output will be in UNIX format\n" \ 4173 "\n -d unix2dos"
4172 " -d Output will be in DOS format"
4173 4174
4174#define unzip_trivial_usage \ 4175#define unzip_trivial_usage \
4175 "[-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]" 4176 "[-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]"
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c
index 19a2c6db5..6e3575cf9 100644
--- a/libbb/setup_environment.c
+++ b/libbb/setup_environment.c
@@ -30,16 +30,16 @@
30 30
31#include "libbb.h" 31#include "libbb.h"
32 32
33void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw) 33void setup_environment(const char *shell, int clear_env, int change_env, const struct passwd *pw)
34{ 34{
35 if (loginshell) { 35 if (clear_env) {
36 const char *term; 36 const char *term;
37 37
38 /* Change the current working directory to be the home directory 38 /* Change the current working directory to be the home directory
39 * of the user */ 39 * of the user */
40 if (chdir(pw->pw_dir)) { 40 if (chdir(pw->pw_dir)) {
41 xchdir("/"); 41 xchdir("/");
42 fputs("warning: cannot change to home directory\n", stderr); 42 bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir);
43 } 43 }
44 44
45 /* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH. 45 /* 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
56 //xsetenv("HOME", pw->pw_dir); 56 //xsetenv("HOME", pw->pw_dir);
57 //xsetenv("SHELL", shell); 57 //xsetenv("SHELL", shell);
58 } 58 }
59 else if (changeenv) { 59 else if (change_env) {
60 /* Set HOME, SHELL, and if not becoming a super-user, 60 /* Set HOME, SHELL, and if not becoming a super-user,
61 USER and LOGNAME. */ 61 USER and LOGNAME. */
62 if (pw->pw_uid) { 62 if (pw->pw_uid) {
diff --git a/loginutils/login.c b/loginutils/login.c
index bc437bb6b..a3caa0fca 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -237,8 +237,8 @@ int login_main(int argc, char **argv)
237 unsigned opt; 237 unsigned opt;
238 int count = 0; 238 int count = 0;
239 struct passwd *pw; 239 struct passwd *pw;
240 char *opt_host = NULL; 240 char *opt_host = opt_host; /* for compiler */
241 char *opt_user = NULL; 241 char *opt_user = opt_user; /* for compiler */
242 char full_tty[TTYNAME_SIZE]; 242 char full_tty[TTYNAME_SIZE];
243 USE_SELINUX(security_context_t user_sid = NULL;) 243 USE_SELINUX(security_context_t user_sid = NULL;)
244 USE_FEATURE_UTMP(struct utmp utent;) 244 USE_FEATURE_UTMP(struct utmp utent;)
@@ -287,7 +287,7 @@ int login_main(int argc, char **argv)
287 287
288 read_or_build_utent(&utent, !amroot); 288 read_or_build_utent(&utent, !amroot);
289 289
290 if (opt_host) { 290 if (opt & LOGIN_OPT_h) {
291 USE_FEATURE_UTMP( 291 USE_FEATURE_UTMP(
292 safe_strncpy(utent.ut_host, opt_host, sizeof(utent.ut_host)); 292 safe_strncpy(utent.ut_host, opt_host, sizeof(utent.ut_host));
293 ) 293 )
@@ -450,9 +450,12 @@ int login_main(int argc, char **argv)
450 xsetenv("LOGIN_UID", utoa(pw->pw_uid)); 450 xsetenv("LOGIN_UID", utoa(pw->pw_uid));
451 xsetenv("LOGIN_GID", utoa(pw->pw_gid)); 451 xsetenv("LOGIN_GID", utoa(pw->pw_gid));
452 xsetenv("LOGIN_SHELL", pw->pw_shell); 452 xsetenv("LOGIN_SHELL", pw->pw_shell);
453 xspawn(t_argv); /* NOMMU-friendly */ 453 spawn_and_wait(t_argv); /* NOMMU-friendly */
454 /* All variables are unset by setup_environment */ 454 unsetenv("LOGIN_TTY" );
455 wait(NULL); 455 unsetenv("LOGIN_USER" );
456 unsetenv("LOGIN_UID" );
457 unsetenv("LOGIN_GID" );
458 unsetenv("LOGIN_SHELL");
456 } 459 }
457 } 460 }
458 461
@@ -460,9 +463,8 @@ int login_main(int argc, char **argv)
460 tmp = pw->pw_shell; 463 tmp = pw->pw_shell;
461 if (!tmp || !*tmp) 464 if (!tmp || !*tmp)
462 tmp = DEFAULT_SHELL; 465 tmp = DEFAULT_SHELL;
463 /* setup_environment params: shell, loginshell, changeenv, pw */ 466 /* setup_environment params: shell, clear_env, change_env, pw */
464 setup_environment(tmp, 1, !(opt & LOGIN_OPT_p), pw); 467 setup_environment(tmp, !(opt & LOGIN_OPT_p), 1, pw);
465 /* FIXME: login shell = 1 -> 3rd parameter is ignored! */
466 468
467 motd(); 469 motd();
468 470
diff --git a/loginutils/su.c b/loginutils/su.c
index 8c55170ca..afb9843f8 100644
--- a/loginutils/su.c
+++ b/loginutils/su.c
@@ -93,7 +93,7 @@ int su_main(int argc, char **argv)
93 opt_shell = pw->pw_shell; 93 opt_shell = pw->pw_shell;
94 94
95 change_identity(pw); 95 change_identity(pw);
96 /* setup_environment params: shell, loginshell, changeenv, pw */ 96 /* setup_environment params: shell, clear_env, change_env, pw */
97 setup_environment(opt_shell, flags & SU_OPT_l, !(flags & SU_OPT_mp), pw); 97 setup_environment(opt_shell, flags & SU_OPT_l, !(flags & SU_OPT_mp), pw);
98 USE_SELINUX(set_current_security_context(NULL);) 98 USE_SELINUX(set_current_security_context(NULL);)
99 99
diff --git a/procps/pgrep.c b/procps/pgrep.c
index 2ebcca1c0..e4dfacb54 100644
--- a/procps/pgrep.c
+++ b/procps/pgrep.c
@@ -72,8 +72,9 @@ int pgrep_main(int argc, char **argv)
72 first_arg = argv[first_arg_idx]; 72 first_arg = argv[first_arg_idx];
73 if (!first_arg) 73 if (!first_arg)
74 break; 74 break;
75 /* not "-<small_letter>..."? */
75 if (first_arg[0] != '-' || first_arg[1] < 'a' || first_arg[1] > 'z') { 76 if (first_arg[0] != '-' || first_arg[1] < 'a' || first_arg[1] > 'z') {
76 argv[first_arg_idx] = NULL; 77 argv[first_arg_idx] = NULL; /* terminate argv here */
77 break; 78 break;
78 } 79 }
79 first_arg_idx++; 80 first_arg_idx++;
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index 827ea21f3..a75b4f817 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -318,6 +318,23 @@ struct globals {
318} while (0) 318} while (0)
319 319
320 320
321/* TODO: move to libbb? */
322static ullong bb_BLKGETSIZE_sectors(void)
323{
324 uint64_t v64;
325 unsigned long longsectors;
326
327 if (ioctl(fd, BLKGETSIZE64, &v64) == 0) {
328 /* got bytes, convert to 512 byte sectors */
329 return (v64 >> 9);
330 }
331 /* Needs temp of type long */
332 if (ioctl(fd, BLKGETSIZE, &longsectors))
333 longsectors = 0;
334 return longsectors;
335}
336
337
321#define IS_EXTENDED(i) \ 338#define IS_EXTENDED(i) \
322 ((i) == EXTENDED || (i) == WIN98_EXTENDED || (i) == LINUX_EXTENDED) 339 ((i) == EXTENDED || (i) == WIN98_EXTENDED || (i) == LINUX_EXTENDED)
323 340
@@ -624,12 +641,12 @@ get_nr_sects(const struct partition *p)
624/* normally O_RDWR, -l option gives O_RDONLY */ 641/* normally O_RDWR, -l option gives O_RDONLY */
625static int type_open = O_RDWR; 642static int type_open = O_RDWR;
626 643
627static int ext_index; /* the prime extended partition */ 644static int ext_index; /* the prime extended partition */
628static smallint listing; /* no aborts for fdisk -l */ 645static smallint listing; /* no aborts for fdisk -l */
629static int dos_compatible_flag = ~0; 646static smallint dos_compatible_flag = 1;
630#if ENABLE_FEATURE_FDISK_WRITABLE 647#if ENABLE_FEATURE_FDISK_WRITABLE
631//static int dos_changed; 648//static int dos_changed;
632static smallint nowarn; /* no warnings for fdisk -l/-s */ 649static smallint nowarn; /* no warnings for fdisk -l/-s */
633#endif 650#endif
634 651
635static unsigned user_cylinders, user_heads, user_sectors; 652static unsigned user_cylinders, user_heads, user_sectors;
@@ -1184,7 +1201,6 @@ static void
1184get_geometry(void) 1201get_geometry(void)
1185{ 1202{
1186 int sec_fac; 1203 int sec_fac;
1187 uint64_t v64;
1188 1204
1189 get_sectorsize(); 1205 get_sectorsize();
1190 sec_fac = sector_size / 512; 1206 sec_fac = sector_size / 512;
@@ -1204,15 +1220,7 @@ get_geometry(void)
1204 g_sectors = user_sectors ? user_sectors : 1220 g_sectors = user_sectors ? user_sectors :
1205 pt_sectors ? pt_sectors : 1221 pt_sectors ? pt_sectors :
1206 kern_sectors ? kern_sectors : 63; 1222 kern_sectors ? kern_sectors : 63;
1207 if (ioctl(fd, BLKGETSIZE64, &v64) == 0) { 1223 total_number_of_sectors = bb_BLKGETSIZE_sectors();
1208 /* got bytes, convert to 512 byte sectors */
1209 total_number_of_sectors = (v64 >> 9);
1210 } else {
1211 unsigned long longsectors; /* need temp of type long */
1212 if (ioctl(fd, BLKGETSIZE, &longsectors))
1213 longsectors = 0;
1214 total_number_of_sectors = longsectors;
1215 }
1216 1224
1217 sector_offset = 1; 1225 sector_offset = 1;
1218 if (dos_compatible_flag) 1226 if (dos_compatible_flag)
@@ -1576,7 +1584,7 @@ toggle_active(int i)
1576static void 1584static void
1577toggle_dos_compatibility_flag(void) 1585toggle_dos_compatibility_flag(void)
1578{ 1586{
1579 dos_compatible_flag = ~dos_compatible_flag; 1587 dos_compatible_flag = 1 - dos_compatible_flag;
1580 if (dos_compatible_flag) { 1588 if (dos_compatible_flag) {
1581 sector_offset = g_sectors; 1589 sector_offset = g_sectors;
1582 printf("DOS Compatibility flag is set\n"); 1590 printf("DOS Compatibility flag is set\n");
@@ -2732,7 +2740,8 @@ tryprocpt(void)
2732 if (sscanf(line, " %d %d %d %[^\n ]", 2740 if (sscanf(line, " %d %d %d %[^\n ]",
2733 &ma, &mi, &sz, ptname) != 4) 2741 &ma, &mi, &sz, ptname) != 4)
2734 continue; 2742 continue;
2735 for (s = ptname; *s; s++); 2743 for (s = ptname; *s; s++)
2744 continue;
2736 if (isdigit(s[-1])) 2745 if (isdigit(s[-1]))
2737 continue; 2746 continue;
2738 sprintf(devname, "/dev/%s", ptname); 2747 sprintf(devname, "/dev/%s", ptname);
@@ -2798,28 +2807,19 @@ int fdisk_main(int argc, char **argv)
2798 if (opt & OPT_u) 2807 if (opt & OPT_u)
2799 display_in_cyl_units = 0; // -u 2808 display_in_cyl_units = 0; // -u
2800 2809
2801 if (user_set_sector_size && argc != 1)
2802 printf("Warning: the -b (set sector size) option should"
2803 " be used with one specified device\n");
2804
2805#if ENABLE_FEATURE_FDISK_WRITABLE 2810#if ENABLE_FEATURE_FDISK_WRITABLE
2806 if (opt & OPT_l) { 2811 if (opt & OPT_l) {
2807 nowarn = 1; 2812 nowarn = 1;
2808#endif 2813#endif
2809 type_open = O_RDONLY; 2814 type_open = O_RDONLY;
2810 if (argc > 0) { 2815 if (*argv) {
2811 int k;
2812#if defined(__GNUC__)
2813 /* avoid gcc warning:
2814 variable `k' might be clobbered by `longjmp' */
2815 (void)&k;
2816#endif
2817 listing = 1; 2816 listing = 1;
2818 for (k = 0; k < argc; k++) 2817 do {
2819 trydev(argv[k], 1); 2818 trydev(*argv, 1);
2819 } while (*++argv);
2820 } else { 2820 } else {
2821 /* we no longer have default device names */ 2821 /* we don't have device names, */
2822 /* but, we can use /proc/partitions instead */ 2822 /* use /proc/partitions instead */
2823 tryprocpt(); 2823 tryprocpt();
2824 } 2824 }
2825 return 0; 2825 return 0;
@@ -2829,27 +2829,20 @@ int fdisk_main(int argc, char **argv)
2829 2829
2830#if ENABLE_FEATURE_FDISK_BLKSIZE 2830#if ENABLE_FEATURE_FDISK_BLKSIZE
2831 if (opt & OPT_s) { 2831 if (opt & OPT_s) {
2832 long size;
2833 int j; 2832 int j;
2834 2833
2835 nowarn = 1; 2834 nowarn = 1;
2836 type_open = O_RDONLY;
2837
2838 if (argc <= 0) 2835 if (argc <= 0)
2839 bb_show_usage(); 2836 bb_show_usage();
2840
2841 for (j = 0; j < argc; j++) { 2837 for (j = 0; j < argc; j++) {
2842 disk_device = argv[j]; 2838 unsigned long long size;
2843 fd = open(disk_device, type_open); 2839 fd = xopen(argv[j], O_RDONLY);
2844 if (fd < 0) 2840 size = bb_BLKGETSIZE_sectors() / 2;
2845 fdisk_fatal(unable_to_open);
2846 if (ioctl(fd, BLKGETSIZE, &size))
2847 fdisk_fatal(ioctl_error);
2848 close(fd); 2841 close(fd);
2849 if (argc == 1) 2842 if (argc == 1)
2850 printf("%ld\n", size/2); 2843 printf("%lld\n", size);
2851 else 2844 else
2852 printf("%s: %ld\n", argv[j], size/2); 2845 printf("%s: %lld\n", argv[j], size);
2853 } 2846 }
2854 return 0; 2847 return 0;
2855 } 2848 }