summaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-03-15 08:49:48 +0000
committerRon Yorston <rmy@pobox.com>2018-03-15 08:49:48 +0000
commit6fe4ad9a6c96624c2b75c0d51b035bc1a71d9eba (patch)
treebb7620a3217f5adf6fb5f3358b2b89a97331b5e8 /util-linux
parentf3d24e08a385a68c4bacb284bd8a8e3da7f0f4b3 (diff)
parentbbe47d9b9aee3824845f1ce08c9caeb262c15059 (diff)
downloadbusybox-w32-6fe4ad9a6c96624c2b75c0d51b035bc1a71d9eba.tar.gz
busybox-w32-6fe4ad9a6c96624c2b75c0d51b035bc1a71d9eba.tar.bz2
busybox-w32-6fe4ad9a6c96624c2b75c0d51b035bc1a71d9eba.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/ipcs.c76
-rw-r--r--util-linux/readprofile.c67
2 files changed, 66 insertions, 77 deletions
diff --git a/util-linux/ipcs.c b/util-linux/ipcs.c
index 7092ecd92..4863a5c29 100644
--- a/util-linux/ipcs.c
+++ b/util-linux/ipcs.c
@@ -101,8 +101,6 @@ union semun {
101#define TIME 4 101#define TIME 4
102#define PID 5 102#define PID 5
103 103
104static char format;
105
106static void print_perms(int id, struct ipc_perm *ipcp) 104static void print_perms(int id, struct ipc_perm *ipcp)
107{ 105{
108 struct passwd *pw; 106 struct passwd *pw;
@@ -125,8 +123,7 @@ static void print_perms(int id, struct ipc_perm *ipcp)
125 else printf(" %-10d\n", ipcp->gid); 123 else printf(" %-10d\n", ipcp->gid);
126} 124}
127 125
128 126static NOINLINE void do_shm(int format)
129static NOINLINE void do_shm(void)
130{ 127{
131 int maxid, shmid, id; 128 int maxid, shmid, id;
132 struct shmid_ds shmseg; 129 struct shmid_ds shmseg;
@@ -252,8 +249,7 @@ static NOINLINE void do_shm(void)
252 } 249 }
253} 250}
254 251
255 252static NOINLINE void do_sem(int format)
256static NOINLINE void do_sem(void)
257{ 253{
258 int maxid, semid, id; 254 int maxid, semid, id;
259 struct semid_ds semary; 255 struct semid_ds semary;
@@ -358,8 +354,7 @@ static NOINLINE void do_sem(void)
358 } 354 }
359} 355}
360 356
361 357static NOINLINE void do_msg(int format)
362static NOINLINE void do_msg(void)
363{ 358{
364 int maxid, msqid, id; 359 int maxid, msqid, id;
365 struct msqid_ds msgque; 360 struct msqid_ds msgque;
@@ -466,7 +461,6 @@ static NOINLINE void do_msg(void)
466 } 461 }
467} 462}
468 463
469
470static void print_shm(int shmid) 464static void print_shm(int shmid)
471{ 465{
472 struct shmid_ds shmds; 466 struct shmid_ds shmds;
@@ -493,7 +487,6 @@ static void print_shm(int shmid)
493 printf("change_time=%-26.24s\n\n", ctime(&shmds.shm_ctime)); 487 printf("change_time=%-26.24s\n\n", ctime(&shmds.shm_ctime));
494} 488}
495 489
496
497static void print_msg(int msqid) 490static void print_msg(int msqid)
498{ 491{
499 struct msqid_ds buf; 492 struct msqid_ds buf;
@@ -570,9 +563,9 @@ static void print_sem(int semid)
570} 563}
571 564
572//usage:#define ipcs_trivial_usage 565//usage:#define ipcs_trivial_usage
573//usage: "[[-smq] -i shmid] | [[-asmq] [-tcplu]]" 566//usage: "[[-smq] -i SHMID] | [[-asmq] [-tcplu]]"
574//usage:#define ipcs_full_usage "\n\n" 567//usage:#define ipcs_full_usage "\n\n"
575//usage: " -i Show specific resource" 568//usage: " -i ID Show specific resource"
576//usage: "\nResource specification:" 569//usage: "\nResource specification:"
577//usage: "\n -m Shared memory segments" 570//usage: "\n -m Shared memory segments"
578//usage: "\n -q Message queues" 571//usage: "\n -q Message queues"
@@ -588,60 +581,57 @@ static void print_sem(int semid)
588int ipcs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 581int ipcs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
589int ipcs_main(int argc UNUSED_PARAM, char **argv) 582int ipcs_main(int argc UNUSED_PARAM, char **argv)
590{ 583{
591 int id = 0; 584 int format = 0;
592 unsigned flags = 0;
593 unsigned opt; 585 unsigned opt;
594 char *opt_i; 586 char *opt_i;
595#define flag_print (1<<0)
596#define flag_msg (1<<1)
597#define flag_sem (1<<2)
598#define flag_shm (1<<3)
599 587
600 opt = getopt32(argv, "i:aqsmtcplu", &opt_i); 588 opt = getopt32(argv, "i:aqsmtcplu", &opt_i);
601 if (opt & 0x1) { // -i 589#define flag_msg (1<<2)
590#define flag_sem (1<<3)
591#define flag_shm (1<<4)
592 if (opt & (1<<5)) format = TIME; // -t
593 if (opt & (1<<6)) format = CREATOR; // -c
594 if (opt & (1<<7)) format = PID; // -p
595 if (opt & (1<<8)) format = LIMITS; // -l
596 if (opt & (1<<9)) format = STATUS; // -u
597
598 if (opt & (1<<0)) { // -i
599 int id;
600
602 id = xatoi(opt_i); 601 id = xatoi(opt_i);
603 flags |= flag_print; 602 if (opt & flag_shm) {
604 }
605 if (opt & 0x2) flags |= flag_msg | flag_sem | flag_shm; // -a
606 if (opt & 0x4) flags |= flag_msg; // -q
607 if (opt & 0x8) flags |= flag_sem; // -s
608 if (opt & 0x10) flags |= flag_shm; // -m
609 if (opt & 0x20) format = TIME; // -t
610 if (opt & 0x40) format = CREATOR; // -c
611 if (opt & 0x80) format = PID; // -p
612 if (opt & 0x100) format = LIMITS; // -l
613 if (opt & 0x200) format = STATUS; // -u
614
615 if (flags & flag_print) {
616 if (flags & flag_shm) {
617 print_shm(id); 603 print_shm(id);
618 fflush_stdout_and_exit(EXIT_SUCCESS); 604 fflush_stdout_and_exit(EXIT_SUCCESS);
619 } 605 }
620 if (flags & flag_sem) { 606 if (opt & flag_sem) {
621 print_sem(id); 607 print_sem(id);
622 fflush_stdout_and_exit(EXIT_SUCCESS); 608 fflush_stdout_and_exit(EXIT_SUCCESS);
623 } 609 }
624 if (flags & flag_msg) { 610 if (opt & flag_msg) {
625 print_msg(id); 611 print_msg(id);
626 fflush_stdout_and_exit(EXIT_SUCCESS); 612 fflush_stdout_and_exit(EXIT_SUCCESS);
627 } 613 }
628 bb_show_usage(); 614 bb_show_usage();
629 } 615 }
630 616
631 if (!(flags & (flag_shm | flag_msg | flag_sem))) 617 if ((opt & (1<<1)) // -a
632 flags |= flag_msg | flag_shm | flag_sem; 618 || !(opt & (flag_msg | flag_sem | flag_shm)) // none of -q,-s,-m == all
619 ) {
620 opt |= flag_msg | flag_sem | flag_shm;
621 }
622
633 bb_putchar('\n'); 623 bb_putchar('\n');
634 624
635 if (flags & flag_msg) { 625 if (opt & flag_msg) {
636 do_msg(); 626 do_msg(format);
637 bb_putchar('\n'); 627 bb_putchar('\n');
638 } 628 }
639 if (flags & flag_shm) { 629 if (opt & flag_shm) {
640 do_shm(); 630 do_shm(format);
641 bb_putchar('\n'); 631 bb_putchar('\n');
642 } 632 }
643 if (flags & flag_sem) { 633 if (opt & flag_sem) {
644 do_sem(); 634 do_sem(format);
645 bb_putchar('\n'); 635 bb_putchar('\n');
646 } 636 }
647 fflush_stdout_and_exit(EXIT_SUCCESS); 637 fflush_stdout_and_exit(EXIT_SUCCESS);
diff --git a/util-linux/readprofile.c b/util-linux/readprofile.c
index 8fc33be3c..219c0c18c 100644
--- a/util-linux/readprofile.c
+++ b/util-linux/readprofile.c
@@ -61,27 +61,22 @@
61 61
62#define S_LEN 128 62#define S_LEN 128
63 63
64/* These are the defaults */
65static const char defaultmap[] ALIGN1 = "/boot/System.map";
66static const char defaultpro[] ALIGN1 = "/proc/profile";
67
68int readprofile_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 64int readprofile_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
69int readprofile_main(int argc UNUSED_PARAM, char **argv) 65int readprofile_main(int argc UNUSED_PARAM, char **argv)
70{ 66{
71 FILE *map; 67 FILE *map;
72 const char *mapFile, *proFile; 68 const char *mapFile, *proFile;
73 unsigned long indx = 1; 69 unsigned long indx;
74 size_t len; 70 size_t len;
75 uint64_t add0 = 0; 71 uint64_t add0;
76 unsigned int step; 72 unsigned int step;
77 unsigned int *buf, total, fn_len; 73 unsigned int *buf, total, fn_len;
78 unsigned long long fn_add, next_add; /* current and next address */ 74 unsigned long long fn_add, next_add; /* current and next address */
79 char fn_name[S_LEN], next_name[S_LEN]; /* current and next name */ 75 char fn_name[S_LEN], next_name[S_LEN]; /* current and next name */
80 char mapline[S_LEN]; 76 char mapline[S_LEN];
81 char mode[8]; 77 char mode[8];
82 int maplineno = 1; 78 int maplineno;
83 int header_printed; 79 int multiplier;
84 int multiplier = 0;
85 unsigned opt; 80 unsigned opt;
86 enum { 81 enum {
87 OPT_M = (1 << 0), 82 OPT_M = (1 << 0),
@@ -106,8 +101,9 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv)
106 101
107#define next (current^1) 102#define next (current^1)
108 103
109 proFile = defaultpro; 104 proFile = "/proc/profile";
110 mapFile = defaultmap; 105 mapFile = "/boot/System.map";
106 multiplier = 0;
111 107
112 opt = getopt32(argv, "M:+m:p:nabsirv", &multiplier, &mapFile, &proFile); 108 opt = getopt32(argv, "M:+m:p:nabsirv", &multiplier, &mapFile, &proFile);
113 109
@@ -122,7 +118,7 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv)
122 if (!optMult) 118 if (!optMult)
123 to_write = 1; /* sth different from sizeof(int) */ 119 to_write = 1; /* sth different from sizeof(int) */
124 120
125 fd = xopen(defaultpro, O_WRONLY); 121 fd = xopen("/proc/profile", O_WRONLY);
126 xwrite(fd, &multiplier, to_write); 122 xwrite(fd, &multiplier, to_write);
127 close(fd); 123 close(fd);
128 return EXIT_SUCCESS; 124 return EXIT_SUCCESS;
@@ -133,12 +129,13 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv)
133 */ 129 */
134 len = MAXINT(ssize_t); 130 len = MAXINT(ssize_t);
135 buf = xmalloc_xopen_read_close(proFile, &len); 131 buf = xmalloc_xopen_read_close(proFile, &len);
132 len /= sizeof(*buf);
133
136 if (!optNative) { 134 if (!optNative) {
137 int entries = len / sizeof(*buf); 135 int big = 0, small = 0;
138 int big = 0, small = 0, i;
139 unsigned *p; 136 unsigned *p;
140 137
141 for (p = buf+1; p < buf+entries; p++) { 138 for (p = buf+1; p < buf+len; p++) {
142 if (*p & ~0U << (sizeof(*buf)*4)) 139 if (*p & ~0U << (sizeof(*buf)*4))
143 big++; 140 big++;
144 if (*p & ((1 << (sizeof(*buf)*4))-1)) 141 if (*p & ((1 << (sizeof(*buf)*4))-1))
@@ -147,15 +144,15 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv)
147 if (big > small) { 144 if (big > small) {
148 bb_error_msg("assuming reversed byte order, " 145 bb_error_msg("assuming reversed byte order, "
149 "use -n to force native byte order"); 146 "use -n to force native byte order");
150 for (p = buf; p < buf+entries; p++) 147 BUILD_BUG_ON(sizeof(*p) > 8);
151 for (i = 0; i < sizeof(*buf)/2; i++) { 148 for (p = buf; p < buf+len; p++) {
152 unsigned char *b = (unsigned char *) p; 149 if (sizeof(*p) == 2)
153 unsigned char tmp; 150 *p = bswap_16(*p);
154 151 if (sizeof(*p) == 4)
155 tmp = b[i]; 152 *p = bswap_32(*p);
156 b[i] = b[sizeof(*buf)-i-1]; 153 if (sizeof(*p) == 8)
157 b[sizeof(*buf)-i-1] = tmp; 154 *p = bb_bswap_64(*p);
158 } 155 }
159 } 156 }
160 } 157 }
161 158
@@ -165,10 +162,9 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv)
165 return EXIT_SUCCESS; 162 return EXIT_SUCCESS;
166 } 163 }
167 164
168 total = 0;
169
170 map = xfopen_for_read(mapFile); 165 map = xfopen_for_read(mapFile);
171 166 add0 = 0;
167 maplineno = 1;
172 while (fgets(mapline, S_LEN, map)) { 168 while (fgets(mapline, S_LEN, map)) {
173 if (sscanf(mapline, "%llx %s %s", &fn_add, mode, fn_name) != 3) 169 if (sscanf(mapline, "%llx %s %s", &fn_add, mode, fn_name) != 3)
174 bb_error_msg_and_die("%s(%i): wrong map line", 170 bb_error_msg_and_die("%s(%i): wrong map line",
@@ -187,8 +183,11 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv)
187 /* 183 /*
188 * Main loop. 184 * Main loop.
189 */ 185 */
186 total = 0;
187 indx = 1;
190 while (fgets(mapline, S_LEN, map)) { 188 while (fgets(mapline, S_LEN, map)) {
191 unsigned int this = 0; 189 bool header_printed;
190 unsigned int this;
192 191
193 if (sscanf(mapline, "%llx %s %s", &next_add, mode, next_name) != 3) 192 if (sscanf(mapline, "%llx %s %s", &next_add, mode, next_name) != 3)
194 bb_error_msg_and_die("%s(%i): wrong map line", 193 bb_error_msg_and_die("%s(%i): wrong map line",
@@ -198,17 +197,17 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv)
198 197
199 /* ignore any LEADING (before a '[tT]' symbol is found) 198 /* ignore any LEADING (before a '[tT]' symbol is found)
200 Absolute symbols */ 199 Absolute symbols */
201 if ((*mode == 'A' || *mode == '?') && total == 0) continue; 200 if ((mode[0] == 'A' || mode[0] == '?') && total == 0)
202 if (*mode != 'T' && *mode != 't' 201 continue;
203 && *mode != 'W' && *mode != 'w' 202 if ((mode[0]|0x20) != 't' && (mode[0]|0x20) != 'w') {
204 ) {
205 break; /* only text is profiled */ 203 break; /* only text is profiled */
206 } 204 }
207 205
208 if (indx >= len / sizeof(*buf)) 206 if (indx >= len)
209 bb_error_msg_and_die("profile address out of range. " 207 bb_error_msg_and_die("profile address out of range. "
210 "Wrong map file?"); 208 "Wrong map file?");
211 209
210 this = 0;
212 while (indx < (next_add-add0)/step) { 211 while (indx < (next_add-add0)/step) {
213 if (optBins && (buf[indx] || optAll)) { 212 if (optBins && (buf[indx] || optAll)) {
214 if (!header_printed) { 213 if (!header_printed) {
@@ -256,7 +255,7 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv)
256 } 255 }
257 256
258 /* clock ticks, out of kernel text - probably modules */ 257 /* clock ticks, out of kernel text - probably modules */
259 printf("%6u %s\n", buf[len/sizeof(*buf)-1], "*unknown*"); 258 printf("%6u *unknown*\n", buf[len-1]);
260 259
261 /* trailer */ 260 /* trailer */
262 if (optVerbose) 261 if (optVerbose)